ueditor.all.js 895 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836
  1. /*
  2. * ! UEditor version: ueditor build: Thu May 29 2014 16:47:57 GMT+0800 (中国标准时间)
  3. */
  4. window.initedUEALL = false;
  5. /* 再去掉,去掉 ?wdApplication= -- 不支持多个应用,ssServ= 里可以写 ss.xxx。Lin
  6. function getWdApp() {
  7. return window.wdApp;
  8. // var vars = [],
  9. // hash;
  10. // var hashes = window.location.href.slice(
  11. // window.location.href.indexOf('?') + 1).split('&');
  12. // for (var i = 0; i < hashes.length; i++) {
  13. // hash = hashes[i].split('=');
  14. // vars.push(hash[0]);
  15. // vars[hash[0]] = hash[1];
  16. // }
  17. // return "&wdApp=" + vars["wdApplication"];
  18. };
  19. */
  20. (function() {
  21. // editor.js
  22. if(!window.initedUEALL) {
  23. window.initedUEALL = true;
  24. } else {
  25. return;
  26. }
  27. UEDITOR_CONFIG = window.UEDITOR_CONFIG || {};
  28. var baidu = window.baidu || {};
  29. window.baidu = baidu;
  30. window.UE = baidu.editor = window.UE || {};
  31. UE.plugins = UE.plugins || {};
  32. UE.commands = UE.commands || {};
  33. UE.instants = UE.instants || {};
  34. UE.I18N = UE.I18N || {};
  35. UE._customizeUI = UE._customizeUI || {};
  36. UE.version = "1.4.3";
  37. var dom = UE.dom = UE.dom || {};
  38. // core/browser.js
  39. /**
  40. * 浏览器判断模块
  41. *
  42. * @file
  43. * @module UE.browser
  44. * @since 1.2.6.1
  45. */
  46. /**
  47. * 提供浏览器检测的模块
  48. *
  49. * @unfile
  50. * @module UE.browser
  51. */
  52. var browser = UE.browser = function() {
  53. var agent = navigator.userAgent.toLowerCase(),
  54. opera = window.opera,
  55. browser = {
  56. /**
  57. * @property {boolean} ie 检测当前浏览器是否为IE
  58. * @example ```javascript if ( UE.browser.ie ) { console.log(
  59. * '当前浏览器是IE' ); } ```
  60. */
  61. ie: /(msie\s|trident.*rv:)([\w.]+)/.test(agent),
  62. /**
  63. * @property {boolean} opera 检测当前浏览器是否为Opera
  64. * @example ```javascript if ( UE.browser.opera ) { console.log(
  65. * '当前浏览器是Opera' ); } ```
  66. */
  67. opera: (!!opera && opera.version),
  68. /**
  69. * @property {boolean} webkit 检测当前浏览器是否是webkit内核的浏览器
  70. * @example ```javascript if ( UE.browser.webkit ) { console.log(
  71. * '当前浏览器是webkit内核浏览器' ); } ```
  72. */
  73. webkit: (agent.indexOf(' applewebkit/') > -1),
  74. /**
  75. * @property {boolean} mac 检测当前浏览器是否是运行在mac平台下
  76. * @example ```javascript if ( UE.browser.mac ) { console.log(
  77. * '当前浏览器运行在mac平台下' ); } ```
  78. */
  79. mac: (agent.indexOf('macintosh') > -1),
  80. /**
  81. * @property {boolean} quirks 检测当前浏览器是否处于“怪异模式”下
  82. * @example ```javascript if ( UE.browser.quirks ) { console.log(
  83. * '当前浏览器运行处于“怪异模式”' ); } ```
  84. */
  85. quirks: (document.compatMode == 'BackCompat')
  86. };
  87. /**
  88. * @property {boolean} gecko 检测当前浏览器内核是否是gecko内核
  89. * @example ```javascript if ( UE.browser.gecko ) { console.log(
  90. * '当前浏览器内核是gecko内核' ); } ```
  91. */
  92. browser.gecko = (navigator.product == 'Gecko' && !browser.webkit &&
  93. !browser.opera && !browser.ie);
  94. var version = 0;
  95. // Internet Explorer 6.0+
  96. if(browser.ie) {
  97. var v1 = agent.match(/(?:msie\s([\w.]+))/);
  98. var v2 = agent.match(/(?:trident.*rv:([\w.]+))/);
  99. if(v1 && v2 && v1[1] && v2[1]) {
  100. version = Math.max(v1[1] * 1, v2[1] * 1);
  101. } else if(v1 && v1[1]) {
  102. version = v1[1] * 1;
  103. } else if(v2 && v2[1]) {
  104. version = v2[1] * 1;
  105. } else {
  106. version = 0;
  107. }
  108. browser.ie11Compat = document.documentMode == 11;
  109. /**
  110. * @property { boolean } ie9Compat 检测浏览器模式是否为 IE9 兼容模式
  111. * @warning 如果浏览器不是IE, 则该值为undefined
  112. * @example ```javascript if ( UE.browser.ie9Compat ) { console.log(
  113. * '当前浏览器运行在IE9兼容模式下' ); } ```
  114. */
  115. browser.ie9Compat = document.documentMode == 9;
  116. /**
  117. * @property { boolean } ie8 检测浏览器是否是IE8浏览器
  118. * @warning 如果浏览器不是IE, 则该值为undefined
  119. * @example ```javascript if ( UE.browser.ie8 ) { console.log(
  120. * '当前浏览器是IE8浏览器' ); } ```
  121. */
  122. browser.ie8 = !!document.documentMode;
  123. /**
  124. * @property { boolean } ie8Compat 检测浏览器模式是否为 IE8 兼容模式
  125. * @warning 如果浏览器不是IE, 则该值为undefined
  126. * @example ```javascript if ( UE.browser.ie8Compat ) { console.log(
  127. * '当前浏览器运行在IE8兼容模式下' ); } ```
  128. */
  129. browser.ie8Compat = document.documentMode == 8;
  130. /**
  131. * @property { boolean } ie7Compat 检测浏览器模式是否为 IE7 兼容模式
  132. * @warning 如果浏览器不是IE, 则该值为undefined
  133. * @example ```javascript if ( UE.browser.ie7Compat ) { console.log(
  134. * '当前浏览器运行在IE7兼容模式下' ); } ```
  135. */
  136. browser.ie7Compat = ((version == 7 && !document.documentMode) || document.documentMode == 7);
  137. /**
  138. * @property { boolean } ie6Compat 检测浏览器模式是否为 IE6 模式 或者怪异模式
  139. * @warning 如果浏览器不是IE, 则该值为undefined
  140. * @example ```javascript if ( UE.browser.ie6Compat ) { console.log(
  141. * '当前浏览器运行在IE6模式或者怪异模式下' ); } ```
  142. */
  143. browser.ie6Compat = (version < 7 || browser.quirks);
  144. browser.ie9above = version > 8;
  145. browser.ie9below = version < 9;
  146. browser.ie11above = version > 10;
  147. browser.ie11below = version < 11;
  148. }
  149. // Gecko.
  150. if(browser.gecko) {
  151. var geckoRelease = agent.match(/rv:([\d\.]+)/);
  152. if(geckoRelease) {
  153. geckoRelease = geckoRelease[1].split('.');
  154. version = geckoRelease[0] * 10000 + (geckoRelease[1] || 0) *
  155. 100 + (geckoRelease[2] || 0) * 1;
  156. }
  157. }
  158. /**
  159. * @property { Number } chrome 检测当前浏览器是否为Chrome, 如果是,则返回Chrome的大版本号
  160. * @warning 如果浏览器不是chrome, 则该值为undefined
  161. * @example ```javascript if ( UE.browser.chrome ) { console.log(
  162. * '当前浏览器是Chrome' ); } ```
  163. */
  164. if(/chrome\/(\d+\.\d)/i.test(agent)) {
  165. browser.chrome = +RegExp['\x241'];
  166. }
  167. /**
  168. * @property { Number } safari 检测当前浏览器是否为Safari, 如果是,则返回Safari的大版本号
  169. * @warning 如果浏览器不是safari, 则该值为undefined
  170. * @example ```javascript if ( UE.browser.safari ) { console.log(
  171. * '当前浏览器是Safari' ); } ```
  172. */
  173. if(/(\d+\.\d)?(?:\.\d)?\s+safari\/?(\d+\.\d+)?/i.test(agent) &&
  174. !/chrome/i.test(agent)) {
  175. browser.safari = +(RegExp['\x241'] || RegExp['\x242']);
  176. }
  177. // Opera 9.50+
  178. if(browser.opera)
  179. version = parseFloat(opera.version());
  180. // WebKit 522+ (Safari 3+)
  181. if(browser.webkit)
  182. version = parseFloat(agent.match(/ applewebkit\/(\d+)/)[1]);
  183. /**
  184. * @property { Number } version 检测当前浏览器版本号
  185. * @remind
  186. * <ul>
  187. * <li>IE系列返回值为5,6,7,8,9,10等</li>
  188. * <li>gecko系列会返回10900,158900等</li>
  189. * <li>webkit系列会返回其build号 (如 522等)</li>
  190. * </ul>
  191. * @example ```javascript console.log( '当前浏览器版本号是: ' +
  192. * UE.browser.version ); ```
  193. */
  194. browser.version = version;
  195. /**
  196. * @property { boolean } isCompatible 检测当前浏览器是否能够与UEditor良好兼容
  197. * @example ```javascript if ( UE.browser.isCompatible ) { console.log(
  198. * '浏览器与UEditor能够良好兼容' ); } ```
  199. */
  200. browser.isCompatible = !browser.mobile &&
  201. ((browser.ie && version >= 6) ||
  202. (browser.gecko && version >= 10801) ||
  203. (browser.opera && version >= 9.5) ||
  204. (browser.air && version >= 1) ||
  205. (browser.webkit && version >= 522) || false);
  206. return browser;
  207. }();
  208. // 快捷方式
  209. var ie = browser.ie,
  210. webkit = browser.webkit,
  211. gecko = browser.gecko,
  212. opera = browser.opera;
  213. // core/utils.js
  214. /**
  215. * 工具函数包
  216. *
  217. * @file
  218. * @module UE.utils
  219. * @since 1.2.6.1
  220. */
  221. /**
  222. * UEditor封装使用的静态工具函数
  223. *
  224. * @module UE.utils
  225. * @unfile
  226. */
  227. var utils = UE.utils = {
  228. /**
  229. * 用给定的迭代器遍历对象
  230. *
  231. * @method each
  232. * @param {
  233. * Object } obj 需要遍历的对象
  234. * @param {
  235. * Function } iterator 迭代器, 该方法接受两个参数, 第一个参数是当前所处理的value,
  236. * 第二个参数是当前遍历对象的key
  237. * @example ```javascript var demoObj = { key1: 1, key2: 2 };
  238. *
  239. * //output: key1: 1, key2: 2 UE.utils.each( demoObj, funciton ( value,
  240. * key ) {
  241. *
  242. * console.log( key + ":" + value ); } ); ```
  243. */
  244. /**
  245. * 用给定的迭代器遍历数组或类数组对象
  246. *
  247. * @method each
  248. * @param {
  249. * Array } array 需要遍历的数组或者类数组
  250. * @param {
  251. * Function } iterator 迭代器, 该方法接受两个参数, 第一个参数是当前所处理的value,
  252. * 第二个参数是当前遍历对象的key
  253. * @example ```javascript var divs = document.getElmentByTagNames( "div" );
  254. *
  255. * //output: 0: DIV, 1: DIV ... UE.utils.each( divs, funciton ( value,
  256. * key ) {
  257. *
  258. * console.log( key + ":" + value.tagName ); } ); ```
  259. */
  260. each: function(obj, iterator, context) {
  261. if(obj == null)
  262. return;
  263. if(obj.length === +obj.length) {
  264. for(var i = 0, l = obj.length; i < l; i++) {
  265. if(iterator.call(context, obj[i], i, obj) === false)
  266. return false;
  267. }
  268. } else {
  269. for(var key in obj) {
  270. if(obj.hasOwnProperty(key)) {
  271. if(iterator.call(context, obj[key], key, obj) === false)
  272. return false;
  273. }
  274. }
  275. }
  276. },
  277. /**
  278. * 以给定对象作为原型创建一个新对象
  279. *
  280. * @method makeInstance
  281. * @param {
  282. * Object } protoObject 该对象将作为新创建对象的原型
  283. * @return { Object } 新的对象, 该对象的原型是给定的protoObject对象
  284. * @example ```javascript
  285. *
  286. * var protoObject = { sayHello: function () { console.log('Hello
  287. * UEditor!'); } };
  288. *
  289. * var newObject = UE.utils.makeInstance( protoObject ); //output: Hello
  290. * UEditor! newObject.sayHello(); ```
  291. */
  292. makeInstance: function(obj) {
  293. var noop = new Function();
  294. noop.prototype = obj;
  295. obj = new noop;
  296. noop.prototype = null;
  297. return obj;
  298. },
  299. /**
  300. * 将source对象中的属性扩展到target对象上
  301. *
  302. * @method extend
  303. * @remind 该方法将强制把source对象上的属性复制到target对象上
  304. * @see UE.utils.extend(Object,Object,Boolean)
  305. * @param {
  306. * Object } target 目标对象, 新的属性将附加到该对象上
  307. * @param {
  308. * Object } source 源对象, 该对象的属性会被附加到target对象上
  309. * @return { Object } 返回target对象
  310. * @example ```javascript
  311. *
  312. * var target = { name: 'target', sex: 1 }, source = { name: 'source',
  313. * age: 17 };
  314. *
  315. * UE.utils.extend( target, source );
  316. *
  317. * //output: { name: 'source', sex: 1, age: 17 } console.log( target );
  318. *
  319. * ```
  320. */
  321. /**
  322. * 将source对象中的属性扩展到target对象上, 根据指定的isKeepTarget值决定是否保留目标对象中与
  323. * 源对象属性名相同的属性值。
  324. *
  325. * @method extend
  326. * @param {
  327. * Object } target 目标对象, 新的属性将附加到该对象上
  328. * @param {
  329. * Object } source 源对象, 该对象的属性会被附加到target对象上
  330. * @param {
  331. * Boolean } isKeepTarget 是否保留目标对象中与源对象中属性名相同的属性
  332. * @return { Object } 返回target对象
  333. * @example ```javascript
  334. *
  335. * var target = { name: 'target', sex: 1 }, source = { name: 'source',
  336. * age: 17 };
  337. *
  338. * UE.utils.extend( target, source, true );
  339. *
  340. * //output: { name: 'target', sex: 1, age: 17 } console.log( target );
  341. *
  342. * ```
  343. */
  344. extend: function(t, s, b) {
  345. if(s) {
  346. for(var k in s) {
  347. if(!b || !t.hasOwnProperty(k)) {
  348. t[k] = s[k];
  349. }
  350. }
  351. }
  352. return t;
  353. },
  354. /**
  355. * 将给定的多个对象的属性复制到目标对象target上
  356. *
  357. * @method extend2
  358. * @remind 该方法将强制把源对象上的属性复制到target对象上
  359. * @remind 该方法支持两个及以上的参数, 从第二个参数开始, 其属性都会被复制到第一个参数上。 如果遇到同名的属性,
  360. * 将会覆盖掉之前的值。
  361. * @param {
  362. * Object } target 目标对象, 新的属性将附加到该对象上
  363. * @param {
  364. * Object... } source 源对象, 支持多个对象, 该对象的属性会被附加到target对象上
  365. * @return { Object } 返回target对象
  366. * @example ```javascript
  367. *
  368. * var target = {}, source1 = { name: 'source', age: 17 }, source2 = {
  369. * title: 'dev' };
  370. *
  371. * UE.utils.extend2( target, source1, source2 );
  372. *
  373. * //output: { name: 'source', age: 17, title: 'dev' } console.log(
  374. * target );
  375. *
  376. * ```
  377. */
  378. extend2: function(t) {
  379. var a = arguments;
  380. for(var i = 1; i < a.length; i++) {
  381. var x = a[i];
  382. for(var k in x) {
  383. if(!t.hasOwnProperty(k)) {
  384. t[k] = x[k];
  385. }
  386. }
  387. }
  388. return t;
  389. },
  390. /**
  391. * 模拟继承机制, 使得subClass继承自superClass
  392. *
  393. * @method inherits
  394. * @param {
  395. * Object } subClass 子类对象
  396. * @param {
  397. * Object } superClass 超类对象
  398. * @warning 该方法只能让subClass继承超类的原型, subClass对象自身的属性和方法不会被继承
  399. * @return { Object } 继承superClass后的子类对象
  400. * @example ```javascript function SuperClass(){ this.name = "小李"; }
  401. *
  402. * SuperClass.prototype = { hello:function(str){ console.log(this.name +
  403. * str); } }
  404. *
  405. * function SubClass(){ this.name = "小张"; }
  406. *
  407. * UE.utils.inherits(SubClass,SuperClass);
  408. *
  409. * var sub = new SubClass(); //output: '小张早上好! sub.hello("早上好!"); ```
  410. */
  411. inherits: function(subClass, superClass) {
  412. var oldP = subClass.prototype,
  413. newP = utils
  414. .makeInstance(superClass.prototype);
  415. utils.extend(newP, oldP, true);
  416. subClass.prototype = newP;
  417. return(newP.constructor = subClass);
  418. },
  419. /**
  420. * 用指定的context对象作为函数fn的上下文
  421. *
  422. * @method bind
  423. * @param {
  424. * Function } fn 需要绑定上下文的函数对象
  425. * @param {
  426. * Object } content 函数fn新的上下文对象
  427. * @return { Function } 一个新的函数, 该函数作为原始函数fn的代理, 将完成fn的上下文调换工作。
  428. * @example ```javascript
  429. *
  430. * var name = 'window', newTest = null;
  431. *
  432. * function test () { console.log( this.name ); }
  433. *
  434. * newTest = UE.utils.bind( test, { name: 'object' } );
  435. *
  436. * //output: object newTest();
  437. *
  438. * //output: window test();
  439. *
  440. * ```
  441. */
  442. bind: function(fn, context) {
  443. return function() {
  444. return fn.apply(context, arguments);
  445. };
  446. },
  447. /**
  448. * 创建延迟指定时间后执行的函数fn
  449. *
  450. * @method defer
  451. * @param {
  452. * Function } fn 需要延迟执行的函数对象
  453. * @param {
  454. * int } delay 延迟的时间, 单位是毫秒
  455. * @warning 该方法的时间控制是不精确的,仅仅只能保证函数的执行是在给定的时间之后, 而不能保证刚好到达延迟时间时执行。
  456. * @return { Function } 目标函数fn的代理函数, 只有执行该函数才能起到延时效果
  457. * @example ```javascript var start = 0;
  458. *
  459. * function test(){ console.log( new Date() - start ); }
  460. *
  461. * var testDefer = UE.utils.defer( test, 1000 ); // start = new Date();
  462. * //output: (大约在1000毫秒之后输出) 1000 testDefer(); ```
  463. */
  464. /**
  465. * 创建延迟指定时间后执行的函数fn, 如果在延迟时间内再次执行该方法, 将会根据指定的exclusion的值,
  466. * 决定是否取消前一次函数的执行, 如果exclusion的值为true, 则取消执行,反之,将继续执行前一个方法。
  467. *
  468. * @method defer
  469. * @param {
  470. * Function } fn 需要延迟执行的函数对象
  471. * @param {
  472. * int } delay 延迟的时间, 单位是毫秒
  473. * @param {
  474. * Boolean } exclusion 如果在延迟时间内再次执行该函数,该值将决定是否取消执行前一次函数的执行,
  475. * 值为true表示取消执行, 反之则将在执行前一次函数之后才执行本次函数调用。
  476. * @warning 该方法的时间控制是不精确的,仅仅只能保证函数的执行是在给定的时间之后, 而不能保证刚好到达延迟时间时执行。
  477. * @return { Function } 目标函数fn的代理函数, 只有执行该函数才能起到延时效果
  478. * @example ```javascript
  479. *
  480. * function test(){ console.log(1); }
  481. *
  482. * var testDefer = UE.utils.defer( test, 1000, true );
  483. *
  484. * //output: (两次调用仅有一次输出) 1 testDefer(); testDefer(); ```
  485. */
  486. defer: function(fn, delay, exclusion) {
  487. var timerID;
  488. return function() {
  489. if(exclusion) {
  490. clearTimeout(timerID);
  491. }
  492. timerID = setTimeout(fn, delay);
  493. };
  494. },
  495. /**
  496. * 获取元素item在数组array中首次出现的位置, 如果未找到item, 则返回-1
  497. *
  498. * @method indexOf
  499. * @remind 该方法的匹配过程使用的是恒等“===”
  500. * @param {
  501. * Array } array 需要查找的数组对象
  502. * @param { * }
  503. * item 需要在目标数组中查找的值
  504. * @return { int } 返回item在目标数组array中首次出现的位置, 如果在数组中未找到item, 则返回-1
  505. * @example ```javascript var item = 1, arr = [ 3, 4, 6, 8, 1, 1, 2 ];
  506. *
  507. * //output: 4 console.log( UE.utils.indexOf( arr, item ) ); ```
  508. */
  509. /**
  510. * 获取元素item数组array中首次出现的位置, 如果未找到item, 则返回-1。通过start的值可以指定搜索的起始位置。
  511. *
  512. * @method indexOf
  513. * @remind 该方法的匹配过程使用的是恒等“===”
  514. * @param {
  515. * Array } array 需要查找的数组对象
  516. * @param { * }
  517. * item 需要在目标数组中查找的值
  518. * @param {
  519. * int } start 搜索的起始位置
  520. * @return { int } 返回item在目标数组array中的start位置之后首次出现的位置, 如果在数组中未找到item,
  521. * 则返回-1
  522. * @example ```javascript var item = 1, arr = [ 3, 4, 6, 8, 1, 2, 8, 3,
  523. * 2, 1, 1, 4 ];
  524. *
  525. * //output: 9 console.log( UE.utils.indexOf( arr, item, 5 ) ); ```
  526. */
  527. indexOf: function(array, item, start) {
  528. var index = -1;
  529. start = this.isNumber(start) ? start : 0;
  530. this.each(array, function(v, i) {
  531. if(i >= start && v === item) {
  532. index = i;
  533. return false;
  534. }
  535. });
  536. return index;
  537. },
  538. /**
  539. * 移除数组array中所有的元素item
  540. *
  541. * @method removeItem
  542. * @param {
  543. * Array } array 要移除元素的目标数组
  544. * @param { * }
  545. * item 将要被移除的元素
  546. * @remind 该方法的匹配过程使用的是恒等“===”
  547. * @example ```javascript var arr = [ 4, 5, 7, 1, 3, 4, 6 ];
  548. *
  549. * UE.utils.removeItem( arr, 4 ); //output: [ 5, 7, 1, 3, 6 ]
  550. * console.log( arr );
  551. *
  552. * ```
  553. */
  554. removeItem: function(array, item) {
  555. for(var i = 0, l = array.length; i < l; i++) {
  556. if(array[i] === item) {
  557. array.splice(i, 1);
  558. i--;
  559. }
  560. }
  561. },
  562. /**
  563. * 删除字符串str的首尾空格
  564. *
  565. * @method trim
  566. * @param {
  567. * String } str 需要删除首尾空格的字符串
  568. * @return { String } 删除了首尾的空格后的字符串
  569. * @example ```javascript
  570. *
  571. * var str = " UEdtior ";
  572. *
  573. * //output: 9 console.log( str.length );
  574. *
  575. * //output: 7 console.log( UE.utils.trim( " UEdtior " ).length );
  576. *
  577. * //output: 9 console.log( str.length );
  578. *
  579. * ```
  580. */
  581. trim: function(str) {
  582. return str.replace(/(^[ \t\n\r]+)|([ \t\n\r]+$)/g, '');
  583. },
  584. /**
  585. * 将字符串str以','分隔成数组后,将该数组转换成哈希对象, 其生成的hash对象的key为数组中的元素, value为1
  586. *
  587. * @method listToMap
  588. * @warning 该方法在生成的hash对象中,会为每一个key同时生成一个另一个全大写的key。
  589. * @param {
  590. * String } str 该字符串将被以','分割为数组, 然后进行转化
  591. * @return { Object } 转化之后的hash对象
  592. * @example ```javascript
  593. *
  594. * //output: Object {UEdtior: 1, UEDTIOR: 1, Hello: 1, HELLO: 1}
  595. * console.log( UE.utils.listToMap( 'UEdtior,Hello' ) );
  596. *
  597. * ```
  598. */
  599. /**
  600. * 将字符串数组转换成哈希对象, 其生成的hash对象的key为数组中的元素, value为1
  601. *
  602. * @method listToMap
  603. * @warning 该方法在生成的hash对象中,会为每一个key同时生成一个另一个全大写的key。
  604. * @param {
  605. * Array } arr 字符串数组
  606. * @return { Object } 转化之后的hash对象
  607. * @example ```javascript
  608. *
  609. * //output: Object {UEdtior: 1, UEDTIOR: 1, Hello: 1, HELLO: 1}
  610. * console.log( UE.utils.listToMap( [ 'UEdtior', 'Hello' ] ) );
  611. *
  612. * ```
  613. */
  614. listToMap: function(list) {
  615. if(!list)
  616. return {};
  617. list = utils.isArray(list) ? list : list.split(',');
  618. for(var i = 0, ci, obj = {}; ci = list[i++];) {
  619. obj[ci.toUpperCase()] = obj[ci] = 1;
  620. }
  621. return obj;
  622. },
  623. /**
  624. * 将str中的html符号转义,将转义“',&,<,",>”五个字符
  625. *
  626. * @method unhtml
  627. * @param {
  628. * String } str 需要转义的字符串
  629. * @return { String } 转义后的字符串
  630. * @example ```javascript var html = '<body>&</body>';
  631. *
  632. * //output: &lt;body&gt;&amp;&lt;/body&gt; console.log(
  633. * UE.utils.unhtml( html ) );
  634. *
  635. * ```
  636. */
  637. unhtml: function(str, reg) {
  638. return str ? str.replace(reg ||
  639. /[&<">'](?:(amp|lt|quot|gt|#39|nbsp|#\d+);)?/g,
  640. function(a, b) {
  641. if(b) {
  642. return a;
  643. } else {
  644. return {
  645. '<': '&lt;',
  646. '&': '&amp;',
  647. '"': '&quot;',
  648. '>': '&gt;',
  649. "'": '&#39;'
  650. }[a]
  651. }
  652. }) : '';
  653. },
  654. /**
  655. * 将str中的转义字符还原成html字符
  656. *
  657. * @see UE.utils.unhtml(String);
  658. * @method html
  659. * @param {
  660. * String } str 需要逆转义的字符串
  661. * @return { String } 逆转义后的字符串
  662. * @example ```javascript
  663. *
  664. * var str = '&lt;body&gt;&amp;&lt;/body&gt;';
  665. *
  666. * //output: <body>&</body> console.log( UE.utils.html( str ) );
  667. *
  668. * ```
  669. */
  670. html: function(str) {
  671. return str ? str.replace(/&((g|l|quo)t|amp|#39|nbsp);/g,
  672. function(m) {
  673. return {
  674. '&lt;': '<',
  675. '&amp;': '&',
  676. '&quot;': '"',
  677. '&gt;': '>',
  678. '&#39;': "'",
  679. '&nbsp;': ' '
  680. }[m]
  681. }) : '';
  682. },
  683. /**
  684. * 将css样式转换为驼峰的形式
  685. *
  686. * @method cssStyleToDomStyle
  687. * @param {
  688. * String } cssName 需要转换的css样式名
  689. * @return { String } 转换成驼峰形式后的css样式名
  690. * @example ```javascript
  691. *
  692. * var str = 'border-top';
  693. *
  694. * //output: borderTop console.log( UE.utils.cssStyleToDomStyle( str ) );
  695. *
  696. * ```
  697. */
  698. cssStyleToDomStyle: function() {
  699. var test = document.createElement('div').style,
  700. cache = {
  701. 'float': test.cssFloat != undefined ?
  702. 'cssFloat' : test.styleFloat != undefined ? 'styleFloat' : 'float'
  703. };
  704. return function(cssName) {
  705. return cache[cssName] ||
  706. (cache[cssName] = cssName.toLowerCase().replace(
  707. /-./g,
  708. function(match) {
  709. return match.charAt(1).toUpperCase();
  710. }));
  711. };
  712. }(),
  713. /**
  714. * 动态加载文件到doc中
  715. *
  716. * @method loadFile
  717. * @param {
  718. * DomDocument } document 需要加载资源文件的文档对象
  719. * @param {
  720. * Object } options 加载资源文件的属性集合, 取值请参考代码示例
  721. * @example ```javascript
  722. *
  723. * UE.utils.loadFile( document, { src:"test.js", tag:"script",
  724. * type:"text/javascript", defer:"defer" } );
  725. *
  726. * ```
  727. */
  728. /**
  729. * 动态加载文件到doc中,加载成功后执行的回调函数fn
  730. *
  731. * @method loadFile
  732. * @param {
  733. * DomDocument } document 需要加载资源文件的文档对象
  734. * @param {
  735. * Object } options 加载资源文件的属性集合,
  736. * 该集合支持的值是script标签和style标签支持的所有属性。
  737. * @param {
  738. * Function } fn 资源文件加载成功之后执行的回调
  739. * @warning 对于在同一个文档中多次加载同一URL的文件, 该方法会在第一次加载之后缓存该请求, 在此之后的所有同一URL的请求,
  740. * 将会直接触发回调。
  741. * @example ```javascript
  742. *
  743. * UE.utils.loadFile( document, { src:"test.js", tag:"script",
  744. * type:"text/javascript", defer:"defer" }, function () {
  745. * console.log('加载成功'); } );
  746. *
  747. * ```
  748. */
  749. loadFile: function() {
  750. var tmpList = [];
  751. function getItem(doc, obj) {
  752. try {
  753. for(var i = 0, ci; ci = tmpList[i++];) {
  754. if(ci.doc === doc && ci.url == (obj.src || obj.href)) {
  755. return ci;
  756. }
  757. }
  758. } catch(e) {
  759. return null;
  760. }
  761. }
  762. return function(doc, obj, fn) {
  763. var item = getItem(doc, obj);
  764. if(item) {
  765. if(item.ready) {
  766. fn && fn();
  767. } else {
  768. item.funs.push(fn)
  769. }
  770. return;
  771. }
  772. tmpList.push({
  773. doc: doc,
  774. url: obj.src || obj.href,
  775. funs: [fn]
  776. });
  777. if(!doc.body) {
  778. var html = [];
  779. for(var p in obj) {
  780. if(p == 'tag')
  781. continue;
  782. html.push(p + '="' + obj[p] + '"')
  783. }
  784. doc.write('<' + obj.tag + ' ' + html.join(' ') + ' ></' +
  785. obj.tag + '>');
  786. return;
  787. }
  788. if(obj.id && doc.getElementById(obj.id)) {
  789. return;
  790. }
  791. var element = doc.createElement(obj.tag);
  792. delete obj.tag;
  793. for(var p in obj) {
  794. element.setAttribute(p, obj[p]);
  795. }
  796. element.onload = element.onreadystatechange = function() {
  797. if(!this.readyState ||
  798. /loaded|complete/.test(this.readyState)) {
  799. item = getItem(doc, obj);
  800. if(item.funs.length > 0) {
  801. item.ready = 1;
  802. for(var fi; fi = item.funs.pop();) {
  803. fi();
  804. }
  805. }
  806. element.onload = element.onreadystatechange = null;
  807. }
  808. };
  809. element.onerror = function() {
  810. throw Error('The load ' +
  811. (obj.href || obj.src) +
  812. ' fails,check the url settings of file ueditor.config.js ')
  813. };
  814. doc.getElementsByTagName("head")[0].appendChild(element);
  815. }
  816. }(),
  817. /**
  818. * 判断obj对象是否为空
  819. *
  820. * @method isEmptyObject
  821. * @param { * }
  822. * obj 需要判断的对象
  823. * @remind 如果判断的对象是NULL, 将直接返回true, 如果是数组且为空, 返回true, 如果是字符串, 且字符串为空,
  824. * 返回true, 如果是普通对象, 且该对象没有任何实例属性, 返回true
  825. * @return { Boolean } 对象是否为空
  826. * @example ```javascript
  827. *
  828. * //output: true console.log( UE.utils.isEmptyObject( {} ) );
  829. *
  830. * //output: true console.log( UE.utils.isEmptyObject( [] ) );
  831. *
  832. * //output: true console.log( UE.utils.isEmptyObject( "" ) );
  833. *
  834. * //output: false console.log( UE.utils.isEmptyObject( { key: 1 } ) );
  835. *
  836. * //output: false console.log( UE.utils.isEmptyObject( [1] ) );
  837. *
  838. * //output: false console.log( UE.utils.isEmptyObject( "1" ) );
  839. *
  840. * ```
  841. */
  842. isEmptyObject: function(obj) {
  843. if(obj == null)
  844. return true;
  845. if(this.isArray(obj) || this.isString(obj))
  846. return obj.length === 0;
  847. for(var key in obj)
  848. if(obj.hasOwnProperty(key))
  849. return false;
  850. return true;
  851. },
  852. /**
  853. * 把rgb格式的颜色值转换成16进制格式
  854. *
  855. * @method fixColor
  856. * @param {
  857. * String } rgb格式的颜色值
  858. * @param {
  859. * String }
  860. * @example rgb(255,255,255) => "#ffffff"
  861. */
  862. fixColor: function(name, value) {
  863. if(/color/i.test(name) && /rgba?/.test(value)) {
  864. var array = value.split(",");
  865. if(array.length > 3)
  866. return "";
  867. value = "#";
  868. for(var i = 0, color; color = array[i++];) {
  869. color = parseInt(color.replace(/[^\d]/gi, ''), 10)
  870. .toString(16);
  871. value += color.length == 1 ? "0" + color : color;
  872. }
  873. value = value.toUpperCase();
  874. }
  875. return value;
  876. },
  877. /**
  878. * 只针对border,padding,margin做了处理,因为性能问题
  879. *
  880. * @public
  881. * @function
  882. * @param {String}
  883. * val style字符串
  884. */
  885. optCss: function(val) {
  886. var padding, margin, border;
  887. val = val.replace(/(padding|margin|border)\-([^:]+):([^;]+);?/gi,
  888. function(str, key, name, val) {
  889. if(val.split(' ').length == 1) {
  890. switch(key) {
  891. case 'padding':
  892. !padding && (padding = {});
  893. padding[name] = val;
  894. return '';
  895. case 'margin':
  896. !margin && (margin = {});
  897. margin[name] = val;
  898. return '';
  899. case 'border':
  900. return val == 'initial' ? '' : str;
  901. }
  902. }
  903. return str;
  904. });
  905. function opt(obj, name) {
  906. if(!obj) {
  907. return '';
  908. }
  909. var t = obj.top,
  910. b = obj.bottom,
  911. l = obj.left,
  912. r = obj.right,
  913. val = '';
  914. if(!t || !l || !b || !r) {
  915. for(var p in obj) {
  916. val += ';' + name + '-' + p + ':' + obj[p] + ';';
  917. }
  918. } else {
  919. val += ';' +
  920. name +
  921. ':' +
  922. (t == b && b == l && l == r ? t : t == b &&
  923. l == r ? (t + ' ' + l) : l == r ? (t +
  924. ' ' + l + ' ' + b) : (t + ' ' + r + ' ' +
  925. b + ' ' + l)) + ';'
  926. }
  927. return val;
  928. }
  929. val += opt(padding, 'padding') + opt(margin, 'margin');
  930. return val.replace(/^[ \n\r\t;]*|[ \n\r\t]*$/, '').replace(
  931. /;([ \n\r\t]+)|\1;/g, ';').replace(
  932. /(&((l|g)t|quot|#39))?;{2,}/g,
  933. function(a, b) {
  934. return b ? b + ";;" : ';'
  935. });
  936. },
  937. /**
  938. * 克隆对象
  939. *
  940. * @method clone
  941. * @param {
  942. * Object } source 源对象
  943. * @return { Object } source的一个副本
  944. */
  945. /**
  946. * 深度克隆对象,将source的属性克隆到target对象, 会覆盖target重名的属性。
  947. *
  948. * @method clone
  949. * @param {
  950. * Object } source 源对象
  951. * @param {
  952. * Object } target 目标对象
  953. * @return { Object } 附加了source对象所有属性的target对象
  954. */
  955. clone: function(source, target) {
  956. var tmp;
  957. target = target || {};
  958. for(var i in source) {
  959. if(source.hasOwnProperty(i)) {
  960. tmp = source[i];
  961. if(typeof tmp == 'object') {
  962. target[i] = utils.isArray(tmp) ? [] : {};
  963. utils.clone(source[i], target[i])
  964. } else {
  965. target[i] = tmp;
  966. }
  967. }
  968. }
  969. return target;
  970. },
  971. /**
  972. * 把cm/pt为单位的值转换为px为单位的值
  973. *
  974. * @method transUnitToPx
  975. * @param {
  976. * String } 待转换的带单位的字符串
  977. * @return { String } 转换为px为计量单位的值的字符串
  978. * @example ```javascript
  979. *
  980. * //output: 500px console.log( UE.utils.transUnitToPx( '20cm' ) );
  981. *
  982. * //output: 27px console.log( UE.utils.transUnitToPx( '20pt' ) );
  983. *
  984. * ```
  985. */
  986. transUnitToPx: function(val) {
  987. if(!/(pt|cm)/.test(val)) {
  988. return val
  989. }
  990. var unit;
  991. val.replace(/([\d.]+)(\w+)/, function(str, v, u) {
  992. val = v;
  993. unit = u;
  994. });
  995. switch(unit) {
  996. case 'cm':
  997. val = parseFloat(val) * 25;
  998. break;
  999. case 'pt':
  1000. val = Math.round(parseFloat(val) * 96 / 72);
  1001. }
  1002. return val + (val ? 'px' : '');
  1003. },
  1004. /**
  1005. * 在dom树ready之后执行给定的回调函数
  1006. *
  1007. * @method domReady
  1008. * @remind 如果在执行该方法的时候, dom树已经ready, 那么回调函数将立刻执行
  1009. * @param {
  1010. * Function } fn dom树ready之后的回调函数
  1011. * @example ```javascript
  1012. *
  1013. * UE.utils.domReady( function () {
  1014. *
  1015. * console.log('123'); } );
  1016. *
  1017. * ```
  1018. */
  1019. domReady: function() {
  1020. var fnArr = [];
  1021. function doReady(doc) {
  1022. // 确保onready只执行一次
  1023. doc.isReady = true;
  1024. for(var ci; ci = fnArr.pop(); ci()) {}
  1025. }
  1026. return function(onready, win) {
  1027. win = win || window;
  1028. var doc = win.document;
  1029. onready && fnArr.push(onready);
  1030. if(doc.readyState === "complete") {
  1031. doReady(doc);
  1032. } else {
  1033. doc.isReady && doReady(doc);
  1034. if(browser.ie && browser.version != 11) {
  1035. (function() {
  1036. if(doc.isReady)
  1037. return;
  1038. try {
  1039. doc.documentElement.doScroll("left");
  1040. } catch(error) {
  1041. setTimeout(arguments.callee, 0);
  1042. return;
  1043. }
  1044. doReady(doc);
  1045. })();
  1046. win.attachEvent('onload', function() {
  1047. doReady(doc)
  1048. });
  1049. } else {
  1050. doc.addEventListener("DOMContentLoaded", function() {
  1051. doc.removeEventListener("DOMContentLoaded",
  1052. arguments.callee, false);
  1053. doReady(doc);
  1054. }, false);
  1055. win.addEventListener('load', function() {
  1056. doReady(doc)
  1057. }, false);
  1058. }
  1059. }
  1060. }
  1061. }(),
  1062. /**
  1063. * 动态添加css样式
  1064. *
  1065. * @method cssRule
  1066. * @param {
  1067. * String } 节点名称
  1068. * @grammar UE.utils.cssRule('添加的样式的节点名称',['样式','放到哪个document上'])
  1069. * @grammar UE.utils.cssRule('body','body{background:#ccc}') => null
  1070. * //给body添加背景颜色
  1071. * @grammar UE.utils.cssRule('body') =>样式的字符串
  1072. * //取得key值为body的样式的内容,如果没有找到key值先关的样式将返回空,例如刚才那个背景颜色,将返回
  1073. * body{background:#ccc}
  1074. * @grammar UE.utils.cssRule('body',document) =>
  1075. * 返回指定key的样式,并且指定是哪个document
  1076. * @grammar UE.utils.cssRule('body','') =>null //清空给定的key值的背景颜色
  1077. */
  1078. cssRule: browser.ie && browser.version != 11 ? function(key, style,
  1079. doc) {
  1080. var indexList, index;
  1081. if(style === undefined || style && style.nodeType &&
  1082. style.nodeType == 9) {
  1083. // 获取样式
  1084. doc = style && style.nodeType && style.nodeType == 9 ?
  1085. style :
  1086. (doc || document);
  1087. indexList = doc.indexList || (doc.indexList = {});
  1088. index = indexList[key];
  1089. if(index !== undefined) {
  1090. return doc.styleSheets[index].cssText
  1091. }
  1092. return undefined;
  1093. }
  1094. doc = doc || document;
  1095. indexList = doc.indexList || (doc.indexList = {});
  1096. index = indexList[key];
  1097. // 清除样式
  1098. if(style === '') {
  1099. if(index !== undefined) {
  1100. doc.styleSheets[index].cssText = '';
  1101. delete indexList[key];
  1102. return true
  1103. }
  1104. return false;
  1105. }
  1106. // 添加样式
  1107. if(index !== undefined) {
  1108. sheetStyle = doc.styleSheets[index];
  1109. } else {
  1110. sheetStyle = doc.createStyleSheet('',
  1111. index = doc.styleSheets.length);
  1112. indexList[key] = index;
  1113. }
  1114. sheetStyle.cssText = style;
  1115. } : function(key, style, doc) {
  1116. var head, node;
  1117. if(style === undefined || style && style.nodeType &&
  1118. style.nodeType == 9) {
  1119. // 获取样式
  1120. doc = style && style.nodeType && style.nodeType == 9 ?
  1121. style :
  1122. (doc || document);
  1123. node = doc.getElementById(key);
  1124. return node ? node.innerHTML : undefined;
  1125. }
  1126. doc = doc || document;
  1127. node = doc.getElementById(key);
  1128. // 清除样式
  1129. if(style === '') {
  1130. if(node) {
  1131. node.parentNode.removeChild(node);
  1132. return true
  1133. }
  1134. return false;
  1135. }
  1136. // 添加样式
  1137. if(node) {
  1138. node.innerHTML = style;
  1139. } else {
  1140. node = doc.createElement('style');
  1141. node.id = key;
  1142. node.innerHTML = style;
  1143. doc.getElementsByTagName('head')[0].appendChild(node);
  1144. }
  1145. },
  1146. sort: function(array, compareFn) {
  1147. compareFn = compareFn || function(item1, item2) {
  1148. return item1.localeCompare(item2);
  1149. };
  1150. for(var i = 0, len = array.length; i < len; i++) {
  1151. for(var j = i, length = array.length; j < length; j++) {
  1152. if(compareFn(array[i], array[j]) > 0) {
  1153. var t = array[i];
  1154. array[i] = array[j];
  1155. array[j] = t;
  1156. }
  1157. }
  1158. }
  1159. return array;
  1160. },
  1161. serializeParam: function(json) {
  1162. var strArr = [];
  1163. for(var i in json) {
  1164. // 忽略默认的几个参数
  1165. if(i == "method" || i == "timeout" || i == "async")
  1166. continue;
  1167. // 传递过来的对象和函数不在提交之列
  1168. if(!((typeof json[i]).toLowerCase() == "function" || (typeof json[i])
  1169. .toLowerCase() == "object")) {
  1170. strArr.push(encodeURIComponent(i) + "=" +
  1171. encodeURIComponent(json[i]));
  1172. } else if(utils.isArray(json[i])) {
  1173. // 支持传数组内容
  1174. for(var j = 0; j < json[i].length; j++) {
  1175. strArr.push(encodeURIComponent(i) + "[]=" +
  1176. encodeURIComponent(json[i][j]));
  1177. }
  1178. }
  1179. }
  1180. return strArr.join("&");
  1181. },
  1182. formatUrl: function(url) {
  1183. var u = url.replace(/&&/g, '&');
  1184. u = u.replace(/\?&/g, '?');
  1185. u = u.replace(/&$/g, '');
  1186. u = u.replace(/&#/g, '#');
  1187. u = u.replace(/&+/g, '&');
  1188. return u;
  1189. },
  1190. isCrossDomainUrl: function(url) {
  1191. var a = document.createElement('a');
  1192. a.href = url;
  1193. if(browser.ie) {
  1194. a.href = a.href;
  1195. }
  1196. return !(a.protocol == location.protocol &&
  1197. a.hostname == location.hostname && (a.port == location.port ||
  1198. (a.port == '80' && location.port == '') || (a.port == '' && location.port == '80')));
  1199. },
  1200. clearEmptyAttrs: function(obj) {
  1201. for(var p in obj) {
  1202. if(obj[p] === '') {
  1203. delete obj[p]
  1204. }
  1205. }
  1206. return obj;
  1207. },
  1208. str2json: function(s) {
  1209. if(!utils.isString(s))
  1210. return null;
  1211. if(window.JSON) {
  1212. return JSON.parse(s);
  1213. } else {
  1214. return(new Function("return " + utils.trim(s || '')))();
  1215. }
  1216. },
  1217. json2str: (function() {
  1218. if(window.JSON) {
  1219. return JSON.stringify;
  1220. } else {
  1221. var escapeMap = {
  1222. "\b": '\\b',
  1223. "\t": '\\t',
  1224. "\n": '\\n',
  1225. "\f": '\\f',
  1226. "\r": '\\r',
  1227. '"': '\\"',
  1228. "\\": '\\\\'
  1229. };
  1230. function encodeString(source) {
  1231. if(/["\\\x00-\x1f]/.test(source)) {
  1232. source = source.replace(/["\\\x00-\x1f]/g, function(
  1233. match) {
  1234. var c = escapeMap[match];
  1235. if(c) {
  1236. return c;
  1237. }
  1238. c = match.charCodeAt();
  1239. return "\\u00" + Math.floor(c / 16).toString(16) +
  1240. (c % 16).toString(16);
  1241. });
  1242. }
  1243. return '"' + source + '"';
  1244. }
  1245. function encodeArray(source) {
  1246. var result = ["["],
  1247. l = source.length,
  1248. preComma, i, item;
  1249. for(i = 0; i < l; i++) {
  1250. item = source[i];
  1251. switch(typeof item) {
  1252. case "undefined":
  1253. case "function":
  1254. case "unknown":
  1255. break;
  1256. default:
  1257. if(preComma) {
  1258. result.push(',');
  1259. }
  1260. result.push(utils.json2str(item));
  1261. preComma = 1;
  1262. }
  1263. }
  1264. result.push("]");
  1265. return result.join("");
  1266. }
  1267. function pad(source) {
  1268. return source < 10 ? '0' + source : source;
  1269. }
  1270. function encodeDate(source) {
  1271. return '"' + source.getFullYear() + "-" +
  1272. pad(source.getMonth() + 1) + "-" +
  1273. pad(source.getDate()) + "T" +
  1274. pad(source.getHours()) + ":" +
  1275. pad(source.getMinutes()) + ":" +
  1276. pad(source.getSeconds()) + '"';
  1277. }
  1278. return function(value) {
  1279. switch(typeof value) {
  1280. case 'undefined':
  1281. return 'undefined';
  1282. case 'number':
  1283. return isFinite(value) ? String(value) : "null";
  1284. case 'string':
  1285. return encodeString(value);
  1286. case 'boolean':
  1287. return String(value);
  1288. default:
  1289. if(value === null) {
  1290. return 'null';
  1291. } else if(utils.isArray(value)) {
  1292. return encodeArray(value);
  1293. } else if(utils.isDate(value)) {
  1294. return encodeDate(value);
  1295. } else {
  1296. var result = ['{'],
  1297. encode = utils.json2str,
  1298. preComma, item;
  1299. for(var key in value) {
  1300. if(Object.prototype.hasOwnProperty.call(
  1301. value, key)) {
  1302. item = value[key];
  1303. switch(typeof item) {
  1304. case 'undefined':
  1305. case 'unknown':
  1306. case 'function':
  1307. break;
  1308. default:
  1309. if(preComma) {
  1310. result.push(',');
  1311. }
  1312. preComma = 1;
  1313. result.push(encode(key) + ':' +
  1314. encode(item));
  1315. }
  1316. }
  1317. }
  1318. result.push('}');
  1319. return result.join('');
  1320. }
  1321. }
  1322. };
  1323. }
  1324. })()
  1325. };
  1326. /**
  1327. * 判断给定的对象是否是字符串
  1328. *
  1329. * @method isString
  1330. * @param { * }
  1331. * object 需要判断的对象
  1332. * @return { Boolean } 给定的对象是否是字符串
  1333. */
  1334. /**
  1335. * 判断给定的对象是否是数组
  1336. *
  1337. * @method isArray
  1338. * @param { * }
  1339. * object 需要判断的对象
  1340. * @return { Boolean } 给定的对象是否是数组
  1341. */
  1342. /**
  1343. * 判断给定的对象是否是一个Function
  1344. *
  1345. * @method isFunction
  1346. * @param { * }
  1347. * object 需要判断的对象
  1348. * @return { Boolean } 给定的对象是否是Function
  1349. */
  1350. /**
  1351. * 判断给定的对象是否是Number
  1352. *
  1353. * @method isNumber
  1354. * @param { * }
  1355. * object 需要判断的对象
  1356. * @return { Boolean } 给定的对象是否是Number
  1357. */
  1358. /**
  1359. * 判断给定的对象是否是一个正则表达式
  1360. *
  1361. * @method isRegExp
  1362. * @param { * }
  1363. * object 需要判断的对象
  1364. * @return { Boolean } 给定的对象是否是正则表达式
  1365. */
  1366. /**
  1367. * 判断给定的对象是否是一个普通对象
  1368. *
  1369. * @method isObject
  1370. * @param { * }
  1371. * object 需要判断的对象
  1372. * @return { Boolean } 给定的对象是否是普通对象
  1373. */
  1374. utils.each(['String', 'Function', 'Array', 'Number', 'RegExp', 'Object',
  1375. 'Date'
  1376. ], function(v) {
  1377. UE.utils['is' + v] = function(obj) {
  1378. return Object.prototype.toString.apply(obj) == '[object ' + v + ']';
  1379. }
  1380. });
  1381. // core/EventBase.js
  1382. /**
  1383. * UE采用的事件基类
  1384. *
  1385. * @file
  1386. * @module UE
  1387. * @class EventBase
  1388. * @since 1.2.6.1
  1389. */
  1390. /**
  1391. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  1392. *
  1393. * @unfile
  1394. * @module UE
  1395. */
  1396. /**
  1397. * UE采用的事件基类,继承此类的对应类将获取addListener,removeListener,fireEvent方法。
  1398. * 在UE中,Editor以及所有ui实例都继承了该类,故可以在对应的ui对象以及editor对象上使用上述方法。
  1399. *
  1400. * @unfile
  1401. * @module UE
  1402. * @class EventBase
  1403. */
  1404. /**
  1405. * 通过此构造器,子类可以继承EventBase获取事件监听的方法
  1406. *
  1407. * @constructor
  1408. * @example ```javascript UE.EventBase.call(editor); ```
  1409. */
  1410. var EventBase = UE.EventBase = function() {};
  1411. EventBase.prototype = {
  1412. /**
  1413. * 注册事件监听器
  1414. *
  1415. * @method addListener
  1416. * @param {
  1417. * String } types 监听的事件名称,同时监听多个事件使用空格分隔
  1418. * @param {
  1419. * Function } fn 监听的事件被触发时,会执行该回调函数
  1420. * @waining 事件被触发时,监听的函数假如返回的值恒等于true,回调函数的队列中后面的函数将不执行
  1421. * @example ```javascript
  1422. * editor.addListener('selectionchange',function(){
  1423. * console.log("选区已经变化!"); })
  1424. * editor.addListener('beforegetcontent
  1425. * aftergetcontent',function(type){ if(type ==
  1426. * 'beforegetcontent'){ //do something }else{ //do something }
  1427. * console.log(this.getContent) // this是注册的事件的编辑器实例 }) ```
  1428. * @see UE.EventBase:fireEvent(String)
  1429. */
  1430. addListener: function(types, listener) {
  1431. types = utils.trim(types).split(/\s+/);
  1432. for(var i = 0, ti; ti = types[i++];) {
  1433. getListener(this, ti, true).push(listener);
  1434. }
  1435. },
  1436. on: function(types, listener) {
  1437. return this.addListener(types, listener);
  1438. },
  1439. off: function(types, listener) {
  1440. return this.removeListener(types, listener)
  1441. },
  1442. trigger: function() {
  1443. return this.fireEvent.apply(this, arguments);
  1444. },
  1445. /**
  1446. * 移除事件监听器
  1447. *
  1448. * @method removeListener
  1449. * @param {
  1450. * String } types 移除的事件名称,同时移除多个事件使用空格分隔
  1451. * @param {
  1452. * Function } fn 移除监听事件的函数引用
  1453. * @example ```javascript //changeCallback为方法体
  1454. * editor.removeListener("selectionchange",changeCallback); ```
  1455. */
  1456. removeListener: function(types, listener) {
  1457. types = utils.trim(types).split(/\s+/);
  1458. for(var i = 0, ti; ti = types[i++];) {
  1459. utils.removeItem(getListener(this, ti) || [], listener);
  1460. }
  1461. },
  1462. /**
  1463. * 触发事件
  1464. *
  1465. * @method fireEvent
  1466. * @param {
  1467. * String } types 触发的事件名称,同时触发多个事件使用空格分隔
  1468. * @remind 该方法会触发addListener
  1469. * @return { * } 返回触发事件的队列中,最后执行的回调函数的返回值
  1470. * @example ```javascript editor.fireEvent("selectionchange"); ```
  1471. */
  1472. /**
  1473. * 触发事件
  1474. *
  1475. * @method fireEvent
  1476. * @param {
  1477. * String } types 触发的事件名称,同时触发多个事件使用空格分隔
  1478. * @param {
  1479. * *... } options 可选参数,可以传入一个或多个参数,会传给事件触发的回调函数
  1480. * @return { * } 返回触发事件的队列中,最后执行的回调函数的返回值
  1481. * @example ```javascript
  1482. *
  1483. * editor.addListener( "selectionchange", function ( type, arg1, arg2 ) {
  1484. *
  1485. * console.log( arg1 + " " + arg2 ); } );
  1486. *
  1487. * //触发selectionchange事件, 会执行上面的事件监听器 //output: Hello World
  1488. * editor.fireEvent("selectionchange", "Hello", "World"); ```
  1489. */
  1490. fireEvent: function() {
  1491. var types = arguments[0];
  1492. types = utils.trim(types).split(' ');
  1493. for(var i = 0, ti; ti = types[i++];) {
  1494. var listeners = getListener(this, ti),
  1495. r, t, k;
  1496. if(listeners) {
  1497. k = listeners.length;
  1498. while(k--) {
  1499. if(!listeners[k])
  1500. continue;
  1501. t = listeners[k].apply(this, arguments);
  1502. if(t === true) {
  1503. return t;
  1504. }
  1505. if(t !== undefined) {
  1506. r = t;
  1507. }
  1508. }
  1509. }
  1510. if(t = this['on' + ti.toLowerCase()]) {
  1511. r = t.apply(this, arguments);
  1512. }
  1513. }
  1514. return r;
  1515. }
  1516. };
  1517. /**
  1518. * 获得对象所拥有监听类型的所有监听器
  1519. *
  1520. * @unfile
  1521. * @module UE
  1522. * @since 1.2.6.1
  1523. * @method getListener
  1524. * @public
  1525. * @param {
  1526. * Object } obj 查询监听器的对象
  1527. * @param {
  1528. * String } type 事件类型
  1529. * @param {
  1530. * Boolean } force 为true且当前所有type类型的侦听器不存在时,创建一个空监听器数组
  1531. * @return { Array } 监听器数组
  1532. */
  1533. function getListener(obj, type, force) {
  1534. var allListeners;
  1535. type = type.toLowerCase();
  1536. return((allListeners = (obj.__allListeners || force &&
  1537. (obj.__allListeners = {}))) && (allListeners[type] || force &&
  1538. (allListeners[type] = [])));
  1539. }
  1540. // core/dtd.js
  1541. // /import editor.js
  1542. // /import core/dom/dom.js
  1543. // /import core/utils.js
  1544. /**
  1545. * dtd html语义化的体现类
  1546. *
  1547. * @constructor
  1548. * @namespace dtd
  1549. */
  1550. var dtd = dom.dtd = (function() {
  1551. function _(s) {
  1552. for(var k in s) {
  1553. s[k.toUpperCase()] = s[k];
  1554. }
  1555. return s;
  1556. }
  1557. var X = utils.extend2;
  1558. var A = _({
  1559. isindex: 1,
  1560. fieldset: 1
  1561. }),
  1562. B = _({
  1563. input: 1,
  1564. button: 1,
  1565. select: 1,
  1566. textarea: 1,
  1567. label: 1
  1568. }),
  1569. C = X(_({
  1570. a: 1
  1571. }), B),
  1572. D = X({
  1573. iframe: 1
  1574. }, C),
  1575. E = _({
  1576. hr: 1,
  1577. ul: 1,
  1578. menu: 1,
  1579. div: 1,
  1580. blockquote: 1,
  1581. noscript: 1,
  1582. table: 1,
  1583. center: 1,
  1584. address: 1,
  1585. dir: 1,
  1586. pre: 1,
  1587. h5: 1,
  1588. dl: 1,
  1589. h4: 1,
  1590. noframes: 1,
  1591. h6: 1,
  1592. ol: 1,
  1593. h1: 1,
  1594. h3: 1,
  1595. h2: 1
  1596. }),
  1597. F = _({
  1598. ins: 1,
  1599. del: 1,
  1600. script: 1,
  1601. style: 1
  1602. }),
  1603. G = X(_({
  1604. b: 1,
  1605. acronym: 1,
  1606. bdo: 1,
  1607. 'var': 1,
  1608. '#': 1,
  1609. abbr: 1,
  1610. code: 1,
  1611. br: 1,
  1612. i: 1,
  1613. cite: 1,
  1614. kbd: 1,
  1615. u: 1,
  1616. strike: 1,
  1617. s: 1,
  1618. tt: 1,
  1619. strong: 1,
  1620. q: 1,
  1621. samp: 1,
  1622. em: 1,
  1623. dfn: 1,
  1624. span: 1
  1625. }), F),
  1626. H = X(_({
  1627. sub: 1,
  1628. img: 1,
  1629. embed: 1,
  1630. object: 1,
  1631. sup: 1,
  1632. basefont: 1,
  1633. map: 1,
  1634. applet: 1,
  1635. font: 1,
  1636. big: 1,
  1637. small: 1
  1638. }), G),
  1639. I = X(_({
  1640. p: 1
  1641. }), H),
  1642. J = X(_({
  1643. iframe: 1
  1644. }), H, B),
  1645. K = _({
  1646. img: 1,
  1647. embed: 1,
  1648. noscript: 1,
  1649. br: 1,
  1650. kbd: 1,
  1651. center: 1,
  1652. button: 1,
  1653. basefont: 1,
  1654. h5: 1,
  1655. h4: 1,
  1656. samp: 1,
  1657. h6: 1,
  1658. ol: 1,
  1659. h1: 1,
  1660. h3: 1,
  1661. h2: 1,
  1662. form: 1,
  1663. font: 1,
  1664. '#': 1,
  1665. select: 1,
  1666. menu: 1,
  1667. ins: 1,
  1668. abbr: 1,
  1669. label: 1,
  1670. code: 1,
  1671. table: 1,
  1672. script: 1,
  1673. cite: 1,
  1674. input: 1,
  1675. iframe: 1,
  1676. strong: 1,
  1677. textarea: 1,
  1678. noframes: 1,
  1679. big: 1,
  1680. small: 1,
  1681. span: 1,
  1682. hr: 1,
  1683. sub: 1,
  1684. bdo: 1,
  1685. 'var': 1,
  1686. div: 1,
  1687. object: 1,
  1688. sup: 1,
  1689. strike: 1,
  1690. dir: 1,
  1691. map: 1,
  1692. dl: 1,
  1693. applet: 1,
  1694. del: 1,
  1695. isindex: 1,
  1696. fieldset: 1,
  1697. ul: 1,
  1698. b: 1,
  1699. acronym: 1,
  1700. a: 1,
  1701. blockquote: 1,
  1702. i: 1,
  1703. u: 1,
  1704. s: 1,
  1705. tt: 1,
  1706. address: 1,
  1707. q: 1,
  1708. pre: 1,
  1709. p: 1,
  1710. em: 1,
  1711. dfn: 1
  1712. }),
  1713. L = X(_({
  1714. a: 0
  1715. }), J), // a不能被切开,所以把他
  1716. M = _({
  1717. tr: 1
  1718. }),
  1719. N = _({
  1720. '#': 1
  1721. }),
  1722. O = X(_({
  1723. param: 1
  1724. }), K),
  1725. P = X(_({
  1726. form: 1
  1727. }), A, D, E, I),
  1728. Q = _({
  1729. li: 1,
  1730. ol: 1,
  1731. ul: 1
  1732. }),
  1733. R = _({
  1734. style: 1,
  1735. script: 1
  1736. }),
  1737. S = _({
  1738. base: 1,
  1739. link: 1,
  1740. meta: 1,
  1741. title: 1
  1742. }),
  1743. T = X(S, R),
  1744. U = _({
  1745. head: 1,
  1746. body: 1
  1747. }),
  1748. V = _({
  1749. html: 1
  1750. });
  1751. var block = _({
  1752. address: 1,
  1753. blockquote: 1,
  1754. center: 1,
  1755. dir: 1,
  1756. div: 1,
  1757. dl: 1,
  1758. fieldset: 1,
  1759. form: 1,
  1760. h1: 1,
  1761. h2: 1,
  1762. h3: 1,
  1763. h4: 1,
  1764. h5: 1,
  1765. h6: 1,
  1766. hr: 1,
  1767. isindex: 1,
  1768. menu: 1,
  1769. noframes: 1,
  1770. ol: 1,
  1771. p: 1,
  1772. pre: 1,
  1773. table: 1,
  1774. ul: 1
  1775. }),
  1776. empty = _({
  1777. area: 1,
  1778. base: 1,
  1779. basefont: 1,
  1780. br: 1,
  1781. col: 1,
  1782. command: 1,
  1783. dialog: 1,
  1784. embed: 1,
  1785. hr: 1,
  1786. img: 1,
  1787. input: 1,
  1788. isindex: 1,
  1789. keygen: 1,
  1790. link: 1,
  1791. meta: 1,
  1792. param: 1,
  1793. source: 1,
  1794. track: 1,
  1795. wbr: 1
  1796. });
  1797. return _({
  1798. // $ 表示自定的属性
  1799. // body外的元素列表.
  1800. $nonBodyContent: X(V, U, S),
  1801. // 块结构元素列表
  1802. $block: block,
  1803. // 内联元素列表
  1804. $inline: L,
  1805. $inlineWithA: X(_({
  1806. a: 1
  1807. }), L),
  1808. $body: X(_({
  1809. script: 1,
  1810. style: 1
  1811. }), block),
  1812. $cdata: _({
  1813. // script: 1,
  1814. // style: 1
  1815. }),
  1816. // 自闭和元素
  1817. $empty: empty,
  1818. // 不是自闭合,但不能让range选中里边
  1819. $nonChild: _({
  1820. iframe: 1,
  1821. textarea: 1
  1822. }),
  1823. // 列表元素列表
  1824. $listItem: _({
  1825. dd: 1,
  1826. dt: 1,
  1827. li: 1
  1828. }),
  1829. // 列表根元素列表
  1830. $list: _({
  1831. ul: 1,
  1832. ol: 1,
  1833. dl: 1
  1834. }),
  1835. // 不能认为是空的元素
  1836. $isNotEmpty: _({
  1837. table: 1,
  1838. ul: 1,
  1839. ol: 1,
  1840. dl: 1,
  1841. iframe: 1,
  1842. area: 1,
  1843. base: 1,
  1844. col: 1,
  1845. hr: 1,
  1846. img: 1,
  1847. embed: 1,
  1848. input: 1,
  1849. link: 1,
  1850. meta: 1,
  1851. param: 1,
  1852. h1: 1,
  1853. h2: 1,
  1854. h3: 1,
  1855. h4: 1,
  1856. h5: 1,
  1857. h6: 1
  1858. }),
  1859. // 如果没有子节点就可以删除的元素列表,像span,a
  1860. $removeEmpty: _({
  1861. a: 1,
  1862. abbr: 1,
  1863. acronym: 1,
  1864. address: 1,
  1865. b: 1,
  1866. bdo: 1,
  1867. big: 1,
  1868. cite: 1,
  1869. code: 1,
  1870. del: 1,
  1871. dfn: 1,
  1872. em: 1,
  1873. font: 1,
  1874. i: 1,
  1875. ins: 1,
  1876. label: 1,
  1877. kbd: 1,
  1878. q: 1,
  1879. s: 1,
  1880. samp: 1,
  1881. small: 1,
  1882. span: 1,
  1883. strike: 1,
  1884. strong: 1,
  1885. sub: 1,
  1886. sup: 1,
  1887. tt: 1,
  1888. u: 1,
  1889. 'var': 1
  1890. }),
  1891. $removeEmptyBlock: _({
  1892. 'p': 1,
  1893. 'div': 1
  1894. }),
  1895. // 在table元素里的元素列表
  1896. $tableContent: _({
  1897. caption: 1,
  1898. col: 1,
  1899. colgroup: 1,
  1900. tbody: 1,
  1901. td: 1,
  1902. tfoot: 1,
  1903. th: 1,
  1904. thead: 1,
  1905. tr: 1,
  1906. table: 1
  1907. }),
  1908. // 不转换的标签
  1909. $notTransContent: _({
  1910. pre: 1,
  1911. script: 1,
  1912. style: 1,
  1913. textarea: 1
  1914. }),
  1915. html: U,
  1916. head: T,
  1917. style: N,
  1918. script: N,
  1919. body: P,
  1920. base: {},
  1921. link: {},
  1922. meta: {},
  1923. title: N,
  1924. col: {},
  1925. tr: _({
  1926. td: 1,
  1927. th: 1
  1928. }),
  1929. img: {},
  1930. embed: {},
  1931. colgroup: _({
  1932. thead: 1,
  1933. col: 1,
  1934. tbody: 1,
  1935. tr: 1,
  1936. tfoot: 1
  1937. }),
  1938. noscript: P,
  1939. td: P,
  1940. br: {},
  1941. th: P,
  1942. center: P,
  1943. kbd: L,
  1944. button: X(I, E),
  1945. basefont: {},
  1946. h5: L,
  1947. h4: L,
  1948. samp: L,
  1949. h6: L,
  1950. ol: Q,
  1951. h1: L,
  1952. h3: L,
  1953. option: N,
  1954. h2: L,
  1955. form: X(A, D, E, I),
  1956. select: _({
  1957. optgroup: 1,
  1958. option: 1
  1959. }),
  1960. font: L,
  1961. ins: L,
  1962. menu: Q,
  1963. abbr: L,
  1964. label: L,
  1965. table: _({
  1966. thead: 1,
  1967. col: 1,
  1968. tbody: 1,
  1969. tr: 1,
  1970. colgroup: 1,
  1971. caption: 1,
  1972. tfoot: 1
  1973. }),
  1974. code: L,
  1975. tfoot: M,
  1976. cite: L,
  1977. li: P,
  1978. input: {},
  1979. iframe: P,
  1980. strong: L,
  1981. textarea: N,
  1982. noframes: P,
  1983. big: L,
  1984. small: L,
  1985. // trace:
  1986. span: _({
  1987. '#': 1,
  1988. br: 1,
  1989. b: 1,
  1990. strong: 1,
  1991. u: 1,
  1992. i: 1,
  1993. em: 1,
  1994. sub: 1,
  1995. sup: 1,
  1996. strike: 1,
  1997. span: 1
  1998. }),
  1999. hr: L,
  2000. dt: L,
  2001. sub: L,
  2002. optgroup: _({
  2003. option: 1
  2004. }),
  2005. param: {},
  2006. bdo: L,
  2007. 'var': L,
  2008. div: P,
  2009. object: O,
  2010. sup: L,
  2011. dd: P,
  2012. strike: L,
  2013. area: {},
  2014. dir: Q,
  2015. map: X(_({
  2016. area: 1,
  2017. form: 1,
  2018. p: 1
  2019. }), A, F, E),
  2020. applet: O,
  2021. dl: _({
  2022. dt: 1,
  2023. dd: 1
  2024. }),
  2025. del: L,
  2026. isindex: {},
  2027. fieldset: X(_({
  2028. legend: 1
  2029. }), K),
  2030. thead: M,
  2031. ul: Q,
  2032. acronym: L,
  2033. b: L,
  2034. a: X(_({
  2035. a: 1
  2036. }), J),
  2037. blockquote: X(_({
  2038. td: 1,
  2039. tr: 1,
  2040. tbody: 1,
  2041. li: 1
  2042. }), P),
  2043. caption: L,
  2044. i: L,
  2045. u: L,
  2046. tbody: M,
  2047. s: L,
  2048. address: X(D, I),
  2049. tt: L,
  2050. legend: L,
  2051. q: L,
  2052. pre: X(G, C),
  2053. p: X(_({
  2054. 'a': 1
  2055. }), L),
  2056. em: L,
  2057. dfn: L
  2058. });
  2059. })();
  2060. // core/domUtils.js
  2061. /**
  2062. * Dom操作工具包
  2063. *
  2064. * @file
  2065. * @module UE.dom.domUtils
  2066. * @since 1.2.6.1
  2067. */
  2068. /**
  2069. * Dom操作工具包
  2070. *
  2071. * @unfile
  2072. * @module UE.dom.domUtils
  2073. */
  2074. function getDomNode(node, start, ltr, startFromChild, fn, guard) {
  2075. var tmpNode = startFromChild && node[start],
  2076. parent;
  2077. !tmpNode && (tmpNode = node[ltr]);
  2078. while(!tmpNode && (parent = (parent || node).parentNode)) {
  2079. if(parent.tagName == 'BODY' || guard && !guard(parent)) {
  2080. return null;
  2081. }
  2082. tmpNode = parent[ltr];
  2083. }
  2084. if(tmpNode && fn && !fn(tmpNode)) {
  2085. return getDomNode(tmpNode, start, ltr, false, fn);
  2086. }
  2087. return tmpNode;
  2088. }
  2089. var attrFix = ie && browser.version < 9 ? {
  2090. tabindex: "tabIndex",
  2091. readonly: "readOnly",
  2092. "for": "htmlFor",
  2093. "class": "className",
  2094. maxlength: "maxLength",
  2095. cellspacing: "cellSpacing",
  2096. cellpadding: "cellPadding",
  2097. rowspan: "rowSpan",
  2098. colspan: "colSpan",
  2099. usemap: "useMap",
  2100. frameborder: "frameBorder"
  2101. } : {
  2102. tabindex: "tabIndex",
  2103. readonly: "readOnly"
  2104. },
  2105. styleBlock = utils.listToMap(['-webkit-box', '-moz-box', 'block',
  2106. 'list-item', 'table', 'table-row-group', 'table-header-group',
  2107. 'table-footer-group', 'table-row', 'table-column-group',
  2108. 'table-column', 'table-cell', 'table-caption'
  2109. ]);
  2110. var domUtils = dom.domUtils = {
  2111. // 节点常量
  2112. NODE_ELEMENT: 1,
  2113. NODE_DOCUMENT: 9,
  2114. NODE_TEXT: 3,
  2115. NODE_COMMENT: 8,
  2116. NODE_DOCUMENT_FRAGMENT: 11,
  2117. // 位置关系
  2118. POSITION_IDENTICAL: 0,
  2119. POSITION_DISCONNECTED: 1,
  2120. POSITION_FOLLOWING: 2,
  2121. POSITION_PRECEDING: 4,
  2122. POSITION_IS_CONTAINED: 8,
  2123. POSITION_CONTAINS: 16,
  2124. // ie6使用其他的会有一段空白出现
  2125. fillChar: ie && browser.version == '6' ? '\ufeff' : '\u200B',
  2126. // -------------------------Node部分--------------------------------
  2127. keys: {
  2128. /* Backspace */
  2129. 8: 1,
  2130. /* Delete */
  2131. 46: 1,
  2132. /* Shift */
  2133. 16: 1,
  2134. /* Ctrl */
  2135. 17: 1,
  2136. /* Alt */
  2137. 18: 1,
  2138. 37: 1,
  2139. 38: 1,
  2140. 39: 1,
  2141. 40: 1,
  2142. 13: 1
  2143. /* enter */
  2144. },
  2145. /**
  2146. * 获取节点A相对于节点B的位置关系
  2147. *
  2148. * @method getPosition
  2149. * @param {
  2150. * Node } nodeA 需要查询位置关系的节点A
  2151. * @param {
  2152. * Node } nodeB 需要查询位置关系的节点B
  2153. * @return { Number } 节点A与节点B的关系
  2154. * @example ```javascript //output: 20 var position =
  2155. * UE.dom.domUtils.getPosition( document.documentElement,
  2156. * document.body );
  2157. *
  2158. * switch ( position ) {
  2159. *
  2160. * //0 case UE.dom.domUtils.POSITION_IDENTICAL: console.log('元素相同');
  2161. * break; //1 case UE.dom.domUtils.POSITION_DISCONNECTED:
  2162. * console.log('两个节点在不同的文档中'); break; //2 case
  2163. * UE.dom.domUtils.POSITION_FOLLOWING: console.log('节点A在节点B之后'); break;
  2164. * //4 case UE.dom.domUtils.POSITION_PRECEDING;
  2165. * console.log('节点A在节点B之前'); break; //8 case
  2166. * UE.dom.domUtils.POSITION_IS_CONTAINED: console.log('节点A被节点B包含');
  2167. * break; case 10: console.log('节点A被节点B包含且节点A在节点B之后'); break; //16 case
  2168. * UE.dom.domUtils.POSITION_CONTAINS: console.log('节点A包含节点B'); break;
  2169. * case 20: console.log('节点A包含节点B且节点A在节点B之前'); break; } ```
  2170. */
  2171. getPosition: function(nodeA, nodeB) {
  2172. // 如果两个节点是同一个节点
  2173. if(nodeA === nodeB) {
  2174. // domUtils.POSITION_IDENTICAL
  2175. return 0;
  2176. }
  2177. var node, parentsA = [nodeA],
  2178. parentsB = [nodeB];
  2179. node = nodeA;
  2180. while(node = node.parentNode) {
  2181. // 如果nodeB是nodeA的祖先节点
  2182. if(node === nodeB) {
  2183. // domUtils.POSITION_IS_CONTAINED +
  2184. // domUtils.POSITION_FOLLOWING
  2185. return 10;
  2186. }
  2187. parentsA.push(node);
  2188. }
  2189. node = nodeB;
  2190. while(node = node.parentNode) {
  2191. // 如果nodeA是nodeB的祖先节点
  2192. if(node === nodeA) {
  2193. // domUtils.POSITION_CONTAINS + domUtils.POSITION_PRECEDING
  2194. return 20;
  2195. }
  2196. parentsB.push(node);
  2197. }
  2198. parentsA.reverse();
  2199. parentsB.reverse();
  2200. if(parentsA[0] !== parentsB[0]) {
  2201. // domUtils.POSITION_DISCONNECTED
  2202. return 1;
  2203. }
  2204. var i = -1;
  2205. while(i++, parentsA[i] === parentsB[i]) {}
  2206. nodeA = parentsA[i];
  2207. nodeB = parentsB[i];
  2208. while(nodeA = nodeA.nextSibling) {
  2209. if(nodeA === nodeB) {
  2210. // domUtils.POSITION_PRECEDING
  2211. return 4
  2212. }
  2213. }
  2214. // domUtils.POSITION_FOLLOWING
  2215. return 2;
  2216. },
  2217. /**
  2218. * 检测节点node在父节点中的索引位置
  2219. *
  2220. * @method getNodeIndex
  2221. * @param {
  2222. * Node } node 需要检测的节点对象
  2223. * @return { Number } 该节点在父节点中的位置
  2224. * @see UE.dom.domUtils.getNodeIndex(Node,Boolean)
  2225. */
  2226. /**
  2227. * 检测节点node在父节点中的索引位置, 根据给定的mergeTextNode参数决定是否要合并多个连续的文本节点为一个节点
  2228. *
  2229. * @method getNodeIndex
  2230. * @param {
  2231. * Node } node 需要检测的节点对象
  2232. * @param {
  2233. * Boolean } mergeTextNode 是否合并多个连续的文本节点为一个节点
  2234. * @return { Number } 该节点在父节点中的位置
  2235. * @example ```javascript
  2236. *
  2237. * var node = document.createElement("div");
  2238. *
  2239. * node.appendChild( document.createTextNode( "hello" ) );
  2240. * node.appendChild( document.createTextNode( "world" ) );
  2241. * node.appendChild( node = document.createElement( "div" ) );
  2242. *
  2243. * //output: 2 console.log( UE.dom.domUtils.getNodeIndex( node ) );
  2244. *
  2245. * //output: 1 console.log( UE.dom.domUtils.getNodeIndex( node, true ) );
  2246. *
  2247. * ```
  2248. */
  2249. getNodeIndex: function(node, ignoreTextNode) {
  2250. var preNode = node,
  2251. i = 0;
  2252. while(preNode = preNode.previousSibling) {
  2253. if(ignoreTextNode && preNode.nodeType == 3) {
  2254. if(preNode.nodeType != preNode.nextSibling.nodeType) {
  2255. i++;
  2256. }
  2257. continue;
  2258. }
  2259. i++;
  2260. }
  2261. return i;
  2262. },
  2263. /**
  2264. * 检测节点node是否在给定的document对象上
  2265. *
  2266. * @method inDoc
  2267. * @param {
  2268. * Node } node 需要检测的节点对象
  2269. * @param {
  2270. * DomDocument } doc 需要检测的document对象
  2271. * @return { Boolean } 该节点node是否在给定的document的dom树上
  2272. * @example ```javascript
  2273. *
  2274. * var node = document.createElement("div");
  2275. *
  2276. * //output: false console.log( UE.do.domUtils.inDoc( node, document ) );
  2277. *
  2278. * document.body.appendChild( node );
  2279. *
  2280. * //output: true console.log( UE.do.domUtils.inDoc( node, document ) );
  2281. *
  2282. * ```
  2283. */
  2284. inDoc: function(node, doc) {
  2285. return domUtils.getPosition(node, doc) == 10;
  2286. },
  2287. /**
  2288. * 根据给定的过滤规则filterFn, 查找符合该过滤规则的node节点的第一个祖先节点, 查找的起点是给定node节点的父节点。
  2289. *
  2290. * @method findParent
  2291. * @param {
  2292. * Node } node 需要查找的节点
  2293. * @param {
  2294. * Function } filterFn 自定义的过滤方法。
  2295. * @warning 查找的终点是到body节点为止
  2296. * @remind 自定义的过滤方法filterFn接受一个Node对象作为参数, 该对象代表当前执行检测的祖先节点。 如果该
  2297. * 节点满足过滤条件, 则要求返回true, 这时将直接返回该节点作为findParent()的结果, 否则,
  2298. * 请返回false。
  2299. * @return { Node | Null } 如果找到符合过滤条件的节点, 就返回该节点, 否则返回NULL
  2300. * @example ```javascript var filterNode = UE.dom.domUtils.findParent(
  2301. * document.body.firstChild, function ( node ) {
  2302. *
  2303. * //由于查找的终点是body节点, 所以永远也不会匹配当前过滤器的条件, 即这里永远会返回false return
  2304. * node.tagName === "HTML"; } );
  2305. *
  2306. * //output: true console.log( filterNode === null ); ```
  2307. */
  2308. /**
  2309. * 根据给定的过滤规则filterFn, 查找符合该过滤规则的node节点的第一个祖先节点,
  2310. * 如果includeSelf的值为true,则查找的起点是给定的节点node, 否则, 起点是node的父节点
  2311. *
  2312. * @method findParent
  2313. * @param {
  2314. * Node } node 需要查找的节点
  2315. * @param {
  2316. * Function } filterFn 自定义的过滤方法。
  2317. * @param {
  2318. * Boolean } includeSelf 查找过程是否包含自身
  2319. * @warning 查找的终点是到body节点为止
  2320. * @remind 自定义的过滤方法filterFn接受一个Node对象作为参数, 该对象代表当前执行检测的祖先节点。 如果该
  2321. * 节点满足过滤条件, 则要求返回true, 这时将直接返回该节点作为findParent()的结果, 否则,
  2322. * 请返回false。
  2323. * @remind 如果includeSelf为true, 则过滤器第一次执行时的参数会是节点本身。 反之,
  2324. * 过滤器第一次执行时的参数将是该节点的父节点。
  2325. * @return { Node | Null } 如果找到符合过滤条件的节点, 就返回该节点, 否则返回NULL
  2326. * @example ```html <body>
  2327. *
  2328. * <div id="test"> </div>
  2329. *
  2330. * <script type="text/javascript">
  2331. *
  2332. * //output: DIV, BODY var filterNode = UE.dom.domUtils.findParent(
  2333. * document.getElementById( "test" ), function ( node ) {
  2334. *
  2335. * console.log( node.tagName ); return false; }, true );
  2336. *
  2337. * </script> </body> ```
  2338. */
  2339. findParent: function(node, filterFn, includeSelf) {
  2340. if(node && !domUtils.isBody(node)) {
  2341. node = includeSelf ? node : node.parentNode;
  2342. while(node) {
  2343. if(!filterFn || filterFn(node) || domUtils.isBody(node)) {
  2344. return filterFn && !filterFn(node) &&
  2345. domUtils.isBody(node) ? null : node;
  2346. }
  2347. node = node.parentNode;
  2348. }
  2349. }
  2350. return null;
  2351. },
  2352. /**
  2353. * 查找node的节点名为tagName的第一个祖先节点, 查找的起点是node节点的父节点。
  2354. *
  2355. * @method findParentByTagName
  2356. * @param {
  2357. * Node } node 需要查找的节点对象
  2358. * @param {
  2359. * Array } tagNames 需要查找的父节点的名称数组
  2360. * @warning 查找的终点是到body节点为止
  2361. * @return { Node | NULL } 如果找到符合条件的节点, 则返回该节点, 否则返回NULL
  2362. * @example ```javascript var node =
  2363. * UE.dom.domUtils.findParentByTagName(
  2364. * document.getElementsByTagName("div")[0], [ "BODY" ] );
  2365. * //output: BODY console.log( node.tagName ); ```
  2366. */
  2367. /**
  2368. * 查找node的节点名为tagName的祖先节点, 如果includeSelf的值为true,则查找的起点是给定的节点node, 否则,
  2369. * 起点是node的父节点。
  2370. *
  2371. * @method findParentByTagName
  2372. * @param {
  2373. * Node } node 需要查找的节点对象
  2374. * @param {
  2375. * Array } tagNames 需要查找的父节点的名称数组
  2376. * @param {
  2377. * Boolean } includeSelf 查找过程是否包含node节点自身
  2378. * @warning 查找的终点是到body节点为止
  2379. * @return { Node | NULL } 如果找到符合条件的节点, 则返回该节点, 否则返回NULL
  2380. * @example ```javascript var queryTarget =
  2381. * document.getElementsByTagName("div")[0]; var node =
  2382. * UE.dom.domUtils.findParentByTagName( queryTarget, [ "DIV" ],
  2383. * true ); //output: true console.log( queryTarget === node );
  2384. * ```
  2385. */
  2386. findParentByTagName: function(node, tagNames, includeSelf, excludeFn) {
  2387. tagNames = utils.listToMap(utils.isArray(tagNames) ?
  2388. tagNames : [tagNames]);
  2389. return domUtils.findParent(node, function(node) {
  2390. return tagNames[node.tagName] &&
  2391. !(excludeFn && excludeFn(node));
  2392. }, includeSelf);
  2393. },
  2394. /**
  2395. * 查找节点node的祖先节点集合, 查找的起点是给定节点的父节点,结果集中不包含给定的节点。
  2396. *
  2397. * @method findParents
  2398. * @param {
  2399. * Node } node 需要查找的节点对象
  2400. * @return { Array } 给定节点的祖先节点数组
  2401. * @grammar UE.dom.domUtils.findParents(node) => Array
  2402. * //返回一个祖先节点数组集合,不包含自身
  2403. * @grammar UE.dom.domUtils.findParents(node,includeSelf) => Array
  2404. * //返回一个祖先节点数组集合,includeSelf指定是否包含自身
  2405. * @grammar UE.dom.domUtils.findParents(node,includeSelf,filterFn) =>
  2406. * Array //返回一个祖先节点数组集合,filterFn指定过滤条件,返回true的node将被选取
  2407. * @grammar UE.dom.domUtils.findParents(node,includeSelf,filterFn,closerFirst) =>
  2408. * Array //返回一个祖先节点数组集合,closerFirst为true的话,node的直接父亲节点是数组的第0个
  2409. */
  2410. /**
  2411. * 查找节点node的祖先节点集合, 如果includeSelf的值为true, 则返回的结果集中允许出现当前给定的节点, 否则,
  2412. * 该节点不会出现在其结果集中。
  2413. *
  2414. * @method findParents
  2415. * @param {
  2416. * Node } node 需要查找的节点对象
  2417. * @param {
  2418. * Boolean } includeSelf 查找的结果中是否允许包含当前查找的节点对象
  2419. * @return { Array } 给定节点的祖先节点数组
  2420. */
  2421. findParents: function(node, includeSelf, filterFn, closerFirst) {
  2422. var parents = includeSelf &&
  2423. (filterFn && filterFn(node) || !filterFn) ? [node] : [];
  2424. while(node = domUtils.findParent(node, filterFn)) {
  2425. parents.push(node);
  2426. }
  2427. return closerFirst ? parents : parents.reverse();
  2428. },
  2429. /**
  2430. * 在节点node后面插入新节点newNode
  2431. *
  2432. * @method insertAfter
  2433. * @param {
  2434. * Node } node 目标节点
  2435. * @param {
  2436. * Node } newNode 新插入的节点, 该节点将置于目标节点之后
  2437. * @return { Node } 新插入的节点
  2438. */
  2439. insertAfter: function(node, newNode) {
  2440. return node.nextSibling ? node.parentNode.insertBefore(newNode,
  2441. node.nextSibling) : node.parentNode.appendChild(newNode);
  2442. },
  2443. /**
  2444. * 删除节点node及其下属的所有节点
  2445. *
  2446. * @method remove
  2447. * @param {
  2448. * Node } node 需要删除的节点对象
  2449. * @return { Node } 返回刚删除的节点对象
  2450. * @example ```html <div id="test"> <div id="child">你好</div> </div>
  2451. * <script> UE.dom.domUtils.remove( document.body, false );
  2452. * //output: false console.log( document.getElementById(
  2453. * "child" ) !== null ); </script> ```
  2454. */
  2455. /**
  2456. * 删除节点node,并根据keepChildren的值决定是否保留子节点
  2457. *
  2458. * @method remove
  2459. * @param {
  2460. * Node } node 需要删除的节点对象
  2461. * @param {
  2462. * Boolean } keepChildren 是否需要保留子节点
  2463. * @return { Node } 返回刚删除的节点对象
  2464. * @example ```html <div id="test"> <div id="child">你好</div> </div>
  2465. * <script> UE.dom.domUtils.remove( document.body, true );
  2466. * //output: true console.log( document.getElementById( "child" )
  2467. * !== null ); </script> ```
  2468. */
  2469. remove: function(node, keepChildren) {
  2470. var parent = node.parentNode,
  2471. child;
  2472. if(parent) {
  2473. if(keepChildren && node.hasChildNodes()) {
  2474. while(child = node.firstChild) {
  2475. parent.insertBefore(child, node);
  2476. }
  2477. }
  2478. parent.removeChild(node);
  2479. }
  2480. return node;
  2481. },
  2482. /**
  2483. * 取得node节点的下一个兄弟节点, 如果该节点其后没有兄弟节点, 则递归查找其父节点之后的第一个兄弟节点,
  2484. * 直到找到满足条件的节点或者递归到BODY节点之后才会结束。
  2485. *
  2486. * @method getNextDomNode
  2487. * @param {
  2488. * Node } node 需要获取其后的兄弟节点的节点对象
  2489. * @return { Node | NULL } 如果找满足条件的节点, 则返回该节点, 否则返回NULL
  2490. * @example ```html <body> <div id="test"> <span></span> </div> <i>xxx</i>
  2491. * </body> <script>
  2492. *
  2493. * //output: i节点 console.log( UE.dom.domUtils.getNextDomNode(
  2494. * document.getElementById( "test" ) ) );
  2495. *
  2496. * </script> ```
  2497. * @example ```html <body> <div> <span></span> <i id="test">xxx</i>
  2498. * </div> <b>xxx</b> </body> <script>
  2499. *
  2500. * //由于id为test的i节点之后没有兄弟节点, 则查找其父节点(div)后面的兄弟节点 //output: b节点
  2501. * console.log( UE.dom.domUtils.getNextDomNode( document.getElementById(
  2502. * "test" ) ) );
  2503. *
  2504. * </script> ```
  2505. */
  2506. /**
  2507. * 取得node节点的下一个兄弟节点, 如果startFromChild的值为ture,则先获取其子节点,
  2508. * 如果有子节点则直接返回第一个子节点;如果没有子节点或者startFromChild的值为false, 则执行<a
  2509. * href="#UE.dom.domUtils.getNextDomNode(Node)">getNextDomNode(Node
  2510. * node)</a>的查找过程。
  2511. *
  2512. * @method getNextDomNode
  2513. * @param {
  2514. * Node } node 需要获取其后的兄弟节点的节点对象
  2515. * @param {
  2516. * Boolean } startFromChild 查找过程是否从其子节点开始
  2517. * @return { Node | NULL } 如果找满足条件的节点, 则返回该节点, 否则返回NULL
  2518. * @see UE.dom.domUtils.getNextDomNode(Node)
  2519. */
  2520. getNextDomNode: function(node, startFromChild, filterFn, guard) {
  2521. return getDomNode(node, 'firstChild', 'nextSibling',
  2522. startFromChild, filterFn, guard);
  2523. },
  2524. getPreDomNode: function(node, startFromChild, filterFn, guard) {
  2525. return getDomNode(node, 'lastChild', 'previousSibling',
  2526. startFromChild, filterFn, guard);
  2527. },
  2528. /**
  2529. * 检测节点node是否属是UEditor定义的bookmark节点
  2530. *
  2531. * @method isBookmarkNode
  2532. * @private
  2533. * @param {
  2534. * Node } node 需要检测的节点对象
  2535. * @return { Boolean } 是否是bookmark节点
  2536. * @example ```html <span id="_baidu_bookmark_1"></span> <script> var
  2537. * bookmarkNode = document.getElementById("_baidu_bookmark_1");
  2538. * //output: true console.log( UE.dom.domUtils.isBookmarkNode(
  2539. * bookmarkNode ) ); </script> ```
  2540. */
  2541. isBookmarkNode: function(node) {
  2542. return node.nodeType == 1 && node.id &&
  2543. /^_baidu_bookmark_/i.test(node.id);
  2544. },
  2545. /**
  2546. * 获取节点node所属的window对象
  2547. *
  2548. * @method getWindow
  2549. * @param {
  2550. * Node } node 节点对象
  2551. * @return { Window } 当前节点所属的window对象
  2552. * @example ```javascript //output: true console.log(
  2553. * UE.dom.domUtils.getWindow( document.body ) === window ); ```
  2554. */
  2555. getWindow: function(node) {
  2556. var doc = node.ownerDocument || node;
  2557. return doc.defaultView || doc.parentWindow;
  2558. },
  2559. /**
  2560. * 获取离nodeA与nodeB最近的公共的祖先节点
  2561. *
  2562. * @method getCommonAncestor
  2563. * @param {
  2564. * Node } nodeA 第一个节点
  2565. * @param {
  2566. * Node } nodeB 第二个节点
  2567. * @remind 如果给定的两个节点是同一个节点, 将直接返回该节点。
  2568. * @return { Node | NULL } 如果未找到公共节点, 返回NULL, 否则返回最近的公共祖先节点。
  2569. * @example ```javascript var commonAncestor =
  2570. * UE.dom.domUtils.getCommonAncestor( document.body,
  2571. * document.body.firstChild ); //output: true console.log(
  2572. * commonAncestor.tagName.toLowerCase() === 'body' ); ```
  2573. */
  2574. getCommonAncestor: function(nodeA, nodeB) {
  2575. if(nodeA === nodeB)
  2576. return nodeA;
  2577. var parentsA = [nodeA],
  2578. parentsB = [nodeB],
  2579. parent = nodeA,
  2580. i = -1;
  2581. while(parent = parent.parentNode) {
  2582. if(parent === nodeB) {
  2583. return parent;
  2584. }
  2585. parentsA.push(parent);
  2586. }
  2587. parent = nodeB;
  2588. while(parent = parent.parentNode) {
  2589. if(parent === nodeA)
  2590. return parent;
  2591. parentsB.push(parent);
  2592. }
  2593. parentsA.reverse();
  2594. parentsB.reverse();
  2595. while(i++, parentsA[i] === parentsB[i]) {}
  2596. return i == 0 ? null : parentsA[i - 1];
  2597. },
  2598. /**
  2599. * 清除node节点左右连续为空的兄弟inline节点
  2600. *
  2601. * @method clearEmptySibling
  2602. * @param {
  2603. * Node } node 执行的节点对象, 如果该节点的左右连续的兄弟节点是空的inline节点,
  2604. * 则这些兄弟节点将被删除
  2605. * @grammar UE.dom.domUtils.clearEmptySibling(node,ignoreNext)
  2606. * //ignoreNext指定是否忽略右边空节点
  2607. * @grammar UE.dom.domUtils.clearEmptySibling(node,ignoreNext,ignorePre)
  2608. * //ignorePre指定是否忽略左边空节点
  2609. * @example ```html <body> <div></div> <span id="test"></span> <i></i>
  2610. * <b></b> <em>xxx</em> <span></span> </body> <script>
  2611. *
  2612. * UE.dom.domUtils.clearEmptySibling( document.getElementById( "test" ) );
  2613. *
  2614. * //output: <div></div><span id="test"></span><em>xxx</em><span></span>
  2615. * console.log( document.body.innerHTML );
  2616. *
  2617. * </script> ```
  2618. */
  2619. /**
  2620. * 清除node节点左右连续为空的兄弟inline节点, 如果ignoreNext的值为true, 则忽略对右边兄弟节点的操作。
  2621. *
  2622. * @method clearEmptySibling
  2623. * @param {
  2624. * Node } node 执行的节点对象, 如果该节点的左右连续的兄弟节点是空的inline节点,
  2625. * @param {
  2626. * Boolean } ignoreNext 是否忽略忽略对右边的兄弟节点的操作 则这些兄弟节点将被删除
  2627. * @see UE.dom.domUtils.clearEmptySibling(Node)
  2628. */
  2629. /**
  2630. * 清除node节点左右连续为空的兄弟inline节点, 如果ignoreNext的值为true, 则忽略对右边兄弟节点的操作,
  2631. * 如果ignorePre的值为true,则忽略对左边兄弟节点的操作。
  2632. *
  2633. * @method clearEmptySibling
  2634. * @param {
  2635. * Node } node 执行的节点对象, 如果该节点的左右连续的兄弟节点是空的inline节点,
  2636. * @param {
  2637. * Boolean } ignoreNext 是否忽略忽略对右边的兄弟节点的操作
  2638. * @param {
  2639. * Boolean } ignorePre 是否忽略忽略对左边的兄弟节点的操作 则这些兄弟节点将被删除
  2640. * @see UE.dom.domUtils.clearEmptySibling(Node)
  2641. */
  2642. clearEmptySibling: function(node, ignoreNext, ignorePre) {
  2643. function clear(next, dir) {
  2644. var tmpNode;
  2645. while(next && !domUtils.isBookmarkNode(next) &&
  2646. (domUtils.isEmptyInlineElement(next)
  2647. // 这里不能把空格算进来会吧空格干掉,出现文字间的空格丢掉了
  2648. ||
  2649. !new RegExp('[^\t\n\r' + domUtils.fillChar + ']')
  2650. .test(next.nodeValue))) {
  2651. tmpNode = next[dir];
  2652. domUtils.remove(next);
  2653. next = tmpNode;
  2654. }
  2655. }!ignoreNext && clear(node.nextSibling, 'nextSibling');
  2656. !ignorePre && clear(node.previousSibling, 'previousSibling');
  2657. },
  2658. /**
  2659. * 将一个文本节点textNode拆分成两个文本节点,offset指定拆分位置
  2660. *
  2661. * @method split
  2662. * @param {
  2663. * Node } textNode 需要拆分的文本节点对象
  2664. * @param {
  2665. * int } offset 需要拆分的位置, 位置计算从0开始
  2666. * @return { Node } 拆分后形成的新节点
  2667. * @example ```html <div id="test">abcdef</div> <script> var newNode =
  2668. * UE.dom.domUtils.split( document.getElementById( "test"
  2669. * ).firstChild, 3 ); //output: def console.log(
  2670. * newNode.nodeValue ); </script> ```
  2671. */
  2672. split: function(node, offset) {
  2673. var doc = node.ownerDocument;
  2674. if(browser.ie && offset == node.nodeValue.length) {
  2675. var next = doc.createTextNode('');
  2676. return domUtils.insertAfter(node, next);
  2677. }
  2678. var retval = node.splitText(offset);
  2679. // ie8下splitText不会跟新childNodes,我们手动触发他的更新
  2680. if(browser.ie8) {
  2681. var tmpNode = doc.createTextNode('');
  2682. domUtils.insertAfter(retval, tmpNode);
  2683. domUtils.remove(tmpNode);
  2684. }
  2685. return retval;
  2686. },
  2687. /**
  2688. * 检测文本节点textNode是否为空节点(包括空格、换行、占位符等字符)
  2689. *
  2690. * @method isWhitespace
  2691. * @param {
  2692. * Node } node 需要检测的节点对象
  2693. * @return { Boolean } 检测的节点是否为空
  2694. * @example ```html <div id="test">
  2695. *
  2696. * </div> <script> //output: true console.log(
  2697. * UE.dom.domUtils.isWhitespace(
  2698. * document.getElementById("test").firstChild ) ); </script> ```
  2699. */
  2700. isWhitespace: function(node) {
  2701. return !new RegExp('[^ \t\n\r' + domUtils.fillChar + ']')
  2702. .test(node.nodeValue);
  2703. },
  2704. /**
  2705. * 获取元素element相对于viewport的位置坐标
  2706. *
  2707. * @method getXY
  2708. * @param {
  2709. * Node } element 需要计算位置的节点对象
  2710. * @return { Object } 返回形如{x:left,y:top}的一个key-value映射对象, 其中键x代表水平偏移距离,
  2711. * y代表垂直偏移距离。
  2712. *
  2713. * @example ```javascript var location = UE.dom.domUtils.getXY(
  2714. * document.getElementById("test") ); //output: test的坐标为: 12,
  2715. * 24 console.log( 'test的坐标为: ', location.x, ',', location.y );
  2716. * ```
  2717. */
  2718. getXY: function(element) {
  2719. var x = 0,
  2720. y = 0;
  2721. while(element.offsetParent) {
  2722. y += element.offsetTop;
  2723. x += element.offsetLeft;
  2724. element = element.offsetParent;
  2725. }
  2726. return {
  2727. 'x': x,
  2728. 'y': y
  2729. };
  2730. },
  2731. /**
  2732. * 为元素element绑定原生DOM事件,type为事件类型,handler为处理函数
  2733. *
  2734. * @method on
  2735. * @param {
  2736. * Node } element 需要绑定事件的节点对象
  2737. * @param {
  2738. * String } type 绑定的事件类型
  2739. * @param {
  2740. * Function } handler 事件处理器
  2741. * @example ```javascript
  2742. * UE.dom.domUtils.on(document.body,"click",function(e){
  2743. * //e为事件对象,this为被点击元素对戏那个 }); ```
  2744. */
  2745. /**
  2746. * 为元素element绑定原生DOM事件,type为事件类型,handler为处理函数
  2747. *
  2748. * @method on
  2749. * @param {
  2750. * Node } element 需要绑定事件的节点对象
  2751. * @param {
  2752. * Array } type 绑定的事件类型数组
  2753. * @param {
  2754. * Function } handler 事件处理器
  2755. * @example ```javascript
  2756. * UE.dom.domUtils.on(document.body,["click","mousedown"],function(evt){
  2757. * //evt为事件对象,this为被点击元素对象 }); ```
  2758. */
  2759. on: function(element, type, handler) {
  2760. var types = utils.isArray(type) ? type : utils.trim(type)
  2761. .split(/\s+/),
  2762. k = types.length;
  2763. if(k)
  2764. while(k--) {
  2765. type = types[k];
  2766. if(element.addEventListener) {
  2767. element.addEventListener(type, handler, false);
  2768. } else {
  2769. if(!handler._d) {
  2770. handler._d = {
  2771. els: []
  2772. };
  2773. }
  2774. var key = type + handler.toString(),
  2775. index = utils
  2776. .indexOf(handler._d.els, element);
  2777. if(!handler._d[key] || index == -1) {
  2778. if(index == -1) {
  2779. handler._d.els.push(element);
  2780. }
  2781. if(!handler._d[key]) {
  2782. handler._d[key] = function(evt) {
  2783. return handler.call(evt.srcElement, evt ||
  2784. window.event);
  2785. };
  2786. }
  2787. element.attachEvent('on' + type, handler._d[key]);
  2788. }
  2789. }
  2790. }
  2791. element = null;
  2792. },
  2793. /**
  2794. * 解除DOM事件绑定
  2795. *
  2796. * @method un
  2797. * @param {
  2798. * Node } element 需要解除事件绑定的节点对象
  2799. * @param {
  2800. * String } type 需要接触绑定的事件类型
  2801. * @param {
  2802. * Function } handler 对应的事件处理器
  2803. * @example ```javascript
  2804. * UE.dom.domUtils.un(document.body,"click",function(evt){
  2805. * //evt为事件对象,this为被点击元素对象 }); ```
  2806. */
  2807. /**
  2808. * 解除DOM事件绑定
  2809. *
  2810. * @method un
  2811. * @param {
  2812. * Node } element 需要解除事件绑定的节点对象
  2813. * @param {
  2814. * Array } type 需要接触绑定的事件类型数组
  2815. * @param {
  2816. * Function } handler 对应的事件处理器
  2817. * @example ```javascript UE.dom.domUtils.un(document.body,
  2818. * ["click","mousedown"],function(evt){ //evt为事件对象,this为被点击元素对象
  2819. * }); ```
  2820. */
  2821. un: function(element, type, handler) {
  2822. var types = utils.isArray(type) ? type : utils.trim(type)
  2823. .split(/\s+/),
  2824. k = types.length;
  2825. if(k)
  2826. while(k--) {
  2827. type = types[k];
  2828. if(element.removeEventListener) {
  2829. element.removeEventListener(type, handler, false);
  2830. } else {
  2831. var key = type + handler.toString();
  2832. try {
  2833. element.detachEvent('on' + type, handler._d ?
  2834. handler._d[key] :
  2835. handler);
  2836. } catch(e) {}
  2837. if(handler._d && handler._d[key]) {
  2838. var index = utils.indexOf(handler._d.els, element);
  2839. if(index != -1) {
  2840. handler._d.els.splice(index, 1);
  2841. }
  2842. handler._d.els.length == 0 &&
  2843. delete handler._d[key];
  2844. }
  2845. }
  2846. }
  2847. },
  2848. /**
  2849. * 比较节点nodeA与节点nodeB是否具有相同的标签名、属性名以及属性值
  2850. *
  2851. * @method isSameElement
  2852. * @param {
  2853. * Node } nodeA 需要比较的节点
  2854. * @param {
  2855. * Node } nodeB 需要比较的节点
  2856. * @return { Boolean } 两个节点是否具有相同的标签名、属性名以及属性值
  2857. * @example ```html <span style="font-size:12px">ssss</span> <span
  2858. * style="font-size:12px">bbbbb</span> <span
  2859. * style="font-size:13px">ssss</span> <span
  2860. * style="font-size:14px">bbbbb</span>
  2861. *
  2862. * <script>
  2863. *
  2864. * var nodes = document.getElementsByTagName( "span" );
  2865. *
  2866. * //output: true console.log( UE.dom.domUtils.isSameElement( nodes[0],
  2867. * nodes[1] ) );
  2868. *
  2869. * //output: false console.log( UE.dom.domUtils.isSameElement( nodes[2],
  2870. * nodes[3] ) );
  2871. *
  2872. * </script> ```
  2873. */
  2874. isSameElement: function(nodeA, nodeB) {
  2875. if(nodeA.tagName != nodeB.tagName) {
  2876. return false;
  2877. }
  2878. var thisAttrs = nodeA.attributes,
  2879. otherAttrs = nodeB.attributes;
  2880. if(!ie && thisAttrs.length != otherAttrs.length) {
  2881. return false;
  2882. }
  2883. var attrA, attrB, al = 0,
  2884. bl = 0;
  2885. for(var i = 0; attrA = thisAttrs[i++];) {
  2886. if(attrA.nodeName == 'style') {
  2887. if(attrA.specified) {
  2888. al++;
  2889. }
  2890. if(domUtils.isSameStyle(nodeA, nodeB)) {
  2891. continue;
  2892. } else {
  2893. return false;
  2894. }
  2895. }
  2896. if(ie) {
  2897. if(attrA.specified) {
  2898. al++;
  2899. attrB = otherAttrs.getNamedItem(attrA.nodeName);
  2900. } else {
  2901. continue;
  2902. }
  2903. } else {
  2904. attrB = nodeB.attributes[attrA.nodeName];
  2905. }
  2906. if(!attrB.specified || attrA.nodeValue != attrB.nodeValue) {
  2907. return false;
  2908. }
  2909. }
  2910. // 有可能attrB的属性包含了attrA的属性之外还有自己的属性
  2911. if(ie) {
  2912. for(i = 0; attrB = otherAttrs[i++];) {
  2913. if(attrB.specified) {
  2914. bl++;
  2915. }
  2916. }
  2917. if(al != bl) {
  2918. return false;
  2919. }
  2920. }
  2921. return true;
  2922. },
  2923. /**
  2924. * 判断节点nodeA与节点nodeB的元素的style属性是否一致
  2925. *
  2926. * @method isSameStyle
  2927. * @param {
  2928. * Node } nodeA 需要比较的节点
  2929. * @param {
  2930. * Node } nodeB 需要比较的节点
  2931. * @return { Boolean } 两个节点是否具有相同的style属性值
  2932. * @example ```html <span style="font-size:12px">ssss</span> <span
  2933. * style="font-size:12px">bbbbb</span> <span
  2934. * style="font-size:13px">ssss</span> <span
  2935. * style="font-size:14px">bbbbb</span>
  2936. *
  2937. * <script>
  2938. *
  2939. * var nodes = document.getElementsByTagName( "span" );
  2940. *
  2941. * //output: true console.log( UE.dom.domUtils.isSameStyle( nodes[0],
  2942. * nodes[1] ) );
  2943. *
  2944. * //output: false console.log( UE.dom.domUtils.isSameStyle( nodes[2],
  2945. * nodes[3] ) );
  2946. *
  2947. * </script> ```
  2948. */
  2949. isSameStyle: function(nodeA, nodeB) {
  2950. var styleA = nodeA.style.cssText.replace(/( ?; ?)/g, ';').replace(
  2951. /( ?: ?)/g, ':'),
  2952. styleB = nodeB.style.cssText.replace(
  2953. /( ?; ?)/g, ';').replace(/( ?: ?)/g, ':');
  2954. if(browser.opera) {
  2955. styleA = nodeA.style;
  2956. styleB = nodeB.style;
  2957. if(styleA.length != styleB.length)
  2958. return false;
  2959. for(var p in styleA) {
  2960. if(/^(\d+|csstext)$/i.test(p)) {
  2961. continue;
  2962. }
  2963. if(styleA[p] != styleB[p]) {
  2964. return false;
  2965. }
  2966. }
  2967. return true;
  2968. }
  2969. if(!styleA || !styleB) {
  2970. return styleA == styleB;
  2971. }
  2972. styleA = styleA.split(';');
  2973. styleB = styleB.split(';');
  2974. if(styleA.length != styleB.length) {
  2975. return false;
  2976. }
  2977. for(var i = 0, ci; ci = styleA[i++];) {
  2978. if(utils.indexOf(styleB, ci) == -1) {
  2979. return false;
  2980. }
  2981. }
  2982. return true;
  2983. },
  2984. /**
  2985. * 检查节点node是否为block元素
  2986. *
  2987. * @method isBlockElm
  2988. * @param {
  2989. * Node } node 需要检测的节点对象
  2990. * @return { Boolean } 是否是block元素节点
  2991. * @warning 该方法的判断规则如下: 如果该元素原本是block元素, 则不论该元素当前的css样式是什么都会返回true;
  2992. * 否则,检测该元素的css样式, 如果该元素当前是block元素, 则返回true。 其余情况下都返回false。
  2993. * @example ```html <span id="test1" style="display: block"></span>
  2994. * <span id="test2"></span> <div id="test3" style="display:
  2995. * inline"></div>
  2996. *
  2997. * <script>
  2998. *
  2999. * //output: true console.log( UE.dom.domUtils.isBlockElm(
  3000. * document.getElementById("test1") ) );
  3001. *
  3002. * //output: false console.log( UE.dom.domUtils.isBlockElm(
  3003. * document.getElementById("test2") ) );
  3004. *
  3005. * //output: true console.log( UE.dom.domUtils.isBlockElm(
  3006. * document.getElementById("test3") ) );
  3007. *
  3008. * </script> ```
  3009. */
  3010. isBlockElm: function(node) {
  3011. return node.nodeType == 1 &&
  3012. (dtd.$block[node.tagName] || styleBlock[domUtils
  3013. .getComputedStyle(node, 'display')]) &&
  3014. !dtd.$nonChild[node.tagName];
  3015. },
  3016. /**
  3017. * 检测node节点是否为body节点
  3018. *
  3019. * @method isBody
  3020. * @param {
  3021. * Element } node 需要检测的dom元素
  3022. * @return { Boolean } 给定的元素是否是body元素
  3023. * @example ```javascript //output: true console.log(
  3024. * UE.dom.domUtils.isBody( document.body ) ); ```
  3025. */
  3026. isBody: function(node) {
  3027. return node && node.nodeType == 1 &&
  3028. node.tagName.toLowerCase() == 'body';
  3029. },
  3030. /**
  3031. * 以node节点为分界,将该节点的指定祖先节点parent拆分成两个独立的节点, 拆分形成的两个节点之间是node节点
  3032. *
  3033. * @method breakParent
  3034. * @param {
  3035. * Node } node 作为分界的节点对象
  3036. * @param {
  3037. * Node } parent 该节点必须是node节点的祖先节点, 且是block节点。
  3038. * @return { Node } 给定的node分界节点
  3039. * @example ```javascript
  3040. *
  3041. * var node = document.createElement("span"), wrapNode =
  3042. * document.createElement( "div" ), parent =
  3043. * document.createElement("p");
  3044. *
  3045. * parent.appendChild( node ); wrapNode.appendChild( parent );
  3046. *
  3047. * //拆分前 //output:
  3048. * <p>
  3049. * <span></span>
  3050. * </p>
  3051. * console.log( wrapNode.innerHTML );
  3052. *
  3053. *
  3054. * UE.dom.domUtils.breakParent( node, parent ); //拆分后 //output:
  3055. * <p>
  3056. * </p>
  3057. * <span></span>
  3058. * <p>
  3059. * </p>
  3060. * console.log( wrapNode.innerHTML );
  3061. *
  3062. * ```
  3063. */
  3064. breakParent: function(node, parent) {
  3065. var tmpNode, parentClone = node,
  3066. clone = node,
  3067. leftNodes, rightNodes;
  3068. do {
  3069. parentClone = parentClone.parentNode;
  3070. if(leftNodes) {
  3071. tmpNode = parentClone.cloneNode(false);
  3072. tmpNode.appendChild(leftNodes);
  3073. leftNodes = tmpNode;
  3074. tmpNode = parentClone.cloneNode(false);
  3075. tmpNode.appendChild(rightNodes);
  3076. rightNodes = tmpNode;
  3077. } else {
  3078. leftNodes = parentClone.cloneNode(false);
  3079. rightNodes = leftNodes.cloneNode(false);
  3080. }
  3081. while(tmpNode = clone.previousSibling) {
  3082. leftNodes.insertBefore(tmpNode, leftNodes.firstChild);
  3083. }
  3084. while(tmpNode = clone.nextSibling) {
  3085. rightNodes.appendChild(tmpNode);
  3086. }
  3087. clone = parentClone;
  3088. } while (parent !== parentClone);
  3089. tmpNode = parent.parentNode;
  3090. tmpNode.insertBefore(leftNodes, parent);
  3091. tmpNode.insertBefore(rightNodes, parent);
  3092. tmpNode.insertBefore(node, rightNodes);
  3093. domUtils.remove(parent);
  3094. return node;
  3095. },
  3096. /**
  3097. * 检查节点node是否是空inline节点
  3098. *
  3099. * @method isEmptyInlineElement
  3100. * @param {
  3101. * Node } node 需要检测的节点对象
  3102. * @return { Number } 如果给定的节点是空的inline节点, 则返回1, 否则返回0。
  3103. * @example ```html <b><i></i></b> => 1 <b><i></i><u></u></b> =>
  3104. * 1 <b></b> => 1 <b>xx<i></i></b> => 0 ```
  3105. */
  3106. isEmptyInlineElement: function(node) {
  3107. if(node.nodeType != 1 || !dtd.$removeEmpty[node.tagName]) {
  3108. return 0;
  3109. }
  3110. node = node.firstChild;
  3111. while(node) {
  3112. // 如果是创建的bookmark就跳过
  3113. if(domUtils.isBookmarkNode(node)) {
  3114. return 0;
  3115. }
  3116. if(node.nodeType == 1 && !domUtils.isEmptyInlineElement(node) ||
  3117. node.nodeType == 3 && !domUtils.isWhitespace(node)) {
  3118. return 0;
  3119. }
  3120. node = node.nextSibling;
  3121. }
  3122. return 1;
  3123. },
  3124. /**
  3125. * 删除node节点下首尾两端的空白文本子节点
  3126. *
  3127. * @method trimWhiteTextNode
  3128. * @param {
  3129. * Element } node 需要执行删除操作的元素对象
  3130. * @example ```javascript var node = document.createElement("div");
  3131. *
  3132. * node.appendChild( document.createTextNode( "" ) );
  3133. *
  3134. * node.appendChild( document.createElement("div") );
  3135. *
  3136. * node.appendChild( document.createTextNode( "" ) );
  3137. *
  3138. * //3 console.log( node.childNodes.length );
  3139. *
  3140. * UE.dom.domUtils.trimWhiteTextNode( node );
  3141. *
  3142. * //1 console.log( node.childNodes.length ); ```
  3143. */
  3144. trimWhiteTextNode: function(node) {
  3145. function remove(dir) {
  3146. var child;
  3147. while((child = node[dir]) && child.nodeType == 3 &&
  3148. domUtils.isWhitespace(child)) {
  3149. node.removeChild(child);
  3150. }
  3151. }
  3152. remove('firstChild');
  3153. remove('lastChild');
  3154. },
  3155. /**
  3156. * 合并node节点下相同的子节点
  3157. *
  3158. * @name mergeChild
  3159. * @desc UE.dom.domUtils.mergeChild(node,tagName) //tagName要合并的子节点的标签
  3160. * @example
  3161. * <p>
  3162. * <span style="font-size:12px;">xx<span
  3163. * style="font-size:12px;">aa</span>xx</span>
  3164. * </p>
  3165. * ==> UE.dom.domUtils.mergeChild(node,'span')
  3166. * <p>
  3167. * <span style="font-size:12px;">xxaaxx</span>
  3168. * </p>
  3169. */
  3170. mergeChild: function(node, tagName, attrs) {
  3171. var list = domUtils.getElementsByTagName(node, node.tagName
  3172. .toLowerCase());
  3173. for(var i = 0, ci; ci = list[i++];) {
  3174. if(!ci.parentNode || domUtils.isBookmarkNode(ci)) {
  3175. continue;
  3176. }
  3177. // span单独处理
  3178. if(ci.tagName.toLowerCase() == 'span') {
  3179. if(node === ci.parentNode) {
  3180. domUtils.trimWhiteTextNode(node);
  3181. if(node.childNodes.length == 1) {
  3182. node.style.cssText = ci.style.cssText + ";" +
  3183. node.style.cssText;
  3184. domUtils.remove(ci, true);
  3185. continue;
  3186. }
  3187. }
  3188. ci.style.cssText = node.style.cssText + ';' +
  3189. ci.style.cssText;
  3190. if(attrs) {
  3191. var style = attrs.style;
  3192. if(style) {
  3193. style = style.split(';');
  3194. for(var j = 0, s; s = style[j++];) {
  3195. ci.style[utils
  3196. .cssStyleToDomStyle(s.split(':')[0])] = s
  3197. .split(':')[1];
  3198. }
  3199. }
  3200. }
  3201. if(domUtils.isSameStyle(ci, node)) {
  3202. domUtils.remove(ci, true);
  3203. }
  3204. continue;
  3205. }
  3206. if(domUtils.isSameElement(node, ci)) {
  3207. domUtils.remove(ci, true);
  3208. }
  3209. }
  3210. },
  3211. /**
  3212. * 原生方法getElementsByTagName的封装
  3213. *
  3214. * @method getElementsByTagName
  3215. * @param {
  3216. * Node } node 目标节点对象
  3217. * @param {
  3218. * String } tagName 需要查找的节点的tagName, 多个tagName以空格分割
  3219. * @return { Array } 符合条件的节点集合
  3220. */
  3221. getElementsByTagName: function(node, name, filter) {
  3222. if(filter && utils.isString(filter)) {
  3223. var className = filter;
  3224. filter = function(node) {
  3225. return domUtils.hasClass(node, className)
  3226. }
  3227. }
  3228. name = utils.trim(name).replace(/[ ]{2,}/g, ' ').split(' ');
  3229. var arr = [];
  3230. for(var n = 0, ni; ni = name[n++];) {
  3231. var list = node.getElementsByTagName(ni);
  3232. for(var i = 0, ci; ci = list[i++];) {
  3233. if(!filter || filter(ci))
  3234. arr.push(ci);
  3235. }
  3236. }
  3237. return arr;
  3238. },
  3239. /**
  3240. * 将节点node提取到父节点上
  3241. *
  3242. * @method mergeToParent
  3243. * @param {
  3244. * Element } node 需要提取的元素对象
  3245. * @example ```html <div id="parent"> <div id="sub"> <span id="child"></span>
  3246. * </div> </div>
  3247. *
  3248. * <script>
  3249. *
  3250. * var child = document.getElementById( "child" );
  3251. *
  3252. * //output: sub console.log( child.parentNode.id );
  3253. *
  3254. * UE.dom.domUtils.mergeToParent( child );
  3255. *
  3256. * //output: parent console.log( child.parentNode.id );
  3257. *
  3258. * </script> ```
  3259. */
  3260. mergeToParent: function(node) {
  3261. var parent = node.parentNode;
  3262. while(parent && dtd.$removeEmpty[parent.tagName]) {
  3263. if(parent.tagName == node.tagName || parent.tagName == 'A') { // 针对a标签单独处理
  3264. domUtils.trimWhiteTextNode(parent);
  3265. // span需要特殊处理 不处理这样的情况 <span stlye="color:#fff">xxx<span
  3266. // style="color:#ccc">xxx</span>xxx</span>
  3267. if(parent.tagName == 'SPAN' &&
  3268. !domUtils.isSameStyle(parent, node) ||
  3269. (parent.tagName == 'A' && node.tagName == 'SPAN')) {
  3270. if(parent.childNodes.length > 1 ||
  3271. parent !== node.parentNode) {
  3272. node.style.cssText = parent.style.cssText + ";" +
  3273. node.style.cssText;
  3274. parent = parent.parentNode;
  3275. continue;
  3276. } else {
  3277. parent.style.cssText += ";" + node.style.cssText;
  3278. // trace:952 a标签要保持下划线
  3279. if(parent.tagName == 'A') {
  3280. parent.style.textDecoration = 'underline';
  3281. }
  3282. }
  3283. }
  3284. if(parent.tagName != 'A') {
  3285. parent === node.parentNode &&
  3286. domUtils.remove(node, true);
  3287. break;
  3288. }
  3289. }
  3290. parent = parent.parentNode;
  3291. }
  3292. },
  3293. /**
  3294. * 合并节点node的左右兄弟节点
  3295. *
  3296. * @method mergeSibling
  3297. * @param {
  3298. * Element } node 需要合并的目标节点
  3299. * @example ```html <b>xxxx</b><b id="test">ooo</b><b>xxxx</b>
  3300. *
  3301. * <script> var demoNode = document.getElementById("test");
  3302. * UE.dom.domUtils.mergeSibling( demoNode ); //output: xxxxoooxxxx
  3303. * console.log( demoNode.innerHTML ); </script> ```
  3304. */
  3305. /**
  3306. * 合并节点node的左右兄弟节点, 可以根据给定的条件选择是否忽略合并左节点。
  3307. *
  3308. * @method mergeSibling
  3309. * @param {
  3310. * Element } node 需要合并的目标节点
  3311. * @param {
  3312. * Boolean } ignorePre 是否忽略合并左节点
  3313. * @example ```html <b>xxxx</b><b id="test">ooo</b><b>xxxx</b>
  3314. *
  3315. * <script> var demoNode = document.getElementById("test");
  3316. * UE.dom.domUtils.mergeSibling( demoNode, true ); //output: oooxxxx
  3317. * console.log( demoNode.innerHTML ); </script> ```
  3318. */
  3319. /**
  3320. * 合并节点node的左右兄弟节点,可以根据给定的条件选择是否忽略合并左右节点。
  3321. *
  3322. * @method mergeSibling
  3323. * @param {
  3324. * Element } node 需要合并的目标节点
  3325. * @param {
  3326. * Boolean } ignorePre 是否忽略合并左节点
  3327. * @param {
  3328. * Boolean } ignoreNext 是否忽略合并右节点
  3329. * @remind 如果同时忽略左右节点, 则该操作什么也不会做
  3330. * @example ```html <b>xxxx</b><b id="test">ooo</b><b>xxxx</b>
  3331. *
  3332. * <script> var demoNode = document.getElementById("test");
  3333. * UE.dom.domUtils.mergeSibling( demoNode, false, true ); //output:
  3334. * xxxxooo console.log( demoNode.innerHTML ); </script> ```
  3335. */
  3336. mergeSibling: function(node, ignorePre, ignoreNext) {
  3337. function merge(rtl, start, node) {
  3338. var next;
  3339. if((next = node[rtl]) && !domUtils.isBookmarkNode(next) &&
  3340. next.nodeType == 1 &&
  3341. domUtils.isSameElement(node, next)) {
  3342. while(next.firstChild) {
  3343. if(start == 'firstChild') {
  3344. node.insertBefore(next.lastChild, node.firstChild);
  3345. } else {
  3346. node.appendChild(next.firstChild);
  3347. }
  3348. }
  3349. domUtils.remove(next);
  3350. }
  3351. }!ignorePre && merge('previousSibling', 'firstChild', node);
  3352. !ignoreNext && merge('nextSibling', 'lastChild', node);
  3353. },
  3354. /**
  3355. * 设置节点node及其子节点不会被选中
  3356. *
  3357. * @method unSelectable
  3358. * @param {
  3359. * Element } node 需要执行操作的dom元素
  3360. * @remind 执行该操作后的节点, 将不能被鼠标选中
  3361. * @example ```javascript UE.dom.domUtils.unSelectable( document.body );
  3362. * ```
  3363. */
  3364. unSelectable: ie && browser.ie9below || browser.opera ?
  3365. function(node) {
  3366. // for ie9
  3367. node.onselectstart = function() {
  3368. return false;
  3369. };
  3370. node.onclick = node.onkeyup = node.onkeydown = function() {
  3371. return false;
  3372. };
  3373. node.unselectable = 'on';
  3374. node.setAttribute("unselectable", "on");
  3375. for(var i = 0, ci; ci = node.all[i++];) {
  3376. switch(ci.tagName.toLowerCase()) {
  3377. case 'iframe':
  3378. case 'textarea':
  3379. case 'input':
  3380. case 'select':
  3381. break;
  3382. default:
  3383. ci.unselectable = 'on';
  3384. node.setAttribute("unselectable", "on");
  3385. }
  3386. }
  3387. } : function(node) {
  3388. node.style.MozUserSelect = node.style.webkitUserSelect = node.style.msUserSelect = node.style.KhtmlUserSelect = 'none';
  3389. },
  3390. /**
  3391. * 删除节点node上的指定属性名称的属性
  3392. *
  3393. * @method removeAttributes
  3394. * @param {
  3395. * Node } node 需要删除属性的节点对象
  3396. * @param {
  3397. * String } attrNames 可以是空格隔开的多个属性名称,该操作将会依次删除相应的属性
  3398. * @example ```html <div id="wrap"> <span style="font-size:14px;"
  3399. * id="test" name="followMe">xxxxx</span> </div>
  3400. *
  3401. * <script>
  3402. *
  3403. * UE.dom.domUtils.removeAttributes( document.getElementById( "test" ),
  3404. * "id name" );
  3405. *
  3406. * //output: <span style="font-size:14px;">xxxxx</span> console.log(
  3407. * document.getElementById("wrap").innerHTML );
  3408. *
  3409. * </script> ```
  3410. */
  3411. /**
  3412. * 删除节点node上的指定属性名称的属性
  3413. *
  3414. * @method removeAttributes
  3415. * @param {
  3416. * Node } node 需要删除属性的节点对象
  3417. * @param {
  3418. * Array } attrNames 需要删除的属性名数组
  3419. * @example ```html <div id="wrap"> <span style="font-size:14px;"
  3420. * id="test" name="followMe">xxxxx</span> </div>
  3421. *
  3422. * <script>
  3423. *
  3424. * UE.dom.domUtils.removeAttributes( document.getElementById( "test" ),
  3425. * ["id", "name"] );
  3426. *
  3427. * //output: <span style="font-size:14px;">xxxxx</span> console.log(
  3428. * document.getElementById("wrap").innerHTML );
  3429. *
  3430. * </script> ```
  3431. */
  3432. removeAttributes: function(node, attrNames) {
  3433. attrNames = utils.isArray(attrNames) ? attrNames : utils
  3434. .trim(attrNames).replace(/[ ]{2,}/g, ' ').split(' ');
  3435. for(var i = 0, ci; ci = attrNames[i++];) {
  3436. ci = attrFix[ci] || ci;
  3437. switch(ci) {
  3438. case 'className':
  3439. node[ci] = '';
  3440. break;
  3441. case 'style':
  3442. node.style.cssText = '';
  3443. var val = node.getAttributeNode('style');
  3444. !browser.ie && val && node.removeAttributeNode(val);
  3445. }
  3446. node.removeAttribute(ci);
  3447. }
  3448. },
  3449. /**
  3450. * 在doc下创建一个标签名为tag,属性为attrs的元素
  3451. *
  3452. * @method createElement
  3453. * @param {
  3454. * DomDocument } doc 新创建的元素属于该document节点创建
  3455. * @param {
  3456. * String } tagName 需要创建的元素的标签名
  3457. * @param {
  3458. * Object } attrs 新创建的元素的属性key-value集合
  3459. * @return { Element } 新创建的元素对象
  3460. * @example ```javascript var ele = UE.dom.domUtils.createElement(
  3461. * document, 'div', { id: 'test' } );
  3462. *
  3463. * //output: DIV console.log( ele.tagName );
  3464. *
  3465. * //output: test console.log( ele.id );
  3466. *
  3467. * ```
  3468. */
  3469. createElement: function(doc, tag, attrs) {
  3470. return domUtils.setAttributes(doc.createElement(tag), attrs)
  3471. },
  3472. /**
  3473. * 为节点node添加属性attrs,attrs为属性键值对
  3474. *
  3475. * @method setAttributes
  3476. * @param {
  3477. * Element } node 需要设置属性的元素对象
  3478. * @param {
  3479. * Object } attrs 需要设置的属性名-值对
  3480. * @return { Element } 设置属性的元素对象
  3481. * @example ```html <span id="test"></span>
  3482. *
  3483. * <script>
  3484. *
  3485. * var testNode = UE.dom.domUtils.setAttributes(
  3486. * document.getElementById( "test" ), { id: 'demo' } );
  3487. *
  3488. * //output: demo console.log( testNode.id );
  3489. *
  3490. * </script>
  3491. *
  3492. */
  3493. setAttributes: function(node, attrs) {
  3494. for(var attr in attrs) {
  3495. if(attrs.hasOwnProperty(attr)) {
  3496. var value = attrs[attr];
  3497. switch(attr) {
  3498. case 'class':
  3499. // ie下要这样赋值,setAttribute不起作用
  3500. node.className = value;
  3501. break;
  3502. case 'style':
  3503. node.style.cssText = node.style.cssText + ";" +
  3504. value;
  3505. break;
  3506. case 'innerHTML':
  3507. node[attr] = value;
  3508. break;
  3509. case 'value':
  3510. node.value = value;
  3511. break;
  3512. default:
  3513. node.setAttribute(attrFix[attr] || attr, value);
  3514. }
  3515. }
  3516. }
  3517. return node;
  3518. },
  3519. /**
  3520. * 获取元素element经过计算后的样式值
  3521. *
  3522. * @method getComputedStyle
  3523. * @param {
  3524. * Element } element 需要获取样式的元素对象
  3525. * @param {
  3526. * String } styleName 需要获取的样式名
  3527. * @return { String } 获取到的样式值
  3528. * @example ```html <style type="text/css"> #test { font-size: 15px; }
  3529. * </style>
  3530. *
  3531. * <span id="test"></span>
  3532. *
  3533. * <script> //output: 15px console.log(
  3534. * UE.dom.domUtils.getComputedStyle( document.getElementById( "test" ),
  3535. * 'font-size' ) ); </script> ```
  3536. */
  3537. getComputedStyle: function(element, styleName) {
  3538. // 一下的属性单独处理
  3539. var pros = 'width height top left';
  3540. if(pros.indexOf(styleName) > -1) {
  3541. return element['offset' + styleName.replace(/^\w/, function(s) {
  3542. return s.toUpperCase()
  3543. })] + 'px';
  3544. }
  3545. // 忽略文本节点
  3546. if(element.nodeType == 3) {
  3547. element = element.parentNode;
  3548. }
  3549. // ie下font-size若body下定义了font-size,则从currentStyle里会取到这个font-size.
  3550. // 取不到实际值,故此修改.
  3551. if(browser.ie && browser.version < 9 && styleName == 'font-size' &&
  3552. !element.style.fontSize && !dtd.$empty[element.tagName] &&
  3553. !dtd.$nonChild[element.tagName]) {
  3554. var span = element.ownerDocument.createElement('span');
  3555. span.style.cssText = 'padding:0;border:0;font-family:simsun;';
  3556. span.innerHTML = '.';
  3557. element.appendChild(span);
  3558. var result = span.offsetHeight;
  3559. element.removeChild(span);
  3560. span = null;
  3561. return result + 'px';
  3562. }
  3563. try {
  3564. var value = domUtils.getStyle(element, styleName) ||
  3565. (window.getComputedStyle ?
  3566. domUtils.getWindow(element).getComputedStyle(
  3567. element, '')
  3568. .getPropertyValue(styleName) :
  3569. (element.currentStyle || element.style)[utils
  3570. .cssStyleToDomStyle(styleName)]);
  3571. } catch(e) {
  3572. return "";
  3573. }
  3574. return utils.transUnitToPx(utils.fixColor(styleName, value));
  3575. },
  3576. /**
  3577. * 删除元素element指定的className
  3578. *
  3579. * @method removeClasses
  3580. * @param {
  3581. * Element } ele 需要删除class的元素节点
  3582. * @param {
  3583. * String } classNames 需要删除的className, 多个className之间以空格分开
  3584. * @example ```html <span id="test" class="test1 test2 test3">xxx</span>
  3585. *
  3586. * <script>
  3587. *
  3588. * var testNode = document.getElementById( "test" );
  3589. * UE.dom.domUtils.removeClasses( testNode, "test1 test2" );
  3590. *
  3591. * //output: test3 console.log( testNode.className );
  3592. *
  3593. * </script> ```
  3594. */
  3595. /**
  3596. * 删除元素element指定的className
  3597. *
  3598. * @method removeClasses
  3599. * @param {
  3600. * Element } ele 需要删除class的元素节点
  3601. * @param {
  3602. * Array } classNames 需要删除的className数组
  3603. * @example ```html <span id="test" class="test1 test2 test3">xxx</span>
  3604. *
  3605. * <script>
  3606. *
  3607. * var testNode = document.getElementById( "test" );
  3608. * UE.dom.domUtils.removeClasses( testNode, ["test1", "test2"] );
  3609. *
  3610. * //output: test3 console.log( testNode.className );
  3611. *
  3612. * </script> ```
  3613. */
  3614. removeClasses: function(elm, classNames) {
  3615. classNames = utils.isArray(classNames) ? classNames : utils
  3616. .trim(classNames).replace(/[ ]{2,}/g, ' ').split(' ');
  3617. for(var i = 0, ci, cls = elm.className; ci = classNames[i++];) {
  3618. cls = cls.replace(new RegExp('\\b' + ci + '\\b'), '')
  3619. }
  3620. cls = utils.trim(cls).replace(/[ ]{2,}/g, ' ');
  3621. if(cls) {
  3622. elm.className = cls;
  3623. } else {
  3624. domUtils.removeAttributes(elm, ['class']);
  3625. }
  3626. },
  3627. /**
  3628. * 给元素element添加className
  3629. *
  3630. * @method addClass
  3631. * @param {
  3632. * Node } ele 需要增加className的元素
  3633. * @param {
  3634. * String } classNames 需要添加的className, 多个className之间以空格分割
  3635. * @remind 相同的类名不会被重复添加
  3636. * @example ```html <span id="test" class="cls1 cls2"></span>
  3637. *
  3638. * <script> var testNode = document.getElementById("test");
  3639. *
  3640. * UE.dom.domUtils.addClass( testNode, "cls2 cls3 cls4" );
  3641. *
  3642. * //output: cl1 cls2 cls3 cls4 console.log( testNode.className );
  3643. *
  3644. * <script> ```
  3645. */
  3646. /**
  3647. * 给元素element添加className
  3648. *
  3649. * @method addClass
  3650. * @param {
  3651. * Node } ele 需要增加className的元素
  3652. * @param {
  3653. * Array } classNames 需要添加的className的数组
  3654. * @remind 相同的类名不会被重复添加
  3655. * @example ```html <span id="test" class="cls1 cls2"></span>
  3656. *
  3657. * <script> var testNode = document.getElementById("test");
  3658. *
  3659. * UE.dom.domUtils.addClass( testNode, ["cls2", "cls3", "cls4"] );
  3660. *
  3661. * //output: cl1 cls2 cls3 cls4 console.log( testNode.className );
  3662. *
  3663. * <script> ```
  3664. */
  3665. addClass: function(elm, classNames) {
  3666. if(!elm)
  3667. return;
  3668. classNames = utils.trim(classNames).replace(/[ ]{2,}/g, ' ')
  3669. .split(' ');
  3670. for(var i = 0, ci, cls = elm.className; ci = classNames[i++];) {
  3671. if(!new RegExp('\\b' + ci + '\\b').test(cls)) {
  3672. cls += ' ' + ci;
  3673. }
  3674. }
  3675. elm.className = utils.trim(cls);
  3676. },
  3677. /**
  3678. * 判断元素element是否包含给定的样式类名className
  3679. *
  3680. * @method hasClass
  3681. * @param {
  3682. * Node } ele 需要检测的元素
  3683. * @param {
  3684. * String } classNames 需要检测的className, 多个className之间用空格分割
  3685. * @return { Boolean } 元素是否包含所有给定的className
  3686. * @example ```html <span id="test1" class="cls1 cls2"></span>
  3687. *
  3688. * <script> var test1 = document.getElementById("test1");
  3689. *
  3690. * //output: false console.log( UE.dom.domUtils.hasClass( test1, "cls2
  3691. * cls1 cls3" ) );
  3692. *
  3693. * //output: true console.log( UE.dom.domUtils.hasClass( test1, "cls2
  3694. * cls1" ) ); </script> ```
  3695. */
  3696. /**
  3697. * 判断元素element是否包含给定的样式类名className
  3698. *
  3699. * @method hasClass
  3700. * @param {
  3701. * Node } ele 需要检测的元素
  3702. * @param {
  3703. * Array } classNames 需要检测的className数组
  3704. * @return { Boolean } 元素是否包含所有给定的className
  3705. * @example ```html <span id="test1" class="cls1 cls2"></span>
  3706. *
  3707. * <script> var test1 = document.getElementById("test1");
  3708. *
  3709. * //output: false console.log( UE.dom.domUtils.hasClass( test1, [
  3710. * "cls2", "cls1", "cls3" ] ) );
  3711. *
  3712. * //output: true console.log( UE.dom.domUtils.hasClass( test1, [
  3713. * "cls2", "cls1" ]) ); </script> ```
  3714. */
  3715. hasClass: function(element, className) {
  3716. if(utils.isRegExp(className)) {
  3717. return className.test(element.className)
  3718. }
  3719. className = utils.trim(className).replace(/[ ]{2,}/g, ' ')
  3720. .split(' ');
  3721. for(var i = 0, ci, cls = element.className; ci = className[i++];) {
  3722. if(!new RegExp('\\b' + ci + '\\b', 'i').test(cls)) {
  3723. return false;
  3724. }
  3725. }
  3726. return i - 1 == className.length;
  3727. },
  3728. /**
  3729. * 阻止事件默认行为
  3730. *
  3731. * @method preventDefault
  3732. * @param {
  3733. * Event } evt 需要阻止默认行为的事件对象
  3734. * @example ```javascript UE.dom.domUtils.preventDefault( evt ); ```
  3735. */
  3736. preventDefault: function(evt) {
  3737. evt.preventDefault ?
  3738. evt.preventDefault() :
  3739. (evt.returnValue = false);
  3740. },
  3741. /**
  3742. * 删除元素element指定的样式
  3743. *
  3744. * @method removeStyle
  3745. * @param {
  3746. * Element } element 需要删除样式的元素
  3747. * @param {
  3748. * String } styleName 需要删除的样式名
  3749. * @example ```html <span id="test" style="color: red; background:
  3750. * blue;"></span>
  3751. *
  3752. * <script>
  3753. *
  3754. * var testNode = document.getElementById("test");
  3755. *
  3756. * UE.dom.domUtils.removeStyle( testNode, 'color' );
  3757. *
  3758. * //output: background: blue; console.log( testNode.style.cssText );
  3759. *
  3760. * </script> ```
  3761. */
  3762. removeStyle: function(element, name) {
  3763. if(browser.ie) {
  3764. // 针对color先单独处理一下
  3765. if(name == 'color') {
  3766. name = '(^|;)' + name;
  3767. }
  3768. element.style.cssText = element.style.cssText.replace(
  3769. new RegExp(name + '[^:]*:[^;]+;?', 'ig'), '')
  3770. } else {
  3771. if(element.style.removeProperty) {
  3772. element.style.removeProperty(name);
  3773. } else {
  3774. element.style.removeAttribute(utils
  3775. .cssStyleToDomStyle(name));
  3776. }
  3777. }
  3778. if(!element.style.cssText) {
  3779. domUtils.removeAttributes(element, ['style']);
  3780. }
  3781. },
  3782. /**
  3783. * 获取元素element的style属性的指定值
  3784. *
  3785. * @method getStyle
  3786. * @param {
  3787. * Element } element 需要获取属性值的元素
  3788. * @param {
  3789. * String } styleName 需要获取的style的名称
  3790. * @warning 该方法仅获取元素style属性中所标明的值
  3791. * @return { String } 该元素包含指定的style属性值
  3792. * @example ```html <div id="test" style="color: red;"></div>
  3793. *
  3794. * <script>
  3795. *
  3796. * var testNode = document.getElementById( "test" );
  3797. *
  3798. * //output: red console.log( UE.dom.domUtils.getStyle( testNode,
  3799. * "color" ) );
  3800. *
  3801. * //output: "" console.log( UE.dom.domUtils.getStyle( testNode,
  3802. * "background" ) );
  3803. *
  3804. * </script> ```
  3805. */
  3806. getStyle: function(element, name) {
  3807. var value = element.style[utils.cssStyleToDomStyle(name)];
  3808. return utils.fixColor(name, value);
  3809. },
  3810. /**
  3811. * 为元素element设置样式属性值
  3812. *
  3813. * @method setStyle
  3814. * @param {
  3815. * Element } element 需要设置样式的元素
  3816. * @param {
  3817. * String } styleName 样式名
  3818. * @param {
  3819. * String } styleValue 样式值
  3820. * @example ```html <div id="test"></div>
  3821. *
  3822. * <script>
  3823. *
  3824. * var testNode = document.getElementById( "test" );
  3825. *
  3826. * //output: "" console.log( testNode.style.color );
  3827. *
  3828. * UE.dom.domUtils.setStyle( testNode, 'color', 'red' ); //output: "red"
  3829. * console.log( testNode.style.color );
  3830. *
  3831. * </script> ```
  3832. */
  3833. setStyle: function(element, name, value) {
  3834. element.style[utils.cssStyleToDomStyle(name)] = value;
  3835. if(!utils.trim(element.style.cssText)) {
  3836. this.removeAttributes(element, 'style')
  3837. }
  3838. },
  3839. /**
  3840. * 为元素element设置多个样式属性值
  3841. *
  3842. * @method setStyles
  3843. * @param {
  3844. * Element } element 需要设置样式的元素
  3845. * @param {
  3846. * Object } styles 样式名值对
  3847. * @example ```html <div id="test"></div>
  3848. *
  3849. * <script>
  3850. *
  3851. * var testNode = document.getElementById( "test" );
  3852. *
  3853. * //output: "" console.log( testNode.style.color );
  3854. *
  3855. * UE.dom.domUtils.setStyles( testNode, { 'color': 'red' } ); //output:
  3856. * "red" console.log( testNode.style.color );
  3857. *
  3858. * </script> ```
  3859. */
  3860. setStyles: function(element, styles) {
  3861. for(var name in styles) {
  3862. if(styles.hasOwnProperty(name)) {
  3863. domUtils.setStyle(element, name, styles[name]);
  3864. }
  3865. }
  3866. },
  3867. /**
  3868. * 删除_moz_dirty属性
  3869. *
  3870. * @private
  3871. * @method removeDirtyAttr
  3872. */
  3873. removeDirtyAttr: function(node) {
  3874. for(var i = 0, ci, nodes = node.getElementsByTagName('*'); ci = nodes[i++];) {
  3875. ci.removeAttribute('_moz_dirty');
  3876. }
  3877. node.removeAttribute('_moz_dirty');
  3878. },
  3879. /**
  3880. * 获取子节点的数量
  3881. *
  3882. * @method getChildCount
  3883. * @param {
  3884. * Element } node 需要检测的元素
  3885. * @return { Number } 给定的node元素的子节点数量
  3886. * @example ```html <div id="test"> <span></span> </div>
  3887. *
  3888. * <script>
  3889. *
  3890. * //output: 3 console.log( UE.dom.domUtils.getChildCount(
  3891. * document.getElementById("test") ) );
  3892. *
  3893. * </script> ```
  3894. */
  3895. /**
  3896. * 根据给定的过滤规则, 获取符合条件的子节点的数量
  3897. *
  3898. * @method getChildCount
  3899. * @param {
  3900. * Element } node 需要检测的元素
  3901. * @param {
  3902. * Function } fn 过滤器, 要求对符合条件的子节点返回true, 反之则要求返回false
  3903. * @return { Number } 符合过滤条件的node元素的子节点数量
  3904. * @example ```html <div id="test"> <span></span> </div>
  3905. *
  3906. * <script>
  3907. *
  3908. * //output: 1 console.log( UE.dom.domUtils.getChildCount(
  3909. * document.getElementById("test"), function ( node ) {
  3910. *
  3911. * return node.nodeType === 1; } ) );
  3912. *
  3913. * </script> ```
  3914. */
  3915. getChildCount: function(node, fn) {
  3916. var count = 0,
  3917. first = node.firstChild;
  3918. fn = fn || function() {
  3919. return 1;
  3920. };
  3921. while(first) {
  3922. if(fn(first)) {
  3923. count++;
  3924. }
  3925. first = first.nextSibling;
  3926. }
  3927. return count;
  3928. },
  3929. /**
  3930. * 判断给定节点是否为空节点
  3931. *
  3932. * @method isEmptyNode
  3933. * @param {
  3934. * Node } node 需要检测的节点对象
  3935. * @return { Boolean } 节点是否为空
  3936. * @example ```javascript UE.dom.domUtils.isEmptyNode( document.body );
  3937. * ```
  3938. */
  3939. isEmptyNode: function(node) {
  3940. return !node.firstChild ||
  3941. domUtils.getChildCount(node, function(node) {
  3942. return !domUtils.isBr(node) &&
  3943. !domUtils.isBookmarkNode(node) &&
  3944. !domUtils.isWhitespace(node)
  3945. }) == 0
  3946. },
  3947. clearSelectedArr: function(nodes) {
  3948. var node;
  3949. while(node = nodes.pop()) {
  3950. domUtils.removeAttributes(node, ['class']);
  3951. }
  3952. },
  3953. /**
  3954. * 将显示区域滚动到指定节点的位置
  3955. *
  3956. * @method scrollToView
  3957. * @param {Node}
  3958. * node 节点
  3959. * @param {window}
  3960. * win window对象
  3961. * @param {Number}
  3962. * offsetTop 距离上方的偏移量
  3963. */
  3964. scrollToView: function(node, win, offsetTop) {
  3965. var getViewPaneSize = function() {
  3966. var doc = win.document,
  3967. mode = doc.compatMode == 'CSS1Compat';
  3968. return {
  3969. width: (mode ?
  3970. doc.documentElement.clientWidth :
  3971. doc.body.clientWidth) ||
  3972. 0,
  3973. height: (mode ?
  3974. doc.documentElement.clientHeight :
  3975. doc.body.clientHeight) ||
  3976. 0
  3977. };
  3978. },
  3979. getScrollPosition = function(win) {
  3980. if('pageXOffset' in win) {
  3981. return {
  3982. x: win.pageXOffset || 0,
  3983. y: win.pageYOffset || 0
  3984. };
  3985. } else {
  3986. var doc = win.document;
  3987. return {
  3988. x: doc.documentElement.scrollLeft ||
  3989. doc.body.scrollLeft || 0,
  3990. y: doc.documentElement.scrollTop || doc.body.scrollTop ||
  3991. 0
  3992. };
  3993. }
  3994. };
  3995. var winHeight = getViewPaneSize().height,
  3996. offset = winHeight * -1 +
  3997. offsetTop;
  3998. offset += (node.offsetHeight || 0);
  3999. var elementPosition = domUtils.getXY(node);
  4000. offset += elementPosition.y;
  4001. var currentScroll = getScrollPosition(win).y;
  4002. // offset += 50;
  4003. if(offset > currentScroll || offset < currentScroll - winHeight) {
  4004. win.scrollTo(0, offset + (offset < 0 ? -20 : 20));
  4005. }
  4006. },
  4007. /**
  4008. * 判断给定节点是否为br
  4009. *
  4010. * @method isBr
  4011. * @param {
  4012. * Node } node 需要判断的节点对象
  4013. * @return { Boolean } 给定的节点是否是br节点
  4014. */
  4015. isBr: function(node) {
  4016. return node.nodeType == 1 && node.tagName == 'BR';
  4017. },
  4018. /**
  4019. * 判断给定的节点是否是一个“填充”节点
  4020. *
  4021. * @private
  4022. * @method isFillChar
  4023. * @param {
  4024. * Node } node 需要判断的节点
  4025. * @param {
  4026. * Boolean } isInStart 是否从节点内容的开始位置匹配
  4027. * @returns { Boolean } 节点是否是填充节点
  4028. */
  4029. isFillChar: function(node, isInStart) {
  4030. if(node.nodeType != 3)
  4031. return false;
  4032. var text = node.nodeValue;
  4033. if(isInStart) {
  4034. return new RegExp('^' + domUtils.fillChar).test(text)
  4035. }
  4036. return !text.replace(new RegExp(domUtils.fillChar, 'g'), '').length
  4037. },
  4038. isStartInblock: function(range) {
  4039. var tmpRange = range.cloneRange(),
  4040. flag = 0,
  4041. start = tmpRange.startContainer,
  4042. tmp;
  4043. if(start.nodeType == 1 && start.childNodes[tmpRange.startOffset]) {
  4044. start = start.childNodes[tmpRange.startOffset];
  4045. var pre = start.previousSibling;
  4046. while(pre && domUtils.isFillChar(pre)) {
  4047. start = pre;
  4048. pre = pre.previousSibling;
  4049. }
  4050. }
  4051. if(this.isFillChar(start, true) && tmpRange.startOffset == 1) {
  4052. tmpRange.setStartBefore(start);
  4053. start = tmpRange.startContainer;
  4054. }
  4055. while(start && domUtils.isFillChar(start)) {
  4056. tmp = start;
  4057. start = start.previousSibling
  4058. }
  4059. if(tmp) {
  4060. tmpRange.setStartBefore(tmp);
  4061. start = tmpRange.startContainer;
  4062. }
  4063. if(start.nodeType == 1 && domUtils.isEmptyNode(start) &&
  4064. tmpRange.startOffset == 1) {
  4065. tmpRange.setStart(start, 0).collapse(true);
  4066. }
  4067. while(!tmpRange.startOffset) {
  4068. start = tmpRange.startContainer;
  4069. if(domUtils.isBlockElm(start) || domUtils.isBody(start)) {
  4070. flag = 1;
  4071. break;
  4072. }
  4073. var pre = tmpRange.startContainer.previousSibling,
  4074. tmpNode;
  4075. if(!pre) {
  4076. tmpRange.setStartBefore(tmpRange.startContainer);
  4077. } else {
  4078. while(pre && domUtils.isFillChar(pre)) {
  4079. tmpNode = pre;
  4080. pre = pre.previousSibling;
  4081. }
  4082. if(tmpNode) {
  4083. tmpRange.setStartBefore(tmpNode);
  4084. } else {
  4085. tmpRange.setStartBefore(tmpRange.startContainer);
  4086. }
  4087. }
  4088. }
  4089. return flag && !domUtils.isBody(tmpRange.startContainer) ? 1 : 0;
  4090. },
  4091. /**
  4092. * 判断给定的元素是否是一个空元素
  4093. *
  4094. * @method isEmptyBlock
  4095. * @param {
  4096. * Element } node 需要判断的元素
  4097. * @return { Boolean } 是否是空元素
  4098. * @example ```html <div id="test"></div>
  4099. *
  4100. * <script> //output: true console.log( UE.dom.domUtils.isEmptyBlock(
  4101. * document.getElementById("test") ) ); </script> ```
  4102. */
  4103. /**
  4104. * 根据指定的判断规则判断给定的元素是否是一个空元素
  4105. *
  4106. * @method isEmptyBlock
  4107. * @param {
  4108. * Element } node 需要判断的元素
  4109. * @param {
  4110. * RegExp } reg 对内容执行判断的正则表达式对象
  4111. * @return { Boolean } 是否是空元素
  4112. */
  4113. isEmptyBlock: function(node, reg) {
  4114. if(node.nodeType != 1)
  4115. return 0;
  4116. reg = reg ||
  4117. new RegExp('[ \xa0\t\r\n' + domUtils.fillChar + ']', 'g');
  4118. if(node[browser.ie ? 'innerText' : 'textContent'].replace(reg, '').length > 0) {
  4119. return 0;
  4120. }
  4121. for(var n in dtd.$isNotEmpty) {
  4122. if(node.getElementsByTagName(n).length) {
  4123. return 0;
  4124. }
  4125. }
  4126. return 1;
  4127. },
  4128. /**
  4129. * 移动元素使得该元素的位置移动指定的偏移量的距离
  4130. *
  4131. * @method setViewportOffset
  4132. * @param {
  4133. * Element } element 需要设置偏移量的元素
  4134. * @param {
  4135. * Object } offset 偏移量, 形如{ left: 100, top: 50 }的一个键值对,
  4136. * 表示该元素将在 现有的位置上向水平方向偏移offset.left的距离, 在竖直方向上偏移
  4137. * offset.top的距离
  4138. * @example ```html <div id="test" style="top: 100px; left: 50px;
  4139. * position: absolute;"></div>
  4140. *
  4141. * <script>
  4142. *
  4143. * var testNode = document.getElementById("test");
  4144. *
  4145. * UE.dom.domUtils.setViewportOffset( testNode, { left: 200, top: 50 } );
  4146. *
  4147. * //output: top: 300px; left: 100px; position: absolute; console.log(
  4148. * testNode.style.cssText );
  4149. *
  4150. * </script> ```
  4151. */
  4152. setViewportOffset: function(element, offset) {
  4153. var left = parseInt(element.style.left) | 0;
  4154. var top = parseInt(element.style.top) | 0;
  4155. var rect = element.getBoundingClientRect();
  4156. var offsetLeft = offset.left - rect.left;
  4157. var offsetTop = offset.top - rect.top;
  4158. if(offsetLeft) {
  4159. element.style.left = left + offsetLeft + 'px';
  4160. }
  4161. if(offsetTop) {
  4162. element.style.top = top + offsetTop + 'px';
  4163. }
  4164. },
  4165. /**
  4166. * 用“填充字符”填充节点
  4167. *
  4168. * @method fillNode
  4169. * @private
  4170. * @param {
  4171. * DomDocument } doc 填充的节点所在的docment对象
  4172. * @param {
  4173. * Node } node 需要填充的节点对象
  4174. * @example ```html <div id="test"></div>
  4175. *
  4176. * <script> var testNode = document.getElementById("test");
  4177. *
  4178. * //output: 0 console.log( testNode.childNodes.length );
  4179. *
  4180. * UE.dom.domUtils.fillNode( document, testNode );
  4181. *
  4182. * //output: 1 console.log( testNode.childNodes.length );
  4183. *
  4184. * </script> ```
  4185. */
  4186. fillNode: function(doc, node) {
  4187. var tmpNode = browser.ie ?
  4188. doc.createTextNode(domUtils.fillChar) :
  4189. doc.createElement('br');
  4190. node.innerHTML = '';
  4191. node.appendChild(tmpNode);
  4192. },
  4193. /**
  4194. * 把节点src的所有子节点追加到另一个节点tag上去
  4195. *
  4196. * @method moveChild
  4197. * @param {
  4198. * Node } src 源节点, 该节点下的所有子节点将被移除
  4199. * @param {
  4200. * Node } tag 目标节点, 从源节点移除的子节点将被追加到该节点下
  4201. * @example ```html <div id="test1"> <span></span> </div> <div
  4202. * id="test2"> <div></div> </div>
  4203. *
  4204. * <script>
  4205. *
  4206. * var test1 = document.getElementById("test1"), test2 =
  4207. * document.getElementById("test2");
  4208. *
  4209. * UE.dom.domUtils.moveChild( test1, test2 );
  4210. *
  4211. * //output: ""(空字符串) console.log( test1.innerHTML );
  4212. *
  4213. * //output: "<div></div><span></span>" console.log( test2.innerHTML );
  4214. *
  4215. * </script> ```
  4216. */
  4217. /**
  4218. * 把节点src的所有子节点移动到另一个节点tag上去, 可以通过dir参数控制附加的行为是“追加”还是“插入顶部”
  4219. *
  4220. * @method moveChild
  4221. * @param {
  4222. * Node } src 源节点, 该节点下的所有子节点将被移除
  4223. * @param {
  4224. * Node } tag 目标节点, 从源节点移除的子节点将被附加到该节点下
  4225. * @param {
  4226. * Boolean } dir 附加方式, 如果为true, 则附加进去的节点将被放到目标节点的顶部, 反之,则放到末尾
  4227. * @example ```html <div id="test1"> <span></span> </div> <div
  4228. * id="test2"> <div></div> </div>
  4229. *
  4230. * <script>
  4231. *
  4232. * var test1 = document.getElementById("test1"), test2 =
  4233. * document.getElementById("test2");
  4234. *
  4235. * UE.dom.domUtils.moveChild( test1, test2, true );
  4236. *
  4237. * //output: ""(空字符串) console.log( test1.innerHTML );
  4238. *
  4239. * //output: "<span></span><div></div>" console.log( test2.innerHTML );
  4240. *
  4241. * </script> ```
  4242. */
  4243. moveChild: function(src, tag, dir) {
  4244. while(src.firstChild) {
  4245. if(dir && tag.firstChild) {
  4246. tag.insertBefore(src.lastChild, tag.firstChild);
  4247. } else {
  4248. tag.appendChild(src.firstChild);
  4249. }
  4250. }
  4251. },
  4252. /**
  4253. * 判断节点的标签上是否不存在任何属性
  4254. *
  4255. * @method hasNoAttributes
  4256. * @private
  4257. * @param {
  4258. * Node } node 需要检测的节点对象
  4259. * @return { Boolean } 节点是否不包含任何属性
  4260. * @example ```html <div id="test"><span>xxxx</span></div>
  4261. *
  4262. * <script>
  4263. *
  4264. * //output: false console.log( UE.dom.domUtils.hasNoAttributes(
  4265. * document.getElementById("test") ) );
  4266. *
  4267. * //output: true console.log( UE.dom.domUtils.hasNoAttributes(
  4268. * document.getElementById("test").firstChild ) );
  4269. *
  4270. * </script> ```
  4271. */
  4272. hasNoAttributes: function(node) {
  4273. return browser.ie ?
  4274. /^<\w+\s*?>/.test(node.outerHTML) :
  4275. node.attributes.length == 0;
  4276. },
  4277. /**
  4278. * 检测节点是否是UEditor所使用的辅助节点
  4279. *
  4280. * @method isCustomeNode
  4281. * @private
  4282. * @param {
  4283. * Node } node 需要检测的节点
  4284. * @remind 辅助节点是指编辑器要完成工作临时添加的节点, 在输出的时候将会从编辑器内移除, 不会影响最终的结果。
  4285. * @return { Boolean } 给定的节点是否是一个辅助节点
  4286. */
  4287. isCustomeNode: function(node) {
  4288. return node.nodeType == 1 && node.getAttribute('_ue_custom_node_');
  4289. },
  4290. /**
  4291. * 检测节点的标签是否是给定的标签
  4292. *
  4293. * @method isTagNode
  4294. * @param {
  4295. * Node } node 需要检测的节点对象
  4296. * @param {
  4297. * String } tagName 标签
  4298. * @return { Boolean } 节点的标签是否是给定的标签
  4299. * @example ```html <div id="test"></div>
  4300. *
  4301. * <script>
  4302. *
  4303. * //output: true console.log( UE.dom.domUtils.isTagNode(
  4304. * document.getElementById("test"), "div" ) );
  4305. *
  4306. * </script> ```
  4307. */
  4308. isTagNode: function(node, tagNames) {
  4309. return node.nodeType == 1 &&
  4310. new RegExp('\\b' + node.tagName + '\\b', 'i')
  4311. .test(tagNames)
  4312. },
  4313. /**
  4314. * 给定一个节点数组,在通过指定的过滤器过滤后, 获取其中满足过滤条件的第一个节点
  4315. *
  4316. * @method filterNodeList
  4317. * @param {
  4318. * Array } nodeList 需要过滤的节点数组
  4319. * @param {
  4320. * Function } fn 过滤器, 对符合条件的节点, 执行结果返回true, 反之则返回false
  4321. * @return { Node | NULL } 如果找到符合过滤条件的节点, 则返回该节点, 否则返回NULL
  4322. * @example ```javascript var divNodes =
  4323. * document.getElementsByTagName("div"); divNodes =
  4324. * [].slice.call( divNodes, 0 );
  4325. *
  4326. * //output: null console.log( UE.dom.domUtils.filterNodeList( divNodes,
  4327. * function ( node ) { return node.tagName.toLowerCase() !== 'div'; } ) );
  4328. * ```
  4329. */
  4330. /**
  4331. * 给定一个节点数组nodeList和一组标签名tagNames, 获取其中能够匹配标签名的节点集合中的第一个节点
  4332. *
  4333. * @method filterNodeList
  4334. * @param {
  4335. * Array } nodeList 需要过滤的节点数组
  4336. * @param {
  4337. * String } tagNames 需要匹配的标签名, 多个标签名之间用空格分割
  4338. * @return { Node | NULL } 如果找到标签名匹配的节点, 则返回该节点, 否则返回NULL
  4339. * @example ```javascript var divNodes =
  4340. * document.getElementsByTagName("div"); divNodes =
  4341. * [].slice.call( divNodes, 0 );
  4342. *
  4343. * //output: null console.log( UE.dom.domUtils.filterNodeList( divNodes,
  4344. * 'a span' ) ); ```
  4345. */
  4346. /**
  4347. * 给定一个节点数组,在通过指定的过滤器过滤后, 如果参数forAll为true, 则会返回所有满足过滤 条件的节点集合, 否则,
  4348. * 返回满足条件的节点集合中的第一个节点
  4349. *
  4350. * @method filterNodeList
  4351. * @param {
  4352. * Array } nodeList 需要过滤的节点数组
  4353. * @param {
  4354. * Function } fn 过滤器, 对符合条件的节点, 执行结果返回true, 反之则返回false
  4355. * @param {
  4356. * Boolean } forAll 是否返回整个节点数组, 如果该参数为false, 则返回节点集合中的第一个节点
  4357. * @return { Array | Node | NULL } 如果找到符合过滤条件的节点, 则根据参数forAll的值决定返回满足
  4358. * 过滤条件的节点数组或第一个节点, 否则返回NULL
  4359. * @example ```javascript var divNodes =
  4360. * document.getElementsByTagName("div"); divNodes =
  4361. * [].slice.call( divNodes, 0 );
  4362. *
  4363. * //output: 3(假定有3个div) console.log( divNodes.length );
  4364. *
  4365. * var nodes = UE.dom.domUtils.filterNodeList( divNodes, function ( node ) {
  4366. * return node.tagName.toLowerCase() === 'div'; }, true );
  4367. *
  4368. * //output: 3 console.log( nodes.length );
  4369. *
  4370. * var node = UE.dom.domUtils.filterNodeList( divNodes, function ( node ) {
  4371. * return node.tagName.toLowerCase() === 'div'; }, false );
  4372. *
  4373. * //output: div console.log( node.nodeName ); ```
  4374. */
  4375. filterNodeList: function(nodelist, filter, forAll) {
  4376. var results = [];
  4377. if(!utils.isFunction(filter)) {
  4378. var str = filter;
  4379. filter = function(n) {
  4380. return utils.indexOf(utils.isArray(str) ? str : str
  4381. .split(' '), n.tagName.toLowerCase()) != -1
  4382. };
  4383. }
  4384. utils.each(nodelist, function(n) {
  4385. filter(n) && results.push(n)
  4386. });
  4387. return results.length == 0 ? null : results.length == 1 || !forAll ?
  4388. results[0] :
  4389. results
  4390. },
  4391. /**
  4392. * 查询给定的range选区是否在给定的node节点内,且在该节点的最末尾
  4393. *
  4394. * @method isInNodeEndBoundary
  4395. * @param {
  4396. * UE.dom.Range } rng 需要判断的range对象, 该对象的startContainer不能为NULL
  4397. * @param node
  4398. * 需要检测的节点对象
  4399. * @return { Number } 如果给定的选取range对象是在node内部的最末端, 则返回1, 否则返回0
  4400. */
  4401. isInNodeEndBoundary: function(rng, node) {
  4402. var start = rng.startContainer;
  4403. if(start.nodeType == 3 &&
  4404. rng.startOffset != start.nodeValue.length) {
  4405. return 0;
  4406. }
  4407. if(start.nodeType == 1 &&
  4408. rng.startOffset != start.childNodes.length) {
  4409. return 0;
  4410. }
  4411. while(start !== node) {
  4412. if(start.nextSibling) {
  4413. return 0
  4414. };
  4415. start = start.parentNode;
  4416. }
  4417. return 1;
  4418. },
  4419. isBoundaryNode: function(node, dir) {
  4420. var tmp;
  4421. while(!domUtils.isBody(node)) {
  4422. tmp = node;
  4423. node = node.parentNode;
  4424. if(tmp !== node[dir]) {
  4425. return false;
  4426. }
  4427. }
  4428. return true;
  4429. },
  4430. fillHtml: browser.ie11below ? '&nbsp;' : '<br/>'
  4431. };
  4432. var fillCharReg = new RegExp(domUtils.fillChar, 'g');
  4433. // core/Range.js
  4434. /**
  4435. * Range封装
  4436. *
  4437. * @file
  4438. * @module UE.dom
  4439. * @class Range
  4440. * @since 1.2.6.1
  4441. */
  4442. /**
  4443. * dom操作封装
  4444. *
  4445. * @unfile
  4446. * @module UE.dom
  4447. */
  4448. /**
  4449. * Range实现类,本类是UEditor底层核心类,封装不同浏览器之间的Range操作。
  4450. *
  4451. * @unfile
  4452. * @module UE.dom
  4453. * @class Range
  4454. */
  4455. (function() {
  4456. var guid = 0,
  4457. fillChar = domUtils.fillChar,
  4458. fillData;
  4459. /**
  4460. * 更新range的collapse状态
  4461. *
  4462. * @param {Range}
  4463. * range range对象
  4464. */
  4465. function updateCollapse(range) {
  4466. range.collapsed = range.startContainer && range.endContainer &&
  4467. range.startContainer === range.endContainer &&
  4468. range.startOffset == range.endOffset;
  4469. }
  4470. function selectOneNode(rng) {
  4471. return !rng.collapsed && rng.startContainer.nodeType == 1 &&
  4472. rng.startContainer === rng.endContainer &&
  4473. rng.endOffset - rng.startOffset == 1
  4474. }
  4475. function setEndPoint(toStart, node, offset, range) {
  4476. // 如果node是自闭合标签要处理
  4477. if(node.nodeType == 1 &&
  4478. (dtd.$empty[node.tagName] || dtd.$nonChild[node.tagName])) {
  4479. offset = domUtils.getNodeIndex(node) + (toStart ? 0 : 1);
  4480. node = node.parentNode;
  4481. }
  4482. if(toStart) {
  4483. range.startContainer = node;
  4484. range.startOffset = offset;
  4485. if(!range.endContainer) {
  4486. range.collapse(true);
  4487. }
  4488. } else {
  4489. range.endContainer = node;
  4490. range.endOffset = offset;
  4491. if(!range.startContainer) {
  4492. range.collapse(false);
  4493. }
  4494. }
  4495. updateCollapse(range);
  4496. return range;
  4497. }
  4498. function execContentsAction(range, action) {
  4499. // 调整边界
  4500. // range.includeBookmark();
  4501. var start = range.startContainer,
  4502. end = range.endContainer,
  4503. startOffset = range.startOffset,
  4504. endOffset = range.endOffset,
  4505. doc = range.document,
  4506. frag = doc
  4507. .createDocumentFragment(),
  4508. tmpStart, tmpEnd;
  4509. if(start.nodeType == 1) {
  4510. start = start.childNodes[startOffset] ||
  4511. (tmpStart = start
  4512. .appendChild(doc.createTextNode('')));
  4513. }
  4514. if(end.nodeType == 1) {
  4515. end = end.childNodes[endOffset] ||
  4516. (tmpEnd = end.appendChild(doc.createTextNode('')));
  4517. }
  4518. if(start === end && start.nodeType == 3) {
  4519. frag.appendChild(doc.createTextNode(start.substringData(
  4520. startOffset, endOffset - startOffset)));
  4521. // is not clone
  4522. if(action) {
  4523. start.deleteData(startOffset, endOffset - startOffset);
  4524. range.collapse(true);
  4525. }
  4526. return frag;
  4527. }
  4528. var current, currentLevel, clone = frag,
  4529. startParents = domUtils
  4530. .findParents(start, true),
  4531. endParents = domUtils
  4532. .findParents(end, true);
  4533. for(var i = 0; startParents[i] == endParents[i];) {
  4534. i++;
  4535. }
  4536. for(var j = i, si; si = startParents[j]; j++) {
  4537. current = si.nextSibling;
  4538. if(si == start) {
  4539. if(!tmpStart) {
  4540. if(range.startContainer.nodeType == 3) {
  4541. clone.appendChild(doc
  4542. .createTextNode(start.nodeValue
  4543. .slice(startOffset)));
  4544. // is not clone
  4545. if(action) {
  4546. start.deleteData(startOffset,
  4547. start.nodeValue.length - startOffset);
  4548. }
  4549. } else {
  4550. clone.appendChild(!action ?
  4551. start.cloneNode(true) :
  4552. start);
  4553. }
  4554. }
  4555. } else {
  4556. currentLevel = si.cloneNode(false);
  4557. clone.appendChild(currentLevel);
  4558. }
  4559. while(current) {
  4560. if(current === end || current === endParents[j]) {
  4561. break;
  4562. }
  4563. si = current.nextSibling;
  4564. clone.appendChild(!action ?
  4565. current.cloneNode(true) :
  4566. current);
  4567. current = si;
  4568. }
  4569. clone = currentLevel;
  4570. }
  4571. clone = frag;
  4572. if(!startParents[i]) {
  4573. clone.appendChild(startParents[i - 1].cloneNode(false));
  4574. clone = clone.firstChild;
  4575. }
  4576. for(var j = i, ei; ei = endParents[j]; j++) {
  4577. current = ei.previousSibling;
  4578. if(ei == end) {
  4579. if(!tmpEnd && range.endContainer.nodeType == 3) {
  4580. clone.appendChild(doc.createTextNode(end.substringData(
  4581. 0, endOffset)));
  4582. // is not clone
  4583. if(action) {
  4584. end.deleteData(0, endOffset);
  4585. }
  4586. }
  4587. } else {
  4588. currentLevel = ei.cloneNode(false);
  4589. clone.appendChild(currentLevel);
  4590. }
  4591. // 如果两端同级,右边第一次已经被开始做了
  4592. if(j != i || !startParents[i]) {
  4593. while(current) {
  4594. if(current === start) {
  4595. break;
  4596. }
  4597. ei = current.previousSibling;
  4598. clone.insertBefore(!action ?
  4599. current.cloneNode(true) :
  4600. current, clone.firstChild);
  4601. current = ei;
  4602. }
  4603. }
  4604. clone = currentLevel;
  4605. }
  4606. if(action) {
  4607. range.setStartBefore(!endParents[i] ?
  4608. endParents[i - 1] :
  4609. !startParents[i] ?
  4610. startParents[i - 1] :
  4611. endParents[i]).collapse(true);
  4612. }
  4613. tmpStart && domUtils.remove(tmpStart);
  4614. tmpEnd && domUtils.remove(tmpEnd);
  4615. return frag;
  4616. }
  4617. /**
  4618. * 创建一个跟document绑定的空的Range实例
  4619. *
  4620. * @constructor
  4621. * @param {
  4622. * Document } document 新建的选区所属的文档对象
  4623. */
  4624. /**
  4625. * @property { Node } startContainer 当前Range的开始边界的容器节点, 可以是一个元素节点或者是文本节点
  4626. */
  4627. /**
  4628. * @property { Node } startOffset 当前Range的开始边界容器节点的偏移量, 如果是元素节点,
  4629. * 该值就是childNodes中的第几个节点, 如果是文本节点就是文本内容的第几个字符
  4630. */
  4631. /**
  4632. * @property { Node } endContainer 当前Range的结束边界的容器节点, 可以是一个元素节点或者是文本节点
  4633. */
  4634. /**
  4635. * @property { Node } endOffset 当前Range的结束边界容器节点的偏移量, 如果是元素节点,
  4636. * 该值就是childNodes中的第几个节点, 如果是文本节点就是文本内容的第几个字符
  4637. */
  4638. /**
  4639. * @property { Boolean } collapsed 当前Range是否闭合
  4640. * @default true
  4641. * @remind Range是闭合的时候, startContainer === endContainer && startOffset
  4642. * === endOffset
  4643. */
  4644. /**
  4645. * @property { Document } document 当前Range所属的Document对象
  4646. * @remind 不同range的的document属性可以是不同的
  4647. */
  4648. var Range = dom.Range = function(document) {
  4649. var me = this;
  4650. me.startContainer = me.startOffset = me.endContainer = me.endOffset = null;
  4651. me.document = document;
  4652. me.collapsed = true;
  4653. };
  4654. /**
  4655. * 删除fillData
  4656. *
  4657. * @param doc
  4658. * @param excludeNode
  4659. */
  4660. function removeFillData(doc, excludeNode) {
  4661. try {
  4662. if(fillData && domUtils.inDoc(fillData, doc)) {
  4663. if(!fillData.nodeValue.replace(fillCharReg, '').length) {
  4664. var tmpNode = fillData.parentNode;
  4665. domUtils.remove(fillData);
  4666. while(tmpNode &&
  4667. domUtils.isEmptyInlineElement(tmpNode) &&
  4668. // safari的contains有bug
  4669. (browser.safari ?
  4670. !(domUtils.getPosition(tmpNode,
  4671. excludeNode) & domUtils.POSITION_CONTAINS) :
  4672. !tmpNode.contains(excludeNode))) {
  4673. fillData = tmpNode.parentNode;
  4674. domUtils.remove(tmpNode);
  4675. tmpNode = fillData;
  4676. }
  4677. } else {
  4678. fillData.nodeValue = fillData.nodeValue.replace(
  4679. fillCharReg, '');
  4680. }
  4681. }
  4682. } catch(e) {}
  4683. }
  4684. /**
  4685. * @param node
  4686. * @param dir
  4687. */
  4688. function mergeSibling(node, dir) {
  4689. var tmpNode;
  4690. node = node[dir];
  4691. while(node && domUtils.isFillChar(node)) {
  4692. tmpNode = node[dir];
  4693. domUtils.remove(node);
  4694. node = tmpNode;
  4695. }
  4696. }
  4697. Range.prototype = {
  4698. /**
  4699. * 克隆选区的内容到一个DocumentFragment里
  4700. *
  4701. * @method cloneContents
  4702. * @return { DocumentFragment | NULL } 如果选区是闭合的将返回null, 否则,
  4703. * 返回包含所clone内容的DocumentFragment元素
  4704. * @example ```html <body> <!-- 中括号表示选区 --> <b>x<i>x[x</i>xx]x</b>
  4705. *
  4706. * <script> //range是已选中的选区 var fragment = range.cloneContents(),
  4707. * node = document.createElement("div");
  4708. *
  4709. * node.appendChild( fragment );
  4710. *
  4711. * //output: <i>x</i>xx console.log( node.innerHTML );
  4712. *
  4713. * </script> </body> ```
  4714. */
  4715. cloneContents: function() {
  4716. return this.collapsed ? null : execContentsAction(this, 0);
  4717. },
  4718. /**
  4719. * 删除当前选区范围中的所有内容
  4720. *
  4721. * @method deleteContents
  4722. * @remind 执行完该操作后, 当前Range对象变成了闭合状态
  4723. * @return { UE.dom.Range } 当前操作的Range对象
  4724. * @example ```html <body> <!-- 中括号表示选区 --> <b>x<i>x[x</i>xx]x</b>
  4725. *
  4726. * <script> //range是已选中的选区 range.deleteContents();
  4727. *
  4728. * //竖线表示闭合后的选区位置 //output: <b>x<i>x</i>|x</b> console.log(
  4729. * document.body.innerHTML );
  4730. *
  4731. * //此时, range的各项属性为 //output: B console.log(
  4732. * range.startContainer.tagName ); //output: 2 console.log(
  4733. * range.startOffset ); //output: B console.log(
  4734. * range.endContainer.tagName ); //output: 2 console.log(
  4735. * range.endOffset ); //output: true console.log( range.collapsed );
  4736. *
  4737. * </script> </body> ```
  4738. */
  4739. deleteContents: function() {
  4740. var txt;
  4741. if(!this.collapsed) {
  4742. execContentsAction(this, 1);
  4743. }
  4744. if(browser.webkit) {
  4745. txt = this.startContainer;
  4746. if(txt.nodeType == 3 && !txt.nodeValue.length) {
  4747. this.setStartBefore(txt).collapse(true);
  4748. domUtils.remove(txt);
  4749. }
  4750. }
  4751. return this;
  4752. },
  4753. /**
  4754. * 将当前选区的内容提取到一个DocumentFragment里
  4755. *
  4756. * @method extractContents
  4757. * @remind 执行该操作后, 选区将变成闭合状态
  4758. * @warning 执行该操作后, 原来选区所选中的内容将从dom树上剥离出来
  4759. * @return { DocumentFragment } 返回包含所提取内容的DocumentFragment对象
  4760. * @example ```html <body> <!-- 中括号表示选区 --> <b>x<i>x[x</i>xx]x</b>
  4761. *
  4762. * <script> //range是已选中的选区 var fragment = range.extractContents(),
  4763. * node = document.createElement( "div" );
  4764. *
  4765. * node.appendChild( fragment );
  4766. *
  4767. * //竖线表示闭合后的选区位置
  4768. *
  4769. * //output: <b>x<i>x</i>|x</b> console.log(
  4770. * document.body.innerHTML ); //output: <i>x</i>xx console.log(
  4771. * node.innerHTML );
  4772. *
  4773. * //此时, range的各项属性为 //output: B console.log(
  4774. * range.startContainer.tagName ); //output: 2 console.log(
  4775. * range.startOffset ); //output: B console.log(
  4776. * range.endContainer.tagName ); //output: 2 console.log(
  4777. * range.endOffset ); //output: true console.log( range.collapsed );
  4778. *
  4779. * </script> </body>
  4780. */
  4781. extractContents: function() {
  4782. return this.collapsed ? null : execContentsAction(this, 2);
  4783. },
  4784. /**
  4785. * 设置Range的开始容器节点和偏移量
  4786. *
  4787. * @method setStart
  4788. * @remind 如果给定的节点是元素节点,那么offset指的是其子元素中索引为offset的元素,
  4789. * 如果是文本节点,那么offset指的是其文本内容的第offset个字符
  4790. * @remind 如果提供的容器节点是一个不能包含子元素的节点, 则该选区的开始容器将被设置 为该节点的父节点, 此时,
  4791. * 其距离开始容器的偏移量也变成了该节点在其父节点 中的索引
  4792. * @param {
  4793. * Node } node 将被设为当前选区开始边界容器的节点对象
  4794. * @param {
  4795. * int } offset 选区的开始位置偏移量
  4796. * @return { UE.dom.Range } 当前range对象
  4797. * @example ```html <!-- 选区 --> <b>xxx<i>x<span>xx</span>xx<em>xx</em>xxx</i>[xxx]</b>
  4798. *
  4799. * <script>
  4800. *
  4801. * //执行操作 range.setStart( document.getElementsByTagName("i")[0], 1 );
  4802. *
  4803. * //此时, 选区变成了 //<b>xxx<i>x[<span>xx</span>xx<em>xx</em>xxx</i>xxx]</b>
  4804. *
  4805. * </script> ```
  4806. * @example ```html <!-- 选区 --> <b>xxx<img>[xx]x</b>
  4807. *
  4808. * <script>
  4809. *
  4810. * //执行操作 range.setStart( document.getElementsByTagName("img")[0], 3 );
  4811. *
  4812. * //此时, 选区变成了 //<b>xxx[<img>xx]x</b>
  4813. *
  4814. * </script> ```
  4815. */
  4816. setStart: function(node, offset) {
  4817. return setEndPoint(true, node, offset, this);
  4818. },
  4819. /**
  4820. * 设置Range的结束容器和偏移量
  4821. *
  4822. * @method setEnd
  4823. * @param {
  4824. * Node } node 作为当前选区结束边界容器的节点对象
  4825. * @param {
  4826. * int } offset 结束边界的偏移量
  4827. * @see UE.dom.Range:setStart(Node,int)
  4828. * @return { UE.dom.Range } 当前range对象
  4829. */
  4830. setEnd: function(node, offset) {
  4831. return setEndPoint(false, node, offset, this);
  4832. },
  4833. /**
  4834. * 将Range开始位置设置到node节点之后
  4835. *
  4836. * @method setStartAfter
  4837. * @remind 该操作将会把给定节点的父节点作为range的开始容器, 且偏移量是该节点在其父节点中的位置索引+1
  4838. * @param {
  4839. * Node } node 选区的开始边界将紧接着该节点之后
  4840. * @return { UE.dom.Range } 当前range对象
  4841. * @example ```html <!-- 选区示例 --> <b>xx<i>xxx</i><span>xx[x</span>xxx]</b>
  4842. *
  4843. * <script>
  4844. *
  4845. * //执行操作 range.setStartAfter( document.getElementsByTagName("i")[0] );
  4846. *
  4847. * //结果选区 //<b>xx<i>xxx</i>[<span>xxx</span>xxx]</b>
  4848. *
  4849. * </script> ```
  4850. */
  4851. setStartAfter: function(node) {
  4852. return this.setStart(node.parentNode, domUtils
  4853. .getNodeIndex(node) +
  4854. 1);
  4855. },
  4856. /**
  4857. * 将Range开始位置设置到node节点之前
  4858. *
  4859. * @method setStartBefore
  4860. * @remind 该操作将会把给定节点的父节点作为range的开始容器, 且偏移量是该节点在其父节点中的位置索引
  4861. * @param {
  4862. * Node } node 新的选区开始位置在该节点之前
  4863. * @see UE.dom.Range:setStartAfter(Node)
  4864. * @return { UE.dom.Range } 当前range对象
  4865. */
  4866. setStartBefore: function(node) {
  4867. return this.setStart(node.parentNode, domUtils
  4868. .getNodeIndex(node));
  4869. },
  4870. /**
  4871. * 将Range结束位置设置到node节点之后
  4872. *
  4873. * @method setEndAfter
  4874. * @remind 该操作将会把给定节点的父节点作为range的结束容器, 且偏移量是该节点在其父节点中的位置索引+1
  4875. * @param {
  4876. * Node } node 目标节点
  4877. * @see UE.dom.Range:setStartAfter(Node)
  4878. * @return { UE.dom.Range } 当前range对象
  4879. * @example ```html <!-- 选区示例 --> <b>[xx<i>xxx</i><span>xx]x</span>xxx</b>
  4880. *
  4881. * <script>
  4882. *
  4883. * //执行操作 range.setStartAfter(
  4884. * document.getElementsByTagName("span")[0] );
  4885. *
  4886. * //结果选区 //<b>[xx<i>xxx</i><span>xxx</span>]xxx</b>
  4887. *
  4888. * </script> ```
  4889. */
  4890. setEndAfter: function(node) {
  4891. return this.setEnd(node.parentNode, domUtils.getNodeIndex(node) +
  4892. 1);
  4893. },
  4894. /**
  4895. * 将Range结束位置设置到node节点之前
  4896. *
  4897. * @method setEndBefore
  4898. * @remind 该操作将会把给定节点的父节点作为range的结束容器, 且偏移量是该节点在其父节点中的位置索引
  4899. * @param {
  4900. * Node } node 目标节点
  4901. * @see UE.dom.Range:setEndAfter(Node)
  4902. * @return { UE.dom.Range } 当前range对象
  4903. */
  4904. setEndBefore: function(node) {
  4905. return this
  4906. .setEnd(node.parentNode, domUtils.getNodeIndex(node));
  4907. },
  4908. /**
  4909. * 设置Range的开始位置到node节点内的第一个子节点之前
  4910. *
  4911. * @method setStartAtFirst
  4912. * @remind 选区的开始容器将变成给定的节点, 且偏移量为0
  4913. * @remind 如果给定的节点是元素节点, 则该节点必须是允许包含子节点的元素。
  4914. * @param {
  4915. * Node } node 目标节点
  4916. * @see UE.dom.Range:setStartBefore(Node)
  4917. * @return { UE.dom.Range } 当前range对象
  4918. * @example ```html <!-- 选区示例 --> <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  4919. *
  4920. * <script>
  4921. *
  4922. * //执行操作 range.setStartAtFirst(
  4923. * document.getElementsByTagName("i")[0] );
  4924. *
  4925. * //结果选区 //<b>xx<i>[xxx</i><span>xx]x</span>xxx</b>
  4926. *
  4927. * </script> ```
  4928. */
  4929. setStartAtFirst: function(node) {
  4930. return this.setStart(node, 0);
  4931. },
  4932. /**
  4933. * 设置Range的开始位置到node节点内的最后一个节点之后
  4934. *
  4935. * @method setStartAtLast
  4936. * @remind 选区的开始容器将变成给定的节点, 且偏移量为该节点的子节点数
  4937. * @remind 如果给定的节点是元素节点, 则该节点必须是允许包含子节点的元素。
  4938. * @param {
  4939. * Node } node 目标节点
  4940. * @see UE.dom.Range:setStartAtFirst(Node)
  4941. * @return { UE.dom.Range } 当前range对象
  4942. */
  4943. setStartAtLast: function(node) {
  4944. return this.setStart(node, node.nodeType == 3 ?
  4945. node.nodeValue.length :
  4946. node.childNodes.length);
  4947. },
  4948. /**
  4949. * 设置Range的结束位置到node节点内的第一个节点之前
  4950. *
  4951. * @method setEndAtFirst
  4952. * @param {
  4953. * Node } node 目标节点
  4954. * @remind 选区的结束容器将变成给定的节点, 且偏移量为0
  4955. * @remind node必须是一个元素节点, 且必须是允许包含子节点的元素。
  4956. * @see UE.dom.Range:setStartAtFirst(Node)
  4957. * @return { UE.dom.Range } 当前range对象
  4958. */
  4959. setEndAtFirst: function(node) {
  4960. return this.setEnd(node, 0);
  4961. },
  4962. /**
  4963. * 设置Range的结束位置到node节点内的最后一个节点之后
  4964. *
  4965. * @method setEndAtLast
  4966. * @param {
  4967. * Node } node 目标节点
  4968. * @remind 选区的结束容器将变成给定的节点, 且偏移量为该节点的子节点数量
  4969. * @remind node必须是一个元素节点, 且必须是允许包含子节点的元素。
  4970. * @see UE.dom.Range:setStartAtFirst(Node)
  4971. * @return { UE.dom.Range } 当前range对象
  4972. */
  4973. setEndAtLast: function(node) {
  4974. return this.setEnd(node, node.nodeType == 3 ?
  4975. node.nodeValue.length :
  4976. node.childNodes.length);
  4977. },
  4978. /**
  4979. * 选中给定节点
  4980. *
  4981. * @method selectNode
  4982. * @remind 此时, 选区的开始容器和结束容器都是该节点的父节点, 其startOffset是该节点在父节点中的位置索引,
  4983. * 而endOffset为startOffset+1
  4984. * @param {
  4985. * Node } node 需要选中的节点
  4986. * @return { UE.dom.Range } 当前range对象,此时的range仅包含当前给定的节点对象
  4987. * @example ```html <!-- 选区示例 --> <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  4988. *
  4989. * <script>
  4990. *
  4991. * //执行操作 range.selectNode( document.getElementsByTagName("i")[0] );
  4992. *
  4993. * //结果选区 //<b>xx[<i>xxx</i>]<span>xxx</span>xxx</b>
  4994. *
  4995. * </script> ```
  4996. */
  4997. selectNode: function(node) {
  4998. return this.setStartBefore(node).setEndAfter(node);
  4999. },
  5000. /**
  5001. * 选中给定节点内部的所有节点
  5002. *
  5003. * @method selectNodeContents
  5004. * @remind 此时, 选区的开始容器和结束容器都是该节点, 其startOffset为0,
  5005. * 而endOffset是该节点的子节点数。
  5006. * @param {
  5007. * Node } node 目标节点, 当前range将包含该节点内的所有节点
  5008. * @return { UE.dom.Range } 当前range对象, 此时range仅包含给定节点的所有子节点
  5009. * @example ```html <!-- 选区示例 --> <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  5010. *
  5011. * <script>
  5012. *
  5013. * //执行操作 range.selectNode( document.getElementsByTagName("b")[0] );
  5014. *
  5015. * //结果选区 //<b>[xx<i>xxx</i><span>xxx</span>xxx]</b>
  5016. *
  5017. * </script> ```
  5018. */
  5019. selectNodeContents: function(node) {
  5020. return this.setStart(node, 0).setEndAtLast(node);
  5021. },
  5022. /**
  5023. * clone当前Range对象
  5024. *
  5025. * @method cloneRange
  5026. * @remind 返回的range是一个全新的range对象, 其内部所有属性与当前被clone的range相同。
  5027. * @return { UE.dom.Range } 当前range对象的一个副本
  5028. */
  5029. cloneRange: function() {
  5030. var me = this;
  5031. return new Range(me.document).setStart(me.startContainer,
  5032. me.startOffset).setEnd(me.endContainer, me.endOffset);
  5033. },
  5034. /**
  5035. * 向当前选区的结束处闭合选区
  5036. *
  5037. * @method collapse
  5038. * @return { UE.dom.Range } 当前range对象
  5039. * @example ```html <!-- 选区示例 --> <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  5040. *
  5041. * <script>
  5042. *
  5043. * //执行操作 range.collapse();
  5044. *
  5045. * //结果选区 //"|" 表示选区已闭合 //<b>xx<i>xxx</i><span>xx|x</span>xxx</b>
  5046. *
  5047. * </script> ```
  5048. */
  5049. /**
  5050. * 闭合当前选区,根据给定的toStart参数项决定是向当前选区开始处闭合还是向结束处闭合,
  5051. * 如果toStart的值为true,则向开始位置闭合, 反之,向结束位置闭合。
  5052. *
  5053. * @method collapse
  5054. * @param {
  5055. * Boolean } toStart 是否向选区开始处闭合
  5056. * @return { UE.dom.Range } 当前range对象,此时range对象处于闭合状态
  5057. * @see UE.dom.Range:collapse()
  5058. * @example ```html <!-- 选区示例 --> <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  5059. *
  5060. * <script>
  5061. *
  5062. * //执行操作 range.collapse( true );
  5063. *
  5064. * //结果选区 //"|" 表示选区已闭合 //<b>xx<i>xxx</i><span>|xxx</span>xxx</b>
  5065. *
  5066. * </script> ```
  5067. */
  5068. collapse: function(toStart) {
  5069. var me = this;
  5070. if(toStart) {
  5071. me.endContainer = me.startContainer;
  5072. me.endOffset = me.startOffset;
  5073. } else {
  5074. me.startContainer = me.endContainer;
  5075. me.startOffset = me.endOffset;
  5076. }
  5077. me.collapsed = true;
  5078. return me;
  5079. },
  5080. /**
  5081. * 调整range的开始位置和结束位置,使其"收缩"到最小的位置
  5082. *
  5083. * @method shrinkBoundary
  5084. * @return { UE.dom.Range } 当前range对象
  5085. * @example ```html <span>xx<b>xx[</b>xxxxx]</span> => <span>xx<b>xx</b>[xxxxx]</span>
  5086. * ```
  5087. *
  5088. * @example ```html <!-- 选区示例 --> <b>x[xx</b><i>]xxx</i>
  5089. *
  5090. * <script>
  5091. *
  5092. * //执行收缩 range.shrinkBoundary();
  5093. *
  5094. * //结果选区 //<b>x[xx]</b><i>xxx</i> </script> ```
  5095. *
  5096. * @example ```html [<b><i>xxxx</i>xxxxxxx</b>] => <b><i>[xxxx</i>xxxxxxx]</b>
  5097. * ```
  5098. */
  5099. /**
  5100. * 调整range的开始位置和结束位置,使其"收缩"到最小的位置, 如果ignoreEnd的值为true,则忽略对结束位置的调整
  5101. *
  5102. * @method shrinkBoundary
  5103. * @param {
  5104. * Boolean } ignoreEnd 是否忽略对结束位置的调整
  5105. * @return { UE.dom.Range } 当前range对象
  5106. * @see UE.dom.domUtils.Range:shrinkBoundary()
  5107. */
  5108. shrinkBoundary: function(ignoreEnd) {
  5109. var me = this,
  5110. child, collapsed = me.collapsed;
  5111. function check(node) {
  5112. return node.nodeType == 1 && !domUtils.isBookmarkNode(node) &&
  5113. !dtd.$empty[node.tagName] &&
  5114. !dtd.$nonChild[node.tagName]
  5115. }
  5116. while(me.startContainer.nodeType == 1 // 是element
  5117. &&
  5118. (child = me.startContainer.childNodes[me.startOffset]) // 子节点也是element
  5119. &&
  5120. check(child)) {
  5121. me.setStart(child, 0);
  5122. }
  5123. if(collapsed) {
  5124. return me.collapse(true);
  5125. }
  5126. if(!ignoreEnd) {
  5127. while(me.endContainer.nodeType == 1 // 是element
  5128. &&
  5129. me.endOffset > 0 // 如果是空元素就退出
  5130. // endOffset=0那么endOffst-1为负值,childNodes[endOffset]报错
  5131. &&
  5132. (child = me.endContainer.childNodes[me.endOffset -
  5133. 1]) // 子节点也是element
  5134. &&
  5135. check(child)) {
  5136. me.setEnd(child, child.childNodes.length);
  5137. }
  5138. }
  5139. return me;
  5140. },
  5141. /**
  5142. * 获取离当前选区内包含的所有节点最近的公共祖先节点,
  5143. *
  5144. * @method getCommonAncestor
  5145. * @remind 返回的公共祖先节点一定不是range自身的容器节点, 但有可能是一个文本节点
  5146. * @return { Node } 当前range对象内所有节点的公共祖先节点
  5147. * @example ```html //选区示例 <span>xxx<b>x[x<em>xx]x</em>xxx</b>xx</span>
  5148. * <script>
  5149. *
  5150. * var node = range.getCommonAncestor();
  5151. *
  5152. * //公共祖先节点是: b节点 //输出: B console.log(node.tagName);
  5153. *
  5154. * </script> ```
  5155. */
  5156. /**
  5157. * 获取当前选区所包含的所有节点的公共祖先节点, 可以根据给定的参数 includeSelf 决定获取到
  5158. * 的公共祖先节点是否可以是当前选区的startContainer或endContainer节点, 如果 includeSelf
  5159. * 的取值为true, 则返回的节点可以是自身的容器节点, 否则, 则不能是容器节点
  5160. *
  5161. * @method getCommonAncestor
  5162. * @param {
  5163. * Boolean } includeSelf 是否允许获取到的公共祖先节点是当前range对象的容器节点
  5164. * @return { Node } 当前range对象内所有节点的公共祖先节点
  5165. * @see UE.dom.Range:getCommonAncestor()
  5166. * @example ```html <body>
  5167. *
  5168. * <!-- 选区示例 --> <b>xxx<i>xxxx<span>xx[x</span>xx]x</i>xxxxxxx</b>
  5169. *
  5170. * <script>
  5171. *
  5172. * var node = range.getCommonAncestor( false );
  5173. *
  5174. * //这里的公共祖先节点是B而不是I, 是因为参数限制了获取到的节点不能是容器节点 //output: B console.log(
  5175. * node.tagName );
  5176. *
  5177. * </script>
  5178. *
  5179. * </body> ```
  5180. */
  5181. /**
  5182. * 获取当前选区所包含的所有节点的公共祖先节点, 可以根据给定的参数 includeSelf 决定获取到
  5183. * 的公共祖先节点是否可以是当前选区的startContainer或endContainer节点, 如果 includeSelf
  5184. * 的取值为true, 则返回的节点可以是自身的容器节点, 否则, 则不能是容器节点; 同时可以根据 ignoreTextNode
  5185. * 参数的取值决定是否忽略类型为文本节点的祖先节点。
  5186. *
  5187. * @method getCommonAncestor
  5188. * @param {
  5189. * Boolean } includeSelf 是否允许获取到的公共祖先节点是当前range对象的容器节点
  5190. * @param {
  5191. * Boolean } ignoreTextNode 获取祖先节点的过程中是否忽略类型为文本节点的祖先节点
  5192. * @return { Node } 当前range对象内所有节点的公共祖先节点
  5193. * @see UE.dom.Range:getCommonAncestor()
  5194. * @see UE.dom.Range:getCommonAncestor(Boolean)
  5195. * @example ```html <body>
  5196. *
  5197. * <!-- 选区示例 --> <b>xxx<i>xxxx<span>x[x]x</span>xxx</i>xxxxxxx</b>
  5198. *
  5199. * <script>
  5200. *
  5201. * var node = range.getCommonAncestor( true, false );
  5202. *
  5203. * //output: SPAN console.log( node.tagName );
  5204. *
  5205. * </script>
  5206. *
  5207. * </body> ```
  5208. */
  5209. getCommonAncestor: function(includeSelf, ignoreTextNode) {
  5210. var me = this,
  5211. start = me.startContainer,
  5212. end = me.endContainer;
  5213. if(start === end) {
  5214. if(includeSelf && selectOneNode(this)) {
  5215. start = start.childNodes[me.startOffset];
  5216. if(start.nodeType == 1)
  5217. return start;
  5218. }
  5219. // 只有在上来就相等的情况下才会出现是文本的情况
  5220. return ignoreTextNode && start.nodeType == 3 ?
  5221. start.parentNode :
  5222. start;
  5223. }
  5224. return domUtils.getCommonAncestor(start, end);
  5225. },
  5226. /**
  5227. * 调整当前Range的开始和结束边界容器,如果是容器节点是文本节点,就调整到包含该文本节点的父节点上
  5228. *
  5229. * @method trimBoundary
  5230. * @remind 该操作有可能会引起文本节点被切开
  5231. * @return { UE.dom.Range } 当前range对象
  5232. * @example ```html
  5233. *
  5234. * //选区示例 <b>xxx<i>[xxxxx]</i>xxx</b>
  5235. *
  5236. * <script> //未调整前, 选区的开始容器和结束都是文本节点 //执行调整 range.trimBoundary();
  5237. *
  5238. * //调整之后, 容器节点变成了i节点 //<b>xxx[<i>xxxxx</i>]xxx</b> </script>
  5239. * ```
  5240. */
  5241. /**
  5242. * 调整当前Range的开始和结束边界容器,如果是容器节点是文本节点,就调整到包含该文本节点的父节点上, 可以根据 ignoreEnd
  5243. * 参数的值决定是否调整对结束边界的调整
  5244. *
  5245. * @method trimBoundary
  5246. * @param {
  5247. * Boolean } ignoreEnd 是否忽略对结束边界的调整
  5248. * @return { UE.dom.Range } 当前range对象
  5249. * @example ```html
  5250. *
  5251. * //选区示例 <b>xxx<i>[xxxxx]</i>xxx</b>
  5252. *
  5253. * <script> //未调整前, 选区的开始容器和结束都是文本节点 //执行调整 range.trimBoundary( true );
  5254. *
  5255. * //调整之后, 开始容器节点变成了i节点 //但是, 结束容器没有发生变化 //<b>xxx[<i>xxxxx]</i>xxx</b>
  5256. * </script> ```
  5257. */
  5258. trimBoundary: function(ignoreEnd) {
  5259. this.txtToElmBoundary();
  5260. var start = this.startContainer,
  5261. offset = this.startOffset,
  5262. collapsed = this.collapsed,
  5263. end = this.endContainer;
  5264. if(start.nodeType == 3) {
  5265. if(offset == 0) {
  5266. this.setStartBefore(start);
  5267. } else {
  5268. if(offset >= start.nodeValue.length) {
  5269. this.setStartAfter(start);
  5270. } else {
  5271. var textNode = domUtils.split(start, offset);
  5272. // 跟新结束边界
  5273. if(start === end) {
  5274. this.setEnd(textNode, this.endOffset - offset);
  5275. } else if(start.parentNode === end) {
  5276. this.endOffset += 1;
  5277. }
  5278. this.setStartBefore(textNode);
  5279. }
  5280. }
  5281. if(collapsed) {
  5282. return this.collapse(true);
  5283. }
  5284. }
  5285. if(!ignoreEnd) {
  5286. offset = this.endOffset;
  5287. end = this.endContainer;
  5288. if(end.nodeType == 3) {
  5289. if(offset == 0) {
  5290. this.setEndBefore(end);
  5291. } else {
  5292. offset < end.nodeValue.length &&
  5293. domUtils.split(end, offset);
  5294. this.setEndAfter(end);
  5295. }
  5296. }
  5297. }
  5298. return this;
  5299. },
  5300. /**
  5301. * 如果选区在文本的边界上,就扩展选区到文本的父节点上, 如果当前选区是闭合的, 则什么也不做
  5302. *
  5303. * @method txtToElmBoundary
  5304. * @remind 该操作不会修改dom节点
  5305. * @return { UE.dom.Range } 当前range对象
  5306. */
  5307. /**
  5308. * 如果选区在文本的边界上,就扩展选区到文本的父节点上, 如果当前选区是闭合的, 则根据参数项 ignoreCollapsed
  5309. * 的值决定是否执行该调整
  5310. *
  5311. * @method txtToElmBoundary
  5312. * @param {
  5313. * Boolean } ignoreCollapsed 是否忽略选区的闭合状态, 如果该参数取值为true, 则
  5314. * 不论选区是否闭合, 都会执行该操作, 反之, 则不会对闭合的选区执行该操作
  5315. * @return { UE.dom.Range } 当前range对象
  5316. */
  5317. txtToElmBoundary: function(ignoreCollapsed) {
  5318. function adjust(r, c) {
  5319. var container = r[c + 'Container'],
  5320. offset = r[c + 'Offset'];
  5321. if(container.nodeType == 3) {
  5322. if(!offset) {
  5323. r['set' + c.replace(/(\w)/, function(a) {
  5324. return a.toUpperCase();
  5325. }) + 'Before'](container);
  5326. } else if(offset >= container.nodeValue.length) {
  5327. r['set' + c.replace(/(\w)/, function(a) {
  5328. return a.toUpperCase();
  5329. }) + 'After'](container);
  5330. }
  5331. }
  5332. }
  5333. if(ignoreCollapsed || !this.collapsed) {
  5334. adjust(this, 'start');
  5335. adjust(this, 'end');
  5336. }
  5337. return this;
  5338. },
  5339. /**
  5340. * 在当前选区的开始位置前插入节点,新插入的节点会被该range包含
  5341. *
  5342. * @method insertNode
  5343. * @param {
  5344. * Node } node 需要插入的节点
  5345. * @remind 插入的节点可以是一个DocumentFragment依次插入多个节点
  5346. * @return { UE.dom.Range } 当前range对象
  5347. */
  5348. insertNode: function(node) {
  5349. var first = node,
  5350. length = 1;
  5351. if(node.nodeType == 11) {
  5352. first = node.firstChild;
  5353. length = node.childNodes.length;
  5354. }
  5355. this.trimBoundary(true);
  5356. var start = this.startContainer,
  5357. offset = this.startOffset;
  5358. var nextNode = start.childNodes[offset];
  5359. if(nextNode) {
  5360. start.insertBefore(node, nextNode);
  5361. } else {
  5362. start.appendChild(node);
  5363. }
  5364. if(first.parentNode === this.endContainer) {
  5365. this.endOffset = this.endOffset + length;
  5366. }
  5367. return this.setStartBefore(first);
  5368. },
  5369. /**
  5370. * 闭合选区到当前选区的开始位置, 并且定位光标到闭合后的位置
  5371. *
  5372. * @method setCursor
  5373. * @return { UE.dom.Range } 当前range对象
  5374. * @see UE.dom.Range:collapse()
  5375. */
  5376. /**
  5377. * 闭合选区,可以根据参数toEnd的值控制选区是向前闭合还是向后闭合, 并且定位光标到闭合后的位置。
  5378. *
  5379. * @method setCursor
  5380. * @param {
  5381. * Boolean } toEnd 是否向后闭合, 如果为true, 则闭合选区时, 将向结束容器方向闭合,
  5382. * 反之,则向开始容器方向闭合
  5383. * @return { UE.dom.Range } 当前range对象
  5384. * @see UE.dom.Range:collapse(Boolean)
  5385. */
  5386. setCursor: function(toEnd, noFillData) {
  5387. return this.collapse(!toEnd).select(noFillData);
  5388. },
  5389. /**
  5390. * 创建当前range的一个书签,记录下当前range的位置,方便当dom树改变时,还能找回原来的选区位置
  5391. *
  5392. * @method createBookmark
  5393. * @param {
  5394. * Boolean } serialize 控制返回的标记位置是对当前位置的引用还是ID,如果该值为true,则
  5395. * 返回标记位置的ID, 反之则返回标记位置节点的引用
  5396. * @return { Object } 返回一个书签记录键值对, 其包含的key有: start => 开始标记的ID或者引用,
  5397. * end => 结束标记的ID或引用, id => 当前标记的类型, 如果为true,则表示
  5398. * 返回的记录的类型为ID, 反之则为引用
  5399. */
  5400. createBookmark: function(serialize, same) {
  5401. var endNode, startNode = this.document.createElement('span');
  5402. startNode.style.cssText = 'display:none;line-height:0px;';
  5403. startNode.appendChild(this.document.createTextNode('\u200D'));
  5404. startNode.id = '_baidu_bookmark_start_' + (same ? '' : guid++);
  5405. if(!this.collapsed) {
  5406. endNode = startNode.cloneNode(true);
  5407. endNode.id = '_baidu_bookmark_end_' + (same ? '' : guid++);
  5408. }
  5409. this.insertNode(startNode);
  5410. if(endNode) {
  5411. this.collapse().insertNode(endNode).setEndBefore(endNode);
  5412. }
  5413. this.setStartAfter(startNode);
  5414. return {
  5415. start: serialize ? startNode.id : startNode,
  5416. end: endNode ? serialize ? endNode.id : endNode : null,
  5417. id: serialize
  5418. }
  5419. },
  5420. /**
  5421. * 调整当前range的边界到书签位置,并删除该书签对象所标记的位置内的节点
  5422. *
  5423. * @method moveToBookmark
  5424. * @param {
  5425. * BookMark } bookmark createBookmark所创建的标签对象
  5426. * @return { UE.dom.Range } 当前range对象
  5427. * @see UE.dom.Range:createBookmark(Boolean)
  5428. */
  5429. moveToBookmark: function(bookmark) {
  5430. var start = bookmark.id ? this.document
  5431. .getElementById(bookmark.start) : bookmark.start,
  5432. end = bookmark.end &&
  5433. bookmark.id ? this.document
  5434. .getElementById(bookmark.end) : bookmark.end;
  5435. this.setStartBefore(start);
  5436. domUtils.remove(start);
  5437. if(end) {
  5438. this.setEndBefore(end);
  5439. domUtils.remove(end);
  5440. } else {
  5441. this.collapse(true);
  5442. }
  5443. return this;
  5444. },
  5445. /**
  5446. * 调整range的边界,使其"放大"到最近的父节点
  5447. *
  5448. * @method enlarge
  5449. * @remind 会引起选区的变化
  5450. * @return { UE.dom.Range } 当前range对象
  5451. */
  5452. /**
  5453. * 调整range的边界,使其"放大"到最近的父节点,根据参数 toBlock 的取值, 可以 要求扩大之后的父节点是block节点
  5454. *
  5455. * @method enlarge
  5456. * @param {
  5457. * Boolean } toBlock 是否要求扩大之后的父节点必须是block节点
  5458. * @return { UE.dom.Range } 当前range对象
  5459. */
  5460. enlarge: function(toBlock, stopFn) {
  5461. var isBody = domUtils.isBody,
  5462. pre, node, tmp = this.document
  5463. .createTextNode('');
  5464. if(toBlock) {
  5465. node = this.startContainer;
  5466. if(node.nodeType == 1) {
  5467. if(node.childNodes[this.startOffset]) {
  5468. pre = node = node.childNodes[this.startOffset]
  5469. } else {
  5470. node.appendChild(tmp);
  5471. pre = node = tmp;
  5472. }
  5473. } else {
  5474. pre = node;
  5475. }
  5476. while(1) {
  5477. if(domUtils.isBlockElm(node)) {
  5478. node = pre;
  5479. while((pre = node.previousSibling) &&
  5480. !domUtils.isBlockElm(pre)) {
  5481. node = pre;
  5482. }
  5483. this.setStartBefore(node);
  5484. break;
  5485. }
  5486. pre = node;
  5487. node = node.parentNode;
  5488. }
  5489. node = this.endContainer;
  5490. if(node.nodeType == 1) {
  5491. if(pre = node.childNodes[this.endOffset]) {
  5492. node.insertBefore(tmp, pre);
  5493. } else {
  5494. node.appendChild(tmp);
  5495. }
  5496. pre = node = tmp;
  5497. } else {
  5498. pre = node;
  5499. }
  5500. while(1) {
  5501. if(domUtils.isBlockElm(node)) {
  5502. node = pre;
  5503. while((pre = node.nextSibling) &&
  5504. !domUtils.isBlockElm(pre)) {
  5505. node = pre;
  5506. }
  5507. this.setEndAfter(node);
  5508. break;
  5509. }
  5510. pre = node;
  5511. node = node.parentNode;
  5512. }
  5513. if(tmp.parentNode === this.endContainer) {
  5514. this.endOffset--;
  5515. }
  5516. domUtils.remove(tmp);
  5517. }
  5518. // 扩展边界到最大
  5519. if(!this.collapsed) {
  5520. while(this.startOffset == 0) {
  5521. if(stopFn && stopFn(this.startContainer)) {
  5522. break;
  5523. }
  5524. if(isBody(this.startContainer)) {
  5525. break;
  5526. }
  5527. this.setStartBefore(this.startContainer);
  5528. }
  5529. while(this.endOffset == (this.endContainer.nodeType == 1 ?
  5530. this.endContainer.childNodes.length :
  5531. this.endContainer.nodeValue.length)) {
  5532. if(stopFn && stopFn(this.endContainer)) {
  5533. break;
  5534. }
  5535. if(isBody(this.endContainer)) {
  5536. break;
  5537. }
  5538. this.setEndAfter(this.endContainer);
  5539. }
  5540. }
  5541. return this;
  5542. },
  5543. enlargeToBlockElm: function(ignoreEnd) {
  5544. while(!domUtils.isBlockElm(this.startContainer)) {
  5545. this.setStartBefore(this.startContainer);
  5546. }
  5547. if(!ignoreEnd) {
  5548. while(!domUtils.isBlockElm(this.endContainer)) {
  5549. this.setEndAfter(this.endContainer);
  5550. }
  5551. }
  5552. return this;
  5553. },
  5554. /**
  5555. * 调整Range的边界,使其"缩小"到最合适的位置
  5556. *
  5557. * @method adjustmentBoundary
  5558. * @return { UE.dom.Range } 当前range对象
  5559. * @see UE.dom.Range:shrinkBoundary()
  5560. */
  5561. adjustmentBoundary: function() {
  5562. if(!this.collapsed) {
  5563. while(!domUtils.isBody(this.startContainer) &&
  5564. this.startOffset == this.startContainer[this.startContainer.nodeType == 3 ?
  5565. 'nodeValue' :
  5566. 'childNodes'].length &&
  5567. this.startContainer[this.startContainer.nodeType == 3 ?
  5568. 'nodeValue' :
  5569. 'childNodes'].length) {
  5570. this.setStartAfter(this.startContainer);
  5571. }
  5572. while(!domUtils.isBody(this.endContainer) &&
  5573. !this.endOffset &&
  5574. this.endContainer[this.endContainer.nodeType == 3 ?
  5575. 'nodeValue' :
  5576. 'childNodes'].length) {
  5577. this.setEndBefore(this.endContainer);
  5578. }
  5579. }
  5580. return this;
  5581. },
  5582. /**
  5583. * 给range选区中的内容添加给定的inline标签
  5584. *
  5585. * @method applyInlineStyle
  5586. * @param {
  5587. * String } tagName 需要添加的标签名
  5588. * @example ```html
  5589. * <p>
  5590. * xxxx[xxxx]x
  5591. * </p>
  5592. * ==> range.applyInlineStyle("strong") ==>
  5593. * <p>
  5594. * xxxx[<strong>xxxx</strong>]x
  5595. * </p>
  5596. * ```
  5597. */
  5598. /**
  5599. * 给range选区中的内容添加给定的inline标签, 并且为标签附加上一些初始化属性。
  5600. *
  5601. * @method applyInlineStyle
  5602. * @param {
  5603. * String } tagName 需要添加的标签名
  5604. * @param {
  5605. * Object } attrs 跟随新添加的标签的属性
  5606. * @return { UE.dom.Range } 当前选区
  5607. * @example ```html
  5608. * <p>
  5609. * xxxx[xxxx]x
  5610. * </p>
  5611. *
  5612. * ==>
  5613. *
  5614. * <!-- 执行操作 -->
  5615. * range.applyInlineStyle("strong",{"style":"font-size:12px"})
  5616. *
  5617. * ==>
  5618. *
  5619. * <p>
  5620. * xxxx[<strong style="font-size:12px">xxxx</strong>]x
  5621. * </p>
  5622. * ```
  5623. */
  5624. applyInlineStyle: function(tagName, attrs, list) {
  5625. if(this.collapsed)
  5626. return this;
  5627. this.trimBoundary().enlarge(false, function(node) {
  5628. return node.nodeType == 1 && domUtils.isBlockElm(node)
  5629. }).adjustmentBoundary();
  5630. var bookmark = this.createBookmark(),
  5631. end = bookmark.end,
  5632. filterFn = function(
  5633. node) {
  5634. return node.nodeType == 1 ?
  5635. node.tagName.toLowerCase() != 'br' :
  5636. !domUtils.isWhitespace(node);
  5637. },
  5638. current = domUtils.getNextDomNode(bookmark.start, false,
  5639. filterFn),
  5640. node, pre, range = this.cloneRange();
  5641. while(current &&
  5642. (domUtils.getPosition(current, end) & domUtils.POSITION_PRECEDING)) {
  5643. if(current.nodeType == 3 || dtd[tagName][current.tagName]) {
  5644. range.setStartBefore(current);
  5645. node = current;
  5646. while(node &&
  5647. (node.nodeType == 3 || dtd[tagName][node.tagName]) &&
  5648. node !== end) {
  5649. pre = node;
  5650. node = domUtils.getNextDomNode(node,
  5651. node.nodeType == 1, null,
  5652. function(parent) {
  5653. return dtd[tagName][parent.tagName];
  5654. });
  5655. }
  5656. var frag = range.setEndAfter(pre).extractContents(),
  5657. elm;
  5658. if(list && list.length > 0) {
  5659. var level, top;
  5660. top = level = list[0].cloneNode(false);
  5661. for(var i = 1, ci; ci = list[i++];) {
  5662. level.appendChild(ci.cloneNode(false));
  5663. level = level.firstChild;
  5664. }
  5665. elm = level;
  5666. } else {
  5667. elm = range.document.createElement(tagName);
  5668. }
  5669. if(attrs) {
  5670. domUtils.setAttributes(elm, attrs);
  5671. }
  5672. elm.appendChild(frag);
  5673. range.insertNode(list ? top : elm);
  5674. // 处理下滑线在a上的情况
  5675. var aNode;
  5676. if(tagName == 'span' &&
  5677. attrs.style &&
  5678. /text\-decoration/.test(attrs.style) &&
  5679. (aNode = domUtils.findParentByTagName(elm,
  5680. 'a', true))) {
  5681. domUtils.setAttributes(aNode, attrs);
  5682. domUtils.remove(elm, true);
  5683. elm = aNode;
  5684. } else {
  5685. domUtils.mergeSibling(elm);
  5686. domUtils.clearEmptySibling(elm);
  5687. }
  5688. // 去除子节点相同的
  5689. domUtils.mergeChild(elm, attrs);
  5690. current = domUtils.getNextDomNode(elm, false, filterFn);
  5691. domUtils.mergeToParent(elm);
  5692. if(node === end) {
  5693. break;
  5694. }
  5695. } else {
  5696. current = domUtils.getNextDomNode(current, true,
  5697. filterFn);
  5698. }
  5699. }
  5700. return this.moveToBookmark(bookmark);
  5701. },
  5702. /**
  5703. * 移除当前选区内指定的inline标签,但保留其中的内容
  5704. *
  5705. * @method removeInlineStyle
  5706. * @param {
  5707. * String } tagName 需要移除的标签名
  5708. * @return { UE.dom.Range } 当前的range对象
  5709. * @example ```html xx[x<span>xxx<em>yyy</em>zz]z</span> =>
  5710. * range.removeInlineStyle(["em"]) => xx[x<span>xxxyyyzz]z</span>
  5711. * ```
  5712. */
  5713. /**
  5714. * 移除当前选区内指定的一组inline标签,但保留其中的内容
  5715. *
  5716. * @method removeInlineStyle
  5717. * @param {
  5718. * Array } tagNameArr 需要移除的标签名的数组
  5719. * @return { UE.dom.Range } 当前的range对象
  5720. * @see UE.dom.Range:removeInlineStyle(String)
  5721. */
  5722. removeInlineStyle: function(tagNames) {
  5723. if(this.collapsed)
  5724. return this;
  5725. tagNames = utils.isArray(tagNames) ? tagNames : [tagNames];
  5726. this.shrinkBoundary().adjustmentBoundary();
  5727. var start = this.startContainer,
  5728. end = this.endContainer;
  5729. while(1) {
  5730. if(start.nodeType == 1) {
  5731. if(utils
  5732. .indexOf(tagNames, start.tagName.toLowerCase()) > -1) {
  5733. break;
  5734. }
  5735. if(start.tagName.toLowerCase() == 'body') {
  5736. start = null;
  5737. break;
  5738. }
  5739. }
  5740. start = start.parentNode;
  5741. }
  5742. while(1) {
  5743. if(end.nodeType == 1) {
  5744. if(utils.indexOf(tagNames, end.tagName.toLowerCase()) > -1) {
  5745. break;
  5746. }
  5747. if(end.tagName.toLowerCase() == 'body') {
  5748. end = null;
  5749. break;
  5750. }
  5751. }
  5752. end = end.parentNode;
  5753. }
  5754. var bookmark = this.createBookmark(),
  5755. frag, tmpRange;
  5756. if(start) {
  5757. tmpRange = this.cloneRange().setEndBefore(bookmark.start)
  5758. .setStartBefore(start);
  5759. frag = tmpRange.extractContents();
  5760. tmpRange.insertNode(frag);
  5761. domUtils.clearEmptySibling(start, true);
  5762. start.parentNode.insertBefore(bookmark.start, start);
  5763. }
  5764. if(end) {
  5765. tmpRange = this.cloneRange().setStartAfter(bookmark.end)
  5766. .setEndAfter(end);
  5767. frag = tmpRange.extractContents();
  5768. tmpRange.insertNode(frag);
  5769. domUtils.clearEmptySibling(end, false, true);
  5770. end.parentNode.insertBefore(bookmark.end, end.nextSibling);
  5771. }
  5772. var current = domUtils.getNextDomNode(bookmark.start, false,
  5773. function(node) {
  5774. return node.nodeType == 1;
  5775. }),
  5776. next;
  5777. while(current && current !== bookmark.end) {
  5778. next = domUtils.getNextDomNode(current, true,
  5779. function(node) {
  5780. return node.nodeType == 1;
  5781. });
  5782. if(utils.indexOf(tagNames, current.tagName.toLowerCase()) > -1) {
  5783. domUtils.remove(current, true);
  5784. }
  5785. current = next;
  5786. }
  5787. return this.moveToBookmark(bookmark);
  5788. },
  5789. /**
  5790. * 获取当前选中的自闭合的节点
  5791. *
  5792. * @method getClosedNode
  5793. * @return { Node | NULL } 如果当前选中的是自闭合节点, 则返回该节点, 否则返回NULL
  5794. */
  5795. getClosedNode: function() {
  5796. var node;
  5797. if(!this.collapsed) {
  5798. var range = this.cloneRange().adjustmentBoundary()
  5799. .shrinkBoundary();
  5800. if(selectOneNode(range)) {
  5801. var child = range.startContainer.childNodes[range.startOffset];
  5802. if(child &&
  5803. child.nodeType == 1 &&
  5804. (dtd.$empty[child.tagName] || dtd.$nonChild[child.tagName])) {
  5805. node = child;
  5806. }
  5807. }
  5808. }
  5809. return node;
  5810. },
  5811. /**
  5812. * 在页面上高亮range所表示的选区
  5813. *
  5814. * @method select
  5815. * @return { UE.dom.Range } 返回当前Range对象
  5816. */
  5817. // 这里不区分ie9以上,trace:3824
  5818. select: browser.ie ? function(noFillData, textRange) {
  5819. var nativeRange;
  5820. if(!this.collapsed)
  5821. this.shrinkBoundary();
  5822. var node = this.getClosedNode();
  5823. if(node && !textRange) {
  5824. try {
  5825. nativeRange = this.document.body.createControlRange();
  5826. nativeRange.addElement(node);
  5827. nativeRange.select();
  5828. } catch(e) {}
  5829. return this;
  5830. }
  5831. var bookmark = this.createBookmark(),
  5832. start = bookmark.start,
  5833. end;
  5834. nativeRange = this.document.body.createTextRange();
  5835. nativeRange.moveToElementText(start);
  5836. nativeRange.moveStart('character', 1);
  5837. if(!this.collapsed) {
  5838. var nativeRangeEnd = this.document.body.createTextRange();
  5839. end = bookmark.end;
  5840. nativeRangeEnd.moveToElementText(end);
  5841. nativeRange.setEndPoint('EndToEnd', nativeRangeEnd);
  5842. } else {
  5843. if(!noFillData && this.startContainer.nodeType != 3) {
  5844. // 使用<span>|x<span>固定住光标
  5845. var tmpText = this.document.createTextNode(fillChar),
  5846. tmp = this.document
  5847. .createElement('span');
  5848. tmp.appendChild(this.document.createTextNode(fillChar));
  5849. start.parentNode.insertBefore(tmp, start);
  5850. start.parentNode.insertBefore(tmpText, start);
  5851. // 当点b,i,u时,不能清除i上边的b
  5852. removeFillData(this.document, tmpText);
  5853. fillData = tmpText;
  5854. mergeSibling(tmp, 'previousSibling');
  5855. mergeSibling(start, 'nextSibling');
  5856. nativeRange.moveStart('character', -1);
  5857. nativeRange.collapse(true);
  5858. }
  5859. }
  5860. this.moveToBookmark(bookmark);
  5861. tmp && domUtils.remove(tmp);
  5862. // IE在隐藏状态下不支持range操作,catch一下
  5863. try {
  5864. nativeRange.select();
  5865. } catch(e) {}
  5866. return this;
  5867. } : function(notInsertFillData) {
  5868. function checkOffset(rng) {
  5869. function check(node, offset, dir) {
  5870. if(node.nodeType == 3 &&
  5871. node.nodeValue.length < offset) {
  5872. rng[dir + 'Offset'] = node.nodeValue.length
  5873. }
  5874. }
  5875. check(rng.startContainer, rng.startOffset, 'start');
  5876. check(rng.endContainer, rng.endOffset, 'end');
  5877. }
  5878. var win = domUtils.getWindow(this.document),
  5879. sel = win
  5880. .getSelection(),
  5881. txtNode;
  5882. // FF下关闭自动长高时滚动条在关闭dialog时会跳
  5883. // ff下如果不body.focus将不能定位闭合光标到编辑器内
  5884. browser.gecko ? this.document.body.focus() : win
  5885. .focus();
  5886. if(sel) {
  5887. sel.removeAllRanges();
  5888. // trace:870 chrome/safari后边是br对于闭合得range不能定位
  5889. // 所以去掉了判断
  5890. // this.startContainer.nodeType != 3 &&! ((child =
  5891. // this.startContainer.childNodes[this.startOffset])
  5892. // &&
  5893. // child.nodeType == 1 && child.tagName == 'BR'
  5894. if(this.collapsed && !notInsertFillData) {
  5895. // //opear如果没有节点接着,原生的不能够定位,不能在body的第一级插入空白节点
  5896. // if (notInsertFillData && browser.opera &&
  5897. // !domUtils.isBody(this.startContainer) &&
  5898. // this.startContainer.nodeType == 1) {
  5899. // var tmp = this.document.createTextNode('');
  5900. // this.insertNode(tmp).setStart(tmp,
  5901. // 0).collapse(true);
  5902. // }
  5903. //
  5904. // 处理光标落在文本节点的情况
  5905. // 处理以下的情况
  5906. // <b>|xxxx</b>
  5907. // <b>xxxx</b>|xxxx
  5908. // xxxx<b>|</b>
  5909. var start = this.startContainer,
  5910. child = start;
  5911. if(start.nodeType == 1) {
  5912. child = start.childNodes[this.startOffset];
  5913. }
  5914. if(!(start.nodeType == 3 && this.startOffset) &&
  5915. (child ?
  5916. (!child.previousSibling || child.previousSibling.nodeType != 3) :
  5917. (!start.lastChild || start.lastChild.nodeType != 3))) {
  5918. txtNode = this.document
  5919. .createTextNode(fillChar);
  5920. // 跟着前边走
  5921. this.insertNode(txtNode);
  5922. removeFillData(this.document, txtNode);
  5923. mergeSibling(txtNode, 'previousSibling');
  5924. mergeSibling(txtNode, 'nextSibling');
  5925. fillData = txtNode;
  5926. this.setStart(txtNode,
  5927. browser.webkit ? 1 : 0)
  5928. .collapse(true);
  5929. }
  5930. }
  5931. var nativeRange = this.document.createRange();
  5932. if(this.collapsed && browser.opera &&
  5933. this.startContainer.nodeType == 1) {
  5934. var child = this.startContainer.childNodes[this.startOffset];
  5935. if(!child) {
  5936. // 往前靠拢
  5937. child = this.startContainer.lastChild;
  5938. if(child && domUtils.isBr(child)) {
  5939. this.setStartBefore(child)
  5940. .collapse(true);
  5941. }
  5942. } else {
  5943. // 向后靠拢
  5944. while(child && domUtils.isBlockElm(child)) {
  5945. if(child.nodeType == 1 &&
  5946. child.childNodes[0]) {
  5947. child = child.childNodes[0]
  5948. } else {
  5949. break;
  5950. }
  5951. }
  5952. child
  5953. &&
  5954. this.setStartBefore(child)
  5955. .collapse(true)
  5956. }
  5957. }
  5958. // 是createAddress最后一位算的不准,现在这里进行微调
  5959. checkOffset(this);
  5960. nativeRange.setStart(this.startContainer,
  5961. this.startOffset);
  5962. nativeRange.setEnd(this.endContainer,
  5963. this.endOffset);
  5964. sel.addRange(nativeRange);
  5965. }
  5966. return this;
  5967. },
  5968. /**
  5969. * 滚动到当前range开始的位置
  5970. *
  5971. * @method scrollToView
  5972. * @param {
  5973. * Window } win 当前range对象所属的window对象
  5974. * @return { UE.dom.Range } 当前Range对象
  5975. */
  5976. /**
  5977. * 滚动到距离当前range开始位置 offset 的位置处
  5978. *
  5979. * @method scrollToView
  5980. * @param {
  5981. * Window } win 当前range对象所属的window对象
  5982. * @param {
  5983. * Number } offset 距离range开始位置处的偏移量, 如果为正数, 则向下偏移, 反之,
  5984. * 则向上偏移
  5985. * @return { UE.dom.Range } 当前Range对象
  5986. */
  5987. scrollToView: function(win, offset) {
  5988. win = win ? window : domUtils.getWindow(this.document);
  5989. var me = this,
  5990. span = me.document.createElement('span');
  5991. // trace:717
  5992. span.innerHTML = '&nbsp;';
  5993. me.cloneRange().insertNode(span);
  5994. domUtils.scrollToView(span, win, offset);
  5995. domUtils.remove(span);
  5996. return me;
  5997. },
  5998. /**
  5999. * 判断当前选区内容是否占位符
  6000. *
  6001. * @private
  6002. * @method inFillChar
  6003. * @return { Boolean } 如果是占位符返回true,否则返回false
  6004. */
  6005. inFillChar: function() {
  6006. var start = this.startContainer;
  6007. if(this.collapsed &&
  6008. start.nodeType == 3 &&
  6009. start.nodeValue.replace(new RegExp('^' +
  6010. domUtils.fillChar), '').length +
  6011. 1 == start.nodeValue.length) {
  6012. return true;
  6013. }
  6014. return false;
  6015. },
  6016. /**
  6017. * 保存
  6018. *
  6019. * @method createAddress
  6020. * @private
  6021. * @return { Boolean } 返回开始和结束的位置
  6022. * @example ```html <body>
  6023. * <p>
  6024. * aaaa <em>
  6025. * <!-- 选区开始 -->
  6026. * bbbb
  6027. * <!-- 选区结束 -->
  6028. * </em>
  6029. * </p>
  6030. *
  6031. * <script> //output: {startAddress:[0,1,0,0],endAddress:[0,1,0,4]}
  6032. * console.log( range.createAddress() ); </script> </body> ```
  6033. */
  6034. createAddress: function(ignoreEnd, ignoreTxt) {
  6035. var addr = {},
  6036. me = this;
  6037. function getAddress(isStart) {
  6038. var node = isStart ? me.startContainer : me.endContainer;
  6039. var parents = domUtils.findParents(node, true, function(
  6040. node) {
  6041. return !domUtils.isBody(node)
  6042. }),
  6043. addrs = [];
  6044. for(var i = 0, ci; ci = parents[i++];) {
  6045. addrs.push(domUtils.getNodeIndex(ci, ignoreTxt));
  6046. }
  6047. var firstIndex = 0;
  6048. if(ignoreTxt) {
  6049. if(node.nodeType == 3) {
  6050. var tmpNode = node.previousSibling;
  6051. while(tmpNode && tmpNode.nodeType == 3) {
  6052. firstIndex += tmpNode.nodeValue.replace(
  6053. fillCharReg, '').length;
  6054. tmpNode = tmpNode.previousSibling;
  6055. }
  6056. firstIndex += (isStart ?
  6057. me.startOffset :
  6058. me.endOffset) // -
  6059. // (fillCharReg.test(node.nodeValue)
  6060. // ? 1
  6061. // : 0
  6062. // )
  6063. } else {
  6064. node = node.childNodes[isStart ?
  6065. me.startOffset :
  6066. me.endOffset];
  6067. if(node) {
  6068. firstIndex = domUtils.getNodeIndex(node,
  6069. ignoreTxt);
  6070. } else {
  6071. node = isStart ?
  6072. me.startContainer :
  6073. me.endContainer;
  6074. var first = node.firstChild;
  6075. while(first) {
  6076. if(domUtils.isFillChar(first)) {
  6077. first = first.nextSibling;
  6078. continue;
  6079. }
  6080. firstIndex++;
  6081. if(first.nodeType == 3) {
  6082. while(first && first.nodeType == 3) {
  6083. first = first.nextSibling;
  6084. }
  6085. } else {
  6086. first = first.nextSibling;
  6087. }
  6088. }
  6089. }
  6090. }
  6091. } else {
  6092. firstIndex = isStart ? domUtils.isFillChar(node) ?
  6093. 0 :
  6094. me.startOffset : me.endOffset
  6095. }
  6096. if(firstIndex < 0) {
  6097. firstIndex = 0;
  6098. }
  6099. addrs.push(firstIndex);
  6100. return addrs;
  6101. }
  6102. addr.startAddress = getAddress(true);
  6103. if(!ignoreEnd) {
  6104. addr.endAddress = me.collapsed ? []
  6105. .concat(addr.startAddress) : getAddress();
  6106. }
  6107. return addr;
  6108. },
  6109. /**
  6110. * 保存
  6111. *
  6112. * @method createAddress
  6113. * @private
  6114. * @return { Boolean } 返回开始和结束的位置
  6115. * @example ```html <body>
  6116. * <p>
  6117. * aaaa <em>
  6118. * <!-- 选区开始 -->
  6119. * bbbb
  6120. * <!-- 选区结束 -->
  6121. * </em>
  6122. * </p>
  6123. *
  6124. * <script> var range = editor.selection.getRange();
  6125. * range.moveToAddress({startAddress:[0,1,0,0],endAddress:[0,1,0,4]});
  6126. * range.select(); //output: 'bbbb'
  6127. * console.log(editor.selection.getText()); </script> </body> ```
  6128. */
  6129. moveToAddress: function(addr, ignoreEnd) {
  6130. var me = this;
  6131. function getNode(address, isStart) {
  6132. var tmpNode = me.document.body,
  6133. parentNode, offset;
  6134. for(var i = 0, ci, l = address.length; i < l; i++) {
  6135. ci = address[i];
  6136. parentNode = tmpNode;
  6137. tmpNode = tmpNode.childNodes[ci];
  6138. if(!tmpNode) {
  6139. offset = ci;
  6140. break;
  6141. }
  6142. }
  6143. if(isStart) {
  6144. if(tmpNode) {
  6145. me.setStartBefore(tmpNode)
  6146. } else {
  6147. me.setStart(parentNode, offset)
  6148. }
  6149. } else {
  6150. if(tmpNode) {
  6151. me.setEndBefore(tmpNode)
  6152. } else {
  6153. me.setEnd(parentNode, offset)
  6154. }
  6155. }
  6156. }
  6157. getNode(addr.startAddress, true);
  6158. !ignoreEnd && addr.endAddress && getNode(addr.endAddress);
  6159. return me;
  6160. },
  6161. /**
  6162. * 判断给定的Range对象是否和当前Range对象表示的是同一个选区
  6163. *
  6164. * @method equals
  6165. * @param {
  6166. * UE.dom.Range } 需要判断的Range对象
  6167. * @return { Boolean } 如果给定的Range对象与当前Range对象表示的是同一个选区, 则返回true,
  6168. * 否则返回false
  6169. */
  6170. equals: function(rng) {
  6171. for(var p in this) {
  6172. if(this.hasOwnProperty(p)) {
  6173. if(this[p] !== rng[p])
  6174. return false
  6175. }
  6176. }
  6177. return true;
  6178. },
  6179. /**
  6180. * 遍历range内的节点。每当遍历一个节点时, 都会执行参数项 doFn 指定的函数, 该函数的接受当前遍历的节点 作为其参数。
  6181. *
  6182. * @method traversal
  6183. * @param {
  6184. * Function } doFn 对每个遍历的节点要执行的方法, 该方法接受当前遍历的节点作为其参数
  6185. * @return { UE.dom.Range } 当前range对象
  6186. * @example ```html
  6187. *
  6188. * <body>
  6189. *
  6190. * <!-- 选区开始 --> <span></span> <a></a> <!-- 选区结束 --> </body>
  6191. *
  6192. * <script>
  6193. *
  6194. * //output: <span></span><a></a> console.log(
  6195. * range.cloneContents() );
  6196. *
  6197. * range.traversal( function ( node ) {
  6198. *
  6199. * if ( node.nodeType === 1 ) { node.className = "test"; } } );
  6200. *
  6201. * //output: <span class="test"></span><a class="test"></a>
  6202. * console.log( range.cloneContents() );
  6203. *
  6204. * </script> ```
  6205. */
  6206. /**
  6207. * 遍历range内的节点。 每当遍历一个节点时, 都会执行参数项 doFn 指定的函数, 该函数的接受当前遍历的节点 作为其参数。
  6208. * 可以通过参数项 filterFn 来指定一个过滤器, 只有符合该过滤器过滤规则的节点才会触 发doFn函数的执行
  6209. *
  6210. * @method traversal
  6211. * @param {
  6212. * Function } doFn 对每个遍历的节点要执行的方法, 该方法接受当前遍历的节点作为其参数
  6213. * @param {
  6214. * Function } filterFn 过滤器, 该函数接受当前遍历的节点作为参数, 如果该节点满足过滤
  6215. * 规则, 请返回true, 该节点会触发doFn, 否则, 请返回false, 则该节点不 会触发doFn。
  6216. * @return { UE.dom.Range } 当前range对象
  6217. * @see UE.dom.Range:traversal(Function)
  6218. * @example ```html
  6219. *
  6220. * <body>
  6221. *
  6222. * <!-- 选区开始 --> <span></span> <a></a> <!-- 选区结束 --> </body>
  6223. *
  6224. * <script>
  6225. *
  6226. * //output: <span></span><a></a> console.log(
  6227. * range.cloneContents() );
  6228. *
  6229. * range.traversal( function ( node ) {
  6230. *
  6231. * node.className = "test"; }, function ( node ) { return
  6232. * node.nodeType === 1; } );
  6233. *
  6234. * //output: <span class="test"></span><a class="test"></a>
  6235. * console.log( range.cloneContents() );
  6236. *
  6237. * </script> ```
  6238. */
  6239. traversal: function(doFn, filterFn) {
  6240. if(this.collapsed)
  6241. return this;
  6242. var bookmark = this.createBookmark(),
  6243. end = bookmark.end,
  6244. current = domUtils
  6245. .getNextDomNode(bookmark.start, false, filterFn);
  6246. while(current &&
  6247. current !== end &&
  6248. (domUtils.getPosition(current, end) & domUtils.POSITION_PRECEDING)) {
  6249. var tmpNode = domUtils.getNextDomNode(current, false,
  6250. filterFn);
  6251. doFn(current);
  6252. current = tmpNode;
  6253. }
  6254. return this.moveToBookmark(bookmark);
  6255. }
  6256. };
  6257. })();
  6258. // core/Selection.js
  6259. /**
  6260. * 选集
  6261. *
  6262. * @file
  6263. * @module UE.dom
  6264. * @class Selection
  6265. * @since 1.2.6.1
  6266. */
  6267. /**
  6268. * 选区集合
  6269. *
  6270. * @unfile
  6271. * @module UE.dom
  6272. * @class Selection
  6273. */
  6274. (function() {
  6275. function getBoundaryInformation(range, start) {
  6276. var getIndex = domUtils.getNodeIndex;
  6277. range = range.duplicate();
  6278. range.collapse(start);
  6279. var parent = range.parentElement();
  6280. // 如果节点里没有子节点,直接退出
  6281. if(!parent.hasChildNodes()) {
  6282. return {
  6283. container: parent,
  6284. offset: 0
  6285. };
  6286. }
  6287. var siblings = parent.children,
  6288. child, testRange = range
  6289. .duplicate(),
  6290. startIndex = 0,
  6291. endIndex = siblings.length -
  6292. 1,
  6293. index = -1,
  6294. distance;
  6295. while(startIndex <= endIndex) {
  6296. index = Math.floor((startIndex + endIndex) / 2);
  6297. child = siblings[index];
  6298. testRange.moveToElementText(child);
  6299. var position = testRange
  6300. .compareEndPoints('StartToStart', range);
  6301. if(position > 0) {
  6302. endIndex = index - 1;
  6303. } else if(position < 0) {
  6304. startIndex = index + 1;
  6305. } else {
  6306. // trace:1043
  6307. return {
  6308. container: parent,
  6309. offset: getIndex(child)
  6310. };
  6311. }
  6312. }
  6313. if(index == -1) {
  6314. testRange.moveToElementText(parent);
  6315. testRange.setEndPoint('StartToStart', range);
  6316. distance = testRange.text.replace(/(\r\n|\r)/g, '\n').length;
  6317. siblings = parent.childNodes;
  6318. if(!distance) {
  6319. child = siblings[siblings.length - 1];
  6320. return {
  6321. container: child,
  6322. offset: child.nodeValue.length
  6323. };
  6324. }
  6325. var i = siblings.length;
  6326. while(distance > 0) {
  6327. distance -= siblings[--i].nodeValue.length;
  6328. }
  6329. return {
  6330. container: siblings[i],
  6331. offset: -distance
  6332. };
  6333. }
  6334. testRange.collapse(position > 0);
  6335. testRange.setEndPoint(position > 0 ? 'StartToStart' : 'EndToStart',
  6336. range);
  6337. distance = testRange.text.replace(/(\r\n|\r)/g, '\n').length;
  6338. if(!distance) {
  6339. return dtd.$empty[child.tagName] ||
  6340. dtd.$nonChild[child.tagName] ? {
  6341. container: parent,
  6342. offset: getIndex(child) + (position > 0 ? 0 : 1)
  6343. } : {
  6344. container: child,
  6345. offset: position > 0 ? 0 : child.childNodes.length
  6346. }
  6347. }
  6348. while(distance > 0) {
  6349. try {
  6350. var pre = child;
  6351. child = child[position > 0 ?
  6352. 'previousSibling' :
  6353. 'nextSibling'];
  6354. distance -= child.nodeValue.length;
  6355. } catch(e) {
  6356. return {
  6357. container: parent,
  6358. offset: getIndex(pre)
  6359. };
  6360. }
  6361. }
  6362. return {
  6363. container: child,
  6364. offset: position > 0 ? -distance : child.nodeValue.length +
  6365. distance
  6366. }
  6367. }
  6368. /**
  6369. * 将ieRange转换为Range对象
  6370. *
  6371. * @param {Range}
  6372. * ieRange ieRange对象
  6373. * @param {Range}
  6374. * range Range对象
  6375. * @return {Range} range 返回转换后的Range对象
  6376. */
  6377. function transformIERangeToRange(ieRange, range) {
  6378. if(ieRange.item) {
  6379. range.selectNode(ieRange.item(0));
  6380. } else {
  6381. var bi = getBoundaryInformation(ieRange, true);
  6382. range.setStart(bi.container, bi.offset);
  6383. if(ieRange.compareEndPoints('StartToEnd', ieRange) != 0) {
  6384. bi = getBoundaryInformation(ieRange, false);
  6385. range.setEnd(bi.container, bi.offset);
  6386. }
  6387. }
  6388. return range;
  6389. }
  6390. /**
  6391. * 获得ieRange
  6392. *
  6393. * @param {Selection}
  6394. * sel Selection对象
  6395. * @return {ieRange} 得到ieRange
  6396. */
  6397. function _getIERange(sel) {
  6398. var ieRange;
  6399. // ie下有可能报错
  6400. try {
  6401. ieRange = sel.getNative().createRange();
  6402. } catch(e) {
  6403. return null;
  6404. }
  6405. var el = ieRange.item ? ieRange.item(0) : ieRange.parentElement();
  6406. if((el.ownerDocument || el) === sel.document) {
  6407. return ieRange;
  6408. }
  6409. return null;
  6410. }
  6411. var Selection = dom.Selection = function(doc) {
  6412. var me = this,
  6413. iframe;
  6414. me.document = doc;
  6415. if(browser.ie9below) {
  6416. iframe = domUtils.getWindow(doc).frameElement;
  6417. domUtils.on(iframe, 'beforedeactivate', function() {
  6418. me._bakIERange = me.getIERange();
  6419. });
  6420. domUtils.on(iframe, 'activate', function() {
  6421. try {
  6422. if(!_getIERange(me) && me._bakIERange) {
  6423. me._bakIERange.select();
  6424. }
  6425. } catch(ex) {}
  6426. me._bakIERange = null;
  6427. });
  6428. }
  6429. iframe = doc = null;
  6430. };
  6431. Selection.prototype = {
  6432. rangeInBody: function(rng, txtRange) {
  6433. var node = browser.ie9below || txtRange ? rng.item ?
  6434. rng.item() :
  6435. rng.parentElement() : rng.startContainer;
  6436. return node === this.document.body ||
  6437. domUtils.inDoc(node, this.document);
  6438. },
  6439. /**
  6440. * 获取原生seleciton对象
  6441. *
  6442. * @method getNative
  6443. * @return { Object } 获得selection对象
  6444. * @example ```javascript editor.selection.getNative(); ```
  6445. */
  6446. getNative: function() {
  6447. var doc = this.document;
  6448. try {
  6449. return !doc ? null : browser.ie9below ?
  6450. doc.selection :
  6451. domUtils.getWindow(doc).getSelection();
  6452. } catch(e) {
  6453. return null;
  6454. }
  6455. },
  6456. /**
  6457. * 获得ieRange
  6458. *
  6459. * @method getIERange
  6460. * @return { Object } 返回ie原生的Range
  6461. * @example ```javascript editor.selection.getIERange(); ```
  6462. */
  6463. getIERange: function() {
  6464. var ieRange = _getIERange(this);
  6465. if(!ieRange) {
  6466. if(this._bakIERange) {
  6467. return this._bakIERange;
  6468. }
  6469. }
  6470. return ieRange;
  6471. },
  6472. /**
  6473. * 缓存当前选区的range和选区的开始节点
  6474. *
  6475. * @method cache
  6476. */
  6477. cache: function() {
  6478. this.clear();
  6479. this._cachedRange = this.getRange();
  6480. this._cachedStartElement = this.getStart();
  6481. this._cachedStartElementPath = this.getStartElementPath();
  6482. },
  6483. /**
  6484. * 获取选区开始位置的父节点到body
  6485. *
  6486. * @method getStartElementPath
  6487. * @return { Array } 返回父节点集合
  6488. * @example ```javascript editor.selection.getStartElementPath();
  6489. * ```
  6490. */
  6491. getStartElementPath: function() {
  6492. if(this._cachedStartElementPath) {
  6493. return this._cachedStartElementPath;
  6494. }
  6495. var start = this.getStart();
  6496. if(start) {
  6497. return domUtils.findParents(start, true, null, true)
  6498. }
  6499. return [];
  6500. },
  6501. /**
  6502. * 清空缓存
  6503. *
  6504. * @method clear
  6505. */
  6506. clear: function() {
  6507. this._cachedStartElementPath = this._cachedRange = this._cachedStartElement = null;
  6508. },
  6509. /**
  6510. * 编辑器是否得到了选区
  6511. *
  6512. * @method isFocus
  6513. */
  6514. isFocus: function() {
  6515. try {
  6516. if(browser.ie9below) {
  6517. var nativeRange = _getIERange(this);
  6518. return !!(nativeRange && this.rangeInBody(nativeRange));
  6519. } else {
  6520. return !!this.getNative().rangeCount;
  6521. }
  6522. } catch(e) {
  6523. return false;
  6524. }
  6525. },
  6526. /**
  6527. * 获取选区对应的Range
  6528. *
  6529. * @method getRange
  6530. * @return { Object } 得到Range对象
  6531. * @example ```javascript editor.selection.getRange(); ```
  6532. */
  6533. getRange: function() {
  6534. var me = this;
  6535. function optimze(range) {
  6536. var child = me.document.body.firstChild,
  6537. collapsed = range.collapsed;
  6538. while(child && child.firstChild) {
  6539. range.setStart(child, 0);
  6540. child = child.firstChild;
  6541. }
  6542. if(!range.startContainer) {
  6543. range.setStart(me.document.body, 0)
  6544. }
  6545. if(collapsed) {
  6546. range.collapse(true);
  6547. }
  6548. }
  6549. if(me._cachedRange != null) {
  6550. return this._cachedRange;
  6551. }
  6552. var range = new baidu.editor.dom.Range(me.document);
  6553. if(browser.ie9below) {
  6554. var nativeRange = me.getIERange();
  6555. if(nativeRange) {
  6556. // 备份的_bakIERange可能已经实效了,dom树发生了变化比如从源码模式切回来,所以try一下,实效就放到body开始位置
  6557. try {
  6558. transformIERangeToRange(nativeRange, range);
  6559. } catch(e) {
  6560. optimze(range);
  6561. }
  6562. } else {
  6563. optimze(range);
  6564. }
  6565. } else {
  6566. var sel = me.getNative();
  6567. if(sel && sel.rangeCount) {
  6568. var firstRange = sel.getRangeAt(0);
  6569. var lastRange = sel.getRangeAt(sel.rangeCount - 1);
  6570. range.setStart(firstRange.startContainer,
  6571. firstRange.startOffset).setEnd(
  6572. lastRange.endContainer, lastRange.endOffset);
  6573. if(range.collapsed &&
  6574. domUtils.isBody(range.startContainer) &&
  6575. !range.startOffset) {
  6576. optimze(range);
  6577. }
  6578. } else {
  6579. // trace:1734 有可能已经不在dom树上了,标识的节点
  6580. if(this._bakRange &&
  6581. domUtils.inDoc(
  6582. this._bakRange.startContainer,
  6583. this.document)) {
  6584. return this._bakRange;
  6585. }
  6586. optimze(range);
  6587. }
  6588. }
  6589. return this._bakRange = range;
  6590. },
  6591. /**
  6592. * 获取开始元素,用于状态反射
  6593. *
  6594. * @method getStart
  6595. * @return { Element } 获得开始元素
  6596. * @example ```javascript editor.selection.getStart(); ```
  6597. */
  6598. getStart: function() {
  6599. if(this._cachedStartElement) {
  6600. return this._cachedStartElement;
  6601. }
  6602. var range = browser.ie9below ? this.getIERange() : this
  6603. .getRange(),
  6604. tmpRange, start, tmp, parent;
  6605. if(browser.ie9below) {
  6606. if(!range) {
  6607. // todo 给第一个值可能会有问题
  6608. return this.document.body.firstChild;
  6609. }
  6610. // control元素
  6611. if(range.item) {
  6612. return range.item(0);
  6613. }
  6614. tmpRange = range.duplicate();
  6615. // 修正ie下<b>x</b>[xx] 闭合后 <b>x|</b>xx
  6616. tmpRange.text.length > 0 &&
  6617. tmpRange.moveStart('character', 1);
  6618. tmpRange.collapse(1);
  6619. start = tmpRange.parentElement();
  6620. parent = tmp = range.parentElement();
  6621. while(tmp = tmp.parentNode) {
  6622. if(tmp == start) {
  6623. start = parent;
  6624. break;
  6625. }
  6626. }
  6627. } else {
  6628. range.shrinkBoundary();
  6629. start = range.startContainer;
  6630. if(start.nodeType == 1 && start.hasChildNodes()) {
  6631. start = start.childNodes[Math.min(
  6632. start.childNodes.length - 1, range.startOffset)];
  6633. }
  6634. if(start.nodeType == 3) {
  6635. return start.parentNode;
  6636. }
  6637. }
  6638. return start;
  6639. },
  6640. /**
  6641. * 得到选区中的文本
  6642. *
  6643. * @method getText
  6644. * @return { String } 选区中包含的文本
  6645. * @example ```javascript editor.selection.getText(); ```
  6646. */
  6647. getText: function() {
  6648. var nativeSel, nativeRange;
  6649. if(this.isFocus() && (nativeSel = this.getNative())) {
  6650. nativeRange = browser.ie9below ?
  6651. nativeSel.createRange() :
  6652. nativeSel.getRangeAt(0);
  6653. return browser.ie9below ? nativeRange.text : nativeRange
  6654. .toString();
  6655. }
  6656. return '';
  6657. },
  6658. /**
  6659. * 清除选区
  6660. *
  6661. * @method clearRange
  6662. * @example ```javascript editor.selection.clearRange(); ```
  6663. */
  6664. clearRange: function() {
  6665. this.getNative()[browser.ie9below ? 'empty' : 'removeAllRanges']();
  6666. }
  6667. };
  6668. })();
  6669. // core/Editor.js
  6670. /**
  6671. * 编辑器主类,包含编辑器提供的大部分公用接口
  6672. *
  6673. * @file
  6674. * @module UE
  6675. * @class Editor
  6676. * @since 1.2.6.1
  6677. */
  6678. /**
  6679. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  6680. *
  6681. * @unfile
  6682. * @module UE
  6683. */
  6684. /**
  6685. * UEditor的核心类,为用户提供与编辑器交互的接口。
  6686. *
  6687. * @unfile
  6688. * @module UE
  6689. * @class Editor
  6690. */
  6691. (function() {
  6692. var uid = 0,
  6693. _selectionChangeTimer;
  6694. /**
  6695. * 获取编辑器的html内容,赋值到编辑器所在表单的textarea文本域里面
  6696. *
  6697. * @private
  6698. * @method setValue
  6699. * @param {
  6700. * UE.Editor } editor 编辑器事例
  6701. */
  6702. function setValue(form, editor) {
  6703. var textarea;
  6704. if(editor.textarea) {
  6705. if(utils.isString(editor.textarea)) {
  6706. for(var i = 0, ti, tis = domUtils.getElementsByTagName(
  6707. form, 'textarea'); ti = tis[i++];) {
  6708. if(ti.id == 'ueditor_textarea_' +
  6709. editor.options.textarea) {
  6710. textarea = ti;
  6711. break;
  6712. }
  6713. }
  6714. } else {
  6715. textarea = editor.textarea;
  6716. }
  6717. }
  6718. if(!textarea) {
  6719. form.appendChild(textarea = domUtils.createElement(document,
  6720. 'textarea', {
  6721. 'name': editor.options.textarea,
  6722. 'id': 'ueditor_textarea_' +
  6723. editor.options.textarea,
  6724. 'style': "display:none"
  6725. }));
  6726. // 不要产生多个textarea
  6727. editor.textarea = textarea;
  6728. }!textarea.getAttribute('name') &&
  6729. textarea.setAttribute('name', editor.options.textarea);
  6730. textarea.value = editor.hasContents() ?
  6731. (editor.options.allHtmlEnabled ?
  6732. editor.getAllHtml() :
  6733. editor.getContent(null, null, true)) :
  6734. ''
  6735. }
  6736. function loadPlugins(me) {
  6737. // 初始化插件
  6738. for(var pi in UE.plugins) {
  6739. UE.plugins[pi].call(me);
  6740. }
  6741. }
  6742. function checkCurLang(I18N) {
  6743. for(var lang in I18N) {
  6744. return lang
  6745. }
  6746. }
  6747. function langReadied(me) {
  6748. me.langIsReady = true;
  6749. me.fireEvent("langReady");
  6750. }
  6751. /**
  6752. * 编辑器准备就绪后会触发该事件
  6753. *
  6754. * @module UE
  6755. * @class Editor
  6756. * @event ready
  6757. * @remind render方法执行完成之后,会触发该事件
  6758. * @remind
  6759. * @example ```javascript editor.addListener( 'ready', function( editor ) {
  6760. * editor.execCommand( 'focus' ); //编辑器家在完成后,让编辑器拿到焦点 } ); ```
  6761. */
  6762. /**
  6763. * 执行destroy方法,会触发该事件
  6764. *
  6765. * @module UE
  6766. * @class Editor
  6767. * @event destroy
  6768. * @see UE.Editor:destroy()
  6769. */
  6770. /**
  6771. * 执行reset方法,会触发该事件
  6772. *
  6773. * @module UE
  6774. * @class Editor
  6775. * @event reset
  6776. * @see UE.Editor:reset()
  6777. */
  6778. /**
  6779. * 执行focus方法,会触发该事件
  6780. *
  6781. * @module UE
  6782. * @class Editor
  6783. * @event focus
  6784. * @see UE.Editor:focus(Boolean)
  6785. */
  6786. /**
  6787. * 语言加载完成会触发该事件
  6788. *
  6789. * @module UE
  6790. * @class Editor
  6791. * @event langReady
  6792. */
  6793. /**
  6794. * 运行命令之后会触发该命令
  6795. *
  6796. * @module UE
  6797. * @class Editor
  6798. * @event beforeExecCommand
  6799. */
  6800. /**
  6801. * 运行命令之后会触发该命令
  6802. *
  6803. * @module UE
  6804. * @class Editor
  6805. * @event afterExecCommand
  6806. */
  6807. /**
  6808. * 运行命令之前会触发该命令
  6809. *
  6810. * @module UE
  6811. * @class Editor
  6812. * @event firstBeforeExecCommand
  6813. */
  6814. /**
  6815. * 在getContent方法执行之前会触发该事件
  6816. *
  6817. * @module UE
  6818. * @class Editor
  6819. * @event beforeGetContent
  6820. * @see UE.Editor:getContent()
  6821. */
  6822. /**
  6823. * 在getContent方法执行之后会触发该事件
  6824. *
  6825. * @module UE
  6826. * @class Editor
  6827. * @event afterGetContent
  6828. * @see UE.Editor:getContent()
  6829. */
  6830. /**
  6831. * 在getAllHtml方法执行时会触发该事件
  6832. *
  6833. * @module UE
  6834. * @class Editor
  6835. * @event getAllHtml
  6836. * @see UE.Editor:getAllHtml()
  6837. */
  6838. /**
  6839. * 在setContent方法执行之前会触发该事件
  6840. *
  6841. * @module UE
  6842. * @class Editor
  6843. * @event beforeSetContent
  6844. * @see UE.Editor:setContent(String)
  6845. */
  6846. /**
  6847. * 在setContent方法执行之后会触发该事件
  6848. *
  6849. * @module UE
  6850. * @class Editor
  6851. * @event afterSetContent
  6852. * @see UE.Editor:setContent(String)
  6853. */
  6854. /**
  6855. * 每当编辑器内部选区发生改变时,将触发该事件
  6856. *
  6857. * @event selectionchange
  6858. * @warning 该事件的触发非常频繁,不建议在该事件的处理过程中做重量级的处理
  6859. * @example ```javascript editor.addListener( 'selectionchange',
  6860. * function( editor ) { console.log('选区发生改变'); }
  6861. */
  6862. /**
  6863. * 在所有selectionchange的监听函数执行之前,会触发该事件
  6864. *
  6865. * @module UE
  6866. * @class Editor
  6867. * @event beforeSelectionChange
  6868. * @see UE.Editor:selectionchange
  6869. */
  6870. /**
  6871. * 在所有selectionchange的监听函数执行完之后,会触发该事件
  6872. *
  6873. * @module UE
  6874. * @class Editor
  6875. * @event afterSelectionChange
  6876. * @see UE.Editor:selectionchange
  6877. */
  6878. /**
  6879. * 编辑器内容发生改变时会触发该事件
  6880. *
  6881. * @module UE
  6882. * @class Editor
  6883. * @event contentChange
  6884. */
  6885. /**
  6886. * 以默认参数构建一个编辑器实例
  6887. *
  6888. * @constructor
  6889. * @remind 通过 改构造方法实例化的编辑器,不带ui层.需要render到一个容器,编辑器实例才能正常渲染到页面
  6890. * @example ```javascript var editor = new UE.Editor();
  6891. * editor.execCommand('blod'); ```
  6892. * @see UE.Config
  6893. */
  6894. /**
  6895. * 以给定的参数集合创建一个编辑器实例,对于未指定的参数,将应用默认参数。
  6896. *
  6897. * @constructor
  6898. * @remind 通过 改构造方法实例化的编辑器,不带ui层.需要render到一个容器,编辑器实例才能正常渲染到页面
  6899. * @param {
  6900. * Object } setting 创建编辑器的参数
  6901. * @example ```javascript var editor = new UE.Editor();
  6902. * editor.execCommand('blod'); ```
  6903. * @see UE.Config
  6904. */
  6905. var Editor = UE.Editor = function(options) {
  6906. var me = this;
  6907. me.uid = uid++;
  6908. EventBase.call(me);
  6909. me.commands = {};
  6910. me.options = utils.extend(utils.clone(options || {}),
  6911. UEDITOR_CONFIG, true);
  6912. me.shortcutkeys = {};
  6913. me.inputRules = [];
  6914. me.outputRules = [];
  6915. // 设置默认的常用属性
  6916. me.setOpt(Editor.defaultOptions(me));
  6917. /* 尝试异步加载后台配置 */
  6918. me.loadServerConfig();
  6919. if(!utils.isEmptyObject(UE.I18N)) {
  6920. // 修改默认的语言类型
  6921. me.options.lang = checkCurLang(UE.I18N);
  6922. UE.plugin.load(me);
  6923. langReadied(me);
  6924. } else {
  6925. utils.loadFile(document, {
  6926. src: me.options.langPath + me.options.lang + "/" +
  6927. me.options.lang + ".js",
  6928. tag: "script",
  6929. type: "text/javascript",
  6930. defer: "defer"
  6931. }, function() {
  6932. UE.plugin.load(me);
  6933. langReadied(me);
  6934. });
  6935. }
  6936. UE.instants['ueditorInstant' + me.uid] = me;
  6937. };
  6938. Editor.prototype = {
  6939. registerCommand: function(name, obj) {
  6940. this.commands[name] = obj;
  6941. },
  6942. /**
  6943. * 编辑器对外提供的监听ready事件的接口, 通过调用该方法,达到的效果与监听ready事件是一致的
  6944. *
  6945. * @method ready
  6946. * @param {
  6947. * Function } fn 编辑器ready之后所执行的回调, 如果在注册事件之前编辑器已经ready,将会
  6948. * 立即触发该回调。
  6949. * @remind 需要等待编辑器加载完成后才能执行的代码,可以使用该方法传入
  6950. * @example ```javascript editor.ready( function( editor ) {
  6951. * editor.setContent('初始化完毕'); } ); ```
  6952. * @see UE.Editor.event:ready
  6953. */
  6954. ready: function(fn) {
  6955. var me = this;
  6956. if(fn) {
  6957. me.isReady ? fn.apply(me) : me.addListener('ready', fn);
  6958. }
  6959. },
  6960. /**
  6961. * 该方法是提供给插件里面使用,设置配置项默认值
  6962. *
  6963. * @method setOpt
  6964. * @warning 三处设置配置项的优先级: 实例化时传入参数 > setOpt()设置 > config文件里设置
  6965. * @warning 该方法仅供编辑器插件内部和编辑器初始化时调用,其他地方不能调用。
  6966. * @param {
  6967. * String } key 编辑器的可接受的选项名称
  6968. * @param { * }
  6969. * val 该选项可接受的值
  6970. * @example ```javascript editor.setOpt( 'initContent', '欢迎使用编辑器' );
  6971. * ```
  6972. */
  6973. /**
  6974. * 该方法是提供给插件里面使用,以{key:value}集合的方式设置插件内用到的配置项默认值
  6975. *
  6976. * @method setOpt
  6977. * @warning 三处设置配置项的优先级: 实例化时传入参数 > setOpt()设置 > config文件里设置
  6978. * @warning 该方法仅供编辑器插件内部和编辑器初始化时调用,其他地方不能调用。
  6979. * @param {
  6980. * Object } options 将要设置的选项的键值对对象
  6981. * @example ```javascript editor.setOpt( { 'initContent': '欢迎使用编辑器' } );
  6982. * ```
  6983. */
  6984. setOpt: function(key, val) {
  6985. var obj = {};
  6986. if(utils.isString(key)) {
  6987. obj[key] = val
  6988. } else {
  6989. obj = key;
  6990. }
  6991. utils.extend(this.options, obj, true);
  6992. },
  6993. getOpt: function(key) {
  6994. return this.options[key]
  6995. },
  6996. /**
  6997. * 销毁编辑器实例,使用textarea代替
  6998. *
  6999. * @method destroy
  7000. * @example ```javascript editor.destroy(); ```
  7001. */
  7002. destroy: function() {
  7003. var me = this;
  7004. me.fireEvent('destroy');
  7005. var container = me.container.parentNode;
  7006. var textarea = me.textarea;
  7007. if(!textarea) {
  7008. textarea = document.createElement('textarea');
  7009. container.parentNode.insertBefore(textarea, container);
  7010. } else {
  7011. textarea.style.display = ''
  7012. }
  7013. textarea.style.width = me.iframe.offsetWidth + 'px';
  7014. textarea.style.height = me.iframe.offsetHeight + 'px';
  7015. textarea.value = me.getContent();
  7016. textarea.id = me.key;
  7017. container.innerHTML = '';
  7018. domUtils.remove(container);
  7019. var key = me.key;
  7020. // trace:2004
  7021. for(var p in me) {
  7022. if(me.hasOwnProperty(p)) {
  7023. delete this[p];
  7024. }
  7025. }
  7026. UE.delEditor(key);
  7027. },
  7028. /**
  7029. * 渲染编辑器的DOM到指定容器
  7030. *
  7031. * @method render
  7032. * @param {
  7033. * String } containerId 指定一个容器ID
  7034. * @remind 执行该方法,会触发ready事件
  7035. * @warning 必须且只能调用一次
  7036. */
  7037. /**
  7038. * 渲染编辑器的DOM到指定容器
  7039. *
  7040. * @method render
  7041. * @param {
  7042. * Element } containerDom 直接指定容器对象
  7043. * @remind 执行该方法,会触发ready事件
  7044. * @warning 必须且只能调用一次
  7045. */
  7046. render: function(container) {
  7047. var me = this,
  7048. options = me.options,
  7049. getStyleValue = function(
  7050. attr) {
  7051. return parseInt(domUtils.getComputedStyle(container, attr));
  7052. };
  7053. if(utils.isString(container)) {
  7054. container = document.getElementById(container);
  7055. }
  7056. if(container) {
  7057. if(options.initialFrameWidth) {
  7058. options.minFrameWidth = options.initialFrameWidth
  7059. } else {
  7060. options.minFrameWidth = options.initialFrameWidth = container.offsetWidth;
  7061. }
  7062. if(options.initialFrameHeight) {
  7063. options.minFrameHeight = options.initialFrameHeight
  7064. } else {
  7065. options.initialFrameHeight = options.minFrameHeight = container.offsetHeight;
  7066. }
  7067. container.style.width = /%$/
  7068. .test(options.initialFrameWidth) ?
  7069. '100%' :
  7070. options.initialFrameWidth -
  7071. getStyleValue("padding-left") -
  7072. getStyleValue("padding-right") + 'px';
  7073. container.style.height = /%$/
  7074. .test(options.initialFrameHeight) ?
  7075. '100%' :
  7076. options.initialFrameHeight -
  7077. getStyleValue("padding-top") -
  7078. getStyleValue("padding-bottom") + 'px';
  7079. container.style.zIndex = options.zIndex;
  7080. var html = (ie && browser.version < 9 ?
  7081. '' :
  7082. '<!DOCTYPE html>') +
  7083. '<html xmlns=\'http://www.w3.org/1999/xhtml\' class=\'view\' ><head>' +
  7084. '<script type=\'text/javascript\' src=\'/ss/jquery/jquery.js\'></script>' +
  7085. // '<script type=\'text/javascript\' src=\'/wd/display.js\'></script>' +
  7086. // '<script type=\'text/javascript\' src=\'/wd/js/nicescroll376/jquery.nicescroll.js\'></script>' +
  7087. // '<script type=\'text/javascript\' src=\'/wd/js/nicescroll376/jquery.nicescroll.iframehelper.min.js\'></script>' +
  7088. '<style type=\'text/css\'>' +
  7089. // 设置四周的留边
  7090. //'.view{padding:0;word-wrap:break-word;cursor:text;height:90%;}\n' +
  7091. //'.view p{line-height:1.2}\n' +
  7092. //'.view span{line-height:1.2}\n' +
  7093. //'.list-paddingleft-2 li{padding-left:7px}\n'+
  7094. // 设置默认字体和字号
  7095. // font-family不能呢随便改,在safari下fillchar会有解析问题
  7096. //'body{margin:8px;font-family:sans-serif;font-size:16px;}' +
  7097. // 设置段落间距
  7098. //'p{margin:5px 0;}'+
  7099. '</style>' +
  7100. (options.iframeCssUrl ?
  7101. '<link rel=\'stylesheet\' type=\'text/css\' href=\'' +
  7102. utils
  7103. .unhtml(options.iframeCssUrl) +
  7104. '\'/>' :
  7105. '') +
  7106. (options.initialStyle ? '<style>' +
  7107. options.initialStyle + '</style>' : '') +
  7108. '</head><body class=\'view scrollbar\'></body>' +
  7109. '<script type=\'text/javascript\' ' +
  7110. (ie ? 'defer=\'defer\'' : '') +
  7111. ' id=\'_initialScript\'>' +
  7112. 'setTimeout(function(){editor = window.parent.UE.instants[\'ueditorInstant' +
  7113. me.uid +
  7114. '\'];editor._setup(document);},0);' +
  7115. 'var _tmpScript = document.getElementById(\'_initialScript\');_tmpScript.parentNode.removeChild(_tmpScript);</script></html>';
  7116. container.appendChild(domUtils.createElement(document,
  7117. 'iframe', {
  7118. id: 'ueditor_' + me.uid,
  7119. width: "100%",
  7120. height: "100%",
  7121. frameborder: "0",
  7122. // 先注释掉了,加的原因忘记了,但开启会直接导致全屏模式下内容多时不会出现滚动条
  7123. // scrolling :'no',
  7124. src: 'javascript:void(function(){document.open();' +
  7125. (options.customDomain &&
  7126. document.domain != location.hostname ?
  7127. 'document.domain="' +
  7128. document.domain +
  7129. '";' :
  7130. '') +
  7131. 'document.write("' +
  7132. html + '");document.close();}())'
  7133. }));
  7134. // container.style.overflow = 'hidden';
  7135. // 解决如果是给定的百分比,会导致高度算不对的问题
  7136. setTimeout(function() {
  7137. if(/%$/.test(options.initialFrameWidth)) {
  7138. options.minFrameWidth = options.initialFrameWidth = container.offsetWidth;
  7139. // 如果这里给定宽度,会导致ie在拖动窗口大小时,编辑区域不随着变化
  7140. // container.style.width = options.initialFrameWidth
  7141. // + 'px';
  7142. }
  7143. if(/%$/.test(options.initialFrameHeight)) {
  7144. options.minFrameHeight = options.initialFrameHeight = container.offsetHeight;
  7145. // container.style.height = options.initialFrameHeight +
  7146. // 'px';
  7147. }
  7148. })
  7149. }
  7150. },
  7151. /**
  7152. * 编辑器初始化
  7153. *
  7154. * @method _setup
  7155. * @private
  7156. * @param {
  7157. * Element } doc 编辑器Iframe中的文档对象
  7158. */
  7159. _setup: function(doc) {
  7160. var me = this,
  7161. options = me.options;
  7162. if(ie) {
  7163. doc.body.disabled = true;
  7164. doc.body.contentEditable = true;
  7165. doc.body.disabled = false;
  7166. } else {
  7167. doc.body.contentEditable = true;
  7168. }
  7169. doc.body.spellcheck = false;
  7170. me.document = doc;
  7171. me.window = doc.defaultView || doc.parentWindow;
  7172. me.iframe = me.window.frameElement;
  7173. me.body = doc.body;
  7174. me.selection = new dom.Selection(doc);
  7175. // gecko初始化就能得到range,无法判断isFocus了
  7176. var geckoSel;
  7177. if(browser.gecko && (geckoSel = this.selection.getNative())) {
  7178. geckoSel.removeAllRanges();
  7179. }
  7180. this._initEvents();
  7181. // 为form提交提供一个隐藏的textarea
  7182. for(var form = this.iframe.parentNode; !domUtils.isBody(form); form = form.parentNode) {
  7183. if(form.tagName == 'FORM') {
  7184. me.form = form;
  7185. if(me.options.autoSyncData) {
  7186. domUtils.on(me.window, 'blur', function() {
  7187. setValue(form, me);
  7188. });
  7189. } else {
  7190. domUtils.on(form, 'submit', function() {
  7191. setValue(this, me);
  7192. });
  7193. }
  7194. break;
  7195. }
  7196. }
  7197. if(options.initialContent) {
  7198. if(options.autoClearinitialContent) {
  7199. var oldExecCommand = me.execCommand;
  7200. me.execCommand = function() {
  7201. me.fireEvent('firstBeforeExecCommand');
  7202. return oldExecCommand.apply(me, arguments);
  7203. };
  7204. this._setDefaultContent(options.initialContent);
  7205. } else
  7206. this.setContent(options.initialContent, false, true);
  7207. }
  7208. // 编辑器不能为空内容
  7209. if(domUtils.isEmptyNode(me.body)) {
  7210. me.body.innerHTML = '<p>' + (browser.ie ? '' : '<br/>') +
  7211. '</p>';
  7212. }
  7213. // 如果要求focus, 就把光标定位到内容开始
  7214. if(options.focus) {
  7215. setTimeout(function() {
  7216. me.focus(me.options.focusInEnd);
  7217. // 如果自动清除开着,就不需要做selectionchange;
  7218. !me.options.autoClearinitialContent &&
  7219. me._selectionChange();
  7220. }, 0);
  7221. }
  7222. if(!me.container) {
  7223. me.container = this.iframe.parentNode;
  7224. }
  7225. if(options.fullscreen && me.ui) {
  7226. me.ui.setFullScreen(true);
  7227. }
  7228. try {
  7229. me.document.execCommand('2D-position', false, false);
  7230. } catch(e) {}
  7231. try {
  7232. me.document.execCommand('enableInlineTableEditing', false,
  7233. false);
  7234. } catch(e) {}
  7235. try {
  7236. me.document.execCommand('enableObjectResizing', false,
  7237. false);
  7238. } catch(e) {}
  7239. // 挂接快捷键
  7240. me._bindshortcutKeys();
  7241. me.isReady = 1;
  7242. me.fireEvent('ready');
  7243. options.onready && options.onready.call(me);
  7244. if(!browser.ie9below) {
  7245. domUtils.on(me.window, ['blur', 'focus'], function(e) {
  7246. // chrome下会出现alt+tab切换时,导致选区位置不对
  7247. if(e.type == 'blur') {
  7248. me._bakRange = me.selection.getRange();
  7249. try {
  7250. me._bakNativeRange = me.selection.getNative()
  7251. .getRangeAt(0);
  7252. me.selection.getNative().removeAllRanges();
  7253. } catch(e) {
  7254. me._bakNativeRange = null;
  7255. }
  7256. } else {
  7257. try {
  7258. me._bakRange && me._bakRange.select();
  7259. } catch(e) {}
  7260. }
  7261. });
  7262. }
  7263. // trace:1518 ff3.6body不够寛,会导致点击空白处无法获得焦点
  7264. if(browser.gecko && browser.version <= 10902) {
  7265. // 修复ff3.6初始化进来,不能点击获得焦点
  7266. me.body.contentEditable = false;
  7267. setTimeout(function() {
  7268. me.body.contentEditable = true;
  7269. }, 100);
  7270. setInterval(function() {
  7271. me.body.style.height = me.iframe.offsetHeight - 20 +
  7272. 'px'
  7273. }, 100)
  7274. }
  7275. !options.isShow && me.setHide();
  7276. options.readonly && me.setDisabled();
  7277. },
  7278. /**
  7279. * 同步数据到编辑器所在的form
  7280. * 从编辑器的容器节点向上查找form元素,若找到,就同步编辑内容到找到的form里,为提交数据做准备,主要用于是手动提交的情况
  7281. * 后台取得数据的键值,使用你容器上的name属性,如果没有就使用参数里的textarea项
  7282. *
  7283. * @method sync
  7284. * @example ```javascript editor.sync(); form.sumbit();
  7285. * //form变量已经指向了form元素 ```
  7286. */
  7287. /**
  7288. * 根据传入的formId,在页面上查找要同步数据的表单,若找到,就同步编辑内容到找到的form里,为提交数据做准备
  7289. * 后台取得数据的键值,该键值默认使用给定的编辑器容器的name属性,如果没有name属性则使用参数项里给定的“textarea”项
  7290. *
  7291. * @method sync
  7292. * @param {
  7293. * String } formID 指定一个要同步数据的form的id,编辑器的数据会同步到你指定form下
  7294. */
  7295. sync: function(formId) {
  7296. var me = this,
  7297. form = formId ?
  7298. document.getElementById(formId) :
  7299. domUtils.findParent(me.iframe.parentNode, function(
  7300. node) {
  7301. return node.tagName == 'FORM'
  7302. }, true);
  7303. form && setValue(form, me);
  7304. },
  7305. /**
  7306. * 设置编辑器高度
  7307. *
  7308. * @method setHeight
  7309. * @remind 当配置项autoHeightEnabled为真时,该方法无效
  7310. * @param {
  7311. * Number } number 设置的高度值,纯数值,不带单位
  7312. * @example ```javascript editor.setHeight(number); ```
  7313. */
  7314. setHeight: function(height, notSetHeight) {
  7315. if(height !== parseInt(this.iframe.parentNode.style.height)) {
  7316. this.iframe.parentNode.style.height = height + 'px';
  7317. }!notSetHeight
  7318. &&
  7319. (this.options.minFrameHeight = this.options.initialFrameHeight = height);
  7320. this.body.style.height = height + 'px';
  7321. !notSetHeight && this.trigger('setHeight')
  7322. },
  7323. /**
  7324. * 为编辑器的编辑命令提供快捷键 这个接口是为插件扩展提供的接口,主要是为新添加的插件,如果需要添加快捷键,所提供的接口
  7325. *
  7326. * @method addshortcutkey
  7327. * @param {
  7328. * Object } keyset 命令名和快捷键键值对对象,多个按钮的快捷键用“+”分隔
  7329. * @example ```javascript editor.addshortcutkey({ "Bold" :
  7330. * "ctrl+66",//^B "Italic" : "ctrl+73", //^I }); ```
  7331. */
  7332. /**
  7333. * 这个接口是为插件扩展提供的接口,主要是为新添加的插件,如果需要添加快捷键,所提供的接口
  7334. *
  7335. * @method addshortcutkey
  7336. * @param {
  7337. * String } cmd 触发快捷键时,响应的命令
  7338. * @param {
  7339. * String } keys 快捷键的字符串,多个按钮用“+”分隔
  7340. * @example ```javascript editor.addshortcutkey("Underline",
  7341. * "ctrl+85"); //^U ```
  7342. */
  7343. addshortcutkey: function(cmd, keys) {
  7344. var obj = {};
  7345. if(keys) {
  7346. obj[cmd] = keys
  7347. } else {
  7348. obj = cmd;
  7349. }
  7350. utils.extend(this.shortcutkeys, obj)
  7351. },
  7352. /**
  7353. * 对编辑器设置keydown事件监听,绑定快捷键和命令,当快捷键组合触发成功,会响应对应的命令
  7354. *
  7355. * @method _bindshortcutKeys
  7356. * @private
  7357. */
  7358. _bindshortcutKeys: function() {
  7359. var me = this,
  7360. shortcutkeys = this.shortcutkeys;
  7361. me.addListener('keydown', function(type, e) {
  7362. var keyCode = e.keyCode || e.which;
  7363. for(var i in shortcutkeys) {
  7364. var tmp = shortcutkeys[i].split(',');
  7365. for(var t = 0, ti; ti = tmp[t++];) {
  7366. ti = ti.split(':');
  7367. var key = ti[0],
  7368. param = ti[1];
  7369. if(/^(ctrl)(\+shift)?\+(\d+)$/.test(key
  7370. .toLowerCase()) ||
  7371. /^(\d+)$/.test(key)) {
  7372. if(((RegExp.$1 == 'ctrl' ?
  7373. (e.ctrlKey || e.metaKey) :
  7374. 0) &&
  7375. (RegExp.$2 != "" ? e[RegExp.$2
  7376. .slice(1) +
  7377. "Key"] : 1) && keyCode == RegExp.$3) ||
  7378. keyCode == RegExp.$1) {
  7379. if(me.queryCommandState(i, param) != -1)
  7380. me.execCommand(i, param);
  7381. domUtils.preventDefault(e);
  7382. }
  7383. }
  7384. }
  7385. }
  7386. });
  7387. },
  7388. /**
  7389. * 获取编辑器的内容
  7390. *
  7391. * @method getContent
  7392. * @warning 该方法获取到的是经过编辑器内置的过滤规则进行过滤后得到的内容
  7393. * @return { String } 编辑器的内容字符串,
  7394. * 如果编辑器的内容为空,或者是空的标签内容(如:”&lt;p&gt;&lt;br/&gt;&lt;/p&gt;“),
  7395. * 则返回空字符串
  7396. * @example ```javascript //编辑器html内容:
  7397. * <p>
  7398. * 1<strong>2<em>34</em>5</strong>6
  7399. * </p>
  7400. * var content = editor.getContent(); //返回值:
  7401. * <p>
  7402. * 1<strong>2<em>34</em>5</strong>6
  7403. * </p>
  7404. * ```
  7405. */
  7406. /**
  7407. * 获取编辑器的内容。 可以通过参数定义编辑器内置的判空规则
  7408. *
  7409. * @method getContent
  7410. * @param {
  7411. * Function } fn 自定的判空规则, 要求该方法返回一个boolean类型的值,
  7412. * 代表当前编辑器的内容是否空, 如果返回true,
  7413. * 则该方法将直接返回空字符串;如果返回false,则编辑器将返回 经过内置过滤规则处理后的内容。
  7414. * @remind 该方法在处理包含有初始化内容的时候能起到很好的作用。
  7415. * @warning 该方法获取到的是经过编辑器内置的过滤规则进行过滤后得到的内容
  7416. * @return { String } 编辑器的内容字符串
  7417. * @example ```javascript // editor 是一个编辑器的实例 var content =
  7418. * editor.getContent( function ( editor ) { return
  7419. * editor.body.innerHTML === '欢迎使用UEditor'; //返回空字符串 } );
  7420. * ```
  7421. */
  7422. getContent: function(cmd, fn, notSetCursor, ignoreBlank, formatter) {
  7423. var me = this;
  7424. if(cmd && utils.isFunction(cmd)) {
  7425. fn = cmd;
  7426. cmd = '';
  7427. }
  7428. if(fn ? !fn() : !this.hasContents()) {
  7429. return '';
  7430. }
  7431. me.fireEvent('beforegetcontent');
  7432. var root = UE.htmlparser(me.body.innerHTML, ignoreBlank);
  7433. me.filterOutputRule(root);
  7434. me.fireEvent('aftergetcontent', cmd, root);
  7435. return root.toHtml(formatter);
  7436. },
  7437. /**
  7438. * 取得完整的html代码,可以直接显示成完整的html文档
  7439. *
  7440. * @method getAllHtml
  7441. * @return { String } 编辑器的内容html文档字符串
  7442. * @eaxmple ```javascript editor.getAllHtml(); //返回格式大致是: <html><head>...</head><body>...</body></html>
  7443. * ```
  7444. */
  7445. getAllHtml: function() {
  7446. var me = this,
  7447. headHtml = [],
  7448. html = '';
  7449. me.fireEvent('getAllHtml', headHtml);
  7450. if(browser.ie && browser.version > 8) {
  7451. var headHtmlForIE9 = '';
  7452. utils.each(me.document.styleSheets, function(si) {
  7453. headHtmlForIE9 += (si.href ?
  7454. '<link rel="stylesheet" type="text/css" href="' +
  7455. si.href + '" />' :
  7456. '<style>' + si.cssText + '</style>');
  7457. });
  7458. utils.each(me.document.getElementsByTagName('script'),
  7459. function(si) {
  7460. headHtmlForIE9 += si.outerHTML;
  7461. });
  7462. }
  7463. return '<html><head>' +
  7464. (me.options.charset ?
  7465. '<meta http-equiv="Content-Type" content="text/html; charset=' +
  7466. me.options.charset + '"/>' :
  7467. '') +
  7468. (headHtmlForIE9 || me.document
  7469. .getElementsByTagName('head')[0].innerHTML) +
  7470. headHtml.join('\n') + '</head>' + '<body ' +
  7471. (ie && browser.version < 9 ? 'class="view"' : '') +
  7472. '>' + me.getContent(null, null, true) +
  7473. '</body></html>';
  7474. },
  7475. /**
  7476. * 得到编辑器的纯文本内容,但会保留段落格式
  7477. *
  7478. * @method getPlainTxt
  7479. * @return { String } 编辑器带段落格式的纯文本内容字符串
  7480. * @example ```javascript //编辑器html内容:
  7481. * <p>
  7482. * <strong>1</strong>
  7483. * </p>
  7484. * <p>
  7485. * <strong>2</strong>
  7486. * </p>
  7487. * console.log(editor.getPlainTxt()); //输出:"1\n2\n ```
  7488. */
  7489. getPlainTxt: function() {
  7490. var reg = new RegExp(domUtils.fillChar, 'g'),
  7491. html = this.body.innerHTML
  7492. .replace(/[\n\r]/g, ''); // ie要先去了\n在处理
  7493. html = html.replace(/<(p|div)[^>]*>(<br\/?>|&nbsp;)<\/\1>/gi,
  7494. '\n').replace(/<br\/?>/gi, '\n').replace(/<[^>/]+>/g,
  7495. '').replace(/(\n)?<\/([^>]+)>/g, function(a, b, c) {
  7496. return dtd.$block[c] ? '\n' : b ? b : '';
  7497. });
  7498. // 取出来的空格会有c2a0会变成乱码,处理这种情况\u00a0
  7499. return html.replace(reg, '').replace(/\u00a0/g, ' ').replace(
  7500. /&nbsp;/g, ' ');
  7501. },
  7502. /**
  7503. * 获取编辑器中的纯文本内容,没有段落格式
  7504. *
  7505. * @method getContentTxt
  7506. * @return { String } 编辑器不带段落格式的纯文本内容字符串
  7507. * @example ```javascript //编辑器html内容:
  7508. * <p>
  7509. * <strong>1</strong>
  7510. * </p>
  7511. * <p>
  7512. * <strong>2</strong>
  7513. * </p>
  7514. * console.log(editor.getPlainTxt()); //输出:"12 ```
  7515. */
  7516. getContentTxt: function() {
  7517. var reg = new RegExp(domUtils.fillChar, 'g');
  7518. // 取出来的空格会有c2a0会变成乱码,处理这种情况\u00a0
  7519. return this.body[browser.ie ? 'innerText' : 'textContent']
  7520. .replace(reg, '').replace(/\u00a0/g, ' ');
  7521. },
  7522. /**
  7523. * 设置编辑器的内容,可修改编辑器当前的html内容
  7524. *
  7525. * @method setContent
  7526. * @warning 通过该方法插入的内容,是经过编辑器内置的过滤规则进行过滤后得到的内容
  7527. * @warning 该方法会触发selectionchange事件
  7528. * @param {
  7529. * String } html 要插入的html内容
  7530. * @example ```javascript editor.getContent('
  7531. * <p>
  7532. * test
  7533. * </p>
  7534. * '); ```
  7535. */
  7536. /**
  7537. * 设置编辑器的内容,可修改编辑器当前的html内容
  7538. *
  7539. * @method setContent
  7540. * @warning 通过该方法插入的内容,是经过编辑器内置的过滤规则进行过滤后得到的内容
  7541. * @warning 该方法会触发selectionchange事件
  7542. * @param {
  7543. * String } html 要插入的html内容
  7544. * @param {
  7545. * Boolean } isAppendTo
  7546. * 若传入true,不清空原来的内容,在最后插入内容,否则,清空内容再插入
  7547. * @example ```javascript //假设设置前的编辑器内容是
  7548. * <p>
  7549. * old text
  7550. * </p>
  7551. * editor.setContent('
  7552. * <p>
  7553. * new text
  7554. * </p>', true); //插入的结果是
  7555. * <p>
  7556. * old text
  7557. * </p>
  7558. * <p>
  7559. * new text
  7560. * </p>
  7561. * ```
  7562. */
  7563. setContent: function(html, isAppendTo, notFireSelectionchange) {
  7564. var me = this;
  7565. me.fireEvent('beforesetcontent', html);
  7566. var root = UE.htmlparser(html);
  7567. me.filterInputRule(root);
  7568. html = root.toHtml();
  7569. me.body.innerHTML = (isAppendTo ? me.body.innerHTML : '') +
  7570. html;
  7571. function isCdataDiv(node) {
  7572. return node.tagName == 'DIV' &&
  7573. node.getAttribute('cdata_tag');
  7574. }
  7575. // 给文本或者inline节点套p标签
  7576. if(me.options.enterTag == 'p') {
  7577. var child = this.body.firstChild,
  7578. tmpNode;
  7579. if(!child ||
  7580. child.nodeType == 1 &&
  7581. (dtd.$cdata[child.tagName] || isCdataDiv(child) || domUtils
  7582. .isCustomeNode(child)) &&
  7583. child === this.body.lastChild) {
  7584. this.body.innerHTML = '<p>' +
  7585. (browser.ie ? '&nbsp;' : '<br/>') + '</p>' +
  7586. this.body.innerHTML;
  7587. } else {
  7588. var p = me.document.createElement('p');
  7589. while(child) {
  7590. while(child &&
  7591. (child.nodeType == 3 || child.nodeType == 1 &&
  7592. dtd.p[child.tagName] &&
  7593. !dtd.$cdata[child.tagName])) {
  7594. tmpNode = child.nextSibling;
  7595. p.appendChild(child);
  7596. child = tmpNode;
  7597. }
  7598. if(p.firstChild) {
  7599. if(!child) {
  7600. me.body.appendChild(p);
  7601. break;
  7602. } else {
  7603. child.parentNode.insertBefore(p, child);
  7604. p = me.document.createElement('p');
  7605. }
  7606. }
  7607. child = child.nextSibling;
  7608. }
  7609. }
  7610. }
  7611. me.fireEvent('aftersetcontent');
  7612. me.fireEvent('contentchange');
  7613. !notFireSelectionchange && me._selectionChange();
  7614. // 清除保存的选区
  7615. me._bakRange = me._bakIERange = me._bakNativeRange = null;
  7616. // trace:1742 setContent后gecko能得到焦点问题
  7617. var geckoSel;
  7618. if(browser.gecko && (geckoSel = this.selection.getNative())) {
  7619. geckoSel.removeAllRanges();
  7620. }
  7621. if(me.options.autoSyncData) {
  7622. me.form && setValue(me.form, me);
  7623. }
  7624. },
  7625. /**
  7626. * 让编辑器获得焦点,默认focus到编辑器头部
  7627. *
  7628. * @method focus
  7629. * @example ```javascript editor.focus() ```
  7630. */
  7631. /**
  7632. * 让编辑器获得焦点,toEnd确定focus位置
  7633. *
  7634. * @method focus
  7635. * @param {
  7636. * Boolean } toEnd 默认focus到编辑器头部,toEnd为true时focus到内容尾部
  7637. * @example ```javascript editor.focus(true) ```
  7638. */
  7639. focus: function(toEnd) {
  7640. try {
  7641. var me = this,
  7642. rng = me.selection.getRange();
  7643. if(toEnd) {
  7644. var node = me.body.lastChild;
  7645. if(node && node.nodeType == 1 &&
  7646. !dtd.$empty[node.tagName]) {
  7647. if(domUtils.isEmptyBlock(node)) {
  7648. rng.setStartAtFirst(node)
  7649. } else {
  7650. rng.setStartAtLast(node)
  7651. }
  7652. rng.collapse(true);
  7653. }
  7654. rng.setCursor(true);
  7655. } else {
  7656. if(!rng.collapsed &&
  7657. domUtils.isBody(rng.startContainer) &&
  7658. rng.startOffset == 0) {
  7659. var node = me.body.firstChild;
  7660. if(node && node.nodeType == 1 &&
  7661. !dtd.$empty[node.tagName]) {
  7662. rng.setStartAtFirst(node).collapse(true);
  7663. }
  7664. }
  7665. rng.select(true);
  7666. }
  7667. this.fireEvent('focus selectionchange');
  7668. } catch(e) {}
  7669. },
  7670. isFocus: function() {
  7671. return this.selection.isFocus();
  7672. },
  7673. blur: function() {
  7674. var sel = this.selection.getNative();
  7675. if(sel.empty && browser.ie) {
  7676. var nativeRng = document.body.createTextRange();
  7677. nativeRng.moveToElementText(document.body);
  7678. nativeRng.collapse(true);
  7679. nativeRng.select();
  7680. sel.empty()
  7681. } else {
  7682. sel.removeAllRanges()
  7683. }
  7684. // this.fireEvent('blur selectionchange');
  7685. },
  7686. /**
  7687. * 初始化UE事件及部分事件代理
  7688. *
  7689. * @method _initEvents
  7690. * @private
  7691. */
  7692. _initEvents: function() {
  7693. var me = this,
  7694. doc = me.document,
  7695. win = me.window;
  7696. me._proxyDomEvent = utils.bind(me._proxyDomEvent, me);
  7697. domUtils.on(doc, ['click', 'contextmenu', 'mousedown',
  7698. 'keydown', 'keyup', 'keypress', 'mouseup', 'mouseover',
  7699. 'mouseout', 'selectstart'
  7700. ], me._proxyDomEvent);
  7701. domUtils.on(win, ['focus', 'blur'], me._proxyDomEvent);
  7702. domUtils.on(me.body, 'drop', function(e) {
  7703. // 阻止ff下默认的弹出新页面打开图片
  7704. if(browser.gecko && e.stopPropagation) {
  7705. e.stopPropagation();
  7706. }
  7707. me.fireEvent('contentchange')
  7708. });
  7709. domUtils.on(doc, ['mouseup', 'keydown'], function(evt) {
  7710. // 特殊键不触发selectionchange
  7711. if(evt.type == 'keydown' &&
  7712. (evt.ctrlKey || evt.metaKey || evt.shiftKey || evt.altKey)) {
  7713. return;
  7714. }
  7715. if(evt.button == 2)
  7716. return;
  7717. me._selectionChange(250, evt);
  7718. });
  7719. },
  7720. /**
  7721. * 触发事件代理
  7722. *
  7723. * @method _proxyDomEvent
  7724. * @private
  7725. * @return { * } fireEvent的返回值
  7726. * @see UE.EventBase:fireEvent(String)
  7727. */
  7728. _proxyDomEvent: function(evt) {
  7729. if(this.fireEvent('before' +
  7730. evt.type.replace(/^on/, '').toLowerCase()) === false) {
  7731. return false;
  7732. }
  7733. if(this.fireEvent(evt.type.replace(/^on/, ''), evt) === false) {
  7734. return false;
  7735. }
  7736. return this.fireEvent('after' +
  7737. evt.type.replace(/^on/, '').toLowerCase())
  7738. },
  7739. /**
  7740. * 变化选区
  7741. *
  7742. * @method _selectionChange
  7743. * @private
  7744. */
  7745. _selectionChange: function(delay, evt) {
  7746. var me = this;
  7747. // 有光标才做selectionchange
  7748. // 为了解决未focus时点击source不能触发更改工具栏状态的问题(source命令notNeedUndo=1)
  7749. // if ( !me.selection.isFocus() ){
  7750. // return;
  7751. // }
  7752. var hackForMouseUp = false;
  7753. var mouseX, mouseY;
  7754. if(browser.ie && browser.version < 9 && evt &&
  7755. evt.type == 'mouseup') {
  7756. var range = this.selection.getRange();
  7757. if(!range.collapsed) {
  7758. hackForMouseUp = true;
  7759. mouseX = evt.clientX;
  7760. mouseY = evt.clientY;
  7761. }
  7762. }
  7763. clearTimeout(_selectionChangeTimer);
  7764. _selectionChangeTimer = setTimeout(function() {
  7765. if(!me.selection || !me.selection.getNative()) {
  7766. return;
  7767. }
  7768. // 修复一个IE下的bug:
  7769. // 鼠标点击一段已选择的文本中间时,可能在mouseup后的一段时间内取到的range是在selection的type为None下的错误值.
  7770. // IE下如果用户是拖拽一段已选择文本,则不会触发mouseup事件,所以这里的特殊处理不会对其有影响
  7771. var ieRange;
  7772. if(hackForMouseUp &&
  7773. me.selection.getNative().type == 'None') {
  7774. ieRange = me.document.body.createTextRange();
  7775. try {
  7776. ieRange.moveToPoint(mouseX, mouseY);
  7777. } catch(ex) {
  7778. ieRange = null;
  7779. }
  7780. }
  7781. var bakGetIERange;
  7782. if(ieRange) {
  7783. bakGetIERange = me.selection.getIERange;
  7784. me.selection.getIERange = function() {
  7785. return ieRange;
  7786. };
  7787. }
  7788. me.selection.cache();
  7789. if(bakGetIERange) {
  7790. me.selection.getIERange = bakGetIERange;
  7791. }
  7792. if(me.selection._cachedRange &&
  7793. me.selection._cachedStartElement) {
  7794. me.fireEvent('beforeselectionchange');
  7795. // 第二个参数causeByUi为true代表由用户交互造成的selectionchange.
  7796. me.fireEvent('selectionchange', !!evt);
  7797. me.fireEvent('afterselectionchange');
  7798. me.selection.clear();
  7799. }
  7800. }, delay || 50);
  7801. },
  7802. /**
  7803. * 执行编辑命令
  7804. *
  7805. * @method _callCmdFn
  7806. * @private
  7807. * @param {
  7808. * String } fnName 函数名称
  7809. * @param { * }
  7810. * args 传给命令函数的参数
  7811. * @return { * } 返回命令函数运行的返回值
  7812. */
  7813. _callCmdFn: function(fnName, args) {
  7814. var cmdName = args[0].toLowerCase(),
  7815. cmd, cmdFn;
  7816. cmd = this.commands[cmdName] || UE.commands[cmdName];
  7817. cmdFn = cmd && cmd[fnName];
  7818. // 没有querycommandstate或者没有command的都默认返回0
  7819. if((!cmd || !cmdFn) && fnName == 'queryCommandState') {
  7820. return 0;
  7821. } else if(cmdFn) {
  7822. return cmdFn.apply(this, args);
  7823. }
  7824. },
  7825. /**
  7826. * 执行编辑命令cmdName,完成富文本编辑效果
  7827. *
  7828. * @method execCommand
  7829. * @param {
  7830. * String } cmdName 需要执行的命令
  7831. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  7832. * @return { * } 返回命令函数运行的返回值
  7833. * @example ```javascript editor.execCommand(cmdName); ```
  7834. */
  7835. execCommand: function(cmdName) {
  7836. cmdName = cmdName.toLowerCase();
  7837. var me = this,
  7838. result, cmd = me.commands[cmdName] ||
  7839. UE.commands[cmdName];
  7840. if(!cmd || !cmd.execCommand) {
  7841. return null;
  7842. }
  7843. if(!cmd.notNeedUndo && !me.__hasEnterExecCommand) {
  7844. me.__hasEnterExecCommand = true;
  7845. if(me.queryCommandState.apply(me, arguments) != -1) {
  7846. me.fireEvent('saveScene');
  7847. me.fireEvent.apply(me, ['beforeexeccommand', cmdName]
  7848. .concat(arguments));
  7849. result = this._callCmdFn('execCommand', arguments);
  7850. // 保存场景时,做了内容对比,再看是否进行contentchange触发,这里多触发了一次,去掉
  7851. // (!cmd.ignoreContentChange &&
  7852. // !me._ignoreContentChange) &&
  7853. // me.fireEvent('contentchange');
  7854. me.fireEvent.apply(me, ['afterexeccommand', cmdName]
  7855. .concat(arguments));
  7856. me.fireEvent('saveScene');
  7857. }
  7858. me.__hasEnterExecCommand = false;
  7859. } else {
  7860. result = this._callCmdFn('execCommand', arguments);
  7861. (!me.__hasEnterExecCommand && !cmd.ignoreContentChange && !me._ignoreContentChange) &&
  7862. me.fireEvent('contentchange')
  7863. }
  7864. (!me.__hasEnterExecCommand && !cmd.ignoreContentChange && !me._ignoreContentChange) &&
  7865. me._selectionChange();
  7866. return result;
  7867. },
  7868. /**
  7869. * 根据传入的command命令,查选编辑器当前的选区,返回命令的状态
  7870. *
  7871. * @method queryCommandState
  7872. * @param {
  7873. * String } cmdName 需要查询的命令名称
  7874. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  7875. * @return { Number } number 返回放前命令的状态,返回值三种情况:(-1|0|1)
  7876. * @example ```javascript editor.queryCommandState(cmdName) =>
  7877. * (-1|0|1) ```
  7878. * @see COMMAND.LIST
  7879. */
  7880. queryCommandState: function(cmdName) {
  7881. return this._callCmdFn('queryCommandState', arguments);
  7882. },
  7883. /**
  7884. * 根据传入的command命令,查选编辑器当前的选区,根据命令返回相关的值
  7885. *
  7886. * @method queryCommandValue
  7887. * @param {
  7888. * String } cmdName 需要查询的命令名称
  7889. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  7890. * @remind 只有部分插件有此方法
  7891. * @return { * } 返回每个命令特定的当前状态值
  7892. * @grammar editor.queryCommandValue(cmdName) => {*}
  7893. * @see COMMAND.LIST
  7894. */
  7895. queryCommandValue: function(cmdName) {
  7896. return this._callCmdFn('queryCommandValue', arguments);
  7897. },
  7898. /**
  7899. * 检查编辑区域中是否有内容
  7900. *
  7901. * @method hasContents
  7902. * @remind 默认有文本内容,或者有以下节点都不认为是空
  7903. * table,ul,ol,dl,iframe,area,base,col,hr,img,embed,input,link,meta,param
  7904. * @return { Boolean } 检查有内容返回true,否则返回false
  7905. * @example ```javascript editor.hasContents() ```
  7906. */
  7907. /**
  7908. * 检查编辑区域中是否有内容,若包含参数tags中的节点类型,直接返回true
  7909. *
  7910. * @method hasContents
  7911. * @param {
  7912. * Array } tags 传入数组判断时用到的节点类型
  7913. * @return { Boolean } 若文档中包含tags数组里对应的tag,返回true,否则返回false
  7914. * @example ```javascript editor.hasContents(['span']); ```
  7915. */
  7916. hasContents: function(tags) {
  7917. if(tags) {
  7918. for(var i = 0, ci; ci = tags[i++];) {
  7919. if(this.document.getElementsByTagName(ci).length > 0) {
  7920. return true;
  7921. }
  7922. }
  7923. }
  7924. if(!domUtils.isEmptyBlock(this.body)) {
  7925. return true
  7926. }
  7927. // 随时添加,定义的特殊标签如果存在,不能认为是空
  7928. tags = ['div'];
  7929. for(i = 0; ci = tags[i++];) {
  7930. var nodes = domUtils
  7931. .getElementsByTagName(this.document, ci);
  7932. for(var n = 0, cn; cn = nodes[n++];) {
  7933. if(domUtils.isCustomeNode(cn)) {
  7934. return true;
  7935. }
  7936. }
  7937. }
  7938. return false;
  7939. },
  7940. /**
  7941. * 重置编辑器,可用来做多个tab使用同一个编辑器实例
  7942. *
  7943. * @method reset
  7944. * @remind 此方法会清空编辑器内容,清空回退列表,会触发reset事件
  7945. * @example ```javascript editor.reset() ```
  7946. */
  7947. reset: function() {
  7948. this.fireEvent('reset');
  7949. },
  7950. /**
  7951. * 设置当前编辑区域可以编辑
  7952. *
  7953. * @method setEnabled
  7954. * @example ```javascript editor.setEnabled() ```
  7955. */
  7956. setEnabled: function() {
  7957. var me = this,
  7958. range;
  7959. if(me.body.contentEditable == 'false') {
  7960. me.body.contentEditable = true;
  7961. range = me.selection.getRange();
  7962. // 有可能内容丢失了
  7963. try {
  7964. range.moveToBookmark(me.lastBk);
  7965. delete me.lastBk
  7966. } catch(e) {
  7967. range.setStartAtFirst(me.body).collapse(true)
  7968. }
  7969. range.select(true);
  7970. if(me.bkqueryCommandState) {
  7971. me.queryCommandState = me.bkqueryCommandState;
  7972. delete me.bkqueryCommandState;
  7973. }
  7974. if(me.bkqueryCommandValue) {
  7975. me.queryCommandValue = me.bkqueryCommandValue;
  7976. delete me.bkqueryCommandValue;
  7977. }
  7978. me.fireEvent('selectionchange');
  7979. }
  7980. },
  7981. enable: function() {
  7982. return this.setEnabled();
  7983. },
  7984. /**
  7985. * 设置当前编辑区域不可编辑
  7986. *
  7987. * @method setDisabled
  7988. */
  7989. /**
  7990. * 设置当前编辑区域不可编辑,except中的命令除外
  7991. *
  7992. * @method setDisabled
  7993. * @param {
  7994. * String } except 例外命令的字符串
  7995. * @remind 即使设置了disable,此处配置的例外命令仍然可以执行
  7996. * @example ```javascript editor.setDisabled('bold');
  7997. * //禁用工具栏中除加粗之外的所有功能 ```
  7998. */
  7999. /**
  8000. * 设置当前编辑区域不可编辑,except中的命令除外
  8001. *
  8002. * @method setDisabled
  8003. * @param {
  8004. * Array } except 例外命令的字符串数组,数组中的命令仍然可以执行
  8005. * @remind 即使设置了disable,此处配置的例外命令仍然可以执行
  8006. * @example ```javascript
  8007. * editor.setDisabled(['bold','insertimage']);
  8008. * //禁用工具栏中除加粗和插入图片之外的所有功能 ```
  8009. */
  8010. setDisabled: function(except) {
  8011. var me = this;
  8012. except = except ?
  8013. utils.isArray(except) ? except : [except] : [];
  8014. if(me.body.contentEditable == 'true') {
  8015. if(!me.lastBk) {
  8016. me.lastBk = me.selection.getRange()
  8017. .createBookmark(true);
  8018. }
  8019. me.body.contentEditable = false;
  8020. me.bkqueryCommandState = me.queryCommandState;
  8021. me.bkqueryCommandValue = me.queryCommandValue;
  8022. me.queryCommandState = function(type) {
  8023. if(utils.indexOf(except, type) != -1) {
  8024. return me.bkqueryCommandState.apply(me, arguments);
  8025. }
  8026. return -1;
  8027. };
  8028. me.queryCommandValue = function(type) {
  8029. if(utils.indexOf(except, type) != -1) {
  8030. return me.bkqueryCommandValue.apply(me, arguments);
  8031. }
  8032. return null;
  8033. };
  8034. me.fireEvent('selectionchange');
  8035. }
  8036. },
  8037. disable: function(except) {
  8038. return this.setDisabled(except);
  8039. },
  8040. /**
  8041. * 设置默认内容
  8042. *
  8043. * @method _setDefaultContent
  8044. * @private
  8045. * @param {
  8046. * String } cont 要存入的内容
  8047. */
  8048. _setDefaultContent: function() {
  8049. function clear() {
  8050. var me = this;
  8051. if(me.document.getElementById('initContent')) {
  8052. me.body.innerHTML = '<p>' + (ie ? '' : '<br/>') +
  8053. '</p>';
  8054. me
  8055. .removeListener('firstBeforeExecCommand focus',
  8056. clear);
  8057. setTimeout(function() {
  8058. me.focus();
  8059. me._selectionChange();
  8060. }, 0)
  8061. }
  8062. }
  8063. return function(cont) {
  8064. var me = this;
  8065. me.body.innerHTML = '<p id="initContent">' + cont + '</p>';
  8066. me.addListener('firstBeforeExecCommand focus', clear);
  8067. }
  8068. }(),
  8069. /**
  8070. * 显示编辑器
  8071. *
  8072. * @method setShow
  8073. * @example ```javascript editor.setShow() ```
  8074. */
  8075. setShow: function() {
  8076. var me = this,
  8077. range = me.selection.getRange();
  8078. if(me.container.style.display == 'none') {
  8079. // 有可能内容丢失了
  8080. try {
  8081. range.moveToBookmark(me.lastBk);
  8082. delete me.lastBk
  8083. } catch(e) {
  8084. range.setStartAtFirst(me.body).collapse(true)
  8085. }
  8086. // ie下focus实效,所以做了个延迟
  8087. setTimeout(function() {
  8088. range.select(true);
  8089. }, 100);
  8090. me.container.style.display = '';
  8091. }
  8092. },
  8093. show: function() {
  8094. return this.setShow();
  8095. },
  8096. /**
  8097. * 隐藏编辑器
  8098. *
  8099. * @method setHide
  8100. * @example ```javascript editor.setHide() ```
  8101. */
  8102. setHide: function() {
  8103. var me = this;
  8104. if(!me.lastBk) {
  8105. me.lastBk = me.selection.getRange().createBookmark(true);
  8106. }
  8107. me.container.style.display = 'none'
  8108. },
  8109. hide: function() {
  8110. return this.setHide();
  8111. },
  8112. /**
  8113. * 根据指定的路径,获取对应的语言资源
  8114. *
  8115. * @method getLang
  8116. * @param {
  8117. * String } path 路径根据的是lang目录下的语言文件的路径结构
  8118. * @return { Object | String } 根据路径返回语言资源的Json格式对象或者语言字符串
  8119. * @example ```javascript editor.getLang('contextMenu.delete');
  8120. * //如果当前是中文,那返回是的是'删除' ```
  8121. */
  8122. getLang: function(path) {
  8123. var lang = UE.I18N[this.options.lang];
  8124. if(!lang) {
  8125. throw Error("not import language file");
  8126. }
  8127. path = (path || "").split(".");
  8128. for(var i = 0, ci; ci = path[i++];) {
  8129. lang = lang[ci];
  8130. if(!lang)
  8131. break;
  8132. }
  8133. return lang;
  8134. },
  8135. /**
  8136. * 计算编辑器html内容字符串的长度
  8137. *
  8138. * @method getContentLength
  8139. * @return { Number } 返回计算的长度
  8140. * @example ```javascript //编辑器html内容
  8141. * <p>
  8142. * <strong>132</strong>
  8143. * </p>
  8144. * editor.getContentLength() //返回27 ```
  8145. */
  8146. /**
  8147. * 计算编辑器当前纯文本内容的长度
  8148. *
  8149. * @method getContentLength
  8150. * @param {
  8151. * Boolean } ingoneHtml 传入true时,只按照纯文本来计算
  8152. * @return { Number } 返回计算的长度,内容中有hr/img/iframe标签,长度加1
  8153. * @example ```javascript //编辑器html内容
  8154. * <p>
  8155. * <strong>132</strong>
  8156. * </p>
  8157. * editor.getContentLength() //返回3 ```
  8158. */
  8159. getContentLength: function(ingoneHtml, tagNames) {
  8160. var count = this.getContent(false, false, true).length;
  8161. if(ingoneHtml) {
  8162. tagNames = (tagNames || []).concat(['hr', 'img', 'iframe']);
  8163. count = this.getContentTxt().replace(/[\t\r\n]+/g, '').length;
  8164. for(var i = 0, ci; ci = tagNames[i++];) {
  8165. count += this.document.getElementsByTagName(ci).length;
  8166. }
  8167. }
  8168. return count;
  8169. },
  8170. /**
  8171. * 注册输入过滤规则
  8172. *
  8173. * @method addInputRule
  8174. * @param {
  8175. * Function } rule 要添加的过滤规则
  8176. * @example ```javascript editor.addInputRule(function(root){
  8177. * $.each(root.getNodesByTagName('div'),function(i,node){
  8178. * node.tagName="p"; }); }); ```
  8179. */
  8180. addInputRule: function(rule) {
  8181. this.inputRules.push(rule);
  8182. },
  8183. /**
  8184. * 执行注册的过滤规则
  8185. *
  8186. * @method filterInputRule
  8187. * @param {
  8188. * UE.uNode } root 要过滤的uNode节点
  8189. * @remind 执行editor.setContent方法和执行'inserthtml'命令后,会运行该过滤函数
  8190. * @example ```javascript editor.filterInputRule(editor.body); ```
  8191. * @see UE.Editor:addInputRule
  8192. */
  8193. filterInputRule: function(root) {
  8194. for(var i = 0, ci; ci = this.inputRules[i++];) {
  8195. ci.call(this, root)
  8196. }
  8197. },
  8198. /**
  8199. * 注册输出过滤规则
  8200. *
  8201. * @method addOutputRule
  8202. * @param {
  8203. * Function } rule 要添加的过滤规则
  8204. * @example ```javascript editor.addOutputRule(function(root){
  8205. * $.each(root.getNodesByTagName('p'),function(i,node){
  8206. * node.tagName="div"; }); }); ```
  8207. */
  8208. addOutputRule: function(rule) {
  8209. this.outputRules.push(rule)
  8210. },
  8211. /**
  8212. * 根据输出过滤规则,过滤编辑器内容
  8213. *
  8214. * @method filterOutputRule
  8215. * @remind 执行editor.getContent方法的时候,会先运行该过滤函数
  8216. * @param {
  8217. * UE.uNode } root 要过滤的uNode节点
  8218. * @example ```javascript editor.filterOutputRule(editor.body); ```
  8219. * @see UE.Editor:addOutputRule
  8220. */
  8221. filterOutputRule: function(root) {
  8222. for(var i = 0, ci; ci = this.outputRules[i++];) {
  8223. ci.call(this, root)
  8224. }
  8225. },
  8226. /**
  8227. * 根据action名称获取请求的路径
  8228. *
  8229. * @method getActionUrl
  8230. * @remind 假如没有设置serverUrl,会根据imageUrl设置默认的controller路径
  8231. * @param {
  8232. * String } action action名称
  8233. * @example ```javascript editor.getActionUrl('config'); //返回
  8234. * "/ueditor/php/controller.php?action=config"
  8235. * editor.getActionUrl('image'); //返回
  8236. * "/ueditor/php/controller.php?action=uplaodimage"
  8237. * editor.getActionUrl('scrawl'); //返回
  8238. * "/ueditor/php/controller.php?action=uplaodscrawl"
  8239. * editor.getActionUrl('imageManager'); //返回
  8240. * "/ueditor/php/controller.php?action=listimage" ```
  8241. */
  8242. getActionUrl: function(action) {
  8243. console.info("====>action:" + action);
  8244. var actionName = this.getOpt(action) || action,
  8245. imageUrl = this
  8246. .getOpt('imageUrl'),
  8247. serverUrl = this
  8248. .getOpt('serverUrl');
  8249. // serverUrl="/service?wdApplication=wenz&wdService=tpsc&wdToken=9521";
  8250. // console.info("====>action:" + action);
  8251. // console.info("====>action:" + action);
  8252. if(!serverUrl && imageUrl) {
  8253. serverUrl = imageUrl.replace(/^(.*[\/]).+([\.].+)$/,
  8254. '$1controller$2');
  8255. }
  8256. if(serverUrl) {
  8257. serverUrl = serverUrl +
  8258. (serverUrl.indexOf('?') == -1 ? '?' : '&') +
  8259. 'action=' + (actionName || '');
  8260. return utils.formatUrl(serverUrl);
  8261. } else {
  8262. return '';
  8263. }
  8264. }
  8265. };
  8266. utils.inherits(Editor, EventBase);
  8267. })();
  8268. // core/Editor.defaultoptions.js
  8269. // 维护编辑器一下默认的不在插件中的配置项
  8270. UE.Editor.defaultOptions = function(editor) {
  8271. var _url = editor.options.UEDITOR_HOME_URL;
  8272. return {
  8273. isShow: true,
  8274. initialContent: '',
  8275. initialStyle: '',
  8276. autoClearinitialContent: false,
  8277. iframeCssUrl: _url + 'themes/iframe.css',
  8278. textarea: 'editorValue',
  8279. focus: false,
  8280. focusInEnd: true,
  8281. autoClearEmptyNode: true,
  8282. fullscreen: false,
  8283. readonly: false,
  8284. zIndex: 999,
  8285. imagePopup: true,
  8286. enterTag: 'p',
  8287. customDomain: false,
  8288. lang: 'zh-cn',
  8289. langPath: _url + 'lang/',
  8290. theme: 'default',
  8291. themePath: _url + 'themes/',
  8292. allHtmlEnabled: false,
  8293. scaleEnabled: false,
  8294. tableNativeEditInFF: false,
  8295. autoSyncData: true,
  8296. fileNameFormat: '{time}{rand:6}'
  8297. }
  8298. };
  8299. // core/loadconfig.js
  8300. (function() {
  8301. UE.Editor.prototype.loadServerConfig = function() {
  8302. var me = this;
  8303. setTimeout(function() {
  8304. try {
  8305. me.options.imageUrl &&
  8306. me.setOpt('serverUrl', me.options.imageUrl
  8307. .replace(/^(.*[\/]).+([\.].+)$/,
  8308. '$1controller$2'));
  8309. var configUrl = me.getActionUrl('config'),
  8310. isJsonp = utils
  8311. .isCrossDomainUrl(configUrl);
  8312. /* 发出ajax请求 */
  8313. me._serverConfigLoaded = false;
  8314. configUrl && UE.ajax.request(configUrl, { // (configUrl + getWdApp(),。去掉 ?wdApplication=,不支持多个应用Lin
  8315. 'method': 'GET',
  8316. 'dataType': isJsonp ? 'jsonp' : '',
  8317. 'onsuccess': function(r) {
  8318. try {
  8319. var config = isJsonp ? r : eval("(" +
  8320. r.responseText + ")");
  8321. utils.extend(me.options, config);
  8322. me.fireEvent('serverConfigLoaded');
  8323. me._serverConfigLoaded = true;
  8324. } catch(e) {
  8325. ErrorMsg(me.getLang('loadconfigFormatError'));
  8326. }
  8327. },
  8328. 'onerror': function() {
  8329. showErrorMsg(me.getLang('loadconfigHttpError'));
  8330. }
  8331. });
  8332. } catch(e) {
  8333. showErrorMsg(me.getLang('loadconfigError'));
  8334. }
  8335. });
  8336. function showErrorMsg(msg) {
  8337. console && console.error(msg);
  8338. // me.fireEvent('showMessage', {
  8339. // 'title': msg,
  8340. // 'type': 'error'
  8341. // });
  8342. }
  8343. };
  8344. UE.Editor.prototype.isServerConfigLoaded = function() {
  8345. var me = this;
  8346. return me._serverConfigLoaded || false;
  8347. };
  8348. UE.Editor.prototype.afterConfigReady = function(handler) {
  8349. if(!handler || !utils.isFunction(handler))
  8350. return;
  8351. var me = this;
  8352. var readyHandler = function() {
  8353. handler.apply(me, arguments);
  8354. me.removeListener('serverConfigLoaded', readyHandler);
  8355. };
  8356. if(me.isServerConfigLoaded()) {
  8357. handler.call(me, 'serverConfigLoaded');
  8358. } else {
  8359. me.addListener('serverConfigLoaded', readyHandler);
  8360. }
  8361. };
  8362. })();
  8363. // core/ajax.js
  8364. /**
  8365. * @file
  8366. * @module UE.ajax
  8367. * @since 1.2.6.1
  8368. */
  8369. /**
  8370. * 提供对ajax请求的支持
  8371. *
  8372. * @module UE.ajax
  8373. */
  8374. UE.ajax = function() {
  8375. // 创建一个ajaxRequest对象
  8376. var fnStr = 'XMLHttpRequest()';
  8377. try {
  8378. new ActiveXObject("Msxml2.XMLHTTP");
  8379. fnStr = 'ActiveXObject(\'Msxml2.XMLHTTP\')';
  8380. } catch(e) {
  8381. try {
  8382. new ActiveXObject("Microsoft.XMLHTTP");
  8383. fnStr = 'ActiveXObject(\'Microsoft.XMLHTTP\')'
  8384. } catch(e) {}
  8385. }
  8386. var creatAjaxRequest = new Function('return new ' + fnStr);
  8387. /**
  8388. * 将json参数转化成适合ajax提交的参数列表
  8389. *
  8390. * @param json
  8391. */
  8392. function json2str(json) {
  8393. var strArr = [];
  8394. for(var i in json) {
  8395. // 忽略默认的几个参数
  8396. if(i == "method" || i == "timeout" || i == "async" ||
  8397. i == "dataType" || i == "callback")
  8398. continue;
  8399. // 忽略控制
  8400. if(json[i] == undefined || json[i] == null)
  8401. continue;
  8402. // 传递过来的对象和函数不在提交之列
  8403. if(!((typeof json[i]).toLowerCase() == "function" || (typeof json[i])
  8404. .toLowerCase() == "object")) {
  8405. strArr.push(encodeURIComponent(i) + "=" +
  8406. encodeURIComponent(json[i]));
  8407. } else if(utils.isArray(json[i])) {
  8408. // 支持传数组内容
  8409. for(var j = 0; j < json[i].length; j++) {
  8410. strArr.push(encodeURIComponent(i) + "[]=" +
  8411. encodeURIComponent(json[i][j]));
  8412. }
  8413. }
  8414. }
  8415. return strArr.join("&");
  8416. }
  8417. function doAjax(url, ajaxOptions) {
  8418. var xhr = creatAjaxRequest(),
  8419. // 是否超时
  8420. timeIsOut = false,
  8421. // 默认参数
  8422. defaultAjaxOptions = {
  8423. method: "POST",
  8424. timeout: 5000,
  8425. async: true,
  8426. data: {}, // 需要传递对象的话只能覆盖
  8427. onsuccess: function() {},
  8428. onerror: function() {}
  8429. };
  8430. if(typeof url === "object") {
  8431. ajaxOptions = url;
  8432. url = ajaxOptions.url;
  8433. }
  8434. if(!xhr || !url)
  8435. return;
  8436. var ajaxOpts = ajaxOptions ? utils.extend(defaultAjaxOptions,
  8437. ajaxOptions) : defaultAjaxOptions;
  8438. var submitStr = json2str(ajaxOpts); // { name:"Jim",city:"Beijing" }
  8439. // --> "name=Jim&city=Beijing"
  8440. // 如果用户直接通过data参数传递json对象过来,则也要将此json对象转化为字符串
  8441. if(!utils.isEmptyObject(ajaxOpts.data)) {
  8442. submitStr += (submitStr ? "&" : "") + json2str(ajaxOpts.data);
  8443. }
  8444. // 超时检测
  8445. var timerID = setTimeout(function() {
  8446. if(xhr.readyState != 4) {
  8447. timeIsOut = true;
  8448. xhr.abort();
  8449. clearTimeout(timerID);
  8450. }
  8451. }, ajaxOpts.timeout);
  8452. var method = ajaxOpts.method.toUpperCase();
  8453. var str = url +
  8454. (url.indexOf("?") == -1 ? "?" : "&") +
  8455. (method == "POST" ? "" : submitStr + "&noCache=" +
  8456. +new Date);
  8457. xhr.open(method, str, ajaxOpts.async);
  8458. xhr.onreadystatechange = function() {
  8459. if(xhr.readyState == 4) {
  8460. if(!timeIsOut && xhr.status == 200) {
  8461. ajaxOpts.onsuccess(xhr);
  8462. } else {
  8463. ajaxOpts.onerror(xhr);
  8464. }
  8465. }
  8466. };
  8467. if(method == "POST") {
  8468. xhr.setRequestHeader('Content-Type',
  8469. 'application/x-www-form-urlencoded');
  8470. xhr.send(submitStr);
  8471. } else {
  8472. xhr.send(null);
  8473. }
  8474. }
  8475. function doJsonp(url, opts) {
  8476. var successhandler = opts.onsuccess || function() {},
  8477. scr = document.createElement('SCRIPT'),
  8478. options = opts || {},
  8479. charset = options['charset'],
  8480. callbackField = options['jsonp'] ||
  8481. 'callback',
  8482. callbackFnName, timeOut = options['timeOut'] ||
  8483. 0,
  8484. timer, reg = new RegExp('(\\?|&)' + callbackField +
  8485. '=([^&]*)'),
  8486. matches;
  8487. if(utils.isFunction(successhandler)) {
  8488. callbackFnName = 'bd__editor__' +
  8489. Math.floor(Math.random() * 2147483648).toString(36);
  8490. window[callbackFnName] = getCallBack(0);
  8491. } else if(utils.isString(successhandler)) {
  8492. callbackFnName = successhandler;
  8493. } else {
  8494. if(matches = reg.exec(url)) {
  8495. callbackFnName = matches[2];
  8496. }
  8497. }
  8498. url = url.replace(reg, '\x241' + callbackField + '=' +
  8499. callbackFnName);
  8500. if(url.search(reg) < 0) {
  8501. url += (url.indexOf('?') < 0 ? '?' : '&') + callbackField + '=' +
  8502. callbackFnName;
  8503. }
  8504. var queryStr = json2str(opts); // { name:"Jim",city:"Beijing" } -->
  8505. // "name=Jim&city=Beijing"
  8506. // 如果用户直接通过data参数传递json对象过来,则也要将此json对象转化为字符串
  8507. if(!utils.isEmptyObject(opts.data)) {
  8508. queryStr += (queryStr ? "&" : "") + json2str(opts.data);
  8509. }
  8510. if(queryStr) {
  8511. url = url.replace(/\?/, '?' + queryStr + '&');
  8512. }
  8513. scr.onerror = getCallBack(1);
  8514. if(timeOut) {
  8515. timer = setTimeout(getCallBack(1), timeOut);
  8516. }
  8517. createScriptTag(scr, url, charset);
  8518. function createScriptTag(scr, url, charset) {
  8519. scr.setAttribute('type', 'text/javascript');
  8520. scr.setAttribute('defer', 'defer');
  8521. charset && scr.setAttribute('charset', charset);
  8522. scr.setAttribute('src', url);
  8523. document.getElementsByTagName('head')[0].appendChild(scr);
  8524. }
  8525. function getCallBack(onTimeOut) {
  8526. return function() {
  8527. try {
  8528. if(onTimeOut) {
  8529. options.onerror && options.onerror();
  8530. } else {
  8531. try {
  8532. clearTimeout(timer);
  8533. successhandler.apply(window, arguments);
  8534. } catch(e) {}
  8535. }
  8536. } catch(exception) {
  8537. options.onerror &&
  8538. options.onerror.call(window, exception);
  8539. } finally {
  8540. options.oncomplete &&
  8541. options.oncomplete.apply(window, arguments);
  8542. scr.parentNode && scr.parentNode.removeChild(scr);
  8543. window[callbackFnName] = null;
  8544. try {
  8545. delete window[callbackFnName];
  8546. } catch(e) {}
  8547. }
  8548. }
  8549. }
  8550. }
  8551. return {
  8552. /**
  8553. * 根据给定的参数项,向指定的url发起一个ajax请求。 ajax请求完成后,会根据请求结果调用相应回调: 如果请求 成功,
  8554. * 则调用onsuccess回调, 失败则调用 onerror 回调
  8555. *
  8556. * @method request
  8557. * @param {
  8558. * URLString } url ajax请求的url地址
  8559. * @param {
  8560. * Object } ajaxOptions ajax请求选项的键值对,支持的选项如下:
  8561. * @example ```javascript //向sayhello.php发起一个异步的Ajax GET请求,
  8562. * 请求超时时间为10s, 请求完成后执行相应的回调。 UE.ajax.requeset(
  8563. * 'sayhello.php', {
  8564. *
  8565. * //请求方法。可选值: 'GET', 'POST',默认值是'POST' method: 'GET',
  8566. *
  8567. * //超时时间。 默认为5000, 单位是ms timeout: 10000,
  8568. *
  8569. * //是否是异步请求。 true为异步请求, false为同步请求 async: true,
  8570. *
  8571. * //请求携带的数据。如果请求为GET请求, data会经过stringify后附加到请求url之后。 data: { name:
  8572. * 'ueditor' },
  8573. *
  8574. * //请求成功后的回调, 该回调接受当前的XMLHttpRequest对象作为参数。 onsuccess: function (
  8575. * xhr ) { console.log( xhr.responseText ); },
  8576. *
  8577. * //请求失败或者超时后的回调。 onerror: function ( xhr ) { alert( 'Ajax请求失败' ); } } );
  8578. * ```
  8579. */
  8580. /**
  8581. * 根据给定的参数项发起一个ajax请求, 参数项里必须包含一个url地址。 ajax请求完成后,会根据请求结果调用相应回调:
  8582. * 如果请求 成功, 则调用onsuccess回调, 失败则调用 onerror 回调。
  8583. *
  8584. * @method request
  8585. * @warning 如果在参数项里未提供一个key为“url”的地址值,则该请求将直接退出。
  8586. * @param {
  8587. * Object } ajaxOptions ajax请求选项的键值对,支持的选项如下:
  8588. * @example ```javascript
  8589. *
  8590. * //向sayhello.php发起一个异步的Ajax POST请求, 请求超时时间为5s, 请求完成后不执行任何回调。
  8591. * UE.ajax.requeset( 'sayhello.php', {
  8592. *
  8593. * //请求的地址, 该项是必须的。 url: 'sayhello.php' } ); ```
  8594. */
  8595. request: function(url, opts) {
  8596. if(opts && opts.dataType == 'jsonp') {
  8597. doJsonp(url, opts);
  8598. } else {
  8599. doAjax(url, opts);
  8600. }
  8601. },
  8602. getJSONP: function(url, data, fn) {
  8603. var opts = {
  8604. 'data': data,
  8605. 'oncomplete': fn
  8606. };
  8607. doJsonp(url, opts);
  8608. }
  8609. };
  8610. }();
  8611. // core/filterword.js
  8612. /**
  8613. * UE过滤word的静态方法
  8614. *
  8615. * @file
  8616. */
  8617. /**
  8618. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  8619. *
  8620. * @module UE
  8621. */
  8622. /**
  8623. * 根据传入html字符串过滤word
  8624. *
  8625. * @module UE
  8626. * @since 1.2.6.1
  8627. * @method filterWord
  8628. * @param {
  8629. * String } html html字符串
  8630. * @return { String } 已过滤后的结果字符串
  8631. * @example ```javascript UE.filterWord(html); ```
  8632. */
  8633. var filterWord = UE.filterWord = function() {
  8634. // 是否是word过来的内容
  8635. function isWordDocument(str) {
  8636. return /(class="?Mso|style="[^"]*\bmso\-|w:WordDocument|<(v|o):|lang=)/ig
  8637. .test(str);
  8638. }
  8639. // 去掉小数
  8640. function transUnit(v) {
  8641. v = v.replace(/[\d.]+\w+/g, function(m) {
  8642. return utils.transUnitToPx(m);
  8643. });
  8644. return v;
  8645. }
  8646. function filterPasteWord(str) {
  8647. return str
  8648. .replace(/[\t\r\n]+/g, ' ')
  8649. .replace(/<!--[\s\S]*?-->/ig, "")
  8650. // 转换图片
  8651. .replace(/<v:shape [^>]*>[\s\S]*?.<\/v:shape>/gi,
  8652. function(str) {
  8653. // opera能自己解析出image所这里直接返回空
  8654. if(browser.opera) {
  8655. return '';
  8656. }
  8657. try {
  8658. // 有可能是bitmap占为图,无用,直接过滤掉,主要体现在粘贴excel表格中
  8659. if(/Bitmap/i.test(str)) {
  8660. return '';
  8661. }
  8662. var width = str
  8663. .match(/width:([ \d.]*p[tx])/i)[1],
  8664. height = str
  8665. .match(/height:([ \d.]*p[tx])/i)[1],
  8666. src = str
  8667. .match(/src=\s*"([^"]*)"/i)[1];
  8668. return '<img width="' + transUnit(width) +
  8669. '" height="' + transUnit(height) +
  8670. '" src="' + src + '" />';
  8671. } catch(e) {
  8672. return '';
  8673. }
  8674. })
  8675. // 针对wps添加的多余标签处理
  8676. .replace(/<\/?div[^>]*>/g, '')
  8677. // 去掉多余的属性
  8678. .replace(/v:\w+=(["']?)[^'"]+\1/g, '')
  8679. .replace(
  8680. /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|xml|meta|link|style|\w+:\w+)(?=[\s\/>]))[^>]*>/gi,
  8681. "").replace(
  8682. /<p [^>]*class="?MsoHeading"?[^>]*>(.*?)<\/p>/gi,
  8683. "<p><strong>$1</strong></p>")
  8684. // 去掉多余的属性
  8685. .replace(/\s+(class|lang|align)\s*=\s*(['"]?)([\w-]+)\2/ig,
  8686. function(str, name, marks, val) {
  8687. // 保留list的标示
  8688. return name == 'class' &&
  8689. val == 'MsoListParagraph' ? str : ''
  8690. })
  8691. // 清除多余的font/span不能匹配&nbsp;有可能是空格
  8692. .replace(/<(font|span)[^>]*>(\s*)<\/\1>/gi,
  8693. function(a, b, c) {
  8694. return c.replace(/[\t\r\n ]+/g, ' ')
  8695. })
  8696. // 处理style的问题
  8697. .replace(/(<[a-z][^>]*)\sstyle=(["'])([^\2]*?)\2/gi,
  8698. function(str, tag, tmp, style) {
  8699. var n = [],
  8700. s = style.replace(/^\s+|\s+$/, '')
  8701. .replace(/&#39;/g, '\'').replace(
  8702. /&quot;/gi, "'").replace(
  8703. /[\d.]+(cm|pt)/g,
  8704. function(str) {
  8705. return utils
  8706. .transUnitToPx(str)
  8707. }).split(/;\s*/g);
  8708. for(var i = 0, v; v = s[i]; i++) {
  8709. var name, value, parts = v.split(":");
  8710. if(parts.length == 2) {
  8711. name = parts[0].toLowerCase();
  8712. value = parts[1].toLowerCase();
  8713. if(/^(background)\w*/.test(name) &&
  8714. value.replace(
  8715. /(initial|\s)/g, '').length == 0 ||
  8716. /^(margin)\w*/.test(name) &&
  8717. /^0\w+$/.test(value)) {
  8718. continue;
  8719. }
  8720. switch(name) {
  8721. case "mso-padding-alt":
  8722. case "mso-padding-top-alt":
  8723. case "mso-padding-right-alt":
  8724. case "mso-padding-bottom-alt":
  8725. case "mso-padding-left-alt":
  8726. case "mso-margin-alt":
  8727. case "mso-margin-top-alt":
  8728. case "mso-margin-right-alt":
  8729. case "mso-margin-bottom-alt":
  8730. case "mso-margin-left-alt":
  8731. // ie下会出现挤到一起的情况
  8732. // case "mso-table-layout-alt":
  8733. case "mso-height":
  8734. case "mso-width":
  8735. case "mso-vertical-align-alt":
  8736. // trace:1819
  8737. // ff下会解析出padding在table上
  8738. if(!/<table/.test(tag))
  8739. n[i] = name.replace(
  8740. /^mso-|-alt$/g, "") +
  8741. ":" +
  8742. transUnit(value);
  8743. continue;
  8744. case "horiz-align":
  8745. n[i] = "text-align:" + value;
  8746. continue;
  8747. case "vert-align":
  8748. n[i] = "vertical-align:" +
  8749. value;
  8750. continue;
  8751. case "font-color":
  8752. case "mso-foreground":
  8753. n[i] = "color:" + value;
  8754. continue;
  8755. case "mso-background":
  8756. case "mso-highlight":
  8757. n[i] = "background:" + value;
  8758. continue;
  8759. case "mso-default-height":
  8760. n[i] = "min-height:" +
  8761. transUnit(value);
  8762. continue;
  8763. case "mso-default-width":
  8764. n[i] = "min-width:" +
  8765. transUnit(value);
  8766. continue;
  8767. case "mso-padding-between-alt":
  8768. n[i] = "border-collapse:separate;border-spacing:" +
  8769. transUnit(value);
  8770. continue;
  8771. case "text-line-through":
  8772. if((value == "single") ||
  8773. (value == "double")) {
  8774. n[i] = "text-decoration:line-through";
  8775. }
  8776. continue;
  8777. case "mso-zero-height":
  8778. if(value == "yes") {
  8779. n[i] = "display:none";
  8780. }
  8781. continue;
  8782. // case 'background':
  8783. // break;
  8784. case 'margin':
  8785. if(!/[1-9]/.test(value)) {
  8786. continue;
  8787. }
  8788. }
  8789. if(/^(mso|column|font-emph|lang|layout|line-break|list-image|nav|panose|punct|row|ruby|sep|size|src|tab-|table-border|text-(?:decor|trans)|top-bar|version|vnd|word-break)/
  8790. .test(name) ||
  8791. /text\-indent|padding|margin/
  8792. .test(name) &&
  8793. /\-[\d.]+/.test(value)) {
  8794. continue;
  8795. }
  8796. n[i] = name + ":" + parts[1];
  8797. }
  8798. }
  8799. return tag +
  8800. (n.length ? ' style="' +
  8801. n.join(';').replace(/;{2,}/g,
  8802. ';') + '"' : '');
  8803. })
  8804. }
  8805. return function(html) {
  8806. return(isWordDocument(html) ? filterPasteWord(html) : html);
  8807. };
  8808. }();
  8809. // core/node.js
  8810. /**
  8811. * 编辑器模拟的节点类
  8812. *
  8813. * @file
  8814. * @module UE
  8815. * @class uNode
  8816. * @since 1.2.6.1
  8817. */
  8818. /**
  8819. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  8820. *
  8821. * @unfile
  8822. * @module UE
  8823. */
  8824. (function() {
  8825. /**
  8826. * 编辑器模拟的节点类
  8827. *
  8828. * @unfile
  8829. * @module UE
  8830. * @class uNode
  8831. */
  8832. /**
  8833. * 通过一个键值对,创建一个uNode对象
  8834. *
  8835. * @constructor
  8836. * @param {
  8837. * Object } attr 传入要创建的uNode的初始属性
  8838. * @example ```javascript var node = new uNode({ type:'element',
  8839. * tagName:'span', attrs:{style:'font-size:14px;'} } ```
  8840. */
  8841. var uNode = UE.uNode = function(obj) {
  8842. this.type = obj.type;
  8843. this.data = obj.data;
  8844. this.tagName = obj.tagName;
  8845. this.parentNode = obj.parentNode;
  8846. this.attrs = obj.attrs || {};
  8847. this.children = obj.children;
  8848. };
  8849. var notTransAttrs = {
  8850. 'href': 1,
  8851. 'src': 1,
  8852. '_src': 1,
  8853. '_href': 1,
  8854. 'cdata_data': 1
  8855. };
  8856. var notTransTagName = {
  8857. style: 1,
  8858. script: 1
  8859. };
  8860. var indentChar = ' ',
  8861. breakChar = '\n';
  8862. function insertLine(arr, current, begin) {
  8863. arr.push(breakChar);
  8864. return current + (begin ? 1 : -1);
  8865. }
  8866. function insertIndent(arr, current) {
  8867. // 插入缩进
  8868. for(var i = 0; i < current; i++) {
  8869. arr.push(indentChar);
  8870. }
  8871. }
  8872. // 创建uNode的静态方法
  8873. // 支持标签和html
  8874. uNode.createElement = function(html) {
  8875. if(/[<>]/.test(html)) {
  8876. return UE.htmlparser(html).children[0]
  8877. } else {
  8878. return new uNode({
  8879. type: 'element',
  8880. children: [],
  8881. tagName: html
  8882. })
  8883. }
  8884. };
  8885. uNode.createText = function(data, noTrans) {
  8886. return new UE.uNode({
  8887. type: 'text',
  8888. 'data': noTrans ? data : utils.unhtml(data || '')
  8889. })
  8890. };
  8891. function nodeToHtml(node, arr, formatter, current) {
  8892. switch(node.type) {
  8893. case 'root':
  8894. for(var i = 0, ci; ci = node.children[i++];) {
  8895. // 插入新行
  8896. if(formatter && ci.type == 'element' &&
  8897. !dtd.$inlineWithA[ci.tagName] && i > 1) {
  8898. insertLine(arr, current, true);
  8899. insertIndent(arr, current)
  8900. }
  8901. nodeToHtml(ci, arr, formatter, current)
  8902. }
  8903. break;
  8904. case 'text':
  8905. isText(node, arr);
  8906. break;
  8907. case 'element':
  8908. isElement(node, arr, formatter, current);
  8909. break;
  8910. case 'comment':
  8911. isComment(node, arr, formatter);
  8912. }
  8913. return arr;
  8914. }
  8915. function isText(node, arr) {
  8916. if(node.parentNode.tagName == 'pre') {
  8917. // 源码模式下输入html标签,不能做转换处理,直接输出
  8918. arr.push(node.data)
  8919. } else {
  8920. arr.push(notTransTagName[node.parentNode.tagName] ? utils
  8921. .html(node.data) : node.data.replace(/[ ]{2}/g,
  8922. ' &nbsp;'))
  8923. }
  8924. }
  8925. function isElement(node, arr, formatter, current) {
  8926. var attrhtml = '';
  8927. if(node.attrs) {
  8928. attrhtml = [];
  8929. var attrs = node.attrs;
  8930. for(var a in attrs) {
  8931. // 这里就针对
  8932. // <p>'<img
  8933. // src='http://nsclick.baidu.com/u.gif?&asdf=\"sdf&asdfasdfs;asdf'></p>
  8934. // 这里边的\"做转换,要不用innerHTML直接被截断了,属性src
  8935. // 有可能做的不够
  8936. attrhtml.push(a +
  8937. (attrs[a] !== undefined ?
  8938. '="' +
  8939. (notTransAttrs[a] ? utils
  8940. .html(attrs[a]).replace(
  8941. /["]/g,
  8942. function(a) {
  8943. return '&quot;'
  8944. }) : utils
  8945. .unhtml(attrs[a])) + '"' :
  8946. ''))
  8947. }
  8948. attrhtml = attrhtml.join(' ');
  8949. }
  8950. arr.push('<' + node.tagName + (attrhtml ? ' ' + attrhtml : '') +
  8951. (dtd.$empty[node.tagName] ? '\/' : '') + '>');
  8952. // 插入新行
  8953. if(formatter && !dtd.$inlineWithA[node.tagName] &&
  8954. node.tagName != 'pre') {
  8955. if(node.children && node.children.length) {
  8956. current = insertLine(arr, current, true);
  8957. insertIndent(arr, current)
  8958. }
  8959. }
  8960. if(node.children && node.children.length) {
  8961. for(var i = 0, ci; ci = node.children[i++];) {
  8962. if(formatter && ci.type == 'element' &&
  8963. !dtd.$inlineWithA[ci.tagName] && i > 1) {
  8964. insertLine(arr, current);
  8965. insertIndent(arr, current)
  8966. }
  8967. nodeToHtml(ci, arr, formatter, current)
  8968. }
  8969. }
  8970. if(!dtd.$empty[node.tagName]) {
  8971. if(formatter && !dtd.$inlineWithA[node.tagName] &&
  8972. node.tagName != 'pre') {
  8973. if(node.children && node.children.length) {
  8974. current = insertLine(arr, current);
  8975. insertIndent(arr, current)
  8976. }
  8977. }
  8978. arr.push('<\/' + node.tagName + '>');
  8979. }
  8980. }
  8981. function isComment(node, arr) {
  8982. arr.push('<!--' + node.data + '-->');
  8983. }
  8984. function getNodeById(root, id) {
  8985. var node;
  8986. if(root.type == 'element' && root.getAttr('id') == id) {
  8987. return root;
  8988. }
  8989. if(root.children && root.children.length) {
  8990. for(var i = 0, ci; ci = root.children[i++];) {
  8991. if(node = getNodeById(ci, id)) {
  8992. return node;
  8993. }
  8994. }
  8995. }
  8996. }
  8997. function getNodesByTagName(node, tagName, arr) {
  8998. if(node.type == 'element' && node.tagName == tagName) {
  8999. arr.push(node);
  9000. }
  9001. if(node.children && node.children.length) {
  9002. for(var i = 0, ci; ci = node.children[i++];) {
  9003. getNodesByTagName(ci, tagName, arr)
  9004. }
  9005. }
  9006. }
  9007. function nodeTraversal(root, fn) {
  9008. if(root.children && root.children.length) {
  9009. for(var i = 0, ci; ci = root.children[i];) {
  9010. nodeTraversal(ci, fn);
  9011. // ci被替换的情况,这里就不再走 fn了
  9012. if(ci.parentNode) {
  9013. if(ci.children && ci.children.length) {
  9014. fn(ci)
  9015. }
  9016. if(ci.parentNode)
  9017. i++
  9018. }
  9019. }
  9020. } else {
  9021. fn(root)
  9022. }
  9023. }
  9024. uNode.prototype = {
  9025. /**
  9026. * 当前节点对象,转换成html文本
  9027. *
  9028. * @method toHtml
  9029. * @return { String } 返回转换后的html字符串
  9030. * @example ```javascript node.toHtml(); ```
  9031. */
  9032. /**
  9033. * 当前节点对象,转换成html文本
  9034. *
  9035. * @method toHtml
  9036. * @param {
  9037. * Boolean } formatter 是否格式化返回值
  9038. * @return { String } 返回转换后的html字符串
  9039. * @example ```javascript node.toHtml( true ); ```
  9040. */
  9041. toHtml: function(formatter) {
  9042. var arr = [];
  9043. nodeToHtml(this, arr, formatter, 0);
  9044. return arr.join('')
  9045. },
  9046. /**
  9047. * 获取节点的html内容
  9048. *
  9049. * @method innerHTML
  9050. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  9051. * @return { String } 返回节点的html内容
  9052. * @example ```javascript var htmlstr = node.innerHTML(); ```
  9053. */
  9054. /**
  9055. * 设置节点的html内容
  9056. *
  9057. * @method innerHTML
  9058. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  9059. * @param {
  9060. * String } htmlstr 传入要设置的html内容
  9061. * @return { UE.uNode } 返回节点本身
  9062. * @example ```javascript node.innerHTML('<span>text</span>'); ```
  9063. */
  9064. innerHTML: function(htmlstr) {
  9065. if(this.type != 'element' || dtd.$empty[this.tagName]) {
  9066. return this;
  9067. }
  9068. if(utils.isString(htmlstr)) {
  9069. if(this.children) {
  9070. for(var i = 0, ci; ci = this.children[i++];) {
  9071. ci.parentNode = null;
  9072. }
  9073. }
  9074. this.children = [];
  9075. var tmpRoot = UE.htmlparser(htmlstr);
  9076. for(var i = 0, ci; ci = tmpRoot.children[i++];) {
  9077. this.children.push(ci);
  9078. ci.parentNode = this;
  9079. }
  9080. return this;
  9081. } else {
  9082. var tmpRoot = new UE.uNode({
  9083. type: 'root',
  9084. children: this.children
  9085. });
  9086. return tmpRoot.toHtml();
  9087. }
  9088. },
  9089. /**
  9090. * 获取节点的纯文本内容
  9091. *
  9092. * @method innerText
  9093. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  9094. * @return { String } 返回节点的存文本内容
  9095. * @example ```javascript var textStr = node.innerText(); ```
  9096. */
  9097. /**
  9098. * 设置节点的纯文本内容
  9099. *
  9100. * @method innerText
  9101. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  9102. * @param {
  9103. * String } textStr 传入要设置的文本内容
  9104. * @return { UE.uNode } 返回节点本身
  9105. * @example ```javascript node.innerText('<span>text</span>'); ```
  9106. */
  9107. innerText: function(textStr, noTrans) {
  9108. if(this.type != 'element' || dtd.$empty[this.tagName]) {
  9109. return this;
  9110. }
  9111. if(textStr) {
  9112. if(this.children) {
  9113. for(var i = 0, ci; ci = this.children[i++];) {
  9114. ci.parentNode = null;
  9115. }
  9116. }
  9117. this.children = [];
  9118. this.appendChild(uNode.createText(textStr, noTrans));
  9119. return this;
  9120. } else {
  9121. return this.toHtml().replace(/<[^>]+>/g, '');
  9122. }
  9123. },
  9124. /**
  9125. * 获取当前对象的data属性
  9126. *
  9127. * @method getData
  9128. * @return { Object } 若节点的type值是elemenet,返回空字符串,否则返回节点的data属性
  9129. * @example ```javascript node.getData(); ```
  9130. */
  9131. getData: function() {
  9132. if(this.type == 'element')
  9133. return '';
  9134. return this.data
  9135. },
  9136. /**
  9137. * 获取当前节点下的第一个子节点
  9138. *
  9139. * @method firstChild
  9140. * @return { UE.uNode } 返回第一个子节点
  9141. * @example ```javascript node.firstChild(); //返回第一个子节点 ```
  9142. */
  9143. firstChild: function() {
  9144. // if (this.type != 'element' || dtd.$empty[this.tagName]) {
  9145. // return this;
  9146. // }
  9147. return this.children ? this.children[0] : null;
  9148. },
  9149. /**
  9150. * 获取当前节点下的最后一个子节点
  9151. *
  9152. * @method lastChild
  9153. * @return { UE.uNode } 返回最后一个子节点
  9154. * @example ```javascript node.lastChild(); //返回最后一个子节点 ```
  9155. */
  9156. lastChild: function() {
  9157. // if (this.type != 'element' || dtd.$empty[this.tagName] ) {
  9158. // return this;
  9159. // }
  9160. return this.children ?
  9161. this.children[this.children.length - 1] :
  9162. null;
  9163. },
  9164. /**
  9165. * 获取和当前节点有相同父亲节点的前一个节点
  9166. *
  9167. * @method previousSibling
  9168. * @return { UE.uNode } 返回前一个节点
  9169. * @example ```javascript node.children[2].previousSibling();
  9170. * //返回子节点node.children[1] ```
  9171. */
  9172. previousSibling: function() {
  9173. var parent = this.parentNode;
  9174. for(var i = 0, ci; ci = parent.children[i]; i++) {
  9175. if(ci === this) {
  9176. return i == 0 ? null : parent.children[i - 1];
  9177. }
  9178. }
  9179. },
  9180. /**
  9181. * 获取和当前节点有相同父亲节点的后一个节点
  9182. *
  9183. * @method nextSibling
  9184. * @return { UE.uNode } 返回后一个节点,找不到返回null
  9185. * @example ```javascript node.children[2].nextSibling();
  9186. * //如果有,返回子节点node.children[3] ```
  9187. */
  9188. nextSibling: function() {
  9189. var parent = this.parentNode;
  9190. for(var i = 0, ci; ci = parent.children[i++];) {
  9191. if(ci === this) {
  9192. return parent.children[i];
  9193. }
  9194. }
  9195. },
  9196. /**
  9197. * 用新的节点替换当前节点
  9198. *
  9199. * @method replaceChild
  9200. * @param {
  9201. * UE.uNode } target 要替换成该节点参数
  9202. * @param {
  9203. * UE.uNode } source 要被替换掉的节点
  9204. * @return { UE.uNode } 返回替换之后的节点对象
  9205. * @example ```javascript node.replaceChild(newNode, childNode);
  9206. * //用newNode替换childNode,childNode是node的子节点 ```
  9207. */
  9208. replaceChild: function(target, source) {
  9209. if(this.children) {
  9210. if(target.parentNode) {
  9211. target.parentNode.removeChild(target);
  9212. }
  9213. for(var i = 0, ci; ci = this.children[i]; i++) {
  9214. if(ci === source) {
  9215. this.children.splice(i, 1, target);
  9216. source.parentNode = null;
  9217. target.parentNode = this;
  9218. return target;
  9219. }
  9220. }
  9221. }
  9222. },
  9223. /**
  9224. * 在节点的子节点列表最后位置插入一个节点
  9225. *
  9226. * @method appendChild
  9227. * @param {
  9228. * UE.uNode } node 要插入的节点
  9229. * @return { UE.uNode } 返回刚插入的子节点
  9230. * @example ```javascript node.appendChild( newNode );
  9231. * //在node内插入子节点newNode ```
  9232. */
  9233. appendChild: function(node) {
  9234. if(this.type == 'root' ||
  9235. (this.type == 'element' && !dtd.$empty[this.tagName])) {
  9236. if(!this.children) {
  9237. this.children = []
  9238. }
  9239. if(node.parentNode) {
  9240. node.parentNode.removeChild(node);
  9241. }
  9242. for(var i = 0, ci; ci = this.children[i]; i++) {
  9243. if(ci === node) {
  9244. this.children.splice(i, 1);
  9245. break;
  9246. }
  9247. }
  9248. this.children.push(node);
  9249. node.parentNode = this;
  9250. return node;
  9251. }
  9252. },
  9253. /**
  9254. * 在传入节点的前面插入一个节点
  9255. *
  9256. * @method insertBefore
  9257. * @param {
  9258. * UE.uNode } target 要插入的节点
  9259. * @param {
  9260. * UE.uNode } source 在该参数节点前面插入
  9261. * @return { UE.uNode } 返回刚插入的子节点
  9262. * @example ```javascript node.parentNode.insertBefore(newNode,
  9263. * node); //在node节点后面插入newNode ```
  9264. */
  9265. insertBefore: function(target, source) {
  9266. if(this.children) {
  9267. if(target.parentNode) {
  9268. target.parentNode.removeChild(target);
  9269. }
  9270. for(var i = 0, ci; ci = this.children[i]; i++) {
  9271. if(ci === source) {
  9272. this.children.splice(i, 0, target);
  9273. target.parentNode = this;
  9274. return target;
  9275. }
  9276. }
  9277. }
  9278. },
  9279. /**
  9280. * 在传入节点的后面插入一个节点
  9281. *
  9282. * @method insertAfter
  9283. * @param {
  9284. * UE.uNode } target 要插入的节点
  9285. * @param {
  9286. * UE.uNode } source 在该参数节点后面插入
  9287. * @return { UE.uNode } 返回刚插入的子节点
  9288. * @example ```javascript node.parentNode.insertAfter(newNode,
  9289. * node); //在node节点后面插入newNode ```
  9290. */
  9291. insertAfter: function(target, source) {
  9292. if(this.children) {
  9293. if(target.parentNode) {
  9294. target.parentNode.removeChild(target);
  9295. }
  9296. for(var i = 0, ci; ci = this.children[i]; i++) {
  9297. if(ci === source) {
  9298. this.children.splice(i + 1, 0, target);
  9299. target.parentNode = this;
  9300. return target;
  9301. }
  9302. }
  9303. }
  9304. },
  9305. /**
  9306. * 从当前节点的子节点列表中,移除节点
  9307. *
  9308. * @method removeChild
  9309. * @param {
  9310. * UE.uNode } node 要移除的节点引用
  9311. * @param {
  9312. * Boolean } keepChildren
  9313. * 是否保留移除节点的子节点,若传入true,自动把移除节点的子节点插入到移除的位置
  9314. * @return { * } 返回刚移除的子节点
  9315. * @example ```javascript node.removeChild(childNode,true);
  9316. * //在node的子节点列表中移除child节点,并且吧child的子节点插入到移除的位置 ```
  9317. */
  9318. removeChild: function(node, keepChildren) {
  9319. if(this.children) {
  9320. for(var i = 0, ci; ci = this.children[i]; i++) {
  9321. if(ci === node) {
  9322. this.children.splice(i, 1);
  9323. ci.parentNode = null;
  9324. if(keepChildren && ci.children &&
  9325. ci.children.length) {
  9326. for(var j = 0, cj; cj = ci.children[j]; j++) {
  9327. this.children.splice(i + j, 0, cj);
  9328. cj.parentNode = this;
  9329. }
  9330. }
  9331. return ci;
  9332. }
  9333. }
  9334. }
  9335. },
  9336. /**
  9337. * 获取当前节点所代表的元素属性,即获取attrs对象下的属性值
  9338. *
  9339. * @method getAttr
  9340. * @param {
  9341. * String } attrName 要获取的属性名称
  9342. * @return { * } 返回attrs对象下的属性值
  9343. * @example ```javascript node.getAttr('title'); ```
  9344. */
  9345. getAttr: function(attrName) {
  9346. return this.attrs && this.attrs[attrName.toLowerCase()]
  9347. },
  9348. /**
  9349. * 设置当前节点所代表的元素属性,即设置attrs对象下的属性值
  9350. *
  9351. * @method setAttr
  9352. * @param {
  9353. * String } attrName 要设置的属性名称
  9354. * @param { * }
  9355. * attrVal 要设置的属性值,类型视设置的属性而定
  9356. * @return { * } 返回attrs对象下的属性值
  9357. * @example ```javascript node.setAttr('title','标题'); ```
  9358. */
  9359. setAttr: function(attrName, attrVal) {
  9360. if(!attrName) {
  9361. delete this.attrs;
  9362. return;
  9363. }
  9364. if(!this.attrs) {
  9365. this.attrs = {};
  9366. }
  9367. if(utils.isObject(attrName)) {
  9368. for(var a in attrName) {
  9369. if(!attrName[a]) {
  9370. delete this.attrs[a]
  9371. } else {
  9372. this.attrs[a.toLowerCase()] = attrName[a];
  9373. }
  9374. }
  9375. } else {
  9376. if(!attrVal) {
  9377. delete this.attrs[attrName]
  9378. } else {
  9379. this.attrs[attrName.toLowerCase()] = attrVal;
  9380. }
  9381. }
  9382. },
  9383. /**
  9384. * 获取当前节点在父节点下的位置索引
  9385. *
  9386. * @method getIndex
  9387. * @return { Number } 返回索引数值,如果没有父节点,返回-1
  9388. * @example ```javascript node.getIndex(); ```
  9389. */
  9390. getIndex: function() {
  9391. var parent = this.parentNode;
  9392. for(var i = 0, ci; ci = parent.children[i]; i++) {
  9393. if(ci === this) {
  9394. return i;
  9395. }
  9396. }
  9397. return -1;
  9398. },
  9399. /**
  9400. * 在当前节点下,根据id查找节点
  9401. *
  9402. * @method getNodeById
  9403. * @param {
  9404. * String } id 要查找的id
  9405. * @return { UE.uNode } 返回找到的节点
  9406. * @example ```javascript node.getNodeById('textId'); ```
  9407. */
  9408. getNodeById: function(id) {
  9409. var node;
  9410. if(this.children && this.children.length) {
  9411. for(var i = 0, ci; ci = this.children[i++];) {
  9412. if(node = getNodeById(ci, id)) {
  9413. return node;
  9414. }
  9415. }
  9416. }
  9417. },
  9418. /**
  9419. * 在当前节点下,根据元素名称查找节点列表
  9420. *
  9421. * @method getNodesByTagName
  9422. * @param {
  9423. * String } tagNames 要查找的元素名称
  9424. * @return { Array } 返回找到的节点列表
  9425. * @example ```javascript node.getNodesByTagName('span'); ```
  9426. */
  9427. getNodesByTagName: function(tagNames) {
  9428. tagNames = utils.trim(tagNames).replace(/[ ]{2,}/g, ' ')
  9429. .split(' ');
  9430. var arr = [],
  9431. me = this;
  9432. utils.each(tagNames, function(tagName) {
  9433. if(me.children && me.children.length) {
  9434. for(var i = 0, ci; ci = me.children[i++];) {
  9435. getNodesByTagName(ci, tagName, arr)
  9436. }
  9437. }
  9438. });
  9439. return arr;
  9440. },
  9441. /**
  9442. * 根据样式名称,获取节点的样式值
  9443. *
  9444. * @method getStyle
  9445. * @param {
  9446. * String } name 要获取的样式名称
  9447. * @return { String } 返回样式值
  9448. * @example ```javascript node.getStyle('font-size'); ```
  9449. */
  9450. getStyle: function(name) {
  9451. var cssStyle = this.getAttr('style');
  9452. if(!cssStyle) {
  9453. return ''
  9454. }
  9455. var reg = new RegExp('(^|;)\\s*' + name + ':([^;]+)', 'i');
  9456. var match = cssStyle.match(reg);
  9457. if(match && match[0]) {
  9458. return match[2]
  9459. }
  9460. return '';
  9461. },
  9462. /**
  9463. * 给节点设置样式
  9464. *
  9465. * @method setStyle
  9466. * @param {
  9467. * String } name 要设置的的样式名称
  9468. * @param {
  9469. * String } val 要设置的的样值
  9470. * @example ```javascript node.setStyle('font-size', '12px'); ```
  9471. */
  9472. setStyle: function(name, val) {
  9473. function exec(name, val) {
  9474. var reg = new RegExp('(^|;)\\s*' + name + ':([^;]+;?)',
  9475. 'gi');
  9476. cssStyle = cssStyle.replace(reg, '$1');
  9477. if(val) {
  9478. cssStyle = name + ':' + utils.unhtml(val) + ';' +
  9479. cssStyle
  9480. }
  9481. }
  9482. var cssStyle = this.getAttr('style');
  9483. if(!cssStyle) {
  9484. cssStyle = '';
  9485. }
  9486. if(utils.isObject(name)) {
  9487. for(var a in name) {
  9488. exec(a, name[a])
  9489. }
  9490. } else {
  9491. exec(name, val)
  9492. }
  9493. this.setAttr('style', utils.trim(cssStyle))
  9494. },
  9495. /**
  9496. * 传入一个函数,递归遍历当前节点下的所有节点
  9497. *
  9498. * @method traversal
  9499. * @param {
  9500. * Function } fn 遍历到节点的时,传入节点作为参数,运行此函数
  9501. * @example ```javascript traversal(node, function(){
  9502. * console.log(node.type); }); ```
  9503. */
  9504. traversal: function(fn) {
  9505. if(this.children && this.children.length) {
  9506. nodeTraversal(this, fn);
  9507. }
  9508. return this;
  9509. }
  9510. }
  9511. })();
  9512. // core/htmlparser.js
  9513. /**
  9514. * html字符串转换成uNode节点
  9515. *
  9516. * @file
  9517. * @module UE
  9518. * @since 1.2.6.1
  9519. */
  9520. /**
  9521. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  9522. *
  9523. * @unfile
  9524. * @module UE
  9525. */
  9526. /**
  9527. * html字符串转换成uNode节点的静态方法
  9528. *
  9529. * @method htmlparser
  9530. * @param {
  9531. * String } htmlstr 要转换的html代码
  9532. * @param {
  9533. * Boolean } ignoreBlank 若设置为true,转换的时候忽略\n\r\t等空白字符
  9534. * @return { uNode } 给定的html片段转换形成的uNode对象
  9535. * @example ```javascript var root = UE.htmlparser('
  9536. * <p>
  9537. * <b>htmlparser</b>
  9538. * </p>', true); ```
  9539. */
  9540. var htmlparser = UE.htmlparser = function(htmlstr, ignoreBlank) {
  9541. // todo 原来的方式 [^"'<>\/] 有\/就不能配对上 <TD vAlign=top background=../AAA.JPG>
  9542. // 这样的标签了
  9543. // 先去掉了,加上的原因忘了,这里先记录
  9544. var re_tag = /<(?:(?:\/([^>]+)>)|(?:!--([\S|\s]*?)-->)|(?:([^\s\/<>]+)\s*((?:(?:"[^"]*")|(?:'[^']*')|[^"'<>])*)\/?>))/g,
  9545. re_attr = /([\w\-:.]+)(?:(?:\s*=\s*(?:(?:"([^"]*)")|(?:'([^']*)')|([^\s>]+)))|(?=\s|$))/g;
  9546. // ie下取得的html可能会有\n存在,要去掉,在处理replace(/[\t\r\n]*/g,'');代码高量的\n不能去除
  9547. var allowEmptyTags = {
  9548. b: 1,
  9549. code: 1,
  9550. i: 1,
  9551. u: 1,
  9552. strike: 1,
  9553. s: 1,
  9554. tt: 1,
  9555. strong: 1,
  9556. q: 1,
  9557. samp: 1,
  9558. em: 1,
  9559. span: 1,
  9560. sub: 1,
  9561. img: 1,
  9562. sup: 1,
  9563. font: 1,
  9564. big: 1,
  9565. small: 1,
  9566. iframe: 1,
  9567. a: 1,
  9568. br: 1,
  9569. pre: 1
  9570. };
  9571. htmlstr = htmlstr.replace(new RegExp(domUtils.fillChar, 'g'), '');
  9572. if(!ignoreBlank) {
  9573. htmlstr = htmlstr.replace(new RegExp('[\\r\\t\\n' +
  9574. (ignoreBlank ? '' : ' ') +
  9575. ']*<\/?(\\w+)\\s*(?:[^>]*)>[\\r\\t\\n' +
  9576. (ignoreBlank ? '' : ' ') + ']*', 'g'), function(a, b) {
  9577. // br暂时单独处理
  9578. if(b && allowEmptyTags[b.toLowerCase()]) {
  9579. return a.replace(/(^[\n\r]+)|([\n\r]+$)/g, '');
  9580. }
  9581. return a
  9582. .replace(
  9583. new RegExp('^[\\r\\n' +
  9584. (ignoreBlank ? '' : ' ') + ']+'), '')
  9585. .replace(
  9586. new RegExp('[\\r\\n' + (ignoreBlank ? '' : ' ') +
  9587. ']+$'), '');
  9588. });
  9589. }
  9590. var notTransAttrs = {
  9591. 'href': 1,
  9592. 'src': 1
  9593. };
  9594. var uNode = UE.uNode,
  9595. needParentNode = {
  9596. 'td': 'tr',
  9597. 'tr': ['tbody', 'thead', 'tfoot'],
  9598. 'tbody': 'table',
  9599. 'th': 'tr',
  9600. 'thead': 'table',
  9601. 'tfoot': 'table',
  9602. 'caption': 'table',
  9603. 'li': ['ul', 'ol'],
  9604. 'dt': 'dl',
  9605. 'dd': 'dl',
  9606. 'option': 'select'
  9607. },
  9608. needChild = {
  9609. 'ol': 'li',
  9610. 'ul': 'li'
  9611. };
  9612. function text(parent, data) {
  9613. if(needChild[parent.tagName]) {
  9614. var tmpNode = uNode.createElement(needChild[parent.tagName]);
  9615. parent.appendChild(tmpNode);
  9616. tmpNode.appendChild(uNode.createText(data));
  9617. parent = tmpNode;
  9618. } else {
  9619. parent.appendChild(uNode.createText(data));
  9620. }
  9621. }
  9622. function element(parent, tagName, htmlattr) {
  9623. var needParentTag;
  9624. if(needParentTag = needParentNode[tagName]) {
  9625. var tmpParent = parent,
  9626. hasParent;
  9627. while(tmpParent.type != 'root') {
  9628. if(utils.isArray(needParentTag) ?
  9629. utils.indexOf(needParentTag, tmpParent.tagName) != -1 :
  9630. needParentTag == tmpParent.tagName) {
  9631. parent = tmpParent;
  9632. hasParent = true;
  9633. break;
  9634. }
  9635. tmpParent = tmpParent.parentNode;
  9636. }
  9637. if(!hasParent) {
  9638. parent = element(parent, utils.isArray(needParentTag) ?
  9639. needParentTag[0] :
  9640. needParentTag)
  9641. }
  9642. }
  9643. // 按dtd处理嵌套
  9644. // if(parent.type != 'root' && !dtd[parent.tagName][tagName])
  9645. // parent = parent.parentNode;
  9646. var elm = new uNode({
  9647. parentNode: parent,
  9648. type: 'element',
  9649. tagName: tagName.toLowerCase(),
  9650. // 是自闭合的处理一下
  9651. children: dtd.$empty[tagName] ? null : []
  9652. });
  9653. // 如果属性存在,处理属性
  9654. if(htmlattr) {
  9655. var attrs = {},
  9656. match;
  9657. while(match = re_attr.exec(htmlattr)) {
  9658. attrs[match[1].toLowerCase()] = notTransAttrs[match[1]
  9659. .toLowerCase()] ?
  9660. (match[2] || match[3] || match[4]) :
  9661. utils.unhtml(match[2] || match[3] || match[4])
  9662. }
  9663. elm.attrs = attrs;
  9664. }
  9665. // trace:3970
  9666. // //如果parent下不能放elm
  9667. // if(dtd.$inline[parent.tagName] && dtd.$block[elm.tagName] &&
  9668. // !dtd[parent.tagName][elm.tagName]){
  9669. // parent = parent.parentNode;
  9670. // elm.parentNode = parent;
  9671. // }
  9672. parent.children.push(elm);
  9673. // 如果是自闭合节点返回父亲节点
  9674. return dtd.$empty[tagName] ? parent : elm
  9675. }
  9676. function comment(parent, data) {
  9677. parent.children.push(new uNode({
  9678. type: 'comment',
  9679. data: data,
  9680. parentNode: parent
  9681. }));
  9682. }
  9683. var match, currentIndex = 0,
  9684. nextIndex = 0;
  9685. // 设置根节点
  9686. var root = new uNode({
  9687. type: 'root',
  9688. children: []
  9689. });
  9690. var currentParent = root;
  9691. while(match = re_tag.exec(htmlstr)) {
  9692. currentIndex = match.index;
  9693. try {
  9694. if(currentIndex > nextIndex) {
  9695. // text node
  9696. text(currentParent, htmlstr.slice(nextIndex, currentIndex));
  9697. }
  9698. if(match[3]) {
  9699. if(dtd.$cdata[currentParent.tagName]) {
  9700. text(currentParent, match[0]);
  9701. } else {
  9702. // start tag
  9703. currentParent = element(currentParent, match[3]
  9704. .toLowerCase(), match[4]);
  9705. }
  9706. } else if(match[1]) {
  9707. if(currentParent.type != 'root') {
  9708. if(dtd.$cdata[currentParent.tagName] &&
  9709. !dtd.$cdata[match[1]]) {
  9710. text(currentParent, match[0]);
  9711. } else {
  9712. var tmpParent = currentParent;
  9713. while(currentParent.type == 'element' &&
  9714. currentParent.tagName != match[1]
  9715. .toLowerCase()) {
  9716. currentParent = currentParent.parentNode;
  9717. if(currentParent.type == 'root') {
  9718. currentParent = tmpParent;
  9719. throw 'break'
  9720. }
  9721. }
  9722. // end tag
  9723. currentParent = currentParent.parentNode;
  9724. }
  9725. }
  9726. } else if(match[2]) {
  9727. // comment
  9728. comment(currentParent, match[2])
  9729. }
  9730. } catch(e) {}
  9731. nextIndex = re_tag.lastIndex;
  9732. }
  9733. // 如果结束是文本,就有可能丢掉,所以这里手动判断一下
  9734. // 例如 <li>sdfsdfsdf<li>sdfsdfsdfsdf
  9735. if(nextIndex < htmlstr.length) {
  9736. text(currentParent, htmlstr.slice(nextIndex));
  9737. }
  9738. return root;
  9739. };
  9740. // core/filternode.js
  9741. /**
  9742. * UE过滤节点的静态方法
  9743. *
  9744. * @file
  9745. */
  9746. /**
  9747. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  9748. *
  9749. * @module UE
  9750. */
  9751. /**
  9752. * 根据传入节点和过滤规则过滤相应节点
  9753. *
  9754. * @module UE
  9755. * @since 1.2.6.1
  9756. * @method filterNode
  9757. * @param {
  9758. * Object } root 指定root节点
  9759. * @param {
  9760. * Object } rules 过滤规则json对象
  9761. * @example ```javascript UE.filterNode(root,editor.options.filterRules);
  9762. * ```
  9763. */
  9764. var filterNode = UE.filterNode = function() {
  9765. function filterNode(node, rules) {
  9766. switch(node.type) {
  9767. case 'text':
  9768. break;
  9769. case 'element':
  9770. var val;
  9771. if(val = rules[node.tagName]) {
  9772. if(val === '-') {
  9773. node.parentNode.removeChild(node)
  9774. } else if(utils.isFunction(val)) {
  9775. var parentNode = node.parentNode,
  9776. index = node
  9777. .getIndex();
  9778. val(node);
  9779. if(node.parentNode) {
  9780. if(node.children) {
  9781. for(var i = 0, ci; ci = node.children[i];) {
  9782. filterNode(ci, rules);
  9783. if(ci.parentNode) {
  9784. i++;
  9785. }
  9786. }
  9787. }
  9788. } else {
  9789. for(var i = index, ci; ci = parentNode.children[i];) {
  9790. filterNode(ci, rules);
  9791. if(ci.parentNode) {
  9792. i++;
  9793. }
  9794. }
  9795. }
  9796. } else {
  9797. var attrs = val['$'];
  9798. if(attrs && node.attrs) {
  9799. var tmpAttrs = {},
  9800. tmpVal;
  9801. for(var a in attrs) {
  9802. tmpVal = node.getAttr(a);
  9803. // todo 只先对style单独处理
  9804. if(a == 'style' && utils.isArray(attrs[a])) {
  9805. var tmpCssStyle = [];
  9806. utils.each(attrs[a], function(v) {
  9807. var tmp;
  9808. if(tmp = node.getStyle(v)) {
  9809. tmpCssStyle.push(v + ':' + tmp);
  9810. }
  9811. });
  9812. tmpVal = tmpCssStyle.join(';')
  9813. }
  9814. if(tmpVal) {
  9815. tmpAttrs[a] = tmpVal;
  9816. }
  9817. }
  9818. node.attrs = tmpAttrs;
  9819. }
  9820. if(node.children) {
  9821. for(var i = 0, ci; ci = node.children[i];) {
  9822. filterNode(ci, rules);
  9823. if(ci.parentNode) {
  9824. i++;
  9825. }
  9826. }
  9827. }
  9828. }
  9829. } else {
  9830. // 如果不在名单里扣出子节点并删除该节点,cdata除外
  9831. if(dtd.$cdata[node.tagName]) {
  9832. node.parentNode.removeChild(node)
  9833. } else {
  9834. var parentNode = node.parentNode,
  9835. index = node
  9836. .getIndex();
  9837. node.parentNode.removeChild(node, true);
  9838. for(var i = index, ci; ci = parentNode.children[i];) {
  9839. filterNode(ci, rules);
  9840. if(ci.parentNode) {
  9841. i++;
  9842. }
  9843. }
  9844. }
  9845. }
  9846. break;
  9847. case 'comment':
  9848. node.parentNode.removeChild(node)
  9849. }
  9850. }
  9851. return function(root, rules) {
  9852. if(utils.isEmptyObject(rules)) {
  9853. return root;
  9854. }
  9855. var val;
  9856. if(val = rules['-']) {
  9857. utils.each(val.split(' '), function(k) {
  9858. rules[k] = '-'
  9859. })
  9860. }
  9861. for(var i = 0, ci; ci = root.children[i];) {
  9862. filterNode(ci, rules);
  9863. if(ci.parentNode) {
  9864. i++;
  9865. }
  9866. }
  9867. return root;
  9868. }
  9869. }();
  9870. // core/plugin.js
  9871. /**
  9872. * Created with JetBrains PhpStorm. User: campaign Date: 10/8/13 Time: 6:15
  9873. * PM To change this template use File | Settings | File Templates.
  9874. */
  9875. UE.plugin = function() {
  9876. var _plugins = {};
  9877. return {
  9878. register: function(pluginName, fn, oldOptionName, afterDisabled) {
  9879. if(oldOptionName && utils.isFunction(oldOptionName)) {
  9880. afterDisabled = oldOptionName;
  9881. oldOptionName = null
  9882. }
  9883. _plugins[pluginName] = {
  9884. optionName: oldOptionName || pluginName,
  9885. execFn: fn,
  9886. // 当插件被禁用时执行
  9887. afterDisabled: afterDisabled
  9888. }
  9889. },
  9890. load: function(editor) {
  9891. utils.each(_plugins, function(plugin) {
  9892. var _export = plugin.execFn.call(editor);
  9893. if(editor.options[plugin.optionName] !== false) {
  9894. if(_export) {
  9895. // 后边需要再做扩展
  9896. utils.each(_export, function(v, k) {
  9897. switch(k.toLowerCase()) {
  9898. case 'shortcutkey':
  9899. editor.addshortcutkey(v);
  9900. break;
  9901. case 'bindevents':
  9902. utils.each(v, function(fn, eventName) {
  9903. editor.addListener(eventName, fn);
  9904. });
  9905. break;
  9906. case 'bindmultievents':
  9907. utils.each(utils.isArray(v) ? v : [v],
  9908. function(event) {
  9909. var types = utils
  9910. .trim(event.type)
  9911. .split(/\s+/);
  9912. utils.each(types, function(
  9913. eventName) {
  9914. editor.addListener(
  9915. eventName,
  9916. event.handler);
  9917. });
  9918. });
  9919. break;
  9920. case 'commands':
  9921. utils.each(v,
  9922. function(execFn, execName) {
  9923. editor.commands[execName] = execFn
  9924. });
  9925. break;
  9926. case 'outputrule':
  9927. editor.addOutputRule(v);
  9928. break;
  9929. case 'inputrule':
  9930. editor.addInputRule(v);
  9931. break;
  9932. case 'defaultoptions':
  9933. editor.setOpt(v)
  9934. }
  9935. })
  9936. }
  9937. } else if(plugin.afterDisabled) {
  9938. plugin.afterDisabled.call(editor)
  9939. }
  9940. });
  9941. // 向下兼容
  9942. utils.each(UE.plugins, function(plugin) {
  9943. plugin.call(editor);
  9944. });
  9945. },
  9946. run: function(pluginName, editor) {
  9947. var plugin = _plugins[pluginName];
  9948. if(plugin) {
  9949. plugin.exeFn.call(editor)
  9950. }
  9951. }
  9952. }
  9953. }();
  9954. // core/keymap.js
  9955. var keymap = UE.keymap = {
  9956. 'Backspace': 8,
  9957. 'Tab': 9,
  9958. 'Enter': 13,
  9959. 'Shift': 16,
  9960. 'Control': 17,
  9961. 'Alt': 18,
  9962. 'CapsLock': 20,
  9963. 'Esc': 27,
  9964. 'Spacebar': 32,
  9965. 'PageUp': 33,
  9966. 'PageDown': 34,
  9967. 'End': 35,
  9968. 'Home': 36,
  9969. 'Left': 37,
  9970. 'Up': 38,
  9971. 'Right': 39,
  9972. 'Down': 40,
  9973. 'Insert': 45,
  9974. 'Del': 46,
  9975. 'NumLock': 144,
  9976. 'Cmd': 91,
  9977. '=': 187,
  9978. '-': 189,
  9979. "b": 66,
  9980. 'i': 73,
  9981. // 回退
  9982. 'z': 90,
  9983. 'y': 89,
  9984. // 粘贴
  9985. 'v': 86,
  9986. 'x': 88,
  9987. 's': 83,
  9988. 'n': 78
  9989. };
  9990. // core/localstorage.js
  9991. // 存储媒介封装
  9992. var LocalStorage = UE.LocalStorage = (function() {
  9993. var storage = window.localStorage || getUserData() || null,
  9994. LOCAL_FILE = 'localStorage';
  9995. return {
  9996. saveLocalData: function(key, data) {
  9997. if(storage && data) {
  9998. storage.setItem(key, data);
  9999. return true;
  10000. }
  10001. return false;
  10002. },
  10003. getLocalData: function(key) {
  10004. if(storage) {
  10005. return storage.getItem(key);
  10006. }
  10007. return null;
  10008. },
  10009. removeItem: function(key) {
  10010. storage && storage.removeItem(key);
  10011. }
  10012. };
  10013. function getUserData() {
  10014. var container = document.createElement("div");
  10015. container.style.display = "none";
  10016. if(!container.addBehavior) {
  10017. return null;
  10018. }
  10019. container.addBehavior("#default#userdata");
  10020. return {
  10021. getItem: function(key) {
  10022. var result = null;
  10023. try {
  10024. document.body.appendChild(container);
  10025. container.load(LOCAL_FILE);
  10026. result = container.getAttribute(key);
  10027. document.body.removeChild(container);
  10028. } catch(e) {}
  10029. return result;
  10030. },
  10031. setItem: function(key, value) {
  10032. document.body.appendChild(container);
  10033. container.setAttribute(key, value);
  10034. container.save(LOCAL_FILE);
  10035. document.body.removeChild(container);
  10036. },
  10037. // // 暂时没有用到
  10038. // clear: function () {
  10039. //
  10040. // var expiresTime = new Date();
  10041. // expiresTime.setFullYear(expiresTime.getFullYear() - 1);
  10042. // document.body.appendChild(container);
  10043. // container.expires = expiresTime.toUTCString();
  10044. // container.save(LOCAL_FILE);
  10045. // document.body.removeChild(container);
  10046. //
  10047. // },
  10048. removeItem: function(key) {
  10049. document.body.appendChild(container);
  10050. container.removeAttribute(key);
  10051. container.save(LOCAL_FILE);
  10052. document.body.removeChild(container);
  10053. }
  10054. };
  10055. }
  10056. })();
  10057. (function() {
  10058. var ROOTKEY = 'ueditor_preference';
  10059. UE.Editor.prototype.setPreferences = function(key, value) {
  10060. var obj = {};
  10061. if(utils.isString(key)) {
  10062. obj[key] = value;
  10063. } else {
  10064. obj = key;
  10065. }
  10066. var data = LocalStorage.getLocalData(ROOTKEY);
  10067. if(data && (data = utils.str2json(data))) {
  10068. utils.extend(data, obj);
  10069. } else {
  10070. data = obj;
  10071. }
  10072. data && LocalStorage.saveLocalData(ROOTKEY, utils.json2str(data));
  10073. };
  10074. UE.Editor.prototype.getPreferences = function(key) {
  10075. var data = LocalStorage.getLocalData(ROOTKEY);
  10076. if(data && (data = utils.str2json(data))) {
  10077. return key ? data[key] : data
  10078. }
  10079. return null;
  10080. };
  10081. UE.Editor.prototype.removePreferences = function(key) {
  10082. var data = LocalStorage.getLocalData(ROOTKEY);
  10083. if(data && (data = utils.str2json(data))) {
  10084. data[key] = undefined;
  10085. delete data[key]
  10086. }
  10087. data && LocalStorage.saveLocalData(ROOTKEY, utils.json2str(data));
  10088. };
  10089. })();
  10090. // plugins/defaultfilter.js
  10091. // /import core
  10092. // /plugin 编辑器默认的过滤转换机制
  10093. UE.plugins['defaultfilter'] = function() {
  10094. var me = this;
  10095. me.setOpt({
  10096. 'allowDivTransToP': false,
  10097. 'disabledTableInTable': true
  10098. });
  10099. // 默认的过滤处理
  10100. // 进入编辑器的内容处理
  10101. me.addInputRule(function(root) {
  10102. var allowDivTransToP = this.options.allowDivTransToP;
  10103. var val;
  10104. function tdParent(node) {
  10105. while(node && node.type == 'element') {
  10106. if(node.tagName == 'td') {
  10107. return true;
  10108. }
  10109. node = node.parentNode;
  10110. }
  10111. return false;
  10112. }
  10113. // 进行默认的处理
  10114. root.traversal(function(node) {
  10115. if(node.type == 'element') {
  10116. if(!dtd.$cdata[node.tagName] &&
  10117. me.options.autoClearEmptyNode &&
  10118. dtd.$inline[node.tagName] &&
  10119. !dtd.$empty[node.tagName] &&
  10120. (!node.attrs || utils.isEmptyObject(node.attrs))) {
  10121. if(!node.firstChild())
  10122. node.parentNode.removeChild(node);
  10123. else if(node.tagName == 'span' &&
  10124. (!node.attrs || utils
  10125. .isEmptyObject(node.attrs))) {
  10126. node.parentNode.removeChild(node, true)
  10127. }
  10128. return;
  10129. }
  10130. switch(node.tagName) {
  10131. // case 'style':
  10132. // case 'script':
  10133. // node.setAttr({
  10134. // cdata_tag: node.tagName,
  10135. // cdata_data: (node.innerHTML() || ''),
  10136. // '_ue_custom_node_': 'true'
  10137. // });
  10138. // node.tagName = 'div';
  10139. // node.innerHTML('');
  10140. // break;
  10141. case 'a':
  10142. if(val = node.getAttr('href')) {
  10143. node.setAttr('_href', val)
  10144. }
  10145. break;
  10146. case 'img':
  10147. // todo base64暂时去掉,后边做远程图片上传后,干掉这个
  10148. if(val = node.getAttr('src')) {
  10149. if(/^data:/.test(val)) {
  10150. node.parentNode.removeChild(node);
  10151. break;
  10152. }
  10153. }
  10154. node.setAttr('_src', node.getAttr('src'));
  10155. break;
  10156. case 'span':
  10157. if(browser.webkit &&
  10158. (val = node.getStyle('white-space'))) {
  10159. if(/nowrap|normal/.test(val)) {
  10160. node.setStyle('white-space', '');
  10161. if(me.options.autoClearEmptyNode &&
  10162. utils.isEmptyObject(node.attrs)) {
  10163. node.parentNode.removeChild(node, true)
  10164. }
  10165. }
  10166. }
  10167. val = node.getAttr('id');
  10168. if(val && /^_baidu_bookmark_/i.test(val)) {
  10169. node.parentNode.removeChild(node)
  10170. }
  10171. break;
  10172. case 'p':
  10173. if(val = node.getAttr('align')) {
  10174. node.setAttr('align');
  10175. node.setStyle('text-align', val)
  10176. }
  10177. // trace:3431
  10178. // var cssStyle = node.getAttr('style');
  10179. // if (cssStyle) {
  10180. // cssStyle =
  10181. // cssStyle.replace(/(margin|padding)[^;]+/g, '');
  10182. // node.setAttr('style', cssStyle)
  10183. //
  10184. // }
  10185. // p标签不允许嵌套
  10186. utils.each(node.children, function(n) {
  10187. if(n.type == 'element' && n.tagName == 'p') {
  10188. var next = n.nextSibling();
  10189. node.parentNode.insertAfter(n, node);
  10190. var last = n;
  10191. while(next) {
  10192. var tmp = next.nextSibling();
  10193. node.parentNode.insertAfter(next, last);
  10194. last = next;
  10195. next = tmp;
  10196. }
  10197. return false;
  10198. }
  10199. });
  10200. if(!node.firstChild()) {
  10201. node.innerHTML(browser.ie ? '&nbsp;' : '<br/>')
  10202. }
  10203. break;
  10204. case 'div':
  10205. if(node.getAttr('cdata_tag')) {
  10206. break;
  10207. }
  10208. // 针对代码这里不处理插入代码的div
  10209. val = node.getAttr('class');
  10210. if(val && /^line number\d+/.test(val)) {
  10211. break;
  10212. }
  10213. if(!allowDivTransToP) {
  10214. break;
  10215. }
  10216. var tmpNode, p = UE.uNode.createElement('p');
  10217. while(tmpNode = node.firstChild()) {
  10218. if(tmpNode.type == 'text' ||
  10219. !UE.dom.dtd.$block[tmpNode.tagName]) {
  10220. p.appendChild(tmpNode);
  10221. } else {
  10222. if(p.firstChild()) {
  10223. node.parentNode.insertBefore(p, node);
  10224. p = UE.uNode.createElement('p');
  10225. } else {
  10226. node.parentNode.insertBefore(tmpNode,
  10227. node);
  10228. }
  10229. }
  10230. }
  10231. if(p.firstChild()) {
  10232. node.parentNode.insertBefore(p, node);
  10233. }
  10234. node.parentNode.removeChild(node);
  10235. break;
  10236. case 'dl':
  10237. node.tagName = 'ul';
  10238. break;
  10239. case 'dt':
  10240. case 'dd':
  10241. node.tagName = 'li';
  10242. break;
  10243. case 'li':
  10244. var className = node.getAttr('class');
  10245. if(!className || !/list\-/.test(className)) {
  10246. node.setAttr()
  10247. }
  10248. var tmpNodes = node.getNodesByTagName('ol ul');
  10249. UE.utils.each(tmpNodes, function(n) {
  10250. node.parentNode.insertAfter(n, node);
  10251. });
  10252. break;
  10253. case 'td':
  10254. case 'th':
  10255. case 'caption':
  10256. if(!node.children || !node.children.length) {
  10257. node.appendChild(browser.ie11below ? UE.uNode
  10258. .createText(' ') : UE.uNode
  10259. .createElement('br'))
  10260. }
  10261. break;
  10262. case 'table':
  10263. if(me.options.disabledTableInTable &&
  10264. tdParent(node)) {
  10265. node.parentNode.insertBefore(UE.uNode
  10266. .createText(node.innerText()), node);
  10267. node.parentNode.removeChild(node)
  10268. }
  10269. }
  10270. }
  10271. // if(node.type == 'comment'){
  10272. // node.parentNode.removeChild(node);
  10273. // }
  10274. })
  10275. });
  10276. // 从编辑器出去的内容处理
  10277. me.addOutputRule(function(root) {
  10278. var val;
  10279. root.traversal(function(node) {
  10280. if(node.type == 'element') {
  10281. if(me.options.autoClearEmptyNode &&
  10282. dtd.$inline[node.tagName] &&
  10283. !dtd.$empty[node.tagName] &&
  10284. (!node.attrs || utils.isEmptyObject(node.attrs))) {
  10285. if(!node.firstChild())
  10286. node.parentNode.removeChild(node);
  10287. else if(node.tagName == 'span' &&
  10288. (!node.attrs || utils
  10289. .isEmptyObject(node.attrs))) {
  10290. node.parentNode.removeChild(node, true)
  10291. }
  10292. return;
  10293. }
  10294. switch(node.tagName) {
  10295. case 'div':
  10296. if(val = node.getAttr('cdata_tag')) {
  10297. node.tagName = val;
  10298. node.appendChild(UE.uNode.createText(node
  10299. .getAttr('cdata_data')));
  10300. node.setAttr({
  10301. cdata_tag: '',
  10302. cdata_data: '',
  10303. '_ue_custom_node_': ''
  10304. });
  10305. }
  10306. break;
  10307. case 'a':
  10308. if(val = node.getAttr('_href')) {
  10309. node.setAttr({
  10310. 'href': utils.html(val),
  10311. '_href': ''
  10312. })
  10313. }
  10314. break;
  10315. break;
  10316. case 'span':
  10317. val = node.getAttr('id');
  10318. if(val && /^_baidu_bookmark_/i.test(val)) {
  10319. node.parentNode.removeChild(node)
  10320. }
  10321. break;
  10322. case 'img':
  10323. if(val = node.getAttr('_src')) {
  10324. node.setAttr({
  10325. 'src': node.getAttr('_src'),
  10326. '_src': ''
  10327. })
  10328. }
  10329. }
  10330. }
  10331. })
  10332. });
  10333. };
  10334. // plugins/inserthtml.js
  10335. /**
  10336. * 插入html字符串插件
  10337. *
  10338. * @file
  10339. * @since 1.2.6.1
  10340. */
  10341. /**
  10342. * 插入html代码
  10343. *
  10344. * @command inserthtml
  10345. * @method execCommand
  10346. * @param {
  10347. * String } cmd 命令字符串
  10348. * @param {
  10349. * String } html 插入的html字符串
  10350. * @remaind 插入的标签内容是在当前的选区位置上插入,如果当前是闭合状态,那直接插入内容,
  10351. * 如果当前是选中状态,将先清除当前选中内容后,再做插入
  10352. * @warning 注意:该命令会对当前选区的位置,对插入的内容进行过滤转换处理。 过滤的规则遵循html语意化的原则。
  10353. * @example ```javascript //xxx[BB]xxx 当前选区为非闭合选区,选中BB这两个文本 //执行命令,插入<b>CC</b>
  10354. * //插入后的效果 xxx<b>CC</b>xxx //
  10355. * <p>
  10356. * xx|xxx
  10357. * </p>
  10358. * 当前选区为闭合状态 //插入
  10359. * <p>
  10360. * CC
  10361. * </p>
  10362. * //结果
  10363. * <p>
  10364. * xx
  10365. * </p>
  10366. * <p>
  10367. * CC
  10368. * </p>
  10369. * <p>
  10370. * xxx
  10371. * </p> //
  10372. * <p>
  10373. * xxxx
  10374. * </p>|
  10375. * </p>
  10376. * xxx
  10377. * </p>
  10378. * 当前选区在两个p标签之间 //插入 xxxx //结果
  10379. * <p>
  10380. * xxxx
  10381. * </p>
  10382. * <p>
  10383. * xxxx
  10384. * </p>
  10385. * </p>
  10386. * xxx
  10387. * </p>
  10388. * ```
  10389. */
  10390. UE.commands['showall'] = { // "展开"按钮
  10391. execCommand: function(command) {
  10392. var h = $("#" + this.options.editor.key + " .hideTools");
  10393. var display_ = h.css("display");
  10394. h.css("display", display_ == "none" ? "block" : "none");
  10395. return true;
  10396. },
  10397. queryCommandValue: function(cmdName) {
  10398. return 0;
  10399. },
  10400. quertCommandState: function(cmdName) {
  10401. concole.log(this)
  10402. var checked = (state++ % 2 != 0);
  10403. ui.setclassName = 'edui-for-' + (checked ? "hideall" : cmd);
  10404. }
  10405. };
  10406. UE.commands['inserthtml'] = {
  10407. execCommand: function(command, html, notNeedFilter) {
  10408. var me = this,
  10409. range, div;
  10410. if(!html) {
  10411. return;
  10412. }
  10413. if(me.fireEvent('beforeinserthtml', html) === true) {
  10414. return;
  10415. }
  10416. range = me.selection.getRange();
  10417. div = range.document.createElement('div');
  10418. div.style.display = 'inline';
  10419. if(!notNeedFilter) {
  10420. var root = UE.htmlparser(html);
  10421. // 如果给了过滤规则就先进行过滤
  10422. if(me.options.filterRules) {
  10423. UE.filterNode(root, me.options.filterRules);
  10424. }
  10425. // 执行默认的处理
  10426. me.filterInputRule(root);
  10427. html = root.toHtml()
  10428. }
  10429. div.innerHTML = utils.trim(html);
  10430. if(!range.collapsed) {
  10431. var tmpNode = range.startContainer;
  10432. if(domUtils.isFillChar(tmpNode)) {
  10433. range.setStartBefore(tmpNode)
  10434. }
  10435. tmpNode = range.endContainer;
  10436. if(domUtils.isFillChar(tmpNode)) {
  10437. range.setEndAfter(tmpNode)
  10438. }
  10439. range.txtToElmBoundary();
  10440. // 结束边界可能放到了br的前边,要把br包含进来
  10441. // x[xxx]<br/>
  10442. if(range.endContainer && range.endContainer.nodeType == 1) {
  10443. tmpNode = range.endContainer.childNodes[range.endOffset];
  10444. if(tmpNode && domUtils.isBr(tmpNode)) {
  10445. range.setEndAfter(tmpNode);
  10446. }
  10447. }
  10448. if(range.startOffset == 0) {
  10449. tmpNode = range.startContainer;
  10450. if(domUtils.isBoundaryNode(tmpNode, 'firstChild')) {
  10451. tmpNode = range.endContainer;
  10452. if(range.endOffset == (tmpNode.nodeType == 3 ?
  10453. tmpNode.nodeValue.length :
  10454. tmpNode.childNodes.length) &&
  10455. domUtils
  10456. .isBoundaryNode(tmpNode, 'lastChild')) {
  10457. me.body.innerHTML = '<p>' +
  10458. (browser.ie ? '' : '<br/>') + '</p>';
  10459. range.setStart(me.body.firstChild, 0)
  10460. .collapse(true)
  10461. }
  10462. }
  10463. }!range.collapsed && range.deleteContents();
  10464. if(range.startContainer.nodeType == 1) {
  10465. var child = range.startContainer.childNodes[range.startOffset],
  10466. pre;
  10467. if(child && domUtils.isBlockElm(child) &&
  10468. (pre = child.previousSibling) &&
  10469. domUtils.isBlockElm(pre)) {
  10470. range.setEnd(pre, pre.childNodes.length).collapse();
  10471. while(child.firstChild) {
  10472. pre.appendChild(child.firstChild);
  10473. }
  10474. domUtils.remove(child);
  10475. }
  10476. }
  10477. }
  10478. var child, parent, pre, tmp, hadBreak = 0,
  10479. nextNode;
  10480. // 如果当前位置选中了fillchar要干掉,要不会产生空行
  10481. if(range.inFillChar()) {
  10482. child = range.startContainer;
  10483. if(domUtils.isFillChar(child)) {
  10484. range.setStartBefore(child).collapse(true);
  10485. domUtils.remove(child);
  10486. } else if(domUtils.isFillChar(child, true)) {
  10487. child.nodeValue = child.nodeValue.replace(fillCharReg, '');
  10488. range.startOffset--;
  10489. range.collapsed && range.collapse(true)
  10490. }
  10491. }
  10492. // 列表单独处理
  10493. var li = domUtils.findParentByTagName(range.startContainer, 'li',
  10494. true);
  10495. if(li) {
  10496. var next, last;
  10497. while(child = div.firstChild) {
  10498. // 针对hr单独处理一下先
  10499. while(child &&
  10500. (child.nodeType == 3 ||
  10501. !domUtils.isBlockElm(child) || child.tagName == 'HR')) {
  10502. next = child.nextSibling;
  10503. range.insertNode(child).collapse();
  10504. last = child;
  10505. child = next;
  10506. }
  10507. if(child) {
  10508. if(/^(ol|ul)$/i.test(child.tagName)) {
  10509. while(child.firstChild) {
  10510. last = child.firstChild;
  10511. domUtils.insertAfter(li, child.firstChild);
  10512. li = li.nextSibling;
  10513. }
  10514. domUtils.remove(child)
  10515. } else {
  10516. var tmpLi;
  10517. next = child.nextSibling;
  10518. tmpLi = me.document.createElement('li');
  10519. domUtils.insertAfter(li, tmpLi);
  10520. tmpLi.appendChild(child);
  10521. last = child;
  10522. child = next;
  10523. li = tmpLi;
  10524. }
  10525. }
  10526. }
  10527. li = domUtils.findParentByTagName(range.startContainer, 'li',
  10528. true);
  10529. if(domUtils.isEmptyBlock(li)) {
  10530. domUtils.remove(li)
  10531. }
  10532. if(last) {
  10533. range.setStartAfter(last).collapse(true).select(true)
  10534. }
  10535. } else {
  10536. while(child = div.firstChild) {
  10537. if(hadBreak) {
  10538. var p = me.document.createElement('p');
  10539. while(child &&
  10540. (child.nodeType == 3 || !dtd.$block[child.tagName])) {
  10541. nextNode = child.nextSibling;
  10542. p.appendChild(child);
  10543. child = nextNode;
  10544. }
  10545. if(p.firstChild) {
  10546. child = p
  10547. }
  10548. }
  10549. range.insertNode(child);
  10550. nextNode = child.nextSibling;
  10551. if(!hadBreak && child.nodeType == domUtils.NODE_ELEMENT &&
  10552. domUtils.isBlockElm(child)) {
  10553. parent = domUtils.findParent(child, function(node) {
  10554. return domUtils.isBlockElm(node);
  10555. });
  10556. if(parent &&
  10557. parent.tagName.toLowerCase() != 'body' &&
  10558. !(dtd[parent.tagName][child.nodeName] && child.parentNode === parent)) {
  10559. if(!dtd[parent.tagName][child.nodeName]) {
  10560. pre = parent;
  10561. } else {
  10562. tmp = child.parentNode;
  10563. while(tmp !== parent) {
  10564. pre = tmp;
  10565. tmp = tmp.parentNode;
  10566. }
  10567. }
  10568. domUtils.breakParent(child, pre || tmp);
  10569. // 去掉break后前一个多余的节点 <p>|<[p> ==>
  10570. // <p></p><div></div><p>|</p>
  10571. var pre = child.previousSibling;
  10572. domUtils.trimWhiteTextNode(pre);
  10573. if(!pre.childNodes.length) {
  10574. domUtils.remove(pre);
  10575. }
  10576. // trace:2012,在非ie的情况,切开后剩下的节点有可能不能点入光标添加br占位
  10577. if(!browser.ie && (next = child.nextSibling) &&
  10578. domUtils.isBlockElm(next) &&
  10579. next.lastChild &&
  10580. !domUtils.isBr(next.lastChild)) {
  10581. next.appendChild(me.document
  10582. .createElement('br'));
  10583. }
  10584. hadBreak = 1;
  10585. }
  10586. }
  10587. var next = child.nextSibling;
  10588. if(!div.firstChild && next && domUtils.isBlockElm(next)) {
  10589. range.setStart(next, 0).collapse(true);
  10590. break;
  10591. }
  10592. range.setEndAfter(child).collapse();
  10593. }
  10594. child = range.startContainer;
  10595. if(nextNode && domUtils.isBr(nextNode)) {
  10596. domUtils.remove(nextNode)
  10597. }
  10598. // 用chrome可能有空白展位符
  10599. if(domUtils.isBlockElm(child) && domUtils.isEmptyNode(child)) {
  10600. if(nextNode = child.nextSibling) {
  10601. domUtils.remove(child);
  10602. if(nextNode.nodeType == 1 &&
  10603. dtd.$block[nextNode.tagName]) {
  10604. range.setStart(nextNode, 0).collapse(true)
  10605. .shrinkBoundary()
  10606. }
  10607. } else {
  10608. try {
  10609. child.innerHTML = browser.ie ?
  10610. domUtils.fillChar :
  10611. '<br/>';
  10612. } catch(e) {
  10613. range.setStartBefore(child);
  10614. domUtils.remove(child)
  10615. }
  10616. }
  10617. }
  10618. // 加上true因为在删除表情等时会删两次,第一次是删的fillData
  10619. try {
  10620. range.select(true);
  10621. } catch(e) {}
  10622. }
  10623. setTimeout(function() {
  10624. range = me.selection.getRange();
  10625. range.scrollToView(me.autoHeightEnabled, me.autoHeightEnabled ?
  10626. domUtils.getXY(me.iframe).y :
  10627. 0);
  10628. me.fireEvent('afterinserthtml', html);
  10629. }, 200);
  10630. }
  10631. };
  10632. // plugins/autotypeset.js
  10633. /**
  10634. * 自动排版
  10635. *
  10636. * @file
  10637. * @since 1.2.6.1
  10638. */
  10639. /**
  10640. * 对当前编辑器的内容执行自动排版, 排版的行为根据config配置文件里的“autotypeset”选项进行控制。
  10641. *
  10642. * @command autotypeset
  10643. * @method execCommand
  10644. * @param {
  10645. * String } cmd 命令字符串
  10646. * @example ```javascript editor.execCommand( 'autotypeset' ); ```
  10647. */
  10648. UE.plugins['autotypeset'] = function() {
  10649. this.setOpt({
  10650. 'autotypeset': {
  10651. mergeEmptyline: true, // 合并空行
  10652. removeClass: true, // 去掉冗余的class
  10653. removeEmptyline: false, // 去掉空行
  10654. textAlign: "left", // 段落的排版方式,可以是 left,right,center,justify
  10655. // 去掉这个属性表示不执行排版
  10656. imageBlockLine: 'center', // 图片的浮动方式,独占一行剧中,左右浮动,默认:
  10657. // center,left,right,none
  10658. // 去掉这个属性表示不执行排版
  10659. pasteFilter: false, // 根据规则过滤没事粘贴进来的内容
  10660. clearFontSize: false, // 去掉所有的内嵌字号,使用编辑器默认的字号
  10661. clearFontFamily: false, // 去掉所有的内嵌字体,使用编辑器默认的字体
  10662. removeEmptyNode: false, // 去掉空节点
  10663. // 可以去掉的标签
  10664. removeTagNames: utils.extend({
  10665. div: 1
  10666. }, dtd.$removeEmpty),
  10667. indent: false, // 行首缩进
  10668. indentValue: '2em', // 行首缩进的大小
  10669. bdc2sb: false,
  10670. tobdc: false
  10671. }
  10672. });
  10673. var me = this,
  10674. opt = me.options.autotypeset,
  10675. remainClass = {
  10676. 'selectTdClass': 1,
  10677. 'pagebreak': 1,
  10678. 'anchorclass': 1
  10679. },
  10680. remainTag = {
  10681. 'li': 1
  10682. },
  10683. tags = {
  10684. div: 1,
  10685. p: 1,
  10686. // trace:2183 这些也认为是行
  10687. blockquote: 1,
  10688. center: 1,
  10689. h1: 1,
  10690. h2: 1,
  10691. h3: 1,
  10692. h4: 1,
  10693. h5: 1,
  10694. h6: 1,
  10695. span: 1
  10696. },
  10697. highlightCont;
  10698. // 升级了版本,但配置项目里没有autotypeset
  10699. if(!opt) {
  10700. return;
  10701. }
  10702. readLocalOpts();
  10703. function isLine(node, notEmpty) {
  10704. if(!node || node.nodeType == 3)
  10705. return 0;
  10706. if(domUtils.isBr(node))
  10707. return 1;
  10708. if(node && node.parentNode && tags[node.tagName.toLowerCase()]) {
  10709. if(highlightCont && highlightCont.contains(node) ||
  10710. node.getAttribute('pagebreak')) {
  10711. return 0;
  10712. }
  10713. return notEmpty ? !domUtils.isEmptyBlock(node) : domUtils
  10714. .isEmptyBlock(node, new RegExp('[\\s' +
  10715. domUtils.fillChar + ']', 'g'));
  10716. }
  10717. }
  10718. function removeNotAttributeSpan(node) {
  10719. if(!node.style.cssText) {
  10720. domUtils.removeAttributes(node, ['style']);
  10721. if(node.tagName.toLowerCase() == 'span' &&
  10722. domUtils.hasNoAttributes(node)) {
  10723. domUtils.remove(node, true);
  10724. }
  10725. }
  10726. }
  10727. function autotype(type, html) {
  10728. var me = this,
  10729. cont;
  10730. if(html) {
  10731. if(!opt.pasteFilter) {
  10732. return;
  10733. }
  10734. cont = me.document.createElement('div');
  10735. cont.innerHTML = html.html;
  10736. } else {
  10737. cont = me.document.body;
  10738. }
  10739. var nodes = domUtils.getElementsByTagName(cont, '*');
  10740. // 行首缩进,段落方向,段间距,段内间距
  10741. for(var i = 0, ci; ci = nodes[i++];) {
  10742. if(me.fireEvent('excludeNodeinautotype', ci) === true) {
  10743. continue;
  10744. }
  10745. // font-size
  10746. if(opt.clearFontSize && ci.style.fontSize) {
  10747. domUtils.removeStyle(ci, 'font-size');
  10748. removeNotAttributeSpan(ci);
  10749. }
  10750. // font-family
  10751. if(opt.clearFontFamily && ci.style.fontFamily) {
  10752. domUtils.removeStyle(ci, 'font-family');
  10753. removeNotAttributeSpan(ci);
  10754. }
  10755. if(isLine(ci)) {
  10756. // 合并空行
  10757. if(opt.mergeEmptyline) {
  10758. var next = ci.nextSibling,
  10759. tmpNode, isBr = domUtils
  10760. .isBr(ci);
  10761. while(isLine(next)) {
  10762. tmpNode = next;
  10763. next = tmpNode.nextSibling;
  10764. if(isBr && (!next || next && !domUtils.isBr(next))) {
  10765. break;
  10766. }
  10767. domUtils.remove(tmpNode);
  10768. }
  10769. }
  10770. // 去掉空行,保留占位的空行
  10771. if(opt.removeEmptyline && domUtils.inDoc(ci, cont) &&
  10772. !remainTag[ci.parentNode.tagName.toLowerCase()]) {
  10773. if(domUtils.isBr(ci)) {
  10774. next = ci.nextSibling;
  10775. if(next && !domUtils.isBr(next)) {
  10776. continue;
  10777. }
  10778. }
  10779. domUtils.remove(ci);
  10780. continue;
  10781. }
  10782. }
  10783. if(isLine(ci, true) && ci.tagName != 'SPAN') {
  10784. if(opt.indent) {
  10785. ci.style.textIndent = opt.indentValue;
  10786. }
  10787. if(opt.textAlign) {
  10788. ci.style.textAlign = opt.textAlign;
  10789. }
  10790. // if(opt.lineHeight)
  10791. // ci.style.lineHeight = opt.lineHeight + 'cm';
  10792. }
  10793. // 去掉class,保留的class不去掉
  10794. if(opt.removeClass && ci.className &&
  10795. !remainClass[ci.className.toLowerCase()]) {
  10796. if(highlightCont && highlightCont.contains(ci)) {
  10797. continue;
  10798. }
  10799. domUtils.removeAttributes(ci, ['class']);
  10800. }
  10801. // 表情不处理
  10802. if(opt.imageBlockLine && ci.tagName.toLowerCase() == 'img' &&
  10803. !ci.getAttribute('emotion')) {
  10804. if(html) {
  10805. var img = ci;
  10806. switch(opt.imageBlockLine) {
  10807. case 'left':
  10808. case 'right':
  10809. case 'none':
  10810. var pN = img.parentNode,
  10811. tmpNode, pre, next;
  10812. while(dtd.$inline[pN.tagName] ||
  10813. pN.tagName == 'A') {
  10814. pN = pN.parentNode;
  10815. }
  10816. tmpNode = pN;
  10817. if(tmpNode.tagName == 'P' &&
  10818. domUtils.getStyle(tmpNode,
  10819. 'text-align') == 'center') {
  10820. if(!domUtils.isBody(tmpNode) &&
  10821. domUtils.getChildCount(tmpNode,
  10822. function(node) {
  10823. return !domUtils
  10824. .isBr(node) &&
  10825. !domUtils
  10826. .isWhitespace(node)
  10827. }) == 1) {
  10828. pre = tmpNode.previousSibling;
  10829. next = tmpNode.nextSibling;
  10830. if(pre && next && pre.nodeType == 1 &&
  10831. next.nodeType == 1 &&
  10832. pre.tagName == next.tagName &&
  10833. domUtils.isBlockElm(pre)) {
  10834. pre.appendChild(tmpNode.firstChild);
  10835. while(next.firstChild) {
  10836. pre
  10837. .appendChild(next.firstChild);
  10838. }
  10839. domUtils.remove(tmpNode);
  10840. domUtils.remove(next);
  10841. } else {
  10842. domUtils.setStyle(tmpNode,
  10843. 'text-align', '');
  10844. }
  10845. }
  10846. }
  10847. domUtils.setStyle(img, 'float',
  10848. opt.imageBlockLine);
  10849. break;
  10850. case 'center':
  10851. if(me.queryCommandValue('imagefloat') != 'center') {
  10852. pN = img.parentNode;
  10853. domUtils.setStyle(img, 'float', 'none');
  10854. tmpNode = img;
  10855. while(pN &&
  10856. domUtils.getChildCount(pN,
  10857. function(node) {
  10858. return !domUtils
  10859. .isBr(node) &&
  10860. !domUtils
  10861. .isWhitespace(node)
  10862. }) == 1 &&
  10863. (dtd.$inline[pN.tagName] || pN.tagName == 'A')) {
  10864. tmpNode = pN;
  10865. pN = pN.parentNode;
  10866. }
  10867. var pNode = me.document.createElement('p');
  10868. domUtils.setAttributes(pNode, {
  10869. style: 'text-align:center'
  10870. });
  10871. tmpNode.parentNode.insertBefore(pNode,
  10872. tmpNode);
  10873. pNode.appendChild(tmpNode);
  10874. domUtils.setStyle(tmpNode, 'float', '');
  10875. }
  10876. }
  10877. } else {
  10878. var range = me.selection.getRange();
  10879. range.selectNode(ci).select();
  10880. me.execCommand('imagefloat', opt.imageBlockLine);
  10881. }
  10882. }
  10883. // 去掉冗余的标签
  10884. if(opt.removeEmptyNode) {
  10885. if(opt.removeTagNames[ci.tagName.toLowerCase()] &&
  10886. domUtils.hasNoAttributes(ci) &&
  10887. domUtils.isEmptyBlock(ci)) {
  10888. domUtils.remove(ci);
  10889. }
  10890. }
  10891. }
  10892. if(opt.tobdc) {
  10893. var root = UE.htmlparser(cont.innerHTML);
  10894. root.traversal(function(node) {
  10895. if(node.type == 'text') {
  10896. node.data = ToDBC(node.data)
  10897. }
  10898. });
  10899. cont.innerHTML = root.toHtml()
  10900. }
  10901. if(opt.bdc2sb) {
  10902. var root = UE.htmlparser(cont.innerHTML);
  10903. root.traversal(function(node) {
  10904. if(node.type == 'text') {
  10905. node.data = DBC2SB(node.data)
  10906. }
  10907. });
  10908. cont.innerHTML = root.toHtml()
  10909. }
  10910. if(html) {
  10911. html.html = cont.innerHTML;
  10912. }
  10913. }
  10914. if(opt.pasteFilter) {
  10915. me.addListener('beforepaste', autotype);
  10916. }
  10917. function DBC2SB(str) {
  10918. var result = '';
  10919. for(var i = 0; i < str.length; i++) {
  10920. var code = str.charCodeAt(i); // 获取当前字符的unicode编码
  10921. if(code >= 65281 && code <= 65373) // 在这个unicode编码范围中的是所有的英文字母已经各种字符
  10922. {
  10923. result += String.fromCharCode(str.charCodeAt(i) - 65248); // 把全角字符的unicode编码转换为对应半角字符的unicode码
  10924. } else if(code == 12288) // 空格
  10925. {
  10926. result += String.fromCharCode(str.charCodeAt(i) - 12288 +
  10927. 32);
  10928. } else {
  10929. result += str.charAt(i);
  10930. }
  10931. }
  10932. return result;
  10933. }
  10934. function ToDBC(txtstring) {
  10935. txtstring = utils.html(txtstring);
  10936. var tmp = "";
  10937. var mark = ""; /* 用于判断,如果是html尖括里的标记,则不进行全角的转换 */
  10938. for(var i = 0; i < txtstring.length; i++) {
  10939. if(txtstring.charCodeAt(i) == 32) {
  10940. tmp = tmp + String.fromCharCode(12288);
  10941. } else if(txtstring.charCodeAt(i) < 127) {
  10942. tmp = tmp +
  10943. String.fromCharCode(txtstring.charCodeAt(i) +
  10944. 65248);
  10945. } else {
  10946. tmp += txtstring.charAt(i);
  10947. }
  10948. }
  10949. return tmp;
  10950. }
  10951. function readLocalOpts() {
  10952. var cookieOpt = me.getPreferences('autotypeset');
  10953. utils.extend(me.options.autotypeset, cookieOpt);
  10954. }
  10955. me.commands['autotypeset'] = {
  10956. execCommand: function() {
  10957. me.removeListener('beforepaste', autotype);
  10958. if(opt.pasteFilter) {
  10959. me.addListener('beforepaste', autotype);
  10960. }
  10961. autotype.call(me)
  10962. }
  10963. };
  10964. };
  10965. // plugins/autosubmit.js
  10966. /**
  10967. * 快捷键提交
  10968. *
  10969. * @file
  10970. * @since 1.2.6.1
  10971. */
  10972. /**
  10973. * 提交表单
  10974. *
  10975. * @command autosubmit
  10976. * @method execCommand
  10977. * @param {
  10978. * String } cmd 命令字符串
  10979. * @example ```javascript editor.execCommand( 'autosubmit' ); ```
  10980. */
  10981. UE.plugin.register('autosubmit', function() {
  10982. return {
  10983. shortcutkey: {
  10984. "autosubmit": "ctrl+13" // 手动提交
  10985. },
  10986. commands: {
  10987. 'autosubmit': {
  10988. execCommand: function() {
  10989. var me = this,
  10990. form = domUtils.findParentByTagName(
  10991. me.iframe, "form", false);
  10992. if(form) {
  10993. if(me.fireEvent("beforesubmit") === false) {
  10994. return;
  10995. }
  10996. me.sync();
  10997. form.submit();
  10998. }
  10999. }
  11000. }
  11001. }
  11002. }
  11003. });
  11004. // plugins/background.js
  11005. /**
  11006. * 背景插件,为UEditor提供设置背景功能
  11007. *
  11008. * @file
  11009. * @since 1.2.6.1
  11010. */
  11011. UE.plugin.register('background', function() {
  11012. var me = this,
  11013. cssRuleId = 'editor_background',
  11014. isSetColored, reg = new RegExp(
  11015. 'body[\\s]*\\{(.+)\\}', 'i');
  11016. function stringToObj(str) {
  11017. var obj = {},
  11018. styles = str.split(';');
  11019. utils.each(styles, function(v) {
  11020. var index = v.indexOf(':'),
  11021. key = utils
  11022. .trim(v.substr(0, index)).toLowerCase();
  11023. key && (obj[key] = utils.trim(v.substr(index + 1) || ''));
  11024. });
  11025. return obj;
  11026. }
  11027. function setBackground(obj) {
  11028. if(obj) {
  11029. var styles = [];
  11030. for(var name in obj) {
  11031. if(obj.hasOwnProperty(name)) {
  11032. styles.push(name + ":" + obj[name] + '; ');
  11033. }
  11034. }
  11035. utils.cssRule(cssRuleId, styles.length ? ('body{' +
  11036. styles.join("") + '}') : '', me.document);
  11037. } else {
  11038. utils.cssRule(cssRuleId, '', me.document)
  11039. }
  11040. }
  11041. // 重写editor.hasContent方法
  11042. var orgFn = me.hasContents;
  11043. me.hasContents = function() {
  11044. if(me.queryCommandValue('background')) {
  11045. return true
  11046. }
  11047. return orgFn.apply(me, arguments);
  11048. };
  11049. return {
  11050. bindEvents: {
  11051. 'getAllHtml': function(type, headHtml) {
  11052. var body = this.body,
  11053. su = domUtils.getComputedStyle(body,
  11054. "background-image"),
  11055. url = "";
  11056. if(su.indexOf(me.options.imagePath) > 0) {
  11057. url = su.substring(su.indexOf(me.options.imagePath),
  11058. su.length - 1).replace(/"|\(|\)/ig, "");
  11059. } else {
  11060. url = su != "none" ?
  11061. su.replace(/url\("?|"?\)/ig, "") :
  11062. "";
  11063. }
  11064. var html = '<style type="text/css">body{';
  11065. var bgObj = {
  11066. "background-color": domUtils.getComputedStyle(body,
  11067. "background-color") ||
  11068. "#ffffff",
  11069. 'background-image': url ? 'url(' + url + ')' : '',
  11070. 'background-repeat': domUtils.getComputedStyle(body,
  11071. "background-repeat") ||
  11072. "",
  11073. 'background-position': browser.ie ?
  11074. (domUtils.getComputedStyle(body,
  11075. "background-position-x") +
  11076. " " + domUtils.getComputedStyle(body,
  11077. "background-position-y")) : domUtils.getComputedStyle(body,
  11078. "background-position"),
  11079. 'height': domUtils.getComputedStyle(body, "height")
  11080. };
  11081. for(var name in bgObj) {
  11082. if(bgObj.hasOwnProperty(name)) {
  11083. html += name + ":" + bgObj[name] + "; ";
  11084. }
  11085. }
  11086. html += '}</style> ';
  11087. headHtml.push(html);
  11088. },
  11089. 'aftersetcontent': function() {
  11090. if(isSetColored == false)
  11091. setBackground();
  11092. }
  11093. },
  11094. inputRule: function(root) {
  11095. isSetColored = false;
  11096. utils.each(root.getNodesByTagName('p'), function(p) {
  11097. var styles = p.getAttr('data-background');
  11098. if(styles) {
  11099. isSetColored = true;
  11100. setBackground(stringToObj(styles));
  11101. p.parentNode.removeChild(p);
  11102. }
  11103. })
  11104. },
  11105. outputRule: function(root) {
  11106. var me = this,
  11107. styles = (utils.cssRule(cssRuleId, me.document) || '')
  11108. .replace(/[\n\r]+/g, '').match(reg);
  11109. if(styles) {
  11110. root
  11111. .appendChild(UE.uNode
  11112. .createElement('<p style="display:none;" data-background="' +
  11113. utils.trim(styles[1].replace(
  11114. /"/g, '').replace(/[\s]+/g,
  11115. ' ')) + '"><br/></p>'));
  11116. }
  11117. },
  11118. commands: {
  11119. 'background': {
  11120. execCommand: function(cmd, obj) {
  11121. setBackground(obj);
  11122. },
  11123. queryCommandValue: function() {
  11124. var me = this,
  11125. styles = (utils.cssRule(cssRuleId,
  11126. me.document) || '').replace(/[\n\r]+/g, '')
  11127. .match(reg);
  11128. return styles ? stringToObj(styles[1]) : null;
  11129. },
  11130. notNeedUndo: true
  11131. }
  11132. }
  11133. }
  11134. });
  11135. // plugins/image.js
  11136. /**
  11137. * 图片插入、排版插件
  11138. *
  11139. * @file
  11140. * @since 1.2.6.1
  11141. */
  11142. /**
  11143. * 图片对齐方式
  11144. *
  11145. * @command imagefloat
  11146. * @method execCommand
  11147. * @remind 值center为独占一行居中
  11148. * @param {
  11149. * String } cmd 命令字符串
  11150. * @param {
  11151. * String } align 对齐方式,可传left、right、none、center
  11152. * @remaind center表示图片独占一行
  11153. * @example ```javascript editor.execCommand( 'imagefloat', 'center' ); ```
  11154. */
  11155. /**
  11156. * 如果选区所在位置是图片区域
  11157. *
  11158. * @command imagefloat
  11159. * @method queryCommandValue
  11160. * @param {
  11161. * String } cmd 命令字符串
  11162. * @return { String } 返回图片对齐方式
  11163. * @example ```javascript editor.queryCommandValue( 'imagefloat' ); ```
  11164. */
  11165. UE.commands['imagefloat'] = {
  11166. execCommand: function(cmd, align) {
  11167. var me = this,
  11168. range = me.selection.getRange();
  11169. if(!range.collapsed) {
  11170. var img = range.getClosedNode();
  11171. if(img && img.tagName == 'IMG') {
  11172. switch(align) {
  11173. case 'left':
  11174. case 'right':
  11175. case 'none':
  11176. var pN = img.parentNode,
  11177. tmpNode, pre, next;
  11178. while(dtd.$inline[pN.tagName] || pN.tagName == 'A') {
  11179. pN = pN.parentNode;
  11180. }
  11181. tmpNode = pN;
  11182. if(tmpNode.tagName == 'P' &&
  11183. domUtils.getStyle(tmpNode, 'text-align') == 'center') {
  11184. if(!domUtils.isBody(tmpNode) &&
  11185. domUtils.getChildCount(tmpNode,
  11186. function(node) {
  11187. return !domUtils.isBr(node) &&
  11188. !domUtils
  11189. .isWhitespace(node);
  11190. }) == 1) {
  11191. pre = tmpNode.previousSibling;
  11192. next = tmpNode.nextSibling;
  11193. if(pre && next && pre.nodeType == 1 &&
  11194. next.nodeType == 1 &&
  11195. pre.tagName == next.tagName &&
  11196. domUtils.isBlockElm(pre)) {
  11197. pre.appendChild(tmpNode.firstChild);
  11198. while(next.firstChild) {
  11199. pre.appendChild(next.firstChild);
  11200. }
  11201. domUtils.remove(tmpNode);
  11202. domUtils.remove(next);
  11203. } else {
  11204. domUtils.setStyle(tmpNode,
  11205. 'text-align', '');
  11206. }
  11207. }
  11208. range.selectNode(img).select();
  11209. }
  11210. domUtils.setStyle(img, 'float', align == 'none' ?
  11211. '' :
  11212. align);
  11213. if(align == 'none') {
  11214. domUtils.removeAttributes(img, 'align');
  11215. }
  11216. break;
  11217. case 'center':
  11218. if(me.queryCommandValue('imagefloat') != 'center') {
  11219. pN = img.parentNode;
  11220. domUtils.setStyle(img, 'float', '');
  11221. domUtils.removeAttributes(img, 'align');
  11222. tmpNode = img;
  11223. while(pN &&
  11224. domUtils.getChildCount(pN, function(
  11225. node) {
  11226. return !domUtils.isBr(node) &&
  11227. !domUtils
  11228. .isWhitespace(node);
  11229. }) == 1 &&
  11230. (dtd.$inline[pN.tagName] || pN.tagName == 'A')) {
  11231. tmpNode = pN;
  11232. pN = pN.parentNode;
  11233. }
  11234. range.setStartBefore(tmpNode).setCursor(false);
  11235. pN = me.document.createElement('div');
  11236. pN.appendChild(tmpNode);
  11237. domUtils.setStyle(tmpNode, 'float', '');
  11238. me.execCommand('insertHtml',
  11239. '<p id="_img_parent_tmp" style="text-align:center">' +
  11240. pN.innerHTML + '</p>');
  11241. tmpNode = me.document
  11242. .getElementById('_img_parent_tmp');
  11243. tmpNode.removeAttribute('id');
  11244. tmpNode = tmpNode.firstChild;
  11245. range.selectNode(tmpNode).select();
  11246. // 去掉后边多余的元素
  11247. next = tmpNode.parentNode.nextSibling;
  11248. if(next && domUtils.isEmptyNode(next)) {
  11249. domUtils.remove(next);
  11250. }
  11251. }
  11252. break;
  11253. }
  11254. }
  11255. }
  11256. },
  11257. queryCommandValue: function() {
  11258. var range = this.selection.getRange(),
  11259. startNode, floatStyle;
  11260. if(range.collapsed) {
  11261. return 'none';
  11262. }
  11263. startNode = range.getClosedNode();
  11264. if(startNode && startNode.nodeType == 1 &&
  11265. startNode.tagName == 'IMG') {
  11266. floatStyle = domUtils.getComputedStyle(startNode, 'float') ||
  11267. startNode.getAttribute('align');
  11268. if(floatStyle == 'none') {
  11269. floatStyle = domUtils.getComputedStyle(
  11270. startNode.parentNode, 'text-align') == 'center' ?
  11271. 'center' :
  11272. floatStyle;
  11273. }
  11274. return {
  11275. left: 1,
  11276. right: 1,
  11277. center: 1
  11278. }[floatStyle] ? floatStyle: 'none';
  11279. }
  11280. return 'none';
  11281. },
  11282. queryCommandState: function() {
  11283. var range = this.selection.getRange(),
  11284. startNode;
  11285. if(range.collapsed)
  11286. return -1;
  11287. startNode = range.getClosedNode();
  11288. if(startNode && startNode.nodeType == 1 &&
  11289. startNode.tagName == 'IMG') {
  11290. return 0;
  11291. }
  11292. return -1;
  11293. }
  11294. };
  11295. /**
  11296. * 插入图片
  11297. *
  11298. * @command insertimage
  11299. * @method execCommand
  11300. * @param {
  11301. * String } cmd 命令字符串
  11302. * @param {
  11303. * Object } opt 属性键值对,这些属性都将被复制到当前插入图片
  11304. * @remind 该命令第二个参数可接受一个图片配置项对象的数组,可以插入多张图片, 此时数组的每一个元素都是一个Object类型的图片属性集合。
  11305. * @example ```javascript editor.execCommand( 'insertimage', {
  11306. * src:'a/b/c.jpg', width:'100', height:'100' } ); ```
  11307. * @example ```javascript editor.execCommand( 'insertimage', [{
  11308. * src:'a/b/c.jpg', width:'100', height:'100' },{ src:'a/b/d.jpg',
  11309. * width:'100', height:'100' }] ); ```
  11310. */
  11311. UE.commands['insertimage'] = {
  11312. execCommand: function(cmd, opt) {
  11313. opt = utils.isArray(opt) ? opt : [opt];
  11314. if(!opt.length) {
  11315. return;
  11316. }
  11317. var me = this,
  11318. range = me.selection.getRange(),
  11319. img = range
  11320. .getClosedNode();
  11321. if(me.fireEvent('beforeinsertimage', opt) === true) {
  11322. return;
  11323. }
  11324. if(img &&
  11325. /img/i.test(img.tagName) &&
  11326. (img.className != "edui-faked-video" || img.className
  11327. .indexOf("edui-upload-video") != -1) &&
  11328. !img.getAttribute("word_img")) {
  11329. var first = opt.shift();
  11330. var floatStyle = first['floatStyle'];
  11331. delete first['floatStyle'];
  11332. // // img.style.border = (first.border||0) +"px solid #000";
  11333. // // img.style.margin = (first.margin||0) +"px";
  11334. // img.style.cssText += ';margin:' + (first.margin||0) +"px;" +
  11335. // 'border:' + (first.border||0) +"px solid #000";
  11336. domUtils.setAttributes(img, first);
  11337. me.execCommand('imagefloat', floatStyle);
  11338. if(opt.length > 0) {
  11339. range.setStartAfter(img).setCursor(false, true);
  11340. me.execCommand('insertimage', opt);
  11341. }
  11342. } else {
  11343. var html = [],
  11344. str = '',
  11345. ci;
  11346. ci = opt[0];
  11347. if(opt.length == 1) {//插入图片
  11348. str = '<img src="' +
  11349. ci.tokenURL +
  11350. '" ' +
  11351. " tokentag='" + (ci.istokentag ? true : false) + "' srcAttrName='11src' " +
  11352. (ci.tokenURL ? ' _src="' + ci.tokenURL + '" ' : '') +
  11353. (ci.width ? 'width="' + ci.width + '" ' : '') +
  11354. (ci.height ? ' height="' + ci.height + '" ' : '') +
  11355. (ci['floatStyle'] == 'left' ||
  11356. ci['floatStyle'] == 'right' ?
  11357. ' style="float:' + ci['floatStyle'] +
  11358. ';"' :
  11359. '') +
  11360. (ci.title && ci.title != "" ? ' title="' +
  11361. ci.title + '"' : '') +
  11362. (ci.border && ci.border != "0" ? ' border="' +
  11363. ci.border + '"' : '') +
  11364. (ci.alt && ci.alt != "" ?
  11365. ' alt="' + ci.alt + '"' :
  11366. '') +
  11367. (ci.hspace && ci.hspace != "0" ? ' hspace = "' +
  11368. ci.hspace + '"' : '') +
  11369. (ci.vspace && ci.vspace != "0" ? ' vspace = "' +
  11370. ci.vspace + '"' : '') + '/>';
  11371. if(ci['floatStyle'] == 'center') {
  11372. str = '<p style="text-align: center">' + str + '</p>';
  11373. }
  11374. html.push(str);
  11375. } else {
  11376. for(var i = 0; ci = opt[i++];) {
  11377. str = '<p ' +
  11378. (ci['floatStyle'] == 'center' ?
  11379. 'style="text-align: center" ' :
  11380. '') +
  11381. '><img src="' +
  11382. ci.tokenURL +
  11383. '" ' + "tokentag='" + (ci.istokentag ? true : false) + "' srcAttrName='src' " +
  11384. (ci.width ? 'width="' + ci.width + '" ' : '') +
  11385. (ci.tokenURL ? ' _src="' + ci.tokenURL + '" ' : '') +
  11386. (ci.height ?
  11387. ' height="' + ci.height + '" ' :
  11388. '') +
  11389. ' style="' +
  11390. (ci['floatStyle'] &&
  11391. ci['floatStyle'] != 'center' ?
  11392. 'float:' + ci['floatStyle'] + ';' :
  11393. '') + (ci.border || '') + '" ' +
  11394. (ci.title ? ' title="' + ci.title + '"' : '') +
  11395. ' /></p>';
  11396. html.push(str);
  11397. }
  11398. }
  11399. me.execCommand('insertHtml', html.join(''));
  11400. }
  11401. me.fireEvent('afterinsertimage', opt)
  11402. }
  11403. };
  11404. // plugins/justify.js
  11405. /**
  11406. * 段落格式
  11407. *
  11408. * @file
  11409. * @since 1.2.6.1
  11410. */
  11411. /**
  11412. * 段落对齐方式
  11413. *
  11414. * @command justify
  11415. * @method execCommand
  11416. * @param {
  11417. * String } cmd 命令字符串
  11418. * @param {
  11419. * String } align 对齐方式:left => 居左,right => 居右,center =>
  11420. * 居中,justify => 两端对齐
  11421. * @example ```javascript editor.execCommand( 'justify', 'center' ); ```
  11422. */
  11423. /**
  11424. * 如果选区所在位置是段落区域,返回当前段落对齐方式
  11425. *
  11426. * @command justify
  11427. * @method queryCommandValue
  11428. * @param {
  11429. * String } cmd 命令字符串
  11430. * @return { String } 返回段落对齐方式
  11431. * @example ```javascript editor.queryCommandValue( 'justify' ); ```
  11432. */
  11433. UE.plugins['justify'] = function() {
  11434. var me = this,
  11435. block = domUtils.isBlockElm,
  11436. defaultValue = {
  11437. left: 1,
  11438. right: 1,
  11439. center: 1,
  11440. justify: 1
  11441. },
  11442. doJustify = function(range, style) {
  11443. var bookmark = range.createBookmark(),
  11444. filterFn = function(node) {
  11445. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' &&
  11446. !domUtils.isBookmarkNode(node) : !domUtils
  11447. .isWhitespace(node);
  11448. };
  11449. range.enlarge(true);
  11450. var bookmark2 = range.createBookmark(),
  11451. current = domUtils
  11452. .getNextDomNode(bookmark2.start, false, filterFn),
  11453. tmpRange = range
  11454. .cloneRange(),
  11455. tmpNode;
  11456. while(current &&
  11457. !(domUtils.getPosition(current, bookmark2.end) & domUtils.POSITION_FOLLOWING)) {
  11458. if(current.nodeType == 3 || !block(current)) {
  11459. tmpRange.setStartBefore(current);
  11460. while(current && current !== bookmark2.end &&
  11461. !block(current)) {
  11462. tmpNode = current;
  11463. current = domUtils.getNextDomNode(current, false, null,
  11464. function(node) {
  11465. return !block(node);
  11466. });
  11467. }
  11468. tmpRange.setEndAfter(tmpNode);
  11469. var common = tmpRange.getCommonAncestor();
  11470. if(!domUtils.isBody(common) && block(common)) {
  11471. domUtils.setStyles(common, utils.isString(style) ? {
  11472. 'text-align': style
  11473. } : style);
  11474. current = common;
  11475. } else {
  11476. var p = range.document.createElement('p');
  11477. domUtils.setStyles(p, utils.isString(style) ? {
  11478. 'text-align': style
  11479. } : style);
  11480. var frag = tmpRange.extractContents();
  11481. p.appendChild(frag);
  11482. tmpRange.insertNode(p);
  11483. current = p;
  11484. }
  11485. current = domUtils.getNextDomNode(current, false, filterFn);
  11486. } else {
  11487. current = domUtils.getNextDomNode(current, true, filterFn);
  11488. }
  11489. }
  11490. return range.moveToBookmark(bookmark2).moveToBookmark(bookmark);
  11491. };
  11492. UE.commands['justify'] = {
  11493. execCommand: function(cmdName, align) {
  11494. var range = this.selection.getRange(),
  11495. txt;
  11496. // 闭合时单独处理
  11497. if(range.collapsed) {
  11498. txt = this.document.createTextNode('p');
  11499. range.insertNode(txt);
  11500. }
  11501. doJustify(range, align);
  11502. if(txt) {
  11503. range.setStartBefore(txt).collapse(true);
  11504. domUtils.remove(txt);
  11505. }
  11506. range.select();
  11507. return true;
  11508. },
  11509. queryCommandValue: function() {
  11510. var startNode = this.selection.getStart(),
  11511. value = domUtils
  11512. .getComputedStyle(startNode, 'text-align');
  11513. return defaultValue[value] ? value : 'left';
  11514. },
  11515. queryCommandState: function() {
  11516. var start = this.selection.getStart(),
  11517. cell = start &&
  11518. domUtils.findParentByTagName(start, ["td", "th",
  11519. "caption"
  11520. ], true);
  11521. return cell ? -1 : 0;
  11522. }
  11523. };
  11524. };
  11525. // plugins/font.js
  11526. /**
  11527. * 字体颜色,背景色,字号,字体,下划线,删除线
  11528. *
  11529. * @file
  11530. * @since 1.2.6.1
  11531. */
  11532. /**
  11533. * 字体颜色
  11534. *
  11535. * @command forecolor
  11536. * @method execCommand
  11537. * @param {
  11538. * String } cmd 命令字符串
  11539. * @param {
  11540. * String } value 色值(必须十六进制)
  11541. * @example ```javascript editor.execCommand( 'forecolor', '#000' ); ```
  11542. */
  11543. /**
  11544. * 返回选区字体颜色
  11545. *
  11546. * @command forecolor
  11547. * @method queryCommandValue
  11548. * @param {
  11549. * String } cmd 命令字符串
  11550. * @return { String } 返回字体颜色
  11551. * @example ```javascript editor.queryCommandValue( 'forecolor' ); ```
  11552. */
  11553. /**
  11554. * 字体背景颜色
  11555. *
  11556. * @command backcolor
  11557. * @method execCommand
  11558. * @param {
  11559. * String } cmd 命令字符串
  11560. * @param {
  11561. * String } value 色值(必须十六进制)
  11562. * @example ```javascript editor.execCommand( 'backcolor', '#000' ); ```
  11563. */
  11564. /**
  11565. * 返回选区字体颜色
  11566. *
  11567. * @command backcolor
  11568. * @method queryCommandValue
  11569. * @param {
  11570. * String } cmd 命令字符串
  11571. * @return { String } 返回字体背景颜色
  11572. * @example ```javascript editor.queryCommandValue( 'backcolor' ); ```
  11573. */
  11574. /**
  11575. * 字体大小
  11576. *
  11577. * @command fontsize
  11578. * @method execCommand
  11579. * @param {
  11580. * String } cmd 命令字符串
  11581. * @param {
  11582. * String } value 字体大小
  11583. * @example ```javascript editor.execCommand( 'fontsize', '14px' ); ```
  11584. */
  11585. /**
  11586. * 返回选区字体大小
  11587. *
  11588. * @command fontsize
  11589. * @method queryCommandValue
  11590. * @param {
  11591. * String } cmd 命令字符串
  11592. * @return { String } 返回字体大小
  11593. * @example ```javascript editor.queryCommandValue( 'fontsize' ); ```
  11594. */
  11595. /**
  11596. * 字体样式
  11597. *
  11598. * @command fontfamily
  11599. * @method execCommand
  11600. * @param {
  11601. * String } cmd 命令字符串
  11602. * @param {
  11603. * String } value 字体样式
  11604. * @example ```javascript editor.execCommand( 'fontfamily', '微软雅黑' ); ```
  11605. */
  11606. /**
  11607. * 返回选区字体样式
  11608. *
  11609. * @command fontfamily
  11610. * @method queryCommandValue
  11611. * @param {
  11612. * String } cmd 命令字符串
  11613. * @return { String } 返回字体样式
  11614. * @example ```javascript editor.queryCommandValue( 'fontfamily' ); ```
  11615. */
  11616. /**
  11617. * 字体下划线,与删除线互斥
  11618. *
  11619. * @command underline
  11620. * @method execCommand
  11621. * @param {
  11622. * String } cmd 命令字符串
  11623. * @example ```javascript editor.execCommand( 'underline' ); ```
  11624. */
  11625. /**
  11626. * 字体删除线,与下划线互斥
  11627. *
  11628. * @command strikethrough
  11629. * @method execCommand
  11630. * @param {
  11631. * String } cmd 命令字符串
  11632. * @example ```javascript editor.execCommand( 'strikethrough' ); ```
  11633. */
  11634. /**
  11635. * 字体边框
  11636. *
  11637. * @command fontborder
  11638. * @method execCommand
  11639. * @param {
  11640. * String } cmd 命令字符串
  11641. * @example ```javascript editor.execCommand( 'fontborder' ); ```
  11642. */
  11643. UE.plugins['font'] = function() {
  11644. var me = this,
  11645. fonts = {
  11646. 'forecolor': 'color',
  11647. 'backcolor': 'background-color',
  11648. 'fontsize': 'font-size',
  11649. 'fontfamily': 'font-family',
  11650. 'underline': 'text-decoration',
  11651. 'strikethrough': 'text-decoration',
  11652. 'fontborder': 'border'
  11653. },
  11654. needCmd = {
  11655. 'underline': 1,
  11656. 'strikethrough': 1,
  11657. 'fontborder': 1
  11658. },
  11659. needSetChild = {
  11660. 'forecolor': 'color',
  11661. 'backcolor': 'background-color',
  11662. 'fontsize': 'font-size',
  11663. 'fontfamily': 'font-family'
  11664. };
  11665. me.setOpt({
  11666. 'fontfamily': [{
  11667. name: 'songti',
  11668. val: '宋体,SimSun'
  11669. }, {
  11670. name: 'yahei',
  11671. val: '微软雅黑,Microsoft YaHei'
  11672. }, {
  11673. name: 'kaiti',
  11674. val: '楷体,楷体_GB2312, SimKai'
  11675. }, {
  11676. name: 'heiti',
  11677. val: '黑体, SimHei'
  11678. }, {
  11679. name: 'lishu',
  11680. val: '隶书, SimLi'
  11681. }, {
  11682. name: 'andaleMono',
  11683. val: 'andale mono'
  11684. }, {
  11685. name: 'arial',
  11686. val: 'arial, helvetica,sans-serif'
  11687. }, {
  11688. name: 'arialBlack',
  11689. val: 'arial black,avant garde'
  11690. }, {
  11691. name: 'comicSansMs',
  11692. val: 'comic sans ms'
  11693. }, {
  11694. name: 'impact',
  11695. val: 'impact,chicago'
  11696. }, {
  11697. name: 'timesNewRoman',
  11698. val: 'times new roman'
  11699. }],
  11700. 'fontsize': [10, 11, 12, 14, 16, 18, 20, 24, 36]
  11701. });
  11702. function mergeWithParent(node) {
  11703. var parent;
  11704. while(parent = node.parentNode) {
  11705. if(parent.tagName == 'SPAN' &&
  11706. domUtils.getChildCount(parent, function(child) {
  11707. return !domUtils.isBookmarkNode(child) &&
  11708. !domUtils.isBr(child)
  11709. }) == 1) {
  11710. parent.style.cssText += node.style.cssText;
  11711. domUtils.remove(node, true);
  11712. node = parent;
  11713. } else {
  11714. break;
  11715. }
  11716. }
  11717. }
  11718. function mergeChild(rng, cmdName, value) {
  11719. if(needSetChild[cmdName]) {
  11720. rng.adjustmentBoundary();
  11721. if(!rng.collapsed && rng.startContainer.nodeType == 1) {
  11722. var start = rng.startContainer.childNodes[rng.startOffset];
  11723. if(start && domUtils.isTagNode(start, 'span')) {
  11724. var bk = rng.createBookmark();
  11725. utils.each(
  11726. domUtils.getElementsByTagName(start, 'span'),
  11727. function(span) {
  11728. if(!span.parentNode ||
  11729. domUtils.isBookmarkNode(span))
  11730. return;
  11731. if(cmdName == 'backcolor' &&
  11732. domUtils.getComputedStyle(span,
  11733. 'background-color')
  11734. .toLowerCase() === value) {
  11735. return;
  11736. }
  11737. domUtils.removeStyle(span,
  11738. needSetChild[cmdName]);
  11739. if(span.style.cssText.replace(/^\s+$/, '').length == 0) {
  11740. domUtils.remove(span, true)
  11741. }
  11742. });
  11743. rng.moveToBookmark(bk)
  11744. }
  11745. }
  11746. }
  11747. }
  11748. function mergesibling(rng, cmdName, value) {
  11749. var collapsed = rng.collapsed,
  11750. bk = rng.createBookmark(),
  11751. common;
  11752. if(collapsed) {
  11753. common = bk.start.parentNode;
  11754. while(dtd.$inline[common.tagName]) {
  11755. common = common.parentNode;
  11756. }
  11757. } else {
  11758. common = domUtils.getCommonAncestor(bk.start, bk.end);
  11759. }
  11760. utils.each(domUtils.getElementsByTagName(common, 'span'), function(
  11761. span) {
  11762. if(!span.parentNode || domUtils.isBookmarkNode(span))
  11763. return;
  11764. if(/\s*border\s*:\s*none;?\s*/i.test(span.style.cssText)) {
  11765. if(/^\s*border\s*:\s*none;?\s*$/.test(span.style.cssText)) {
  11766. domUtils.remove(span, true);
  11767. } else {
  11768. domUtils.removeStyle(span, 'border');
  11769. }
  11770. return
  11771. }
  11772. if(/border/i.test(span.style.cssText) &&
  11773. span.parentNode.tagName == 'SPAN' &&
  11774. /border/i.test(span.parentNode.style.cssText)) {
  11775. span.style.cssText = span.style.cssText.replace(
  11776. /border[^:]*:[^;]+;?/gi, '');
  11777. }
  11778. if(!(cmdName == 'fontborder' && value == 'none')) {
  11779. var next = span.nextSibling;
  11780. while(next && next.nodeType == 1 && next.tagName == 'SPAN') {
  11781. if(domUtils.isBookmarkNode(next) &&
  11782. cmdName == 'fontborder') {
  11783. span.appendChild(next);
  11784. next = span.nextSibling;
  11785. continue;
  11786. }
  11787. if(next.style.cssText == span.style.cssText) {
  11788. domUtils.moveChild(next, span);
  11789. domUtils.remove(next);
  11790. }
  11791. if(span.nextSibling === next)
  11792. break;
  11793. next = span.nextSibling;
  11794. }
  11795. }
  11796. mergeWithParent(span);
  11797. if(browser.ie && browser.version > 8) {
  11798. // 拷贝父亲们的特别的属性,这里只做背景颜色的处理
  11799. var parent = domUtils.findParent(span, function(n) {
  11800. return n.tagName == 'SPAN' &&
  11801. /background-color/.test(n.style.cssText)
  11802. });
  11803. if(parent && !/background-color/.test(span.style.cssText)) {
  11804. span.style.backgroundColor = parent.style.backgroundColor;
  11805. }
  11806. }
  11807. });
  11808. rng.moveToBookmark(bk);
  11809. mergeChild(rng, cmdName, value)
  11810. }
  11811. me.addInputRule(function(root) {
  11812. utils.each(root.getNodesByTagName('u s del font strike'), function(
  11813. node) {
  11814. if(node.tagName == 'font') {
  11815. var cssStyle = [];
  11816. for(var p in node.attrs) {
  11817. switch(p) {
  11818. case 'size':
  11819. cssStyle.push('font-size:' + ({
  11820. '1': '10',
  11821. '2': '12',
  11822. '3': '16',
  11823. '4': '18',
  11824. '5': '24',
  11825. '6': '32',
  11826. '7': '48'
  11827. }[node.attrs[p]] || node.attrs[p]) + 'px');
  11828. break;
  11829. case 'color':
  11830. cssStyle.push('color:' + node.attrs[p]);
  11831. break;
  11832. case 'face':
  11833. cssStyle.push('font-family:' + node.attrs[p]);
  11834. break;
  11835. case 'style':
  11836. cssStyle.push(node.attrs[p]);
  11837. }
  11838. }
  11839. node.attrs = {
  11840. 'style': cssStyle.join(';')
  11841. };
  11842. } else {
  11843. var val = node.tagName == 'u' ?
  11844. 'underline' :
  11845. 'line-through';
  11846. node.attrs = {
  11847. 'style': (node.getAttr('style') || '') +
  11848. 'text-decoration:' + val + ';'
  11849. }
  11850. }
  11851. node.tagName = 'span';
  11852. });
  11853. // utils.each(root.getNodesByTagName('span'), function (node) {
  11854. // var val;
  11855. // if(val = node.getAttr('class')){
  11856. // if(/fontstrikethrough/.test(val)){
  11857. // node.setStyle('text-decoration','line-through');
  11858. // if(node.attrs['class']){
  11859. // node.attrs['class'] =
  11860. // node.attrs['class'].replace(/fontstrikethrough/,'');
  11861. // }else{
  11862. // node.setAttr('class')
  11863. // }
  11864. // }
  11865. // if(/fontborder/.test(val)){
  11866. // node.setStyle('border','1px solid #000');
  11867. // if(node.attrs['class']){
  11868. // node.attrs['class'] =
  11869. // node.attrs['class'].replace(/fontborder/,'');
  11870. // }else{
  11871. // node.setAttr('class')
  11872. // }
  11873. // }
  11874. // }
  11875. // });
  11876. });
  11877. // me.addOutputRule(function(root){
  11878. // utils.each(root.getNodesByTagName('span'), function (node) {
  11879. // var val;
  11880. // if(val = node.getStyle('text-decoration')){
  11881. // if(/line-through/.test(val)){
  11882. // if(node.attrs['class']){
  11883. // node.attrs['class'] += ' fontstrikethrough';
  11884. // }else{
  11885. // node.setAttr('class','fontstrikethrough')
  11886. // }
  11887. // }
  11888. //
  11889. // node.setStyle('text-decoration')
  11890. // }
  11891. // if(val = node.getStyle('border')){
  11892. // if(/1px/.test(val) && /solid/.test(val)){
  11893. // if(node.attrs['class']){
  11894. // node.attrs['class'] += ' fontborder';
  11895. //
  11896. // }else{
  11897. // node.setAttr('class','fontborder')
  11898. // }
  11899. // }
  11900. // node.setStyle('border')
  11901. //
  11902. // }
  11903. // });
  11904. // });
  11905. for(var p in fonts) {
  11906. (function(cmd, style) {
  11907. UE.commands[cmd] = {
  11908. execCommand: function(cmdName, value) {
  11909. value = value ||
  11910. (this.queryCommandState(cmdName) ?
  11911. 'none' :
  11912. cmdName == 'underline' ?
  11913. 'underline' :
  11914. cmdName == 'fontborder' ?
  11915. '1px solid #000' :
  11916. 'line-through');
  11917. var me = this,
  11918. range = this.selection.getRange(),
  11919. text;
  11920. if(value == 'default') {
  11921. if(range.collapsed) {
  11922. text = me.document.createTextNode('font');
  11923. range.insertNode(text).select();
  11924. }
  11925. me.execCommand('removeFormat', 'span,a', style);
  11926. if(text) {
  11927. range.setStartBefore(text).collapse(true);
  11928. domUtils.remove(text);
  11929. }
  11930. mergesibling(range, cmdName, value);
  11931. range.select()
  11932. } else {
  11933. if(!range.collapsed) {
  11934. if(needCmd[cmd] && me.queryCommandValue(cmd)) {
  11935. me.execCommand('removeFormat', 'span,a',
  11936. style);
  11937. }
  11938. range = me.selection.getRange();
  11939. range.applyInlineStyle('span', {
  11940. 'style': style + ':' + value
  11941. });
  11942. mergesibling(range, cmdName, value);
  11943. range.select();
  11944. } else {
  11945. var span = domUtils.findParentByTagName(
  11946. range.startContainer, 'span', true);
  11947. text = me.document.createTextNode('font');
  11948. if(span &&
  11949. !span.children.length &&
  11950. !span[browser.ie ?
  11951. 'innerText' :
  11952. 'textContent'].replace(
  11953. fillCharReg, '').length) {
  11954. // for ie hack when enter
  11955. range.insertNode(text);
  11956. if(needCmd[cmd]) {
  11957. range.selectNode(text).select();
  11958. me.execCommand('removeFormat',
  11959. 'span,a', style, null);
  11960. span = domUtils.findParentByTagName(
  11961. text, 'span', true);
  11962. range.setStartBefore(text);
  11963. }
  11964. span
  11965. &&
  11966. (span.style.cssText += ';' +
  11967. style + ':' + value);
  11968. range.collapse(true).select();
  11969. } else {
  11970. range.insertNode(text);
  11971. range.selectNode(text).select();
  11972. span = range.document.createElement('span');
  11973. if(needCmd[cmd]) {
  11974. // a标签内的不处理跳过
  11975. if(domUtils.findParentByTagName(text,
  11976. 'a', true)) {
  11977. range.setStartBefore(text)
  11978. .setCursor();
  11979. domUtils.remove(text);
  11980. return;
  11981. }
  11982. me.execCommand('removeFormat',
  11983. 'span,a', style);
  11984. }
  11985. span.style.cssText = style + ':' + value;
  11986. text.parentNode.insertBefore(span, text);
  11987. // 修复,span套span 但样式不继承的问题
  11988. if(!browser.ie || browser.ie &&
  11989. browser.version == 9) {
  11990. var spanParent = span.parentNode;
  11991. while(!domUtils.isBlockElm(spanParent)) {
  11992. if(spanParent.tagName == 'SPAN') {
  11993. // opera合并style不会加入";"
  11994. span.style.cssText = spanParent.style.cssText +
  11995. ";" +
  11996. span.style.cssText;
  11997. }
  11998. spanParent = spanParent.parentNode;
  11999. }
  12000. }
  12001. if(opera) {
  12002. setTimeout(function() {
  12003. range.setStart(span, 0)
  12004. .collapse(true);
  12005. mergesibling(range, cmdName, value);
  12006. range.select();
  12007. });
  12008. } else {
  12009. range.setStart(span, 0).collapse(true);
  12010. mergesibling(range, cmdName, value);
  12011. range.select();
  12012. }
  12013. // trace:981
  12014. // domUtils.mergeToParent(span)
  12015. }
  12016. domUtils.remove(text);
  12017. }
  12018. }
  12019. return true;
  12020. },
  12021. queryCommandValue: function(cmdName) {
  12022. var startNode = this.selection.getStart();
  12023. // trace:946
  12024. if(cmdName == 'underline' ||
  12025. cmdName == 'strikethrough') {
  12026. var tmpNode = startNode,
  12027. value;
  12028. while(tmpNode && !domUtils.isBlockElm(tmpNode) &&
  12029. !domUtils.isBody(tmpNode)) {
  12030. if(tmpNode.nodeType == 1) {
  12031. value = domUtils.getComputedStyle(tmpNode,
  12032. style);
  12033. if(value != 'none') {
  12034. return value;
  12035. }
  12036. }
  12037. tmpNode = tmpNode.parentNode;
  12038. }
  12039. return 'none';
  12040. }
  12041. if(cmdName == 'fontborder') {
  12042. var tmp = startNode,
  12043. val;
  12044. while(tmp && dtd.$inline[tmp.tagName]) {
  12045. if(val = domUtils.getComputedStyle(tmp,
  12046. 'border')) {
  12047. if(/1px/.test(val) && /solid/.test(val)) {
  12048. return val;
  12049. }
  12050. }
  12051. tmp = tmp.parentNode;
  12052. }
  12053. return ''
  12054. }
  12055. if(cmdName == 'FontSize') {
  12056. var styleVal = domUtils.getComputedStyle(startNode,
  12057. style),
  12058. tmp = /^([\d\.]+)(\w+)$/
  12059. .exec(styleVal);
  12060. if(tmp) {
  12061. return Math.floor(tmp[1]) + tmp[2];
  12062. }
  12063. return styleVal;
  12064. }
  12065. return domUtils.getComputedStyle(startNode, style);
  12066. },
  12067. queryCommandState: function(cmdName) {
  12068. if(!needCmd[cmdName])
  12069. return 0;
  12070. var val = this.queryCommandValue(cmdName);
  12071. if(cmdName == 'fontborder') {
  12072. return /1px/.test(val) && /solid/.test(val)
  12073. } else {
  12074. return cmdName == 'underline' ? /underline/
  12075. .test(val) : /line\-through/.test(val);
  12076. }
  12077. }
  12078. };
  12079. })(p, fonts[p]);
  12080. }
  12081. };
  12082. // plugins/link.js
  12083. /**
  12084. * 超链接
  12085. *
  12086. * @file
  12087. * @since 1.2.6.1
  12088. */
  12089. /**
  12090. * 插入超链接
  12091. *
  12092. * @command link
  12093. * @method execCommand
  12094. * @param {
  12095. * String } cmd 命令字符串
  12096. * @param {
  12097. * Object } options 设置自定义属性,例如:url、title、target
  12098. * @example ```javascript editor.execCommand( 'link', '{
  12099. * url:'ueditor.baidu.com', title:'ueditor', target:'_blank' }' );
  12100. * ```
  12101. */
  12102. /**
  12103. * 返回当前选中的第一个超链接节点
  12104. *
  12105. * @command link
  12106. * @method queryCommandValue
  12107. * @param {
  12108. * String } cmd 命令字符串
  12109. * @return { Element } 超链接节点
  12110. * @example ```javascript editor.queryCommandValue( 'link' ); ```
  12111. */
  12112. /**
  12113. * 取消超链接
  12114. *
  12115. * @command unlink
  12116. * @method execCommand
  12117. * @param {
  12118. * String } cmd 命令字符串
  12119. * @example ```javascript editor.execCommand( 'unlink'); ```
  12120. */
  12121. UE.plugins['link'] = function() {
  12122. function optimize(range) {
  12123. var start = range.startContainer,
  12124. end = range.endContainer;
  12125. if(start = domUtils.findParentByTagName(start, 'a', true)) {
  12126. range.setStartBefore(start);
  12127. }
  12128. if(end = domUtils.findParentByTagName(end, 'a', true)) {
  12129. range.setEndAfter(end);
  12130. }
  12131. }
  12132. UE.commands['unlink'] = {
  12133. execCommand: function() {
  12134. var range = this.selection.getRange(),
  12135. bookmark;
  12136. if(range.collapsed &&
  12137. !domUtils.findParentByTagName(range.startContainer,
  12138. 'a', true)) {
  12139. return;
  12140. }
  12141. bookmark = range.createBookmark();
  12142. optimize(range);
  12143. range.removeInlineStyle('a').moveToBookmark(bookmark).select();
  12144. },
  12145. queryCommandState: function() {
  12146. return !this.highlight && this.queryCommandValue('link') ?
  12147. 0 :
  12148. -1;
  12149. }
  12150. };
  12151. function doLink(range, opt, me) {
  12152. var rngClone = range.cloneRange(),
  12153. link = me
  12154. .queryCommandValue('link');
  12155. optimize(range = range.adjustmentBoundary());
  12156. var start = range.startContainer;
  12157. if(start.nodeType == 1 && link) {
  12158. start = start.childNodes[range.startOffset];
  12159. if(start &&
  12160. start.nodeType == 1 &&
  12161. start.tagName == 'A' &&
  12162. /^(?:https?|ftp|file)\s*:\s*\/\//
  12163. .test(start[browser.ie ?
  12164. 'innerText' :
  12165. 'textContent'])) {
  12166. start[browser.ie ? 'innerText' : 'textContent'] = utils
  12167. .html(opt.textValue || opt.href);
  12168. }
  12169. }
  12170. if(!rngClone.collapsed || link) {
  12171. range.removeInlineStyle('a');
  12172. rngClone = range.cloneRange();
  12173. }
  12174. if(rngClone.collapsed) {
  12175. var a = range.document.createElement('a'),
  12176. text = '';
  12177. if(opt.textValue) {
  12178. text = utils.html(opt.textValue);
  12179. delete opt.textValue;
  12180. } else {
  12181. text = utils.html(opt.href);
  12182. }
  12183. domUtils.setAttributes(a, opt);
  12184. start = domUtils.findParentByTagName(rngClone.startContainer,
  12185. 'a', true);
  12186. if(start && domUtils.isInNodeEndBoundary(rngClone, start)) {
  12187. range.setStartAfter(start).collapse(true);
  12188. }
  12189. a[browser.ie ? 'innerText' : 'textContent'] = text;
  12190. range.insertNode(a).selectNode(a);
  12191. } else {
  12192. range.applyInlineStyle('a', opt);
  12193. }
  12194. }
  12195. UE.commands['link'] = {
  12196. execCommand: function(cmdName, opt) {
  12197. var range;
  12198. opt._href && (opt._href = utils.unhtml(opt._href, /[<">]/g));
  12199. opt.href && (opt.href = utils.unhtml(opt.href, /[<">]/g));
  12200. opt.textValue &&
  12201. (opt.textValue = utils.unhtml(opt.textValue,
  12202. /[<">]/g));
  12203. doLink(range = this.selection.getRange(), opt, this);
  12204. // 闭合都不加占位符,如果加了会在a后边多个占位符节点,导致a是图片背景组成的列表,出现空白问题
  12205. range.collapse().select(true);
  12206. },
  12207. queryCommandValue: function() {
  12208. var range = this.selection.getRange(),
  12209. node;
  12210. if(range.collapsed) {
  12211. // node = this.selection.getStart();
  12212. // 在ie下getstart()取值偏上了
  12213. node = range.startContainer;
  12214. node = node.nodeType == 1 ? node : node.parentNode;
  12215. if(node &&
  12216. (node = domUtils.findParentByTagName(node, 'a',
  12217. true)) &&
  12218. !domUtils.isInNodeEndBoundary(range, node)) {
  12219. return node;
  12220. }
  12221. } else {
  12222. // trace:1111 如果是<p><a>xx</a></p> startContainer是p就会找不到a
  12223. range.shrinkBoundary();
  12224. var start = range.startContainer.nodeType == 3 ||
  12225. !range.startContainer.childNodes[range.startOffset] ?
  12226. range.startContainer :
  12227. range.startContainer.childNodes[range.startOffset],
  12228. end = range.endContainer.nodeType == 3 ||
  12229. range.endOffset == 0 ?
  12230. range.endContainer :
  12231. range.endContainer.childNodes[range.endOffset - 1],
  12232. common = range
  12233. .getCommonAncestor();
  12234. node = domUtils.findParentByTagName(common, 'a', true);
  12235. if(!node && common.nodeType == 1) {
  12236. var as = common.getElementsByTagName('a'),
  12237. ps, pe;
  12238. for(var i = 0, ci; ci = as[i++];) {
  12239. ps = domUtils.getPosition(ci, start), pe = domUtils
  12240. .getPosition(ci, end);
  12241. if((ps & domUtils.POSITION_FOLLOWING || ps &
  12242. domUtils.POSITION_CONTAINS) &&
  12243. (pe & domUtils.POSITION_PRECEDING || pe &
  12244. domUtils.POSITION_CONTAINS)) {
  12245. node = ci;
  12246. break;
  12247. }
  12248. }
  12249. }
  12250. return node;
  12251. }
  12252. },
  12253. queryCommandState: function() {
  12254. // 判断如果是视频的话连接不可用
  12255. // fix 853
  12256. var img = this.selection.getRange().getClosedNode(),
  12257. flag = img &&
  12258. (img.className == "edui-faked-video" || img.className
  12259. .indexOf("edui-upload-video") != -1);
  12260. return flag ? -1 : 0;
  12261. }
  12262. };
  12263. };
  12264. // plugins/iframe.js
  12265. // /import core
  12266. // /import plugins\inserthtml.js
  12267. // /commands 插入框架
  12268. // /commandsName InsertFrame
  12269. // /commandsTitle 插入Iframe
  12270. // /commandsDialog dialogs\insertframe
  12271. UE.plugins['insertframe'] = function() {
  12272. var me = this;
  12273. function deleteIframe() {
  12274. me._iframe && delete me._iframe;
  12275. }
  12276. me.addListener("selectionchange", function() {
  12277. deleteIframe();
  12278. });
  12279. };
  12280. // plugins/scrawl.js
  12281. // /import core
  12282. // /commands 涂鸦
  12283. // /commandsName Scrawl
  12284. // /commandsTitle 涂鸦
  12285. // /commandsDialog dialogs\scrawl
  12286. UE.commands['scrawl'] = {
  12287. queryCommandState: function() {
  12288. return(browser.ie && browser.version <= 8) ? -1 : 0;
  12289. }
  12290. };
  12291. // plugins/removeformat.js
  12292. /**
  12293. * 清除格式
  12294. *
  12295. * @file
  12296. * @since 1.2.6.1
  12297. */
  12298. /**
  12299. * 清除文字样式
  12300. *
  12301. * @command removeformat
  12302. * @method execCommand
  12303. * @param {
  12304. * String } cmd 命令字符串
  12305. * @param {String}
  12306. * tags 以逗号隔开的标签。如:strong
  12307. * @param {String}
  12308. * style 样式如:color
  12309. * @param {String}
  12310. * attrs 属性如:width
  12311. * @example ```javascript editor.execCommand( 'removeformat',
  12312. * 'strong','color','width' ); ```
  12313. */
  12314. UE.plugins['removeformat'] = function() {
  12315. var me = this;
  12316. me.setOpt({
  12317. 'removeFormatTags': 'b,big,code,del,dfn,em,font,i,ins,kbd,q,samp,small,span,strike,strong,sub,sup,tt,u,var',
  12318. 'removeFormatAttributes': 'class,style,lang,width,height,align,hspace,valign'
  12319. });
  12320. me.commands['removeformat'] = {
  12321. execCommand: function(cmdName, tags, style, attrs, notIncludeA) {
  12322. var tagReg = new RegExp('^(?:' +
  12323. (tags || this.options.removeFormatTags).replace(/,/g,
  12324. '|') + ')$', 'i'),
  12325. removeFormatAttributes = style ? [] :
  12326. (attrs || this.options.removeFormatAttributes)
  12327. .split(','),
  12328. range = new dom.Range(this.document),
  12329. bookmark, node, parent, filter = function(
  12330. node) {
  12331. return node.nodeType == 1;
  12332. };
  12333. function isRedundantSpan(node) {
  12334. if(node.nodeType == 3 ||
  12335. node.tagName.toLowerCase() != 'span') {
  12336. return 0;
  12337. }
  12338. if(browser.ie) {
  12339. // ie 下判断实效,所以只能简单用style来判断
  12340. // return node.style.cssText == '' ? 1 : 0;
  12341. var attrs = node.attributes;
  12342. if(attrs.length) {
  12343. for(var i = 0, l = attrs.length; i < l; i++) {
  12344. if(attrs[i].specified) {
  12345. return 0;
  12346. }
  12347. }
  12348. return 1;
  12349. }
  12350. }
  12351. return !node.attributes.length;
  12352. }
  12353. function doRemove(range) {
  12354. var bookmark1 = range.createBookmark();
  12355. if(range.collapsed) {
  12356. range.enlarge(true);
  12357. }
  12358. // 不能把a标签切了
  12359. if(!notIncludeA) {
  12360. var aNode = domUtils.findParentByTagName(
  12361. range.startContainer, 'a', true);
  12362. if(aNode) {
  12363. range.setStartBefore(aNode);
  12364. }
  12365. aNode = domUtils.findParentByTagName(
  12366. range.endContainer, 'a', true);
  12367. if(aNode) {
  12368. range.setEndAfter(aNode);
  12369. }
  12370. }
  12371. bookmark = range.createBookmark();
  12372. node = bookmark.start;
  12373. // 切开始
  12374. while((parent = node.parentNode) &&
  12375. !domUtils.isBlockElm(parent)) {
  12376. domUtils.breakParent(node, parent);
  12377. domUtils.clearEmptySibling(node);
  12378. }
  12379. if(bookmark.end) {
  12380. // 切结束
  12381. node = bookmark.end;
  12382. while((parent = node.parentNode) &&
  12383. !domUtils.isBlockElm(parent)) {
  12384. domUtils.breakParent(node, parent);
  12385. domUtils.clearEmptySibling(node);
  12386. }
  12387. // 开始去除样式
  12388. var current = domUtils.getNextDomNode(bookmark.start,
  12389. false, filter),
  12390. next;
  12391. while(current) {
  12392. if(current == bookmark.end) {
  12393. break;
  12394. }
  12395. next = domUtils.getNextDomNode(current, true,
  12396. filter);
  12397. if(!dtd.$empty[current.tagName.toLowerCase()] &&
  12398. !domUtils.isBookmarkNode(current)) {
  12399. if(tagReg.test(current.tagName)) {
  12400. if(style) {
  12401. domUtils.removeStyle(current, style);
  12402. if(isRedundantSpan(current) &&
  12403. style != 'text-decoration') {
  12404. domUtils.remove(current, true);
  12405. }
  12406. } else {
  12407. domUtils.remove(current, true);
  12408. }
  12409. } else {
  12410. // trace:939 不能把list上的样式去掉
  12411. if(!dtd.$tableContent[current.tagName] &&
  12412. !dtd.$list[current.tagName]) {
  12413. domUtils.removeAttributes(current,
  12414. removeFormatAttributes);
  12415. if(isRedundantSpan(current)) {
  12416. domUtils.remove(current, true);
  12417. }
  12418. }
  12419. }
  12420. }
  12421. current = next;
  12422. }
  12423. }
  12424. // trace:1035
  12425. // trace:1096 不能把td上的样式去掉,比如边框
  12426. var pN = bookmark.start.parentNode;
  12427. if(domUtils.isBlockElm(pN) &&
  12428. !dtd.$tableContent[pN.tagName] &&
  12429. !dtd.$list[pN.tagName]) {
  12430. domUtils.removeAttributes(pN, removeFormatAttributes);
  12431. }
  12432. pN = bookmark.end.parentNode;
  12433. if(bookmark.end && domUtils.isBlockElm(pN) &&
  12434. !dtd.$tableContent[pN.tagName] &&
  12435. !dtd.$list[pN.tagName]) {
  12436. domUtils.removeAttributes(pN, removeFormatAttributes);
  12437. }
  12438. range.moveToBookmark(bookmark).moveToBookmark(bookmark1);
  12439. // 清除冗余的代码 <b><bookmark></b>
  12440. var node = range.startContainer,
  12441. tmp, collapsed = range.collapsed;
  12442. while(node.nodeType == 1 && domUtils.isEmptyNode(node) &&
  12443. dtd.$removeEmpty[node.tagName]) {
  12444. tmp = node.parentNode;
  12445. range.setStartBefore(node);
  12446. // trace:937
  12447. // 更新结束边界
  12448. if(range.startContainer === range.endContainer) {
  12449. range.endOffset--;
  12450. }
  12451. domUtils.remove(node);
  12452. node = tmp;
  12453. }
  12454. if(!collapsed) {
  12455. node = range.endContainer;
  12456. while(node.nodeType == 1 && domUtils.isEmptyNode(node) &&
  12457. dtd.$removeEmpty[node.tagName]) {
  12458. tmp = node.parentNode;
  12459. range.setEndBefore(node);
  12460. domUtils.remove(node);
  12461. node = tmp;
  12462. }
  12463. }
  12464. }
  12465. range = this.selection.getRange();
  12466. doRemove(range);
  12467. range.select();
  12468. }
  12469. };
  12470. };
  12471. // plugins/blockquote.js
  12472. /**
  12473. * 添加引用
  12474. *
  12475. * @file
  12476. * @since 1.2.6.1
  12477. */
  12478. /**
  12479. * 添加引用
  12480. *
  12481. * @command blockquote
  12482. * @method execCommand
  12483. * @param {
  12484. * String } cmd 命令字符串
  12485. * @example ```javascript editor.execCommand( 'blockquote' ); ```
  12486. */
  12487. /**
  12488. * 添加引用
  12489. *
  12490. * @command blockquote
  12491. * @method execCommand
  12492. * @param {
  12493. * String } cmd 命令字符串
  12494. * @param {
  12495. * Object } attrs 节点属性
  12496. * @example ```javascript editor.execCommand( 'blockquote',{ style: "color:
  12497. * red;" } ); ```
  12498. */
  12499. UE.plugins['blockquote'] = function() {
  12500. var me = this;
  12501. function getObj(editor) {
  12502. return domUtils.filterNodeList(editor.selection
  12503. .getStartElementPath(), 'blockquote');
  12504. }
  12505. me.commands['blockquote'] = {
  12506. execCommand: function(cmdName, attrs) {
  12507. var range = this.selection.getRange(),
  12508. obj = getObj(this),
  12509. blockquote = dtd.blockquote,
  12510. bookmark = range
  12511. .createBookmark();
  12512. if(obj) {
  12513. var start = range.startContainer,
  12514. startBlock = domUtils
  12515. .isBlockElm(start) ? start : domUtils.findParent(
  12516. start,
  12517. function(node) {
  12518. return domUtils.isBlockElm(node)
  12519. }),
  12520. end = range.endContainer,
  12521. endBlock = domUtils
  12522. .isBlockElm(end) ? end : domUtils.findParent(end,
  12523. function(node) {
  12524. return domUtils.isBlockElm(node)
  12525. });
  12526. // 处理一下li
  12527. startBlock = domUtils.findParentByTagName(startBlock, 'li',
  12528. true) ||
  12529. startBlock;
  12530. endBlock = domUtils.findParentByTagName(endBlock, 'li',
  12531. true) ||
  12532. endBlock;
  12533. if(startBlock.tagName == 'LI' ||
  12534. startBlock.tagName == 'TD' || startBlock === obj ||
  12535. domUtils.isBody(startBlock)) {
  12536. domUtils.remove(obj, true);
  12537. } else {
  12538. domUtils.breakParent(startBlock, obj);
  12539. }
  12540. if(startBlock !== endBlock) {
  12541. obj = domUtils.findParentByTagName(endBlock,
  12542. 'blockquote');
  12543. if(obj) {
  12544. if(endBlock.tagName == 'LI' ||
  12545. endBlock.tagName == 'TD' ||
  12546. domUtils.isBody(endBlock)) {
  12547. obj.parentNode && domUtils.remove(obj, true);
  12548. } else {
  12549. domUtils.breakParent(endBlock, obj);
  12550. }
  12551. }
  12552. }
  12553. var blockquotes = domUtils.getElementsByTagName(
  12554. this.document, 'blockquote');
  12555. for(var i = 0, bi; bi = blockquotes[i++];) {
  12556. if(!bi.childNodes.length) {
  12557. domUtils.remove(bi);
  12558. } else if(domUtils.getPosition(bi, startBlock) &
  12559. domUtils.POSITION_FOLLOWING &&
  12560. domUtils.getPosition(bi, endBlock) &
  12561. domUtils.POSITION_PRECEDING) {
  12562. domUtils.remove(bi, true);
  12563. }
  12564. }
  12565. } else {
  12566. var tmpRange = range.cloneRange(),
  12567. node = tmpRange.startContainer.nodeType == 1 ?
  12568. tmpRange.startContainer :
  12569. tmpRange.startContainer.parentNode,
  12570. preNode = node,
  12571. doEnd = 1;
  12572. // 调整开始
  12573. while(1) {
  12574. if(domUtils.isBody(node)) {
  12575. if(preNode !== node) {
  12576. if(range.collapsed) {
  12577. tmpRange.selectNode(preNode);
  12578. doEnd = 0;
  12579. } else {
  12580. tmpRange.setStartBefore(preNode);
  12581. }
  12582. } else {
  12583. tmpRange.setStart(node, 0);
  12584. }
  12585. break;
  12586. }
  12587. if(!blockquote[node.tagName]) {
  12588. if(range.collapsed) {
  12589. tmpRange.selectNode(preNode);
  12590. } else {
  12591. tmpRange.setStartBefore(preNode);
  12592. }
  12593. break;
  12594. }
  12595. preNode = node;
  12596. node = node.parentNode;
  12597. }
  12598. // 调整结束
  12599. if(doEnd) {
  12600. preNode = node = node = tmpRange.endContainer.nodeType == 1 ?
  12601. tmpRange.endContainer :
  12602. tmpRange.endContainer.parentNode;
  12603. while(1) {
  12604. if(domUtils.isBody(node)) {
  12605. if(preNode !== node) {
  12606. tmpRange.setEndAfter(preNode);
  12607. } else {
  12608. tmpRange.setEnd(node,
  12609. node.childNodes.length);
  12610. }
  12611. break;
  12612. }
  12613. if(!blockquote[node.tagName]) {
  12614. tmpRange.setEndAfter(preNode);
  12615. break;
  12616. }
  12617. preNode = node;
  12618. node = node.parentNode;
  12619. }
  12620. }
  12621. node = range.document.createElement('blockquote');
  12622. domUtils.setAttributes(node, attrs);
  12623. node.appendChild(tmpRange.extractContents());
  12624. tmpRange.insertNode(node);
  12625. // 去除重复的
  12626. var childs = domUtils.getElementsByTagName(node,
  12627. 'blockquote');
  12628. for(var i = 0, ci; ci = childs[i++];) {
  12629. if(ci.parentNode) {
  12630. domUtils.remove(ci, true);
  12631. }
  12632. }
  12633. }
  12634. range.moveToBookmark(bookmark).select();
  12635. },
  12636. queryCommandState: function() {
  12637. return getObj(this) ? 1 : 0;
  12638. }
  12639. };
  12640. };
  12641. // plugins/convertcase.js
  12642. /**
  12643. * 大小写转换
  12644. *
  12645. * @file
  12646. * @since 1.2.6.1
  12647. */
  12648. /**
  12649. * 把选区内文本变大写,与“tolowercase”命令互斥
  12650. *
  12651. * @command touppercase
  12652. * @method execCommand
  12653. * @param {
  12654. * String } cmd 命令字符串
  12655. * @example ```javascript editor.execCommand( 'touppercase' ); ```
  12656. */
  12657. /**
  12658. * 把选区内文本变小写,与“touppercase”命令互斥
  12659. *
  12660. * @command tolowercase
  12661. * @method execCommand
  12662. * @param {
  12663. * String } cmd 命令字符串
  12664. * @example ```javascript editor.execCommand( 'tolowercase' ); ```
  12665. */
  12666. UE.commands['touppercase'] = UE.commands['tolowercase'] = {
  12667. execCommand: function(cmd) {
  12668. var me = this;
  12669. var rng = me.selection.getRange();
  12670. if(rng.collapsed) {
  12671. return rng;
  12672. }
  12673. var bk = rng.createBookmark(),
  12674. bkEnd = bk.end,
  12675. filterFn = function(
  12676. node) {
  12677. return !domUtils.isBr(node) && !domUtils.isWhitespace(node);
  12678. },
  12679. curNode = domUtils.getNextDomNode(bk.start, false, filterFn);
  12680. while(curNode &&
  12681. (domUtils.getPosition(curNode, bkEnd) & domUtils.POSITION_PRECEDING)) {
  12682. if(curNode.nodeType == 3) {
  12683. curNode.nodeValue = curNode.nodeValue[cmd == 'touppercase' ?
  12684. 'toUpperCase' :
  12685. 'toLowerCase']();
  12686. }
  12687. curNode = domUtils.getNextDomNode(curNode, true, filterFn);
  12688. if(curNode === bkEnd) {
  12689. break;
  12690. }
  12691. }
  12692. rng.moveToBookmark(bk).select();
  12693. }
  12694. };
  12695. // plugins/indent.js
  12696. /**
  12697. * 首行缩进
  12698. *
  12699. * @file
  12700. * @since 1.2.6.1
  12701. */
  12702. /**
  12703. * 缩进
  12704. *
  12705. * @command indent
  12706. * @method execCommand
  12707. * @param {
  12708. * String } cmd 命令字符串
  12709. * @example ```javascript editor.execCommand( 'indent' ); ```
  12710. */
  12711. UE.commands['indent'] = {
  12712. execCommand: function() {
  12713. var me = this,
  12714. value = me.queryCommandState("indent") ?
  12715. "0em" :
  12716. (me.options.indentValue || '2em');
  12717. me.execCommand('Paragraph', 'p', {
  12718. style: 'text-indent:' + value
  12719. });
  12720. },
  12721. queryCommandState: function() {
  12722. var pN = domUtils.filterNodeList(this.selection
  12723. .getStartElementPath(), 'p h1 h2 h3 h4 h5 h6');
  12724. return pN && pN.style.textIndent && parseInt(pN.style.textIndent) ?
  12725. 1 :
  12726. 0;
  12727. }
  12728. };
  12729. // plugins/print.js
  12730. /**
  12731. * 打印
  12732. *
  12733. * @file
  12734. * @since 1.2.6.1
  12735. */
  12736. /**
  12737. * 打印
  12738. *
  12739. * @command print
  12740. * @method execCommand
  12741. * @param {
  12742. * String } cmd 命令字符串
  12743. * @example ```javascript editor.execCommand( 'print' ); ```
  12744. */
  12745. UE.commands['print'] = {
  12746. execCommand: function() {
  12747. this.window.print();
  12748. },
  12749. notNeedUndo: 1
  12750. };
  12751. // plugins/preview.js
  12752. /**
  12753. * 预览
  12754. *
  12755. * @file
  12756. * @since 1.2.6.1
  12757. */
  12758. /**
  12759. * 预览
  12760. *
  12761. * @command preview
  12762. * @method execCommand
  12763. * @param {
  12764. * String } cmd 命令字符串
  12765. * @example ```javascript editor.execCommand( 'preview' ); ```
  12766. */
  12767. UE.commands['preview'] = {
  12768. execCommand: function() {
  12769. var w = window.open('', '_blank', ''),
  12770. d = w.document;
  12771. d.open();
  12772. d
  12773. .write('<!DOCTYPE html><html><head><meta charset="utf-8"/><script src="' +
  12774. this.options.UEDITOR_HOME_URL +
  12775. 'ueditor.parse.js"></script><script>' +
  12776. "setTimeout(function(){uParse('div',{rootPath: '" +
  12777. this.options.UEDITOR_HOME_URL +
  12778. "'})},300)" +
  12779. '</script></head><body><div>' +
  12780. this.getContent(null, null, true) +
  12781. '</div></body></html>');
  12782. d.close();
  12783. },
  12784. notNeedUndo: 1
  12785. };
  12786. // plugins/selectall.js
  12787. /**
  12788. * 全选
  12789. *
  12790. * @file
  12791. * @since 1.2.6.1
  12792. */
  12793. /**
  12794. * 选中所有内容
  12795. *
  12796. * @command selectall
  12797. * @method execCommand
  12798. * @param {
  12799. * String } cmd 命令字符串
  12800. * @example ```javascript editor.execCommand( 'selectall' ); ```
  12801. */
  12802. UE.plugins['selectall'] = function() {
  12803. var me = this;
  12804. me.commands['selectall'] = {
  12805. execCommand: function() {
  12806. // 去掉了原生的selectAll,因为会出现报错和当内容为空时,不能出现闭合状态的光标
  12807. var me = this,
  12808. body = me.body,
  12809. range = me.selection.getRange();
  12810. range.selectNodeContents(body);
  12811. if(domUtils.isEmptyBlock(body)) {
  12812. // opera不能自动合并到元素的里边,要手动处理一下
  12813. if(browser.opera && body.firstChild &&
  12814. body.firstChild.nodeType == 1) {
  12815. range.setStartAtFirst(body.firstChild);
  12816. }
  12817. range.collapse(true);
  12818. }
  12819. range.select(true);
  12820. },
  12821. notNeedUndo: 1
  12822. };
  12823. // 快捷键
  12824. me.addshortcutkey({
  12825. "selectAll": "ctrl+65"
  12826. });
  12827. };
  12828. // plugins/paragraph.js
  12829. /**
  12830. * 段落样式
  12831. *
  12832. * @file
  12833. * @since 1.2.6.1
  12834. */
  12835. /**
  12836. * 段落格式
  12837. *
  12838. * @command paragraph
  12839. * @method execCommand
  12840. * @param {
  12841. * String } cmd 命令字符串
  12842. * @param {String}
  12843. * style 标签值为:'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
  12844. * @param {Object}
  12845. * attrs 标签的属性
  12846. * @example ```javascript editor.execCommand( 'Paragraph','h1','{
  12847. * class:'test' }' ); ```
  12848. */
  12849. /**
  12850. * 返回选区内节点标签名
  12851. *
  12852. * @command paragraph
  12853. * @method queryCommandValue
  12854. * @param {
  12855. * String } cmd 命令字符串
  12856. * @return { String } 节点标签名
  12857. * @example ```javascript editor.queryCommandValue( 'Paragraph' ); ```
  12858. */
  12859. UE.plugins['paragraph'] = function() {
  12860. var me = this,
  12861. block = domUtils.isBlockElm,
  12862. notExchange = ['TD', 'LI',
  12863. 'PRE'
  12864. ],
  12865. doParagraph = function(range, style, attrs, sourceCmdName) {
  12866. var bookmark = range.createBookmark(),
  12867. filterFn = function(node) {
  12868. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' &&
  12869. !domUtils.isBookmarkNode(node) : !domUtils
  12870. .isWhitespace(node);
  12871. },
  12872. para;
  12873. range.enlarge(true);
  12874. var bookmark2 = range.createBookmark(),
  12875. current = domUtils
  12876. .getNextDomNode(bookmark2.start, false, filterFn),
  12877. tmpRange = range
  12878. .cloneRange(),
  12879. tmpNode;
  12880. while(current &&
  12881. !(domUtils.getPosition(current, bookmark2.end) & domUtils.POSITION_FOLLOWING)) {
  12882. if(current.nodeType == 3 || !block(current)) {
  12883. tmpRange.setStartBefore(current);
  12884. while(current && current !== bookmark2.end &&
  12885. !block(current)) {
  12886. tmpNode = current;
  12887. current = domUtils.getNextDomNode(current, false, null,
  12888. function(node) {
  12889. return !block(node);
  12890. });
  12891. }
  12892. tmpRange.setEndAfter(tmpNode);
  12893. para = range.document.createElement(style);
  12894. if(attrs) {
  12895. domUtils.setAttributes(para, attrs);
  12896. if(sourceCmdName && sourceCmdName == 'customstyle' &&
  12897. attrs.style) {
  12898. para.style.cssText = attrs.style;
  12899. }
  12900. }
  12901. para.appendChild(tmpRange.extractContents());
  12902. // 需要内容占位
  12903. if(domUtils.isEmptyNode(para)) {
  12904. domUtils.fillChar(range.document, para);
  12905. }
  12906. tmpRange.insertNode(para);
  12907. var parent = para.parentNode;
  12908. // 如果para上一级是一个block元素且不是body,td就删除它
  12909. if(block(parent) && !domUtils.isBody(para.parentNode) &&
  12910. utils.indexOf(notExchange, parent.tagName) == -1) {
  12911. // 存储dir,style
  12912. if(!(sourceCmdName && sourceCmdName == 'customstyle')) {
  12913. parent.getAttribute('dir') &&
  12914. para.setAttribute('dir', parent
  12915. .getAttribute('dir'));
  12916. // trace:1070
  12917. parent.style.cssText &&
  12918. (para.style.cssText = parent.style.cssText +
  12919. ';' + para.style.cssText);
  12920. // trace:1030
  12921. parent.style.textAlign &&
  12922. !para.style.textAlign &&
  12923. (para.style.textAlign = parent.style.textAlign);
  12924. parent.style.textIndent &&
  12925. !para.style.textIndent &&
  12926. (para.style.textIndent = parent.style.textIndent);
  12927. parent.style.padding &&
  12928. !para.style.padding &&
  12929. (para.style.padding = parent.style.padding);
  12930. }
  12931. // trace:1706 选择的就是h1-6要删除
  12932. if(attrs && /h\d/i.test(parent.tagName) &&
  12933. !/h\d/i.test(para.tagName)) {
  12934. domUtils.setAttributes(parent, attrs);
  12935. if(sourceCmdName && sourceCmdName == 'customstyle' &&
  12936. attrs.style) {
  12937. parent.style.cssText = attrs.style;
  12938. }
  12939. domUtils.remove(para, true);
  12940. para = parent;
  12941. } else {
  12942. domUtils.remove(para.parentNode, true);
  12943. }
  12944. }
  12945. if(utils.indexOf(notExchange, parent.tagName) != -1) {
  12946. current = parent;
  12947. } else {
  12948. current = para;
  12949. }
  12950. current = domUtils.getNextDomNode(current, false, filterFn);
  12951. } else {
  12952. current = domUtils.getNextDomNode(current, true, filterFn);
  12953. }
  12954. }
  12955. return range.moveToBookmark(bookmark2).moveToBookmark(bookmark);
  12956. };
  12957. me.setOpt('paragraph', {
  12958. 'p': '',
  12959. 'h1': '',
  12960. 'h2': '',
  12961. 'h3': '',
  12962. 'h4': '',
  12963. 'h5': '',
  12964. 'h6': ''
  12965. });
  12966. me.commands['paragraph'] = {
  12967. execCommand: function(cmdName, style, attrs, sourceCmdName) {
  12968. var range = this.selection.getRange();
  12969. // 闭合时单独处理
  12970. if(range.collapsed) {
  12971. var txt = this.document.createTextNode('p');
  12972. range.insertNode(txt);
  12973. // 去掉冗余的fillchar
  12974. if(browser.ie) {
  12975. var node = txt.previousSibling;
  12976. if(node && domUtils.isWhitespace(node)) {
  12977. domUtils.remove(node);
  12978. }
  12979. node = txt.nextSibling;
  12980. if(node && domUtils.isWhitespace(node)) {
  12981. domUtils.remove(node);
  12982. }
  12983. }
  12984. }
  12985. range = doParagraph(range, style, attrs, sourceCmdName);
  12986. if(txt) {
  12987. range.setStartBefore(txt).collapse(true);
  12988. pN = txt.parentNode;
  12989. domUtils.remove(txt);
  12990. if(domUtils.isBlockElm(pN) && domUtils.isEmptyNode(pN)) {
  12991. domUtils.fillNode(this.document, pN);
  12992. }
  12993. }
  12994. if(browser.gecko && range.collapsed &&
  12995. range.startContainer.nodeType == 1) {
  12996. var child = range.startContainer.childNodes[range.startOffset];
  12997. if(child && child.nodeType == 1 &&
  12998. child.tagName.toLowerCase() == style) {
  12999. range.setStart(child, 0).collapse(true);
  13000. }
  13001. }
  13002. // trace:1097 原来有true,原因忘了,但去了就不能清除多余的占位符了
  13003. range.select();
  13004. return true;
  13005. },
  13006. queryCommandValue: function() {
  13007. var node = domUtils.filterNodeList(this.selection
  13008. .getStartElementPath(), 'p h1 h2 h3 h4 h5 h6');
  13009. return node ? node.tagName.toLowerCase() : '';
  13010. }
  13011. };
  13012. };
  13013. // plugins/directionality.js
  13014. /**
  13015. * 设置文字输入的方向的插件
  13016. *
  13017. * @file
  13018. * @since 1.2.6.1
  13019. */
  13020. (function() {
  13021. var block = domUtils.isBlockElm,
  13022. getObj = function(editor) {
  13023. // var startNode = editor.selection.getStart(),
  13024. // parents;
  13025. // if ( startNode ) {
  13026. // //查找所有的是block的父亲节点
  13027. // parents = domUtils.findParents( startNode, true, block, true
  13028. // );
  13029. // for ( var i = 0,ci; ci = parents[i++]; ) {
  13030. // if ( ci.getAttribute( 'dir' ) ) {
  13031. // return ci;
  13032. // }
  13033. // }
  13034. // }
  13035. return domUtils.filterNodeList(editor.selection
  13036. .getStartElementPath(),
  13037. function(n) {
  13038. return n && n.nodeType == 1 && n.getAttribute('dir')
  13039. });
  13040. },
  13041. doDirectionality = function(range, editor, forward) {
  13042. var bookmark, filterFn = function(node) {
  13043. return node.nodeType == 1 ?
  13044. !domUtils.isBookmarkNode(node) :
  13045. !domUtils.isWhitespace(node);
  13046. },
  13047. obj = getObj(editor);
  13048. if(obj && range.collapsed) {
  13049. obj.setAttribute('dir', forward);
  13050. return range;
  13051. }
  13052. bookmark = range.createBookmark();
  13053. range.enlarge(true);
  13054. var bookmark2 = range.createBookmark(),
  13055. current = domUtils
  13056. .getNextDomNode(bookmark2.start, false, filterFn),
  13057. tmpRange = range
  13058. .cloneRange(),
  13059. tmpNode;
  13060. while(current &&
  13061. !(domUtils.getPosition(current, bookmark2.end) & domUtils.POSITION_FOLLOWING)) {
  13062. if(current.nodeType == 3 || !block(current)) {
  13063. tmpRange.setStartBefore(current);
  13064. while(current && current !== bookmark2.end &&
  13065. !block(current)) {
  13066. tmpNode = current;
  13067. current = domUtils.getNextDomNode(current, false, null,
  13068. function(node) {
  13069. return !block(node);
  13070. });
  13071. }
  13072. tmpRange.setEndAfter(tmpNode);
  13073. var common = tmpRange.getCommonAncestor();
  13074. if(!domUtils.isBody(common) && block(common)) {
  13075. // 遍历到了block节点
  13076. common.setAttribute('dir', forward);
  13077. current = common;
  13078. } else {
  13079. // 没有遍历到,添加一个block节点
  13080. var p = range.document.createElement('p');
  13081. p.setAttribute('dir', forward);
  13082. var frag = tmpRange.extractContents();
  13083. p.appendChild(frag);
  13084. tmpRange.insertNode(p);
  13085. current = p;
  13086. }
  13087. current = domUtils.getNextDomNode(current, false, filterFn);
  13088. } else {
  13089. current = domUtils.getNextDomNode(current, true, filterFn);
  13090. }
  13091. }
  13092. return range.moveToBookmark(bookmark2).moveToBookmark(bookmark);
  13093. };
  13094. /**
  13095. * 文字输入方向
  13096. *
  13097. * @command directionality
  13098. * @method execCommand
  13099. * @param {
  13100. * String } cmdName 命令字符串
  13101. * @param {
  13102. * String } forward 传入'ltr'表示从左向右输入,传入'rtl'表示从右向左输入
  13103. * @example ```javascript editor.execCommand( 'directionality', 'ltr');
  13104. * ```
  13105. */
  13106. /**
  13107. * 查询当前选区的文字输入方向
  13108. *
  13109. * @command directionality
  13110. * @method queryCommandValue
  13111. * @param {
  13112. * String } cmdName 命令字符串
  13113. * @return { String } 返回'ltr'表示从左向右输入,返回'rtl'表示从右向左输入
  13114. * @example ```javascript editor.queryCommandValue( 'directionality');
  13115. * ```
  13116. */
  13117. UE.commands['directionality'] = {
  13118. execCommand: function(cmdName, forward) {
  13119. var range = this.selection.getRange();
  13120. // 闭合时单独处理
  13121. if(range.collapsed) {
  13122. var txt = this.document.createTextNode('d');
  13123. range.insertNode(txt);
  13124. }
  13125. doDirectionality(range, this, forward);
  13126. if(txt) {
  13127. range.setStartBefore(txt).collapse(true);
  13128. domUtils.remove(txt);
  13129. }
  13130. range.select();
  13131. return true;
  13132. },
  13133. queryCommandValue: function() {
  13134. var node = getObj(this);
  13135. return node ? node.getAttribute('dir') : 'ltr';
  13136. }
  13137. };
  13138. })();
  13139. // plugins/horizontal.js
  13140. /**
  13141. * 插入分割线插件
  13142. *
  13143. * @file
  13144. * @since 1.2.6.1
  13145. */
  13146. /**
  13147. * 插入分割线
  13148. *
  13149. * @command horizontal
  13150. * @method execCommand
  13151. * @param {
  13152. * String } cmdName 命令字符串
  13153. * @example ```javascript editor.execCommand( 'horizontal' ); ```
  13154. */
  13155. UE.plugins['horizontal'] = function() {
  13156. var me = this;
  13157. me.commands['horizontal'] = {
  13158. execCommand: function(cmdName) {
  13159. var me = this;
  13160. if(me.queryCommandState(cmdName) !== -1) {
  13161. me.execCommand('insertHtml', '<hr>');
  13162. var range = me.selection.getRange(),
  13163. start = range.startContainer;
  13164. if(start.nodeType == 1 &&
  13165. !start.childNodes[range.startOffset]) {
  13166. var tmp;
  13167. if(tmp = start.childNodes[range.startOffset - 1]) {
  13168. if(tmp.nodeType == 1 && tmp.tagName == 'HR') {
  13169. if(me.options.enterTag == 'p') {
  13170. tmp = me.document.createElement('p');
  13171. range.insertNode(tmp);
  13172. range.setStart(tmp, 0).setCursor();
  13173. } else {
  13174. tmp = me.document.createElement('br');
  13175. range.insertNode(tmp);
  13176. range.setStartBefore(tmp).setCursor();
  13177. }
  13178. }
  13179. }
  13180. }
  13181. return true;
  13182. }
  13183. },
  13184. // 边界在table里不能加分隔线
  13185. queryCommandState: function() {
  13186. return domUtils.filterNodeList(this.selection
  13187. .getStartElementPath(), 'table') ? -1 : 0;
  13188. }
  13189. };
  13190. // me.addListener('delkeyup',function(){
  13191. // var rng = this.selection.getRange();
  13192. // if(browser.ie && browser.version > 8){
  13193. // rng.txtToElmBoundary(true);
  13194. // if(domUtils.isStartInblock(rng)){
  13195. // var tmpNode = rng.startContainer;
  13196. // var pre = tmpNode.previousSibling;
  13197. // if(pre && domUtils.isTagNode(pre,'hr')){
  13198. // domUtils.remove(pre);
  13199. // rng.select();
  13200. // return;
  13201. // }
  13202. // }
  13203. // }
  13204. // if(domUtils.isBody(rng.startContainer)){
  13205. // var hr = rng.startContainer.childNodes[rng.startOffset -1];
  13206. // if(hr && hr.nodeName == 'HR'){
  13207. // var next = hr.nextSibling;
  13208. // if(next){
  13209. // rng.setStart(next,0)
  13210. // }else if(hr.previousSibling){
  13211. // rng.setStartAtLast(hr.previousSibling)
  13212. // }else{
  13213. // var p = this.document.createElement('p');
  13214. // hr.parentNode.insertBefore(p,hr);
  13215. // domUtils.fillNode(this.document,p);
  13216. // rng.setStart(p,0);
  13217. // }
  13218. // domUtils.remove(hr);
  13219. // rng.setCursor(false,true);
  13220. // }
  13221. // }
  13222. // })
  13223. me.addListener('delkeydown', function(name, evt) {
  13224. var rng = this.selection.getRange();
  13225. rng.txtToElmBoundary(true);
  13226. if(domUtils.isStartInblock(rng)) {
  13227. var tmpNode = rng.startContainer;
  13228. var pre = tmpNode.previousSibling;
  13229. if(pre && domUtils.isTagNode(pre, 'hr')) {
  13230. domUtils.remove(pre);
  13231. rng.select();
  13232. domUtils.preventDefault(evt);
  13233. return true;
  13234. }
  13235. }
  13236. })
  13237. };
  13238. // plugins/time.js
  13239. /**
  13240. * 插入时间和日期
  13241. *
  13242. * @file
  13243. * @since 1.2.6.1
  13244. */
  13245. /**
  13246. * 插入时间,默认格式:12:59:59
  13247. *
  13248. * @command time
  13249. * @method execCommand
  13250. * @param {
  13251. * String } cmd 命令字符串
  13252. * @example ```javascript editor.execCommand( 'time'); ```
  13253. */
  13254. /**
  13255. * 插入日期,默认格式:2013-08-30
  13256. *
  13257. * @command date
  13258. * @method execCommand
  13259. * @param {
  13260. * String } cmd 命令字符串
  13261. * @example ```javascript editor.execCommand( 'date'); ```
  13262. */
  13263. UE.commands['time'] = UE.commands["date"] = {
  13264. execCommand: function(cmd, format) {
  13265. var date = new Date;
  13266. function formatTime(date, format) {
  13267. var hh = ('0' + date.getHours()).slice(-2),
  13268. ii = ('0' + date
  13269. .getMinutes()).slice(-2),
  13270. ss = ('0' + date.getSeconds())
  13271. .slice(-2);
  13272. format = format || 'hh:ii:ss';
  13273. return format.replace(/hh/ig, hh).replace(/ii/ig, ii).replace(
  13274. /ss/ig, ss);
  13275. }
  13276. function formatDate(date, format) {
  13277. var yyyy = ('000' + date.getFullYear()).slice(-4),
  13278. yy = yyyy
  13279. .slice(-2),
  13280. mm = ('0' + (date.getMonth() + 1))
  13281. .slice(-2),
  13282. dd = ('0' + date.getDate()).slice(-2);
  13283. format = format || 'yyyy-mm-dd';
  13284. return format.replace(/yyyy/ig, yyyy).replace(/yy/ig, yy)
  13285. .replace(/mm/ig, mm).replace(/dd/ig, dd);
  13286. }
  13287. this.execCommand('insertHtml', cmd == "time" ? formatTime(date,
  13288. format) : formatDate(date, format));
  13289. }
  13290. };
  13291. // plugins/rowspacing.js
  13292. /**
  13293. * 段前段后间距插件
  13294. *
  13295. * @file
  13296. * @since 1.2.6.1
  13297. */
  13298. /**
  13299. * 设置段间距
  13300. *
  13301. * @command rowspacing
  13302. * @method execCommand
  13303. * @param {
  13304. * String } cmd 命令字符串
  13305. * @param {
  13306. * String } value 段间距的值,以px为单位
  13307. * @param {
  13308. * String } dir 间距位置,top或bottom,分别表示段前和段后
  13309. * @example ```javascript editor.execCommand( 'rowspacing', '10', 'top' );
  13310. * ```
  13311. */
  13312. UE.plugins['rowspacing'] = function() {
  13313. var me = this;
  13314. me.setOpt({
  13315. 'rowspacingtop': ['5', '10', '15', '20', '25'],
  13316. 'rowspacingbottom': ['5', '10', '15', '20', '25']
  13317. });
  13318. me.commands['rowspacing'] = {
  13319. execCommand: function(cmdName, value, dir) {
  13320. this.execCommand('paragraph', 'p', {
  13321. style: 'margin-' + dir + ':' + value + 'px'
  13322. });
  13323. return true;
  13324. },
  13325. queryCommandValue: function(cmdName, dir) {
  13326. var pN = domUtils.filterNodeList(this.selection
  13327. .getStartElementPath(),
  13328. function(node) {
  13329. return domUtils.isBlockElm(node)
  13330. }),
  13331. value;
  13332. // trace:1026
  13333. if(pN) {
  13334. value = domUtils.getComputedStyle(pN, 'margin-' + dir)
  13335. .replace(/[^\d]/g, '');
  13336. return !value ? 0 : value;
  13337. }
  13338. return 0;
  13339. }
  13340. };
  13341. };
  13342. // plugins/lineheight.js
  13343. /**
  13344. * 设置行内间距
  13345. *
  13346. * @file
  13347. * @since 1.2.6.1
  13348. */
  13349. UE.plugins['lineheight'] = function() {
  13350. var me = this;
  13351. me.setOpt({
  13352. 'lineheight': ['1', '1.5', '1.75', '2', '3', '4', '5']
  13353. });
  13354. /**
  13355. * 行距
  13356. *
  13357. * @command lineheight
  13358. * @method execCommand
  13359. * @param {
  13360. * String } cmdName 命令字符串
  13361. * @param {
  13362. * String } value 传入的行高值, 该值是当前字体的倍数, 例如: 1.5, 1.75
  13363. * @example ```javascript editor.execCommand( 'lineheight', 1.5); ```
  13364. */
  13365. /**
  13366. * 查询当前选区内容的行高大小
  13367. *
  13368. * @command lineheight
  13369. * @method queryCommandValue
  13370. * @param {
  13371. * String } cmd 命令字符串
  13372. * @return { String } 返回当前行高大小
  13373. * @example ```javascript editor.queryCommandValue( 'lineheight' ); ```
  13374. */
  13375. me.commands['lineheight'] = {
  13376. execCommand: function(cmdName, value) {
  13377. this.execCommand('paragraph', 'p', {
  13378. style: 'line-height:' +
  13379. (value == "1" ? "normal" : value + 'em')
  13380. });
  13381. return true;
  13382. },
  13383. queryCommandValue: function() {
  13384. var pN = domUtils.filterNodeList(this.selection
  13385. .getStartElementPath(),
  13386. function(node) {
  13387. return domUtils.isBlockElm(node)
  13388. });
  13389. if(pN) {
  13390. var value = domUtils.getComputedStyle(pN, 'line-height');
  13391. return value == 'normal' ? 1 : value.replace(/[^\d.]*/ig,
  13392. "");
  13393. }
  13394. }
  13395. };
  13396. };
  13397. // plugins/insertcode.js
  13398. /**
  13399. * 插入代码插件
  13400. *
  13401. * @file
  13402. * @since 1.2.6.1
  13403. */
  13404. UE.plugins['insertcode'] = function() {
  13405. var me = this;
  13406. me.ready(function() {
  13407. utils
  13408. .cssRule(
  13409. 'pre',
  13410. 'pre{margin:.5em 0;padding:.4em .6em;border-radius:8px;background:#f8f8f8;}',
  13411. me.document)
  13412. });
  13413. me.setOpt('insertcode', {
  13414. 'as3': 'ActionScript3',
  13415. 'bash': 'Bash/Shell',
  13416. 'cpp': 'C/C++',
  13417. 'css': 'Css',
  13418. 'cf': 'CodeFunction',
  13419. 'c#': 'C#',
  13420. 'delphi': 'Delphi',
  13421. 'diff': 'Diff',
  13422. 'erlang': 'Erlang',
  13423. 'groovy': 'Groovy',
  13424. 'html': 'Html',
  13425. 'java': 'Java',
  13426. 'jfx': 'JavaFx',
  13427. 'js': 'Javascript',
  13428. 'pl': 'Perl',
  13429. 'php': 'Php',
  13430. 'plain': 'Plain Text',
  13431. 'ps': 'PowerShell',
  13432. 'python': 'Python',
  13433. 'ruby': 'Ruby',
  13434. 'scala': 'Scala',
  13435. 'sql': 'Sql',
  13436. 'vb': 'Vb',
  13437. 'xml': 'Xml'
  13438. });
  13439. /**
  13440. * 插入代码
  13441. *
  13442. * @command insertcode
  13443. * @method execCommand
  13444. * @param {
  13445. * String } cmd 命令字符串
  13446. * @param {
  13447. * String } lang 插入代码的语言
  13448. * @example ```javascript editor.execCommand( 'insertcode', 'javascript' );
  13449. * ```
  13450. */
  13451. /**
  13452. * 如果选区所在位置是插入插入代码区域,返回代码的语言
  13453. *
  13454. * @command insertcode
  13455. * @method queryCommandValue
  13456. * @param {
  13457. * String } cmd 命令字符串
  13458. * @return { String } 返回代码的语言
  13459. * @example ```javascript editor.queryCommandValue( 'insertcode' ); ```
  13460. */
  13461. me.commands['insertcode'] = {
  13462. execCommand: function(cmd, lang) {
  13463. var me = this,
  13464. rng = me.selection.getRange(),
  13465. pre = domUtils
  13466. .findParentByTagName(rng.startContainer, 'pre', true);
  13467. if(pre) {
  13468. pre.className = 'brush:' + lang + ';toolbar:false;';
  13469. } else {
  13470. var code = '';
  13471. if(rng.collapsed) {
  13472. code = browser.ie && browser.ie11below ?
  13473. (browser.version <= 8 ? '&nbsp;' : '') :
  13474. '<br/>';
  13475. } else {
  13476. var frag = rng.extractContents();
  13477. var div = me.document.createElement('div');
  13478. div.appendChild(frag);
  13479. utils.each(UE.filterNode(UE.htmlparser(div.innerHTML
  13480. .replace(/[\r\t]/g, '')),
  13481. me.options.filterTxtRules).children, function(
  13482. node) {
  13483. if(browser.ie && browser.ie11below &&
  13484. browser.version > 8) {
  13485. if(node.type == 'element') {
  13486. if(node.tagName == 'br') {
  13487. code += '\n'
  13488. } else if(!dtd.$empty[node.tagName]) {
  13489. utils.each(node.children, function(cn) {
  13490. if(cn.type == 'element') {
  13491. if(cn.tagName == 'br') {
  13492. code += '\n'
  13493. } else if(!dtd.$empty[node.tagName]) {
  13494. code += cn.innerText();
  13495. }
  13496. } else {
  13497. code += cn.data
  13498. }
  13499. })
  13500. if(!/\n$/.test(code)) {
  13501. code += '\n';
  13502. }
  13503. }
  13504. } else {
  13505. code += node.data + '\n'
  13506. }
  13507. if(!node.nextSibling() && /\n$/.test(code)) {
  13508. code = code.replace(/\n$/, '');
  13509. }
  13510. } else {
  13511. if(browser.ie && browser.ie11below) {
  13512. if(node.type == 'element') {
  13513. if(node.tagName == 'br') {
  13514. code += '<br>'
  13515. } else if(!dtd.$empty[node.tagName]) {
  13516. utils.each(node.children, function(
  13517. cn) {
  13518. if(cn.type == 'element') {
  13519. if(cn.tagName == 'br') {
  13520. code += '<br>'
  13521. } else if(!dtd.$empty[node.tagName]) {
  13522. code += cn.innerText();
  13523. }
  13524. } else {
  13525. code += cn.data
  13526. }
  13527. });
  13528. if(!/br>$/.test(code)) {
  13529. code += '<br>';
  13530. }
  13531. }
  13532. } else {
  13533. code += node.data + '<br>'
  13534. }
  13535. if(!node.nextSibling() &&
  13536. /<br>$/.test(code)) {
  13537. code = code.replace(/<br>$/, '');
  13538. }
  13539. } else {
  13540. code += (node.type == 'element' ?
  13541. (dtd.$empty[node.tagName] ?
  13542. '' :
  13543. node.innerText()) :
  13544. node.data);
  13545. if(!/br\/?\s*>$/.test(code)) {
  13546. if(!node.nextSibling())
  13547. return;
  13548. code += '<br>'
  13549. }
  13550. }
  13551. }
  13552. });
  13553. }
  13554. me
  13555. .execCommand('inserthtml',
  13556. '<pre id="coder"class="brush:' + lang +
  13557. ';toolbar:false">' + code +
  13558. '</pre>', true);
  13559. pre = me.document.getElementById('coder');
  13560. domUtils.removeAttributes(pre, 'id');
  13561. var tmpNode = pre.previousSibling;
  13562. if(tmpNode &&
  13563. (tmpNode.nodeType == 3 &&
  13564. tmpNode.nodeValue.length == 1 &&
  13565. browser.ie && browser.version == 6 || domUtils
  13566. .isEmptyBlock(tmpNode))) {
  13567. domUtils.remove(tmpNode)
  13568. }
  13569. var rng = me.selection.getRange();
  13570. if(domUtils.isEmptyBlock(pre)) {
  13571. rng.setStart(pre, 0).setCursor(false, true)
  13572. } else {
  13573. rng.selectNodeContents(pre).select()
  13574. }
  13575. }
  13576. },
  13577. queryCommandValue: function() {
  13578. var path = this.selection.getStartElementPath();
  13579. var lang = '';
  13580. utils.each(path, function(node) {
  13581. if(node.nodeName == 'PRE') {
  13582. var match = node.className.match(/brush:([^;]+)/);
  13583. lang = match && match[1] ? match[1] : '';
  13584. return false;
  13585. }
  13586. });
  13587. return lang;
  13588. }
  13589. };
  13590. me.addInputRule(function(root) {
  13591. utils.each(root.getNodesByTagName('pre'), function(pre) {
  13592. var brs = pre.getNodesByTagName('br');
  13593. if(brs.length) {
  13594. browser.ie && browser.ie11below && browser.version > 8 &&
  13595. utils.each(brs, function(br) {
  13596. var txt = UE.uNode.createText('\n');
  13597. br.parentNode.insertBefore(txt, br);
  13598. br.parentNode.removeChild(br);
  13599. });
  13600. return;
  13601. }
  13602. if(browser.ie && browser.ie11below && browser.version > 8)
  13603. return;
  13604. var code = pre.innerText().split(/\n/);
  13605. pre.innerHTML('');
  13606. utils.each(code, function(c) {
  13607. if(c.length) {
  13608. pre.appendChild(UE.uNode.createText(c));
  13609. }
  13610. pre.appendChild(UE.uNode.createElement('br'))
  13611. })
  13612. })
  13613. });
  13614. me.addOutputRule(function(root) {
  13615. utils.each(root.getNodesByTagName('pre'), function(pre) {
  13616. var code = '';
  13617. utils.each(pre.children, function(n) {
  13618. if(n.type == 'text') {
  13619. // 在ie下文本内容有可能末尾带有\n要去掉
  13620. // trace:3396
  13621. code += n.data.replace(/[ ]/g, '&nbsp;').replace(/\n$/,
  13622. '');
  13623. } else {
  13624. if(n.tagName == 'br') {
  13625. code += '\n'
  13626. } else {
  13627. code += (!dtd.$empty[n.tagName] ? '' : n
  13628. .innerText());
  13629. }
  13630. }
  13631. });
  13632. pre.innerText(code.replace(/(&nbsp;|\n)+$/, ''))
  13633. })
  13634. });
  13635. // 不需要判断highlight的command列表
  13636. me.notNeedCodeQuery = {
  13637. help: 1,
  13638. undo: 1,
  13639. redo: 1,
  13640. source: 1,
  13641. print: 1,
  13642. searchreplace: 1,
  13643. fullscreen: 1,
  13644. preview: 1,
  13645. insertparagraph: 1,
  13646. elementpath: 1,
  13647. insertcode: 1,
  13648. inserthtml: 1,
  13649. selectall: 1
  13650. };
  13651. // 将queyCommamndState重置
  13652. var orgQuery = me.queryCommandState;
  13653. me.queryCommandState = function(cmd) {
  13654. var me = this;
  13655. if(!me.notNeedCodeQuery[cmd.toLowerCase()] && me.selection &&
  13656. me.queryCommandValue('insertcode')) {
  13657. return -1;
  13658. }
  13659. return UE.Editor.prototype.queryCommandState.apply(this, arguments)
  13660. };
  13661. me.addListener('beforeenterkeydown', function() {
  13662. var rng = me.selection.getRange();
  13663. var pre = domUtils.findParentByTagName(rng.startContainer, 'pre',
  13664. true);
  13665. if(pre) {
  13666. me.fireEvent('saveScene');
  13667. if(!rng.collapsed) {
  13668. rng.deleteContents();
  13669. }
  13670. if(!browser.ie || browser.ie9above) {
  13671. var tmpNode = me.document.createElement('br'),
  13672. pre;
  13673. rng.insertNode(tmpNode).setStartAfter(tmpNode)
  13674. .collapse(true);
  13675. var next = tmpNode.nextSibling;
  13676. if(!next && (!browser.ie || browser.version > 10)) {
  13677. rng.insertNode(tmpNode.cloneNode(false));
  13678. } else {
  13679. rng.setStartAfter(tmpNode);
  13680. }
  13681. pre = tmpNode.previousSibling;
  13682. var tmp;
  13683. while(pre) {
  13684. tmp = pre;
  13685. pre = pre.previousSibling;
  13686. if(!pre || pre.nodeName == 'BR') {
  13687. pre = tmp;
  13688. break;
  13689. }
  13690. }
  13691. if(pre) {
  13692. var str = '';
  13693. while(pre &&
  13694. pre.nodeName != 'BR' &&
  13695. new RegExp('^[\\s' + domUtils.fillChar +
  13696. ']*$').test(pre.nodeValue)) {
  13697. str += pre.nodeValue;
  13698. pre = pre.nextSibling;
  13699. }
  13700. if(pre.nodeName != 'BR') {
  13701. var match = pre.nodeValue.match(new RegExp('^([\\s' +
  13702. domUtils.fillChar + ']+)'));
  13703. if(match && match[1]) {
  13704. str += match[1]
  13705. }
  13706. }
  13707. if(str) {
  13708. str = me.document.createTextNode(str);
  13709. rng.insertNode(str).setStartAfter(str);
  13710. }
  13711. }
  13712. rng.collapse(true).select(true);
  13713. } else {
  13714. if(browser.version > 8) {
  13715. var txt = me.document.createTextNode('\n');
  13716. var start = rng.startContainer;
  13717. if(rng.startOffset == 0) {
  13718. var preNode = start.previousSibling;
  13719. if(preNode) {
  13720. rng.insertNode(txt);
  13721. var fillchar = me.document.createTextNode(' ');
  13722. rng.setStartAfter(txt).insertNode(fillchar)
  13723. .setStart(fillchar, 0).collapse(true)
  13724. .select(true)
  13725. }
  13726. } else {
  13727. rng.insertNode(txt).setStartAfter(txt);
  13728. var fillchar = me.document.createTextNode(' ');
  13729. start = rng.startContainer.childNodes[rng.startOffset];
  13730. if(start && !/^\n/.test(start.nodeValue)) {
  13731. rng.setStartBefore(txt)
  13732. }
  13733. rng.insertNode(fillchar).setStart(fillchar, 0)
  13734. .collapse(true).select(true)
  13735. }
  13736. } else {
  13737. var tmpNode = me.document.createElement('br');
  13738. rng.insertNode(tmpNode);
  13739. rng.insertNode(me.document
  13740. .createTextNode(domUtils.fillChar));
  13741. rng.setStartAfter(tmpNode);
  13742. pre = tmpNode.previousSibling;
  13743. var tmp;
  13744. while(pre) {
  13745. tmp = pre;
  13746. pre = pre.previousSibling;
  13747. if(!pre || pre.nodeName == 'BR') {
  13748. pre = tmp;
  13749. break;
  13750. }
  13751. }
  13752. if(pre) {
  13753. var str = '';
  13754. while(pre &&
  13755. pre.nodeName != 'BR' &&
  13756. new RegExp('^[ ' + domUtils.fillChar +
  13757. ']*$').test(pre.nodeValue)) {
  13758. str += pre.nodeValue;
  13759. pre = pre.nextSibling;
  13760. }
  13761. if(pre.nodeName != 'BR') {
  13762. var match = pre.nodeValue
  13763. .match(new RegExp('^([ ' +
  13764. domUtils.fillChar + ']+)'));
  13765. if(match && match[1]) {
  13766. str += match[1]
  13767. }
  13768. }
  13769. str = me.document.createTextNode(str);
  13770. rng.insertNode(str).setStartAfter(str);
  13771. }
  13772. rng.collapse(true).select();
  13773. }
  13774. }
  13775. me.fireEvent('saveScene');
  13776. return true;
  13777. }
  13778. });
  13779. me.addListener('tabkeydown', function(cmd, evt) {
  13780. var rng = me.selection.getRange();
  13781. var pre = domUtils.findParentByTagName(rng.startContainer, 'pre',
  13782. true);
  13783. if(pre) {
  13784. me.fireEvent('saveScene');
  13785. if(evt.shiftKey) {
  13786. } else {
  13787. if(!rng.collapsed) {
  13788. var bk = rng.createBookmark();
  13789. var start = bk.start.previousSibling;
  13790. while(start) {
  13791. if(pre.firstChild === start &&
  13792. !domUtils.isBr(start)) {
  13793. pre.insertBefore(me.document
  13794. .createTextNode(' '), start);
  13795. break;
  13796. }
  13797. if(domUtils.isBr(start)) {
  13798. pre.insertBefore(me.document
  13799. .createTextNode(' '),
  13800. start.nextSibling);
  13801. break;
  13802. }
  13803. start = start.previousSibling;
  13804. }
  13805. var end = bk.end;
  13806. start = bk.start.nextSibling;
  13807. if(pre.firstChild === bk.start) {
  13808. pre.insertBefore(
  13809. me.document.createTextNode(' '),
  13810. start.nextSibling)
  13811. }
  13812. while(start && start !== end) {
  13813. if(domUtils.isBr(start) && start.nextSibling) {
  13814. if(start.nextSibling === end) {
  13815. break;
  13816. }
  13817. pre.insertBefore(me.document
  13818. .createTextNode(' '),
  13819. start.nextSibling)
  13820. }
  13821. start = start.nextSibling;
  13822. }
  13823. rng.moveToBookmark(bk).select();
  13824. } else {
  13825. var tmpNode = me.document.createTextNode(' ');
  13826. rng.insertNode(tmpNode).setStartAfter(tmpNode)
  13827. .collapse(true).select(true);
  13828. }
  13829. }
  13830. me.fireEvent('saveScene');
  13831. return true;
  13832. }
  13833. });
  13834. me.addListener('beforeinserthtml', function(evtName, html) {
  13835. var me = this,
  13836. rng = me.selection.getRange(),
  13837. pre = domUtils
  13838. .findParentByTagName(rng.startContainer, 'pre', true);
  13839. if(pre) {
  13840. if(!rng.collapsed) {
  13841. rng.deleteContents()
  13842. }
  13843. var htmlstr = '';
  13844. if(browser.ie && browser.version > 8) {
  13845. utils.each(UE.filterNode(UE.htmlparser(html),
  13846. me.options.filterTxtRules).children,
  13847. function(node) {
  13848. if(node.type == 'element') {
  13849. if(node.tagName == 'br') {
  13850. htmlstr += '\n'
  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. htmlstr += '\n'
  13856. } else if(!dtd.$empty[node.tagName]) {
  13857. htmlstr += cn.innerText();
  13858. }
  13859. } else {
  13860. htmlstr += cn.data
  13861. }
  13862. })
  13863. if(!/\n$/.test(htmlstr)) {
  13864. htmlstr += '\n';
  13865. }
  13866. }
  13867. } else {
  13868. htmlstr += node.data + '\n'
  13869. }
  13870. if(!node.nextSibling() && /\n$/.test(htmlstr)) {
  13871. htmlstr = htmlstr.replace(/\n$/, '');
  13872. }
  13873. });
  13874. var tmpNode = me.document.createTextNode(utils.html(htmlstr
  13875. .replace(/&nbsp;/g, ' ')));
  13876. rng.insertNode(tmpNode).selectNode(tmpNode).select();
  13877. } else {
  13878. var frag = me.document.createDocumentFragment();
  13879. utils.each(UE.filterNode(UE.htmlparser(html),
  13880. me.options.filterTxtRules).children,
  13881. function(node) {
  13882. if(node.type == 'element') {
  13883. if(node.tagName == 'br') {
  13884. frag.appendChild(me.document
  13885. .createElement('br'))
  13886. } else if(!dtd.$empty[node.tagName]) {
  13887. utils.each(node.children, function(cn) {
  13888. if(cn.type == 'element') {
  13889. if(cn.tagName == 'br') {
  13890. frag
  13891. .appendChild(me.document
  13892. .createElement('br'))
  13893. } else if(!dtd.$empty[node.tagName]) {
  13894. frag
  13895. .appendChild(me.document
  13896. .createTextNode(utils
  13897. .html(cn
  13898. .innerText()
  13899. .replace(
  13900. /&nbsp;/g,
  13901. ' '))));
  13902. }
  13903. } else {
  13904. frag
  13905. .appendChild(me.document
  13906. .createTextNode(utils
  13907. .html(cn.data
  13908. .replace(
  13909. /&nbsp;/g,
  13910. ' '))));
  13911. }
  13912. })
  13913. if(frag.lastChild.nodeName != 'BR') {
  13914. frag.appendChild(me.document
  13915. .createElement('br'))
  13916. }
  13917. }
  13918. } else {
  13919. frag.appendChild(me.document
  13920. .createTextNode(utils
  13921. .html(node.data.replace(
  13922. /&nbsp;/g, ' '))));
  13923. }
  13924. if(!node.nextSibling() &&
  13925. frag.lastChild.nodeName == 'BR') {
  13926. frag.removeChild(frag.lastChild)
  13927. }
  13928. });
  13929. rng.insertNode(frag).select();
  13930. }
  13931. return true;
  13932. }
  13933. });
  13934. // 方向键的处理
  13935. me.addListener('keydown', function(cmd, evt) {
  13936. var me = this,
  13937. keyCode = evt.keyCode || evt.which;
  13938. if(keyCode == 40) {
  13939. var rng = me.selection.getRange(),
  13940. pre, start = rng.startContainer;
  13941. if(rng.collapsed &&
  13942. (pre = domUtils.findParentByTagName(
  13943. rng.startContainer, 'pre', true)) &&
  13944. !pre.nextSibling) {
  13945. var last = pre.lastChild
  13946. while(last && last.nodeName == 'BR') {
  13947. last = last.previousSibling;
  13948. }
  13949. if(last === start || rng.startContainer === pre &&
  13950. rng.startOffset == pre.childNodes.length) {
  13951. me.execCommand('insertparagraph');
  13952. domUtils.preventDefault(evt)
  13953. }
  13954. }
  13955. }
  13956. });
  13957. // trace:3395
  13958. me.addListener('delkeydown', function(type, evt) {
  13959. var rng = this.selection.getRange();
  13960. rng.txtToElmBoundary(true);
  13961. var start = rng.startContainer;
  13962. if(domUtils.isTagNode(start, 'pre') && rng.collapsed &&
  13963. domUtils.isStartInblock(rng)) {
  13964. var p = me.document.createElement('p');
  13965. domUtils.fillNode(me.document, p);
  13966. start.parentNode.insertBefore(p, start);
  13967. domUtils.remove(start);
  13968. rng.setStart(p, 0).setCursor(false, true);
  13969. domUtils.preventDefault(evt);
  13970. return true;
  13971. }
  13972. })
  13973. };
  13974. // plugins/cleardoc.js
  13975. /**
  13976. * 清空文档插件
  13977. *
  13978. * @file
  13979. * @since 1.2.6.1
  13980. */
  13981. /**
  13982. * 清空文档
  13983. *
  13984. * @command cleardoc
  13985. * @method execCommand
  13986. * @param {
  13987. * String } cmd 命令字符串
  13988. * @example ```javascript //editor 是编辑器实例 editor.execCommand('cleardoc');
  13989. * ```
  13990. */
  13991. UE.commands['cleardoc'] = {
  13992. execCommand: function(cmdName) {
  13993. var me = this,
  13994. enterTag = me.options.enterTag,
  13995. range = me.selection
  13996. .getRange();
  13997. if(enterTag == "br") {
  13998. me.body.innerHTML = "<br/>";
  13999. range.setStart(me.body, 0).setCursor();
  14000. } else {
  14001. me.body.innerHTML = "<p>" + (ie ? "" : "<br/>") + "</p>";
  14002. range.setStart(me.body.firstChild, 0).setCursor(false, true);
  14003. }
  14004. setTimeout(function() {
  14005. me.fireEvent("clearDoc");
  14006. }, 0);
  14007. }
  14008. };
  14009. // plugins/anchor.js
  14010. /**
  14011. * 锚点插件,为UEditor提供插入锚点支持
  14012. *
  14013. * @file
  14014. * @since 1.2.6.1
  14015. */
  14016. UE.plugin.register('anchor', function() {
  14017. return {
  14018. bindEvents: {
  14019. 'ready': function() {
  14020. utils
  14021. .cssRule(
  14022. 'anchor',
  14023. '.anchorclass{background: url(\'' +
  14024. this.options.themePath +
  14025. this.options.theme +
  14026. '/images/anchor.gif\') no-repeat scroll left center transparent;cursor: auto;display: inline-block;height: 16px;width: 15px;}',
  14027. this.document);
  14028. }
  14029. },
  14030. outputRule: function(root) {
  14031. utils.each(root.getNodesByTagName('img'), function(a) {
  14032. var val;
  14033. if(val = a.getAttr('anchorname')) {
  14034. a.tagName = 'a';
  14035. a.setAttr({
  14036. anchorname: '',
  14037. name: val,
  14038. 'class': ''
  14039. })
  14040. }
  14041. })
  14042. },
  14043. inputRule: function(root) {
  14044. utils.each(root.getNodesByTagName('a'), function(a) {
  14045. var val;
  14046. if((val = a.getAttr('name')) && !a.getAttr('href')) {
  14047. a.tagName = 'img';
  14048. a.setAttr({
  14049. anchorname: a.getAttr('name'),
  14050. 'class': 'anchorclass'
  14051. });
  14052. a.setAttr('name')
  14053. }
  14054. })
  14055. },
  14056. commands: {
  14057. /**
  14058. * 插入锚点
  14059. *
  14060. * @command anchor
  14061. * @method execCommand
  14062. * @param {
  14063. * String } cmd 命令字符串
  14064. * @param {
  14065. * String } name 锚点名称字符串
  14066. * @example ```javascript //editor 是编辑器实例
  14067. * editor.execCommand('anchor', 'anchor1'); ```
  14068. */
  14069. 'anchor': {
  14070. execCommand: function(cmd, name) {
  14071. var range = this.selection.getRange(),
  14072. img = range
  14073. .getClosedNode();
  14074. if(img && img.getAttribute('anchorname')) {
  14075. if(name) {
  14076. img.setAttribute('anchorname', name);
  14077. } else {
  14078. range.setStartBefore(img).setCursor();
  14079. domUtils.remove(img);
  14080. }
  14081. } else {
  14082. if(name) {
  14083. // 只在选区的开始插入
  14084. var anchor = this.document.createElement('img');
  14085. range.collapse(true);
  14086. domUtils.setAttributes(anchor, {
  14087. 'anchorname': name,
  14088. 'class': 'anchorclass'
  14089. });
  14090. range.insertNode(anchor).setStartAfter(anchor)
  14091. .setCursor(false, true);
  14092. }
  14093. }
  14094. }
  14095. }
  14096. }
  14097. }
  14098. });
  14099. // plugins/wordcount.js
  14100. // /import core
  14101. // /commands 字数统计
  14102. // /commandsName WordCount,wordCount
  14103. // /commandsTitle 字数统计
  14104. /*
  14105. * Created by JetBrains WebStorm. User: taoqili Date: 11-9-7 Time: 下午8:18 To
  14106. * change this template use File | Settings | File Templates.
  14107. */
  14108. UE.plugins['wordcount'] = function() {
  14109. var me = this;
  14110. me.setOpt('wordCount', true);
  14111. me.addListener('contentchange', function() {
  14112. me.fireEvent('wordcount');
  14113. });
  14114. var timer;
  14115. me.addListener('ready', function() {
  14116. var me = this;
  14117. domUtils.on(me.body, "keyup", function(evt) {
  14118. var code = evt.keyCode || evt.which,
  14119. // 忽略的按键,ctr,alt,shift,方向键
  14120. ignores = {
  14121. "16": 1,
  14122. "18": 1,
  14123. "20": 1,
  14124. "37": 1,
  14125. "38": 1,
  14126. "39": 1,
  14127. "40": 1
  14128. };
  14129. if(code in ignores)
  14130. return;
  14131. clearTimeout(timer);
  14132. timer = setTimeout(function() {
  14133. me.fireEvent('wordcount');
  14134. }, 200)
  14135. })
  14136. });
  14137. };
  14138. // plugins/pagebreak.js
  14139. /**
  14140. * 分页功能插件
  14141. *
  14142. * @file
  14143. * @since 1.2.6.1
  14144. */
  14145. UE.plugins['pagebreak'] = function() {
  14146. var me = this,
  14147. notBreakTags = ['td'];
  14148. me.setOpt('pageBreakTag', '_ueditor_page_break_tag_');
  14149. function fillNode(node) {
  14150. if(domUtils.isEmptyBlock(node)) {
  14151. var firstChild = node.firstChild,
  14152. tmpNode;
  14153. while(firstChild && firstChild.nodeType == 1 &&
  14154. domUtils.isEmptyBlock(firstChild)) {
  14155. tmpNode = firstChild;
  14156. firstChild = firstChild.firstChild;
  14157. }!tmpNode && (tmpNode = node);
  14158. domUtils.fillNode(me.document, tmpNode);
  14159. }
  14160. }
  14161. // 分页符样式添加
  14162. me.ready(function() {
  14163. utils
  14164. .cssRule(
  14165. 'pagebreak',
  14166. '.pagebreak{display:block;clear:both !important;cursor:default !important;width: 100% !important;margin:0;}',
  14167. me.document);
  14168. });
  14169. function isHr(node) {
  14170. return node && node.nodeType == 1 && node.tagName == 'HR' &&
  14171. node.className == 'pagebreak';
  14172. }
  14173. me.addInputRule(function(root) {
  14174. root.traversal(function(node) {
  14175. if(node.type == 'text' && node.data == me.options.pageBreakTag) {
  14176. var hr = UE.uNode
  14177. .createElement('<hr class="pagebreak" noshade="noshade" size="5" style="-webkit-user-select: none;">');
  14178. node.parentNode.insertBefore(hr, node);
  14179. node.parentNode.removeChild(node)
  14180. }
  14181. })
  14182. });
  14183. me.addOutputRule(function(node) {
  14184. utils.each(node.getNodesByTagName('hr'), function(n) {
  14185. if(n.getAttr('class') == 'pagebreak') {
  14186. var txt = UE.uNode.createText(me.options.pageBreakTag);
  14187. n.parentNode.insertBefore(txt, n);
  14188. n.parentNode.removeChild(n);
  14189. }
  14190. })
  14191. });
  14192. /**
  14193. * 插入分页符
  14194. *
  14195. * @command pagebreak
  14196. * @method execCommand
  14197. * @param {
  14198. * String } cmd 命令字符串
  14199. * @remind 在表格中插入分页符会把表格切分成两部分
  14200. * @remind 获取编辑器内的数据时, 编辑器会把分页符转换成“_ueditor_page_break_tag_”字符串,
  14201. * 以便于提交数据到服务器端后处理分页。
  14202. * @example ```javascript editor.execCommand( 'pagebreak');
  14203. * //插入一个hr标签,带有样式类名pagebreak ```
  14204. */
  14205. me.commands['pagebreak'] = {
  14206. execCommand: function() {
  14207. var range = me.selection.getRange(),
  14208. hr = me.document
  14209. .createElement('hr');
  14210. domUtils.setAttributes(hr, {
  14211. 'class': 'pagebreak',
  14212. noshade: "noshade",
  14213. size: "5"
  14214. });
  14215. domUtils.unSelectable(hr);
  14216. // table单独处理
  14217. var node = domUtils.findParentByTagName(range.startContainer,
  14218. notBreakTags, true),
  14219. parents = [],
  14220. pN;
  14221. if(node) {
  14222. switch(node.tagName) {
  14223. case 'TD':
  14224. pN = node.parentNode;
  14225. if(!pN.previousSibling) {
  14226. var table = domUtils.findParentByTagName(pN,
  14227. 'table');
  14228. // var tableWrapDiv = table.parentNode;
  14229. // if(tableWrapDiv && tableWrapDiv.nodeType == 1
  14230. // && tableWrapDiv.tagName == 'DIV'
  14231. // && tableWrapDiv.getAttribute('dropdrag')
  14232. // ){
  14233. // domUtils.remove(tableWrapDiv,true);
  14234. // }
  14235. table.parentNode.insertBefore(hr, table);
  14236. parents = domUtils.findParents(hr, true);
  14237. } else {
  14238. pN.parentNode.insertBefore(hr, pN);
  14239. parents = domUtils.findParents(hr);
  14240. }
  14241. pN = parents[1];
  14242. if(hr !== pN) {
  14243. domUtils.breakParent(hr, pN);
  14244. }
  14245. // table要重写绑定一下拖拽
  14246. me.fireEvent('afteradjusttable', me.document);
  14247. }
  14248. } else {
  14249. if(!range.collapsed) {
  14250. range.deleteContents();
  14251. var start = range.startContainer;
  14252. while(!domUtils.isBody(start) &&
  14253. domUtils.isBlockElm(start) &&
  14254. domUtils.isEmptyNode(start)) {
  14255. range.setStartBefore(start).collapse(true);
  14256. domUtils.remove(start);
  14257. start = range.startContainer;
  14258. }
  14259. }
  14260. range.insertNode(hr);
  14261. var pN = hr.parentNode,
  14262. nextNode;
  14263. while(!domUtils.isBody(pN)) {
  14264. domUtils.breakParent(hr, pN);
  14265. nextNode = hr.nextSibling;
  14266. if(nextNode && domUtils.isEmptyBlock(nextNode)) {
  14267. domUtils.remove(nextNode);
  14268. }
  14269. pN = hr.parentNode;
  14270. }
  14271. nextNode = hr.nextSibling;
  14272. var pre = hr.previousSibling;
  14273. if(isHr(pre)) {
  14274. domUtils.remove(pre);
  14275. } else {
  14276. pre && fillNode(pre);
  14277. }
  14278. if(!nextNode) {
  14279. var p = me.document.createElement('p');
  14280. hr.parentNode.appendChild(p);
  14281. domUtils.fillNode(me.document, p);
  14282. range.setStart(p, 0).collapse(true);
  14283. } else {
  14284. if(isHr(nextNode)) {
  14285. domUtils.remove(nextNode);
  14286. } else {
  14287. fillNode(nextNode);
  14288. }
  14289. range.setEndAfter(hr).collapse(false);
  14290. }
  14291. range.select(true);
  14292. }
  14293. }
  14294. };
  14295. };
  14296. // plugins/wordimage.js
  14297. // /import core
  14298. // /commands 本地图片引导上传
  14299. // /commandsName WordImage
  14300. // /commandsTitle 本地图片引导上传
  14301. // /commandsDialog dialogs\wordimage
  14302. UE.plugin.register('wordimage', function() {
  14303. var me = this,
  14304. images = [];
  14305. return {
  14306. commands: {
  14307. 'wordimage': {
  14308. execCommand: function() {
  14309. var images = domUtils.getElementsByTagName(me.body,
  14310. "img");
  14311. var urlList = [];
  14312. for(var i = 0, ci; ci = images[i++];) {
  14313. var url = ci.getAttribute("word_img");
  14314. url && urlList.push(url);
  14315. }
  14316. return urlList;
  14317. },
  14318. queryCommandState: function() {
  14319. images = domUtils.getElementsByTagName(me.body, "img");
  14320. for(var i = 0, ci; ci = images[i++];) {
  14321. if(ci.getAttribute("word_img")) {
  14322. return 1;
  14323. }
  14324. }
  14325. return -1;
  14326. },
  14327. notNeedUndo: true
  14328. }
  14329. },
  14330. inputRule: function(root) {
  14331. utils.each(root.getNodesByTagName('img'), function(img) {
  14332. var attrs = img.attrs,
  14333. flag = parseInt(attrs.width) < 128 ||
  14334. parseInt(attrs.height) < 43,
  14335. opt = me.options,
  14336. src = opt.UEDITOR_HOME_URL +
  14337. 'themes/default/images/spacer.gif';
  14338. if(attrs['src'] && /^(?:(file:\/+))/.test(attrs['src'])) {
  14339. img.setAttr({
  14340. width: attrs.width,
  14341. height: attrs.height,
  14342. alt: attrs.alt,
  14343. word_img: attrs.src,
  14344. src: src,
  14345. 'style': 'background:url(' +
  14346. (flag ? opt.themePath + opt.theme +
  14347. '/images/word.gif' : opt.langPath +
  14348. opt.lang +
  14349. '/images/localimage.png') +
  14350. ') no-repeat center center;border:1px solid #ddd'
  14351. })
  14352. }
  14353. })
  14354. }
  14355. }
  14356. });
  14357. // plugins/dragdrop.js
  14358. UE.plugins['dragdrop'] = function() {
  14359. var me = this;
  14360. me.ready(function() {
  14361. domUtils.on(this.body, 'dragend', function() {
  14362. var rng = me.selection.getRange();
  14363. var node = rng.getClosedNode() || me.selection.getStart();
  14364. if(node && node.tagName == 'IMG') {
  14365. var pre = node.previousSibling,
  14366. next;
  14367. while(next = node.nextSibling) {
  14368. if(next.nodeType == 1 && next.tagName == 'SPAN' &&
  14369. !next.firstChild) {
  14370. domUtils.remove(next)
  14371. } else {
  14372. break;
  14373. }
  14374. }
  14375. if((pre && pre.nodeType == 1 &&
  14376. !domUtils.isEmptyBlock(pre) || !pre) &&
  14377. (!next || next && !domUtils.isEmptyBlock(next))) {
  14378. if(pre && pre.tagName == 'P' &&
  14379. !domUtils.isEmptyBlock(pre)) {
  14380. pre.appendChild(node);
  14381. domUtils.moveChild(next, pre);
  14382. domUtils.remove(next);
  14383. } else if(next && next.tagName == 'P' &&
  14384. !domUtils.isEmptyBlock(next)) {
  14385. next.insertBefore(node, next.firstChild);
  14386. }
  14387. if(pre && pre.tagName == 'P' &&
  14388. domUtils.isEmptyBlock(pre)) {
  14389. domUtils.remove(pre)
  14390. }
  14391. if(next && next.tagName == 'P' &&
  14392. domUtils.isEmptyBlock(next)) {
  14393. domUtils.remove(next)
  14394. }
  14395. rng.selectNode(node).select();
  14396. me.fireEvent('saveScene');
  14397. }
  14398. }
  14399. })
  14400. });
  14401. me.addListener('keyup', function(type, evt) {
  14402. var keyCode = evt.keyCode || evt.which;
  14403. if(keyCode == 13) {
  14404. var rng = me.selection.getRange(),
  14405. node;
  14406. if(node = domUtils.findParentByTagName(rng.startContainer,
  14407. 'p', true)) {
  14408. if(domUtils.getComputedStyle(node, 'text-align') == 'center') {
  14409. domUtils.removeStyle(node, 'text-align')
  14410. }
  14411. }
  14412. }
  14413. })
  14414. };
  14415. // plugins/undo.js
  14416. /**
  14417. * undo redo
  14418. *
  14419. * @file
  14420. * @since 1.2.6.1
  14421. */
  14422. /**
  14423. * 撤销上一次执行的命令
  14424. *
  14425. * @command undo
  14426. * @method execCommand
  14427. * @param {
  14428. * String } cmd 命令字符串
  14429. * @example ```javascript editor.execCommand( 'undo' ); ```
  14430. */
  14431. /**
  14432. * 重做上一次执行的命令
  14433. *
  14434. * @command redo
  14435. * @method execCommand
  14436. * @param {
  14437. * String } cmd 命令字符串
  14438. * @example ```javascript editor.execCommand( 'redo' ); ```
  14439. */
  14440. UE.plugins['undo'] = function() {
  14441. var saveSceneTimer;
  14442. var me = this,
  14443. maxUndoCount = me.options.maxUndoCount || 20,
  14444. maxInputCount = me.options.maxInputCount ||
  14445. 20,
  14446. fillchar = new RegExp(domUtils.fillChar + '|<\/hr>',
  14447. 'gi'); // ie会产生多余的</hr>
  14448. var noNeedFillCharTags = {
  14449. ol: 1,
  14450. ul: 1,
  14451. table: 1,
  14452. tbody: 1,
  14453. tr: 1,
  14454. body: 1
  14455. };
  14456. var orgState = me.options.autoClearEmptyNode;
  14457. function compareAddr(indexA, indexB) {
  14458. if(indexA.length != indexB.length)
  14459. return 0;
  14460. for(var i = 0, l = indexA.length; i < l; i++) {
  14461. if(indexA[i] != indexB[i])
  14462. return 0
  14463. }
  14464. return 1;
  14465. }
  14466. function compareRangeAddress(rngAddrA, rngAddrB) {
  14467. if(rngAddrA.collapsed != rngAddrB.collapsed) {
  14468. return 0;
  14469. }
  14470. if(!compareAddr(rngAddrA.startAddress, rngAddrB.startAddress) ||
  14471. !compareAddr(rngAddrA.endAddress, rngAddrB.endAddress)) {
  14472. return 0;
  14473. }
  14474. return 1;
  14475. }
  14476. function UndoManager() {
  14477. this.list = [];
  14478. this.index = 0;
  14479. this.hasUndo = false;
  14480. this.hasRedo = false;
  14481. this.undo = function() {
  14482. if(this.hasUndo) {
  14483. if(!this.list[this.index - 1] && this.list.length == 1) {
  14484. this.reset();
  14485. return;
  14486. }
  14487. while(this.list[this.index].content == this.list[this.index -
  14488. 1].content) {
  14489. this.index--;
  14490. if(this.index == 0) {
  14491. return this.restore(0);
  14492. }
  14493. }
  14494. this.restore(--this.index);
  14495. }
  14496. };
  14497. this.redo = function() {
  14498. if(this.hasRedo) {
  14499. while(this.list[this.index].content == this.list[this.index +
  14500. 1].content) {
  14501. this.index++;
  14502. if(this.index == this.list.length - 1) {
  14503. return this.restore(this.index);
  14504. }
  14505. }
  14506. this.restore(++this.index);
  14507. }
  14508. };
  14509. this.restore = function() {
  14510. var me = this.editor;
  14511. var scene = this.list[this.index];
  14512. var root = UE.htmlparser(scene.content.replace(fillchar, ''));
  14513. me.options.autoClearEmptyNode = false;
  14514. me.filterInputRule(root);
  14515. me.options.autoClearEmptyNode = orgState;
  14516. // trace:873
  14517. // 去掉展位符
  14518. me.document.body.innerHTML = root.toHtml();
  14519. me.fireEvent('afterscencerestore');
  14520. // 处理undo后空格不展位的问题
  14521. if(browser.ie) {
  14522. utils.each(domUtils.getElementsByTagName(me.document,
  14523. 'td th caption p'), function(node) {
  14524. if(domUtils.isEmptyNode(node)) {
  14525. domUtils.fillNode(me.document, node);
  14526. }
  14527. })
  14528. }
  14529. try {
  14530. var rng = new dom.Range(me.document)
  14531. .moveToAddress(scene.address);
  14532. rng.select(noNeedFillCharTags[rng.startContainer.nodeName
  14533. .toLowerCase()]);
  14534. } catch(e) {}
  14535. this.update();
  14536. this.clearKey();
  14537. // 不能把自己reset了
  14538. me.fireEvent('reset', true);
  14539. };
  14540. this.getScene = function() {
  14541. var me = this.editor;
  14542. var rng = me.selection.getRange(),
  14543. rngAddress = rng
  14544. .createAddress(false, true);
  14545. me.fireEvent('beforegetscene');
  14546. var root = UE.htmlparser(me.body.innerHTML);
  14547. me.options.autoClearEmptyNode = false;
  14548. me.filterOutputRule(root);
  14549. me.options.autoClearEmptyNode = orgState;
  14550. var cont = root.toHtml();
  14551. // trace:3461
  14552. // 这个会引起回退时导致空格丢失的情况
  14553. // browser.ie && (cont = cont.replace(/>&nbsp;</g,
  14554. // '><').replace(/\s*</g, '<').replace(/>\s*/g, '>'));
  14555. me.fireEvent('aftergetscene');
  14556. return {
  14557. address: rngAddress,
  14558. content: cont
  14559. }
  14560. };
  14561. this.save = function(notCompareRange, notSetCursor) {
  14562. clearTimeout(saveSceneTimer);
  14563. var currentScene = this.getScene(notSetCursor),
  14564. lastScene = this.list[this.index];
  14565. if(lastScene && lastScene.content != currentScene.content) {
  14566. me.trigger('contentchange')
  14567. }
  14568. // 内容相同位置相同不存
  14569. if(lastScene &&
  14570. lastScene.content == currentScene.content &&
  14571. (notCompareRange ? 1 : compareRangeAddress(
  14572. lastScene.address, currentScene.address))) {
  14573. return;
  14574. }
  14575. this.list = this.list.slice(0, this.index + 1);
  14576. this.list.push(currentScene);
  14577. // 如果大于最大数量了,就把最前的剔除
  14578. if(this.list.length > maxUndoCount) {
  14579. this.list.shift();
  14580. }
  14581. this.index = this.list.length - 1;
  14582. this.clearKey();
  14583. // 跟新undo/redo状态
  14584. this.update();
  14585. };
  14586. this.update = function() {
  14587. this.hasRedo = !!this.list[this.index + 1];
  14588. this.hasUndo = !!this.list[this.index - 1];
  14589. };
  14590. this.reset = function() {
  14591. this.list = [];
  14592. this.index = 0;
  14593. this.hasUndo = false;
  14594. this.hasRedo = false;
  14595. this.clearKey();
  14596. };
  14597. this.clearKey = function() {
  14598. keycont = 0;
  14599. lastKeyCode = null;
  14600. };
  14601. }
  14602. me.undoManger = new UndoManager();
  14603. me.undoManger.editor = me;
  14604. function saveScene() {
  14605. this.undoManger.save();
  14606. }
  14607. me.addListener('saveScene', function() {
  14608. var args = Array.prototype.splice.call(arguments, 1);
  14609. this.undoManger.save.apply(this.undoManger, args);
  14610. });
  14611. // me.addListener('beforeexeccommand', saveScene);
  14612. // me.addListener('afterexeccommand', saveScene);
  14613. me.addListener('reset', function(type, exclude) {
  14614. if(!exclude) {
  14615. this.undoManger.reset();
  14616. }
  14617. });
  14618. me.commands['redo'] = me.commands['undo'] = {
  14619. execCommand: function(cmdName) {
  14620. this.undoManger[cmdName]();
  14621. console.log(this.undoManger);
  14622. console.log(cmdName);
  14623. },
  14624. queryCommandState: function(cmdName) {
  14625. return this.undoManger['has' +
  14626. (cmdName.toLowerCase() == 'undo' ? 'Undo' : 'Redo')] ?
  14627. 0 :
  14628. -1;
  14629. },
  14630. notNeedUndo: 1
  14631. };
  14632. var keys = {
  14633. // /*Backspace*/ 8:1, /*Delete*/ 46:1,
  14634. /* Shift */
  14635. 16: 1,
  14636. /* Ctrl */
  14637. 17: 1,
  14638. /* Alt */
  14639. 18: 1,
  14640. 37: 1,
  14641. 38: 1,
  14642. 39: 1,
  14643. 40: 1
  14644. },
  14645. keycont = 0,
  14646. lastKeyCode;
  14647. // 输入法状态下不计算字符数
  14648. var inputType = false;
  14649. me.addListener('ready', function() {
  14650. domUtils.on(this.body, 'compositionstart', function() {
  14651. inputType = true;
  14652. });
  14653. domUtils.on(this.body, 'compositionend', function() {
  14654. inputType = false;
  14655. })
  14656. });
  14657. // 快捷键
  14658. me.addshortcutkey({
  14659. "Undo": "ctrl+90", // undo
  14660. "Redo": "ctrl+89" // redo
  14661. });
  14662. var isCollapsed = true;
  14663. me.addListener('keydown', function(type, evt) {
  14664. var me = this;
  14665. var keyCode = evt.keyCode || evt.which;
  14666. if(!keys[keyCode] && !evt.ctrlKey && !evt.metaKey && !evt.shiftKey &&
  14667. !evt.altKey) {
  14668. if(inputType)
  14669. return;
  14670. if(!me.selection.getRange().collapsed) {
  14671. me.undoManger.save(false, true);
  14672. isCollapsed = false;
  14673. return;
  14674. }
  14675. if(me.undoManger.list.length == 0) {
  14676. me.undoManger.save(true);
  14677. }
  14678. clearTimeout(saveSceneTimer);
  14679. function save(cont) {
  14680. cont.undoManger.save(false, true);
  14681. cont.fireEvent('selectionchange');
  14682. }
  14683. saveSceneTimer = setTimeout(function() {
  14684. if(inputType) {
  14685. var interalTimer = setInterval(function() {
  14686. if(!inputType) {
  14687. save(me);
  14688. clearInterval(interalTimer)
  14689. }
  14690. }, 300)
  14691. return;
  14692. }
  14693. save(me);
  14694. }, 200);
  14695. lastKeyCode = keyCode;
  14696. keycont++;
  14697. if(keycont >= maxInputCount) {
  14698. save(me)
  14699. }
  14700. }
  14701. });
  14702. me.addListener('keyup', function(type, evt) {
  14703. var keyCode = evt.keyCode || evt.which;
  14704. if(!keys[keyCode] && !evt.ctrlKey && !evt.metaKey && !evt.shiftKey &&
  14705. !evt.altKey) {
  14706. if(inputType)
  14707. return;
  14708. if(!isCollapsed) {
  14709. this.undoManger.save(false, true);
  14710. isCollapsed = true;
  14711. }
  14712. }
  14713. });
  14714. // 扩展实例,添加关闭和开启命令undo
  14715. me.stopCmdUndo = function() {
  14716. me.__hasEnterExecCommand = true;
  14717. };
  14718. me.startCmdUndo = function() {
  14719. me.__hasEnterExecCommand = false;
  14720. }
  14721. };
  14722. // plugins/copy.js
  14723. UE.plugin.register('copy', function() {
  14724. var me = this;
  14725. function initZeroClipboard() {
  14726. ZeroClipboard.config({
  14727. debug: false,
  14728. swfPath: me.options.UEDITOR_HOME_URL +
  14729. 'third-party/zeroclipboard/ZeroClipboard.swf'
  14730. });
  14731. var client = me.zeroclipboard = new ZeroClipboard();
  14732. // 复制内容
  14733. client.on('copy', function(e) {
  14734. var client = e.client,
  14735. rng = me.selection.getRange(),
  14736. div = document
  14737. .createElement('div');
  14738. div.appendChild(rng.cloneContents());
  14739. client.setText(div.innerText || div.textContent);
  14740. client.setHtml(div.innerHTML);
  14741. rng.select();
  14742. });
  14743. // hover事件传递到target
  14744. client.on('mouseover mouseout', function(e) {
  14745. var target = e.target;
  14746. if(e.type == 'mouseover') {
  14747. domUtils.addClass(target, 'edui-state-hover');
  14748. } else if(e.type == 'mouseout') {
  14749. domUtils.removeClasses(target, 'edui-state-hover');
  14750. }
  14751. });
  14752. // flash加载不成功
  14753. client.on('wrongflash noflash', function() {
  14754. ZeroClipboard.destroy();
  14755. });
  14756. }
  14757. return {
  14758. bindEvents: {
  14759. 'ready': function() {
  14760. if(!browser.ie) {
  14761. if(window.ZeroClipboard) {
  14762. initZeroClipboard();
  14763. } else {
  14764. utils.loadFile(document, {
  14765. src: me.options.UEDITOR_HOME_URL +
  14766. "third-party/zeroclipboard/ZeroClipboard.js",
  14767. tag: "script",
  14768. type: "text/javascript",
  14769. defer: "defer"
  14770. }, function() {
  14771. initZeroClipboard();
  14772. });
  14773. }
  14774. }
  14775. }
  14776. },
  14777. commands: {
  14778. 'copy': {
  14779. execCommand: function(cmd) {
  14780. if(!me.document.execCommand('copy')) {
  14781. alert(me.getLang('copymsg'));
  14782. }
  14783. }
  14784. }
  14785. }
  14786. }
  14787. });
  14788. // plugins/paste.js
  14789. // /import core
  14790. // /import plugins/inserthtml.js
  14791. // /import plugins/undo.js
  14792. // /import plugins/serialize.js
  14793. // /commands 粘贴
  14794. // /commandsName PastePlain
  14795. // /commandsTitle 纯文本粘贴模式
  14796. /**
  14797. * @description 粘贴
  14798. * @author zhanyi
  14799. */
  14800. UE.plugins['paste'] = function() {
  14801. function getClipboardData(callback) {
  14802. var doc = this.document;
  14803. if(doc.getElementById('baidu_pastebin')) {
  14804. return;
  14805. }
  14806. var range = this.selection.getRange(),
  14807. bk = range.createBookmark(),
  14808. // 创建剪贴的容器div
  14809. pastebin = doc.createElement('div');
  14810. pastebin.id = 'baidu_pastebin';
  14811. // Safari 要求div必须有内容,才能粘贴内容进来
  14812. browser.webkit &&
  14813. pastebin.appendChild(doc
  14814. .createTextNode(domUtils.fillChar +
  14815. domUtils.fillChar));
  14816. doc.body.appendChild(pastebin);
  14817. // trace:717 隐藏的span不能得到top
  14818. // bk.start.innerHTML = '&nbsp;';
  14819. bk.start.style.display = '';
  14820. pastebin.style.cssText = "position:absolute;width:1px;height:1px;overflow:hidden;left:-1000px;white-space:nowrap;top:" +
  14821. // 要在现在光标平行的位置加入,否则会出现跳动的问题
  14822. domUtils.getXY(bk.start).y + 'px';
  14823. range.selectNodeContents(pastebin).select(true);
  14824. setTimeout(function() {
  14825. if(browser.webkit) {
  14826. for(var i = 0, pastebins = doc
  14827. .querySelectorAll('#baidu_pastebin'), pi; pi = pastebins[i++];) {
  14828. if(domUtils.isEmptyNode(pi)) {
  14829. domUtils.remove(pi);
  14830. } else {
  14831. pastebin = pi;
  14832. break;
  14833. }
  14834. }
  14835. }
  14836. try {
  14837. pastebin.parentNode.removeChild(pastebin);
  14838. } catch(e) {}
  14839. range.moveToBookmark(bk).select(true);
  14840. callback(pastebin);
  14841. }, 0);
  14842. }
  14843. var me = this;
  14844. me.setOpt({
  14845. retainOnlyLabelPasted: false
  14846. });
  14847. var txtContent, htmlContent, address;
  14848. function getPureHtml(html) {
  14849. return html.replace(/<(\/?)([\w\-]+)([^>]*)>/gi, function(a, b,
  14850. tagName, attrs) {
  14851. tagName = tagName.toLowerCase();
  14852. if({
  14853. img: 1
  14854. }[tagName]) {
  14855. return a;
  14856. }
  14857. attrs = attrs
  14858. .replace(
  14859. /([\w\-]*?)\s*=\s*(("([^"]*)")|('([^']*)')|([^\s>]+))/gi,
  14860. function(str, atr, val) {
  14861. if({
  14862. 'src': 1,
  14863. 'href': 1,
  14864. 'name': 1
  14865. }[atr.toLowerCase()]) {
  14866. return atr + '=' + val + ' '
  14867. }
  14868. return ''
  14869. });
  14870. if({
  14871. 'span': 1,
  14872. 'div': 1
  14873. }[tagName]) {
  14874. return ''
  14875. } else {
  14876. return '<' + b + tagName + ' ' + utils.trim(attrs) + '>'
  14877. }
  14878. });
  14879. }
  14880. function filter(div) {
  14881. var html;
  14882. if(div.firstChild) {
  14883. // 去掉cut中添加的边界值
  14884. var nodes = domUtils.getElementsByTagName(div, 'span');
  14885. for(var i = 0, ni; ni = nodes[i++];) {
  14886. if(ni.id == '_baidu_cut_start' ||
  14887. ni.id == '_baidu_cut_end') {
  14888. domUtils.remove(ni);
  14889. }
  14890. }
  14891. if(browser.webkit) {
  14892. var brs = div.querySelectorAll('div br');
  14893. for(var i = 0, bi; bi = brs[i++];) {
  14894. var pN = bi.parentNode;
  14895. if(pN.tagName == 'DIV' && pN.childNodes.length == 1) {
  14896. pN.innerHTML = '<p><br/></p>';
  14897. domUtils.remove(pN);
  14898. }
  14899. }
  14900. var divs = div.querySelectorAll('#baidu_pastebin');
  14901. for(var i = 0, di; di = divs[i++];) {
  14902. var tmpP = me.document.createElement('p');
  14903. di.parentNode.insertBefore(tmpP, di);
  14904. while(di.firstChild) {
  14905. tmpP.appendChild(di.firstChild);
  14906. }
  14907. domUtils.remove(di);
  14908. }
  14909. var metas = div.querySelectorAll('meta');
  14910. for(var i = 0, ci; ci = metas[i++];) {
  14911. domUtils.remove(ci);
  14912. }
  14913. var brs = div.querySelectorAll('br');
  14914. for(i = 0; ci = brs[i++];) {
  14915. if(/^apple-/i.test(ci.className)) {
  14916. domUtils.remove(ci);
  14917. }
  14918. }
  14919. }
  14920. if(browser.gecko) {
  14921. var dirtyNodes = div.querySelectorAll('[_moz_dirty]');
  14922. for(i = 0; ci = dirtyNodes[i++];) {
  14923. ci.removeAttribute('_moz_dirty');
  14924. }
  14925. }
  14926. if(!browser.ie) {
  14927. var spans = div.querySelectorAll('span.Apple-style-span');
  14928. for(var i = 0, ci; ci = spans[i++];) {
  14929. domUtils.remove(ci, true);
  14930. }
  14931. }
  14932. // ie下使用innerHTML会产生多余的\r\n字符,也会产生&nbsp;这里过滤掉
  14933. html = div.innerHTML; // .replace(/>(?:(\s|&nbsp;)*?)</g,'><');
  14934. // 过滤word粘贴过来的冗余属性
  14935. html = UE.filterWord(html);
  14936. // 取消了忽略空白的第二个参数,粘贴过来的有些是有空白的,会被套上相关的标签
  14937. var root = UE.htmlparser(html);
  14938. // 如果给了过滤规则就先进行过滤
  14939. if(me.options.filterRules) {
  14940. UE.filterNode(root, me.options.filterRules);
  14941. }
  14942. // 执行默认的处理
  14943. me.filterInputRule(root);
  14944. // 针对chrome的处理
  14945. if(browser.webkit) {
  14946. var br = root.lastChild();
  14947. if(br && br.type == 'element' && br.tagName == 'br') {
  14948. root.removeChild(br)
  14949. }
  14950. utils.each(me.body.querySelectorAll('div'), function(node) {
  14951. if(domUtils.isEmptyBlock(node)) {
  14952. domUtils.remove(node, true)
  14953. }
  14954. })
  14955. }
  14956. html = {
  14957. 'html': root.toHtml()
  14958. };
  14959. me.fireEvent('beforepaste', html, root);
  14960. // 抢了默认的粘贴,那后边的内容就不执行了,比如表格粘贴
  14961. if(!html.html) {
  14962. return;
  14963. }
  14964. root = UE.htmlparser(html.html, true);
  14965. // 如果开启了纯文本模式
  14966. if(me.queryCommandState('pasteplain') === 1) {
  14967. me.execCommand('insertHtml', UE.filterNode(root,
  14968. me.options.filterTxtRules).toHtml(), true);
  14969. } else {
  14970. // 文本模式
  14971. UE.filterNode(root, me.options.filterTxtRules);
  14972. txtContent = root.toHtml();
  14973. // 完全模式
  14974. htmlContent = html.html;
  14975. address = me.selection.getRange().createAddress(true);
  14976. me.execCommand('insertHtml', me
  14977. .getOpt('retainOnlyLabelPasted') === true ?
  14978. getPureHtml(htmlContent) :
  14979. htmlContent, true);
  14980. }
  14981. me.fireEvent("afterpaste", html);
  14982. }
  14983. }
  14984. me.addListener('pasteTransfer', function(cmd, plainType) {
  14985. if(address && txtContent && htmlContent &&
  14986. txtContent != htmlContent) {
  14987. var range = me.selection.getRange();
  14988. range.moveToAddress(address, true);
  14989. if(!range.collapsed) {
  14990. while(!domUtils.isBody(range.startContainer)) {
  14991. var start = range.startContainer;
  14992. if(start.nodeType == 1) {
  14993. start = start.childNodes[range.startOffset];
  14994. if(!start) {
  14995. range.setStartBefore(range.startContainer);
  14996. continue;
  14997. }
  14998. var pre = start.previousSibling;
  14999. if(pre &&
  15000. pre.nodeType == 3 &&
  15001. new RegExp('^[\n\r\t ' +
  15002. domUtils.fillChar + ']*$')
  15003. .test(pre.nodeValue)) {
  15004. range.setStartBefore(pre)
  15005. }
  15006. }
  15007. if(range.startOffset == 0) {
  15008. range.setStartBefore(range.startContainer);
  15009. } else {
  15010. break;
  15011. }
  15012. }
  15013. while(!domUtils.isBody(range.endContainer)) {
  15014. var end = range.endContainer;
  15015. if(end.nodeType == 1) {
  15016. end = end.childNodes[range.endOffset];
  15017. if(!end) {
  15018. range.setEndAfter(range.endContainer);
  15019. continue;
  15020. }
  15021. var next = end.nextSibling;
  15022. if(next &&
  15023. next.nodeType == 3 &&
  15024. new RegExp('^[\n\r\t' +
  15025. domUtils.fillChar + ']*$')
  15026. .test(next.nodeValue)) {
  15027. range.setEndAfter(next)
  15028. }
  15029. }
  15030. if(range.endOffset == range.endContainer[range.endContainer.nodeType == 3 ?
  15031. 'nodeValue' :
  15032. 'childNodes'].length) {
  15033. range.setEndAfter(range.endContainer);
  15034. } else {
  15035. break;
  15036. }
  15037. }
  15038. }
  15039. range.deleteContents();
  15040. range.select(true);
  15041. me.__hasEnterExecCommand = true;
  15042. var html = htmlContent;
  15043. if(plainType === 2) {
  15044. html = getPureHtml(html);
  15045. } else if(plainType) {
  15046. html = txtContent;
  15047. }
  15048. me.execCommand('inserthtml', html, true);
  15049. me.__hasEnterExecCommand = false;
  15050. var rng = me.selection.getRange();
  15051. while(!domUtils.isBody(rng.startContainer) &&
  15052. !rng.startOffset &&
  15053. rng.startContainer[rng.startContainer.nodeType == 3 ?
  15054. 'nodeValue' :
  15055. 'childNodes'].length) {
  15056. rng.setStartBefore(rng.startContainer);
  15057. }
  15058. var tmpAddress = rng.createAddress(true);
  15059. address.endAddress = tmpAddress.startAddress;
  15060. }
  15061. });
  15062. me.addListener('ready', function() {
  15063. domUtils.on(me.body, 'cut', function() {
  15064. var range = me.selection.getRange();
  15065. if(!range.collapsed && me.undoManger) {
  15066. me.undoManger.save();
  15067. }
  15068. });
  15069. // ie下beforepaste在点击右键时也会触发,所以用监控键盘才处理
  15070. domUtils.on(me.body, browser.ie || browser.opera ?
  15071. 'keydown' :
  15072. 'paste',
  15073. function(e) {
  15074. if((browser.ie || browser.opera) &&
  15075. ((!e.ctrlKey && !e.metaKey) || e.keyCode != '86')) {
  15076. return;
  15077. }
  15078. getClipboardData.call(me, function(div) {
  15079. filter(div);
  15080. });
  15081. });
  15082. });
  15083. me.commands['paste'] = {
  15084. execCommand: function(cmd) {
  15085. if(browser.ie) {
  15086. getClipboardData.call(me, function(div) {
  15087. filter(div);
  15088. });
  15089. me.document.execCommand('paste');
  15090. } else {
  15091. alert(me.getLang('pastemsg'));
  15092. }
  15093. }
  15094. }
  15095. };
  15096. // plugins/puretxtpaste.js
  15097. /**
  15098. * 纯文本粘贴插件
  15099. *
  15100. * @file
  15101. * @since 1.2.6.1
  15102. */
  15103. UE.plugins['pasteplain'] = function() {
  15104. var me = this;
  15105. me.setOpt({
  15106. 'pasteplain': false,
  15107. 'filterTxtRules': function() {
  15108. function transP(node) {
  15109. node.tagName = 'p';
  15110. node.setStyle();
  15111. }
  15112. function removeNode(node) {
  15113. node.parentNode.removeChild(node, true)
  15114. }
  15115. return {
  15116. // 直接删除及其字节点内容
  15117. '-': 'script style object iframe embed input select',
  15118. 'p': {
  15119. $: {}
  15120. },
  15121. 'br': {
  15122. $: {}
  15123. },
  15124. div: function(node) {
  15125. var tmpNode, p = UE.uNode.createElement('p');
  15126. while(tmpNode = node.firstChild()) {
  15127. if(tmpNode.type == 'text' ||
  15128. !UE.dom.dtd.$block[tmpNode.tagName]) {
  15129. p.appendChild(tmpNode);
  15130. } else {
  15131. if(p.firstChild()) {
  15132. node.parentNode.insertBefore(p, node);
  15133. p = UE.uNode.createElement('p');
  15134. } else {
  15135. node.parentNode.insertBefore(tmpNode, node);
  15136. }
  15137. }
  15138. }
  15139. if(p.firstChild()) {
  15140. node.parentNode.insertBefore(p, node);
  15141. }
  15142. node.parentNode.removeChild(node);
  15143. },
  15144. img:"img",
  15145. ol: removeNode,
  15146. ul: removeNode,
  15147. dl: removeNode,
  15148. dt: removeNode,
  15149. dd: removeNode,
  15150. 'li': removeNode,
  15151. 'caption': transP,
  15152. 'th': transP,
  15153. 'tr': transP,
  15154. 'h1': transP,
  15155. 'h2': transP,
  15156. 'h3': transP,
  15157. 'h4': transP,
  15158. 'h5': transP,
  15159. 'h6': transP,
  15160. 'td': function(node) {
  15161. // 没有内容的td直接删掉
  15162. var txt = !!node.innerText();
  15163. if(txt) {
  15164. node.parentNode.insertAfter(UE.uNode
  15165. .createText(' &nbsp; &nbsp;'), node);
  15166. }
  15167. node.parentNode.removeChild(node, node.innerText())
  15168. }
  15169. }
  15170. }()
  15171. });
  15172. // 暂时这里支持一下老版本的属性
  15173. var pasteplain = me.options.pasteplain;
  15174. /**
  15175. * 启用或取消纯文本粘贴模式
  15176. *
  15177. * @command pasteplain
  15178. * @method execCommand
  15179. * @param {
  15180. * String } cmd 命令字符串
  15181. * @example ```javascript editor.queryCommandState( 'pasteplain' ); ```
  15182. */
  15183. /**
  15184. * 查询当前是否处于纯文本粘贴模式
  15185. *
  15186. * @command pasteplain
  15187. * @method queryCommandState
  15188. * @param {
  15189. * String } cmd 命令字符串
  15190. * @return { int } 如果处于纯文本模式,返回1,否则,返回0
  15191. * @example ```javascript editor.queryCommandState( 'pasteplain' ); ```
  15192. */
  15193. me.commands['pasteplain'] = {
  15194. queryCommandState: function() {
  15195. return pasteplain ? 1 : 0;
  15196. },
  15197. execCommand: function() {
  15198. pasteplain = !pasteplain | 0;
  15199. },
  15200. notNeedUndo: 1
  15201. };
  15202. };
  15203. // plugins/list.js
  15204. /**
  15205. * 有序列表,无序列表插件
  15206. *
  15207. * @file
  15208. * @since 1.2.6.1
  15209. */
  15210. UE.plugins['list'] = function() {
  15211. var me = this,
  15212. notExchange = {
  15213. 'TD': 1,
  15214. 'PRE': 1,
  15215. 'BLOCKQUOTE': 1
  15216. };
  15217. var customStyle = {
  15218. 'cn': 'cn-1-',
  15219. 'cn1': 'cn-2-',
  15220. 'cn2': 'cn-3-',
  15221. 'num': 'num-1-',
  15222. 'num1': 'num-2-',
  15223. 'num2': 'num-3-',
  15224. 'dash': 'dash',
  15225. 'dot': 'dot'
  15226. };
  15227. me.setOpt({
  15228. 'autoTransWordToList': false,
  15229. 'insertorderedlist': {
  15230. 'num': '',
  15231. 'num1': '',
  15232. 'num2': '',
  15233. 'cn': '',
  15234. 'cn1': '',
  15235. 'cn2': '',
  15236. 'decimal': '',
  15237. 'lower-alpha': '',
  15238. 'lower-roman': '',
  15239. 'upper-alpha': '',
  15240. 'upper-roman': ''
  15241. },
  15242. 'insertunorderedlist': {
  15243. 'circle': '',
  15244. 'disc': '',
  15245. 'square': '',
  15246. 'dash': '',
  15247. 'dot': ''
  15248. },
  15249. listDefaultPaddingLeft: '30',
  15250. listiconpath: 'http://bs.baidu.com/listicon/',
  15251. maxListLevel: -1, // -1不限制
  15252. disablePInList: false
  15253. });
  15254. function listToArray(list) {
  15255. var arr = [];
  15256. for(var p in list) {
  15257. arr.push(p)
  15258. }
  15259. return arr;
  15260. }
  15261. var listStyle = {
  15262. 'OL': listToArray(me.options.insertorderedlist),
  15263. 'UL': listToArray(me.options.insertunorderedlist)
  15264. };
  15265. var liiconpath = me.options.listiconpath;
  15266. // 根据用户配置,调整customStyle
  15267. for(var s in customStyle) {
  15268. if(!me.options.insertorderedlist.hasOwnProperty(s) &&
  15269. !me.options.insertunorderedlist.hasOwnProperty(s)) {
  15270. delete customStyle[s];
  15271. }
  15272. }
  15273. me.ready(function() {
  15274. var customCss = [];
  15275. for(var p in customStyle) {
  15276. if(p == 'dash' || p == 'dot') {
  15277. customCss.push('li.list-' + customStyle[p] +
  15278. '{background-image:url(' + liiconpath +
  15279. customStyle[p] + '.gif)}');
  15280. customCss
  15281. .push('ul.custom_' +
  15282. p +
  15283. '{list-style:none;}ul.custom_' +
  15284. p +
  15285. ' li{background-position:0 3px;background-repeat:no-repeat}');
  15286. } else {
  15287. for(var i = 0; i < 99; i++) {
  15288. customCss.push('li.list-' + customStyle[p] + i +
  15289. '{background-image:url(' + liiconpath +
  15290. 'list-' + customStyle[p] + i + '.gif)}')
  15291. }
  15292. customCss
  15293. .push('ol.custom_' +
  15294. p +
  15295. '{list-style:none;}ol.custom_' +
  15296. p +
  15297. ' li{background-position:0 3px;background-repeat:no-repeat}');
  15298. }
  15299. switch(p) {
  15300. case 'cn':
  15301. customCss.push('li.list-' + p +
  15302. '-paddingleft-1{padding-left:25px}');
  15303. customCss.push('li.list-' + p +
  15304. '-paddingleft-2{padding-left:40px}');
  15305. customCss.push('li.list-' + p +
  15306. '-paddingleft-3{padding-left:55px}');
  15307. break;
  15308. case 'cn1':
  15309. customCss.push('li.list-' + p +
  15310. '-paddingleft-1{padding-left:30px}');
  15311. customCss.push('li.list-' + p +
  15312. '-paddingleft-2{padding-left:40px}');
  15313. customCss.push('li.list-' + p +
  15314. '-paddingleft-3{padding-left:55px}');
  15315. break;
  15316. case 'cn2':
  15317. customCss.push('li.list-' + p +
  15318. '-paddingleft-1{padding-left:40px}');
  15319. customCss.push('li.list-' + p +
  15320. '-paddingleft-2{padding-left:55px}');
  15321. customCss.push('li.list-' + p +
  15322. '-paddingleft-3{padding-left:68px}');
  15323. break;
  15324. case 'num':
  15325. case 'num1':
  15326. customCss.push('li.list-' + p +
  15327. '-paddingleft-1{padding-left:25px}');
  15328. break;
  15329. case 'num2':
  15330. customCss.push('li.list-' + p +
  15331. '-paddingleft-1{padding-left:35px}');
  15332. customCss.push('li.list-' + p +
  15333. '-paddingleft-2{padding-left:40px}');
  15334. break;
  15335. case 'dash':
  15336. customCss.push('li.list-' + p +
  15337. '-paddingleft{padding-left:35px}');
  15338. break;
  15339. case 'dot':
  15340. customCss.push('li.list-' + p +
  15341. '-paddingleft{padding-left:20px}');
  15342. }
  15343. }
  15344. customCss.push('.list-paddingleft-1{padding-left:0}');
  15345. customCss.push('.list-paddingleft-2{padding-left:' +
  15346. me.options.listDefaultPaddingLeft + 'px}');
  15347. customCss.push('.list-paddingleft-3{padding-left:' +
  15348. me.options.listDefaultPaddingLeft * 2 + 'px}');
  15349. // 如果不给宽度会在自定应样式里出现滚动条
  15350. utils.cssRule('list', 'ol,ul{margin:0;pading:0;' +
  15351. (browser.ie ? '' : 'width:95%') + '}li{clear:both;}' +
  15352. customCss.join('\n'), me.document);
  15353. });
  15354. // 单独处理剪切的问题
  15355. me.ready(function() {
  15356. domUtils.on(me.body, 'cut', function() {
  15357. setTimeout(function() {
  15358. var rng = me.selection.getRange(),
  15359. li;
  15360. // trace:3416
  15361. if(!rng.collapsed) {
  15362. if(li = domUtils.findParentByTagName(
  15363. rng.startContainer, 'li', true)) {
  15364. if(!li.nextSibling && domUtils.isEmptyBlock(li)) {
  15365. var pn = li.parentNode,
  15366. node;
  15367. if(node = pn.previousSibling) {
  15368. domUtils.remove(pn);
  15369. rng.setStartAtLast(node).collapse(true);
  15370. rng.select(true);
  15371. } else if(node = pn.nextSibling) {
  15372. domUtils.remove(pn);
  15373. rng.setStartAtFirst(node).collapse(true);
  15374. rng.select(true);
  15375. } else {
  15376. var tmpNode = me.document
  15377. .createElement('p');
  15378. domUtils.fillNode(me.document, tmpNode);
  15379. pn.parentNode.insertBefore(tmpNode, pn);
  15380. domUtils.remove(pn);
  15381. rng.setStart(tmpNode, 0).collapse(true);
  15382. rng.select(true);
  15383. }
  15384. }
  15385. }
  15386. }
  15387. })
  15388. })
  15389. });
  15390. function getStyle(node) {
  15391. var cls = node.className;
  15392. if(domUtils.hasClass(node, /custom_/)) {
  15393. return cls.match(/custom_(\w+)/)[1]
  15394. }
  15395. return domUtils.getStyle(node, 'list-style-type')
  15396. }
  15397. me.addListener('beforepaste', function(type, html) {
  15398. var me = this,
  15399. rng = me.selection.getRange(),
  15400. li;
  15401. var root = UE.htmlparser(html.html, true);
  15402. if(li = domUtils.findParentByTagName(rng.startContainer, 'li',
  15403. true)) {
  15404. var list = li.parentNode,
  15405. tagName = list.tagName == 'OL' ?
  15406. 'ul' :
  15407. 'ol';
  15408. utils.each(root.getNodesByTagName(tagName), function(n) {
  15409. n.tagName = list.tagName;
  15410. n.setAttr();
  15411. if(n.parentNode === root) {
  15412. type = getStyle(list) ||
  15413. (list.tagName == 'OL' ? 'decimal' : 'disc')
  15414. } else {
  15415. var className = n.parentNode.getAttr('class');
  15416. if(className && /custom_/.test(className)) {
  15417. type = className.match(/custom_(\w+)/)[1]
  15418. } else {
  15419. type = n.parentNode.getStyle('list-style-type');
  15420. }
  15421. if(!type) {
  15422. type = list.tagName == 'OL' ? 'decimal' : 'disc';
  15423. }
  15424. }
  15425. var index = utils.indexOf(listStyle[list.tagName], type);
  15426. if(n.parentNode !== root)
  15427. index = index + 1 == listStyle[list.tagName].length ?
  15428. 0 :
  15429. index + 1;
  15430. var currentStyle = listStyle[list.tagName][index];
  15431. if(customStyle[currentStyle]) {
  15432. n.setAttr('class', 'custom_' + currentStyle)
  15433. } else {
  15434. n.setStyle('list-style-type', currentStyle)
  15435. }
  15436. })
  15437. }
  15438. html.html = root.toHtml();
  15439. });
  15440. // 导出时,去掉p标签
  15441. me.getOpt('disablePInList') === true &&
  15442. me.addOutputRule(function(root) {
  15443. utils.each(root.getNodesByTagName('li'), function(li) {
  15444. var newChildrens = [],
  15445. index = 0;
  15446. utils.each(li.children, function(n) {
  15447. if(n.tagName == 'p') {
  15448. var tmpNode;
  15449. while(tmpNode = n.children.pop()) {
  15450. newChildrens.splice(index, 0, tmpNode);
  15451. tmpNode.parentNode = li;
  15452. lastNode = tmpNode;
  15453. }
  15454. tmpNode = newChildrens[newChildrens.length - 1];
  15455. if(!tmpNode || tmpNode.type != 'element' ||
  15456. tmpNode.tagName != 'br') {
  15457. var br = UE.uNode.createElement('br');
  15458. br.parentNode = li;
  15459. newChildrens.push(br);
  15460. }
  15461. index = newChildrens.length;
  15462. }
  15463. });
  15464. if(newChildrens.length) {
  15465. li.children = newChildrens;
  15466. }
  15467. });
  15468. });
  15469. // 进入编辑器的li要套p标签
  15470. me.addInputRule(function(root) {
  15471. utils.each(root.getNodesByTagName('li'), function(li) {
  15472. var tmpP = UE.uNode.createElement('p');
  15473. for(var i = 0, ci; ci = li.children[i];) {
  15474. if(ci.type == 'text' || dtd.p[ci.tagName]) {
  15475. tmpP.appendChild(ci);
  15476. } else {
  15477. if(tmpP.firstChild()) {
  15478. li.insertBefore(tmpP, ci);
  15479. tmpP = UE.uNode.createElement('p');
  15480. i = i + 2;
  15481. } else {
  15482. i++;
  15483. }
  15484. }
  15485. }
  15486. if(tmpP.firstChild() && !tmpP.parentNode || !li.firstChild()) {
  15487. li.appendChild(tmpP);
  15488. }
  15489. // trace:3357
  15490. // p不能为空
  15491. if(!tmpP.firstChild()) {
  15492. tmpP.innerHTML(browser.ie ? '&nbsp;' : '<br/>')
  15493. }
  15494. // 去掉末尾的空白
  15495. var p = li.firstChild();
  15496. var lastChild = p.lastChild();
  15497. if(lastChild && lastChild.type == 'text' &&
  15498. /^\s*$/.test(lastChild.data)) {
  15499. p.removeChild(lastChild)
  15500. }
  15501. });
  15502. if(me.options.autoTransWordToList) {
  15503. var orderlisttype = {
  15504. 'num1': /^\d+\)/,
  15505. 'decimal': /^\d+\./,
  15506. 'lower-alpha': /^[a-z]+\)/,
  15507. 'upper-alpha': /^[A-Z]+\./,
  15508. 'cn': /^[\u4E00\u4E8C\u4E09\u56DB\u516d\u4e94\u4e03\u516b\u4e5d]+[\u3001]/,
  15509. 'cn2': /^\([\u4E00\u4E8C\u4E09\u56DB\u516d\u4e94\u4e03\u516b\u4e5d]+\)/
  15510. },
  15511. unorderlisttype = {
  15512. 'square': 'n'
  15513. };
  15514. function checkListType(content, container) {
  15515. var span = container.firstChild();
  15516. if(span &&
  15517. span.type == 'element' &&
  15518. span.tagName == 'span' &&
  15519. /Wingdings|Symbol/.test(span
  15520. .getStyle('font-family'))) {
  15521. for(var p in unorderlisttype) {
  15522. if(unorderlisttype[p] == span.data) {
  15523. return p
  15524. }
  15525. }
  15526. return 'disc'
  15527. }
  15528. for(var p in orderlisttype) {
  15529. if(orderlisttype[p].test(content)) {
  15530. return p;
  15531. }
  15532. }
  15533. }
  15534. utils.each(root.getNodesByTagName('p'), function(node) {
  15535. if(node.getAttr('class') != 'MsoListParagraph') {
  15536. return
  15537. }
  15538. // word粘贴过来的会带有margin要去掉,但这样也可能会误命中一些央视
  15539. node.setStyle('margin', '');
  15540. node.setStyle('margin-left', '');
  15541. node.setAttr('class', '');
  15542. function appendLi(list, p, type) {
  15543. if(list.tagName == 'ol') {
  15544. if(browser.ie) {
  15545. var first = p.firstChild();
  15546. if(first.type == 'element' &&
  15547. first.tagName == 'span' &&
  15548. orderlisttype[type].test(first
  15549. .innerText())) {
  15550. p.removeChild(first);
  15551. }
  15552. } else {
  15553. p.innerHTML(p.innerHTML().replace(
  15554. orderlisttype[type], ''));
  15555. }
  15556. } else {
  15557. p.removeChild(p.firstChild())
  15558. }
  15559. var li = UE.uNode.createElement('li');
  15560. li.appendChild(p);
  15561. list.appendChild(li);
  15562. }
  15563. var tmp = node,
  15564. type, cacheNode = node;
  15565. if(node.parentNode.tagName != 'li' &&
  15566. (type = checkListType(node.innerText(), node))) {
  15567. var list = UE.uNode
  15568. .createElement(me.options.insertorderedlist
  15569. .hasOwnProperty(type) ? 'ol' : 'ul');
  15570. if(customStyle[type]) {
  15571. list.setAttr('class', 'custom_' + type)
  15572. } else {
  15573. list.setStyle('list-style-type', type)
  15574. }
  15575. while(node && node.parentNode.tagName != 'li' &&
  15576. checkListType(node.innerText(), node)) {
  15577. tmp = node.nextSibling();
  15578. if(!tmp) {
  15579. node.parentNode.insertBefore(list, node)
  15580. }
  15581. appendLi(list, node, type);
  15582. node = tmp;
  15583. }
  15584. if(!list.parentNode && node && node.parentNode) {
  15585. node.parentNode.insertBefore(list, node)
  15586. }
  15587. }
  15588. var span = cacheNode.firstChild();
  15589. if(span && span.type == 'element' &&
  15590. span.tagName == 'span' &&
  15591. /^\s*(&nbsp;)+\s*$/.test(span.innerText())) {
  15592. span.parentNode.removeChild(span)
  15593. }
  15594. })
  15595. }
  15596. });
  15597. // 调整索引标签
  15598. me.addListener('contentchange', function() {
  15599. adjustListStyle(me.document)
  15600. });
  15601. function adjustListStyle(doc, ignore) {
  15602. utils.each(domUtils.getElementsByTagName(doc, 'ol ul'), function(
  15603. node) {
  15604. if(!domUtils.inDoc(node, doc))
  15605. return;
  15606. var parent = node.parentNode;
  15607. if(parent.tagName == node.tagName) {
  15608. var nodeStyleType = getStyle(node) ||
  15609. (node.tagName == 'OL' ? 'decimal' : 'disc'),
  15610. parentStyleType = getStyle(parent) ||
  15611. (parent.tagName == 'OL' ? 'decimal' : 'disc');
  15612. if(nodeStyleType == parentStyleType) {
  15613. var styleIndex = utils.indexOf(listStyle[node.tagName],
  15614. nodeStyleType);
  15615. styleIndex = styleIndex + 1 == listStyle[node.tagName].length ?
  15616. 0 :
  15617. styleIndex + 1;
  15618. setListStyle(node, listStyle[node.tagName][styleIndex])
  15619. }
  15620. }
  15621. var index = 0,
  15622. type = 2;
  15623. if(domUtils.hasClass(node, /custom_/)) {
  15624. if(!(/[ou]l/i.test(parent.tagName) && domUtils.hasClass(
  15625. parent, /custom_/))) {
  15626. type = 1;
  15627. }
  15628. } else {
  15629. if(/[ou]l/i.test(parent.tagName) &&
  15630. domUtils.hasClass(parent, /custom_/)) {
  15631. type = 3;
  15632. }
  15633. }
  15634. var style = domUtils.getStyle(node, 'list-style-type');
  15635. style && (node.style.cssText = 'list-style-type:' + style);
  15636. node.className = utils.trim(node.className.replace(
  15637. /list-paddingleft-\w+/, '')) +
  15638. ' list-paddingleft-' + type;
  15639. utils.each(domUtils.getElementsByTagName(node, 'li'), function(
  15640. li) {
  15641. li.style.cssText && (li.style.cssText = '');
  15642. if(!li.firstChild) {
  15643. domUtils.remove(li);
  15644. return;
  15645. }
  15646. if(li.parentNode !== node) {
  15647. return;
  15648. }
  15649. index++;
  15650. if(domUtils.hasClass(node, /custom_/)) {
  15651. var paddingLeft = 1,
  15652. currentStyle = getStyle(node);
  15653. if(node.tagName == 'OL') {
  15654. if(currentStyle) {
  15655. switch(currentStyle) {
  15656. case 'cn':
  15657. case 'cn1':
  15658. case 'cn2':
  15659. if(index > 10 &&
  15660. (index % 10 == 0 || index > 10 &&
  15661. index < 20)) {
  15662. paddingLeft = 2
  15663. } else if(index > 20) {
  15664. paddingLeft = 3
  15665. }
  15666. break;
  15667. case 'num2':
  15668. if(index > 9) {
  15669. paddingLeft = 2
  15670. }
  15671. }
  15672. }
  15673. li.className = 'list-' + customStyle[currentStyle] +
  15674. index + ' ' + 'list-' + currentStyle +
  15675. '-paddingleft-' + paddingLeft;
  15676. } else {
  15677. li.className = 'list-' + customStyle[currentStyle] +
  15678. ' ' + 'list-' + currentStyle +
  15679. '-paddingleft';
  15680. }
  15681. } else {
  15682. li.className = li.className.replace(/list-[\w\-]+/gi,
  15683. '');
  15684. }
  15685. var className = li.getAttribute('class');
  15686. if(className !== null && !className.replace(/\s/g, '')) {
  15687. domUtils.removeAttributes(li, 'class')
  15688. }
  15689. });
  15690. !ignore
  15691. &&
  15692. adjustList(node, node.tagName.toLowerCase(),
  15693. getStyle(node) ||
  15694. domUtils.getStyle(node,
  15695. 'list-style-type'), true);
  15696. })
  15697. }
  15698. function adjustList(list, tag, style, ignoreEmpty) {
  15699. var nextList = list.nextSibling;
  15700. if(nextList &&
  15701. nextList.nodeType == 1 &&
  15702. nextList.tagName.toLowerCase() == tag &&
  15703. (getStyle(nextList) ||
  15704. domUtils.getStyle(nextList, 'list-style-type') || (tag == 'ol' ?
  15705. 'decimal' :
  15706. 'disc')) == style) {
  15707. domUtils.moveChild(nextList, list);
  15708. if(nextList.childNodes.length == 0) {
  15709. domUtils.remove(nextList);
  15710. }
  15711. }
  15712. if(nextList && domUtils.isFillChar(nextList)) {
  15713. domUtils.remove(nextList);
  15714. }
  15715. var preList = list.previousSibling;
  15716. if(preList &&
  15717. preList.nodeType == 1 &&
  15718. preList.tagName.toLowerCase() == tag &&
  15719. (getStyle(preList) ||
  15720. domUtils.getStyle(preList, 'list-style-type') || (tag == 'ol' ?
  15721. 'decimal' :
  15722. 'disc')) == style) {
  15723. domUtils.moveChild(list, preList);
  15724. }
  15725. if(preList && domUtils.isFillChar(preList)) {
  15726. domUtils.remove(preList);
  15727. }!ignoreEmpty && domUtils.isEmptyBlock(list) &&
  15728. domUtils.remove(list);
  15729. if(getStyle(list)) {
  15730. adjustListStyle(list.ownerDocument, true)
  15731. }
  15732. }
  15733. function setListStyle(list, style) {
  15734. if(customStyle[style]) {
  15735. list.className = 'custom_' + style;
  15736. }
  15737. try {
  15738. domUtils.setStyle(list, 'list-style-type', style);
  15739. } catch(e) {}
  15740. }
  15741. function clearEmptySibling(node) {
  15742. var tmpNode = node.previousSibling;
  15743. if(tmpNode && domUtils.isEmptyBlock(tmpNode)) {
  15744. domUtils.remove(tmpNode);
  15745. }
  15746. tmpNode = node.nextSibling;
  15747. if(tmpNode && domUtils.isEmptyBlock(tmpNode)) {
  15748. domUtils.remove(tmpNode);
  15749. }
  15750. }
  15751. me.addListener('keydown', function(type, evt) {
  15752. function preventAndSave() {
  15753. evt.preventDefault ?
  15754. evt.preventDefault() :
  15755. (evt.returnValue = false);
  15756. me.fireEvent('contentchange');
  15757. me.undoManger && me.undoManger.save();
  15758. }
  15759. function findList(node, filterFn) {
  15760. while(node && !domUtils.isBody(node)) {
  15761. if(filterFn(node)) {
  15762. return null
  15763. }
  15764. if(node.nodeType == 1 && /[ou]l/i.test(node.tagName)) {
  15765. return node;
  15766. }
  15767. node = node.parentNode;
  15768. }
  15769. return null;
  15770. }
  15771. var keyCode = evt.keyCode || evt.which;
  15772. if(keyCode == 13 && !evt.shiftKey) { // 回车
  15773. var rng = me.selection.getRange(),
  15774. parent = domUtils
  15775. .findParent(rng.startContainer, function(node) {
  15776. return domUtils.isBlockElm(node)
  15777. }, true),
  15778. li = domUtils.findParentByTagName(
  15779. rng.startContainer, 'li', true);
  15780. if(parent && parent.tagName != 'PRE' && !li) {
  15781. var html = parent.innerHTML.replace(new RegExp(
  15782. domUtils.fillChar, 'g'), '');
  15783. if(/^\s*1\s*\.[^\d]/.test(html)) {
  15784. parent.innerHTML = html.replace(/^\s*1\s*\./, '');
  15785. rng.setStartAtLast(parent).collapse(true).select();
  15786. me.__hasEnterExecCommand = true;
  15787. me.execCommand('insertorderedlist');
  15788. me.__hasEnterExecCommand = false;
  15789. }
  15790. }
  15791. var range = me.selection.getRange(),
  15792. start = findList(
  15793. range.startContainer,
  15794. function(node) {
  15795. return node.tagName == 'TABLE';
  15796. }),
  15797. end = range.collapsed ? start : findList(
  15798. range.endContainer,
  15799. function(node) {
  15800. return node.tagName == 'TABLE';
  15801. });
  15802. if(start && end && start === end) {
  15803. if(!range.collapsed) {
  15804. start = domUtils.findParentByTagName(
  15805. range.startContainer, 'li', true);
  15806. end = domUtils.findParentByTagName(range.endContainer,
  15807. 'li', true);
  15808. if(start && end && start === end) {
  15809. range.deleteContents();
  15810. li = domUtils.findParentByTagName(
  15811. range.startContainer, 'li', true);
  15812. if(li && domUtils.isEmptyBlock(li)) {
  15813. pre = li.previousSibling;
  15814. next = li.nextSibling;
  15815. p = me.document.createElement('p');
  15816. domUtils.fillNode(me.document, p);
  15817. parentList = li.parentNode;
  15818. if(pre && next) {
  15819. range.setStart(next, 0).collapse(true)
  15820. .select(true);
  15821. domUtils.remove(li);
  15822. } else {
  15823. if(!pre && !next || !pre) {
  15824. parentList.parentNode.insertBefore(p,
  15825. parentList);
  15826. } else {
  15827. li.parentNode.parentNode.insertBefore(
  15828. p, parentList.nextSibling);
  15829. }
  15830. domUtils.remove(li);
  15831. if(!parentList.firstChild) {
  15832. domUtils.remove(parentList);
  15833. }
  15834. range.setStart(p, 0).setCursor();
  15835. }
  15836. preventAndSave();
  15837. return;
  15838. }
  15839. } else {
  15840. var tmpRange = range.cloneRange(),
  15841. bk = tmpRange
  15842. .collapse(false).createBookmark();
  15843. range.deleteContents();
  15844. tmpRange.moveToBookmark(bk);
  15845. var li = domUtils.findParentByTagName(
  15846. tmpRange.startContainer, 'li', true);
  15847. clearEmptySibling(li);
  15848. tmpRange.select();
  15849. preventAndSave();
  15850. return;
  15851. }
  15852. }
  15853. li = domUtils.findParentByTagName(range.startContainer,
  15854. 'li', true);
  15855. if(li) {
  15856. if(domUtils.isEmptyBlock(li)) {
  15857. bk = range.createBookmark();
  15858. var parentList = li.parentNode;
  15859. if(li !== parentList.lastChild) {
  15860. domUtils.breakParent(li, parentList);
  15861. clearEmptySibling(li);
  15862. } else {
  15863. parentList.parentNode.insertBefore(li,
  15864. parentList.nextSibling);
  15865. if(domUtils.isEmptyNode(parentList)) {
  15866. domUtils.remove(parentList);
  15867. }
  15868. }
  15869. // 嵌套不处理
  15870. if(!dtd.$list[li.parentNode.tagName]) {
  15871. if(!domUtils.isBlockElm(li.firstChild)) {
  15872. p = me.document.createElement('p');
  15873. li.parentNode.insertBefore(p, li);
  15874. while(li.firstChild) {
  15875. p.appendChild(li.firstChild);
  15876. }
  15877. domUtils.remove(li);
  15878. } else {
  15879. domUtils.remove(li, true);
  15880. }
  15881. }
  15882. range.moveToBookmark(bk).select();
  15883. } else {
  15884. var first = li.firstChild;
  15885. if(!first || !domUtils.isBlockElm(first)) {
  15886. var p = me.document.createElement('p');
  15887. !li.firstChild &&
  15888. domUtils.fillNode(me.document, p);
  15889. while(li.firstChild) {
  15890. p.appendChild(li.firstChild);
  15891. }
  15892. li.appendChild(p);
  15893. first = p;
  15894. }
  15895. var span = me.document.createElement('span');
  15896. range.insertNode(span);
  15897. domUtils.breakParent(span, li);
  15898. var nextLi = span.nextSibling;
  15899. first = nextLi.firstChild;
  15900. if(!first) {
  15901. p = me.document.createElement('p');
  15902. domUtils.fillNode(me.document, p);
  15903. nextLi.appendChild(p);
  15904. first = p;
  15905. }
  15906. if(domUtils.isEmptyNode(first)) {
  15907. first.innerHTML = '';
  15908. domUtils.fillNode(me.document, first);
  15909. }
  15910. range.setStart(first, 0).collapse(true)
  15911. .shrinkBoundary().select();
  15912. domUtils.remove(span);
  15913. var pre = nextLi.previousSibling;
  15914. if(pre && domUtils.isEmptyBlock(pre)) {
  15915. pre.innerHTML = '<p></p>';
  15916. domUtils.fillNode(me.document, pre.firstChild);
  15917. }
  15918. }
  15919. // }
  15920. preventAndSave();
  15921. }
  15922. }
  15923. }
  15924. if(keyCode == 8) {
  15925. // 修中ie中li下的问题
  15926. range = me.selection.getRange();
  15927. if(range.collapsed && domUtils.isStartInblock(range)) {
  15928. tmpRange = range.cloneRange().trimBoundary();
  15929. li = domUtils.findParentByTagName(range.startContainer,
  15930. 'li', true);
  15931. // 要在li的最左边,才能处理
  15932. if(li && domUtils.isStartInblock(tmpRange)) {
  15933. start = domUtils.findParentByTagName(
  15934. range.startContainer, 'p', true);
  15935. if(start && start !== li.firstChild) {
  15936. var parentList = domUtils.findParentByTagName(
  15937. start, ['ol', 'ul']);
  15938. domUtils.breakParent(start, parentList);
  15939. clearEmptySibling(start);
  15940. me.fireEvent('contentchange');
  15941. range.setStart(start, 0).setCursor(false, true);
  15942. me.fireEvent('saveScene');
  15943. domUtils.preventDefault(evt);
  15944. return;
  15945. }
  15946. if(li && (pre = li.previousSibling)) {
  15947. if(keyCode == 46 && li.childNodes.length) {
  15948. return;
  15949. }
  15950. // 有可能上边的兄弟节点是个2级菜单,要追加到2级菜单的最后的li
  15951. if(dtd.$list[pre.tagName]) {
  15952. pre = pre.lastChild;
  15953. }
  15954. me.undoManger && me.undoManger.save();
  15955. first = li.firstChild;
  15956. if(domUtils.isBlockElm(first)) {
  15957. if(domUtils.isEmptyNode(first)) {
  15958. // range.setEnd(pre,
  15959. // pre.childNodes.length).shrinkBoundary().collapse().select(true);
  15960. pre.appendChild(first);
  15961. range.setStart(first, 0).setCursor(false,
  15962. true);
  15963. // first不是唯一的节点
  15964. while(li.firstChild) {
  15965. pre.appendChild(li.firstChild);
  15966. }
  15967. } else {
  15968. span = me.document.createElement('span');
  15969. range.insertNode(span);
  15970. // 判断pre是否是空的节点,如果是<p><br/></p>类型的空节点,干掉p标签防止它占位
  15971. if(domUtils.isEmptyBlock(pre)) {
  15972. pre.innerHTML = '';
  15973. }
  15974. domUtils.moveChild(li, pre);
  15975. range.setStartBefore(span).collapse(true)
  15976. .select(true);
  15977. domUtils.remove(span);
  15978. }
  15979. } else {
  15980. if(domUtils.isEmptyNode(li)) {
  15981. var p = me.document.createElement('p');
  15982. pre.appendChild(p);
  15983. range.setStart(p, 0).setCursor();
  15984. // range.setEnd(pre,
  15985. // pre.childNodes.length).shrinkBoundary().collapse().select(true);
  15986. } else {
  15987. range.setEnd(pre, pre.childNodes.length)
  15988. .collapse().select(true);
  15989. while(li.firstChild) {
  15990. pre.appendChild(li.firstChild);
  15991. }
  15992. }
  15993. }
  15994. domUtils.remove(li);
  15995. me.fireEvent('contentchange');
  15996. me.fireEvent('saveScene');
  15997. domUtils.preventDefault(evt);
  15998. return;
  15999. }
  16000. // trace:980
  16001. if(li && !li.previousSibling) {
  16002. var parentList = li.parentNode;
  16003. var bk = range.createBookmark();
  16004. if(domUtils.isTagNode(parentList.parentNode,
  16005. 'ol ul')) {
  16006. parentList.parentNode.insertBefore(li,
  16007. parentList);
  16008. if(domUtils.isEmptyNode(parentList)) {
  16009. domUtils.remove(parentList)
  16010. }
  16011. } else {
  16012. while(li.firstChild) {
  16013. parentList.parentNode.insertBefore(
  16014. li.firstChild, parentList);
  16015. }
  16016. domUtils.remove(li);
  16017. if(domUtils.isEmptyNode(parentList)) {
  16018. domUtils.remove(parentList)
  16019. }
  16020. }
  16021. range.moveToBookmark(bk).setCursor(false, true);
  16022. me.fireEvent('contentchange');
  16023. me.fireEvent('saveScene');
  16024. domUtils.preventDefault(evt);
  16025. return;
  16026. }
  16027. }
  16028. }
  16029. }
  16030. });
  16031. me.addListener('keyup', function(type, evt) {
  16032. var keyCode = evt.keyCode || evt.which;
  16033. if(keyCode == 8) {
  16034. var rng = me.selection.getRange(),
  16035. list;
  16036. if(list = domUtils.findParentByTagName(rng.startContainer, [
  16037. 'ol', 'ul'
  16038. ], true)) {
  16039. adjustList(list, list.tagName.toLowerCase(), getStyle(list) ||
  16040. domUtils.getComputedStyle(list,
  16041. 'list-style-type'), true)
  16042. }
  16043. }
  16044. });
  16045. // 处理tab键
  16046. me.addListener('tabkeydown', function() {
  16047. var range = me.selection.getRange();
  16048. // 控制级数
  16049. function checkLevel(li) {
  16050. if(me.options.maxListLevel != -1) {
  16051. var level = li.parentNode,
  16052. levelNum = 0;
  16053. while(/[ou]l/i.test(level.tagName)) {
  16054. levelNum++;
  16055. level = level.parentNode;
  16056. }
  16057. if(levelNum >= me.options.maxListLevel) {
  16058. return true;
  16059. }
  16060. }
  16061. }
  16062. // 只以开始为准
  16063. // todo 后续改进
  16064. var li = domUtils.findParentByTagName(range.startContainer, 'li',
  16065. true);
  16066. if(li) {
  16067. var bk;
  16068. if(range.collapsed) {
  16069. if(checkLevel(li))
  16070. return true;
  16071. var parentLi = li.parentNode,
  16072. list = me.document
  16073. .createElement(parentLi.tagName),
  16074. index = utils
  16075. .indexOf(listStyle[list.tagName],
  16076. getStyle(parentLi) ||
  16077. domUtils
  16078. .getComputedStyle(parentLi,
  16079. 'list-style-type'));
  16080. index = index + 1 == listStyle[list.tagName].length ?
  16081. 0 :
  16082. index + 1;
  16083. var currentStyle = listStyle[list.tagName][index];
  16084. setListStyle(list, currentStyle);
  16085. if(domUtils.isStartInblock(range)) {
  16086. me.fireEvent('saveScene');
  16087. bk = range.createBookmark();
  16088. parentLi.insertBefore(list, li);
  16089. list.appendChild(li);
  16090. adjustList(list, list.tagName.toLowerCase(),
  16091. currentStyle);
  16092. me.fireEvent('contentchange');
  16093. range.moveToBookmark(bk).select(true);
  16094. return true;
  16095. }
  16096. } else {
  16097. me.fireEvent('saveScene');
  16098. bk = range.createBookmark();
  16099. for(var i = 0, closeList, parents = domUtils
  16100. .findParents(li), ci; ci = parents[i++];) {
  16101. if(domUtils.isTagNode(ci, 'ol ul')) {
  16102. closeList = ci;
  16103. break;
  16104. }
  16105. }
  16106. var current = li;
  16107. if(bk.end) {
  16108. while(current &&
  16109. !(domUtils.getPosition(current, bk.end) & domUtils.POSITION_FOLLOWING)) {
  16110. if(checkLevel(current)) {
  16111. current = domUtils.getNextDomNode(current,
  16112. false, null,
  16113. function(node) {
  16114. return node !== closeList
  16115. });
  16116. continue;
  16117. }
  16118. var parentLi = current.parentNode,
  16119. list = me.document
  16120. .createElement(parentLi.tagName),
  16121. index = utils
  16122. .indexOf(
  16123. listStyle[list.tagName],
  16124. getStyle(parentLi) ||
  16125. domUtils
  16126. .getComputedStyle(
  16127. parentLi,
  16128. 'list-style-type'));
  16129. var currentIndex = index + 1 == listStyle[list.tagName].length ?
  16130. 0 :
  16131. index + 1;
  16132. var currentStyle = listStyle[list.tagName][currentIndex];
  16133. setListStyle(list, currentStyle);
  16134. parentLi.insertBefore(list, current);
  16135. while(current &&
  16136. !(domUtils.getPosition(current, bk.end) & domUtils.POSITION_FOLLOWING)) {
  16137. li = current.nextSibling;
  16138. list.appendChild(current);
  16139. if(!li || domUtils.isTagNode(li, 'ol ul')) {
  16140. if(li) {
  16141. while(li = li.firstChild) {
  16142. if(li.tagName == 'LI') {
  16143. break;
  16144. }
  16145. }
  16146. } else {
  16147. li = domUtils.getNextDomNode(current,
  16148. false, null,
  16149. function(node) {
  16150. return node !== closeList
  16151. });
  16152. }
  16153. break;
  16154. }
  16155. current = li;
  16156. }
  16157. adjustList(list, list.tagName.toLowerCase(),
  16158. currentStyle);
  16159. current = li;
  16160. }
  16161. }
  16162. me.fireEvent('contentchange');
  16163. range.moveToBookmark(bk).select();
  16164. return true;
  16165. }
  16166. }
  16167. });
  16168. function getLi(start) {
  16169. while(start && !domUtils.isBody(start)) {
  16170. if(start.nodeName == 'TABLE') {
  16171. return null;
  16172. }
  16173. if(start.nodeName == 'LI') {
  16174. return start
  16175. }
  16176. start = start.parentNode;
  16177. }
  16178. }
  16179. /**
  16180. * 有序列表,与“insertunorderedlist”命令互斥
  16181. *
  16182. * @command insertorderedlist
  16183. * @method execCommand
  16184. * @param {
  16185. * String } command 命令字符串
  16186. * @param {
  16187. * String } style
  16188. * 插入的有序列表类型,值为:decimal,lower-alpha,lower-roman,upper-alpha,upper-roman,cn,cn1,cn2,num,num1,num2
  16189. * @example ```javascript editor.execCommand(
  16190. * 'insertorderedlist','decimal'); ```
  16191. */
  16192. /**
  16193. * 查询当前选区内容是否有序列表
  16194. *
  16195. * @command insertorderedlist
  16196. * @method queryCommandState
  16197. * @param {
  16198. * String } cmd 命令字符串
  16199. * @return { int } 如果当前选区是有序列表返回1,否则返回0
  16200. * @example ```javascript editor.queryCommandState( 'insertorderedlist' );
  16201. * ```
  16202. */
  16203. /**
  16204. * 查询当前选区内容是否有序列表
  16205. *
  16206. * @command insertorderedlist
  16207. * @method queryCommandValue
  16208. * @param {
  16209. * String } cmd 命令字符串
  16210. * @return { String }
  16211. * 返回当前有序列表的类型,值为null或decimal,lower-alpha,lower-roman,upper-alpha,upper-roman,cn,cn1,cn2,num,num1,num2
  16212. * @example ```javascript editor.queryCommandValue( 'insertorderedlist' );
  16213. * ```
  16214. */
  16215. /**
  16216. * 无序列表,与“insertorderedlist”命令互斥
  16217. *
  16218. * @command insertunorderedlist
  16219. * @method execCommand
  16220. * @param {
  16221. * String } command 命令字符串
  16222. * @param {
  16223. * String } style 插入的无序列表类型,值为:circle,disc,square,dash,dot
  16224. * @example ```javascript editor.execCommand(
  16225. * 'insertunorderedlist','circle'); ```
  16226. */
  16227. /**
  16228. * 查询当前是否有word文档粘贴进来的图片
  16229. *
  16230. * @command insertunorderedlist
  16231. * @method insertunorderedlist
  16232. * @param {
  16233. * String } command 命令字符串
  16234. * @return { int } 如果当前选区是无序列表返回1,否则返回0
  16235. * @example ```javascript editor.queryCommandState(
  16236. * 'insertunorderedlist' ); ```
  16237. */
  16238. /**
  16239. * 查询当前选区内容是否有序列表
  16240. *
  16241. * @command insertunorderedlist
  16242. * @method queryCommandValue
  16243. * @param {
  16244. * String } command 命令字符串
  16245. * @return { String } 返回当前无序列表的类型,值为null或circle,disc,square,dash,dot
  16246. * @example ```javascript editor.queryCommandValue(
  16247. * 'insertunorderedlist' ); ```
  16248. */
  16249. me.commands['insertorderedlist'] = me.commands['insertunorderedlist'] = {
  16250. execCommand: function(command, style) {
  16251. if(!style) {
  16252. style = command.toLowerCase() == 'insertorderedlist' ?
  16253. 'decimal' :
  16254. 'disc';
  16255. }
  16256. var me = this,
  16257. range = this.selection.getRange(),
  16258. filterFn = function(
  16259. node) {
  16260. return node.nodeType == 1 ?
  16261. node.tagName.toLowerCase() != 'br' :
  16262. !domUtils.isWhitespace(node);
  16263. },
  16264. tag = command.toLowerCase() == 'insertorderedlist' ?
  16265. 'ol' :
  16266. 'ul',
  16267. frag = me.document.createDocumentFragment();
  16268. // 去掉是因为会出现选到末尾,导致adjustmentBoundary缩到ol/ul的位置
  16269. // range.shrinkBoundary();//.adjustmentBoundary();
  16270. range.adjustmentBoundary().shrinkBoundary();
  16271. var bko = range.createBookmark(true),
  16272. start = getLi(me.document
  16273. .getElementById(bko.start)),
  16274. modifyStart = 0,
  16275. end = getLi(me.document
  16276. .getElementById(bko.end)),
  16277. modifyEnd = 0,
  16278. startParent, endParent, list, tmp;
  16279. if(start || end) {
  16280. start && (startParent = start.parentNode);
  16281. if(!bko.end) {
  16282. end = start;
  16283. }
  16284. end && (endParent = end.parentNode);
  16285. if(startParent === endParent) {
  16286. while(start !== end) {
  16287. tmp = start;
  16288. start = start.nextSibling;
  16289. if(!domUtils.isBlockElm(tmp.firstChild)) {
  16290. var p = me.document.createElement('p');
  16291. while(tmp.firstChild) {
  16292. p.appendChild(tmp.firstChild);
  16293. }
  16294. tmp.appendChild(p);
  16295. }
  16296. frag.appendChild(tmp);
  16297. }
  16298. tmp = me.document.createElement('span');
  16299. startParent.insertBefore(tmp, end);
  16300. if(!domUtils.isBlockElm(end.firstChild)) {
  16301. p = me.document.createElement('p');
  16302. while(end.firstChild) {
  16303. p.appendChild(end.firstChild);
  16304. }
  16305. end.appendChild(p);
  16306. }
  16307. frag.appendChild(end);
  16308. domUtils.breakParent(tmp, startParent);
  16309. if(domUtils.isEmptyNode(tmp.previousSibling)) {
  16310. domUtils.remove(tmp.previousSibling);
  16311. }
  16312. if(domUtils.isEmptyNode(tmp.nextSibling)) {
  16313. domUtils.remove(tmp.nextSibling)
  16314. }
  16315. var nodeStyle = getStyle(startParent) ||
  16316. domUtils.getComputedStyle(startParent,
  16317. 'list-style-type') ||
  16318. (command.toLowerCase() == 'insertorderedlist' ?
  16319. 'decimal' :
  16320. 'disc');
  16321. if(startParent.tagName.toLowerCase() == tag &&
  16322. nodeStyle == style) {
  16323. for(var i = 0, ci, tmpFrag = me.document
  16324. .createDocumentFragment(); ci = frag.firstChild;) {
  16325. if(domUtils.isTagNode(ci, 'ol ul')) {
  16326. // 删除时,子列表不处理
  16327. // utils.each(domUtils.getElementsByTagName(ci,'li'),function(li){
  16328. // while(li.firstChild){
  16329. // tmpFrag.appendChild(li.firstChild);
  16330. // }
  16331. //
  16332. // });
  16333. tmpFrag.appendChild(ci);
  16334. } else {
  16335. while(ci.firstChild) {
  16336. tmpFrag.appendChild(ci.firstChild);
  16337. domUtils.remove(ci);
  16338. }
  16339. }
  16340. }
  16341. tmp.parentNode.insertBefore(tmpFrag, tmp);
  16342. } else {
  16343. list = me.document.createElement(tag);
  16344. setListStyle(list, style);
  16345. list.appendChild(frag);
  16346. tmp.parentNode.insertBefore(list, tmp);
  16347. }
  16348. domUtils.remove(tmp);
  16349. list && adjustList(list, tag, style);
  16350. range.moveToBookmark(bko).select();
  16351. return;
  16352. }
  16353. // 开始
  16354. if(start) {
  16355. while(start) {
  16356. tmp = start.nextSibling;
  16357. if(domUtils.isTagNode(start, 'ol ul')) {
  16358. frag.appendChild(start);
  16359. } else {
  16360. var tmpfrag = me.document
  16361. .createDocumentFragment(),
  16362. hasBlock = 0;
  16363. while(start.firstChild) {
  16364. if(domUtils.isBlockElm(start.firstChild)) {
  16365. hasBlock = 1;
  16366. }
  16367. tmpfrag.appendChild(start.firstChild);
  16368. }
  16369. if(!hasBlock) {
  16370. var tmpP = me.document.createElement('p');
  16371. tmpP.appendChild(tmpfrag);
  16372. frag.appendChild(tmpP);
  16373. } else {
  16374. frag.appendChild(tmpfrag);
  16375. }
  16376. domUtils.remove(start);
  16377. }
  16378. start = tmp;
  16379. }
  16380. startParent.parentNode.insertBefore(frag,
  16381. startParent.nextSibling);
  16382. if(domUtils.isEmptyNode(startParent)) {
  16383. range.setStartBefore(startParent);
  16384. domUtils.remove(startParent);
  16385. } else {
  16386. range.setStartAfter(startParent);
  16387. }
  16388. modifyStart = 1;
  16389. }
  16390. if(end && domUtils.inDoc(endParent, me.document)) {
  16391. // 结束
  16392. start = endParent.firstChild;
  16393. while(start && start !== end) {
  16394. tmp = start.nextSibling;
  16395. if(domUtils.isTagNode(start, 'ol ul')) {
  16396. frag.appendChild(start);
  16397. } else {
  16398. tmpfrag = me.document.createDocumentFragment();
  16399. hasBlock = 0;
  16400. while(start.firstChild) {
  16401. if(domUtils.isBlockElm(start.firstChild)) {
  16402. hasBlock = 1;
  16403. }
  16404. tmpfrag.appendChild(start.firstChild);
  16405. }
  16406. if(!hasBlock) {
  16407. tmpP = me.document.createElement('p');
  16408. tmpP.appendChild(tmpfrag);
  16409. frag.appendChild(tmpP);
  16410. } else {
  16411. frag.appendChild(tmpfrag);
  16412. }
  16413. domUtils.remove(start);
  16414. }
  16415. start = tmp;
  16416. }
  16417. var tmpDiv = domUtils.createElement(me.document, 'div', {
  16418. 'tmpDiv': 1
  16419. });
  16420. domUtils.moveChild(end, tmpDiv);
  16421. frag.appendChild(tmpDiv);
  16422. domUtils.remove(end);
  16423. endParent.parentNode.insertBefore(frag, endParent);
  16424. range.setEndBefore(endParent);
  16425. if(domUtils.isEmptyNode(endParent)) {
  16426. domUtils.remove(endParent);
  16427. }
  16428. modifyEnd = 1;
  16429. }
  16430. }
  16431. if(!modifyStart) {
  16432. range.setStartBefore(me.document.getElementById(bko.start));
  16433. }
  16434. if(bko.end && !modifyEnd) {
  16435. range.setEndAfter(me.document.getElementById(bko.end));
  16436. }
  16437. range.enlarge(true, function(node) {
  16438. return notExchange[node.tagName];
  16439. });
  16440. frag = me.document.createDocumentFragment();
  16441. var bk = range.createBookmark(),
  16442. current = domUtils
  16443. .getNextDomNode(bk.start, false, filterFn),
  16444. tmpRange = range
  16445. .cloneRange(),
  16446. tmpNode, block = domUtils.isBlockElm;
  16447. while(current &&
  16448. current !== bk.end &&
  16449. (domUtils.getPosition(current, bk.end) & domUtils.POSITION_PRECEDING)) {
  16450. if(current.nodeType == 3 || dtd.li[current.tagName]) {
  16451. if(current.nodeType == 1 && dtd.$list[current.tagName]) {
  16452. while(current.firstChild) {
  16453. frag.appendChild(current.firstChild);
  16454. }
  16455. tmpNode = domUtils.getNextDomNode(current, false,
  16456. filterFn);
  16457. domUtils.remove(current);
  16458. current = tmpNode;
  16459. continue;
  16460. }
  16461. tmpNode = current;
  16462. tmpRange.setStartBefore(current);
  16463. while(current &&
  16464. current !== bk.end &&
  16465. (!block(current) || domUtils
  16466. .isBookmarkNode(current))) {
  16467. tmpNode = current;
  16468. current = domUtils.getNextDomNode(current, false,
  16469. null,
  16470. function(node) {
  16471. return !notExchange[node.tagName];
  16472. });
  16473. }
  16474. if(current && block(current)) {
  16475. tmp = domUtils.getNextDomNode(tmpNode, false,
  16476. filterFn);
  16477. if(tmp && domUtils.isBookmarkNode(tmp)) {
  16478. current = domUtils.getNextDomNode(tmp, false,
  16479. filterFn);
  16480. tmpNode = tmp;
  16481. }
  16482. }
  16483. tmpRange.setEndAfter(tmpNode);
  16484. current = domUtils.getNextDomNode(tmpNode, false,
  16485. filterFn);
  16486. var li = range.document.createElement('li');
  16487. li.appendChild(tmpRange.extractContents());
  16488. if(domUtils.isEmptyNode(li)) {
  16489. var tmpNode = range.document.createElement('p');
  16490. while(li.firstChild) {
  16491. tmpNode.appendChild(li.firstChild)
  16492. }
  16493. li.appendChild(tmpNode);
  16494. }
  16495. frag.appendChild(li);
  16496. } else {
  16497. current = domUtils.getNextDomNode(current, true,
  16498. filterFn);
  16499. }
  16500. }
  16501. range.moveToBookmark(bk).collapse(true);
  16502. list = me.document.createElement(tag);
  16503. setListStyle(list, style);
  16504. list.appendChild(frag);
  16505. range.insertNode(list);
  16506. // 当前list上下看能否合并
  16507. adjustList(list, tag, style);
  16508. // 去掉冗余的tmpDiv
  16509. for(var i = 0, ci, tmpDivs = domUtils.getElementsByTagName(
  16510. list, 'div'); ci = tmpDivs[i++];) {
  16511. if(ci.getAttribute('tmpDiv')) {
  16512. domUtils.remove(ci, true)
  16513. }
  16514. }
  16515. range.moveToBookmark(bko).select();
  16516. },
  16517. queryCommandState: function(command) {
  16518. var tag = command.toLowerCase() == 'insertorderedlist' ?
  16519. 'ol' :
  16520. 'ul';
  16521. var path = this.selection.getStartElementPath();
  16522. for(var i = 0, ci; ci = path[i++];) {
  16523. if(ci.nodeName == 'TABLE') {
  16524. return 0
  16525. }
  16526. if(tag == ci.nodeName.toLowerCase()) {
  16527. return 1
  16528. };
  16529. }
  16530. return 0;
  16531. },
  16532. queryCommandValue: function(command) {
  16533. var tag = command.toLowerCase() == 'insertorderedlist' ?
  16534. 'ol' :
  16535. 'ul';
  16536. var path = this.selection.getStartElementPath(),
  16537. node;
  16538. for(var i = 0, ci; ci = path[i++];) {
  16539. if(ci.nodeName == 'TABLE') {
  16540. node = null;
  16541. break;
  16542. }
  16543. if(tag == ci.nodeName.toLowerCase()) {
  16544. node = ci;
  16545. break;
  16546. };
  16547. }
  16548. return node ?
  16549. getStyle(node) ||
  16550. domUtils.getComputedStyle(node,
  16551. 'list-style-type') :
  16552. null;
  16553. }
  16554. };
  16555. };
  16556. // plugins/source.js
  16557. /**
  16558. * 源码编辑插件
  16559. *
  16560. * @file
  16561. * @since 1.2.6.1
  16562. */
  16563. (function() {
  16564. var sourceEditors = {
  16565. textarea: function(editor, holder) {
  16566. var textarea = holder.ownerDocument.createElement('textarea');
  16567. textarea.style.cssText = 'position:absolute;resize:none;width:100%;height:100%;border:0;padding:0;margin:0;overflow-y:auto;';
  16568. // todo: IE下只有onresize属性可用... 很纠结
  16569. if(browser.ie && browser.version < 8) {
  16570. textarea.style.width = holder.offsetWidth + 'px';
  16571. textarea.style.height = holder.offsetHeight + 'px';
  16572. holder.onresize = function() {
  16573. textarea.style.width = holder.offsetWidth + 'px';
  16574. textarea.style.height = holder.offsetHeight + 'px';
  16575. };
  16576. }
  16577. holder.appendChild(textarea);
  16578. return {
  16579. setContent: function(content) {
  16580. textarea.value = content;
  16581. },
  16582. getContent: function() {
  16583. return textarea.value;
  16584. },
  16585. select: function() {
  16586. var range;
  16587. if(browser.ie) {
  16588. range = textarea.createTextRange();
  16589. range.collapse(true);
  16590. range.select();
  16591. } else {
  16592. // todo: chrome下无法设置焦点
  16593. textarea.setSelectionRange(0, 0);
  16594. textarea.focus();
  16595. }
  16596. },
  16597. dispose: function() {
  16598. holder.removeChild(textarea);
  16599. // todo
  16600. holder.onresize = null;
  16601. textarea = null;
  16602. holder = null;
  16603. }
  16604. };
  16605. },
  16606. codemirror: function(editor, holder) {
  16607. var codeEditor = window.CodeMirror(holder, {
  16608. mode: "text/html",
  16609. tabMode: "indent",
  16610. lineNumbers: true,
  16611. lineWrapping: true
  16612. });
  16613. var dom = codeEditor.getWrapperElement();
  16614. dom.style.cssText = 'position:absolute;left:0;top:0;width:100%;height:100%;font-family:consolas,"Courier new",monospace;font-size:13px;';
  16615. codeEditor.getScrollerElement().style.cssText = 'position:absolute;left:0;top:0;width:100%;height:100%;';
  16616. codeEditor.refresh();
  16617. return {
  16618. getCodeMirror: function() {
  16619. return codeEditor;
  16620. },
  16621. setContent: function(content) {
  16622. codeEditor.setValue(content);
  16623. },
  16624. getContent: function() {
  16625. return codeEditor.getValue();
  16626. },
  16627. select: function() {
  16628. codeEditor.focus();
  16629. },
  16630. dispose: function() {
  16631. holder.removeChild(dom);
  16632. dom = null;
  16633. codeEditor = null;
  16634. }
  16635. };
  16636. }
  16637. };
  16638. UE.plugins['source'] = function() {
  16639. var me = this;
  16640. var opt = this.options;
  16641. var sourceMode = false;
  16642. var sourceEditor;
  16643. var orgSetContent;
  16644. opt.sourceEditor = browser.ie ?
  16645. 'textarea' :
  16646. (opt.sourceEditor || 'codemirror');
  16647. me.setOpt({
  16648. sourceEditorFirst: false
  16649. });
  16650. function createSourceEditor(holder) {
  16651. return sourceEditors[opt.sourceEditor == 'codemirror' &&
  16652. window.CodeMirror ? 'codemirror' : 'textarea'](me,
  16653. holder);
  16654. }
  16655. var bakCssText;
  16656. // 解决在源码模式下getContent不能得到最新的内容问题
  16657. var oldGetContent, bakAddress;
  16658. /**
  16659. * 切换源码模式和编辑模式
  16660. *
  16661. * @command source
  16662. * @method execCommand
  16663. * @param {
  16664. * String } cmd 命令字符串
  16665. * @example ```javascript editor.execCommand( 'source'); ```
  16666. */
  16667. /**
  16668. * 查询当前编辑区域的状态是源码模式还是可视化模式
  16669. *
  16670. * @command source
  16671. * @method queryCommandState
  16672. * @param {
  16673. * String } cmd 命令字符串
  16674. * @return { int } 如果当前是源码编辑模式,返回1,否则返回0
  16675. * @example ```javascript editor.queryCommandState( 'source' ); ```
  16676. */
  16677. me.commands['source'] = {
  16678. execCommand: function() {
  16679. sourceMode = !sourceMode;
  16680. if(sourceMode) {
  16681. bakAddress = me.selection.getRange().createAddress(
  16682. false, true);
  16683. me.undoManger && me.undoManger.save(true);
  16684. if(browser.gecko) {
  16685. me.body.contentEditable = false;
  16686. }
  16687. bakCssText = me.iframe.style.cssText;
  16688. me.iframe.style.cssText += 'position:absolute;left:-32768px;top:-32768px;';
  16689. me.fireEvent('beforegetcontent');
  16690. var root = UE.htmlparser(me.body.innerHTML);
  16691. me.filterOutputRule(root);
  16692. root.traversal(function(node) {
  16693. if(node.type == 'element') {
  16694. switch(node.tagName) {
  16695. case 'td':
  16696. case 'th':
  16697. case 'caption':
  16698. if(node.children &&
  16699. node.children.length == 1) {
  16700. if(node.firstChild().tagName == 'br') {
  16701. node.removeChild(node
  16702. .firstChild())
  16703. }
  16704. };
  16705. break;
  16706. case 'pre':
  16707. node.innerText(node.innerText()
  16708. .replace(/&nbsp;/g, ' '))
  16709. }
  16710. }
  16711. });
  16712. me.fireEvent('aftergetcontent');
  16713. var content = root.toHtml(true);
  16714. sourceEditor = createSourceEditor(me.iframe.parentNode);
  16715. sourceEditor.setContent(content);
  16716. orgSetContent = me.setContent;
  16717. me.setContent = function(html) {
  16718. // 这里暂时不触发事件,防止报错
  16719. var root = UE.htmlparser(html);
  16720. me.filterInputRule(root);
  16721. html = root.toHtml();
  16722. sourceEditor.setContent(html);
  16723. };
  16724. setTimeout(function() {
  16725. sourceEditor.select();
  16726. me.addListener('fullscreenchanged', function() {
  16727. try {
  16728. sourceEditor.getCodeMirror().refresh()
  16729. } catch(e) {}
  16730. });
  16731. });
  16732. // 重置getContent,源码模式下取值也能是最新的数据
  16733. oldGetContent = me.getContent;
  16734. me.getContent = function() {
  16735. return sourceEditor.getContent() || '<p>' +
  16736. (browser.ie ? '' : '<br/>') + '</p>';
  16737. };
  16738. } else {
  16739. me.iframe.style.cssText = bakCssText;
  16740. var cont = sourceEditor.getContent() || '<p>' +
  16741. (browser.ie ? '' : '<br/>') + '</p>';
  16742. // 处理掉block节点前后的空格,有可能会误命中,暂时不考虑
  16743. cont = cont.replace(new RegExp(
  16744. '[\\r\\t\\n ]*<\/?(\\w+)\\s*(?:[^>]*)>', 'g'),
  16745. function(a, b) {
  16746. if(b && !dtd.$inlineWithA[b.toLowerCase()]) {
  16747. return a.replace(
  16748. /(^[\n\r\t ]*)|([\n\r\t ]*$)/g,
  16749. '');
  16750. }
  16751. return a.replace(
  16752. /(^[\n\r\t]*)|([\n\r\t]*$)/g, '')
  16753. });
  16754. me.setContent = orgSetContent;
  16755. me.setContent(cont);
  16756. sourceEditor.dispose();
  16757. sourceEditor = null;
  16758. // 还原getContent方法
  16759. me.getContent = oldGetContent;
  16760. var first = me.body.firstChild;
  16761. // trace:1106 都删除空了,下边会报错,所以补充一个p占位
  16762. if(!first) {
  16763. me.body.innerHTML = '<p>' +
  16764. (browser.ie ? '' : '<br/>') + '</p>';
  16765. first = me.body.firstChild;
  16766. }
  16767. // 要在ifm为显示时ff才能取到selection,否则报错
  16768. // 这里不能比较位置了
  16769. me.undoManger && me.undoManger.save(true);
  16770. if(browser.gecko) {
  16771. var input = document.createElement('input');
  16772. input.style.cssText = 'position:absolute;left:0;top:-32768px';
  16773. document.body.appendChild(input);
  16774. me.body.contentEditable = false;
  16775. setTimeout(function() {
  16776. domUtils.setViewportOffset(input, {
  16777. left: -32768,
  16778. top: 0
  16779. });
  16780. input.focus();
  16781. setTimeout(function() {
  16782. me.body.contentEditable = true;
  16783. me.selection.getRange()
  16784. .moveToAddress(bakAddress)
  16785. .select(true);
  16786. domUtils.remove(input);
  16787. });
  16788. });
  16789. } else {
  16790. // ie下有可能报错,比如在代码顶头的情况
  16791. try {
  16792. me.selection.getRange()
  16793. .moveToAddress(bakAddress).select(true);
  16794. } catch(e) {}
  16795. }
  16796. }
  16797. this.fireEvent('sourcemodechanged', sourceMode);
  16798. },
  16799. queryCommandState: function() {
  16800. return sourceMode | 0;
  16801. },
  16802. notNeedUndo: 1
  16803. };
  16804. var oldQueryCommandState = me.queryCommandState;
  16805. me.queryCommandState = function(cmdName) {
  16806. cmdName = cmdName.toLowerCase();
  16807. if(sourceMode) {
  16808. // 源码模式下可以开启的命令
  16809. return cmdName in {
  16810. 'source': 1,
  16811. 'fullscreen': 1
  16812. } ? 1 : -1
  16813. }
  16814. return oldQueryCommandState.apply(this, arguments);
  16815. };
  16816. if(opt.sourceEditor == "codemirror") {
  16817. me.addListener("ready", function() {
  16818. utils.loadFile(document, {
  16819. src: opt.codeMirrorJsUrl || opt.UEDITOR_HOME_URL +
  16820. "third-party/codemirror/codemirror.js",
  16821. tag: "script",
  16822. type: "text/javascript",
  16823. defer: "defer"
  16824. }, function() {
  16825. if(opt.sourceEditorFirst) {
  16826. setTimeout(function() {
  16827. me.execCommand("source");
  16828. }, 0);
  16829. }
  16830. });
  16831. utils.loadFile(document, {
  16832. tag: "link",
  16833. rel: "stylesheet",
  16834. type: "text/css",
  16835. href: opt.codeMirrorCssUrl || opt.UEDITOR_HOME_URL +
  16836. "third-party/codemirror/codemirror.css"
  16837. });
  16838. });
  16839. }
  16840. };
  16841. })();
  16842. // plugins/enterkey.js
  16843. // /import core
  16844. // /import plugins/undo.js
  16845. // /commands 设置回车标签p或br
  16846. // /commandsName EnterKey
  16847. // /commandsTitle 设置回车标签p或br
  16848. /**
  16849. * @description 处理回车
  16850. * @author zhanyi
  16851. */
  16852. UE.plugins['enterkey'] = function() {
  16853. var hTag, me = this,
  16854. tag = me.options.enterTag;
  16855. me.addListener('keyup', function(type, evt) {
  16856. var keyCode = evt.keyCode || evt.which;
  16857. if(keyCode == 13) {
  16858. var range = me.selection.getRange(),
  16859. start = range.startContainer,
  16860. doSave;
  16861. // 修正在h1-h6里边回车后不能嵌套p的问题
  16862. if(!browser.ie) {
  16863. if(/h\d/i.test(hTag)) {
  16864. if(browser.gecko) {
  16865. var h = domUtils.findParentByTagName(start, ['h1',
  16866. 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote',
  16867. 'caption', 'table'
  16868. ], true);
  16869. if(!h) {
  16870. me.document.execCommand('formatBlock', false,
  16871. '<p>');
  16872. doSave = 1;
  16873. }
  16874. } else {
  16875. // chrome remove div
  16876. if(start.nodeType == 1) {
  16877. var tmp = me.document.createTextNode(''),
  16878. div;
  16879. range.insertNode(tmp);
  16880. div = domUtils.findParentByTagName(tmp, 'div',
  16881. true);
  16882. if(div) {
  16883. var p = me.document.createElement('p');
  16884. while(div.firstChild) {
  16885. p.appendChild(div.firstChild);
  16886. }
  16887. div.parentNode.insertBefore(p, div);
  16888. domUtils.remove(div);
  16889. range.setStartBefore(tmp).setCursor();
  16890. doSave = 1;
  16891. }
  16892. domUtils.remove(tmp);
  16893. }
  16894. }
  16895. if(me.undoManger && doSave) {
  16896. me.undoManger.save();
  16897. }
  16898. }
  16899. // 没有站位符,会出现多行的问题
  16900. browser.opera && range.select();
  16901. } else {
  16902. me.fireEvent('saveScene', true, true)
  16903. }
  16904. }
  16905. });
  16906. me.addListener('keydown', function(type, evt) {
  16907. var keyCode = evt.keyCode || evt.which;
  16908. if(keyCode == 13) { // 回车
  16909. if(me.fireEvent('beforeenterkeydown')) {
  16910. domUtils.preventDefault(evt);
  16911. return;
  16912. }
  16913. me.fireEvent('saveScene', true, true);
  16914. hTag = '';
  16915. var range = me.selection.getRange();
  16916. if(!range.collapsed) {
  16917. // 跨td不能删
  16918. var start = range.startContainer,
  16919. end = range.endContainer,
  16920. startTd = domUtils
  16921. .findParentByTagName(start, 'td', true),
  16922. endTd = domUtils
  16923. .findParentByTagName(end, 'td', true);
  16924. if(startTd && endTd && startTd !== endTd || !startTd &&
  16925. endTd || startTd && !endTd) {
  16926. evt.preventDefault ?
  16927. evt.preventDefault() :
  16928. (evt.returnValue = false);
  16929. return;
  16930. }
  16931. }
  16932. if(tag == 'p') {
  16933. if(!browser.ie) {
  16934. start = domUtils.findParentByTagName(
  16935. range.startContainer, ['ol', 'ul', 'p', 'h1',
  16936. 'h2', 'h3', 'h4', 'h5', 'h6',
  16937. 'blockquote', 'caption'
  16938. ], true);
  16939. // opera下执行formatblock会在table的场景下有问题,回车在opera原生支持很好,所以暂时在opera去掉调用这个原生的command
  16940. // trace:2431
  16941. if(!start && !browser.opera) {
  16942. me.document
  16943. .execCommand('formatBlock', false, '<p>');
  16944. if(browser.gecko) {
  16945. range = me.selection.getRange();
  16946. start = domUtils.findParentByTagName(
  16947. range.startContainer, 'p', true);
  16948. start && domUtils.removeDirtyAttr(start);
  16949. }
  16950. } else {
  16951. hTag = start.tagName;
  16952. start.tagName.toLowerCase() == 'p' && browser.gecko &&
  16953. domUtils.removeDirtyAttr(start);
  16954. }
  16955. }
  16956. } else {
  16957. evt.preventDefault ?
  16958. evt.preventDefault() :
  16959. (evt.returnValue = false);
  16960. if(!range.collapsed) {
  16961. range.deleteContents();
  16962. start = range.startContainer;
  16963. if(start.nodeType == 1 &&
  16964. (start = start.childNodes[range.startOffset])) {
  16965. while(start.nodeType == 1) {
  16966. if(dtd.$empty[start.tagName]) {
  16967. range.setStartBefore(start).setCursor();
  16968. if(me.undoManger) {
  16969. me.undoManger.save();
  16970. }
  16971. return false;
  16972. }
  16973. if(!start.firstChild) {
  16974. var br = range.document.createElement('br');
  16975. start.appendChild(br);
  16976. range.setStart(start, 0).setCursor();
  16977. if(me.undoManger) {
  16978. me.undoManger.save();
  16979. }
  16980. return false;
  16981. }
  16982. start = start.firstChild;
  16983. }
  16984. if(start === range.startContainer.childNodes[range.startOffset]) {
  16985. br = range.document.createElement('br');
  16986. range.insertNode(br).setCursor();
  16987. } else {
  16988. range.setStart(start, 0).setCursor();
  16989. }
  16990. } else {
  16991. br = range.document.createElement('br');
  16992. range.insertNode(br).setStartAfter(br).setCursor();
  16993. }
  16994. } else {
  16995. br = range.document.createElement('br');
  16996. range.insertNode(br);
  16997. var parent = br.parentNode;
  16998. if(parent.lastChild === br) {
  16999. br.parentNode.insertBefore(br.cloneNode(true), br);
  17000. range.setStartBefore(br);
  17001. } else {
  17002. range.setStartAfter(br);
  17003. }
  17004. range.setCursor();
  17005. }
  17006. }
  17007. }
  17008. });
  17009. };
  17010. // plugins/keystrokes.js
  17011. /* 处理特殊键的兼容性问题 */
  17012. UE.plugins['keystrokes'] = function() {
  17013. var me = this;
  17014. var collapsed = true;
  17015. me.addListener('keydown', function(type, evt) {
  17016. var keyCode = evt.keyCode || evt.which,
  17017. rng = me.selection
  17018. .getRange();
  17019. // 处理全选的情况
  17020. if(!rng.collapsed &&
  17021. !(evt.ctrlKey || evt.shiftKey || evt.altKey || evt.metaKey) &&
  17022. (keyCode >= 65 && keyCode <= 90 || keyCode >= 48 &&
  17023. keyCode <= 57 || keyCode >= 96 && keyCode <= 111 || {
  17024. 13: 1,
  17025. 8: 1,
  17026. 46: 1
  17027. }[keyCode])) {
  17028. var tmpNode = rng.startContainer;
  17029. if(domUtils.isFillChar(tmpNode)) {
  17030. rng.setStartBefore(tmpNode)
  17031. }
  17032. tmpNode = rng.endContainer;
  17033. if(domUtils.isFillChar(tmpNode)) {
  17034. rng.setEndAfter(tmpNode)
  17035. }
  17036. rng.txtToElmBoundary();
  17037. // 结束边界可能放到了br的前边,要把br包含进来
  17038. // x[xxx]<br/>
  17039. if(rng.endContainer && rng.endContainer.nodeType == 1) {
  17040. tmpNode = rng.endContainer.childNodes[rng.endOffset];
  17041. if(tmpNode && domUtils.isBr(tmpNode)) {
  17042. rng.setEndAfter(tmpNode);
  17043. }
  17044. }
  17045. if(rng.startOffset == 0) {
  17046. tmpNode = rng.startContainer;
  17047. if(domUtils.isBoundaryNode(tmpNode, 'firstChild')) {
  17048. tmpNode = rng.endContainer;
  17049. if(rng.endOffset == (tmpNode.nodeType == 3 ?
  17050. tmpNode.nodeValue.length :
  17051. tmpNode.childNodes.length) &&
  17052. domUtils
  17053. .isBoundaryNode(tmpNode, 'lastChild')) {
  17054. me.fireEvent('saveScene');
  17055. me.body.innerHTML = '<p>' +
  17056. (browser.ie ? '' : '<br/>') + '</p>';
  17057. rng.setStart(me.body.firstChild, 0).setCursor(
  17058. false, true);
  17059. me._selectionChange();
  17060. return;
  17061. }
  17062. }
  17063. }
  17064. }
  17065. // 处理backspace
  17066. if(keyCode == keymap.Backspace) {
  17067. rng = me.selection.getRange();
  17068. collapsed = rng.collapsed;
  17069. if(me.fireEvent('delkeydown', evt)) {
  17070. return;
  17071. }
  17072. var start, end;
  17073. // 避免按两次删除才能生效的问题
  17074. if(rng.collapsed && rng.inFillChar()) {
  17075. start = rng.startContainer;
  17076. if(domUtils.isFillChar(start)) {
  17077. rng.setStartBefore(start).shrinkBoundary(true)
  17078. .collapse(true);
  17079. domUtils.remove(start)
  17080. } else {
  17081. start.nodeValue = start.nodeValue.replace(
  17082. new RegExp('^' + domUtils.fillChar), '');
  17083. rng.startOffset--;
  17084. rng.collapse(true).select(true)
  17085. }
  17086. }
  17087. // 解决选中control元素不能删除的问题
  17088. if(start = rng.getClosedNode()) {
  17089. me.fireEvent('saveScene');
  17090. rng.setStartBefore(start);
  17091. domUtils.remove(start);
  17092. rng.setCursor();
  17093. me.fireEvent('saveScene');
  17094. domUtils.preventDefault(evt);
  17095. return;
  17096. }
  17097. // 阻止在table上的删除
  17098. if(!browser.ie) {
  17099. start = domUtils.findParentByTagName(rng.startContainer,
  17100. 'table', true);
  17101. end = domUtils.findParentByTagName(rng.endContainer,
  17102. 'table', true);
  17103. if(start && !end || !start && end || start !== end) {
  17104. evt.preventDefault();
  17105. return;
  17106. }
  17107. }
  17108. }
  17109. // 处理tab键的逻辑
  17110. if(keyCode == keymap.Tab) {
  17111. // 不处理以下标签
  17112. var excludeTagNameForTabKey = {
  17113. 'ol': 1,
  17114. 'ul': 1,
  17115. 'table': 1
  17116. };
  17117. // 处理组件里的tab按下事件
  17118. if(me.fireEvent('tabkeydown', evt)) {
  17119. domUtils.preventDefault(evt);
  17120. return;
  17121. }
  17122. var range = me.selection.getRange();
  17123. me.fireEvent('saveScene');
  17124. for(var i = 0, txt = '', tabSize = me.options.tabSize || 4, tabNode = me.options.tabNode ||
  17125. '&nbsp;'; i < tabSize; i++) {
  17126. txt += tabNode;
  17127. }
  17128. var span = me.document.createElement('span');
  17129. span.innerHTML = txt + domUtils.fillChar;
  17130. if(range.collapsed) {
  17131. range.insertNode(span.cloneNode(true).firstChild)
  17132. .setCursor(true);
  17133. } else {
  17134. var filterFn = function(node) {
  17135. return domUtils.isBlockElm(node) &&
  17136. !excludeTagNameForTabKey[node.tagName
  17137. .toLowerCase()]
  17138. };
  17139. // 普通的情况
  17140. start = domUtils.findParent(range.startContainer, filterFn,
  17141. true);
  17142. end = domUtils.findParent(range.endContainer, filterFn,
  17143. true);
  17144. if(start && end && start === end) {
  17145. range.deleteContents();
  17146. range.insertNode(span.cloneNode(true).firstChild)
  17147. .setCursor(true);
  17148. } else {
  17149. var bookmark = range.createBookmark();
  17150. range.enlarge(true);
  17151. var bookmark2 = range.createBookmark(),
  17152. current = domUtils
  17153. .getNextDomNode(bookmark2.start, false,
  17154. filterFn);
  17155. while(current &&
  17156. !(domUtils.getPosition(current,
  17157. bookmark2.end) & domUtils.POSITION_FOLLOWING)) {
  17158. current.insertBefore(
  17159. span.cloneNode(true).firstChild,
  17160. current.firstChild);
  17161. current = domUtils.getNextDomNode(current, false,
  17162. filterFn);
  17163. }
  17164. range.moveToBookmark(bookmark2)
  17165. .moveToBookmark(bookmark).select();
  17166. }
  17167. }
  17168. domUtils.preventDefault(evt)
  17169. }
  17170. // trace:1634
  17171. // ff的del键在容器空的时候,也会删除
  17172. if(browser.gecko && keyCode == 46) {
  17173. range = me.selection.getRange();
  17174. if(range.collapsed) {
  17175. start = range.startContainer;
  17176. if(domUtils.isEmptyBlock(start)) {
  17177. var parent = start.parentNode;
  17178. while(domUtils.getChildCount(parent) == 1 &&
  17179. !domUtils.isBody(parent)) {
  17180. start = parent;
  17181. parent = parent.parentNode;
  17182. }
  17183. if(start === parent.lastChild)
  17184. evt.preventDefault();
  17185. return;
  17186. }
  17187. }
  17188. }
  17189. });
  17190. me.addListener('keyup', function(type, evt) {
  17191. var keyCode = evt.keyCode || evt.which,
  17192. rng, me = this;
  17193. if(keyCode == keymap.Backspace) {
  17194. if(me.fireEvent('delkeyup')) {
  17195. return;
  17196. }
  17197. rng = me.selection.getRange();
  17198. if(rng.collapsed) {
  17199. var tmpNode, autoClearTagName = ['h1', 'h2', 'h3', 'h4',
  17200. 'h5', 'h6'
  17201. ];
  17202. if(tmpNode = domUtils.findParentByTagName(
  17203. rng.startContainer, autoClearTagName, true)) {
  17204. if(domUtils.isEmptyBlock(tmpNode)) {
  17205. var pre = tmpNode.previousSibling;
  17206. if(pre && pre.nodeName != 'TABLE') {
  17207. domUtils.remove(tmpNode);
  17208. rng.setStartAtLast(pre).setCursor(false, true);
  17209. return;
  17210. } else {
  17211. var next = tmpNode.nextSibling;
  17212. if(next && next.nodeName != 'TABLE') {
  17213. domUtils.remove(tmpNode);
  17214. rng.setStartAtFirst(next).setCursor(false,
  17215. true);
  17216. return;
  17217. }
  17218. }
  17219. }
  17220. }
  17221. // 处理当删除到body时,要重新给p标签展位
  17222. if(domUtils.isBody(rng.startContainer)) {
  17223. var tmpNode = domUtils.createElement(me.document, 'p', {
  17224. 'innerHTML': browser.ie ?
  17225. domUtils.fillChar : '<br/>'
  17226. });
  17227. rng.insertNode(tmpNode).setStart(tmpNode, 0).setCursor(
  17228. false, true);
  17229. }
  17230. }
  17231. // chrome下如果删除了inline标签,浏览器会有记忆,在输入文字还是会套上刚才删除的标签,所以这里再选一次就不会了
  17232. if(!collapsed &&
  17233. (rng.startContainer.nodeType == 3 || rng.startContainer.nodeType == 1 &&
  17234. domUtils.isEmptyBlock(rng.startContainer))) {
  17235. if(browser.ie) {
  17236. var span = rng.document.createElement('span');
  17237. rng.insertNode(span).setStartBefore(span)
  17238. .collapse(true);
  17239. rng.select();
  17240. domUtils.remove(span)
  17241. } else {
  17242. rng.select()
  17243. }
  17244. }
  17245. }
  17246. })
  17247. };
  17248. // plugins/fiximgclick.js
  17249. // /import core
  17250. // /commands 修复chrome下图片不能点击的问题,出现八个角可改变大小
  17251. // /commandsName FixImgClick
  17252. // /commandsTitle 修复chrome下图片不能点击的问题,出现八个角可改变大小
  17253. // 修复chrome下图片不能点击的问题,出现八个角可改变大小
  17254. UE.plugins['fiximgclick'] = (function() {
  17255. var elementUpdated = false;
  17256. function Scale() {
  17257. this.editor = null;
  17258. this.resizer = null;
  17259. this.cover = null;
  17260. this.doc = document;
  17261. this.prePos = {
  17262. x: 0,
  17263. y: 0
  17264. };
  17265. this.startPos = {
  17266. x: 0,
  17267. y: 0
  17268. };
  17269. }
  17270. (function() {
  17271. var rect = [
  17272. // [left, top, width, height]
  17273. [0, 0, -1, -1],
  17274. [0, 0, 0, -1],
  17275. [0, 0, 1, -1],
  17276. [0, 0, -1, 0],
  17277. [0, 0, 1, 0],
  17278. [0, 0, -1, 1],
  17279. [0, 0, 0, 1],
  17280. [0, 0, 1, 1]
  17281. ];
  17282. Scale.prototype = {
  17283. init: function(editor) {
  17284. var me = this;
  17285. me.editor = editor;
  17286. me.startPos = this.prePos = {
  17287. x: 0,
  17288. y: 0
  17289. };
  17290. me.dragId = -1;
  17291. var hands = [],
  17292. cover = me.cover = document
  17293. .createElement('div'),
  17294. resizer = me.resizer = document
  17295. .createElement('div');
  17296. cover.id = me.editor.ui.id + '_imagescale_cover';
  17297. cover.style.cssText = 'position:absolute;display:none;z-index:' +
  17298. (me.editor.options.zIndex) +
  17299. ';filter:alpha(opacity=0); opacity:0;background:#CCC;';
  17300. domUtils.on(cover, 'mousedown click', function() {
  17301. me.hide();
  17302. });
  17303. for(i = 0; i < 8; i++) {
  17304. hands.push('<span class="edui-editor-imagescale-hand' +
  17305. i + '"></span>');
  17306. }
  17307. resizer.id = me.editor.ui.id + '_imagescale';
  17308. resizer.className = 'edui-editor-imagescale';
  17309. resizer.innerHTML = hands.join('');
  17310. resizer.style.cssText += ';display:none;border:1px solid #3b77ff;z-index:' +
  17311. (me.editor.options.zIndex) + ';';
  17312. me.editor.ui.getDom().appendChild(cover);
  17313. me.editor.ui.getDom().appendChild(resizer);
  17314. me.initStyle();
  17315. me.initEvents();
  17316. },
  17317. initStyle: function() {
  17318. utils
  17319. .cssRule(
  17320. 'imagescale',
  17321. '.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;}' +
  17322. '.edui-editor-imagescale span{position:absolute;width:6px;height:6px;overflow:hidden;font-size:0px;display:block;background-color:#3C9DD0;}' +
  17323. '.edui-editor-imagescale .edui-editor-imagescale-hand0{cursor:nw-resize;top:0;margin-top:-4px;left:0;margin-left:-4px;}' +
  17324. '.edui-editor-imagescale .edui-editor-imagescale-hand1{cursor:n-resize;top:0;margin-top:-4px;left:50%;margin-left:-4px;}' +
  17325. '.edui-editor-imagescale .edui-editor-imagescale-hand2{cursor:ne-resize;top:0;margin-top:-4px;left:100%;margin-left:-3px;}' +
  17326. '.edui-editor-imagescale .edui-editor-imagescale-hand3{cursor:w-resize;top:50%;margin-top:-4px;left:0;margin-left:-4px;}' +
  17327. '.edui-editor-imagescale .edui-editor-imagescale-hand4{cursor:e-resize;top:50%;margin-top:-4px;left:100%;margin-left:-3px;}' +
  17328. '.edui-editor-imagescale .edui-editor-imagescale-hand5{cursor:sw-resize;top:100%;margin-top:-3px;left:0;margin-left:-4px;}' +
  17329. '.edui-editor-imagescale .edui-editor-imagescale-hand6{cursor:s-resize;top:100%;margin-top:-3px;left:50%;margin-left:-4px;}' +
  17330. '.edui-editor-imagescale .edui-editor-imagescale-hand7{cursor:se-resize;top:100%;margin-top:-3px;left:100%;margin-left:-3px;}');
  17331. },
  17332. initEvents: function() {
  17333. var me = this;
  17334. me.startPos.x = me.startPos.y = 0;
  17335. me.isDraging = false;
  17336. },
  17337. _eventHandler: function(e) {
  17338. var me = this;
  17339. switch(e.type) {
  17340. case 'mousedown':
  17341. var hand = e.target || e.srcElement,
  17342. hand;
  17343. if(hand.className
  17344. .indexOf('edui-editor-imagescale-hand') != -1 &&
  17345. me.dragId == -1) {
  17346. me.dragId = hand.className.slice(-1);
  17347. me.startPos.x = me.prePos.x = e.clientX;
  17348. me.startPos.y = me.prePos.y = e.clientY;
  17349. domUtils.on(me.doc, 'mousemove', me.proxy(
  17350. me._eventHandler, me));
  17351. }
  17352. break;
  17353. case 'mousemove':
  17354. if(me.dragId != -1) {
  17355. me.updateContainerStyle(me.dragId, {
  17356. x: e.clientX - me.prePos.x,
  17357. y: e.clientY - me.prePos.y
  17358. });
  17359. me.prePos.x = e.clientX;
  17360. me.prePos.y = e.clientY;
  17361. elementUpdated = true;
  17362. me.updateTargetElement();
  17363. }
  17364. break;
  17365. case 'mouseup':
  17366. if(me.dragId != -1) {
  17367. me.updateContainerStyle(me.dragId, {
  17368. x: e.clientX - me.prePos.x,
  17369. y: e.clientY - me.prePos.y
  17370. });
  17371. me.updateTargetElement();
  17372. if(me.target.parentNode)
  17373. me.attachTo(me.target);
  17374. me.dragId = -1;
  17375. }
  17376. domUtils.un(me.doc, 'mousemove', me.proxy(
  17377. me._eventHandler, me));
  17378. // 修复只是点击挪动点,但没有改变大小,不应该触发contentchange
  17379. if(elementUpdated) {
  17380. elementUpdated = false;
  17381. me.editor.fireEvent('contentchange');
  17382. }
  17383. break;
  17384. default:
  17385. break;
  17386. }
  17387. },
  17388. updateTargetElement: function() {
  17389. var me = this;
  17390. domUtils.setStyles(me.target, {
  17391. 'width': me.resizer.style.width,
  17392. 'height': me.resizer.style.height
  17393. });
  17394. me.target.width = parseInt(me.resizer.style.width);
  17395. me.target.height = parseInt(me.resizer.style.height);
  17396. me.attachTo(me.target);
  17397. },
  17398. updateContainerStyle: function(dir, offset) {
  17399. var me = this,
  17400. dom = me.resizer,
  17401. tmp;
  17402. if(rect[dir][0] != 0) {
  17403. tmp = parseInt(dom.style.left) + offset.x;
  17404. dom.style.left = me._validScaledProp('left', tmp) +
  17405. 'px';
  17406. }
  17407. if(rect[dir][1] != 0) {
  17408. tmp = parseInt(dom.style.top) + offset.y;
  17409. dom.style.top = me._validScaledProp('top', tmp) + 'px';
  17410. }
  17411. if(rect[dir][2] != 0) {
  17412. tmp = dom.clientWidth + rect[dir][2] * offset.x;
  17413. dom.style.width = me._validScaledProp('width', tmp) +
  17414. 'px';
  17415. }
  17416. if(rect[dir][3] != 0) {
  17417. tmp = dom.clientHeight + rect[dir][3] * offset.y;
  17418. dom.style.height = me._validScaledProp('height', tmp) +
  17419. 'px';
  17420. }
  17421. },
  17422. _validScaledProp: function(prop, value) {
  17423. var ele = this.resizer,
  17424. wrap = document;
  17425. value = isNaN(value) ? 0 : value;
  17426. switch(prop) {
  17427. case 'left':
  17428. return value < 0 ?
  17429. 0 :
  17430. (value + ele.clientWidth) > wrap.clientWidth ?
  17431. wrap.clientWidth -
  17432. ele.clientWidth :
  17433. value;
  17434. case 'top':
  17435. return value < 0 ?
  17436. 0 :
  17437. (value + ele.clientHeight) > wrap.clientHeight ?
  17438. wrap.clientHeight -
  17439. ele.clientHeight :
  17440. value;
  17441. case 'width':
  17442. return value <= 0 ?
  17443. 1 :
  17444. (value + ele.offsetLeft) > wrap.clientWidth ?
  17445. wrap.clientWidth - ele.offsetLeft :
  17446. value;
  17447. case 'height':
  17448. return value <= 0 ?
  17449. 1 :
  17450. (value + ele.offsetTop) > wrap.clientHeight ?
  17451. wrap.clientHeight - ele.offsetTop :
  17452. value;
  17453. }
  17454. },
  17455. hideCover: function() {
  17456. this.cover.style.display = 'none';
  17457. },
  17458. showCover: function() {
  17459. var me = this,
  17460. editorPos = domUtils.getXY(me.editor.ui
  17461. .getDom()),
  17462. iframePos = domUtils
  17463. .getXY(me.editor.iframe);
  17464. domUtils.setStyles(me.cover, {
  17465. 'width': me.editor.iframe.offsetWidth + 'px',
  17466. 'height': me.editor.iframe.offsetHeight + 'px',
  17467. 'top': iframePos.y - editorPos.y + 'px',
  17468. 'left': iframePos.x - editorPos.x + 'px',
  17469. 'position': 'absolute',
  17470. 'display': ''
  17471. })
  17472. },
  17473. show: function(targetObj) {
  17474. var me = this;
  17475. me.resizer.style.display = 'block';
  17476. if(targetObj)
  17477. me.attachTo(targetObj);
  17478. domUtils.on(this.resizer, 'mousedown', me.proxy(
  17479. me._eventHandler, me));
  17480. domUtils.on(me.doc, 'mouseup', me.proxy(me._eventHandler,
  17481. me));
  17482. me.showCover();
  17483. me.editor.fireEvent('afterscaleshow', me);
  17484. me.editor.fireEvent('saveScene');
  17485. },
  17486. hide: function() {
  17487. var me = this;
  17488. me.hideCover();
  17489. me.resizer.style.display = 'none';
  17490. domUtils.un(me.resizer, 'mousedown', me.proxy(
  17491. me._eventHandler, me));
  17492. domUtils.un(me.doc, 'mouseup', me.proxy(me._eventHandler,
  17493. me));
  17494. me.editor.fireEvent('afterscalehide', me);
  17495. },
  17496. proxy: function(fn, context) {
  17497. return function(e) {
  17498. return fn.apply(context || this, arguments);
  17499. };
  17500. },
  17501. attachTo: function(targetObj) {
  17502. var me = this,
  17503. target = me.target = targetObj,
  17504. resizer = this.resizer,
  17505. imgPos = domUtils
  17506. .getXY(target),
  17507. iframePos = domUtils
  17508. .getXY(me.editor.iframe),
  17509. editorPos = domUtils
  17510. .getXY(resizer.parentNode);
  17511. domUtils.setStyles(resizer, {
  17512. 'width': target.width + 'px',
  17513. 'height': target.height + 'px',
  17514. 'left': iframePos.x + imgPos.x -
  17515. me.editor.document.body.scrollLeft -
  17516. editorPos.x -
  17517. parseInt(resizer.style.borderLeftWidth) +
  17518. 'px',
  17519. 'top': iframePos.y + imgPos.y -
  17520. // me.editor.document.body.scrollTop -
  17521. (me.editor.document.documentElement.scrollTop || me.editor.document.body.scrollTop || 0) -
  17522. editorPos.y -
  17523. parseInt(resizer.style.borderTopWidth) + 'px'
  17524. });
  17525. }
  17526. }
  17527. })();
  17528. return function() {
  17529. var me = this,
  17530. imageScale;
  17531. me.setOpt('imageScaleEnabled', true);
  17532. if(!browser.ie && me.options.imageScaleEnabled) {
  17533. me.addListener('click', function(type, e) {
  17534. var range = me.selection.getRange(),
  17535. img = range
  17536. .getClosedNode();
  17537. console.log(img)
  17538. if(img && img.tagName == 'IMG' &&
  17539. me.body.contentEditable != "false") {
  17540. // if(img && img.tagName == 'EMBED' &&
  17541. // me.body.contentEditable != "false") {
  17542. if(img.className.indexOf("edui-faked-music") != -1 ||
  17543. img.getAttribute("anchorname") ||
  17544. domUtils.hasClass(img, 'loadingclass') ||
  17545. domUtils.hasClass(img, 'loaderrorclass')) {
  17546. return
  17547. }
  17548. if(!imageScale) {
  17549. imageScale = new Scale();
  17550. imageScale.init(me);
  17551. me.ui.getDom().appendChild(imageScale.resizer);
  17552. var _keyDownHandler = function(e) {
  17553. imageScale.hide();
  17554. if(imageScale.target)
  17555. me.selection.getRange()
  17556. .selectNode(imageScale.target)
  17557. .select();
  17558. },
  17559. _mouseDownHandler = function(e) {
  17560. var ele = e.target || e.srcElement;
  17561. if(ele &&
  17562. (ele.className === undefined || ele.className
  17563. .indexOf('edui-editor-imagescale') == -1)) {
  17564. _keyDownHandler(e);
  17565. }
  17566. },
  17567. timer;
  17568. me.addListener('afterscaleshow', function(e) {
  17569. me
  17570. .addListener('beforekeydown',
  17571. _keyDownHandler);
  17572. me.addListener('beforemousedown',
  17573. _mouseDownHandler);
  17574. domUtils.on(document, 'keydown',
  17575. _keyDownHandler);
  17576. domUtils.on(document, 'mousedown',
  17577. _mouseDownHandler);
  17578. me.selection.getNative().removeAllRanges();
  17579. });
  17580. me.addListener('afterscalehide', function(e) {
  17581. me.removeListener('beforekeydown',
  17582. _keyDownHandler);
  17583. me.removeListener('beforemousedown',
  17584. _mouseDownHandler);
  17585. domUtils.un(document, 'keydown',
  17586. _keyDownHandler);
  17587. domUtils.un(document, 'mousedown',
  17588. _mouseDownHandler);
  17589. var target = imageScale.target;
  17590. if(target.parentNode) {
  17591. me.selection.getRange().selectNode(target)
  17592. .select();
  17593. }
  17594. });
  17595. // TODO 有iframe的情况,mousedown不能往下传。。
  17596. domUtils.on(imageScale.resizer, 'mousedown',
  17597. function(e) {
  17598. me.selection.getNative()
  17599. .removeAllRanges();
  17600. var ele = e.target || e.srcElement;
  17601. if(ele &&
  17602. ele.className
  17603. .indexOf('edui-editor-imagescale-hand') == -1) {
  17604. timer = setTimeout(function() {
  17605. imageScale.hide();
  17606. if(imageScale.target)
  17607. me.selection.getRange()
  17608. .selectNode(ele)
  17609. .select();
  17610. }, 200);
  17611. }
  17612. });
  17613. domUtils.on(imageScale.resizer, 'mouseup',
  17614. function(e) {
  17615. var ele = e.target || e.srcElement;
  17616. if(ele &&
  17617. ele.className
  17618. .indexOf('edui-editor-imagescale-hand') == -1) {
  17619. clearTimeout(timer);
  17620. }
  17621. });
  17622. }
  17623. //2019-11-05 cj 设置了输
  17624. if(!this.options.imgHeight){
  17625. imageScale.show(img);
  17626. }
  17627. } else {
  17628. if(imageScale &&
  17629. imageScale.resizer.style.display != 'none')
  17630. imageScale.hide();
  17631. }
  17632. });
  17633. }
  17634. if(browser.webkit) {
  17635. me.addListener('click', function(type, e) {
  17636. if(e.target.tagName == 'IMG' &&
  17637. me.body.contentEditable != "false") {
  17638. // if(e.target.tagName == 'EMBED' &&
  17639. // me.body.contentEditable != "false") {
  17640. var range = new dom.Range(me.document);
  17641. range.selectNode(e.target).select();
  17642. }
  17643. });
  17644. }
  17645. }
  17646. })();
  17647. // plugins/autolink.js
  17648. // /import core
  17649. // /commands 为非ie浏览器自动添加a标签
  17650. // /commandsName AutoLink
  17651. // /commandsTitle 自动增加链接
  17652. /**
  17653. * @description 为非ie浏览器自动添加a标签
  17654. * @author zhanyi
  17655. */
  17656. UE.plugin.register('autolink', function() {
  17657. var cont = 0;
  17658. return !browser.ie ? {
  17659. bindEvents: {
  17660. 'reset': function() {
  17661. cont = 0;
  17662. },
  17663. 'keydown': function(type, evt) {
  17664. var me = this;
  17665. var keyCode = evt.keyCode || evt.which;
  17666. if(keyCode == 32 || keyCode == 13) {
  17667. var sel = me.selection.getNative(),
  17668. range = sel
  17669. .getRangeAt(0).cloneRange(),
  17670. offset, charCode;
  17671. var start = range.startContainer;
  17672. while(start.nodeType == 1 && range.startOffset > 0) {
  17673. start = range.startContainer.childNodes[range.startOffset -
  17674. 1];
  17675. if(!start) {
  17676. break;
  17677. }
  17678. range.setStart(start, start.nodeType == 1 ?
  17679. start.childNodes.length :
  17680. start.nodeValue.length);
  17681. range.collapse(true);
  17682. start = range.startContainer;
  17683. }
  17684. do {
  17685. if(range.startOffset == 0) {
  17686. start = range.startContainer.previousSibling;
  17687. while(start && start.nodeType == 1) {
  17688. start = start.lastChild;
  17689. }
  17690. if(!start || domUtils.isFillChar(start)) {
  17691. break;
  17692. }
  17693. offset = start.nodeValue.length;
  17694. } else {
  17695. start = range.startContainer;
  17696. offset = range.startOffset;
  17697. }
  17698. range.setStart(start, offset - 1);
  17699. charCode = range.toString().charCodeAt(0);
  17700. } while (charCode != 160 && charCode != 32);
  17701. if(range
  17702. .toString()
  17703. .replace(new RegExp(domUtils.fillChar, 'g'), '')
  17704. .match(/(?:https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.)/i)) {
  17705. while(range.toString().length) {
  17706. if(/^(?:https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.)/i
  17707. .test(range.toString())) {
  17708. break;
  17709. }
  17710. try {
  17711. range.setStart(range.startContainer,
  17712. range.startOffset + 1);
  17713. } catch(e) {
  17714. // trace:2121
  17715. var start = range.startContainer;
  17716. while(!(next = start.nextSibling)) {
  17717. if(domUtils.isBody(start)) {
  17718. return;
  17719. }
  17720. start = start.parentNode;
  17721. }
  17722. range.setStart(next, 0);
  17723. }
  17724. }
  17725. // range的开始边界已经在a标签里的不再处理
  17726. if(domUtils.findParentByTagName(
  17727. range.startContainer, 'a', true)) {
  17728. return;
  17729. }
  17730. var a = me.document.createElement('a'),
  17731. text = me.document
  17732. .createTextNode(' '),
  17733. href;
  17734. me.undoManger && me.undoManger.save();
  17735. a.appendChild(range.extractContents());
  17736. a.href = a.innerHTML = a.innerHTML.replace(
  17737. /<[^>]+>/g, '');
  17738. href = a.getAttribute("href").replace(
  17739. new RegExp(domUtils.fillChar, 'g'), '');
  17740. href = /^(?:https?:\/\/)/ig.test(href) ?
  17741. href :
  17742. "http://" + href;
  17743. a.setAttribute('_src', utils.html(href));
  17744. a.href = utils.html(href);
  17745. range.insertNode(a);
  17746. a.parentNode.insertBefore(text, a.nextSibling);
  17747. range.setStart(text, 0);
  17748. range.collapse(true);
  17749. sel.removeAllRanges();
  17750. sel.addRange(range);
  17751. me.undoManger && me.undoManger.save();
  17752. }
  17753. }
  17754. }
  17755. }
  17756. } : {}
  17757. }, function() {
  17758. var keyCodes = {
  17759. 37: 1,
  17760. 38: 1,
  17761. 39: 1,
  17762. 40: 1,
  17763. 13: 1,
  17764. 32: 1
  17765. };
  17766. function checkIsCludeLink(node) {
  17767. if(node.nodeType == 3) {
  17768. return null
  17769. }
  17770. if(node.nodeName == 'A') {
  17771. return node;
  17772. }
  17773. var lastChild = node.lastChild;
  17774. while(lastChild) {
  17775. if(lastChild.nodeName == 'A') {
  17776. return lastChild;
  17777. }
  17778. if(lastChild.nodeType == 3) {
  17779. if(domUtils.isWhitespace(lastChild)) {
  17780. lastChild = lastChild.previousSibling;
  17781. continue;
  17782. }
  17783. return null
  17784. }
  17785. lastChild = lastChild.lastChild;
  17786. }
  17787. }
  17788. browser.ie && this.addListener('keyup', function(cmd, evt) {
  17789. var me = this,
  17790. keyCode = evt.keyCode;
  17791. if(keyCodes[keyCode]) {
  17792. var rng = me.selection.getRange();
  17793. var start = rng.startContainer;
  17794. if(keyCode == 13) {
  17795. while(start && !domUtils.isBody(start) &&
  17796. !domUtils.isBlockElm(start)) {
  17797. start = start.parentNode;
  17798. }
  17799. if(start && !domUtils.isBody(start) &&
  17800. start.nodeName == 'P') {
  17801. var pre = start.previousSibling;
  17802. if(pre && pre.nodeType == 1) {
  17803. var pre = checkIsCludeLink(pre);
  17804. if(pre && !pre.getAttribute('_href')) {
  17805. domUtils.remove(pre, true);
  17806. }
  17807. }
  17808. }
  17809. } else if(keyCode == 32) {
  17810. if(start.nodeType == 3 && /^\s$/.test(start.nodeValue)) {
  17811. start = start.previousSibling;
  17812. if(start && start.nodeName == 'A' &&
  17813. !start.getAttribute('_href')) {
  17814. domUtils.remove(start, true);
  17815. }
  17816. }
  17817. } else {
  17818. start = domUtils.findParentByTagName(start, 'a', true);
  17819. if(start && !start.getAttribute('_href')) {
  17820. var bk = rng.createBookmark();
  17821. domUtils.remove(start, true);
  17822. rng.moveToBookmark(bk).select(true)
  17823. }
  17824. }
  17825. }
  17826. });
  17827. });
  17828. // plugins/autoheight.js
  17829. // /import core
  17830. // /commands 当输入内容超过编辑器高度时,编辑器自动增高
  17831. // /commandsName AutoHeight,autoHeightEnabled
  17832. // /commandsTitle 自动增高
  17833. /**
  17834. * @description 自动伸展
  17835. * @author zhanyi
  17836. */
  17837. UE.plugins['autoheight'] = function() {
  17838. var me = this;
  17839. // 提供开关,就算加载也可以关闭
  17840. me.autoHeightEnabled = me.options.autoHeightEnabled !== false;
  17841. if(!me.autoHeightEnabled) {
  17842. return;
  17843. }
  17844. var bakOverflow, lastHeight = 0,
  17845. options = me.options,
  17846. currentHeight, timer;
  17847. function adjustHeight() {
  17848. var me = this;
  17849. clearTimeout(timer);
  17850. if(isFullscreen)
  17851. return;
  17852. if(!me.queryCommandState || me.queryCommandState &&
  17853. me.queryCommandState('source') != 1) {
  17854. timer = setTimeout(function() {
  17855. var node = me.body.lastChild;
  17856. while(node && node.nodeType != 1) {
  17857. node = node.previousSibling;
  17858. }
  17859. if(node && node.nodeType == 1) {
  17860. node.style.clear = 'both';
  17861. currentHeight = Math.max(domUtils.getXY(node).y +
  17862. node.offsetHeight + 25, Math.max(
  17863. options.minFrameHeight,
  17864. options.initialFrameHeight));
  17865. if(currentHeight != lastHeight) {
  17866. if(currentHeight !== parseInt(me.iframe.parentNode.style.height)) {
  17867. me.iframe.parentNode.style.height = currentHeight +
  17868. 'px';
  17869. }
  17870. me.body.style.height = currentHeight + 'px';
  17871. lastHeight = currentHeight;
  17872. }
  17873. domUtils.removeStyle(node, 'clear');
  17874. }
  17875. }, 50)
  17876. }
  17877. }
  17878. var isFullscreen;
  17879. me.addListener('fullscreenchanged', function(cmd, f) {
  17880. isFullscreen = f
  17881. });
  17882. me.addListener('destroy', function() {
  17883. me.removeListener('contentchange afterinserthtml keyup mouseup',
  17884. adjustHeight)
  17885. });
  17886. me.enableAutoHeight = function() {
  17887. var me = this;
  17888. if(!me.autoHeightEnabled) {
  17889. return;
  17890. }
  17891. var doc = me.document;
  17892. me.autoHeightEnabled = true;
  17893. bakOverflow = doc.body.style.overflowY;
  17894. doc.body.style.overflowY = 'hidden';
  17895. me.addListener('contentchange afterinserthtml keyup mouseup',
  17896. adjustHeight);
  17897. // ff不给事件算得不对
  17898. setTimeout(function() {
  17899. adjustHeight.call(me);
  17900. }, browser.gecko ? 100 : 0);
  17901. me.fireEvent('autoheightchanged', me.autoHeightEnabled);
  17902. };
  17903. me.disableAutoHeight = function() {
  17904. me.body.style.overflowY = bakOverflow || '';
  17905. me.removeListener('contentchange', adjustHeight);
  17906. me.removeListener('keyup', adjustHeight);
  17907. me.removeListener('mouseup', adjustHeight);
  17908. me.autoHeightEnabled = false;
  17909. me.fireEvent('autoheightchanged', me.autoHeightEnabled);
  17910. };
  17911. me.on('setHeight', function() {
  17912. me.disableAutoHeight()
  17913. });
  17914. me.addListener('ready', function() {
  17915. me.enableAutoHeight();
  17916. // trace:1764
  17917. var timer;
  17918. domUtils.on(browser.ie ? me.body : me.document, browser.webkit ?
  17919. 'dragover' :
  17920. 'drop',
  17921. function() {
  17922. clearTimeout(timer);
  17923. timer = setTimeout(function() {
  17924. // trace:3681
  17925. adjustHeight.call(me);
  17926. }, 100);
  17927. });
  17928. // 修复内容过多时,回到顶部,顶部内容被工具栏遮挡问题
  17929. var lastScrollY;
  17930. window.onscroll = function() {
  17931. if(lastScrollY === null) {
  17932. lastScrollY = this.scrollY
  17933. } else if(this.scrollY == 0 && lastScrollY != 0) {
  17934. me.window.scrollTo(0, 0);
  17935. lastScrollY = null;
  17936. }
  17937. }
  17938. });
  17939. };
  17940. // plugins/autofloat.js
  17941. // /import core
  17942. // /commands 悬浮工具栏
  17943. // /commandsName AutoFloat,autoFloatEnabled
  17944. // /commandsTitle 悬浮工具栏
  17945. /**
  17946. * modified by chengchao01 注意: 引入此功能后,在IE6下会将body的背景图片覆盖掉!
  17947. */
  17948. UE.plugins['autofloat'] = function() {
  17949. var me = this,
  17950. lang = me.getLang();
  17951. me.setOpt({
  17952. topOffset: 0
  17953. });
  17954. var optsAutoFloatEnabled = me.options.autoFloatEnabled !== false,
  17955. topOffset = me.options.topOffset;
  17956. // 如果不固定toolbar的位置,则直接退出
  17957. if(!optsAutoFloatEnabled) {
  17958. return;
  17959. }
  17960. var uiUtils = UE.ui.uiUtils,
  17961. LteIE6 = browser.ie &&
  17962. browser.version <= 6,
  17963. quirks = browser.quirks;
  17964. function checkHasUI() {
  17965. if(!UE.ui) {
  17966. alert(lang.autofloatMsg);
  17967. return 0;
  17968. }
  17969. return 1;
  17970. }
  17971. function fixIE6FixedPos() {
  17972. var docStyle = document.body.style;
  17973. docStyle.backgroundImage = 'url("about:blank")';
  17974. docStyle.backgroundAttachment = 'fixed';
  17975. }
  17976. var bakCssText, placeHolder = document.createElement('div'),
  17977. toolbarBox, orgTop, getPosition, flag = true; // ie7模式下需要偏移
  17978. function setFloating() {
  17979. var toobarBoxPos = domUtils.getXY(toolbarBox),
  17980. origalFloat = domUtils
  17981. .getComputedStyle(toolbarBox, 'position'),
  17982. origalLeft = domUtils
  17983. .getComputedStyle(toolbarBox, 'left');
  17984. toolbarBox.style.width = toolbarBox.offsetWidth + 'px';
  17985. toolbarBox.style.zIndex = me.options.zIndex * 1 + 1;
  17986. toolbarBox.parentNode.insertBefore(placeHolder, toolbarBox);
  17987. if(LteIE6 || (quirks && browser.ie)) {
  17988. if(toolbarBox.style.position != 'absolute') {
  17989. toolbarBox.style.position = 'absolute';
  17990. }
  17991. toolbarBox.style.top = (document.body.scrollTop || document.documentElement.scrollTop) -
  17992. orgTop + topOffset + 'px';
  17993. } else {
  17994. if(browser.ie7Compat && flag) {
  17995. flag = false;
  17996. toolbarBox.style.left = domUtils.getXY(toolbarBox).x -
  17997. document.documentElement.getBoundingClientRect().left +
  17998. 2 + 'px';
  17999. }
  18000. if(toolbarBox.style.position != 'fixed') {
  18001. toolbarBox.style.position = 'fixed';
  18002. toolbarBox.style.top = topOffset + "px";
  18003. ((origalFloat == 'absolute' || origalFloat == 'relative') && parseFloat(origalLeft)) &&
  18004. (toolbarBox.style.left = toobarBoxPos.x + 'px');
  18005. }
  18006. }
  18007. }
  18008. function unsetFloating() {
  18009. flag = true;
  18010. if(placeHolder.parentNode) {
  18011. placeHolder.parentNode.removeChild(placeHolder);
  18012. }
  18013. toolbarBox.style.cssText = bakCssText;
  18014. }
  18015. function updateFloating() {
  18016. var rect3 = getPosition(me.container);
  18017. var offset = me.options.toolbarTopOffset || 0;
  18018. if(rect3.top < 0 &&
  18019. rect3.bottom - toolbarBox.offsetHeight > offset) {
  18020. setFloating();
  18021. } else {
  18022. unsetFloating();
  18023. }
  18024. }
  18025. var defer_updateFloating = utils.defer(function() {
  18026. updateFloating();
  18027. }, browser.ie ? 200 : 100, true);
  18028. me.addListener('destroy', function() {
  18029. domUtils.un(window, ['scroll', 'resize'], updateFloating);
  18030. me.removeListener('keydown', defer_updateFloating);
  18031. });
  18032. me.addListener('ready', function() {
  18033. if(checkHasUI(me)) {
  18034. // 加载了ui组件,但在new时,没有加载ui,导致编辑器实例上没有ui类,所以这里做判断
  18035. if(!me.ui) {
  18036. return;
  18037. }
  18038. getPosition = uiUtils.getClientRect;
  18039. toolbarBox = me.ui.getDom('toolbarbox');
  18040. orgTop = getPosition(toolbarBox).top;
  18041. bakCssText = toolbarBox.style.cssText;
  18042. placeHolder.style.height = toolbarBox.offsetHeight + 'px';
  18043. if(LteIE6) {
  18044. fixIE6FixedPos();
  18045. }
  18046. domUtils.on(window, ['scroll', 'resize'], updateFloating);
  18047. me.addListener('keydown', defer_updateFloating);
  18048. me.addListener('beforefullscreenchange', function(t, enabled) {
  18049. if(enabled) {
  18050. unsetFloating();
  18051. }
  18052. });
  18053. me.addListener('fullscreenchanged', function(t, enabled) {
  18054. if(!enabled) {
  18055. updateFloating();
  18056. }
  18057. });
  18058. me.addListener('sourcemodechanged', function(t, enabled) {
  18059. setTimeout(function() {
  18060. updateFloating();
  18061. }, 0);
  18062. });
  18063. me.addListener("clearDoc", function() {
  18064. setTimeout(function() {
  18065. updateFloating();
  18066. }, 0);
  18067. })
  18068. }
  18069. });
  18070. };
  18071. // plugins/video.js
  18072. /**
  18073. * video插件, 为UEditor提供视频插入支持
  18074. *
  18075. * @file
  18076. * @since 1.2.6.1
  18077. */
  18078. UE.plugins['video'] = function() {
  18079. var me = this;
  18080. /**
  18081. * 创建插入视频字符窜
  18082. *
  18083. * @param url
  18084. * 视频地址
  18085. * @param width
  18086. * 视频宽度
  18087. * @param height
  18088. * 视频高度
  18089. * @param align
  18090. * 视频对齐
  18091. * @param toEmbed
  18092. * 是否以flash代替显示
  18093. * @param addParagraph
  18094. * 是否需要添加P 标签
  18095. */
  18096. function creatInsertStr(url, width, height, id, align, classname, type, istokentag) {
  18097. console.log(url)
  18098. console.log(istokentag);
  18099. istokentag = (istokentag ? true : false);
  18100. var str;
  18101. switch(type) {
  18102. case 'image':
  18103. str = '<img ' +
  18104. 'tokentag="' + istokentag + '" srcattrname="_url"' +
  18105. (id ? 'id="' + id + '"' : '') +
  18106. ' width="' +
  18107. width +
  18108. '" height="' +
  18109. height +
  18110. '" _url="' +
  18111. url +
  18112. '" class="' +
  18113. classname.replace(/\bvideo-js\b/, '') +
  18114. '"' +
  18115. ' src="' +
  18116. me.options.UEDITOR_HOME_URL +
  18117. 'themes/default/images/spacer.gif" style="background:url(' +
  18118. me.options.UEDITOR_HOME_URL +
  18119. 'themes/default/images/videologo.gif) no-repeat center center; border:1px solid gray;' +
  18120. (align ? 'float:' + align + ';' : '') + '" />'
  18121. break;
  18122. case 'embed':
  18123. str = '<embed type="application/x-shockwave-flash" class="' +
  18124. classname +
  18125. '" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
  18126. 'tokentag="' + istokentag + '" srcattrname="src"' +
  18127. ' src="' +
  18128. utils.html(url) +
  18129. '" width="' +
  18130. width +
  18131. '" height="' +
  18132. height +
  18133. '"' +
  18134. (align ? ' style="float:' + align + '"' : '') +
  18135. ' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >';
  18136. break;
  18137. case 'video':
  18138. var ext = url.substr(url.lastIndexOf('.') + 1);
  18139. if(ext == 'ogv')
  18140. ext = 'ogg';
  18141. str = '<video' + (id ? ' id="' + id + '"' : '') +
  18142. ' tokentag="' + istokentag + '" srcattrname="src"' +
  18143. ' class="' + classname + ' video-js" ' +
  18144. (align ? ' style="float:' + align + '"' : '') +
  18145. ' controls preload="none" width="' + width +
  18146. '" height="' + height + '" src="' + url +
  18147. '" data-setup="{}">' + '<source src="' + url +
  18148. '" type="video/' + ext + '" /></video>';
  18149. break;
  18150. }
  18151. return str;
  18152. }
  18153. function switchImgAndVideo(root, img2video) {
  18154. utils.each(root
  18155. .getNodesByTagName(img2video ? 'img' : 'embed video'),
  18156. function(node) {
  18157. var className = node.getAttr('class');
  18158. if(className &&
  18159. className.indexOf('edui-faked-video') != -1) {
  18160. var html = creatInsertStr(img2video ? node
  18161. .getAttr('_url') : node.getAttr('src'),
  18162. node.getAttr('width'), node
  18163. .getAttr('height'), null, node
  18164. .getStyle('float') ||
  18165. '', className, img2video ?
  18166. 'embed' :
  18167. 'image', node.getAttr('tokentag') == 'true' ? true : false);
  18168. node.parentNode.replaceChild(UE.uNode
  18169. .createElement(html), node);
  18170. }
  18171. if(className &&
  18172. className.indexOf('edui-upload-video') != -1) {
  18173. var html = creatInsertStr(img2video ? node
  18174. .getAttr('_url') : node.getAttr('src'),
  18175. node.getAttr('width'), node
  18176. .getAttr('height'), null, node
  18177. .getStyle('float') ||
  18178. '', className, img2video ?
  18179. 'video' :
  18180. 'image', node.getAttr('tokentag') == 'true' ? true : false);
  18181. node.parentNode.replaceChild(UE.uNode
  18182. .createElement(html), node);
  18183. }
  18184. })
  18185. }
  18186. me.addOutputRule(function(root) {
  18187. switchImgAndVideo(root, true)
  18188. });
  18189. me.addInputRule(function(root) {
  18190. switchImgAndVideo(root)
  18191. });
  18192. /**
  18193. * 插入视频
  18194. *
  18195. * @command insertvideo
  18196. * @method execCommand
  18197. * @param {
  18198. * String } cmd 命令字符串
  18199. * @param {
  18200. * Object } videoAttr 键值对对象, 描述一个视频的所有属性
  18201. * @example ```javascript
  18202. *
  18203. * var videoAttr = { //视频地址 url: 'http://www.youku.com/xxx', //视频宽高值,
  18204. * 单位px width: 200, height: 100 };
  18205. *
  18206. * //editor 是编辑器实例 //向编辑器插入单个视频 editor.execCommand( 'insertvideo',
  18207. * videoAttr ); ```
  18208. */
  18209. /**
  18210. * 插入视频
  18211. *
  18212. * @command insertvideo
  18213. * @method execCommand
  18214. * @param {
  18215. * String } cmd 命令字符串
  18216. * @param {
  18217. * Array } videoArr 需要插入的视频的数组, 其中的每一个元素都是一个键值对对象,
  18218. * 描述了一个视频的所有属性
  18219. * @example ```javascript
  18220. *
  18221. * var videoAttr1 = { //视频地址 url: 'http://www.youku.com/xxx', //视频宽高值,
  18222. * 单位px width: 200, height: 100 }, videoAttr2 = { //视频地址 url:
  18223. * 'http://www.youku.com/xxx', //视频宽高值, 单位px width: 200, height: 100 }
  18224. *
  18225. * //editor 是编辑器实例 //该方法将会向编辑器内插入两个视频 editor.execCommand( 'insertvideo', [
  18226. * videoAttr1, videoAttr2 ] ); ```
  18227. */
  18228. /**
  18229. * 查询当前光标所在处是否是一个视频
  18230. *
  18231. * @command insertvideo
  18232. * @method queryCommandState
  18233. * @param {
  18234. * String } cmd 需要查询的命令字符串
  18235. * @return { int } 如果当前光标所在处的元素是一个视频对象, 则返回1,否则返回0
  18236. * @example ```javascript
  18237. *
  18238. * //editor 是编辑器实例 editor.queryCommandState( 'insertvideo' ); ```
  18239. */
  18240. me.commands["insertvideo"] = {
  18241. execCommand: function(cmd, videoObjs, type) {
  18242. videoObjs = utils.isArray(videoObjs) ? videoObjs : [videoObjs];
  18243. var html = [],
  18244. id = 'tmpVedio',
  18245. cl;
  18246. for(var i = 0, vi, len = videoObjs.length; i < len; i++) {
  18247. vi = videoObjs[i];
  18248. cl = (type == 'upload' ?
  18249. 'edui-upload-video video-js vjs-default-skin' :
  18250. 'edui-faked-video');
  18251. html.push(creatInsertStr(vi.tokenURL, vi.width || 420, vi.height ||
  18252. 280, id + i, null, cl, 'image', vi.istokentag));
  18253. }
  18254. me.execCommand("inserthtml", html.join(""), true);
  18255. var rng = this.selection.getRange();
  18256. for(var i = 0, len = videoObjs.length; i < len; i++) {
  18257. var img = this.document.getElementById('tmpVedio' + i);
  18258. domUtils.removeAttributes(img, 'id');
  18259. rng.selectNode(img).select();
  18260. me.execCommand('imagefloat', videoObjs[i].align)
  18261. }
  18262. },
  18263. queryCommandState: function() {
  18264. var img = me.selection.getRange().getClosedNode(),
  18265. flag = img &&
  18266. (img.className == "edui-faked-video" || img.className
  18267. .indexOf("edui-upload-video") != -1);
  18268. return flag ? 1 : 0;
  18269. }
  18270. };
  18271. };
  18272. // plugins/table.core.js
  18273. /**
  18274. * Created with JetBrains WebStorm. User: taoqili Date: 13-1-18 Time:
  18275. * 上午11:09 To change this template use File | Settings | File Templates.
  18276. */
  18277. /**
  18278. * UE表格操作类
  18279. *
  18280. * @param table
  18281. * @constructor
  18282. */
  18283. (function() {
  18284. var UETable = UE.UETable = function(table) {
  18285. this.table = table;
  18286. this.indexTable = [];
  18287. this.selectedTds = [];
  18288. this.cellsRange = {};
  18289. this.update(table);
  18290. };
  18291. // ===以下为静态工具方法===
  18292. UETable.removeSelectedClass = function(cells) {
  18293. utils.each(cells, function(cell) {
  18294. domUtils.removeClasses(cell, "selectTdClass");
  18295. })
  18296. };
  18297. UETable.addSelectedClass = function(cells) {
  18298. utils.each(cells, function(cell) {
  18299. domUtils.addClass(cell, "selectTdClass");
  18300. })
  18301. };
  18302. UETable.isEmptyBlock = function(node) {
  18303. var reg = new RegExp(domUtils.fillChar, 'g');
  18304. if(node[browser.ie ? 'innerText' : 'textContent'].replace(/^\s*$/,
  18305. '').replace(reg, '').length > 0) {
  18306. return 0;
  18307. }
  18308. for(var i in dtd.$isNotEmpty)
  18309. if(dtd.$isNotEmpty.hasOwnProperty(i)) {
  18310. if(node.getElementsByTagName(i).length) {
  18311. return 0;
  18312. }
  18313. }
  18314. return 1;
  18315. };
  18316. UETable.getWidth = function(cell) {
  18317. if(!cell)
  18318. return 0;
  18319. return parseInt(domUtils.getComputedStyle(cell, "width"), 10);
  18320. };
  18321. /**
  18322. * 获取单元格或者单元格组的“对齐”状态。 如果当前的检测对象是一个单元格组, 只有在满足所有单元格的 水平和竖直 对齐属性都相同的
  18323. * 条件时才会返回其状态值,否则将返回null; 如果当前只检测了一个单元格, 则直接返回当前单元格的对齐状态;
  18324. *
  18325. * @param table
  18326. * cell or table cells , 支持单个单元格dom对象 或者 单元格dom对象数组
  18327. * @return { align: 'left' || 'right' || 'center', valign: 'top' ||
  18328. * 'middle' || 'bottom' } 或者 null
  18329. */
  18330. UETable.getTableCellAlignState = function(cells) {
  18331. !utils.isArray(cells) && (cells = [cells]);
  18332. var result = {},
  18333. status = ['align', 'valign'],
  18334. tempStatus = null,
  18335. isSame = true; // 状态是否相同
  18336. utils.each(cells, function(cellNode) {
  18337. utils.each(status, function(currentState) {
  18338. tempStatus = cellNode.getAttribute(currentState);
  18339. if(!result[currentState] && tempStatus) {
  18340. result[currentState] = tempStatus;
  18341. } else if(!result[currentState] ||
  18342. (tempStatus !== result[currentState])) {
  18343. isSame = false;
  18344. return false;
  18345. }
  18346. });
  18347. return isSame;
  18348. });
  18349. return isSame ? result : null;
  18350. };
  18351. /**
  18352. * 根据当前选区获取相关的table信息
  18353. *
  18354. * @return {Object}
  18355. */
  18356. UETable.getTableItemsByRange = function(editor) {
  18357. var start = editor.selection.getStart();
  18358. // ff下会选中bookmark
  18359. if(start && start.id &&
  18360. start.id.indexOf('_baidu_bookmark_start_') === 0 &&
  18361. start.nextSibling) {
  18362. start = start.nextSibling;
  18363. }
  18364. // 在table或者td边缘有可能存在选中tr的情况
  18365. var cell = start &&
  18366. domUtils.findParentByTagName(start, ["td", "th"], true),
  18367. tr = cell &&
  18368. cell.parentNode,
  18369. caption = start &&
  18370. domUtils.findParentByTagName(start, 'caption', true),
  18371. table = caption ?
  18372. caption.parentNode :
  18373. tr && tr.parentNode.parentNode;
  18374. return {
  18375. cell: cell,
  18376. tr: tr,
  18377. table: table,
  18378. caption: caption
  18379. }
  18380. };
  18381. UETable.getUETableBySelected = function(editor) {
  18382. var table = UETable.getTableItemsByRange(editor).table;
  18383. if(table && table.ueTable && table.ueTable.selectedTds.length) {
  18384. return table.ueTable;
  18385. }
  18386. return null;
  18387. };
  18388. UETable.getDefaultValue = function(editor, table) {
  18389. var borderMap = {
  18390. thin: '0px',
  18391. medium: '1px',
  18392. thick: '2px'
  18393. },
  18394. tableBorder, tdPadding, tdBorder, tmpValue;
  18395. if(!table) {
  18396. table = editor.document.createElement('table');
  18397. table.insertRow(0).insertCell(0).innerHTML = 'xxx';
  18398. editor.body.appendChild(table);
  18399. var td = table.getElementsByTagName('td')[0];
  18400. tmpValue = domUtils
  18401. .getComputedStyle(table, 'border-left-width');
  18402. tableBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  18403. tmpValue = domUtils.getComputedStyle(td, 'padding-left');
  18404. tdPadding = parseInt(borderMap[tmpValue] || tmpValue, 10);
  18405. tmpValue = domUtils.getComputedStyle(td, 'border-left-width');
  18406. tdBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  18407. domUtils.remove(table);
  18408. return {
  18409. tableBorder: tableBorder,
  18410. tdPadding: tdPadding,
  18411. tdBorder: tdBorder
  18412. };
  18413. } else {
  18414. td = table.getElementsByTagName('td')[0];
  18415. tmpValue = domUtils
  18416. .getComputedStyle(table, 'border-left-width');
  18417. tableBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  18418. tmpValue = domUtils.getComputedStyle(td, 'padding-left');
  18419. tdPadding = parseInt(borderMap[tmpValue] || tmpValue, 10);
  18420. tmpValue = domUtils.getComputedStyle(td, 'border-left-width');
  18421. tdBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  18422. return {
  18423. tableBorder: tableBorder,
  18424. tdPadding: tdPadding,
  18425. tdBorder: tdBorder
  18426. };
  18427. }
  18428. };
  18429. /**
  18430. * 根据当前点击的td或者table获取索引对象
  18431. *
  18432. * @param tdOrTable
  18433. */
  18434. UETable.getUETable = function(tdOrTable) {
  18435. var tag = tdOrTable.tagName.toLowerCase();
  18436. tdOrTable = (tag == "td" || tag == "th" || tag == 'caption') ?
  18437. domUtils.findParentByTagName(tdOrTable, "table", true) :
  18438. tdOrTable;
  18439. if(!tdOrTable.ueTable) {
  18440. tdOrTable.ueTable = new UETable(tdOrTable);
  18441. }
  18442. return tdOrTable.ueTable;
  18443. };
  18444. UETable.cloneCell = function(cell, ignoreMerge, keepPro) {
  18445. if(!cell || utils.isString(cell)) {
  18446. return this.table.ownerDocument.createElement(cell || 'td');
  18447. }
  18448. var flag = domUtils.hasClass(cell, "selectTdClass");
  18449. flag && domUtils.removeClasses(cell, "selectTdClass");
  18450. var tmpCell = cell.cloneNode(true);
  18451. if(ignoreMerge) {
  18452. tmpCell.rowSpan = tmpCell.colSpan = 1;
  18453. }
  18454. // 去掉宽高
  18455. !keepPro && domUtils.removeAttributes(tmpCell, 'width height');
  18456. !keepPro && domUtils.removeAttributes(tmpCell, 'style');
  18457. tmpCell.style.borderLeftStyle = "";
  18458. tmpCell.style.borderTopStyle = "";
  18459. tmpCell.style.borderLeftColor = cell.style.borderRightColor;
  18460. tmpCell.style.borderLeftWidth = cell.style.borderRightWidth;
  18461. tmpCell.style.borderTopColor = cell.style.borderBottomColor;
  18462. tmpCell.style.borderTopWidth = cell.style.borderBottomWidth;
  18463. flag && domUtils.addClass(cell, "selectTdClass");
  18464. return tmpCell;
  18465. }
  18466. UETable.prototype = {
  18467. getMaxRows: function() {
  18468. var rows = this.table.rows,
  18469. maxLen = 1;
  18470. for(var i = 0, row; row = rows[i]; i++) {
  18471. var currentMax = 1;
  18472. for(var j = 0, cj; cj = row.cells[j++];) {
  18473. currentMax = Math.max(cj.rowSpan || 1, currentMax);
  18474. }
  18475. maxLen = Math.max(currentMax + i, maxLen);
  18476. }
  18477. return maxLen;
  18478. },
  18479. /**
  18480. * 获取当前表格的最大列数
  18481. */
  18482. getMaxCols: function() {
  18483. var rows = this.table.rows,
  18484. maxLen = 0,
  18485. cellRows = {};
  18486. for(var i = 0, row; row = rows[i]; i++) {
  18487. var cellsNum = 0;
  18488. for(var j = 0, cj; cj = row.cells[j++];) {
  18489. cellsNum += (cj.colSpan || 1);
  18490. if(cj.rowSpan && cj.rowSpan > 1) {
  18491. for(var k = 1; k < cj.rowSpan; k++) {
  18492. if(!cellRows['row_' + (i + k)]) {
  18493. cellRows['row_' + (i + k)] = (cj.colSpan || 1);
  18494. } else {
  18495. cellRows['row_' + (i + k)]++
  18496. }
  18497. }
  18498. }
  18499. }
  18500. cellsNum += cellRows['row_' + i] || 0;
  18501. maxLen = Math.max(cellsNum, maxLen);
  18502. }
  18503. return maxLen;
  18504. },
  18505. getCellColIndex: function(cell) {
  18506. },
  18507. /**
  18508. * 获取当前cell旁边的单元格,
  18509. *
  18510. * @param cell
  18511. * @param right
  18512. */
  18513. getHSideCell: function(cell, right) {
  18514. try {
  18515. var cellInfo = this.getCellInfo(cell),
  18516. previewRowIndex, previewColIndex;
  18517. var len = this.selectedTds.length,
  18518. range = this.cellsRange;
  18519. // 首行或者首列没有前置单元格
  18520. if((!right && (!len ?
  18521. !cellInfo.colIndex :
  18522. !range.beginColIndex)) ||
  18523. (right && (!len ?
  18524. (cellInfo.colIndex == (this.colsNum - 1)) :
  18525. (range.endColIndex == this.colsNum - 1))))
  18526. return null;
  18527. previewRowIndex = !len ?
  18528. cellInfo.rowIndex :
  18529. range.beginRowIndex;
  18530. previewColIndex = !right ? (!len ? (cellInfo.colIndex < 1 ?
  18531. 0 :
  18532. (cellInfo.colIndex - 1)) : range.beginColIndex -
  18533. 1) : (!len ?
  18534. cellInfo.colIndex + 1 :
  18535. range.endColIndex + 1);
  18536. return this
  18537. .getCell(
  18538. this.indexTable[previewRowIndex][previewColIndex].rowIndex,
  18539. this.indexTable[previewRowIndex][previewColIndex].cellIndex);
  18540. } catch(e) {
  18541. showError(e);
  18542. }
  18543. },
  18544. getTabNextCell: function(cell, preRowIndex) {
  18545. var cellInfo = this.getCellInfo(cell),
  18546. rowIndex = preRowIndex ||
  18547. cellInfo.rowIndex,
  18548. colIndex = cellInfo.colIndex + 1 +
  18549. (cellInfo.colSpan - 1),
  18550. nextCell;
  18551. try {
  18552. nextCell = this.getCell(
  18553. this.indexTable[rowIndex][colIndex].rowIndex,
  18554. this.indexTable[rowIndex][colIndex].cellIndex);
  18555. } catch(e) {
  18556. try {
  18557. rowIndex = rowIndex * 1 + 1;
  18558. colIndex = 0;
  18559. nextCell = this.getCell(
  18560. this.indexTable[rowIndex][colIndex].rowIndex,
  18561. this.indexTable[rowIndex][colIndex].cellIndex);
  18562. } catch(e) {}
  18563. }
  18564. return nextCell;
  18565. },
  18566. /**
  18567. * 获取视觉上的后置单元格
  18568. *
  18569. * @param cell
  18570. * @param bottom
  18571. */
  18572. getVSideCell: function(cell, bottom, ignoreRange) {
  18573. try {
  18574. var cellInfo = this.getCellInfo(cell),
  18575. nextRowIndex, nextColIndex;
  18576. var len = this.selectedTds.length && !ignoreRange,
  18577. range = this.cellsRange;
  18578. // 末行或者末列没有后置单元格
  18579. if((!bottom && (cellInfo.rowIndex == 0)) ||
  18580. (bottom && (!len ?
  18581. (cellInfo.rowIndex + cellInfo.rowSpan > this.rowsNum -
  18582. 1) :
  18583. (range.endRowIndex == this.rowsNum - 1))))
  18584. return null;
  18585. nextRowIndex = !bottom ? (!len ?
  18586. cellInfo.rowIndex - 1 :
  18587. range.beginRowIndex - 1) : (!len ?
  18588. (cellInfo.rowIndex + cellInfo.rowSpan) :
  18589. range.endRowIndex + 1);
  18590. nextColIndex = !len ?
  18591. cellInfo.colIndex :
  18592. range.beginColIndex;
  18593. return this
  18594. .getCell(
  18595. this.indexTable[nextRowIndex][nextColIndex].rowIndex,
  18596. this.indexTable[nextRowIndex][nextColIndex].cellIndex);
  18597. } catch(e) {
  18598. showError(e);
  18599. }
  18600. },
  18601. /**
  18602. * 获取相同结束位置的单元格,xOrY指代了是获取x轴相同还是y轴相同
  18603. */
  18604. getSameEndPosCells: function(cell, xOrY) {
  18605. try {
  18606. var flag = (xOrY.toLowerCase() === "x"),
  18607. end = domUtils
  18608. .getXY(cell)[flag ? 'x' : 'y'] +
  18609. cell["offset" + (flag ? 'Width' : 'Height')],
  18610. rows = this.table.rows,
  18611. cells = null,
  18612. returns = [];
  18613. for(var i = 0; i < this.rowsNum; i++) {
  18614. cells = rows[i].cells;
  18615. for(var j = 0, tmpCell; tmpCell = cells[j++];) {
  18616. var tmpEnd = domUtils.getXY(tmpCell)[flag ?
  18617. 'x' :
  18618. 'y'] +
  18619. tmpCell["offset" +
  18620. (flag ? 'Width' : 'Height')];
  18621. // 对应行的td已经被上面行rowSpan了
  18622. if(tmpEnd > end && flag)
  18623. break;
  18624. if(cell == tmpCell || end == tmpEnd) {
  18625. // 只获取单一的单元格
  18626. // todo
  18627. // 仅获取单一单元格在特定情况下会造成returns为空,从而影响后续的拖拽实现,修正这个。需考虑性能
  18628. if(tmpCell[flag ? "colSpan" : "rowSpan"] == 1) {
  18629. returns.push(tmpCell);
  18630. }
  18631. if(flag)
  18632. break;
  18633. }
  18634. }
  18635. }
  18636. return returns;
  18637. } catch(e) {
  18638. showError(e);
  18639. }
  18640. },
  18641. setCellContent: function(cell, content) {
  18642. cell.innerHTML = content ||
  18643. (browser.ie ? domUtils.fillChar : "<br />");
  18644. },
  18645. cloneCell: UETable.cloneCell,
  18646. /**
  18647. * 获取跟当前单元格的右边竖线为左边的所有未合并单元格
  18648. */
  18649. getSameStartPosXCells: function(cell) {
  18650. try {
  18651. var start = domUtils.getXY(cell).x + cell.offsetWidth,
  18652. rows = this.table.rows,
  18653. cells, returns = [];
  18654. for(var i = 0; i < this.rowsNum; i++) {
  18655. cells = rows[i].cells;
  18656. for(var j = 0, tmpCell; tmpCell = cells[j++];) {
  18657. var tmpStart = domUtils.getXY(tmpCell).x;
  18658. if(tmpStart > start)
  18659. break;
  18660. if(tmpStart == start && tmpCell.colSpan == 1) {
  18661. returns.push(tmpCell);
  18662. break;
  18663. }
  18664. }
  18665. }
  18666. return returns;
  18667. } catch(e) {
  18668. showError(e);
  18669. }
  18670. },
  18671. /**
  18672. * 更新table对应的索引表
  18673. */
  18674. update: function(table) {
  18675. this.table = table || this.table;
  18676. this.selectedTds = [];
  18677. this.cellsRange = {};
  18678. this.indexTable = [];
  18679. var rows = this.table.rows,
  18680. rowsNum = this.getMaxRows(),
  18681. dNum = rowsNum -
  18682. rows.length,
  18683. colsNum = this.getMaxCols();
  18684. while(dNum--) {
  18685. this.table.insertRow(rows.length);
  18686. }
  18687. this.rowsNum = rowsNum;
  18688. this.colsNum = colsNum;
  18689. for(var i = 0, len = rows.length; i < len; i++) {
  18690. this.indexTable[i] = new Array(colsNum);
  18691. }
  18692. // 填充索引表
  18693. for(var rowIndex = 0, row; row = rows[rowIndex]; rowIndex++) {
  18694. for(var cellIndex = 0, cell, cells = row.cells; cell = cells[cellIndex]; cellIndex++) {
  18695. // 修正整行被rowSpan时导致的行数计算错误
  18696. if(cell.rowSpan > rowsNum) {
  18697. cell.rowSpan = rowsNum;
  18698. }
  18699. var colIndex = cellIndex,
  18700. rowSpan = cell.rowSpan || 1,
  18701. colSpan = cell.colSpan ||
  18702. 1;
  18703. // 当已经被上一行rowSpan或者被前一列colSpan了,则跳到下一个单元格进行
  18704. while(this.indexTable[rowIndex][colIndex])
  18705. colIndex++;
  18706. for(var j = 0; j < rowSpan; j++) {
  18707. for(var k = 0; k < colSpan; k++) {
  18708. this.indexTable[rowIndex + j][colIndex + k] = {
  18709. rowIndex: rowIndex,
  18710. cellIndex: cellIndex,
  18711. colIndex: colIndex,
  18712. rowSpan: rowSpan,
  18713. colSpan: colSpan
  18714. }
  18715. }
  18716. }
  18717. }
  18718. }
  18719. // 修复残缺td
  18720. for(j = 0; j < rowsNum; j++) {
  18721. for(k = 0; k < colsNum; k++) {
  18722. if(this.indexTable[j][k] === undefined) {
  18723. row = rows[j];
  18724. cell = row.cells[row.cells.length - 1];
  18725. cell = cell ?
  18726. cell.cloneNode(true) :
  18727. this.table.ownerDocument
  18728. .createElement("td");
  18729. this.setCellContent(cell);
  18730. if(cell.colSpan !== 1)
  18731. cell.colSpan = 1;
  18732. if(cell.rowSpan !== 1)
  18733. cell.rowSpan = 1;
  18734. row.appendChild(cell);
  18735. this.indexTable[j][k] = {
  18736. rowIndex: j,
  18737. cellIndex: cell.cellIndex,
  18738. colIndex: k,
  18739. rowSpan: 1,
  18740. colSpan: 1
  18741. }
  18742. }
  18743. }
  18744. }
  18745. // 当框选后删除行或者列后撤销,需要重建选区。
  18746. var tds = domUtils.getElementsByTagName(this.table, "td"),
  18747. selectTds = [];
  18748. utils.each(tds, function(td) {
  18749. if(domUtils.hasClass(td, "selectTdClass")) {
  18750. selectTds.push(td);
  18751. }
  18752. });
  18753. if(selectTds.length) {
  18754. var start = selectTds[0],
  18755. end = selectTds[selectTds.length -
  18756. 1],
  18757. startInfo = this.getCellInfo(start),
  18758. endInfo = this
  18759. .getCellInfo(end);
  18760. this.selectedTds = selectTds;
  18761. this.cellsRange = {
  18762. beginRowIndex: startInfo.rowIndex,
  18763. beginColIndex: startInfo.colIndex,
  18764. endRowIndex: endInfo.rowIndex + endInfo.rowSpan - 1,
  18765. endColIndex: endInfo.colIndex + endInfo.colSpan - 1
  18766. };
  18767. }
  18768. // 给第一行设置firstRow的样式名称,在排序图标的样式上使用到
  18769. if(!domUtils.hasClass(this.table.rows[0], "firstRow")) {
  18770. domUtils.addClass(this.table.rows[0], "firstRow");
  18771. for(var i = 1; i < this.table.rows.length; i++) {
  18772. domUtils.removeClasses(this.table.rows[i], "firstRow");
  18773. }
  18774. }
  18775. },
  18776. /**
  18777. * 获取单元格的索引信息
  18778. */
  18779. getCellInfo: function(cell) {
  18780. if(!cell)
  18781. return;
  18782. var cellIndex = cell.cellIndex,
  18783. rowIndex = cell.parentNode.rowIndex,
  18784. rowInfo = this.indexTable[rowIndex],
  18785. numCols = this.colsNum;
  18786. for(var colIndex = cellIndex; colIndex < numCols; colIndex++) {
  18787. var cellInfo = rowInfo[colIndex];
  18788. if(cellInfo.rowIndex === rowIndex &&
  18789. cellInfo.cellIndex === cellIndex) {
  18790. return cellInfo;
  18791. }
  18792. }
  18793. },
  18794. /**
  18795. * 根据行列号获取单元格
  18796. */
  18797. getCell: function(rowIndex, cellIndex) {
  18798. return rowIndex < this.rowsNum &&
  18799. this.table.rows[rowIndex].cells[cellIndex] || null;
  18800. },
  18801. /**
  18802. * 删除单元格
  18803. */
  18804. deleteCell: function(cell, rowIndex) {
  18805. rowIndex = typeof rowIndex == 'number' ?
  18806. rowIndex :
  18807. cell.parentNode.rowIndex;
  18808. var row = this.table.rows[rowIndex];
  18809. row.deleteCell(cell.cellIndex);
  18810. },
  18811. /**
  18812. * 根据始末两个单元格获取被框选的所有单元格范围
  18813. */
  18814. getCellsRange: function(cellA, cellB) {
  18815. function checkRange(beginRowIndex, beginColIndex, endRowIndex,
  18816. endColIndex) {
  18817. var tmpBeginRowIndex = beginRowIndex,
  18818. tmpBeginColIndex = beginColIndex,
  18819. tmpEndRowIndex = endRowIndex,
  18820. tmpEndColIndex = endColIndex,
  18821. cellInfo, colIndex, rowIndex;
  18822. // 通过indexTable检查是否存在超出TableRange上边界的情况
  18823. if(beginRowIndex > 0) {
  18824. for(colIndex = beginColIndex; colIndex < endColIndex; colIndex++) {
  18825. cellInfo = me.indexTable[beginRowIndex][colIndex];
  18826. rowIndex = cellInfo.rowIndex;
  18827. if(rowIndex < beginRowIndex) {
  18828. tmpBeginRowIndex = Math.min(rowIndex,
  18829. tmpBeginRowIndex);
  18830. }
  18831. }
  18832. }
  18833. // 通过indexTable检查是否存在超出TableRange右边界的情况
  18834. if(endColIndex < me.colsNum) {
  18835. for(rowIndex = beginRowIndex; rowIndex < endRowIndex; rowIndex++) {
  18836. cellInfo = me.indexTable[rowIndex][endColIndex];
  18837. colIndex = cellInfo.colIndex + cellInfo.colSpan - 1;
  18838. if(colIndex > endColIndex) {
  18839. tmpEndColIndex = Math.max(colIndex,
  18840. tmpEndColIndex);
  18841. }
  18842. }
  18843. }
  18844. // 检查是否有超出TableRange下边界的情况
  18845. if(endRowIndex < me.rowsNum) {
  18846. for(colIndex = beginColIndex; colIndex < endColIndex; colIndex++) {
  18847. cellInfo = me.indexTable[endRowIndex][colIndex];
  18848. rowIndex = cellInfo.rowIndex + cellInfo.rowSpan - 1;
  18849. if(rowIndex > endRowIndex) {
  18850. tmpEndRowIndex = Math.max(rowIndex,
  18851. tmpEndRowIndex);
  18852. }
  18853. }
  18854. }
  18855. // 检查是否有超出TableRange左边界的情况
  18856. if(beginColIndex > 0) {
  18857. for(rowIndex = beginRowIndex; rowIndex < endRowIndex; rowIndex++) {
  18858. cellInfo = me.indexTable[rowIndex][beginColIndex];
  18859. colIndex = cellInfo.colIndex;
  18860. if(colIndex < beginColIndex) {
  18861. tmpBeginColIndex = Math.min(cellInfo.colIndex,
  18862. tmpBeginColIndex);
  18863. }
  18864. }
  18865. }
  18866. // 递归调用直至所有完成所有框选单元格的扩展
  18867. if(tmpBeginRowIndex != beginRowIndex ||
  18868. tmpBeginColIndex != beginColIndex ||
  18869. tmpEndRowIndex != endRowIndex ||
  18870. tmpEndColIndex != endColIndex) {
  18871. return checkRange(tmpBeginRowIndex, tmpBeginColIndex,
  18872. tmpEndRowIndex, tmpEndColIndex);
  18873. } else {
  18874. // 不需要扩展TableRange的情况
  18875. return {
  18876. beginRowIndex: beginRowIndex,
  18877. beginColIndex: beginColIndex,
  18878. endRowIndex: endRowIndex,
  18879. endColIndex: endColIndex
  18880. };
  18881. }
  18882. }
  18883. try {
  18884. var me = this,
  18885. cellAInfo = me.getCellInfo(cellA);
  18886. if(cellA === cellB) {
  18887. return {
  18888. beginRowIndex: cellAInfo.rowIndex,
  18889. beginColIndex: cellAInfo.colIndex,
  18890. endRowIndex: cellAInfo.rowIndex +
  18891. cellAInfo.rowSpan - 1,
  18892. endColIndex: cellAInfo.colIndex +
  18893. cellAInfo.colSpan - 1
  18894. };
  18895. }
  18896. var cellBInfo = me.getCellInfo(cellB);
  18897. // 计算TableRange的四个边
  18898. var beginRowIndex = Math.min(cellAInfo.rowIndex,
  18899. cellBInfo.rowIndex),
  18900. beginColIndex = Math.min(
  18901. cellAInfo.colIndex, cellBInfo.colIndex),
  18902. endRowIndex = Math
  18903. .max(cellAInfo.rowIndex + cellAInfo.rowSpan - 1,
  18904. cellBInfo.rowIndex + cellBInfo.rowSpan - 1),
  18905. endColIndex = Math
  18906. .max(cellAInfo.colIndex + cellAInfo.colSpan - 1,
  18907. cellBInfo.colIndex + cellBInfo.colSpan - 1);
  18908. return checkRange(beginRowIndex, beginColIndex,
  18909. endRowIndex, endColIndex);
  18910. } catch(e) {
  18911. // throw e;
  18912. }
  18913. },
  18914. /**
  18915. * 依据cellsRange获取对应的单元格集合
  18916. */
  18917. getCells: function(range) {
  18918. // 每次获取cells之前必须先清除上次的选择,否则会对后续获取操作造成影响
  18919. this.clearSelected();
  18920. var beginRowIndex = range.beginRowIndex,
  18921. beginColIndex = range.beginColIndex,
  18922. endRowIndex = range.endRowIndex,
  18923. endColIndex = range.endColIndex,
  18924. cellInfo, rowIndex, colIndex, tdHash = {},
  18925. returnTds = [];
  18926. for(var i = beginRowIndex; i <= endRowIndex; i++) {
  18927. for(var j = beginColIndex; j <= endColIndex; j++) {
  18928. cellInfo = this.indexTable[i][j];
  18929. rowIndex = cellInfo.rowIndex;
  18930. colIndex = cellInfo.colIndex;
  18931. // 如果Cells里已经包含了此Cell则跳过
  18932. var key = rowIndex + '|' + colIndex;
  18933. if(tdHash[key])
  18934. continue;
  18935. tdHash[key] = 1;
  18936. if(rowIndex < i ||
  18937. colIndex < j ||
  18938. rowIndex + cellInfo.rowSpan - 1 > endRowIndex ||
  18939. colIndex + cellInfo.colSpan - 1 > endColIndex) {
  18940. return null;
  18941. }
  18942. returnTds.push(this.getCell(rowIndex,
  18943. cellInfo.cellIndex));
  18944. }
  18945. }
  18946. return returnTds;
  18947. },
  18948. /**
  18949. * 清理已经选中的单元格
  18950. */
  18951. clearSelected: function() {
  18952. UETable.removeSelectedClass(this.selectedTds);
  18953. this.selectedTds = [];
  18954. this.cellsRange = {};
  18955. },
  18956. /**
  18957. * 根据range设置已经选中的单元格
  18958. */
  18959. setSelected: function(range) {
  18960. var cells = this.getCells(range);
  18961. UETable.addSelectedClass(cells);
  18962. this.selectedTds = cells;
  18963. this.cellsRange = range;
  18964. },
  18965. isFullRow: function() {
  18966. var range = this.cellsRange;
  18967. return(range.endColIndex - range.beginColIndex + 1) == this.colsNum;
  18968. },
  18969. isFullCol: function() {
  18970. var range = this.cellsRange,
  18971. table = this.table,
  18972. ths = table
  18973. .getElementsByTagName("th"),
  18974. rows = range.endRowIndex -
  18975. range.beginRowIndex + 1;
  18976. return !ths.length ?
  18977. rows == this.rowsNum :
  18978. rows == this.rowsNum || (rows == this.rowsNum - 1);
  18979. },
  18980. /**
  18981. * 获取视觉上的前置单元格,默认是左边,top传入时
  18982. *
  18983. * @param cell
  18984. * @param top
  18985. */
  18986. getNextCell: function(cell, bottom, ignoreRange) {
  18987. try {
  18988. var cellInfo = this.getCellInfo(cell),
  18989. nextRowIndex, nextColIndex;
  18990. var len = this.selectedTds.length && !ignoreRange,
  18991. range = this.cellsRange;
  18992. // 末行或者末列没有后置单元格
  18993. if((!bottom && (cellInfo.rowIndex == 0)) ||
  18994. (bottom && (!len ?
  18995. (cellInfo.rowIndex + cellInfo.rowSpan > this.rowsNum -
  18996. 1) :
  18997. (range.endRowIndex == this.rowsNum - 1))))
  18998. return null;
  18999. nextRowIndex = !bottom ? (!len ?
  19000. cellInfo.rowIndex - 1 :
  19001. range.beginRowIndex - 1) : (!len ?
  19002. (cellInfo.rowIndex + cellInfo.rowSpan) :
  19003. range.endRowIndex + 1);
  19004. nextColIndex = !len ?
  19005. cellInfo.colIndex :
  19006. range.beginColIndex;
  19007. return this
  19008. .getCell(
  19009. this.indexTable[nextRowIndex][nextColIndex].rowIndex,
  19010. this.indexTable[nextRowIndex][nextColIndex].cellIndex);
  19011. } catch(e) {
  19012. showError(e);
  19013. }
  19014. },
  19015. getPreviewCell: function(cell, top) {
  19016. try {
  19017. var cellInfo = this.getCellInfo(cell),
  19018. previewRowIndex, previewColIndex;
  19019. var len = this.selectedTds.length,
  19020. range = this.cellsRange;
  19021. // 首行或者首列没有前置单元格
  19022. if((!top && (!len ?
  19023. !cellInfo.colIndex :
  19024. !range.beginColIndex)) ||
  19025. (top && (!len ?
  19026. (cellInfo.rowIndex > (this.colsNum - 1)) :
  19027. (range.endColIndex == this.colsNum - 1))))
  19028. return null;
  19029. previewRowIndex = !top ? (!len ?
  19030. cellInfo.rowIndex :
  19031. range.beginRowIndex) : (!len ?
  19032. (cellInfo.rowIndex < 1 ?
  19033. 0 :
  19034. (cellInfo.rowIndex - 1)) :
  19035. range.beginRowIndex);
  19036. previewColIndex = !top ? (!len ? (cellInfo.colIndex < 1 ?
  19037. 0 :
  19038. (cellInfo.colIndex - 1)) : range.beginColIndex -
  19039. 1) : (!len ?
  19040. cellInfo.colIndex :
  19041. range.endColIndex + 1);
  19042. return this
  19043. .getCell(
  19044. this.indexTable[previewRowIndex][previewColIndex].rowIndex,
  19045. this.indexTable[previewRowIndex][previewColIndex].cellIndex);
  19046. } catch(e) {
  19047. showError(e);
  19048. }
  19049. },
  19050. /**
  19051. * 移动单元格中的内容
  19052. */
  19053. moveContent: function(cellTo, cellFrom) {
  19054. if(UETable.isEmptyBlock(cellFrom))
  19055. return;
  19056. if(UETable.isEmptyBlock(cellTo)) {
  19057. cellTo.innerHTML = cellFrom.innerHTML;
  19058. return;
  19059. }
  19060. var child = cellTo.lastChild;
  19061. if(child.nodeType == 3 || !dtd.$block[child.tagName]) {
  19062. cellTo
  19063. .appendChild(cellTo.ownerDocument
  19064. .createElement('br'))
  19065. }
  19066. while(child = cellFrom.firstChild) {
  19067. cellTo.appendChild(child);
  19068. }
  19069. },
  19070. /**
  19071. * 向右合并单元格
  19072. */
  19073. mergeRight: function(cell) {
  19074. var cellInfo = this.getCellInfo(cell),
  19075. rightColIndex = cellInfo.colIndex +
  19076. cellInfo.colSpan,
  19077. rightCellInfo = this.indexTable[cellInfo.rowIndex][rightColIndex],
  19078. rightCell = this
  19079. .getCell(rightCellInfo.rowIndex,
  19080. rightCellInfo.cellIndex);
  19081. // 合并
  19082. cell.colSpan = cellInfo.colSpan + rightCellInfo.colSpan;
  19083. // 被合并的单元格不应存在宽度属性
  19084. cell.removeAttribute("width");
  19085. // 移动内容
  19086. this.moveContent(cell, rightCell);
  19087. // 删掉被合并的Cell
  19088. this.deleteCell(rightCell, rightCellInfo.rowIndex);
  19089. this.update();
  19090. },
  19091. /**
  19092. * 向下合并单元格
  19093. */
  19094. mergeDown: function(cell) {
  19095. var cellInfo = this.getCellInfo(cell),
  19096. downRowIndex = cellInfo.rowIndex +
  19097. cellInfo.rowSpan,
  19098. downCellInfo = this.indexTable[downRowIndex][cellInfo.colIndex],
  19099. downCell = this
  19100. .getCell(downCellInfo.rowIndex, downCellInfo.cellIndex);
  19101. cell.rowSpan = cellInfo.rowSpan + downCellInfo.rowSpan;
  19102. cell.removeAttribute("height");
  19103. this.moveContent(cell, downCell);
  19104. this.deleteCell(downCell, downCellInfo.rowIndex);
  19105. this.update();
  19106. },
  19107. /**
  19108. * 合并整个range中的内容
  19109. */
  19110. mergeRange: function() {
  19111. // 由于合并操作可以在任意时刻进行,所以无法通过鼠标位置等信息实时生成range,只能通过缓存实例中的cellsRange对象来访问
  19112. var range = this.cellsRange,
  19113. leftTopCell = this
  19114. .getCell(
  19115. range.beginRowIndex,
  19116. this.indexTable[range.beginRowIndex][range.beginColIndex].cellIndex);
  19117. if(leftTopCell.tagName == "TH" &&
  19118. range.endRowIndex !== range.beginRowIndex) {
  19119. var index = this.indexTable,
  19120. info = this
  19121. .getCellInfo(leftTopCell);
  19122. leftTopCell = this.getCell(1,
  19123. index[1][info.colIndex].cellIndex);
  19124. range = this.getCellsRange(leftTopCell, this.getCell(
  19125. index[this.rowsNum - 1][info.colIndex].rowIndex,
  19126. index[this.rowsNum - 1][info.colIndex].cellIndex));
  19127. }
  19128. // 删除剩余的Cells
  19129. var cells = this.getCells(range);
  19130. for(var i = 0, ci; ci = cells[i++];) {
  19131. if(ci !== leftTopCell) {
  19132. this.moveContent(leftTopCell, ci);
  19133. this.deleteCell(ci);
  19134. }
  19135. }
  19136. // 修改左上角Cell的rowSpan和colSpan,并调整宽度属性设置
  19137. leftTopCell.rowSpan = range.endRowIndex - range.beginRowIndex +
  19138. 1;
  19139. leftTopCell.rowSpan > 1 &&
  19140. leftTopCell.removeAttribute("height");
  19141. leftTopCell.colSpan = range.endColIndex - range.beginColIndex +
  19142. 1;
  19143. leftTopCell.colSpan > 1 && leftTopCell.removeAttribute("width");
  19144. if(leftTopCell.rowSpan == this.rowsNum &&
  19145. leftTopCell.colSpan != 1) {
  19146. leftTopCell.colSpan = 1;
  19147. }
  19148. if(leftTopCell.colSpan == this.colsNum &&
  19149. leftTopCell.rowSpan != 1) {
  19150. var rowIndex = leftTopCell.parentNode.rowIndex;
  19151. // 解决IE下的表格操作问题
  19152. if(this.table.deleteRow) {
  19153. for(var i = rowIndex + 1, curIndex = rowIndex + 1, len = leftTopCell.rowSpan; i < len; i++) {
  19154. this.table.deleteRow(curIndex);
  19155. }
  19156. } else {
  19157. for(var i = 0, len = leftTopCell.rowSpan - 1; i < len; i++) {
  19158. var row = this.table.rows[rowIndex + 1];
  19159. row.parentNode.removeChild(row);
  19160. }
  19161. }
  19162. leftTopCell.rowSpan = 1;
  19163. }
  19164. this.update();
  19165. },
  19166. /**
  19167. * 插入一行单元格
  19168. */
  19169. insertRow: function(rowIndex, sourceCell) {
  19170. var numCols = this.colsNum,
  19171. table = this.table,
  19172. row = table
  19173. .insertRow(rowIndex),
  19174. cell, isInsertTitle = typeof sourceCell == 'string' &&
  19175. sourceCell.toUpperCase() == 'TH';
  19176. function replaceTdToTh(colIndex, cell, tableRow) {
  19177. if(colIndex == 0) {
  19178. var tr = tableRow.nextSibling ||
  19179. tableRow.previousSibling,
  19180. th = tr.cells[colIndex];
  19181. if(th.tagName == 'TH') {
  19182. th = cell.ownerDocument.createElement("th");
  19183. th.appendChild(cell.firstChild);
  19184. tableRow.insertBefore(th, cell);
  19185. domUtils.remove(cell)
  19186. }
  19187. } else {
  19188. if(cell.tagName == 'TH') {
  19189. var td = cell.ownerDocument.createElement("td");
  19190. td.appendChild(cell.firstChild);
  19191. tableRow.insertBefore(td, cell);
  19192. domUtils.remove(cell)
  19193. }
  19194. }
  19195. }
  19196. // 首行直接插入,无需考虑部分单元格被rowspan的情况
  19197. if(rowIndex == 0 || rowIndex == this.rowsNum) {
  19198. for(var colIndex = 0; colIndex < numCols; colIndex++) {
  19199. cell = this.cloneCell(sourceCell, true);
  19200. this.setCellContent(cell);
  19201. cell.getAttribute('vAlign') &&
  19202. cell.setAttribute('vAlign', cell
  19203. .getAttribute('vAlign'));
  19204. row.appendChild(cell);
  19205. if(!isInsertTitle)
  19206. replaceTdToTh(colIndex, cell, row);
  19207. }
  19208. } else {
  19209. var infoRow = this.indexTable[rowIndex],
  19210. cellIndex = 0;
  19211. for(colIndex = 0; colIndex < numCols; colIndex++) {
  19212. var cellInfo = infoRow[colIndex];
  19213. // 如果存在某个单元格的rowspan穿过待插入行的位置,则修改该单元格的rowspan即可,无需插入单元格
  19214. if(cellInfo.rowIndex < rowIndex) {
  19215. cell = this.getCell(cellInfo.rowIndex,
  19216. cellInfo.cellIndex);
  19217. cell.rowSpan = cellInfo.rowSpan + 1;
  19218. } else {
  19219. cell = this.cloneCell(sourceCell, true);
  19220. this.setCellContent(cell);
  19221. row.appendChild(cell);
  19222. }
  19223. if(!isInsertTitle)
  19224. replaceTdToTh(colIndex, cell, row);
  19225. }
  19226. }
  19227. // 框选时插入不触发contentchange,需要手动更新索引。
  19228. this.update();
  19229. return row;
  19230. },
  19231. /**
  19232. * 删除一行单元格
  19233. *
  19234. * @param rowIndex
  19235. */
  19236. deleteRow: function(rowIndex) {
  19237. var row = this.table.rows[rowIndex],
  19238. infoRow = this.indexTable[rowIndex],
  19239. colsNum = this.colsNum,
  19240. count = 0; // 处理计数
  19241. for(var colIndex = 0; colIndex < colsNum;) {
  19242. var cellInfo = infoRow[colIndex],
  19243. cell = this.getCell(
  19244. cellInfo.rowIndex, cellInfo.cellIndex);
  19245. if(cell.rowSpan > 1) {
  19246. if(cellInfo.rowIndex == rowIndex) {
  19247. var clone = cell.cloneNode(true);
  19248. clone.rowSpan = cell.rowSpan - 1;
  19249. clone.innerHTML = "";
  19250. cell.rowSpan = 1;
  19251. var nextRowIndex = rowIndex + 1,
  19252. nextRow = this.table.rows[nextRowIndex],
  19253. insertCellIndex, preMerged = this
  19254. .getPreviewMergedCellsNum(nextRowIndex,
  19255. colIndex) -
  19256. count;
  19257. if(preMerged < colIndex) {
  19258. insertCellIndex = colIndex - preMerged - 1;
  19259. // nextRow.insertCell(insertCellIndex);
  19260. domUtils.insertAfter(
  19261. nextRow.cells[insertCellIndex], clone);
  19262. } else {
  19263. if(nextRow.cells.length)
  19264. nextRow.insertBefore(clone,
  19265. nextRow.cells[0])
  19266. }
  19267. count += 1;
  19268. // cell.parentNode.removeChild(cell);
  19269. }
  19270. }
  19271. colIndex += cell.colSpan || 1;
  19272. }
  19273. var deleteTds = [],
  19274. cacheMap = {};
  19275. for(colIndex = 0; colIndex < colsNum; colIndex++) {
  19276. var tmpRowIndex = infoRow[colIndex].rowIndex,
  19277. tmpCellIndex = infoRow[colIndex].cellIndex,
  19278. key = tmpRowIndex +
  19279. "_" + tmpCellIndex;
  19280. if(cacheMap[key])
  19281. continue;
  19282. cacheMap[key] = 1;
  19283. cell = this.getCell(tmpRowIndex, tmpCellIndex);
  19284. deleteTds.push(cell);
  19285. }
  19286. var mergeTds = [];
  19287. utils.each(deleteTds, function(td) {
  19288. if(td.rowSpan == 1) {
  19289. td.parentNode.removeChild(td);
  19290. } else {
  19291. mergeTds.push(td);
  19292. }
  19293. });
  19294. utils.each(mergeTds, function(td) {
  19295. td.rowSpan--;
  19296. });
  19297. row.parentNode.removeChild(row);
  19298. // 浏览器方法本身存在bug,采用自定义方法删除
  19299. // this.table.deleteRow(rowIndex);
  19300. this.update();
  19301. },
  19302. insertCol: function(colIndex, sourceCell, defaultValue) {
  19303. var rowsNum = this.rowsNum,
  19304. rowIndex = 0,
  19305. tableRow, cell, backWidth = parseInt(
  19306. (this.table.offsetWidth - (this.colsNum + 1) * 20 - (this.colsNum + 1)) /
  19307. (this.colsNum + 1), 10),
  19308. isInsertTitleCol = typeof sourceCell == 'string' &&
  19309. sourceCell.toUpperCase() == 'TH';
  19310. function replaceTdToTh(rowIndex, cell, tableRow) {
  19311. if(rowIndex == 0) {
  19312. var th = cell.nextSibling || cell.previousSibling;
  19313. if(th.tagName == 'TH') {
  19314. th = cell.ownerDocument.createElement("th");
  19315. th.appendChild(cell.firstChild);
  19316. tableRow.insertBefore(th, cell);
  19317. domUtils.remove(cell)
  19318. }
  19319. } else {
  19320. if(cell.tagName == 'TH') {
  19321. var td = cell.ownerDocument.createElement("td");
  19322. td.appendChild(cell.firstChild);
  19323. tableRow.insertBefore(td, cell);
  19324. domUtils.remove(cell)
  19325. }
  19326. }
  19327. }
  19328. var preCell;
  19329. if(colIndex == 0 || colIndex == this.colsNum) {
  19330. for(; rowIndex < rowsNum; rowIndex++) {
  19331. tableRow = this.table.rows[rowIndex];
  19332. preCell = tableRow.cells[colIndex == 0 ?
  19333. colIndex :
  19334. tableRow.cells.length];
  19335. cell = this.cloneCell(sourceCell, true); // tableRow.insertCell(colIndex
  19336. // == 0 ?
  19337. // colIndex
  19338. // :
  19339. // tableRow.cells.length);
  19340. this.setCellContent(cell);
  19341. cell
  19342. .setAttribute('vAlign', cell
  19343. .getAttribute('vAlign'));
  19344. preCell
  19345. &&
  19346. cell.setAttribute('width', preCell
  19347. .getAttribute('width'));
  19348. if(!colIndex) {
  19349. tableRow.insertBefore(cell, tableRow.cells[0]);
  19350. } else {
  19351. domUtils.insertAfter(
  19352. tableRow.cells[tableRow.cells.length - 1],
  19353. cell);
  19354. }
  19355. if(!isInsertTitleCol)
  19356. replaceTdToTh(rowIndex, cell, tableRow)
  19357. }
  19358. } else {
  19359. for(; rowIndex < rowsNum; rowIndex++) {
  19360. var cellInfo = this.indexTable[rowIndex][colIndex];
  19361. if(cellInfo.colIndex < colIndex) {
  19362. cell = this.getCell(cellInfo.rowIndex,
  19363. cellInfo.cellIndex);
  19364. cell.colSpan = cellInfo.colSpan + 1;
  19365. } else {
  19366. tableRow = this.table.rows[rowIndex];
  19367. preCell = tableRow.cells[cellInfo.cellIndex];
  19368. cell = this.cloneCell(sourceCell, true); // tableRow.insertCell(cellInfo.cellIndex);
  19369. this.setCellContent(cell);
  19370. cell.setAttribute('vAlign', cell
  19371. .getAttribute('vAlign'));
  19372. preCell
  19373. &&
  19374. cell.setAttribute('width', preCell
  19375. .getAttribute('width'));
  19376. // 防止IE下报错
  19377. preCell
  19378. ?
  19379. tableRow.insertBefore(cell, preCell) :
  19380. tableRow.appendChild(cell);
  19381. }
  19382. if(!isInsertTitleCol)
  19383. replaceTdToTh(rowIndex, cell, tableRow);
  19384. }
  19385. }
  19386. // 框选时插入不触发contentchange,需要手动更新索引
  19387. this.update();
  19388. this.updateWidth(backWidth, defaultValue || {
  19389. tdPadding: 10,
  19390. tdBorder: 1
  19391. });
  19392. },
  19393. updateWidth: function(width, defaultValue) {
  19394. var table = this.table,
  19395. tmpWidth = UETable.getWidth(table) -
  19396. defaultValue.tdPadding * 2 - defaultValue.tdBorder +
  19397. width;
  19398. if(tmpWidth < table.ownerDocument.body.offsetWidth) {
  19399. table.setAttribute("width", tmpWidth);
  19400. return;
  19401. }
  19402. var tds = domUtils.getElementsByTagName(this.table, "td th");
  19403. utils.each(tds, function(td) {
  19404. td.setAttribute("width", width);
  19405. })
  19406. },
  19407. deleteCol: function(colIndex) {
  19408. var indexTable = this.indexTable,
  19409. tableRows = this.table.rows,
  19410. backTableWidth = this.table
  19411. .getAttribute("width"),
  19412. backTdWidth = 0,
  19413. rowsNum = this.rowsNum,
  19414. cacheMap = {};
  19415. for(var rowIndex = 0; rowIndex < rowsNum;) {
  19416. var infoRow = indexTable[rowIndex],
  19417. cellInfo = infoRow[colIndex],
  19418. key = cellInfo.rowIndex +
  19419. '_' + cellInfo.colIndex;
  19420. // 跳过已经处理过的Cell
  19421. if(cacheMap[key])
  19422. continue;
  19423. cacheMap[key] = 1;
  19424. var cell = this.getCell(cellInfo.rowIndex,
  19425. cellInfo.cellIndex);
  19426. if(!backTdWidth)
  19427. backTdWidth = cell &&
  19428. parseInt(cell.offsetWidth / cell.colSpan, 10)
  19429. .toFixed(0);
  19430. // 如果Cell的colSpan大于1, 就修改colSpan, 否则就删掉这个Cell
  19431. if(cell.colSpan > 1) {
  19432. cell.colSpan--;
  19433. } else {
  19434. tableRows[rowIndex].deleteCell(cellInfo.cellIndex);
  19435. }
  19436. rowIndex += cellInfo.rowSpan || 1;
  19437. }
  19438. this.table.setAttribute("width", backTableWidth - backTdWidth);
  19439. this.update();
  19440. },
  19441. splitToCells: function(cell) {
  19442. var me = this,
  19443. cells = this.splitToRows(cell);
  19444. utils.each(cells, function(cell) {
  19445. me.splitToCols(cell);
  19446. })
  19447. },
  19448. splitToRows: function(cell) {
  19449. var cellInfo = this.getCellInfo(cell),
  19450. rowIndex = cellInfo.rowIndex,
  19451. colIndex = cellInfo.colIndex,
  19452. results = [];
  19453. // 修改Cell的rowSpan
  19454. cell.rowSpan = 1;
  19455. results.push(cell);
  19456. // 补齐单元格
  19457. for(var i = rowIndex, endRow = rowIndex + cellInfo.rowSpan; i < endRow; i++) {
  19458. if(i == rowIndex)
  19459. continue;
  19460. var tableRow = this.table.rows[i],
  19461. tmpCell = tableRow
  19462. .insertCell(colIndex -
  19463. this
  19464. .getPreviewMergedCellsNum(i,
  19465. colIndex));
  19466. tmpCell.colSpan = cellInfo.colSpan;
  19467. this.setCellContent(tmpCell);
  19468. tmpCell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  19469. tmpCell.setAttribute('align', cell.getAttribute('align'));
  19470. if(cell.style.cssText) {
  19471. tmpCell.style.cssText = cell.style.cssText;
  19472. }
  19473. results.push(tmpCell);
  19474. }
  19475. this.update();
  19476. return results;
  19477. },
  19478. getPreviewMergedCellsNum: function(rowIndex, colIndex) {
  19479. var indexRow = this.indexTable[rowIndex],
  19480. num = 0;
  19481. for(var i = 0; i < colIndex;) {
  19482. var colSpan = indexRow[i].colSpan,
  19483. tmpRowIndex = indexRow[i].rowIndex;
  19484. num += (colSpan - (tmpRowIndex == rowIndex ? 1 : 0));
  19485. i += colSpan;
  19486. }
  19487. return num;
  19488. },
  19489. splitToCols: function(cell) {
  19490. var backWidth = (cell.offsetWidth / cell.colSpan - 22)
  19491. .toFixed(0),
  19492. cellInfo = this.getCellInfo(cell),
  19493. rowIndex = cellInfo.rowIndex,
  19494. colIndex = cellInfo.colIndex,
  19495. results = [];
  19496. // 修改Cell的rowSpan
  19497. cell.colSpan = 1;
  19498. cell.setAttribute("width", backWidth);
  19499. results.push(cell);
  19500. // 补齐单元格
  19501. for(var j = colIndex, endCol = colIndex + cellInfo.colSpan; j < endCol; j++) {
  19502. if(j == colIndex)
  19503. continue;
  19504. var tableRow = this.table.rows[rowIndex],
  19505. tmpCell = tableRow
  19506. .insertCell(this.indexTable[rowIndex][j].cellIndex +
  19507. 1);
  19508. tmpCell.rowSpan = cellInfo.rowSpan;
  19509. this.setCellContent(tmpCell);
  19510. tmpCell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  19511. tmpCell.setAttribute('align', cell.getAttribute('align'));
  19512. tmpCell.setAttribute('width', backWidth);
  19513. if(cell.style.cssText) {
  19514. tmpCell.style.cssText = cell.style.cssText;
  19515. }
  19516. // 处理th的情况
  19517. if(cell.tagName == 'TH') {
  19518. var th = cell.ownerDocument.createElement('th');
  19519. th.appendChild(tmpCell.firstChild);
  19520. th.setAttribute('vAlign', cell.getAttribute('vAlign'));
  19521. th.rowSpan = tmpCell.rowSpan;
  19522. tableRow.insertBefore(th, tmpCell);
  19523. domUtils.remove(tmpCell);
  19524. }
  19525. results.push(tmpCell);
  19526. }
  19527. this.update();
  19528. return results;
  19529. },
  19530. isLastCell: function(cell, rowsNum, colsNum) {
  19531. rowsNum = rowsNum || this.rowsNum;
  19532. colsNum = colsNum || this.colsNum;
  19533. var cellInfo = this.getCellInfo(cell);
  19534. return((cellInfo.rowIndex + cellInfo.rowSpan) == rowsNum) &&
  19535. ((cellInfo.colIndex + cellInfo.colSpan) == colsNum);
  19536. },
  19537. getLastCell: function(cells) {
  19538. cells = cells || this.table.getElementsByTagName("td");
  19539. var firstInfo = this.getCellInfo(cells[0]);
  19540. var me = this,
  19541. last = cells[0],
  19542. tr = last.parentNode,
  19543. cellsNum = 0,
  19544. cols = 0,
  19545. rows;
  19546. utils.each(cells, function(cell) {
  19547. if(cell.parentNode == tr)
  19548. cols += cell.colSpan || 1;
  19549. cellsNum += cell.rowSpan * cell.colSpan || 1;
  19550. });
  19551. rows = cellsNum / cols;
  19552. utils.each(cells, function(cell) {
  19553. if(me.isLastCell(cell, rows, cols)) {
  19554. last = cell;
  19555. return false;
  19556. }
  19557. });
  19558. return last;
  19559. },
  19560. selectRow: function(rowIndex) {
  19561. var indexRow = this.indexTable[rowIndex],
  19562. start = this.getCell(
  19563. indexRow[0].rowIndex, indexRow[0].cellIndex),
  19564. end = this
  19565. .getCell(indexRow[this.colsNum - 1].rowIndex,
  19566. indexRow[this.colsNum - 1].cellIndex),
  19567. range = this
  19568. .getCellsRange(start, end);
  19569. this.setSelected(range);
  19570. },
  19571. selectTable: function() {
  19572. var tds = this.table.getElementsByTagName("td"),
  19573. range = this
  19574. .getCellsRange(tds[0], tds[tds.length - 1]);
  19575. this.setSelected(range);
  19576. },
  19577. setBackground: function(cells, value) {
  19578. if(typeof value === "string") {
  19579. utils.each(cells, function(cell) {
  19580. cell.style.backgroundColor = value;
  19581. })
  19582. } else if(typeof value === "object") {
  19583. value = utils.extend({
  19584. repeat: true,
  19585. colorList: ["#ddd", "#fff"]
  19586. }, value);
  19587. var rowIndex = this.getCellInfo(cells[0]).rowIndex,
  19588. count = 0,
  19589. colors = value.colorList,
  19590. getColor = function(
  19591. list, index, repeat) {
  19592. return list[index] ? list[index] : repeat ? list[index %
  19593. list.length] : "";
  19594. };
  19595. for(var i = 0, cell; cell = cells[i++];) {
  19596. var cellInfo = this.getCellInfo(cell);
  19597. cell.style.backgroundColor = getColor(colors,
  19598. ((rowIndex + count) == cellInfo.rowIndex) ?
  19599. count :
  19600. ++count, value.repeat);
  19601. }
  19602. }
  19603. },
  19604. removeBackground: function(cells) {
  19605. utils.each(cells, function(cell) {
  19606. cell.style.backgroundColor = "";
  19607. })
  19608. }
  19609. };
  19610. function showError(e) {}
  19611. })();
  19612. // plugins/table.cmds.js
  19613. /**
  19614. * Created with JetBrains PhpStorm. User: taoqili Date: 13-2-20 Time: 下午6:25
  19615. * To change this template use File | Settings | File Templates.
  19616. */
  19617. ;
  19618. (function() {
  19619. var UT = UE.UETable,
  19620. getTableItemsByRange = function(editor) {
  19621. return UT.getTableItemsByRange(editor);
  19622. },
  19623. getUETableBySelected = function(editor) {
  19624. return UT.getUETableBySelected(editor)
  19625. },
  19626. getDefaultValue = function(editor, table) {
  19627. return UT.getDefaultValue(editor, table);
  19628. },
  19629. getUETable = function(tdOrTable) {
  19630. return UT.getUETable(tdOrTable);
  19631. };
  19632. UE.commands['inserttable'] = {
  19633. queryCommandState: function() {
  19634. return getTableItemsByRange(this).table ? -1 : 0;
  19635. },
  19636. execCommand: function(cmd, opt) {
  19637. function createTable(opt, tdWidth) {
  19638. var html = [],
  19639. rowsNum = opt.numRows,
  19640. colsNum = opt.numCols;
  19641. for(var r = 0; r < rowsNum; r++) {
  19642. html.push('<tr' + (r == 0 ? ' class="firstRow"' : '') +
  19643. '>');
  19644. for(var c = 0; c < colsNum; c++) {
  19645. // html.push('<td width="' + tdWidth + '" vAlign="'
  19646. // + opt.tdvalign + '" >' + (browser.ie &&
  19647. // browser.version < 11 ? domUtils.fillChar :
  19648. // '<br/>') + '</td>')
  19649. // html.push('<td width="' + tdWidth + '" vAlign="'
  19650. // + opt.tdvalign + '" >' + (browser.ie ?
  19651. // domUtils.fillChar : '<br/>') + '</td>');
  19652. // //2016.11.18 2:03新增
  19653. ////////////////////////
  19654. // html
  19655. // .push('<td style="border:1px solid #000000;" width="' +
  19656. // tdWidth +
  19657. // '" vAlign="' +
  19658. // opt.tdvalign +
  19659. // '" >' +
  19660. // (browser.ie ?
  19661. // domUtils.fillChar :
  19662. // '<br/>')
  19663. /////////////////////////
  19664. var fontSize=parseFloat(window.getComputedStyle(me.document.documentElement)["fontSize"]);
  19665. html.push('<td style="border:1px solid #000000;width:' + (tdWidth/fontSize) + 'rem"'
  19666. + ' width="' + tdWidth +
  19667. '" vAlign="' +
  19668. opt.tdvalign +
  19669. '" >' +
  19670. (browser.ie ?
  19671. domUtils.fillChar :
  19672. '<br/>') + '</td>') // 20200717
  19673. // 新增
  19674. }
  19675. html.push('</tr>')
  19676. }
  19677. // 禁止指定table-width
  19678. // return '<table border="1"><tbody>' + html.join('') +
  19679. // '</tbody></table>'
  19680. return '<table style="border-collapse:collapse;"><tbody>' +
  19681. html.join('') + '</tbody></table>' // 2016.11.18
  19682. // 2:11 新增
  19683. }
  19684. if(!opt) {
  19685. opt = utils.extend({}, {
  19686. numCols: this.options.defaultCols,
  19687. numRows: this.options.defaultRows,
  19688. tdvalign: this.options.tdvalign
  19689. })
  19690. }
  19691. var me = this;
  19692. var range = this.selection.getRange(),
  19693. start = range.startContainer,
  19694. firstParentBlock = domUtils
  19695. .findParent(start, function(node) {
  19696. return domUtils.isBlockElm(node);
  19697. }, true) ||
  19698. me.body;
  19699. var defaultValue = getDefaultValue(me),
  19700. tableWidth = firstParentBlock.offsetWidth,
  19701. tdWidth = Math
  19702. .floor(tableWidth / opt.numCols -
  19703. defaultValue.tdPadding * 2 -
  19704. defaultValue.tdBorder);
  19705. // todo其他属性
  19706. !opt.tdvalign && (opt.tdvalign = me.options.tdvalign);
  19707. me.execCommand("inserthtml", createTable(opt, tdWidth));
  19708. }
  19709. };
  19710. UE.commands['insertparagraphbeforetable'] = {
  19711. queryCommandState: function() {
  19712. return getTableItemsByRange(this).cell ? 0 : -1;
  19713. },
  19714. execCommand: function() {
  19715. var table = getTableItemsByRange(this).table;
  19716. if(table) {
  19717. var p = this.document.createElement("p");
  19718. p.innerHTML = browser.ie ? '&nbsp;' : '<br />';
  19719. table.parentNode.insertBefore(p, table);
  19720. this.selection.getRange().setStart(p, 0).setCursor();
  19721. }
  19722. }
  19723. };
  19724. UE.commands['deletetable'] = {
  19725. queryCommandState: function() {
  19726. var rng = this.selection.getRange();
  19727. return domUtils.findParentByTagName(rng.startContainer,
  19728. 'table', true) ? 0 : -1;
  19729. },
  19730. execCommand: function(cmd, table) {
  19731. var rng = this.selection.getRange();
  19732. table = table ||
  19733. domUtils.findParentByTagName(rng.startContainer,
  19734. 'table', true);
  19735. if(table) {
  19736. var next = table.nextSibling;
  19737. if(!next) {
  19738. next = domUtils.createElement(this.document, 'p', {
  19739. 'innerHTML': browser.ie ?
  19740. domUtils.fillChar : '<br/>'
  19741. });
  19742. table.parentNode.insertBefore(next, table);
  19743. }
  19744. domUtils.remove(table);
  19745. rng = this.selection.getRange();
  19746. if(next.nodeType == 3) {
  19747. rng.setStartBefore(next)
  19748. } else {
  19749. rng.setStart(next, 0)
  19750. }
  19751. rng.setCursor(false, true)
  19752. this.fireEvent("tablehasdeleted")
  19753. }
  19754. }
  19755. };
  19756. UE.commands['cellalign'] = {
  19757. queryCommandState: function() {
  19758. return getSelectedArr(this).length ? 0 : -1
  19759. },
  19760. execCommand: function(cmd, align) {
  19761. var selectedTds = getSelectedArr(this);
  19762. if(selectedTds.length) {
  19763. for(var i = 0, ci; ci = selectedTds[i++];) {
  19764. ci.setAttribute('align', align);
  19765. }
  19766. }
  19767. }
  19768. };
  19769. UE.commands['cellvalign'] = {
  19770. queryCommandState: function() {
  19771. return getSelectedArr(this).length ? 0 : -1;
  19772. },
  19773. execCommand: function(cmd, valign) {
  19774. var selectedTds = getSelectedArr(this);
  19775. if(selectedTds.length) {
  19776. for(var i = 0, ci; ci = selectedTds[i++];) {
  19777. ci.setAttribute('vAlign', valign);
  19778. }
  19779. }
  19780. }
  19781. };
  19782. UE.commands['insertcaption'] = {
  19783. queryCommandState: function() {
  19784. var table = getTableItemsByRange(this).table;
  19785. if(table) {
  19786. return table.getElementsByTagName('caption').length == 0 ?
  19787. 1 :
  19788. -1;
  19789. }
  19790. return -1;
  19791. },
  19792. execCommand: function() {
  19793. var table = getTableItemsByRange(this).table;
  19794. if(table) {
  19795. var caption = this.document.createElement('caption');
  19796. caption.innerHTML = browser.ie ?
  19797. domUtils.fillChar :
  19798. '<br/>';
  19799. table.insertBefore(caption, table.firstChild);
  19800. var range = this.selection.getRange();
  19801. range.setStart(caption, 0).setCursor();
  19802. }
  19803. }
  19804. };
  19805. UE.commands['deletecaption'] = {
  19806. queryCommandState: function() {
  19807. var rng = this.selection.getRange(),
  19808. table = domUtils
  19809. .findParentByTagName(rng.startContainer, 'table');
  19810. if(table) {
  19811. return table.getElementsByTagName('caption').length == 0 ?
  19812. -1 :
  19813. 1;
  19814. }
  19815. return -1;
  19816. },
  19817. execCommand: function() {
  19818. var rng = this.selection.getRange(),
  19819. table = domUtils
  19820. .findParentByTagName(rng.startContainer, 'table');
  19821. if(table) {
  19822. domUtils.remove(table.getElementsByTagName('caption')[0]);
  19823. var range = this.selection.getRange();
  19824. range.setStart(table.rows[0].cells[0], 0).setCursor();
  19825. }
  19826. }
  19827. };
  19828. UE.commands['inserttitle'] = {
  19829. queryCommandState: function() {
  19830. var table = getTableItemsByRange(this).table;
  19831. if(table) {
  19832. var firstRow = table.rows[0];
  19833. return firstRow.cells[firstRow.cells.length - 1].tagName
  19834. .toLowerCase() != 'th' ? 0 : -1
  19835. }
  19836. return -1;
  19837. },
  19838. execCommand: function() {
  19839. var table = getTableItemsByRange(this).table;
  19840. if(table) {
  19841. getUETable(table).insertRow(0, 'th');
  19842. }
  19843. var th = table.getElementsByTagName('th')[0];
  19844. this.selection.getRange().setStart(th, 0)
  19845. .setCursor(false, true);
  19846. }
  19847. };
  19848. UE.commands['deletetitle'] = {
  19849. queryCommandState: function() {
  19850. var table = getTableItemsByRange(this).table;
  19851. if(table) {
  19852. var firstRow = table.rows[0];
  19853. return firstRow.cells[firstRow.cells.length - 1].tagName
  19854. .toLowerCase() == 'th' ? 0 : -1
  19855. }
  19856. return -1;
  19857. },
  19858. execCommand: function() {
  19859. var table = getTableItemsByRange(this).table;
  19860. if(table) {
  19861. domUtils.remove(table.rows[0])
  19862. }
  19863. var td = table.getElementsByTagName('td')[0];
  19864. this.selection.getRange().setStart(td, 0)
  19865. .setCursor(false, true);
  19866. }
  19867. };
  19868. UE.commands['inserttitlecol'] = {
  19869. queryCommandState: function() {
  19870. var table = getTableItemsByRange(this).table;
  19871. if(table) {
  19872. var lastRow = table.rows[table.rows.length - 1];
  19873. return lastRow.getElementsByTagName('th').length ? -1 : 0;
  19874. }
  19875. return -1;
  19876. },
  19877. execCommand: function(cmd) {
  19878. var table = getTableItemsByRange(this).table;
  19879. if(table) {
  19880. getUETable(table).insertCol(0, 'th');
  19881. }
  19882. resetTdWidth(table, this);
  19883. var th = table.getElementsByTagName('th')[0];
  19884. this.selection.getRange().setStart(th, 0)
  19885. .setCursor(false, true);
  19886. }
  19887. };
  19888. UE.commands['deletetitlecol'] = {
  19889. queryCommandState: function() {
  19890. var table = getTableItemsByRange(this).table;
  19891. if(table) {
  19892. var lastRow = table.rows[table.rows.length - 1];
  19893. return lastRow.getElementsByTagName('th').length ? 0 : -1;
  19894. }
  19895. return -1;
  19896. },
  19897. execCommand: function() {
  19898. var table = getTableItemsByRange(this).table;
  19899. if(table) {
  19900. for(var i = 0; i < table.rows.length; i++) {
  19901. domUtils.remove(table.rows[i].children[0])
  19902. }
  19903. }
  19904. resetTdWidth(table, this);
  19905. var td = table.getElementsByTagName('td')[0];
  19906. this.selection.getRange().setStart(td, 0)
  19907. .setCursor(false, true);
  19908. }
  19909. };
  19910. UE.commands["mergeright"] = {
  19911. queryCommandState: function(cmd) {
  19912. var tableItems = getTableItemsByRange(this),
  19913. table = tableItems.table,
  19914. cell = tableItems.cell;
  19915. if(!table || !cell)
  19916. return -1;
  19917. var ut = getUETable(table);
  19918. if(ut.selectedTds.length)
  19919. return -1;
  19920. var cellInfo = ut.getCellInfo(cell),
  19921. rightColIndex = cellInfo.colIndex +
  19922. cellInfo.colSpan;
  19923. if(rightColIndex >= ut.colsNum)
  19924. return -1; // 如果处于最右边则不能向右合并
  19925. var rightCellInfo = ut.indexTable[cellInfo.rowIndex][rightColIndex],
  19926. rightCell = table.rows[rightCellInfo.rowIndex].cells[rightCellInfo.cellIndex];
  19927. if(!rightCell || cell.tagName != rightCell.tagName)
  19928. return -1; // TH和TD不能相互合并
  19929. // 当且仅当两个Cell的开始列号和结束列号一致时能进行合并
  19930. return(rightCellInfo.rowIndex == cellInfo.rowIndex && rightCellInfo.rowSpan == cellInfo.rowSpan) ?
  19931. 0 :
  19932. -1;
  19933. },
  19934. execCommand: function(cmd) {
  19935. var rng = this.selection.getRange(),
  19936. bk = rng
  19937. .createBookmark(true);
  19938. var cell = getTableItemsByRange(this).cell,
  19939. ut = getUETable(cell);
  19940. ut.mergeRight(cell);
  19941. rng.moveToBookmark(bk).select();
  19942. }
  19943. };
  19944. UE.commands["mergedown"] = {
  19945. queryCommandState: function(cmd) {
  19946. var tableItems = getTableItemsByRange(this),
  19947. table = tableItems.table,
  19948. cell = tableItems.cell;
  19949. if(!table || !cell)
  19950. return -1;
  19951. var ut = getUETable(table);
  19952. if(ut.selectedTds.length)
  19953. return -1;
  19954. var cellInfo = ut.getCellInfo(cell),
  19955. downRowIndex = cellInfo.rowIndex +
  19956. cellInfo.rowSpan;
  19957. if(downRowIndex >= ut.rowsNum)
  19958. return -1; // 如果处于最下边则不能向下合并
  19959. var downCellInfo = ut.indexTable[downRowIndex][cellInfo.colIndex],
  19960. downCell = table.rows[downCellInfo.rowIndex].cells[downCellInfo.cellIndex];
  19961. if(!downCell || cell.tagName != downCell.tagName)
  19962. return -1; // TH和TD不能相互合并
  19963. // 当且仅当两个Cell的开始列号和结束列号一致时能进行合并
  19964. return(downCellInfo.colIndex == cellInfo.colIndex && downCellInfo.colSpan == cellInfo.colSpan) ?
  19965. 0 :
  19966. -1;
  19967. },
  19968. execCommand: function() {
  19969. var rng = this.selection.getRange(),
  19970. bk = rng
  19971. .createBookmark(true);
  19972. var cell = getTableItemsByRange(this).cell,
  19973. ut = getUETable(cell);
  19974. ut.mergeDown(cell);
  19975. rng.moveToBookmark(bk).select();
  19976. }
  19977. };
  19978. UE.commands["mergecells"] = {
  19979. queryCommandState: function() {
  19980. return getUETableBySelected(this) ? 0 : -1;
  19981. },
  19982. execCommand: function() {
  19983. var ut = getUETableBySelected(this);
  19984. if(ut && ut.selectedTds.length) {
  19985. var cell = ut.selectedTds[0];
  19986. ut.mergeRange();
  19987. var rng = this.selection.getRange();
  19988. if(domUtils.isEmptyBlock(cell)) {
  19989. rng.setStart(cell, 0).collapse(true)
  19990. } else {
  19991. rng.selectNodeContents(cell)
  19992. }
  19993. rng.select();
  19994. }
  19995. }
  19996. };
  19997. UE.commands["insertrow"] = {
  19998. queryCommandState: function() {
  19999. var tableItems = getTableItemsByRange(this),
  20000. cell = tableItems.cell;
  20001. return cell &&
  20002. (cell.tagName == "TD" || (cell.tagName == 'TH' && tableItems.tr !== tableItems.table.rows[0])) &&
  20003. getUETable(tableItems.table).rowsNum < this.options.maxRowNum ?
  20004. 0 :
  20005. -1;
  20006. },
  20007. execCommand: function() {
  20008. var rng = this.selection.getRange(),
  20009. bk = rng
  20010. .createBookmark(true);
  20011. var tableItems = getTableItemsByRange(this),
  20012. cell = tableItems.cell,
  20013. table = tableItems.table,
  20014. ut = getUETable(table),
  20015. cellInfo = ut
  20016. .getCellInfo(cell);
  20017. // ut.insertRow(!ut.selectedTds.length ?
  20018. // cellInfo.rowIndex:ut.cellsRange.beginRowIndex,'');
  20019. if(!ut.selectedTds.length) {
  20020. ut.insertRow(cellInfo.rowIndex, cell);
  20021. } else {
  20022. var range = ut.cellsRange;
  20023. for(var i = 0, len = range.endRowIndex -
  20024. range.beginRowIndex + 1; i < len; i++) {
  20025. ut.insertRow(range.beginRowIndex, cell);
  20026. }
  20027. }
  20028. rng.moveToBookmark(bk).select();
  20029. if(table.getAttribute("interlaced") === "enabled")
  20030. this.fireEvent("interlacetable", table);
  20031. }
  20032. };
  20033. // 后插入行
  20034. UE.commands["insertrownext"] = {
  20035. queryCommandState: function() {
  20036. var tableItems = getTableItemsByRange(this),
  20037. cell = tableItems.cell;
  20038. return cell &&
  20039. (cell.tagName == "TD") &&
  20040. getUETable(tableItems.table).rowsNum < this.options.maxRowNum ?
  20041. 0 :
  20042. -1;
  20043. },
  20044. execCommand: function() {
  20045. var rng = this.selection.getRange(),
  20046. bk = rng
  20047. .createBookmark(true);
  20048. var tableItems = getTableItemsByRange(this),
  20049. cell = tableItems.cell,
  20050. table = tableItems.table,
  20051. ut = getUETable(table),
  20052. cellInfo = ut
  20053. .getCellInfo(cell);
  20054. // ut.insertRow(!ut.selectedTds.length? cellInfo.rowIndex +
  20055. // cellInfo.rowSpan : ut.cellsRange.endRowIndex + 1,'');
  20056. if(!ut.selectedTds.length) {
  20057. ut.insertRow(cellInfo.rowIndex + cellInfo.rowSpan, cell);
  20058. } else {
  20059. var range = ut.cellsRange;
  20060. for(var i = 0, len = range.endRowIndex -
  20061. range.beginRowIndex + 1; i < len; i++) {
  20062. ut.insertRow(range.endRowIndex + 1, cell);
  20063. }
  20064. }
  20065. rng.moveToBookmark(bk).select();
  20066. if(table.getAttribute("interlaced") === "enabled")
  20067. this.fireEvent("interlacetable", table);
  20068. }
  20069. };
  20070. UE.commands["deleterow"] = {
  20071. queryCommandState: function() {
  20072. var tableItems = getTableItemsByRange(this);
  20073. return tableItems.cell ? 0 : -1;
  20074. },
  20075. execCommand: function() {
  20076. var cell = getTableItemsByRange(this).cell,
  20077. ut = getUETable(cell),
  20078. cellsRange = ut.cellsRange,
  20079. cellInfo = ut
  20080. .getCellInfo(cell),
  20081. preCell = ut.getVSideCell(cell),
  20082. nextCell = ut
  20083. .getVSideCell(cell, true),
  20084. rng = this.selection
  20085. .getRange();
  20086. if(utils.isEmptyObject(cellsRange)) {
  20087. ut.deleteRow(cellInfo.rowIndex);
  20088. } else {
  20089. for(var i = cellsRange.beginRowIndex; i < cellsRange.endRowIndex +
  20090. 1; i++) {
  20091. ut.deleteRow(cellsRange.beginRowIndex);
  20092. }
  20093. }
  20094. var table = ut.table;
  20095. if(!table.getElementsByTagName('td').length) {
  20096. var nextSibling = table.nextSibling;
  20097. domUtils.remove(table);
  20098. if(nextSibling) {
  20099. rng.setStart(nextSibling, 0).setCursor(false, true);
  20100. }
  20101. } else {
  20102. if(cellInfo.rowSpan == 1 ||
  20103. cellInfo.rowSpan == cellsRange.endRowIndex -
  20104. cellsRange.beginRowIndex + 1) {
  20105. if(nextCell || preCell)
  20106. rng.selectNodeContents(nextCell || preCell)
  20107. .setCursor(false, true);
  20108. } else {
  20109. var newCell = ut
  20110. .getCell(
  20111. cellInfo.rowIndex,
  20112. ut.indexTable[cellInfo.rowIndex][cellInfo.colIndex].cellIndex);
  20113. if(newCell)
  20114. rng.selectNodeContents(newCell).setCursor(false,
  20115. true);
  20116. }
  20117. }
  20118. if(table.getAttribute("interlaced") === "enabled")
  20119. this.fireEvent("interlacetable", table);
  20120. }
  20121. };
  20122. UE.commands["insertcol"] = {
  20123. queryCommandState: function(cmd) {
  20124. var tableItems = getTableItemsByRange(this),
  20125. cell = tableItems.cell;
  20126. return cell &&
  20127. (cell.tagName == "TD" || (cell.tagName == 'TH' && cell !== tableItems.tr.cells[0])) &&
  20128. getUETable(tableItems.table).colsNum < this.options.maxColNum ?
  20129. 0 :
  20130. -1;
  20131. },
  20132. execCommand: function(cmd) {
  20133. var rng = this.selection.getRange(),
  20134. bk = rng
  20135. .createBookmark(true);
  20136. if(this.queryCommandState(cmd) == -1)
  20137. return;
  20138. var cell = getTableItemsByRange(this).cell,
  20139. ut = getUETable(cell),
  20140. cellInfo = ut
  20141. .getCellInfo(cell);
  20142. // ut.insertCol(!ut.selectedTds.length ?
  20143. // cellInfo.colIndex:ut.cellsRange.beginColIndex);
  20144. if(!ut.selectedTds.length) {
  20145. ut.insertCol(cellInfo.colIndex, cell);
  20146. } else {
  20147. var range = ut.cellsRange;
  20148. for(var i = 0, len = range.endColIndex -
  20149. range.beginColIndex + 1; i < len; i++) {
  20150. ut.insertCol(range.beginColIndex, cell);
  20151. }
  20152. }
  20153. rng.moveToBookmark(bk).select(true);
  20154. }
  20155. };
  20156. UE.commands["insertcolnext"] = {
  20157. queryCommandState: function() {
  20158. var tableItems = getTableItemsByRange(this),
  20159. cell = tableItems.cell;
  20160. return cell &&
  20161. getUETable(tableItems.table).colsNum < this.options.maxColNum ?
  20162. 0 :
  20163. -1;
  20164. },
  20165. execCommand: function() {
  20166. var rng = this.selection.getRange(),
  20167. bk = rng
  20168. .createBookmark(true);
  20169. var cell = getTableItemsByRange(this).cell,
  20170. ut = getUETable(cell),
  20171. cellInfo = ut
  20172. .getCellInfo(cell);
  20173. // ut.insertCol(!ut.selectedTds.length ? cellInfo.colIndex +
  20174. // cellInfo.colSpan:ut.cellsRange.endColIndex +1);
  20175. if(!ut.selectedTds.length) {
  20176. ut.insertCol(cellInfo.colIndex + cellInfo.colSpan, cell);
  20177. } else {
  20178. var range = ut.cellsRange;
  20179. for(var i = 0, len = range.endColIndex -
  20180. range.beginColIndex + 1; i < len; i++) {
  20181. ut.insertCol(range.endColIndex + 1, cell);
  20182. }
  20183. }
  20184. rng.moveToBookmark(bk).select();
  20185. }
  20186. };
  20187. UE.commands["deletecol"] = {
  20188. queryCommandState: function() {
  20189. var tableItems = getTableItemsByRange(this);
  20190. return tableItems.cell ? 0 : -1;
  20191. },
  20192. execCommand: function() {
  20193. var cell = getTableItemsByRange(this).cell,
  20194. ut = getUETable(cell),
  20195. range = ut.cellsRange,
  20196. cellInfo = ut
  20197. .getCellInfo(cell),
  20198. preCell = ut.getHSideCell(cell),
  20199. nextCell = ut
  20200. .getHSideCell(cell, true);
  20201. if(utils.isEmptyObject(range)) {
  20202. ut.deleteCol(cellInfo.colIndex);
  20203. } else {
  20204. for(var i = range.beginColIndex; i < range.endColIndex + 1; i++) {
  20205. ut.deleteCol(range.beginColIndex);
  20206. }
  20207. }
  20208. var table = ut.table,
  20209. rng = this.selection.getRange();
  20210. if(!table.getElementsByTagName('td').length) {
  20211. var nextSibling = table.nextSibling;
  20212. domUtils.remove(table);
  20213. if(nextSibling) {
  20214. rng.setStart(nextSibling, 0).setCursor(false, true);
  20215. }
  20216. } else {
  20217. if(domUtils.inDoc(cell, this.document)) {
  20218. rng.setStart(cell, 0).setCursor(false, true);
  20219. } else {
  20220. if(nextCell && domUtils.inDoc(nextCell, this.document)) {
  20221. rng.selectNodeContents(nextCell).setCursor(false,
  20222. true);
  20223. } else {
  20224. if(preCell &&
  20225. domUtils.inDoc(preCell, this.document)) {
  20226. rng.selectNodeContents(preCell).setCursor(true,
  20227. true);
  20228. }
  20229. }
  20230. }
  20231. }
  20232. }
  20233. };
  20234. UE.commands["splittocells"] = {
  20235. queryCommandState: function() {
  20236. var tableItems = getTableItemsByRange(this),
  20237. cell = tableItems.cell;
  20238. if(!cell)
  20239. return -1;
  20240. var ut = getUETable(tableItems.table);
  20241. if(ut.selectedTds.length > 0)
  20242. return -1;
  20243. return cell && (cell.colSpan > 1 || cell.rowSpan > 1) ? 0 : -1;
  20244. },
  20245. execCommand: function() {
  20246. var rng = this.selection.getRange(),
  20247. bk = rng
  20248. .createBookmark(true);
  20249. var cell = getTableItemsByRange(this).cell,
  20250. ut = getUETable(cell);
  20251. ut.splitToCells(cell);
  20252. rng.moveToBookmark(bk).select();
  20253. }
  20254. };
  20255. UE.commands["splittorows"] = {
  20256. queryCommandState: function() {
  20257. var tableItems = getTableItemsByRange(this),
  20258. cell = tableItems.cell;
  20259. if(!cell)
  20260. return -1;
  20261. var ut = getUETable(tableItems.table);
  20262. if(ut.selectedTds.length > 0)
  20263. return -1;
  20264. return cell && cell.rowSpan > 1 ? 0 : -1;
  20265. },
  20266. execCommand: function() {
  20267. var rng = this.selection.getRange(),
  20268. bk = rng
  20269. .createBookmark(true);
  20270. var cell = getTableItemsByRange(this).cell,
  20271. ut = getUETable(cell);
  20272. ut.splitToRows(cell);
  20273. rng.moveToBookmark(bk).select();
  20274. }
  20275. };
  20276. UE.commands["splittocols"] = {
  20277. queryCommandState: function() {
  20278. var tableItems = getTableItemsByRange(this),
  20279. cell = tableItems.cell;
  20280. if(!cell)
  20281. return -1;
  20282. var ut = getUETable(tableItems.table);
  20283. if(ut.selectedTds.length > 0)
  20284. return -1;
  20285. return cell && cell.colSpan > 1 ? 0 : -1;
  20286. },
  20287. execCommand: function() {
  20288. var rng = this.selection.getRange(),
  20289. bk = rng
  20290. .createBookmark(true);
  20291. var cell = getTableItemsByRange(this).cell,
  20292. ut = getUETable(cell);
  20293. ut.splitToCols(cell);
  20294. rng.moveToBookmark(bk).select();
  20295. }
  20296. };
  20297. UE.commands["adaptbytext"] = UE.commands["adaptbywindow"] = {
  20298. queryCommandState: function() {
  20299. return getTableItemsByRange(this).table ? 0 : -1
  20300. },
  20301. execCommand: function(cmd) {
  20302. var tableItems = getTableItemsByRange(this),
  20303. table = tableItems.table;
  20304. if(table) {
  20305. if(cmd == 'adaptbywindow') {
  20306. resetTdWidth(table, this);
  20307. } else {
  20308. var cells = domUtils.getElementsByTagName(table,
  20309. "td th");
  20310. utils.each(cells, function(cell) {
  20311. cell.removeAttribute("width");
  20312. });
  20313. table.removeAttribute("width");
  20314. }
  20315. }
  20316. }
  20317. };
  20318. // 平均分配各列
  20319. UE.commands['averagedistributecol'] = {
  20320. queryCommandState: function() {
  20321. var ut = getUETableBySelected(this);
  20322. if(!ut)
  20323. return -1;
  20324. return ut.isFullRow() || ut.isFullCol() ? 0 : -1;
  20325. },
  20326. execCommand: function(cmd) {
  20327. var me = this,
  20328. ut = getUETableBySelected(me);
  20329. function getAverageWidth() {
  20330. var tb = ut.table,
  20331. averageWidth, sumWidth = 0,
  20332. colsNum = 0,
  20333. tbAttr = getDefaultValue(
  20334. me, tb);
  20335. if(ut.isFullRow()) {
  20336. sumWidth = tb.offsetWidth;
  20337. colsNum = ut.colsNum;
  20338. } else {
  20339. var begin = ut.cellsRange.beginColIndex,
  20340. end = ut.cellsRange.endColIndex,
  20341. node;
  20342. for(var i = begin; i <= end;) {
  20343. node = ut.selectedTds[i];
  20344. sumWidth += node.offsetWidth;
  20345. i += node.colSpan;
  20346. colsNum += 1;
  20347. }
  20348. }
  20349. averageWidth = Math.ceil(sumWidth / colsNum) -
  20350. tbAttr.tdBorder * 2 - tbAttr.tdPadding * 2;
  20351. return averageWidth;
  20352. }
  20353. function setAverageWidth(averageWidth) {
  20354. utils.each(domUtils.getElementsByTagName(ut.table, "th"),
  20355. function(node) {
  20356. node.setAttribute("width", "");
  20357. });
  20358. var cells = ut.isFullRow() ? domUtils.getElementsByTagName(
  20359. ut.table, "td") : ut.selectedTds;
  20360. utils.each(cells, function(node) {
  20361. if(node.colSpan == 1) {
  20362. node.setAttribute("width", averageWidth);
  20363. }
  20364. });
  20365. }
  20366. if(ut && ut.selectedTds.length) {
  20367. setAverageWidth(getAverageWidth());
  20368. }
  20369. }
  20370. };
  20371. // 平均分配各行
  20372. UE.commands['averagedistributerow'] = {
  20373. queryCommandState: function() {
  20374. var ut = getUETableBySelected(this);
  20375. if(!ut)
  20376. return -1;
  20377. if(ut.selectedTds && /th/ig.test(ut.selectedTds[0].tagName))
  20378. return -1;
  20379. return ut.isFullRow() || ut.isFullCol() ? 0 : -1;
  20380. },
  20381. execCommand: function(cmd) {
  20382. var me = this,
  20383. ut = getUETableBySelected(me);
  20384. function getAverageHeight() {
  20385. var averageHeight, rowNum, sumHeight = 0,
  20386. tb = ut.table,
  20387. tbAttr = getDefaultValue(
  20388. me, tb),
  20389. tdpadding = parseInt(domUtils
  20390. .getComputedStyle(tb.getElementsByTagName('td')[0],
  20391. "padding-top"));
  20392. if(ut.isFullCol()) {
  20393. var captionArr = domUtils.getElementsByTagName(tb,
  20394. "caption"),
  20395. thArr = domUtils
  20396. .getElementsByTagName(tb, "th"),
  20397. captionHeight, thHeight;
  20398. if(captionArr.length > 0) {
  20399. captionHeight = captionArr[0].offsetHeight;
  20400. }
  20401. if(thArr.length > 0) {
  20402. thHeight = thArr[0].offsetHeight;
  20403. }
  20404. sumHeight = tb.offsetHeight - (captionHeight || 0) -
  20405. (thHeight || 0);
  20406. rowNum = thArr.length == 0 ?
  20407. ut.rowsNum :
  20408. (ut.rowsNum - 1);
  20409. } else {
  20410. var begin = ut.cellsRange.beginRowIndex,
  20411. end = ut.cellsRange.endRowIndex,
  20412. count = 0,
  20413. trs = domUtils
  20414. .getElementsByTagName(tb, "tr");
  20415. for(var i = begin; i <= end; i++) {
  20416. sumHeight += trs[i].offsetHeight;
  20417. count += 1;
  20418. }
  20419. rowNum = count;
  20420. }
  20421. // ie8下是混杂模式
  20422. if(browser.ie && browser.version < 9) {
  20423. averageHeight = Math.ceil(sumHeight / rowNum);
  20424. } else {
  20425. averageHeight = Math.ceil(sumHeight / rowNum) -
  20426. tbAttr.tdBorder * 2 - tdpadding * 2;
  20427. }
  20428. return averageHeight;
  20429. }
  20430. function setAverageHeight(averageHeight) {
  20431. var cells = ut.isFullCol() ? domUtils.getElementsByTagName(
  20432. ut.table, "td") : ut.selectedTds;
  20433. utils.each(cells, function(node) {
  20434. if(node.rowSpan == 1) {
  20435. node.setAttribute("height", averageHeight);
  20436. }
  20437. });
  20438. }
  20439. if(ut && ut.selectedTds.length) {
  20440. setAverageHeight(getAverageHeight());
  20441. }
  20442. }
  20443. };
  20444. // 单元格对齐方式
  20445. UE.commands['cellalignment'] = {
  20446. queryCommandState: function() {
  20447. return getTableItemsByRange(this).table ? 0 : -1
  20448. },
  20449. execCommand: function(cmd, data) {
  20450. var me = this,
  20451. ut = getUETableBySelected(me);
  20452. if(!ut) {
  20453. var start = me.selection.getStart(),
  20454. cell = start &&
  20455. domUtils.findParentByTagName(start, ["td", "th",
  20456. "caption"
  20457. ], true);
  20458. if(!/caption/ig.test(cell.tagName)) {
  20459. domUtils.setAttributes(cell, data);
  20460. } else {
  20461. cell.style.textAlign = data.align;
  20462. cell.style.verticalAlign = data.vAlign;
  20463. }
  20464. me.selection.getRange().setCursor(true);
  20465. } else {
  20466. utils.each(ut.selectedTds, function(cell) {
  20467. domUtils.setAttributes(cell, data);
  20468. });
  20469. }
  20470. },
  20471. /**
  20472. * 查询当前点击的单元格的对齐状态, 如果当前已经选择了多个单元格, 则会返回所有单元格经过统一协调过后的状态
  20473. *
  20474. * @see UE.UETable.getTableCellAlignState
  20475. */
  20476. queryCommandValue: function(cmd) {
  20477. var activeMenuCell = getTableItemsByRange(this).cell;
  20478. if(!activeMenuCell) {
  20479. activeMenuCell = getSelectedArr(this)[0];
  20480. }
  20481. if(!activeMenuCell) {
  20482. return null;
  20483. } else {
  20484. // 获取同时选中的其他单元格
  20485. var cells = UE.UETable.getUETable(activeMenuCell).selectedTds;
  20486. !cells.length && (cells = activeMenuCell);
  20487. return UE.UETable.getTableCellAlignState(cells);
  20488. }
  20489. }
  20490. };
  20491. // 表格对齐方式
  20492. UE.commands['tablealignment'] = {
  20493. queryCommandState: function() {
  20494. if(browser.ie && browser.version < 8) {
  20495. return -1;
  20496. }
  20497. return getTableItemsByRange(this).table ? 0 : -1
  20498. },
  20499. execCommand: function(cmd, value) {
  20500. var me = this,
  20501. start = me.selection.getStart(),
  20502. table = start &&
  20503. domUtils.findParentByTagName(start, ["table"], true);
  20504. if(table) {
  20505. table.setAttribute("align", value);
  20506. }
  20507. }
  20508. };
  20509. // 表格属性
  20510. UE.commands['edittable'] = {
  20511. queryCommandState: function() {
  20512. return getTableItemsByRange(this).table ? 0 : -1
  20513. },
  20514. execCommand: function(cmd, color) {
  20515. var rng = this.selection.getRange(),
  20516. table = domUtils
  20517. .findParentByTagName(rng.startContainer, 'table');
  20518. if(table) {
  20519. var arr = domUtils.getElementsByTagName(table, "td")
  20520. .concat(
  20521. domUtils.getElementsByTagName(table, "th"),
  20522. domUtils.getElementsByTagName(table,
  20523. "caption"));
  20524. utils.each(arr, function(node) {
  20525. node.style.borderColor = color;
  20526. });
  20527. }
  20528. }
  20529. };
  20530. // 单元格属性
  20531. UE.commands['edittd'] = {
  20532. queryCommandState: function() {
  20533. return getTableItemsByRange(this).table ? 0 : -1
  20534. },
  20535. execCommand: function(cmd, bkColor) {
  20536. var me = this,
  20537. ut = getUETableBySelected(me);
  20538. if(!ut) {
  20539. var start = me.selection.getStart(),
  20540. cell = start &&
  20541. domUtils.findParentByTagName(start, ["td", "th",
  20542. "caption"
  20543. ], true);
  20544. if(cell) {
  20545. cell.style.backgroundColor = bkColor;
  20546. }
  20547. } else {
  20548. utils.each(ut.selectedTds, function(cell) {
  20549. cell.style.backgroundColor = bkColor;
  20550. });
  20551. }
  20552. }
  20553. };
  20554. UE.commands["settablebackground"] = {
  20555. queryCommandState: function() {
  20556. return getSelectedArr(this).length > 1 ? 0 : -1;
  20557. },
  20558. execCommand: function(cmd, value) {
  20559. var cells, ut;
  20560. cells = getSelectedArr(this);
  20561. ut = getUETable(cells[0]);
  20562. ut.setBackground(cells, value);
  20563. }
  20564. };
  20565. UE.commands["cleartablebackground"] = {
  20566. queryCommandState: function() {
  20567. var cells = getSelectedArr(this);
  20568. if(!cells.length)
  20569. return -1;
  20570. for(var i = 0, cell; cell = cells[i++];) {
  20571. if(cell.style.backgroundColor !== "")
  20572. return 0;
  20573. }
  20574. return -1;
  20575. },
  20576. execCommand: function() {
  20577. var cells = getSelectedArr(this),
  20578. ut = getUETable(cells[0]);
  20579. ut.removeBackground(cells);
  20580. }
  20581. };
  20582. UE.commands["interlacetable"] = UE.commands["uninterlacetable"] = {
  20583. queryCommandState: function(cmd) {
  20584. var table = getTableItemsByRange(this).table;
  20585. if(!table)
  20586. return -1;
  20587. var interlaced = table.getAttribute("interlaced");
  20588. if(cmd == "interlacetable") {
  20589. // TODO 待定
  20590. // 是否需要待定,如果设置,则命令只能单次执行成功,但反射具备toggle效果;否则可以覆盖前次命令,但反射将不存在toggle效果
  20591. return(interlaced === "enabled") ? -1 : 0;
  20592. } else {
  20593. return(!interlaced || interlaced === "disabled") ? -1 : 0;
  20594. }
  20595. },
  20596. execCommand: function(cmd, classList) {
  20597. var table = getTableItemsByRange(this).table;
  20598. if(cmd == "interlacetable") {
  20599. table.setAttribute("interlaced", "enabled");
  20600. this.fireEvent("interlacetable", table, classList);
  20601. } else {
  20602. table.setAttribute("interlaced", "disabled");
  20603. this.fireEvent("uninterlacetable", table);
  20604. }
  20605. }
  20606. };
  20607. UE.commands["setbordervisible"] = {
  20608. queryCommandState: function(cmd) {
  20609. var table = getTableItemsByRange(this).table;
  20610. if(!table)
  20611. return -1;
  20612. return 0;
  20613. },
  20614. execCommand: function() {
  20615. var table = getTableItemsByRange(this).table;
  20616. utils.each(domUtils.getElementsByTagName(table, 'td'),
  20617. function(td) {
  20618. td.style.borderWidth = '1px';
  20619. td.style.borderStyle = 'solid';
  20620. })
  20621. }
  20622. };
  20623. function resetTdWidth(table, editor) {
  20624. var tds = domUtils.getElementsByTagName(table, 'td th');
  20625. utils.each(tds, function(td) {
  20626. td.removeAttribute("width");
  20627. });
  20628. table.setAttribute('width', getTableWidth(editor, true,
  20629. getDefaultValue(editor, table)));
  20630. var tdsWidths = [];
  20631. setTimeout(function() {
  20632. utils.each(tds, function(td) {
  20633. (td.colSpan == 1) && tdsWidths.push(td.offsetWidth)
  20634. })
  20635. utils.each(tds, function(td, i) {
  20636. (td.colSpan == 1) &&
  20637. td.setAttribute("width", tdsWidths[i] + "");
  20638. })
  20639. }, 0);
  20640. }
  20641. function getTableWidth(editor, needIEHack, defaultValue) {
  20642. var body = editor.body;
  20643. return body.offsetWidth -
  20644. (needIEHack ? parseInt(domUtils.getComputedStyle(body,
  20645. 'margin-left'), 10) *
  20646. 2 : 0) - defaultValue.tableBorder * 2 -
  20647. (editor.options.offsetWidth || 0);
  20648. }
  20649. function getSelectedArr(editor) {
  20650. var cell = getTableItemsByRange(editor).cell;
  20651. if(cell) {
  20652. var ut = getUETable(cell);
  20653. return ut.selectedTds.length ? ut.selectedTds : [cell];
  20654. } else {
  20655. return [];
  20656. }
  20657. }
  20658. })();
  20659. // plugins/table.action.js
  20660. /**
  20661. * Created with JetBrains PhpStorm. User: taoqili Date: 12-10-12 Time:
  20662. * 上午10:05 To change this template use File | Settings | File Templates.
  20663. */
  20664. UE.plugins['table'] = function() {
  20665. var me = this,
  20666. tabTimer = null,
  20667. // 拖动计时器
  20668. tableDragTimer = null,
  20669. // 双击计时器
  20670. tableResizeTimer = null,
  20671. // 单元格最小宽度
  20672. cellMinWidth = 5,
  20673. isInResizeBuffer = false,
  20674. // 单元格边框大小
  20675. cellBorderWidth = 5,
  20676. // 鼠标偏移距离
  20677. offsetOfTableCell = 10,
  20678. // 记录在有限时间内的点击状态, 共有3个取值, 0, 1, 2。 0代表未初始化, 1代表单击了1次,2代表2次
  20679. singleClickState = 0,
  20680. userActionStatus = null,
  20681. // 双击允许的时间范围
  20682. dblclickTime = 360,
  20683. UT = UE.UETable,
  20684. getUETable = function(tdOrTable) {
  20685. return UT.getUETable(tdOrTable);
  20686. },
  20687. getUETableBySelected = function(editor) {
  20688. return UT.getUETableBySelected(editor);
  20689. },
  20690. getDefaultValue = function(editor, table) {
  20691. return UT.getDefaultValue(editor, table);
  20692. },
  20693. removeSelectedClass = function(cells) {
  20694. return UT.removeSelectedClass(cells);
  20695. };
  20696. function showError(e) {
  20697. // throw e;
  20698. }
  20699. me.ready(function() {
  20700. var me = this;
  20701. var orgGetText = me.selection.getText;
  20702. me.selection.getText = function() {
  20703. var table = getUETableBySelected(me);
  20704. if(table) {
  20705. var str = '';
  20706. utils.each(table.selectedTds, function(td) {
  20707. str += td[browser.ie ? 'innerText' : 'textContent'];
  20708. })
  20709. return str;
  20710. } else {
  20711. return orgGetText.call(me.selection)
  20712. }
  20713. }
  20714. })
  20715. // 处理拖动及框选相关方法
  20716. var startTd = null, // 鼠标按下时的锚点td
  20717. currentTd = null, // 当前鼠标经过时的td
  20718. onDrag = "", // 指示当前拖动状态,其值可为"","h","v"
  20719. // ,分别表示未拖动状态,横向拖动状态,纵向拖动状态,用于鼠标移动过程中的判断
  20720. onBorder = false, // 检测鼠标按下时是否处在单元格边缘位置
  20721. dragButton = null,
  20722. dragOver = false,
  20723. dragLine = null, // 模拟的拖动线
  20724. dragTd = null; // 发生拖动的目标td
  20725. var mousedown = false,
  20726. // todo 判断混乱模式
  20727. needIEHack = true;
  20728. me.setOpt({
  20729. 'maxColNum': 20,
  20730. 'maxRowNum': 100,
  20731. 'defaultCols': 5,
  20732. 'defaultRows': 5,
  20733. 'tdvalign': 'top',
  20734. 'cursorpath': me.options.UEDITOR_HOME_URL +
  20735. "themes/default/images/cursor_",
  20736. 'tableDragable': false,
  20737. 'classList': ["ue-table-interlace-color-single",
  20738. "ue-table-interlace-color-double"
  20739. ]
  20740. });
  20741. me.getUETable = getUETable;
  20742. var commands = {
  20743. 'deletetable': 1,
  20744. 'inserttable': 1,
  20745. 'cellvalign': 1,
  20746. 'insertcaption': 1,
  20747. 'deletecaption': 1,
  20748. 'inserttitle': 1,
  20749. 'deletetitle': 1,
  20750. "mergeright": 1,
  20751. "mergedown": 1,
  20752. "mergecells": 1,
  20753. "insertrow": 1,
  20754. "insertrownext": 1,
  20755. "deleterow": 1,
  20756. "insertcol": 1,
  20757. "insertcolnext": 1,
  20758. "deletecol": 1,
  20759. "splittocells": 1,
  20760. "splittorows": 1,
  20761. "splittocols": 1,
  20762. "adaptbytext": 1,
  20763. "adaptbywindow": 1,
  20764. "adaptbycustomer": 1,
  20765. "insertparagraph": 1,
  20766. "insertparagraphbeforetable": 1,
  20767. "averagedistributecol": 1,
  20768. "averagedistributerow": 1
  20769. };
  20770. me.ready(function() {
  20771. utils
  20772. .cssRule(
  20773. 'table',
  20774. // 选中的td上的样式
  20775. '.selectTdClass{background-color:#edf5fa !important}' +
  20776. 'table.noBorderTable td,table.noBorderTable th,table.noBorderTable caption{border:1px dashed #ddd !important}' +
  20777. // 插入的表格的默认样式
  20778. 'table{margin-bottom:10px;border-collapse:collapse;display:table;}' +
  20779. 'td,th{padding: 5px 10px;border: 1px solid #DDD;}' +
  20780. 'caption{border:1px dashed #DDD;border-bottom:0;padding:3px;text-align:center;}' +
  20781. 'th{border-top:1px solid #BBB;background-color:#F7F7F7;}' +
  20782. 'table tr.firstRow th{border-top-width:2px;}' +
  20783. '.ue-table-interlace-color-single{ background-color: #fcfcfc; } .ue-table-interlace-color-double{ background-color: #f7faff; }' +
  20784. 'td p{margin:0;padding:0;}', me.document);
  20785. var tableCopyList, isFullCol, isFullRow;
  20786. // 注册del/backspace事件
  20787. me.addListener('keydown', function(cmd, evt) {
  20788. var me = this;
  20789. var keyCode = evt.keyCode || evt.which;
  20790. if(keyCode == 8) {
  20791. var ut = getUETableBySelected(me);
  20792. if(ut && ut.selectedTds.length) {
  20793. if(ut.isFullCol()) {
  20794. me.execCommand('deletecol')
  20795. } else if(ut.isFullRow()) {
  20796. me.execCommand('deleterow')
  20797. } else {
  20798. me.fireEvent('delcells');
  20799. }
  20800. domUtils.preventDefault(evt);
  20801. }
  20802. var caption = domUtils.findParentByTagName(me.selection
  20803. .getStart(), 'caption', true),
  20804. range = me.selection
  20805. .getRange();
  20806. if(range.collapsed && caption && isEmptyBlock(caption)) {
  20807. me.fireEvent('saveScene');
  20808. var table = caption.parentNode;
  20809. domUtils.remove(caption);
  20810. if(table) {
  20811. range.setStart(table.rows[0].cells[0], 0)
  20812. .setCursor(false, true);
  20813. }
  20814. me.fireEvent('saveScene');
  20815. }
  20816. }
  20817. if(keyCode == 46) {
  20818. ut = getUETableBySelected(me);
  20819. if(ut) {
  20820. me.fireEvent('saveScene');
  20821. for(var i = 0, ci; ci = ut.selectedTds[i++];) {
  20822. domUtils.fillNode(me.document, ci)
  20823. }
  20824. me.fireEvent('saveScene');
  20825. domUtils.preventDefault(evt);
  20826. }
  20827. }
  20828. if(keyCode == 13) {
  20829. var rng = me.selection.getRange(),
  20830. caption = domUtils
  20831. .findParentByTagName(rng.startContainer, 'caption',
  20832. true);
  20833. if(caption) {
  20834. var table = domUtils.findParentByTagName(caption,
  20835. 'table');
  20836. if(!rng.collapsed) {
  20837. rng.deleteContents();
  20838. me.fireEvent('saveScene');
  20839. } else {
  20840. if(caption) {
  20841. rng.setStart(table.rows[0].cells[0], 0)
  20842. .setCursor(false, true);
  20843. }
  20844. }
  20845. domUtils.preventDefault(evt);
  20846. return;
  20847. }
  20848. if(rng.collapsed) {
  20849. var table = domUtils.findParentByTagName(
  20850. rng.startContainer, 'table');
  20851. if(table) {
  20852. var cell = table.rows[0].cells[0],
  20853. start = domUtils
  20854. .findParentByTagName(me.selection
  20855. .getStart(), ['td', 'th'], true),
  20856. preNode = table.previousSibling;
  20857. if(cell === start &&
  20858. (!preNode || preNode.nodeType == 1 &&
  20859. preNode.tagName == 'TABLE') &&
  20860. domUtils.isStartInblock(rng)) {
  20861. var first = domUtils.findParent(me.selection
  20862. .getStart(),
  20863. function(n) {
  20864. return domUtils.isBlockElm(n)
  20865. }, true);
  20866. if(first &&
  20867. (/t(h|d)/i.test(first.tagName) || first === start.firstChild)) {
  20868. me
  20869. .execCommand('insertparagraphbeforetable');
  20870. domUtils.preventDefault(evt);
  20871. }
  20872. }
  20873. }
  20874. }
  20875. }
  20876. if((evt.ctrlKey || evt.metaKey) && evt.keyCode == '67') {
  20877. tableCopyList = null;
  20878. var ut = getUETableBySelected(me);
  20879. if(ut) {
  20880. var tds = ut.selectedTds;
  20881. isFullCol = ut.isFullCol();
  20882. isFullRow = ut.isFullRow();
  20883. tableCopyList = [
  20884. [ut.cloneCell(tds[0], null, true)]
  20885. ];
  20886. for(var i = 1, ci; ci = tds[i]; i++) {
  20887. if(ci.parentNode !== tds[i - 1].parentNode) {
  20888. tableCopyList.push([ut
  20889. .cloneCell(ci, null, true)
  20890. ]);
  20891. } else {
  20892. tableCopyList[tableCopyList.length - 1].push(ut
  20893. .cloneCell(ci, null, true));
  20894. }
  20895. }
  20896. }
  20897. }
  20898. });
  20899. me.addListener("tablehasdeleted", function() {
  20900. toggleDraggableState(this, false, "", null);
  20901. if(dragButton)
  20902. domUtils.remove(dragButton);
  20903. });
  20904. me.addListener('beforepaste', function(cmd, html) {
  20905. var me = this;
  20906. var rng = me.selection.getRange();
  20907. if(domUtils.findParentByTagName(rng.startContainer, 'caption',
  20908. true)) {
  20909. var div = me.document.createElement("div");
  20910. div.innerHTML = html.html;
  20911. // trace:3729
  20912. html.html = div[browser.ie9below ?
  20913. 'innerText' :
  20914. 'textContent'];
  20915. return;
  20916. }
  20917. var table = getUETableBySelected(me);
  20918. if(tableCopyList) {
  20919. me.fireEvent('saveScene');
  20920. var rng = me.selection.getRange();
  20921. var td = domUtils.findParentByTagName(rng.startContainer, [
  20922. 'td', 'th'
  20923. ], true),
  20924. tmpNode, preNode;
  20925. if(td) {
  20926. var ut = getUETable(td);
  20927. if(isFullRow) {
  20928. var rowIndex = ut.getCellInfo(td).rowIndex;
  20929. if(td.tagName == 'TH') {
  20930. rowIndex++;
  20931. }
  20932. for(var i = 0, ci; ci = tableCopyList[i++];) {
  20933. var tr = ut.insertRow(rowIndex++, "td");
  20934. for(var j = 0, cj; cj = ci[j]; j++) {
  20935. var cell = tr.cells[j];
  20936. if(!cell) {
  20937. cell = tr.insertCell(j)
  20938. }
  20939. cell.innerHTML = cj.innerHTML;
  20940. cj.getAttribute('width') &&
  20941. cell.setAttribute('width', cj
  20942. .getAttribute('width'));
  20943. cj.getAttribute('vAlign') &&
  20944. cell.setAttribute('vAlign', cj
  20945. .getAttribute('vAlign'));
  20946. cj.getAttribute('align') &&
  20947. cell.setAttribute('align', cj
  20948. .getAttribute('align'));
  20949. cj.style.cssText &&
  20950. (cell.style.cssText = cj.style.cssText)
  20951. }
  20952. for(var j = 0, cj; cj = tr.cells[j]; j++) {
  20953. if(!ci[j])
  20954. break;
  20955. cj.innerHTML = ci[j].innerHTML;
  20956. ci[j].getAttribute('width') &&
  20957. cj.setAttribute('width', ci[j]
  20958. .getAttribute('width'));
  20959. ci[j].getAttribute('vAlign') &&
  20960. cj.setAttribute('vAlign', ci[j]
  20961. .getAttribute('vAlign'));
  20962. ci[j].getAttribute('align') &&
  20963. cj.setAttribute('align', ci[j]
  20964. .getAttribute('align'));
  20965. ci[j].style.cssText &&
  20966. (cj.style.cssText = ci[j].style.cssText)
  20967. }
  20968. }
  20969. } else {
  20970. if(isFullCol) {
  20971. cellInfo = ut.getCellInfo(td);
  20972. var maxColNum = 0;
  20973. for(var j = 0, ci = tableCopyList[0], cj; cj = ci[j++];) {
  20974. maxColNum += cj.colSpan || 1;
  20975. }
  20976. me.__hasEnterExecCommand = true;
  20977. for(i = 0; i < maxColNum; i++) {
  20978. me.execCommand('insertcol');
  20979. }
  20980. me.__hasEnterExecCommand = false;
  20981. td = ut.table.rows[0].cells[cellInfo.cellIndex];
  20982. if(td.tagName == 'TH') {
  20983. td = ut.table.rows[1].cells[cellInfo.cellIndex];
  20984. }
  20985. }
  20986. for(var i = 0, ci; ci = tableCopyList[i++];) {
  20987. tmpNode = td;
  20988. for(var j = 0, cj; cj = ci[j++];) {
  20989. if(td) {
  20990. td.innerHTML = cj.innerHTML;
  20991. // todo 定制处理
  20992. cj.getAttribute('width') &&
  20993. td.setAttribute('width', cj
  20994. .getAttribute('width'));
  20995. cj.getAttribute('vAlign') &&
  20996. td
  20997. .setAttribute(
  20998. 'vAlign',
  20999. cj
  21000. .getAttribute('vAlign'));
  21001. cj.getAttribute('align') &&
  21002. td.setAttribute('align', cj
  21003. .getAttribute('align'));
  21004. cj.style.cssText &&
  21005. (td.style.cssText = cj.style.cssText);
  21006. preNode = td;
  21007. td = td.nextSibling;
  21008. } else {
  21009. var cloneTd = cj.cloneNode(true);
  21010. domUtils.removeAttributes(cloneTd, [
  21011. 'class', 'rowSpan', 'colSpan'
  21012. ]);
  21013. preNode.parentNode.appendChild(cloneTd)
  21014. }
  21015. }
  21016. td = ut.getNextCell(tmpNode, true, true);
  21017. if(!tableCopyList[i])
  21018. break;
  21019. if(!td) {
  21020. var cellInfo = ut.getCellInfo(tmpNode);
  21021. ut.table.insertRow(ut.table.rows.length);
  21022. ut.update();
  21023. td = ut.getVSideCell(tmpNode, true);
  21024. }
  21025. }
  21026. }
  21027. ut.update();
  21028. } else {
  21029. table = me.document.createElement('table');
  21030. for(var i = 0, ci; ci = tableCopyList[i++];) {
  21031. var tr = table.insertRow(table.rows.length);
  21032. for(var j = 0, cj; cj = ci[j++];) {
  21033. cloneTd = UT.cloneCell(cj, null, true);
  21034. domUtils.removeAttributes(cloneTd, ['class']);
  21035. tr.appendChild(cloneTd)
  21036. }
  21037. if(j == 2 && cloneTd.rowSpan > 1) {
  21038. cloneTd.rowSpan = 1;
  21039. }
  21040. }
  21041. var defaultValue = getDefaultValue(me),
  21042. width = me.body.offsetWidth -
  21043. (needIEHack ? parseInt(domUtils
  21044. .getComputedStyle(me.body,
  21045. 'margin-left'), 10) *
  21046. 2 : 0) -
  21047. defaultValue.tableBorder *
  21048. 2 -
  21049. (me.options.offsetWidth || 0);
  21050. me
  21051. .execCommand('insertHTML', '<table ' +
  21052. (isFullCol && isFullRow ? 'width="' +
  21053. width + '"' : '') +
  21054. '>' +
  21055. table.innerHTML.replace(/>\s*</g,
  21056. '><').replace(/\bth\b/gi, "td") +
  21057. '</table>')
  21058. }
  21059. me.fireEvent('contentchange');
  21060. me.fireEvent('saveScene');
  21061. html.html = '';
  21062. return true;
  21063. } else {
  21064. var div = me.document.createElement("div"),
  21065. tables;
  21066. div.innerHTML = html.html;
  21067. tables = div.getElementsByTagName("table");
  21068. if(domUtils.findParentByTagName(me.selection.getStart(),
  21069. 'table')) {
  21070. utils.each(tables, function(t) {
  21071. domUtils.remove(t)
  21072. });
  21073. if(domUtils.findParentByTagName(me.selection
  21074. .getStart(), 'caption', true)) {
  21075. div.innerHTML = div[browser.ie ?
  21076. 'innerText' :
  21077. 'textContent'];
  21078. }
  21079. } else {
  21080. utils.each(tables, function(table) {
  21081. removeStyleSize(table, true);
  21082. domUtils.removeAttributes(table, ['style', 'border']);
  21083. utils.each(domUtils.getElementsByTagName(table,
  21084. "td"), function(td) {
  21085. if(isEmptyBlock(td)) {
  21086. domUtils.fillNode(me.document, td);
  21087. }
  21088. removeStyleSize(td, true);
  21089. // domUtils.removeAttributes(td, ['style'])
  21090. });
  21091. });
  21092. }
  21093. html.html = div.innerHTML;
  21094. }
  21095. });
  21096. me.addListener('afterpaste', function() {
  21097. utils.each(domUtils.getElementsByTagName(me.body, "table"),
  21098. function(table) {
  21099. if(table.offsetWidth > me.body.offsetWidth) {
  21100. var defaultValue = getDefaultValue(me, table);
  21101. table.style.width = me.body.offsetWidth -
  21102. (needIEHack ? parseInt(domUtils
  21103. .getComputedStyle(me.body,
  21104. 'margin-left'), 10) *
  21105. 2 : 0) -
  21106. defaultValue.tableBorder * 2 -
  21107. (me.options.offsetWidth || 0) + 'px'
  21108. }
  21109. })
  21110. });
  21111. me.addListener('blur', function() {
  21112. tableCopyList = null;
  21113. });
  21114. var timer;
  21115. me.addListener('keydown', function() {
  21116. clearTimeout(timer);
  21117. timer = setTimeout(function() {
  21118. var rng = me.selection.getRange(),
  21119. cell = domUtils
  21120. .findParentByTagName(rng.startContainer, ['th',
  21121. 'td'
  21122. ], true);
  21123. if(cell) {
  21124. var table = cell.parentNode.parentNode.parentNode;
  21125. if(table.offsetWidth > table.getAttribute("width")) {
  21126. cell.style.wordBreak = "break-all";
  21127. }
  21128. }
  21129. }, 100);
  21130. });
  21131. me.addListener("selectionchange", function() {
  21132. toggleDraggableState(me, false, "", null);
  21133. });
  21134. // 内容变化时触发索引更新
  21135. // todo 可否考虑标记检测,如果不涉及表格的变化就不进行索引重建和更新
  21136. me.addListener("contentchange", function() {
  21137. var me = this;
  21138. // 尽可能排除一些不需要更新的状况
  21139. hideDragLine(me);
  21140. if(getUETableBySelected(me))
  21141. return;
  21142. var rng = me.selection.getRange();
  21143. var start = rng.startContainer;
  21144. start = domUtils.findParentByTagName(start, ['td', 'th'], true);
  21145. utils.each(domUtils.getElementsByTagName(me.document, 'table'),
  21146. function(table) {
  21147. if(me.fireEvent("excludetable", table) === true)
  21148. return;
  21149. table.ueTable = new UT(table);
  21150. // trace:3742
  21151. // utils.each(domUtils.getElementsByTagName(me.document,
  21152. // 'td'), function (td) {
  21153. //
  21154. // if (domUtils.isEmptyBlock(td) && td !== start) {
  21155. // domUtils.fillNode(me.document, td);
  21156. // if (browser.ie && browser.version == 6) {
  21157. // td.innerHTML = '&nbsp;'
  21158. // }
  21159. // }
  21160. // });
  21161. // utils.each(domUtils.getElementsByTagName(me.document,
  21162. // 'th'), function (th) {
  21163. // if (domUtils.isEmptyBlock(th) && th !== start) {
  21164. // domUtils.fillNode(me.document, th);
  21165. // if (browser.ie && browser.version == 6) {
  21166. // th.innerHTML = '&nbsp;'
  21167. // }
  21168. // }
  21169. // });
  21170. table.onmouseover = function() {
  21171. me.fireEvent('tablemouseover', table);
  21172. };
  21173. table.onmousemove = function() {
  21174. me.fireEvent('tablemousemove', table);
  21175. me.options.tableDragable &&
  21176. toggleDragButton(true, this, me);
  21177. utils.defer(function() {
  21178. me.fireEvent('contentchange', 50)
  21179. }, true)
  21180. };
  21181. table.onmouseout = function() {
  21182. me.fireEvent('tablemouseout', table);
  21183. toggleDraggableState(me, false, "", null);
  21184. hideDragLine(me);
  21185. };
  21186. table.onclick = function(evt) {
  21187. evt = me.window.event || evt;
  21188. var target = getParentTdOrTh(evt.target ||
  21189. evt.srcElement);
  21190. if(!target)
  21191. return;
  21192. var ut = getUETable(target),
  21193. table = ut.table,
  21194. cellInfo = ut
  21195. .getCellInfo(target),
  21196. cellsRange, rng = me.selection
  21197. .getRange();
  21198. // if ("topLeft" == inPosition(table,
  21199. // mouseCoords(evt)))
  21200. // {
  21201. // cellsRange =
  21202. // ut.getCellsRange(ut.table.rows[0].cells[0],
  21203. // ut.getLastCell());
  21204. // ut.setSelected(cellsRange);
  21205. // return;
  21206. // }
  21207. // if ("bottomRight" == inPosition(table,
  21208. // mouseCoords(evt))) {
  21209. //
  21210. // return;
  21211. // }
  21212. if(inTableSide(table, target, evt, true)) {
  21213. var endTdCol = ut
  21214. .getCell(
  21215. ut.indexTable[ut.rowsNum -
  21216. 1][cellInfo.colIndex].rowIndex,
  21217. ut.indexTable[ut.rowsNum -
  21218. 1][cellInfo.colIndex].cellIndex);
  21219. if(evt.shiftKey && ut.selectedTds.length) {
  21220. if(ut.selectedTds[0] !== endTdCol) {
  21221. cellsRange = ut
  21222. .getCellsRange(
  21223. ut.selectedTds[0],
  21224. endTdCol);
  21225. ut.setSelected(cellsRange);
  21226. } else {
  21227. rng
  21228. &&
  21229. rng
  21230. .selectNodeContents(endTdCol)
  21231. .select();
  21232. }
  21233. } else {
  21234. if(target !== endTdCol) {
  21235. cellsRange = ut.getCellsRange(
  21236. target, endTdCol);
  21237. ut.setSelected(cellsRange);
  21238. } else {
  21239. rng
  21240. &&
  21241. rng
  21242. .selectNodeContents(endTdCol)
  21243. .select();
  21244. }
  21245. }
  21246. return;
  21247. }
  21248. if(inTableSide(table, target, evt)) {
  21249. var endTdRow = ut
  21250. .getCell(
  21251. ut.indexTable[cellInfo.rowIndex][ut.colsNum -
  21252. 1
  21253. ].rowIndex,
  21254. ut.indexTable[cellInfo.rowIndex][ut.colsNum -
  21255. 1
  21256. ].cellIndex);
  21257. if(evt.shiftKey && ut.selectedTds.length) {
  21258. if(ut.selectedTds[0] !== endTdRow) {
  21259. cellsRange = ut
  21260. .getCellsRange(
  21261. ut.selectedTds[0],
  21262. endTdRow);
  21263. ut.setSelected(cellsRange);
  21264. } else {
  21265. rng
  21266. &&
  21267. rng
  21268. .selectNodeContents(endTdRow)
  21269. .select();
  21270. }
  21271. } else {
  21272. if(target !== endTdRow) {
  21273. cellsRange = ut.getCellsRange(
  21274. target, endTdRow);
  21275. ut.setSelected(cellsRange);
  21276. } else {
  21277. rng
  21278. &&
  21279. rng
  21280. .selectNodeContents(endTdRow)
  21281. .select();
  21282. }
  21283. }
  21284. }
  21285. };
  21286. });
  21287. switchBorderColor(me, true);
  21288. });
  21289. domUtils.on(me.document, "mousemove", mouseMoveEvent);
  21290. domUtils.on(me.document, "mouseout", function(evt) {
  21291. var target = evt.target || evt.srcElement;
  21292. if(target.tagName == "TABLE") {
  21293. toggleDraggableState(me, false, "", null);
  21294. }
  21295. });
  21296. /**
  21297. * 表格隔行变色
  21298. */
  21299. me.addListener("interlacetable", function(type, table, classList) {
  21300. if(!table)
  21301. return;
  21302. var me = this,
  21303. rows = table.rows,
  21304. len = rows.length,
  21305. getClass = function(
  21306. list, index, repeat) {
  21307. return list[index] ? list[index] : repeat ? list[index %
  21308. list.length] : "";
  21309. };
  21310. for(var i = 0; i < len; i++) {
  21311. rows[i].className = getClass(classList ||
  21312. me.options.classList, i, true);
  21313. }
  21314. });
  21315. me.addListener("uninterlacetable", function(type, table) {
  21316. if(!table)
  21317. return;
  21318. var me = this,
  21319. rows = table.rows,
  21320. classList = me.options.classList,
  21321. len = rows.length;
  21322. for(var i = 0; i < len; i++) {
  21323. domUtils.removeClasses(rows[i], classList);
  21324. }
  21325. });
  21326. me.addListener("mousedown", mouseDownEvent);
  21327. me.addListener("mouseup", mouseUpEvent);
  21328. // 拖动的时候触发mouseup
  21329. domUtils.on(me.body, 'dragstart', function(evt) {
  21330. mouseUpEvent.call(me, 'dragstart', evt);
  21331. });
  21332. me.addOutputRule(function(root) {
  21333. utils.each(root.getNodesByTagName('div'), function(n) {
  21334. if(n.getAttr('id') == 'ue_tableDragLine') {
  21335. n.parentNode.removeChild(n);
  21336. }
  21337. });
  21338. });
  21339. var currentRowIndex = 0;
  21340. me.addListener("mousedown", function() {
  21341. currentRowIndex = 0;
  21342. });
  21343. me.addListener('tabkeydown', function() {
  21344. var range = this.selection.getRange(),
  21345. common = range
  21346. .getCommonAncestor(true, true),
  21347. table = domUtils
  21348. .findParentByTagName(common, 'table');
  21349. if(table) {
  21350. if(domUtils.findParentByTagName(common, 'caption', true)) {
  21351. var cell = domUtils
  21352. .getElementsByTagName(table, 'th td');
  21353. if(cell && cell.length) {
  21354. range.setStart(cell[0], 0).setCursor(false, true)
  21355. }
  21356. } else {
  21357. var cell = domUtils.findParentByTagName(common, ['td',
  21358. 'th'
  21359. ], true),
  21360. ua = getUETable(cell);
  21361. currentRowIndex = cell.rowSpan > 1 ?
  21362. currentRowIndex :
  21363. ua.getCellInfo(cell).rowIndex;
  21364. var nextCell = ua.getTabNextCell(cell, currentRowIndex);
  21365. if(nextCell) {
  21366. if(isEmptyBlock(nextCell)) {
  21367. range.setStart(nextCell, 0).setCursor(false,
  21368. true)
  21369. } else {
  21370. range.selectNodeContents(nextCell).select()
  21371. }
  21372. } else {
  21373. me.fireEvent('saveScene');
  21374. me.__hasEnterExecCommand = true;
  21375. this.execCommand('insertrownext');
  21376. me.__hasEnterExecCommand = false;
  21377. range = this.selection.getRange();
  21378. range.setStart(
  21379. table.rows[table.rows.length - 1].cells[0],
  21380. 0).setCursor();
  21381. me.fireEvent('saveScene');
  21382. }
  21383. }
  21384. return true;
  21385. }
  21386. });
  21387. browser.ie && me.addListener('selectionchange', function() {
  21388. toggleDraggableState(this, false, "", null);
  21389. });
  21390. me.addListener("keydown", function(type, evt) {
  21391. var me = this;
  21392. // 处理在表格的最后一个输入tab产生新的表格
  21393. var keyCode = evt.keyCode || evt.which;
  21394. if(keyCode == 8 || keyCode == 46) {
  21395. return;
  21396. }
  21397. var notCtrlKey = !evt.ctrlKey && !evt.metaKey && !evt.shiftKey &&
  21398. !evt.altKey;
  21399. notCtrlKey
  21400. &&
  21401. removeSelectedClass(domUtils.getElementsByTagName(
  21402. me.body, "td"));
  21403. var ut = getUETableBySelected(me);
  21404. if(!ut)
  21405. return;
  21406. notCtrlKey && ut.clearSelected();
  21407. });
  21408. me.addListener("beforegetcontent", function() {
  21409. switchBorderColor(this, false);
  21410. browser.ie &&
  21411. utils.each(this.document
  21412. .getElementsByTagName('caption'),
  21413. function(ci) {
  21414. if(domUtils.isEmptyNode(ci)) {
  21415. ci.innerHTML = '&nbsp;'
  21416. }
  21417. });
  21418. });
  21419. me.addListener("aftergetcontent", function() {
  21420. switchBorderColor(this, true);
  21421. });
  21422. me.addListener("getAllHtml", function() {
  21423. removeSelectedClass(me.document.getElementsByTagName("td"));
  21424. });
  21425. // 修正全屏状态下插入的表格宽度在非全屏状态下撑开编辑器的情况
  21426. me.addListener("fullscreenchanged", function(type, fullscreen) {
  21427. if(!fullscreen) {
  21428. var ratio = this.body.offsetWidth /
  21429. document.body.offsetWidth,
  21430. tables = domUtils
  21431. .getElementsByTagName(this.body, "table");
  21432. utils.each(tables, function(table) {
  21433. if(table.offsetWidth < me.body.offsetWidth)
  21434. return false;
  21435. var tds = domUtils.getElementsByTagName(table, "td"),
  21436. backWidths = [];
  21437. utils.each(tds, function(td) {
  21438. backWidths.push(td.offsetWidth);
  21439. });
  21440. for(var i = 0, td; td = tds[i]; i++) {
  21441. td.setAttribute("width", Math.floor(backWidths[i] *
  21442. ratio));
  21443. }
  21444. table.setAttribute("width", Math.floor(getTableWidth(
  21445. me, needIEHack, getDefaultValue(me))))
  21446. });
  21447. }
  21448. });
  21449. // 重写execCommand命令,用于处理框选时的处理
  21450. var oldExecCommand = me.execCommand;
  21451. me.execCommand = function(cmd, datatat) {
  21452. var me = this,
  21453. args = arguments;
  21454. cmd = cmd.toLowerCase();
  21455. var ut = getUETableBySelected(me),
  21456. tds, range = new dom.Range(me.document),
  21457. cmdFun = me.commands[cmd] ||
  21458. UE.commands[cmd],
  21459. result;
  21460. if(!cmdFun)
  21461. return;
  21462. if(ut && !commands[cmd] && !cmdFun.notNeedUndo &&
  21463. !me.__hasEnterExecCommand) {
  21464. me.__hasEnterExecCommand = true;
  21465. me.fireEvent("beforeexeccommand", cmd);
  21466. tds = ut.selectedTds;
  21467. var lastState = -2,
  21468. lastValue = -2,
  21469. value, state;
  21470. for(var i = 0, td; td = tds[i]; i++) {
  21471. if(isEmptyBlock(td)) {
  21472. range.setStart(td, 0).setCursor(false, true)
  21473. } else {
  21474. range.selectNode(td).select(true);
  21475. }
  21476. state = me.queryCommandState(cmd);
  21477. value = me.queryCommandValue(cmd);
  21478. if(state != -1) {
  21479. if(lastState !== state || lastValue !== value) {
  21480. me._ignoreContentChange = true;
  21481. result = oldExecCommand.apply(me, arguments);
  21482. me._ignoreContentChange = false;
  21483. }
  21484. lastState = me.queryCommandState(cmd);
  21485. lastValue = me.queryCommandValue(cmd);
  21486. if(domUtils.isEmptyBlock(td)) {
  21487. domUtils.fillNode(me.document, td)
  21488. }
  21489. }
  21490. }
  21491. range.setStart(tds[0], 0).shrinkBoundary(true).setCursor(
  21492. false, true);
  21493. me.fireEvent('contentchange');
  21494. me.fireEvent("afterexeccommand", cmd);
  21495. me.__hasEnterExecCommand = false;
  21496. me._selectionChange();
  21497. } else {
  21498. result = oldExecCommand.apply(me, arguments);
  21499. }
  21500. return result;
  21501. };
  21502. });
  21503. /**
  21504. * 删除obj的宽高style,改成属性宽高
  21505. *
  21506. * @param obj
  21507. * @param replaceToProperty
  21508. */
  21509. function removeStyleSize(obj, replaceToProperty) {
  21510. removeStyle(obj, "width", true);
  21511. removeStyle(obj, "height", true);
  21512. }
  21513. function removeStyle(obj, styleName, replaceToProperty) {
  21514. if(obj.style[styleName]) {
  21515. replaceToProperty
  21516. &&
  21517. obj.setAttribute(styleName, parseInt(
  21518. obj.style[styleName], 10));
  21519. obj.style[styleName] = "";
  21520. }
  21521. }
  21522. function getParentTdOrTh(ele) {
  21523. if(ele.tagName == "TD" || ele.tagName == "TH")
  21524. return ele;
  21525. var td;
  21526. if(td = domUtils.findParentByTagName(ele, "td", true) ||
  21527. domUtils.findParentByTagName(ele, "th", true))
  21528. return td;
  21529. return null;
  21530. }
  21531. function isEmptyBlock(node) {
  21532. var reg = new RegExp(domUtils.fillChar, 'g');
  21533. if(node[browser.ie ? 'innerText' : 'textContent'].replace(/^\s*$/,
  21534. '').replace(reg, '').length > 0) {
  21535. return 0;
  21536. }
  21537. for(var n in dtd.$isNotEmpty) {
  21538. if(node.getElementsByTagName(n).length) {
  21539. return 0;
  21540. }
  21541. }
  21542. return 1;
  21543. }
  21544. function mouseCoords(evt) {
  21545. if(evt.pageX || evt.pageY) {
  21546. return {
  21547. x: evt.pageX,
  21548. y: evt.pageY
  21549. };
  21550. }
  21551. return {
  21552. x: evt.clientX + me.document.body.scrollLeft -
  21553. me.document.body.clientLeft,
  21554. y: evt.clientY + me.document.body.scrollTop -
  21555. me.document.body.clientTop
  21556. };
  21557. }
  21558. function mouseMoveEvent(evt) {
  21559. if(isEditorDisabled()) {
  21560. return;
  21561. }
  21562. try {
  21563. // 普通状态下鼠标移动
  21564. var target = getParentTdOrTh(evt.target || evt.srcElement),
  21565. pos;
  21566. // 区分用户的行为是拖动还是双击
  21567. if(isInResizeBuffer) {
  21568. me.body.style.webkitUserSelect = 'none';
  21569. if(Math.abs(userActionStatus.x - evt.clientX) > offsetOfTableCell ||
  21570. Math.abs(userActionStatus.y - evt.clientY) > offsetOfTableCell) {
  21571. clearTableDragTimer();
  21572. isInResizeBuffer = false;
  21573. singleClickState = 0;
  21574. // drag action
  21575. tableBorderDrag(evt);
  21576. }
  21577. }
  21578. // 修改单元格大小时的鼠标移动
  21579. if(onDrag && dragTd) {
  21580. singleClickState = 0;
  21581. me.body.style.webkitUserSelect = 'none';
  21582. me.selection.getNative()[browser.ie9below ?
  21583. 'empty' :
  21584. 'removeAllRanges']();
  21585. pos = mouseCoords(evt);
  21586. toggleDraggableState(me, true, onDrag, pos, target);
  21587. if(onDrag == "h") {
  21588. dragLine.style.left = getPermissionX(dragTd, evt) +
  21589. "px";
  21590. } else if(onDrag == "v") {
  21591. dragLine.style.top = getPermissionY(dragTd, evt) + "px";
  21592. }
  21593. return;
  21594. }
  21595. // 当鼠标处于table上时,修改移动过程中的光标状态
  21596. if(target) {
  21597. // 针对使用table作为容器的组件不触发拖拽效果
  21598. if(me.fireEvent('excludetable', target) === true)
  21599. return;
  21600. pos = mouseCoords(evt);
  21601. var state = getRelation(target, pos),
  21602. table = domUtils
  21603. .findParentByTagName(target, "table", true);
  21604. if(inTableSide(table, target, evt, true)) {
  21605. if(me.fireEvent("excludetable", table) === true)
  21606. return;
  21607. me.body.style.cursor = "url(" + me.options.cursorpath +
  21608. "h.png),pointer";
  21609. } else if(inTableSide(table, target, evt)) {
  21610. if(me.fireEvent("excludetable", table) === true)
  21611. return;
  21612. me.body.style.cursor = "url(" + me.options.cursorpath +
  21613. "v.png),pointer";
  21614. } else {
  21615. me.body.style.cursor = "text";
  21616. var curCell = target;
  21617. if(/\d/.test(state)) {
  21618. state = state.replace(/\d/, '');
  21619. target = getUETable(target).getPreviewCell(target,
  21620. state == "v");
  21621. }
  21622. // 位于第一行的顶部或者第一列的左边时不可拖动
  21623. toggleDraggableState(me, target ? !!state : false,
  21624. target ? state : '', pos, target);
  21625. }
  21626. } else {
  21627. toggleDragButton(false, table, me);
  21628. }
  21629. } catch(e) {
  21630. showError(e);
  21631. }
  21632. }
  21633. var dragButtonTimer;
  21634. function toggleDragButton(show, table, editor) {
  21635. if(!show) {
  21636. if(dragOver)
  21637. return;
  21638. dragButtonTimer = setTimeout(function() {
  21639. !dragOver && dragButton && dragButton.parentNode &&
  21640. dragButton.parentNode.removeChild(dragButton);
  21641. }, 2000);
  21642. } else {
  21643. createDragButton(table, editor);
  21644. }
  21645. }
  21646. function createDragButton(table, editor) {
  21647. var pos = domUtils.getXY(table),
  21648. doc = table.ownerDocument;
  21649. if(dragButton && dragButton.parentNode)
  21650. return dragButton;
  21651. dragButton = doc.createElement("div");
  21652. dragButton.contentEditable = false;
  21653. dragButton.innerHTML = "";
  21654. dragButton.style.cssText = "width:15px;height:15px;background-image:url(" +
  21655. editor.options.UEDITOR_HOME_URL +
  21656. "dialogs/table/dragicon.png);position: absolute;cursor:move;top:" +
  21657. (pos.y - 15) + "px;left:" + (pos.x) + "px;";
  21658. domUtils.unSelectable(dragButton);
  21659. dragButton.onmouseover = function(evt) {
  21660. dragOver = true;
  21661. };
  21662. dragButton.onmouseout = function(evt) {
  21663. dragOver = false;
  21664. };
  21665. domUtils.on(dragButton, 'click', function(type, evt) {
  21666. doClick(evt, this);
  21667. });
  21668. domUtils.on(dragButton, 'dblclick', function(type, evt) {
  21669. doDblClick(evt);
  21670. });
  21671. domUtils.on(dragButton, 'dragstart', function(type, evt) {
  21672. domUtils.preventDefault(evt);
  21673. });
  21674. var timer;
  21675. function doClick(evt, button) {
  21676. // 部分浏览器下需要清理
  21677. clearTimeout(timer);
  21678. timer = setTimeout(function() {
  21679. editor.fireEvent("tableClicked", table, button);
  21680. }, 300);
  21681. }
  21682. function doDblClick(evt) {
  21683. clearTimeout(timer);
  21684. var ut = getUETable(table),
  21685. start = table.rows[0].cells[0],
  21686. end = ut
  21687. .getLastCell(),
  21688. range = ut.getCellsRange(start, end);
  21689. editor.selection.getRange().setStart(start, 0).setCursor(false,
  21690. true);
  21691. ut.setSelected(range);
  21692. }
  21693. doc.body.appendChild(dragButton);
  21694. }
  21695. // function inPosition(table, pos) {
  21696. // var tablePos = domUtils.getXY(table),
  21697. // width = table.offsetWidth,
  21698. // height = table.offsetHeight;
  21699. // if (pos.x - tablePos.x < 5 && pos.y - tablePos.y < 5) {
  21700. // return "topLeft";
  21701. // } else if (tablePos.x + width - pos.x < 5 && tablePos.y + height -
  21702. // pos.y < 5) {
  21703. // return "bottomRight";
  21704. // }
  21705. // }
  21706. function inTableSide(table, cell, evt, top) {
  21707. var pos = mouseCoords(evt),
  21708. state = getRelation(cell, pos);
  21709. if(top) {
  21710. var caption = table.getElementsByTagName("caption")[0],
  21711. capHeight = caption ?
  21712. caption.offsetHeight :
  21713. 0;
  21714. return(state == "v1") &&
  21715. ((pos.y - domUtils.getXY(table).y - capHeight) < 8);
  21716. } else {
  21717. return(state == "h1") &&
  21718. ((pos.x - domUtils.getXY(table).x) < 8);
  21719. }
  21720. }
  21721. /**
  21722. * 获取拖动时允许的X轴坐标
  21723. *
  21724. * @param dragTd
  21725. * @param evt
  21726. */
  21727. function getPermissionX(dragTd, evt) {
  21728. var ut = getUETable(dragTd);
  21729. if(ut) {
  21730. var preTd = ut.getSameEndPosCells(dragTd, "x")[0],
  21731. nextTd = ut
  21732. .getSameStartPosXCells(dragTd)[0],
  21733. mouseX = mouseCoords(evt).x,
  21734. left = (preTd ?
  21735. domUtils.getXY(preTd).x :
  21736. domUtils.getXY(ut.table).x) +
  21737. 20,
  21738. right = nextTd ?
  21739. domUtils.getXY(nextTd).x + nextTd.offsetWidth - 20 :
  21740. (me.body.offsetWidth + 5 || parseInt(domUtils
  21741. .getComputedStyle(me.body, "width"), 10));
  21742. left += cellMinWidth;
  21743. right -= cellMinWidth;
  21744. return mouseX < left ? left : mouseX > right ? right : mouseX;
  21745. }
  21746. }
  21747. /**
  21748. * 获取拖动时允许的Y轴坐标
  21749. */
  21750. function getPermissionY(dragTd, evt) {
  21751. try {
  21752. var top = domUtils.getXY(dragTd).y,
  21753. mousePosY = mouseCoords(evt).y;
  21754. return mousePosY < top ? top : mousePosY;
  21755. } catch(e) {
  21756. showError(e);
  21757. }
  21758. }
  21759. /**
  21760. * 移动状态切换
  21761. */
  21762. function toggleDraggableState(editor, draggable, dir, mousePos, cell) {
  21763. try {
  21764. editor.body.style.cursor = dir == "h" ?
  21765. "col-resize" :
  21766. dir == "v" ? "row-resize" : "text";
  21767. if(browser.ie) {
  21768. if(dir && !mousedown && !getUETableBySelected(editor)) {
  21769. getDragLine(editor, editor.document);
  21770. showDragLineAt(dir, cell);
  21771. } else {
  21772. hideDragLine(editor)
  21773. }
  21774. }
  21775. onBorder = draggable;
  21776. } catch(e) {
  21777. showError(e);
  21778. }
  21779. }
  21780. /**
  21781. * 获取与UETable相关的resize line
  21782. *
  21783. * @param uetable
  21784. * UETable对象
  21785. */
  21786. function getResizeLineByUETable() {
  21787. var lineId = '_UETableResizeLine',
  21788. line = this.document
  21789. .getElementById(lineId);
  21790. if(!line) {
  21791. line = this.document.createElement("div");
  21792. line.id = lineId;
  21793. line.contnetEditable = false;
  21794. line.setAttribute("unselectable", "on");
  21795. var styles = {
  21796. width: 2 * cellBorderWidth + 1 + 'px',
  21797. position: 'absolute',
  21798. 'z-index': 100000,
  21799. cursor: 'col-resize',
  21800. background: 'red',
  21801. display: 'none'
  21802. };
  21803. // 切换状态
  21804. line.onmouseout = function() {
  21805. this.style.display = 'none';
  21806. };
  21807. utils.extend(line.style, styles);
  21808. this.document.body.appendChild(line);
  21809. }
  21810. return line;
  21811. }
  21812. /**
  21813. * 更新resize-line
  21814. */
  21815. function updateResizeLine(cell, uetable) {
  21816. var line = getResizeLineByUETable.call(this),
  21817. table = uetable.table,
  21818. styles = {
  21819. top: domUtils.getXY(table).y + 'px',
  21820. left: domUtils.getXY(cell).x + cell.offsetWidth -
  21821. cellBorderWidth + 'px',
  21822. display: 'block',
  21823. height: table.offsetHeight + 'px'
  21824. };
  21825. utils.extend(line.style, styles);
  21826. }
  21827. /**
  21828. * 显示resize-line
  21829. */
  21830. function showResizeLine(cell) {
  21831. var uetable = getUETable(cell);
  21832. updateResizeLine.call(this, cell, uetable);
  21833. }
  21834. /**
  21835. * 获取鼠标与当前单元格的相对位置
  21836. *
  21837. * @param ele
  21838. * @param mousePos
  21839. */
  21840. function getRelation(ele, mousePos) {
  21841. var elePos = domUtils.getXY(ele);
  21842. if(!elePos) {
  21843. return '';
  21844. }
  21845. if(elePos.x + ele.offsetWidth - mousePos.x < cellBorderWidth) {
  21846. return "h";
  21847. }
  21848. if(mousePos.x - elePos.x < cellBorderWidth) {
  21849. return 'h1'
  21850. }
  21851. if(elePos.y + ele.offsetHeight - mousePos.y < cellBorderWidth) {
  21852. return "v";
  21853. }
  21854. if(mousePos.y - elePos.y < cellBorderWidth) {
  21855. return 'v1'
  21856. }
  21857. return '';
  21858. }
  21859. function mouseDownEvent(type, evt) {
  21860. if(isEditorDisabled()) {
  21861. return;
  21862. }
  21863. userActionStatus = {
  21864. x: evt.clientX,
  21865. y: evt.clientY
  21866. };
  21867. // 右键菜单单独处理
  21868. if(evt.button == 2) {
  21869. var ut = getUETableBySelected(me),
  21870. flag = false;
  21871. if(ut) {
  21872. var td = getTargetTd(me, evt);
  21873. utils.each(ut.selectedTds, function(ti) {
  21874. if(ti === td) {
  21875. flag = true;
  21876. }
  21877. });
  21878. if(!flag) {
  21879. removeSelectedClass(domUtils.getElementsByTagName(
  21880. me.body, "th td"));
  21881. ut.clearSelected()
  21882. } else {
  21883. td = ut.selectedTds[0];
  21884. setTimeout(function() {
  21885. me.selection.getRange().setStart(td, 0).setCursor(
  21886. false, true);
  21887. }, 0);
  21888. }
  21889. }
  21890. } else {
  21891. tableClickHander(evt);
  21892. }
  21893. }
  21894. // 清除表格的计时器
  21895. function clearTableTimer() {
  21896. tabTimer && clearTimeout(tabTimer);
  21897. tabTimer = null;
  21898. }
  21899. // 双击收缩
  21900. function tableDbclickHandler(evt) {
  21901. singleClickState = 0;
  21902. evt = evt || me.window.event;
  21903. var target = getParentTdOrTh(evt.target || evt.srcElement);
  21904. if(target) {
  21905. var h;
  21906. if(h = getRelation(target, mouseCoords(evt))) {
  21907. hideDragLine(me);
  21908. if(h == 'h1') {
  21909. h = 'h';
  21910. if(inTableSide(domUtils.findParentByTagName(target,
  21911. "table"), target, evt)) {
  21912. me.execCommand('adaptbywindow');
  21913. } else {
  21914. target = getUETable(target).getPreviewCell(target);
  21915. if(target) {
  21916. var rng = me.selection.getRange();
  21917. rng.selectNodeContents(target).setCursor(true,
  21918. true)
  21919. }
  21920. }
  21921. }
  21922. if(h == 'h') {
  21923. var ut = getUETable(target),
  21924. table = ut.table,
  21925. cells = getCellsByMoveBorder(
  21926. target, table, true);
  21927. cells = extractArray(cells, 'left');
  21928. ut.width = ut.offsetWidth;
  21929. var oldWidth = [],
  21930. newWidth = [];
  21931. utils.each(cells, function(cell) {
  21932. oldWidth.push(cell.offsetWidth);
  21933. });
  21934. utils.each(cells, function(cell) {
  21935. cell.removeAttribute("width");
  21936. });
  21937. window.setTimeout(function() {
  21938. // 是否允许改变
  21939. var changeable = true;
  21940. utils.each(cells, function(cell, index) {
  21941. var width = cell.offsetWidth;
  21942. if(width > oldWidth[index]) {
  21943. changeable = false;
  21944. return false;
  21945. }
  21946. newWidth.push(width);
  21947. });
  21948. var change = changeable ? newWidth : oldWidth;
  21949. utils.each(cells, function(cell, index) {
  21950. cell.width = change[index] - getTabcellSpace();
  21951. });
  21952. }, 0);
  21953. // minWidth -= cellMinWidth;
  21954. //
  21955. // table.removeAttribute("width");
  21956. // utils.each(cells, function (cell) {
  21957. // cell.style.width = "";
  21958. // cell.width -= minWidth;
  21959. // });
  21960. }
  21961. }
  21962. }
  21963. }
  21964. function tableClickHander(evt) {
  21965. removeSelectedClass(domUtils.getElementsByTagName(me.body, "td th"));
  21966. // trace:3113
  21967. // 选中单元格,点击table外部,不会清掉table上挂的ueTable,会引起getUETableBySelected方法返回值
  21968. utils.each(me.document.getElementsByTagName('table'), function(t) {
  21969. t.ueTable = null;
  21970. });
  21971. startTd = getTargetTd(me, evt);
  21972. if(!startTd)
  21973. return;
  21974. var table = domUtils.findParentByTagName(startTd, "table", true);
  21975. ut = getUETable(table);
  21976. ut && ut.clearSelected();
  21977. // 判断当前鼠标状态
  21978. if(!onBorder) {
  21979. me.document.body.style.webkitUserSelect = '';
  21980. mousedown = true;
  21981. me.addListener('mouseover', mouseOverEvent);
  21982. } else {
  21983. // 边框上的动作处理
  21984. borderActionHandler(evt);
  21985. }
  21986. }
  21987. // 处理表格边框上的动作, 这里做延时处理,避免两种动作互相影响
  21988. function borderActionHandler(evt) {
  21989. if(browser.ie) {
  21990. evt = reconstruct(evt);
  21991. }
  21992. clearTableDragTimer();
  21993. // 是否正在等待resize的缓冲中
  21994. isInResizeBuffer = true;
  21995. tableDragTimer = setTimeout(function() {
  21996. tableBorderDrag(evt);
  21997. }, dblclickTime);
  21998. }
  21999. function extractArray(originArr, key) {
  22000. var result = [],
  22001. tmp = null;
  22002. for(var i = 0, len = originArr.length; i < len; i++) {
  22003. tmp = originArr[i][key];
  22004. if(tmp) {
  22005. result.push(tmp);
  22006. }
  22007. }
  22008. return result;
  22009. }
  22010. function clearTableDragTimer() {
  22011. tableDragTimer && clearTimeout(tableDragTimer);
  22012. tableDragTimer = null;
  22013. }
  22014. function reconstruct(obj) {
  22015. var attrs = ['pageX', 'pageY', 'clientX', 'clientY', 'srcElement',
  22016. 'target'
  22017. ],
  22018. newObj = {};
  22019. if(obj) {
  22020. for(var i = 0, key, val; key = attrs[i]; i++) {
  22021. val = obj[key];
  22022. val && (newObj[key] = val);
  22023. }
  22024. }
  22025. return newObj;
  22026. }
  22027. // 边框拖动
  22028. function tableBorderDrag(evt) {
  22029. isInResizeBuffer = false;
  22030. startTd = evt.target || evt.srcElement;
  22031. if(!startTd)
  22032. return;
  22033. var state = getRelation(startTd, mouseCoords(evt));
  22034. if(/\d/.test(state)) {
  22035. state = state.replace(/\d/, '');
  22036. startTd = getUETable(startTd).getPreviewCell(startTd,
  22037. state == 'v');
  22038. }
  22039. hideDragLine(me);
  22040. getDragLine(me, me.document);
  22041. me.fireEvent('saveScene');
  22042. showDragLineAt(state, startTd);
  22043. mousedown = true;
  22044. // 拖动开始
  22045. onDrag = state;
  22046. dragTd = startTd;
  22047. }
  22048. function mouseUpEvent(type, evt) {
  22049. if(isEditorDisabled()) {
  22050. return;
  22051. }
  22052. clearTableDragTimer();
  22053. isInResizeBuffer = false;
  22054. if(onBorder) {
  22055. singleClickState = ++singleClickState % 3;
  22056. userActionStatus = {
  22057. x: evt.clientX,
  22058. y: evt.clientY
  22059. };
  22060. tableResizeTimer = setTimeout(function() {
  22061. singleClickState > 0 && singleClickState--;
  22062. }, dblclickTime);
  22063. if(singleClickState === 2) {
  22064. singleClickState = 0;
  22065. tableDbclickHandler(evt);
  22066. return;
  22067. }
  22068. }
  22069. if(evt.button == 2)
  22070. return;
  22071. var me = this;
  22072. // 清除表格上原生跨选问题
  22073. var range = me.selection.getRange(),
  22074. start = domUtils
  22075. .findParentByTagName(range.startContainer, 'table', true),
  22076. end = domUtils
  22077. .findParentByTagName(range.endContainer, 'table', true);
  22078. if(start || end) {
  22079. if(start === end) {
  22080. start = domUtils.findParentByTagName(range.startContainer, ['td', 'th', 'caption'], true);
  22081. end = domUtils.findParentByTagName(range.endContainer, [
  22082. 'td', 'th', 'caption'
  22083. ], true);
  22084. if(start !== end) {
  22085. me.selection.clearRange()
  22086. }
  22087. } else {
  22088. me.selection.clearRange()
  22089. }
  22090. }
  22091. mousedown = false;
  22092. me.document.body.style.webkitUserSelect = '';
  22093. // 拖拽状态下的mouseUP
  22094. if(onDrag && dragTd) {
  22095. me.selection.getNative()[browser.ie9below ?
  22096. 'empty' :
  22097. 'removeAllRanges']();
  22098. singleClickState = 0;
  22099. dragLine = me.document.getElementById('ue_tableDragLine');
  22100. // trace 3973
  22101. if(dragLine) {
  22102. var dragTdPos = domUtils.getXY(dragTd),
  22103. dragLinePos = domUtils
  22104. .getXY(dragLine);
  22105. switch(onDrag) {
  22106. case "h":
  22107. changeColWidth(dragTd, dragLinePos.x - dragTdPos.x);
  22108. break;
  22109. case "v":
  22110. changeRowHeight(dragTd, dragLinePos.y - dragTdPos.y -
  22111. dragTd.offsetHeight);
  22112. break;
  22113. default:
  22114. }
  22115. onDrag = "";
  22116. dragTd = null;
  22117. hideDragLine(me);
  22118. me.fireEvent('saveScene');
  22119. return;
  22120. }
  22121. }
  22122. // 正常状态下的mouseup
  22123. if(!startTd) {
  22124. var target = domUtils.findParentByTagName(evt.target ||
  22125. evt.srcElement, "td", true);
  22126. if(!target)
  22127. target = domUtils.findParentByTagName(evt.target ||
  22128. evt.srcElement, "th", true);
  22129. if(target &&
  22130. (target.tagName == "TD" || target.tagName == "TH")) {
  22131. if(me.fireEvent("excludetable", target) === true)
  22132. return;
  22133. range = new dom.Range(me.document);
  22134. range.setStart(target, 0).setCursor(false, true);
  22135. }
  22136. } else {
  22137. var ut = getUETable(startTd),
  22138. cell = ut ?
  22139. ut.selectedTds[0] :
  22140. null;
  22141. if(cell) {
  22142. range = new dom.Range(me.document);
  22143. if(domUtils.isEmptyBlock(cell)) {
  22144. range.setStart(cell, 0).setCursor(false, true);
  22145. } else {
  22146. range.selectNodeContents(cell).shrinkBoundary()
  22147. .setCursor(false, true);
  22148. }
  22149. } else {
  22150. range = me.selection.getRange().shrinkBoundary();
  22151. if(!range.collapsed) {
  22152. var start = domUtils.findParentByTagName(
  22153. range.startContainer, ['td', 'th'], true),
  22154. end = domUtils
  22155. .findParentByTagName(range.endContainer, ['td',
  22156. 'th'
  22157. ], true);
  22158. // 在table里边的不能清除
  22159. if(start && !end || !start && end || start && end &&
  22160. start !== end) {
  22161. range.setCursor(false, true);
  22162. }
  22163. }
  22164. }
  22165. startTd = null;
  22166. me.removeListener('mouseover', mouseOverEvent);
  22167. }
  22168. me._selectionChange(250, evt);
  22169. }
  22170. function mouseOverEvent(type, evt) {
  22171. if(isEditorDisabled()) {
  22172. return;
  22173. }
  22174. var me = this,
  22175. tar = evt.target || evt.srcElement;
  22176. currentTd = domUtils.findParentByTagName(tar, "td", true) ||
  22177. domUtils.findParentByTagName(tar, "th", true);
  22178. // 需要判断两个TD是否位于同一个表格内
  22179. if(startTd &&
  22180. currentTd &&
  22181. ((startTd.tagName == "TD" && currentTd.tagName == "TD") || (startTd.tagName == "TH" && currentTd.tagName == "TH")) &&
  22182. domUtils.findParentByTagName(startTd, 'table') == domUtils
  22183. .findParentByTagName(currentTd, 'table')) {
  22184. var ut = getUETable(currentTd);
  22185. if(startTd != currentTd) {
  22186. me.document.body.style.webkitUserSelect = 'none';
  22187. me.selection.getNative()[browser.ie9below ?
  22188. 'empty' :
  22189. 'removeAllRanges']();
  22190. var range = ut.getCellsRange(startTd, currentTd);
  22191. ut.setSelected(range);
  22192. } else {
  22193. me.document.body.style.webkitUserSelect = '';
  22194. ut.clearSelected();
  22195. }
  22196. }
  22197. evt.preventDefault ?
  22198. evt.preventDefault() :
  22199. (evt.returnValue = false);
  22200. }
  22201. function toRem(cell,px){
  22202. var od=cell.ownerDocument;
  22203. return px/parseFloat(od.defaultView.getComputedStyle(od.documentElement).fontSize);
  22204. }
  22205. function setCellHeight(cell, height, backHeight) {
  22206. var lineHight = parseInt(domUtils.getComputedStyle(cell,
  22207. "line-height"), 10),
  22208. tmpHeight = backHeight + height;
  22209. height = tmpHeight < lineHight ? lineHight : tmpHeight;
  22210. if(cell.style.height)
  22211. cell.style.height = "";
  22212. cell.rowSpan == 1 ?
  22213. cell.setAttribute("height", height) :
  22214. (cell.removeAttribute && cell.removeAttribute("height"));
  22215. if(cell.rowSpan == 1){
  22216. cell.style.height=toRem(cell,cell.height)+"rem";
  22217. }
  22218. }
  22219. function getWidth(cell) {
  22220. if(!cell)
  22221. return 0;
  22222. return parseInt(domUtils.getComputedStyle(cell, "width"), 10);
  22223. }
  22224. function changeColWidth(cell, changeValue) {
  22225. var ut = getUETable(cell);
  22226. if(ut) {
  22227. // 根据当前移动的边框获取相关的单元格
  22228. var table = ut.table,
  22229. cells = getCellsByMoveBorder(cell, table);
  22230. table.style.width = "";
  22231. table.removeAttribute("width");
  22232. // 修正改变量
  22233. changeValue = correctChangeValue(changeValue, cell, cells);
  22234. if(cell.nextSibling) {
  22235. var i = 0;
  22236. utils.each(cells, function(cellGroup) {
  22237. var _left = cellGroup.left, _right = cellGroup.right;
  22238. _left.width = (+_left.width) + changeValue;
  22239. _left.style.width = toRem(_left, _left.width) + "rem";
  22240. _right && (_right.width = (+_right.width) - changeValue);
  22241. _right && (_right.style.width = toRem(_right, _right.width) + "rem");
  22242. });
  22243. } else {
  22244. utils.each(cells, function(cellGroup) {
  22245. cellGroup.left.width -= -changeValue;
  22246. cellGroup.left.style.width = toRem(cellGroup.left, cellGroup.left.width) + "rem";
  22247. });
  22248. }
  22249. }
  22250. }
  22251. function isEditorDisabled() {
  22252. return me.body.contentEditable === "false";
  22253. }
  22254. function changeRowHeight(td, changeValue) {
  22255. if(Math.abs(changeValue) < 10)
  22256. return;
  22257. var ut = getUETable(td);
  22258. if(ut) {
  22259. var cells = ut.getSameEndPosCells(td, "y"),
  22260. // 备份需要连带变化的td的原始高度,否则后期无法获取正确的值
  22261. backHeight = cells[0] ? cells[0].offsetHeight : 0;
  22262. for(var i = 0, cell; cell = cells[i++];) {
  22263. setCellHeight(cell, changeValue, backHeight);
  22264. }
  22265. }
  22266. }
  22267. /**
  22268. * 获取调整单元格大小的相关单元格
  22269. *
  22270. * @isContainMergeCell 返回的结果中是否包含发生合并后的单元格
  22271. */
  22272. function getCellsByMoveBorder(cell, table, isContainMergeCell) {
  22273. if(!table) {
  22274. table = domUtils.findParentByTagName(cell, 'table');
  22275. }
  22276. if(!table) {
  22277. return null;
  22278. }
  22279. // 获取到该单元格所在行的序列号
  22280. var index = domUtils.getNodeIndex(cell),
  22281. temp = cell,
  22282. rows = table.rows,
  22283. colIndex = 0;
  22284. while(temp) {
  22285. // 获取到当前单元格在未发生单元格合并时的序列
  22286. if(temp.nodeType === 1) {
  22287. colIndex += (temp.colSpan || 1);
  22288. }
  22289. temp = temp.previousSibling;
  22290. }
  22291. temp = null;
  22292. // 记录想关的单元格
  22293. var borderCells = [];
  22294. utils.each(rows, function(tabRow) {
  22295. var cells = tabRow.cells,
  22296. currIndex = 0;
  22297. utils.each(cells, function(tabCell) {
  22298. currIndex += (tabCell.colSpan || 1);
  22299. if(currIndex === colIndex) {
  22300. borderCells.push({
  22301. left: tabCell,
  22302. right: tabCell.nextSibling || null
  22303. });
  22304. return false;
  22305. } else if(currIndex > colIndex) {
  22306. if(isContainMergeCell) {
  22307. borderCells.push({
  22308. left: tabCell
  22309. });
  22310. }
  22311. return false;
  22312. }
  22313. });
  22314. });
  22315. return borderCells;
  22316. }
  22317. /**
  22318. * 通过给定的单元格集合获取最小的单元格width
  22319. */
  22320. function getMinWidthByTableCells(cells) {
  22321. var minWidth = Number.MAX_VALUE;
  22322. for(var i = 0, curCell; curCell = cells[i]; i++) {
  22323. minWidth = Math.min(minWidth, curCell.width ||
  22324. getTableCellWidth(curCell));
  22325. }
  22326. return minWidth;
  22327. }
  22328. function correctChangeValue(changeValue, relatedCell, cells) {
  22329. // 为单元格的paading预留空间
  22330. changeValue -= getTabcellSpace();
  22331. if(changeValue < 0) {
  22332. return 0;
  22333. }
  22334. changeValue -= getTableCellWidth(relatedCell);
  22335. // 确定方向
  22336. var direction = changeValue < 0 ? 'left' : 'right';
  22337. changeValue = Math.abs(changeValue);
  22338. // 只关心非最后一个单元格就可以
  22339. utils.each(cells, function(cellGroup) {
  22340. var curCell = cellGroup[direction];
  22341. // 为单元格保留最小空间
  22342. if(curCell) {
  22343. changeValue = Math.min(changeValue,
  22344. getTableCellWidth(curCell) - cellMinWidth);
  22345. }
  22346. });
  22347. // 修正越界
  22348. changeValue = changeValue < 0 ? 0 : changeValue;
  22349. return direction === 'left' ? -changeValue : changeValue;
  22350. }
  22351. function getTableCellWidth(cell) {
  22352. var width = 0,
  22353. // 偏移纠正量
  22354. offset = 0,
  22355. width = cell.offsetWidth - getTabcellSpace();
  22356. // 最后一个节点纠正一下
  22357. if(!cell.nextSibling) {
  22358. width -= getTableCellOffset(cell);
  22359. }
  22360. width = width < 0 ? 0 : width;
  22361. try {
  22362. cell.width = width;
  22363. } catch(e) {}
  22364. return width;
  22365. }
  22366. /**
  22367. * 获取单元格所在表格的最末单元格的偏移量
  22368. */
  22369. function getTableCellOffset(cell) {
  22370. tab = domUtils.findParentByTagName(cell, "table", false);
  22371. if(tab.offsetVal === undefined) {
  22372. var prev = cell.previousSibling;
  22373. if(prev) {
  22374. // 最后一个单元格和前一个单元格的width diff结果 如果恰好为一个border width, 则条件成立
  22375. tab.offsetVal = cell.offsetWidth - prev.offsetWidth === UT.borderWidth ?
  22376. UT.borderWidth :
  22377. 0;
  22378. } else {
  22379. tab.offsetVal = 0;
  22380. }
  22381. }
  22382. return tab.offsetVal;
  22383. }
  22384. function getTabcellSpace() {
  22385. if(UT.tabcellSpace === undefined) {
  22386. var cell = null,
  22387. tab = me.document.createElement("table"),
  22388. tbody = me.document
  22389. .createElement("tbody"),
  22390. trow = me.document
  22391. .createElement("tr"),
  22392. tabcell = me.document
  22393. .createElement("td"),
  22394. mirror = null;
  22395. tabcell.style.cssText = 'border: 0;';
  22396. tabcell.width = 1;
  22397. trow.appendChild(tabcell);
  22398. trow.appendChild(mirror = tabcell.cloneNode(false));
  22399. tbody.appendChild(trow);
  22400. tab.appendChild(tbody);
  22401. tab.style.cssText = "visibility: hidden;";
  22402. me.body.appendChild(tab);
  22403. UT.paddingSpace = tabcell.offsetWidth - 1;
  22404. var tmpTabWidth = tab.offsetWidth;
  22405. tabcell.style.cssText = '';
  22406. mirror.style.cssText = '';
  22407. UT.borderWidth = (tab.offsetWidth - tmpTabWidth) / 3;
  22408. UT.tabcellSpace = UT.paddingSpace + UT.borderWidth;
  22409. me.body.removeChild(tab);
  22410. }
  22411. getTabcellSpace = function() {
  22412. return UT.tabcellSpace;
  22413. };
  22414. return UT.tabcellSpace;
  22415. }
  22416. function getDragLine(editor, doc) {
  22417. if(mousedown)
  22418. return;
  22419. dragLine = editor.document.createElement("div");
  22420. domUtils.setAttributes(dragLine, {
  22421. id: "ue_tableDragLine",
  22422. unselectable: 'on',
  22423. contenteditable: false,
  22424. 'onresizestart': 'return false',
  22425. 'ondragstart': 'return false',
  22426. 'onselectstart': 'return false',
  22427. style: "background-color:blue;position:absolute;padding:0;margin:0;background-image:none;border:0px none;opacity:0;filter:alpha(opacity=0)"
  22428. });
  22429. editor.body.appendChild(dragLine);
  22430. }
  22431. function hideDragLine(editor) {
  22432. if(mousedown)
  22433. return;
  22434. var line;
  22435. while(line = editor.document.getElementById('ue_tableDragLine')) {
  22436. domUtils.remove(line)
  22437. }
  22438. }
  22439. /**
  22440. * 依据state(v|h)在cell位置显示横线
  22441. *
  22442. * @param state
  22443. * @param cell
  22444. */
  22445. function showDragLineAt(state, cell) {
  22446. if(!cell)
  22447. return;
  22448. var table = domUtils.findParentByTagName(cell, "table"),
  22449. caption = table
  22450. .getElementsByTagName('caption'),
  22451. width = table.offsetWidth,
  22452. height = table.offsetHeight -
  22453. (caption.length > 0 ? caption[0].offsetHeight : 0),
  22454. tablePos = domUtils
  22455. .getXY(table),
  22456. cellPos = domUtils.getXY(cell),
  22457. css;
  22458. switch(state) {
  22459. case "h":
  22460. css = 'height:' +
  22461. height +
  22462. 'px;top:' +
  22463. (tablePos.y + (caption.length > 0 ?
  22464. caption[0].offsetHeight :
  22465. 0)) + 'px;left:' +
  22466. (cellPos.x + cell.offsetWidth);
  22467. dragLine.style.cssText = css +
  22468. 'px;position: absolute;display:block;background-color:blue;width:1px;border:0; color:blue;opacity:.3;filter:alpha(opacity=30)';
  22469. break;
  22470. case "v":
  22471. css = 'width:' + width + 'px;left:' + tablePos.x +
  22472. 'px;top:' + (cellPos.y + cell.offsetHeight);
  22473. // 必须加上border:0和color:blue,否则低版ie不支持背景色显示
  22474. dragLine.style.cssText = css +
  22475. 'px;overflow:hidden;position: absolute;display:block;background-color:blue;height:1px;border:0;color:blue;opacity:.2;filter:alpha(opacity=20)';
  22476. break;
  22477. default:
  22478. }
  22479. }
  22480. /**
  22481. * 当表格边框颜色为白色时设置为虚线,true为添加虚线
  22482. *
  22483. * @param editor
  22484. * @param flag
  22485. */
  22486. function switchBorderColor(editor, flag) {
  22487. var tableArr = domUtils.getElementsByTagName(editor.body, "table"),
  22488. color;
  22489. for(var i = 0, node; node = tableArr[i++];) {
  22490. var td = domUtils.getElementsByTagName(node, "td");
  22491. if(td[0]) {
  22492. if(flag) {
  22493. color = (td[0].style.borderColor).replace(/\s/g, "");
  22494. if(/(#ffffff)|(rgb\(255,255,255\))/ig.test(color))
  22495. domUtils.addClass(node, "noBorderTable")
  22496. } else {
  22497. domUtils.removeClasses(node, "noBorderTable")
  22498. }
  22499. }
  22500. }
  22501. }
  22502. function getTableWidth(editor, needIEHack, defaultValue) {
  22503. var body = editor.body;
  22504. return body.offsetWidth -
  22505. (needIEHack ? parseInt(domUtils.getComputedStyle(body,
  22506. 'margin-left'), 10) *
  22507. 2 : 0) - defaultValue.tableBorder * 2 -
  22508. (editor.options.offsetWidth || 0);
  22509. }
  22510. /**
  22511. * 获取当前拖动的单元格
  22512. */
  22513. function getTargetTd(editor, evt) {
  22514. var target = domUtils.findParentByTagName(evt.target ||
  22515. evt.srcElement, ["td", "th"], true),
  22516. dir = null;
  22517. if(!target) {
  22518. return null;
  22519. }
  22520. dir = getRelation(target, mouseCoords(evt));
  22521. // 如果有前一个节点, 需要做一个修正, 否则可能会得到一个错误的td
  22522. if(!target) {
  22523. return null;
  22524. }
  22525. if(dir === 'h1' && target.previousSibling) {
  22526. var position = domUtils.getXY(target),
  22527. cellWidth = target.offsetWidth;
  22528. if(Math.abs(position.x + cellWidth - evt.clientX) > cellWidth /
  22529. 3) {
  22530. target = target.previousSibling;
  22531. }
  22532. } else if(dir === 'v1' && target.parentNode.previousSibling) {
  22533. var position = domUtils.getXY(target),
  22534. cellHeight = target.offsetHeight;
  22535. if(Math.abs(position.y + cellHeight - evt.clientY) > cellHeight /
  22536. 3) {
  22537. target = target.parentNode.previousSibling.firstChild;
  22538. }
  22539. }
  22540. // 排除了非td内部以及用于代码高亮部分的td
  22541. return target &&
  22542. !(editor.fireEvent("excludetable", target) === true) ?
  22543. target :
  22544. null;
  22545. }
  22546. };
  22547. // plugins/table.sort.js
  22548. /**
  22549. * Created with JetBrains PhpStorm. User: Jinqn Date: 13-10-12 Time: 上午10:20
  22550. * To change this template use File | Settings | File Templates.
  22551. */
  22552. UE.UETable.prototype.sortTable = function(sortByCellIndex, compareFn) {
  22553. var table = this.table,
  22554. rows = table.rows,
  22555. trArray = [],
  22556. flag = rows[0].cells[0].tagName === "TH",
  22557. lastRowIndex = 0;
  22558. if(this.selectedTds.length) {
  22559. var range = this.cellsRange,
  22560. len = range.endRowIndex + 1;
  22561. for(var i = range.beginRowIndex; i < len; i++) {
  22562. trArray[i] = rows[i];
  22563. }
  22564. trArray.splice(0, range.beginRowIndex);
  22565. lastRowIndex = (range.endRowIndex + 1) === this.rowsNum ?
  22566. 0 :
  22567. range.endRowIndex + 1;
  22568. } else {
  22569. for(var i = 0, len = rows.length; i < len; i++) {
  22570. trArray[i] = rows[i];
  22571. }
  22572. }
  22573. var Fn = {
  22574. 'reversecurrent': function(td1, td2) {
  22575. return 1;
  22576. },
  22577. 'orderbyasc': function(td1, td2) {
  22578. var value1 = td1.innerText || td1.textContent,
  22579. value2 = td2.innerText ||
  22580. td2.textContent;
  22581. return value1.localeCompare(value2);
  22582. },
  22583. 'reversebyasc': function(td1, td2) {
  22584. var value1 = td1.innerHTML,
  22585. value2 = td2.innerHTML;
  22586. return value2.localeCompare(value1);
  22587. },
  22588. 'orderbynum': function(td1, td2) {
  22589. var value1 = td1[browser.ie ? 'innerText' : 'textContent']
  22590. .match(/\d+/),
  22591. value2 = td2[browser.ie ?
  22592. 'innerText' :
  22593. 'textContent'].match(/\d+/);
  22594. if(value1)
  22595. value1 = +value1[0];
  22596. if(value2)
  22597. value2 = +value2[0];
  22598. return(value1 || 0) - (value2 || 0);
  22599. },
  22600. 'reversebynum': function(td1, td2) {
  22601. var value1 = td1[browser.ie ? 'innerText' : 'textContent']
  22602. .match(/\d+/),
  22603. value2 = td2[browser.ie ?
  22604. 'innerText' :
  22605. 'textContent'].match(/\d+/);
  22606. if(value1)
  22607. value1 = +value1[0];
  22608. if(value2)
  22609. value2 = +value2[0];
  22610. return(value2 || 0) - (value1 || 0);
  22611. }
  22612. };
  22613. // 对表格设置排序的标记data-sort-type
  22614. table.setAttribute('data-sort-type', compareFn &&
  22615. typeof compareFn === "string" && Fn[compareFn] ?
  22616. compareFn :
  22617. '');
  22618. // th不参与排序
  22619. flag && trArray.splice(0, 1);
  22620. trArray = utils.sort(trArray, function(tr1, tr2) {
  22621. var result;
  22622. if(compareFn && typeof compareFn === "function") {
  22623. result = compareFn.call(this, tr1.cells[sortByCellIndex],
  22624. tr2.cells[sortByCellIndex]);
  22625. } else if(compareFn && typeof compareFn === "number") {
  22626. result = 1;
  22627. } else if(compareFn && typeof compareFn === "string" &&
  22628. Fn[compareFn]) {
  22629. result = Fn[compareFn].call(this, tr1.cells[sortByCellIndex],
  22630. tr2.cells[sortByCellIndex]);
  22631. } else {
  22632. result = Fn['orderbyasc'].call(this,
  22633. tr1.cells[sortByCellIndex], tr2.cells[sortByCellIndex]);
  22634. }
  22635. return result;
  22636. });
  22637. var fragment = table.ownerDocument.createDocumentFragment();
  22638. for(var j = 0, len = trArray.length; j < len; j++) {
  22639. fragment.appendChild(trArray[j]);
  22640. }
  22641. var tbody = table.getElementsByTagName("tbody")[0];
  22642. if(!lastRowIndex) {
  22643. tbody.appendChild(fragment);
  22644. } else {
  22645. tbody.insertBefore(fragment, rows[lastRowIndex - range.endRowIndex +
  22646. range.beginRowIndex - 1])
  22647. }
  22648. };
  22649. UE.plugins['tablesort'] = function() {
  22650. var me = this,
  22651. UT = UE.UETable,
  22652. getUETable = function(tdOrTable) {
  22653. return UT.getUETable(tdOrTable);
  22654. },
  22655. getTableItemsByRange = function(editor) {
  22656. return UT.getTableItemsByRange(editor);
  22657. };
  22658. me.ready(function() {
  22659. // 添加表格可排序的样式
  22660. utils
  22661. .cssRule(
  22662. 'tablesort',
  22663. 'table.sortEnabled tr.firstRow th,table.sortEnabled tr.firstRow td{padding-right:20px;background-repeat: no-repeat;background-position: center right;' +
  22664. ' background-image:url(' +
  22665. me.options.themePath +
  22666. me.options.theme +
  22667. '/images/sortable.png);}', me.document);
  22668. // 做单元格合并操作时,清除可排序标识
  22669. me.addListener("afterexeccommand", function(type, cmd) {
  22670. if(cmd == 'mergeright' || cmd == 'mergedown' ||
  22671. cmd == 'mergecells') {
  22672. this.execCommand('disablesort');
  22673. }
  22674. });
  22675. });
  22676. // 表格排序
  22677. UE.commands['sorttable'] = {
  22678. queryCommandState: function() {
  22679. var me = this,
  22680. tableItems = getTableItemsByRange(me);
  22681. if(!tableItems.cell)
  22682. return -1;
  22683. var table = tableItems.table,
  22684. cells = table
  22685. .getElementsByTagName("td");
  22686. for(var i = 0, cell; cell = cells[i++];) {
  22687. if(cell.rowSpan != 1 || cell.colSpan != 1)
  22688. return -1;
  22689. }
  22690. return 0;
  22691. },
  22692. execCommand: function(cmd, fn) {
  22693. var me = this,
  22694. range = me.selection.getRange(),
  22695. bk = range
  22696. .createBookmark(true),
  22697. tableItems = getTableItemsByRange(me),
  22698. cell = tableItems.cell,
  22699. ut = getUETable(tableItems.table),
  22700. cellInfo = ut
  22701. .getCellInfo(cell);
  22702. ut.sortTable(cellInfo.cellIndex, fn);
  22703. range.moveToBookmark(bk);
  22704. try {
  22705. range.select();
  22706. } catch(e) {}
  22707. }
  22708. };
  22709. // 设置表格可排序,清除表格可排序
  22710. UE.commands["enablesort"] = UE.commands["disablesort"] = {
  22711. queryCommandState: function(cmd) {
  22712. var table = getTableItemsByRange(this).table;
  22713. if(table && cmd == 'enablesort') {
  22714. var cells = domUtils.getElementsByTagName(table, 'th td');
  22715. for(var i = 0; i < cells.length; i++) {
  22716. if(cells[i].getAttribute('colspan') > 1 ||
  22717. cells[i].getAttribute('rowspan') > 1)
  22718. return -1;
  22719. }
  22720. }
  22721. return !table ? -1 : cmd == 'enablesort' ^
  22722. table.getAttribute('data-sort') != 'sortEnabled' ?
  22723. -1 :
  22724. 0;
  22725. },
  22726. execCommand: function(cmd) {
  22727. var table = getTableItemsByRange(this).table;
  22728. table.setAttribute("data-sort", cmd == "enablesort" ?
  22729. "sortEnabled" :
  22730. "sortDisabled");
  22731. table.setAttribute("style", "border-collapse:collapse;"); // 2016.11.18
  22732. // 2:08新增
  22733. cmd == "enablesort" ?
  22734. domUtils.addClass(table, "sortEnabled") :
  22735. domUtils.removeClasses(table, "sortEnabled");
  22736. }
  22737. };
  22738. };
  22739. // plugins/contextmenu.js
  22740. // /import core
  22741. // /commands 右键菜单
  22742. // /commandsName ContextMenu
  22743. // /commandsTitle 右键菜单
  22744. /**
  22745. * 右键菜单
  22746. *
  22747. * @function
  22748. * @name baidu.editor.plugins.contextmenu
  22749. * @author zhanyi
  22750. */
  22751. UE.plugins['contextmenu'] = function() {
  22752. var me = this;
  22753. me.setOpt('enableContextMenu', true);
  22754. if(me.getOpt('enableContextMenu') === false) {
  22755. return;
  22756. }
  22757. var lang = me.getLang("contextMenu"),
  22758. menu, items = me.options.contextMenu || [{
  22759. label: lang['selectall'],
  22760. cmdName: 'selectall'
  22761. }, {
  22762. label: lang.cleardoc,
  22763. cmdName: 'cleardoc',
  22764. exec: function() {
  22765. if(confirm(lang.confirmclear)) {
  22766. this.execCommand('cleardoc');
  22767. }
  22768. }
  22769. }, '-', {
  22770. label: lang.unlink,
  22771. cmdName: 'unlink'
  22772. }, '-', {
  22773. group: lang.paragraph,
  22774. icon: 'justifyjustify',
  22775. subMenu: [{
  22776. label: lang.justifyleft,
  22777. cmdName: 'justify',
  22778. value: 'left'
  22779. }, {
  22780. label: lang.justifyright,
  22781. cmdName: 'justify',
  22782. value: 'right'
  22783. }, {
  22784. label: lang.justifycenter,
  22785. cmdName: 'justify',
  22786. value: 'center'
  22787. }, {
  22788. label: lang.justifyjustify,
  22789. cmdName: 'justify',
  22790. value: 'justify'
  22791. }]
  22792. }, '-', {
  22793. group: lang.table,
  22794. icon: 'table',
  22795. subMenu: [{
  22796. label: lang.setbordervisible,
  22797. cmdName: 'setbordervisible'
  22798. }, {
  22799. label: lang.inserttable,
  22800. cmdName: 'inserttable'
  22801. }, {
  22802. label: lang.deletetable,
  22803. cmdName: 'deletetable'
  22804. }, '-', {
  22805. label: lang.deleterow,
  22806. cmdName: 'deleterow'
  22807. }, {
  22808. label: lang.deletecol,
  22809. cmdName: 'deletecol'
  22810. }, {
  22811. label: lang.insertcol,
  22812. cmdName: 'insertcol'
  22813. }, {
  22814. label: lang.insertcolnext,
  22815. cmdName: 'insertcolnext'
  22816. }, {
  22817. label: lang.insertrow,
  22818. cmdName: 'insertrow'
  22819. }, {
  22820. label: lang.insertrownext,
  22821. cmdName: 'insertrownext'
  22822. },
  22823. // '-',
  22824. // {1
  22825. // label: lang.insertcaption,
  22826. // cmdName: 'insertcaption'
  22827. // }, {
  22828. // label: lang.deletecaption,
  22829. // cmdName: 'deletecaption'
  22830. // }, {
  22831. // label: lang.inserttitle,
  22832. // cmdName: 'inserttitle'
  22833. // }, {
  22834. // label: lang.deletetitle,
  22835. // cmdName: 'deletetitle'
  22836. // }, {
  22837. // label: lang.inserttitlecol,
  22838. // cmdName: 'inserttitlecol'
  22839. // }, {
  22840. // label: lang.deletetitlecol,
  22841. // cmdName: 'deletetitlecol'
  22842. // },
  22843. '-', {
  22844. label: lang.mergecells,
  22845. cmdName: 'mergecells'
  22846. }, {
  22847. label: lang.mergeright,
  22848. cmdName: 'mergeright'
  22849. }, {
  22850. label: lang.mergedown,
  22851. cmdName: 'mergedown'
  22852. }, '-', {
  22853. label: lang.splittorows,
  22854. cmdName: 'splittorows'
  22855. }, {
  22856. label: lang.splittocols,
  22857. cmdName: 'splittocols'
  22858. }, {
  22859. label: lang.splittocells,
  22860. cmdName: 'splittocells'
  22861. }, '-', {
  22862. label: lang.averageDiseRow,
  22863. cmdName: 'averagedistributerow'
  22864. }, {
  22865. label: lang.averageDisCol,
  22866. cmdName: 'averagedistributecol'
  22867. }, '-', {
  22868. label: lang.edittd,
  22869. cmdName: 'edittd',
  22870. exec: function() {
  22871. if(UE.ui['edittd']) {
  22872. new UE.ui['edittd'](this);
  22873. }
  22874. this.getDialog('edittd').open();
  22875. }
  22876. }, {
  22877. label: lang.edittable,
  22878. cmdName: 'edittable',
  22879. exec: function() {
  22880. if(UE.ui['edittable']) {
  22881. new UE.ui['edittable'](this);
  22882. }
  22883. this.getDialog('edittable').open();
  22884. }
  22885. }
  22886. ]
  22887. }, {
  22888. group: lang.tablesort,
  22889. icon: 'tablesort',
  22890. subMenu: [{
  22891. label: lang.enablesort,
  22892. cmdName: 'enablesort'
  22893. }, {
  22894. label: lang.disablesort,
  22895. cmdName: 'disablesort'
  22896. }, '-', {
  22897. label: lang.reversecurrent,
  22898. cmdName: 'sorttable',
  22899. value: 'reversecurrent'
  22900. }, {
  22901. label: lang.orderbyasc,
  22902. cmdName: 'sorttable',
  22903. value: 'orderbyasc'
  22904. }, {
  22905. label: lang.reversebyasc,
  22906. cmdName: 'sorttable',
  22907. value: 'reversebyasc'
  22908. }, {
  22909. label: lang.orderbynum,
  22910. cmdName: 'sorttable',
  22911. value: 'orderbynum'
  22912. }, {
  22913. label: lang.reversebynum,
  22914. cmdName: 'sorttable',
  22915. value: 'reversebynum'
  22916. }]
  22917. }, {
  22918. group: lang.borderbk,
  22919. icon: 'borderBack',
  22920. subMenu: [{
  22921. label: lang.setcolor,
  22922. cmdName: "interlacetable",
  22923. exec: function() {
  22924. this.execCommand("interlacetable");
  22925. }
  22926. }, {
  22927. label: lang.unsetcolor,
  22928. cmdName: "uninterlacetable",
  22929. exec: function() {
  22930. this.execCommand("uninterlacetable");
  22931. }
  22932. }, {
  22933. label: lang.setbackground,
  22934. cmdName: "settablebackground",
  22935. exec: function() {
  22936. this.execCommand("settablebackground", {
  22937. repeat: true,
  22938. colorList: ["#bbb", "#ccc"]
  22939. });
  22940. }
  22941. }, {
  22942. label: lang.unsetbackground,
  22943. cmdName: "cleartablebackground",
  22944. exec: function() {
  22945. this.execCommand("cleartablebackground");
  22946. }
  22947. }, {
  22948. label: lang.redandblue,
  22949. cmdName: "settablebackground",
  22950. exec: function() {
  22951. this.execCommand("settablebackground", {
  22952. repeat: true,
  22953. colorList: ["red", "blue"]
  22954. });
  22955. }
  22956. }, {
  22957. label: lang.threecolorgradient,
  22958. cmdName: "settablebackground",
  22959. exec: function() {
  22960. this.execCommand("settablebackground", {
  22961. repeat: true,
  22962. colorList: ["#aaa", "#bbb", "#ccc"]
  22963. });
  22964. }
  22965. }]
  22966. }, {
  22967. group: lang.aligntd,
  22968. icon: 'aligntd',
  22969. subMenu: [{
  22970. cmdName: 'cellalignment',
  22971. value: {
  22972. align: 'left',
  22973. vAlign: 'top'
  22974. }
  22975. }, {
  22976. cmdName: 'cellalignment',
  22977. value: {
  22978. align: 'center',
  22979. vAlign: 'top'
  22980. }
  22981. }, {
  22982. cmdName: 'cellalignment',
  22983. value: {
  22984. align: 'right',
  22985. vAlign: 'top'
  22986. }
  22987. }, {
  22988. cmdName: 'cellalignment',
  22989. value: {
  22990. align: 'left',
  22991. vAlign: 'middle'
  22992. }
  22993. }, {
  22994. cmdName: 'cellalignment',
  22995. value: {
  22996. align: 'center',
  22997. vAlign: 'middle'
  22998. }
  22999. }, {
  23000. cmdName: 'cellalignment',
  23001. value: {
  23002. align: 'right',
  23003. vAlign: 'middle'
  23004. }
  23005. }, {
  23006. cmdName: 'cellalignment',
  23007. value: {
  23008. align: 'left',
  23009. vAlign: 'bottom'
  23010. }
  23011. }, {
  23012. cmdName: 'cellalignment',
  23013. value: {
  23014. align: 'center',
  23015. vAlign: 'bottom'
  23016. }
  23017. }, {
  23018. cmdName: 'cellalignment',
  23019. value: {
  23020. align: 'right',
  23021. vAlign: 'bottom'
  23022. }
  23023. }]
  23024. }, {
  23025. group: lang.aligntable,
  23026. icon: 'aligntable',
  23027. subMenu: [{
  23028. cmdName: 'tablealignment',
  23029. className: 'left',
  23030. label: lang.tableleft,
  23031. value: "left"
  23032. }, {
  23033. cmdName: 'tablealignment',
  23034. className: 'center',
  23035. label: lang.tablecenter,
  23036. value: "center"
  23037. }, {
  23038. cmdName: 'tablealignment',
  23039. className: 'right',
  23040. label: lang.tableright,
  23041. value: "right"
  23042. }]
  23043. }, '-', {
  23044. label: lang.insertparagraphbefore,
  23045. cmdName: 'insertparagraph',
  23046. value: true
  23047. }, {
  23048. label: lang.insertparagraphafter,
  23049. cmdName: 'insertparagraph'
  23050. },
  23051. // {
  23052. // label: lang['copy'],
  23053. // cmdName: 'copy'
  23054. // }, {
  23055. // label: lang['paste'],
  23056. // cmdName: 'paste'
  23057. // }
  23058. ];
  23059. if(!items.length) {
  23060. return;
  23061. }
  23062. var uiUtils = UE.ui.uiUtils;
  23063. me.addListener('contextmenu', function(type, evt) {
  23064. var offset = uiUtils.getViewportOffsetByEvent(evt);
  23065. me.fireEvent('beforeselectionchange');
  23066. if(menu) {
  23067. menu.destroy();
  23068. }
  23069. for(var i = 0, ti, contextItems = []; ti = items[i]; i++) {
  23070. var last;
  23071. (function(item) {
  23072. if(item == '-') {
  23073. if((last = contextItems[contextItems.length - 1]) &&
  23074. last !== '-') {
  23075. contextItems.push('-');
  23076. }
  23077. } else if(item.hasOwnProperty("group")) {
  23078. for(var j = 0, cj, subMenu = []; cj = item.subMenu[j]; j++) {
  23079. (function(subItem) {
  23080. if(subItem == '-') {
  23081. if((last = subMenu[subMenu.length - 1]) &&
  23082. last !== '-') {
  23083. subMenu.push('-');
  23084. } else {
  23085. subMenu.splice(subMenu.length - 1);
  23086. }
  23087. } else {
  23088. if((me.commands[subItem.cmdName] ||
  23089. UE.commands[subItem.cmdName] || subItem.query) &&
  23090. (subItem.query ?
  23091. subItem.query() :
  23092. me
  23093. .queryCommandState(subItem.cmdName)) > -1) {
  23094. subMenu.push({
  23095. 'label': subItem.label ||
  23096. me
  23097. .getLang("contextMenu." +
  23098. subItem.cmdName +
  23099. (subItem.value || '')) ||
  23100. "",
  23101. 'className': 'edui-for-' +
  23102. subItem.cmdName +
  23103. (subItem.className ?
  23104. (' edui-for-' +
  23105. subItem.cmdName +
  23106. '-' + subItem.className) :
  23107. ''),
  23108. onclick: subItem.exec ?
  23109. function() {
  23110. subItem.exec.call(me);
  23111. } : function() {
  23112. me
  23113. .execCommand(
  23114. subItem.cmdName,
  23115. subItem.value);
  23116. }
  23117. });
  23118. }
  23119. }
  23120. })(cj);
  23121. }
  23122. if(subMenu.length) {
  23123. function getLabel() {
  23124. switch(item.icon) {
  23125. case "table":
  23126. return me.getLang("contextMenu.table");
  23127. case "justifyjustify":
  23128. return me
  23129. .getLang("contextMenu.paragraph");
  23130. case "aligntd":
  23131. return me
  23132. .getLang("contextMenu.aligntd");
  23133. case "aligntable":
  23134. return me
  23135. .getLang("contextMenu.aligntable");
  23136. case "tablesort":
  23137. return lang.tablesort;
  23138. case "borderBack":
  23139. return lang.borderbk;
  23140. default:
  23141. return '';
  23142. }
  23143. }
  23144. contextItems.push({
  23145. // todo 修正成自动获取方式
  23146. 'label': getLabel(),
  23147. className: 'edui-for-' + item.icon,
  23148. 'subMenu': {
  23149. items: subMenu,
  23150. editor: me
  23151. }
  23152. });
  23153. }
  23154. } else {
  23155. // 有可能commmand没有加载右键不能出来,或者没有command也想能展示出来添加query方法
  23156. if((me.commands[item.cmdName] ||
  23157. UE.commands[item.cmdName] || item.query) &&
  23158. (item.query ? item.query.call(me) : me
  23159. .queryCommandState(item.cmdName)) > -1) {
  23160. contextItems.push({
  23161. 'label': item.label ||
  23162. me.getLang("contextMenu." +
  23163. item.cmdName),
  23164. className: 'edui-for-' +
  23165. (item.icon ? item.icon : item.cmdName +
  23166. (item.value || '')),
  23167. onclick: item.exec ? function() {
  23168. item.exec.call(me);
  23169. } : function() {
  23170. me.execCommand(item.cmdName, item.value);
  23171. }
  23172. });
  23173. }
  23174. }
  23175. })(ti);
  23176. }
  23177. if(contextItems[contextItems.length - 1] == '-') {
  23178. contextItems.pop();
  23179. }
  23180. menu = new UE.ui.Menu({
  23181. items: contextItems,
  23182. className: "edui-contextmenu",
  23183. editor: me
  23184. });
  23185. menu.render();
  23186. menu.showAt(offset);
  23187. me.fireEvent("aftershowcontextmenu", menu);
  23188. domUtils.preventDefault(evt);
  23189. if(browser.ie) {
  23190. var ieRange;
  23191. try {
  23192. ieRange = me.selection.getNative().createRange();
  23193. } catch(e) {
  23194. return;
  23195. }
  23196. if(ieRange.item) {
  23197. var range = new dom.Range(me.document);
  23198. range.selectNode(ieRange.item(0)).select(true, true);
  23199. }
  23200. }
  23201. });
  23202. // 添加复制的flash按钮
  23203. me.addListener('aftershowcontextmenu', function(type, menu) {
  23204. if(me.zeroclipboard) {
  23205. var items = menu.items;
  23206. for(var key in items) {
  23207. if(items[key].className == 'edui-for-copy') {
  23208. me.zeroclipboard.clip(items[key].getDom());
  23209. }
  23210. }
  23211. }
  23212. });
  23213. };
  23214. // plugins/shortcutmenu.js
  23215. // /import core
  23216. // /commands 弹出菜单
  23217. // commandsName popupmenu
  23218. // /commandsTitle 弹出菜单
  23219. /**
  23220. * 弹出菜单
  23221. *
  23222. * @function
  23223. * @name baidu.editor.plugins.popupmenu
  23224. * @author xuheng
  23225. */
  23226. UE.plugins['shortcutmenu'] = function() {
  23227. var me = this,
  23228. menu, items = me.options.shortcutMenu || [];
  23229. if(!items.length) {
  23230. return;
  23231. }
  23232. me.addListener('contextmenu mouseup', function(type, e) {
  23233. var me = this,
  23234. customEvt = {
  23235. type: type,
  23236. target: e.target || e.srcElement,
  23237. screenX: e.screenX,
  23238. screenY: e.screenY,
  23239. clientX: e.clientX,
  23240. clientY: e.clientY
  23241. };
  23242. setTimeout(function() {
  23243. var rng = me.selection.getRange();
  23244. if(rng.collapsed === false || type == "contextmenu") {
  23245. if(!menu) {
  23246. menu = new baidu.editor.ui.ShortCutMenu({
  23247. editor: me,
  23248. items: items,
  23249. theme: me.options.theme,
  23250. className: 'edui-shortcutmenu'
  23251. });
  23252. menu.render();
  23253. me.fireEvent("afterrendershortcutmenu", menu);
  23254. }
  23255. menu.show(customEvt, !!UE.plugins['contextmenu']);
  23256. }
  23257. });
  23258. if(type == 'contextmenu') {
  23259. domUtils.preventDefault(e);
  23260. if(browser.ie9below) {
  23261. var ieRange;
  23262. try {
  23263. ieRange = me.selection.getNative().createRange();
  23264. } catch(e) {
  23265. return;
  23266. }
  23267. if(ieRange.item) {
  23268. var range = new dom.Range(me.document);
  23269. range.selectNode(ieRange.item(0)).select(true, true);
  23270. }
  23271. }
  23272. }
  23273. });
  23274. me.addListener('keydown', function(type) {
  23275. if(type == "keydown") {
  23276. menu && !menu.isHidden && menu.hide();
  23277. }
  23278. });
  23279. };
  23280. // plugins/basestyle.js
  23281. /**
  23282. * B、I、sub、super命令支持
  23283. *
  23284. * @file
  23285. * @since 1.2.6.1
  23286. */
  23287. UE.plugins['basestyle'] = function() {
  23288. /**
  23289. * 字体加粗
  23290. *
  23291. * @command bold
  23292. * @param {
  23293. * String } cmd 命令字符串
  23294. * @remind 对已加粗的文本内容执行该命令, 将取消加粗
  23295. * @method execCommand
  23296. * @example ```javascript //editor是编辑器实例 //对当前选中的文本内容执行加粗操作 //第一次执行,
  23297. * 文本内容加粗 editor.execCommand( 'bold' );
  23298. *
  23299. * //第二次执行, 文本内容取消加粗 editor.execCommand( 'bold' ); ```
  23300. */
  23301. /**
  23302. * 字体倾斜
  23303. *
  23304. * @command italic
  23305. * @method execCommand
  23306. * @param {
  23307. * String } cmd 命令字符串
  23308. * @remind 对已倾斜的文本内容执行该命令, 将取消倾斜
  23309. * @example ```javascript //editor是编辑器实例 //对当前选中的文本内容执行斜体操作 //第一次操作,
  23310. * 文本内容将变成斜体 editor.execCommand( 'italic' );
  23311. *
  23312. * //再次对同一文本内容执行, 则文本内容将恢复正常 editor.execCommand( 'italic' ); ```
  23313. */
  23314. /**
  23315. * 下标文本,与“superscript”命令互斥
  23316. *
  23317. * @command subscript
  23318. * @method execCommand
  23319. * @remind 把选中的文本内容切换成下标文本, 如果当前选中的文本已经是下标, 则该操作会把文本内容还原成正常文本
  23320. * @param {
  23321. * String } cmd 命令字符串
  23322. * @example ```javascript //editor是编辑器实例 //对当前选中的文本内容执行下标操作 //第一次操作,
  23323. * 文本内容将变成下标文本 editor.execCommand( 'subscript' );
  23324. *
  23325. * //再次对同一文本内容执行, 则文本内容将恢复正常 editor.execCommand( 'subscript' ); ```
  23326. */
  23327. /**
  23328. * 上标文本,与“subscript”命令互斥
  23329. *
  23330. * @command superscript
  23331. * @method execCommand
  23332. * @remind 把选中的文本内容切换成上标文本, 如果当前选中的文本已经是上标, 则该操作会把文本内容还原成正常文本
  23333. * @param {
  23334. * String } cmd 命令字符串
  23335. * @example ```javascript //editor是编辑器实例 //对当前选中的文本内容执行上标操作 //第一次操作,
  23336. * 文本内容将变成上标文本 editor.execCommand( 'superscript' );
  23337. *
  23338. * //再次对同一文本内容执行, 则文本内容将恢复正常 editor.execCommand( 'superscript' ); ```
  23339. */
  23340. var basestyles = {
  23341. 'bold': ['strong', 'b'],
  23342. 'italic': ['em', 'i'],
  23343. 'underline': ['u'],
  23344. 'subscript': ['sub'],
  23345. 'superscript': ['sup']
  23346. },
  23347. getObj = function(editor, tagNames) {
  23348. return domUtils.filterNodeList(editor.selection
  23349. .getStartElementPath(), tagNames);
  23350. },
  23351. me = this;
  23352. // 添加快捷键
  23353. me.addshortcutkey({
  23354. "Bold": "ctrl+66", // ^B
  23355. "Italic": "ctrl+73", // ^I
  23356. "Underline": "ctrl+85" // ^U
  23357. });
  23358. me.addInputRule(function(root) {
  23359. utils.each(root.getNodesByTagName('b i'), function(node) {
  23360. switch(node.tagName) {
  23361. case 'b':
  23362. node.tagName = 'strong';
  23363. break;
  23364. case 'i':
  23365. node.tagName = 'em';
  23366. }
  23367. });
  23368. });
  23369. for(var style in basestyles) {
  23370. (function(cmd, tagNames) {
  23371. me.commands[cmd] = {
  23372. execCommand: function(cmdName) {
  23373. var range = me.selection.getRange(),
  23374. obj = getObj(this,
  23375. tagNames);
  23376. if(range.collapsed) {
  23377. if(obj) {
  23378. var tmpText = me.document.createTextNode('');
  23379. range.insertNode(tmpText)
  23380. .removeInlineStyle(tagNames);
  23381. range.setStartBefore(tmpText);
  23382. domUtils.remove(tmpText);
  23383. } else {
  23384. var tmpNode = range.document
  23385. .createElement(tagNames[0]);
  23386. if(cmdName == 'superscript' ||
  23387. cmdName == 'subscript') {
  23388. tmpText = me.document.createTextNode('');
  23389. range.insertNode(tmpText)
  23390. .removeInlineStyle(['sub', 'sup'])
  23391. .setStartBefore(tmpText)
  23392. .collapse(true);
  23393. }
  23394. range.insertNode(tmpNode).setStart(tmpNode, 0);
  23395. }
  23396. range.collapse(true);
  23397. } else {
  23398. if(cmdName == 'superscript' ||
  23399. cmdName == 'subscript') {
  23400. if(!obj ||
  23401. obj.tagName.toLowerCase() != cmdName) {
  23402. range.removeInlineStyle(['sub', 'sup']);
  23403. }
  23404. }
  23405. obj ? range.removeInlineStyle(tagNames) : range
  23406. .applyInlineStyle(tagNames[0]);
  23407. }
  23408. range.select();
  23409. },
  23410. queryCommandState: function() {
  23411. return getObj(this, tagNames) ? 1 : 0;
  23412. }
  23413. };
  23414. })(style, basestyles[style]);
  23415. }
  23416. };
  23417. // plugins/elementpath.js
  23418. /**
  23419. * 选取路径命令
  23420. *
  23421. * @file
  23422. */
  23423. UE.plugins['elementpath'] = function() {
  23424. var currentLevel, tagNames, me = this;
  23425. me.setOpt('elementPathEnabled', true);
  23426. if(!me.options.elementPathEnabled) {
  23427. return;
  23428. }
  23429. me.commands['elementpath'] = {
  23430. execCommand: function(cmdName, level) {
  23431. var start = tagNames[level],
  23432. range = me.selection.getRange();
  23433. currentLevel = level * 1;
  23434. range.selectNode(start).select();
  23435. },
  23436. queryCommandValue: function() {
  23437. // 产生一个副本,不能修改原来的startElementPath;
  23438. var parents = [].concat(this.selection.getStartElementPath())
  23439. .reverse(),
  23440. names = [];
  23441. tagNames = parents;
  23442. for(var i = 0, ci; ci = parents[i]; i++) {
  23443. if(ci.nodeType == 3) {
  23444. continue;
  23445. }
  23446. var name = ci.tagName.toLowerCase();
  23447. if(name == 'img' && ci.getAttribute('anchorname')) {
  23448. name = 'anchor';
  23449. }
  23450. names[i] = name;
  23451. if(currentLevel == i) {
  23452. currentLevel = -1;
  23453. break;
  23454. }
  23455. }
  23456. return names;
  23457. }
  23458. };
  23459. };
  23460. // plugins/formatmatch.js
  23461. /**
  23462. * 格式刷,只格式inline的
  23463. *
  23464. * @file
  23465. * @since 1.2.6.1
  23466. */
  23467. /**
  23468. * 格式刷
  23469. *
  23470. * @command formatmatch
  23471. * @method execCommand
  23472. * @remind 该操作不能复制段落格式
  23473. * @param {
  23474. * String } cmd 命令字符串
  23475. * @example ```javascript //editor是编辑器实例 //获取格式刷 editor.execCommand(
  23476. * 'formatmatch' ); ```
  23477. */
  23478. UE.plugins['formatmatch'] = function() {
  23479. var me = this,
  23480. list = [],
  23481. img, flag = 0;
  23482. me.addListener('reset', function() {
  23483. list = [];
  23484. flag = 0;
  23485. });
  23486. function addList(type, evt) {
  23487. if(browser.webkit) {
  23488. var target = evt.target.tagName == 'IMG' ? evt.target : null;
  23489. }
  23490. function addFormat(range) {
  23491. if(text) {
  23492. range.selectNode(text);
  23493. }
  23494. return range.applyInlineStyle(list[list.length - 1].tagName,
  23495. null, list);
  23496. }
  23497. me.undoManger && me.undoManger.save();
  23498. var range = me.selection.getRange(),
  23499. imgT = target ||
  23500. range.getClosedNode();
  23501. if(img && imgT && imgT.tagName == 'IMG') {
  23502. // trace:964
  23503. imgT.style.cssText += ';float:' +
  23504. (img.style.cssFloat || img.style.styleFloat || 'none') +
  23505. ';display:' + (img.style.display || 'inline');
  23506. img = null;
  23507. } else {
  23508. if(!img) {
  23509. var collapsed = range.collapsed;
  23510. if(collapsed) {
  23511. var text = me.document.createTextNode('match');
  23512. range.insertNode(text).select();
  23513. }
  23514. me.__hasEnterExecCommand = true;
  23515. // 不能把block上的属性干掉
  23516. // trace:1553
  23517. var removeFormatAttributes = me.options.removeFormatAttributes;
  23518. me.options.removeFormatAttributes = '';
  23519. me.execCommand('removeformat');
  23520. me.options.removeFormatAttributes = removeFormatAttributes;
  23521. me.__hasEnterExecCommand = false;
  23522. // trace:969
  23523. range = me.selection.getRange();
  23524. if(list.length) {
  23525. addFormat(range);
  23526. }
  23527. if(text) {
  23528. range.setStartBefore(text).collapse(true);
  23529. }
  23530. range.select();
  23531. text && domUtils.remove(text);
  23532. }
  23533. }
  23534. me.undoManger && me.undoManger.save();
  23535. me.removeListener('mouseup', addList);
  23536. flag = 0;
  23537. }
  23538. me.commands['formatmatch'] = {
  23539. execCommand: function(cmdName) {
  23540. if(flag) {
  23541. flag = 0;
  23542. list = [];
  23543. me.removeListener('mouseup', addList);
  23544. return;
  23545. }
  23546. var range = me.selection.getRange();
  23547. img = range.getClosedNode();
  23548. if(!img || img.tagName != 'IMG') {
  23549. range.collapse(true).shrinkBoundary();
  23550. var start = range.startContainer;
  23551. list = domUtils.findParents(start, true, function(node) {
  23552. return !domUtils.isBlockElm(node) && node.nodeType == 1;
  23553. });
  23554. // a不能加入格式刷, 并且克隆节点
  23555. for(var i = 0, ci; ci = list[i]; i++) {
  23556. if(ci.tagName == 'A') {
  23557. list.splice(i, 1);
  23558. break;
  23559. }
  23560. }
  23561. }
  23562. me.addListener('mouseup', addList);
  23563. flag = 1;
  23564. },
  23565. queryCommandState: function() {
  23566. return flag;
  23567. },
  23568. notNeedUndo: 1
  23569. };
  23570. };
  23571. // plugins/searchreplace.js
  23572. // /import core
  23573. // /commands 查找替换
  23574. // /commandsName SearchReplace
  23575. // /commandsTitle 查询替换
  23576. // /commandsDialog dialogs\searchreplace
  23577. /**
  23578. * @description 查找替换
  23579. * @author zhanyi
  23580. */
  23581. UE.plugin.register('searchreplace', function() {
  23582. var me = this;
  23583. var _blockElm = {
  23584. 'table': 1,
  23585. 'tbody': 1,
  23586. 'tr': 1,
  23587. 'ol': 1,
  23588. 'ul': 1
  23589. };
  23590. function findTextInString(textContent, opt, currentIndex) {
  23591. var str = opt.searchStr;
  23592. if(opt.dir == -1) {
  23593. textContent = textContent.split('').reverse().join('');
  23594. str = str.split('').reverse().join('');
  23595. currentIndex = textContent.length - currentIndex;
  23596. }
  23597. var reg = new RegExp(str, 'g' + (opt.casesensitive ? '' : 'i')),
  23598. match;
  23599. while(match = reg.exec(textContent)) {
  23600. if(match.index >= currentIndex) {
  23601. return opt.dir == -1 ? textContent.length - match.index -
  23602. opt.searchStr.length : match.index;
  23603. }
  23604. }
  23605. return -1
  23606. }
  23607. function findTextBlockElm(node, currentIndex, opt) {
  23608. var textContent, index, methodName = opt.all || opt.dir == 1 ?
  23609. 'getNextDomNode' :
  23610. 'getPreDomNode';
  23611. if(domUtils.isBody(node)) {
  23612. node = node.firstChild;
  23613. }
  23614. var first = 1;
  23615. while(node) {
  23616. textContent = node.nodeType == 3 ?
  23617. node.nodeValue :
  23618. node[browser.ie ? 'innerText' : 'textContent'];
  23619. index = findTextInString(textContent, opt, currentIndex);
  23620. first = 0;
  23621. if(index != -1) {
  23622. return {
  23623. 'node': node,
  23624. 'index': index
  23625. }
  23626. }
  23627. node = domUtils[methodName](node);
  23628. while(node && _blockElm[node.nodeName.toLowerCase()]) {
  23629. node = domUtils[methodName](node, true);
  23630. }
  23631. if(node) {
  23632. currentIndex = opt.dir == -1 ?
  23633. (node.nodeType == 3 ?
  23634. node.nodeValue :
  23635. node[browser.ie ?
  23636. 'innerText' :
  23637. 'textContent']).length :
  23638. 0;
  23639. }
  23640. }
  23641. }
  23642. function findNTextInBlockElm(node, index, str) {
  23643. var currentIndex = 0,
  23644. currentNode = node.firstChild,
  23645. currentNodeLength = 0,
  23646. result;
  23647. while(currentNode) {
  23648. if(currentNode.nodeType == 3) {
  23649. currentNodeLength = currentNode.nodeValue.replace(
  23650. /(^[\t\r\n]+)|([\t\r\n]+$)/, '').length;
  23651. currentIndex += currentNodeLength;
  23652. if(currentIndex >= index) {
  23653. return {
  23654. 'node': currentNode,
  23655. 'index': currentNodeLength -
  23656. (currentIndex - index)
  23657. }
  23658. }
  23659. } else if(!dtd.$empty[currentNode.tagName]) {
  23660. currentNodeLength = currentNode[browser.ie ?
  23661. 'innerText' :
  23662. 'textContent'].replace(
  23663. /(^[\t\r\n]+)|([\t\r\n]+$)/, '').length
  23664. currentIndex += currentNodeLength;
  23665. if(currentIndex >= index) {
  23666. result = findNTextInBlockElm(currentNode,
  23667. currentNodeLength - (currentIndex - index), str);
  23668. if(result) {
  23669. return result;
  23670. }
  23671. }
  23672. }
  23673. currentNode = domUtils.getNextDomNode(currentNode);
  23674. }
  23675. }
  23676. function searchReplace(me, opt) {
  23677. var rng = me.selection.getRange(),
  23678. startBlockNode, searchStr = opt.searchStr,
  23679. span = me.document
  23680. .createElement('span');
  23681. span.innerHTML = '$$ueditor_searchreplace_key$$';
  23682. rng.shrinkBoundary(true);
  23683. // 判断是不是第一次选中
  23684. if(!rng.collapsed) {
  23685. rng.select();
  23686. var rngText = me.selection.getText();
  23687. if(new RegExp('^' + opt.searchStr + '$', (opt.casesensitive ?
  23688. '' :
  23689. 'i')).test(rngText)) {
  23690. if(opt.replaceStr != undefined) {
  23691. replaceText(rng, opt.replaceStr);
  23692. rng.select();
  23693. return true;
  23694. } else {
  23695. rng.collapse(opt.dir == -1)
  23696. }
  23697. }
  23698. }
  23699. rng.insertNode(span);
  23700. rng.enlargeToBlockElm(true);
  23701. startBlockNode = rng.startContainer;
  23702. var currentIndex = startBlockNode[browser.ie ?
  23703. 'innerText' :
  23704. 'textContent'].indexOf('$$ueditor_searchreplace_key$$');
  23705. rng.setStartBefore(span);
  23706. domUtils.remove(span);
  23707. var result = findTextBlockElm(startBlockNode, currentIndex, opt);
  23708. if(result) {
  23709. var rngStart = findNTextInBlockElm(result.node, result.index,
  23710. searchStr);
  23711. var rngEnd = findNTextInBlockElm(result.node, result.index +
  23712. searchStr.length, searchStr);
  23713. rng.setStart(rngStart.node, rngStart.index).setEnd(rngEnd.node,
  23714. rngEnd.index);
  23715. if(opt.replaceStr !== undefined) {
  23716. replaceText(rng, opt.replaceStr)
  23717. }
  23718. rng.select();
  23719. return true;
  23720. } else {
  23721. rng.setCursor()
  23722. }
  23723. }
  23724. function replaceText(rng, str) {
  23725. str = me.document.createTextNode(str);
  23726. rng.deleteContents().insertNode(str);
  23727. }
  23728. return {
  23729. commands: {
  23730. 'searchreplace': {
  23731. execCommand: function(cmdName, opt) {
  23732. utils.extend(opt, {
  23733. all: false,
  23734. casesensitive: false,
  23735. dir: 1
  23736. }, true);
  23737. var num = 0;
  23738. if(opt.all) {
  23739. var rng = me.selection.getRange(),
  23740. first = me.body.firstChild;
  23741. if(first && first.nodeType == 1) {
  23742. rng.setStart(first, 0);
  23743. rng.shrinkBoundary(true);
  23744. } else if(first.nodeType == 3) {
  23745. rng.setStartBefore(first)
  23746. }
  23747. rng.collapse(true).select(true);
  23748. if(opt.replaceStr !== undefined) {
  23749. me.fireEvent('saveScene');
  23750. }
  23751. while(searchReplace(this, opt)) {
  23752. num++;
  23753. }
  23754. if(num) {
  23755. me.fireEvent('saveScene');
  23756. }
  23757. } else {
  23758. if(opt.replaceStr !== undefined) {
  23759. me.fireEvent('saveScene');
  23760. }
  23761. if(searchReplace(this, opt)) {
  23762. num++
  23763. }
  23764. if(num) {
  23765. me.fireEvent('saveScene');
  23766. }
  23767. }
  23768. return num;
  23769. },
  23770. notNeedUndo: 1
  23771. }
  23772. }
  23773. }
  23774. });
  23775. // plugins/customstyle.js
  23776. /**
  23777. * 自定义样式
  23778. *
  23779. * @file
  23780. * @since 1.2.6.1
  23781. */
  23782. /**
  23783. * 根据config配置文件里“customstyle”选项的值对匹配的标签执行样式替换。
  23784. *
  23785. * @command customstyle
  23786. * @method execCommand
  23787. * @param {
  23788. * String } cmd 命令字符串
  23789. * @example ```javascript editor.execCommand( 'customstyle' ); ```
  23790. */
  23791. UE.plugins['customstyle'] = function() {
  23792. var me = this;
  23793. me.setOpt({
  23794. 'customstyle': [{
  23795. tag: 'h1',
  23796. name: 'tc',
  23797. style: 'font-size:32px;font-weight:bold;border-bottom:#ccc 2px solid;padding:0 4px 0 0;text-align:center;margin:0 0 20px 0;'
  23798. }, {
  23799. tag: 'h1',
  23800. name: 'tl',
  23801. style: 'font-size:32px;font-weight:bold;border-bottom:#ccc 2px solid;padding:0 4px 0 0;text-align:left;margin:0 0 10px 0;'
  23802. }, {
  23803. tag: 'span',
  23804. name: 'im',
  23805. style: 'font-size:16px;font-style:italic;font-weight:bold;line-height:18px;'
  23806. }, {
  23807. tag: 'span',
  23808. name: 'hi',
  23809. style: 'font-size:16px;font-style:italic;font-weight:bold;color:rgb(51, 153, 204);line-height:18px;'
  23810. }]
  23811. });
  23812. me.commands['customstyle'] = {
  23813. execCommand: function(cmdName, obj) {
  23814. var me = this,
  23815. tagName = obj.tag,
  23816. node = domUtils.findParent(
  23817. me.selection.getStart(),
  23818. function(node) {
  23819. return node.getAttribute('label');
  23820. }, true),
  23821. range, bk, tmpObj = {};
  23822. for(var p in obj) {
  23823. if(obj[p] !== undefined)
  23824. tmpObj[p] = obj[p];
  23825. }
  23826. delete tmpObj.tag;
  23827. if(node && node.getAttribute('label') == obj.label) {
  23828. range = this.selection.getRange();
  23829. bk = range.createBookmark();
  23830. if(range.collapsed) {
  23831. // trace:1732 删掉自定义标签,要有p来回填站位
  23832. if(dtd.$block[node.tagName]) {
  23833. var fillNode = me.document.createElement('p');
  23834. domUtils.moveChild(node, fillNode);
  23835. node.parentNode.insertBefore(fillNode, node);
  23836. domUtils.remove(node);
  23837. } else {
  23838. domUtils.remove(node, true);
  23839. }
  23840. } else {
  23841. var common = domUtils.getCommonAncestor(bk.start,
  23842. bk.end),
  23843. nodes = domUtils.getElementsByTagName(
  23844. common, tagName);
  23845. if(new RegExp(tagName, 'i').test(common.tagName)) {
  23846. nodes.push(common);
  23847. }
  23848. for(var i = 0, ni; ni = nodes[i++];) {
  23849. if(ni.getAttribute('label') == obj.label) {
  23850. var ps = domUtils.getPosition(ni, bk.start),
  23851. pe = domUtils
  23852. .getPosition(ni, bk.end);
  23853. if((ps & domUtils.POSITION_FOLLOWING || ps &
  23854. domUtils.POSITION_CONTAINS) &&
  23855. (pe & domUtils.POSITION_PRECEDING || pe &
  23856. domUtils.POSITION_CONTAINS))
  23857. if(dtd.$block[tagName]) {
  23858. var fillNode = me.document
  23859. .createElement('p');
  23860. domUtils.moveChild(ni, fillNode);
  23861. ni.parentNode
  23862. .insertBefore(fillNode, ni);
  23863. }
  23864. domUtils.remove(ni, true);
  23865. }
  23866. }
  23867. node = domUtils.findParent(common, function(node) {
  23868. return node.getAttribute('label') == obj.label;
  23869. }, true);
  23870. if(node) {
  23871. domUtils.remove(node, true);
  23872. }
  23873. }
  23874. range.moveToBookmark(bk).select();
  23875. } else {
  23876. if(dtd.$block[tagName]) {
  23877. this.execCommand('paragraph', tagName, tmpObj,
  23878. 'customstyle');
  23879. range = me.selection.getRange();
  23880. if(!range.collapsed) {
  23881. range.collapse();
  23882. node = domUtils.findParent(me.selection.getStart(),
  23883. function(node) {
  23884. return node.getAttribute('label') == obj.label;
  23885. }, true);
  23886. var pNode = me.document.createElement('p');
  23887. domUtils.insertAfter(node, pNode);
  23888. domUtils.fillNode(me.document, pNode);
  23889. range.setStart(pNode, 0).setCursor();
  23890. }
  23891. } else {
  23892. range = me.selection.getRange();
  23893. if(range.collapsed) {
  23894. node = me.document.createElement(tagName);
  23895. domUtils.setAttributes(node, tmpObj);
  23896. range.insertNode(node).setStart(node, 0)
  23897. .setCursor();
  23898. return;
  23899. }
  23900. bk = range.createBookmark();
  23901. range.applyInlineStyle(tagName, tmpObj)
  23902. .moveToBookmark(bk).select();
  23903. }
  23904. }
  23905. },
  23906. queryCommandValue: function() {
  23907. var parent = domUtils.filterNodeList(this.selection
  23908. .getStartElementPath(),
  23909. function(node) {
  23910. return node.getAttribute('label')
  23911. });
  23912. return parent ? parent.getAttribute('label') : '';
  23913. }
  23914. };
  23915. // 当去掉customstyle是,如果是块元素,用p代替
  23916. me.addListener('keyup', function(type, evt) {
  23917. var keyCode = evt.keyCode || evt.which;
  23918. if(keyCode == 32 || keyCode == 13) {
  23919. var range = me.selection.getRange();
  23920. if(range.collapsed) {
  23921. var node = domUtils.findParent(me.selection.getStart(),
  23922. function(node) {
  23923. return node.getAttribute('label');
  23924. }, true);
  23925. if(node && dtd.$block[node.tagName] &&
  23926. domUtils.isEmptyNode(node)) {
  23927. var p = me.document.createElement('p');
  23928. domUtils.insertAfter(node, p);
  23929. domUtils.fillNode(me.document, p);
  23930. domUtils.remove(node);
  23931. range.setStart(p, 0).setCursor();
  23932. }
  23933. }
  23934. }
  23935. });
  23936. };
  23937. // plugins/catchremoteimage.js
  23938. // /import core
  23939. // /commands 远程图片抓取
  23940. // /commandsName catchRemoteImage,catchremoteimageenable
  23941. // /commandsTitle 远程图片抓取
  23942. /**
  23943. * 远程图片抓取,当开启本插件时所有不符合本地域名的图片都将被抓取成为本地服务器上的图片
  23944. */
  23945. UE.plugins['catchremoteimage'] = function() {
  23946. var me = this,
  23947. ajax = UE.ajax;
  23948. /* 设置默认值 */
  23949. if(me.options.catchRemoteImageEnable === false)
  23950. return;
  23951. me.setOpt({
  23952. catchRemoteImageEnable: false
  23953. });
  23954. me.addListener("afterpaste", function() {
  23955. me.fireEvent("catchRemoteImage");
  23956. });
  23957. me.addListener("catchRemoteImage", function() {
  23958. var catcherLocalDomain = me.getOpt('catcherLocalDomain'),
  23959. catcherActionUrl = me
  23960. .getActionUrl(me.getOpt('catcherActionName')),
  23961. catcherUrlPrefix = me
  23962. .getOpt('catcherUrlPrefix'),
  23963. catcherFieldName = me
  23964. .getOpt('catcherFieldName');
  23965. var remoteImages = [],
  23966. imgs = domUtils.getElementsByTagName(
  23967. me.document, "img"),
  23968. test = function(src, urls) {
  23969. if(src.indexOf(location.host) != -1 || /(^\.)|(^\/)/.test(src)) {
  23970. return true;
  23971. }
  23972. if(urls) {
  23973. for(var j = 0, url; url = urls[j++];) {
  23974. if(src.indexOf(url) !== -1) {
  23975. return true;
  23976. }
  23977. }
  23978. }
  23979. return false;
  23980. };
  23981. for(var i = 0, ci; ci = imgs[i++];) {
  23982. if(ci.getAttribute("word_img")) {
  23983. continue;
  23984. }
  23985. var src = ci.getAttribute("_src") || ci.src || "";
  23986. if(/^(https?|ftp):/i.test(src) &&
  23987. !test(src, catcherLocalDomain)) {
  23988. remoteImages.push(src);
  23989. }
  23990. }
  23991. if(remoteImages.length) {
  23992. catchremoteimage(remoteImages, {
  23993. // 成功抓取
  23994. success: function(r) {
  23995. try {
  23996. var info = r.state !== undefined ? r : eval("(" +
  23997. r.responseText + ")");
  23998. } catch(e) {
  23999. return;
  24000. }
  24001. /* 获取源路径和新路径 */
  24002. var i, j, ci, cj, oldSrc, newSrc, list = info.list;
  24003. for(i = 0; ci = imgs[i++];) {
  24004. oldSrc = ci.getAttribute("_src") || ci.src || "";
  24005. for(j = 0; cj = list[j++];) {
  24006. if(oldSrc == cj.source &&
  24007. cj.state == "SUCCESS") { // 抓取失败时不做替换处理
  24008. newSrc = catcherUrlPrefix + cj.url;
  24009. domUtils.setAttributes(ci, {
  24010. "src": newSrc,
  24011. "_src": newSrc
  24012. });
  24013. break;
  24014. }
  24015. }
  24016. }
  24017. me.fireEvent('catchremotesuccess')
  24018. },
  24019. // 回调失败,本次请求超时
  24020. error: function() {
  24021. me.fireEvent("catchremoteerror");
  24022. }
  24023. });
  24024. }
  24025. function catchremoteimage(imgs, callbacks) {
  24026. var params = utils.serializeParam(me
  24027. .queryCommandValue('serverparam')) ||
  24028. '',
  24029. url = utils.formatUrl(catcherActionUrl +
  24030. (catcherActionUrl.indexOf('?') == -1 ? '?' : '&') +
  24031. params),
  24032. isJsonp = utils.isCrossDomainUrl(url), // (url + getWdApp()),。去掉 ?wdApplication=,不支持多个应用Lin
  24033. opt = {
  24034. 'method': 'POST',
  24035. 'dataType': isJsonp ? 'jsonp' : '',
  24036. 'timeout': 60000, // 单位:毫秒,回调请求超时设置。目标用户如果网速不是很快的话此处建议设置一个较大的数值
  24037. 'onsuccess': callbacks["success"],
  24038. 'onerror': callbacks["error"]
  24039. };
  24040. opt[catcherFieldName] = imgs;
  24041. ajax.request(url, opt);
  24042. }
  24043. });
  24044. };
  24045. // plugins/snapscreen.js
  24046. /**
  24047. * 截屏插件,为UEditor提供插入支持
  24048. *
  24049. * @file
  24050. * @since 1.4.2
  24051. */
  24052. UE.plugin.register('snapscreen', function() {
  24053. var me = this;
  24054. var snapplugin;
  24055. function getLocation(url) {
  24056. var search, a = document.createElement('a'),
  24057. params = utils
  24058. .serializeParam(me.queryCommandValue('serverparam')) ||
  24059. '';
  24060. a.href = url;
  24061. if(browser.ie) {
  24062. a.href = a.href;
  24063. }
  24064. search = a.search;
  24065. if(params) {
  24066. search = search + (search.indexOf('?') == -1 ? '?' : '&') +
  24067. params;
  24068. search = search.replace(/[&]+/ig, '&');
  24069. }
  24070. return {
  24071. 'port': a.port,
  24072. 'hostname': a.hostname,
  24073. 'path': a.pathname + search || +a.hash
  24074. }
  24075. }
  24076. return {
  24077. commands: {
  24078. /**
  24079. * 字体背景颜色
  24080. *
  24081. * @command snapscreen
  24082. * @method execCommand
  24083. * @param {
  24084. * String } cmd 命令字符串
  24085. * @example ```javascript editor.execCommand('snapscreen'); ```
  24086. */
  24087. 'snapscreen': {
  24088. execCommand: function(cmd) {
  24089. var url, local, res;
  24090. var lang = me.getLang("snapScreen_plugin");
  24091. if(!snapplugin) {
  24092. var container = me.container;
  24093. var doc = me.container.ownerDocument ||
  24094. me.container.document;
  24095. snapplugin = doc.createElement("object");
  24096. try {
  24097. snapplugin.type = "application/x-pluginbaidusnap";
  24098. } catch(e) {
  24099. return;
  24100. }
  24101. snapplugin.style.cssText = "position:absolute;left:-9999px;width:0;height:0;";
  24102. snapplugin.setAttribute("width", "0");
  24103. snapplugin.setAttribute("height", "0");
  24104. container.appendChild(snapplugin);
  24105. }
  24106. function onSuccess(rs) {
  24107. try {
  24108. rs = eval("(" + rs + ")");
  24109. if(rs.state == 'SUCCESS') {
  24110. var opt = me.options;
  24111. me.execCommand('insertimage', {
  24112. src: opt.snapscreenUrlPrefix + rs.url,
  24113. _src: opt.snapscreenUrlPrefix + rs.url,
  24114. alt: rs.title || '',
  24115. floatStyle: opt.snapscreenImgAlign
  24116. });
  24117. } else {
  24118. alert(rs.state);
  24119. }
  24120. } catch(e) {
  24121. alert(lang.callBackErrorMsg);
  24122. }
  24123. }
  24124. url = me
  24125. .getActionUrl(me.getOpt('snapscreenActionName'));
  24126. local = getLocation(url); // (url + getWdApp())。去掉 ?wdApplication=,不支持多个应用Lin
  24127. setTimeout(function() {
  24128. try {
  24129. res = snapplugin.saveSnapshot(local.hostname,
  24130. local.path, local.port);
  24131. } catch(e) {
  24132. me.ui._dialogs['snapscreenDialog'].open();
  24133. return;
  24134. }
  24135. onSuccess(res);
  24136. }, 50);
  24137. },
  24138. queryCommandState: function() {
  24139. return(navigator.userAgent.indexOf("Windows", 0) != -1) ?
  24140. 0 :
  24141. -1;
  24142. }
  24143. }
  24144. }
  24145. }
  24146. });
  24147. // plugins/insertparagraph.js
  24148. /**
  24149. * 插入段落
  24150. *
  24151. * @file
  24152. * @since 1.2.6.1
  24153. */
  24154. /**
  24155. * 插入段落
  24156. *
  24157. * @command insertparagraph
  24158. * @method execCommand
  24159. * @param {
  24160. * String } cmd 命令字符串
  24161. * @example ```javascript //editor是编辑器实例 editor.execCommand(
  24162. * 'insertparagraph' ); ```
  24163. */
  24164. UE.commands['insertparagraph'] = {
  24165. execCommand: function(cmdName, front) {
  24166. var me = this,
  24167. range = me.selection.getRange(),
  24168. start = range.startContainer,
  24169. tmpNode;
  24170. while(start) {
  24171. if(domUtils.isBody(start)) {
  24172. break;
  24173. }
  24174. tmpNode = start;
  24175. start = start.parentNode;
  24176. }
  24177. if(tmpNode) {
  24178. var p = me.document.createElement('p');
  24179. if(front) {
  24180. tmpNode.parentNode.insertBefore(p, tmpNode)
  24181. } else {
  24182. tmpNode.parentNode.insertBefore(p, tmpNode.nextSibling)
  24183. }
  24184. domUtils.fillNode(me.document, p);
  24185. range.setStart(p, 0).setCursor(false, true);
  24186. }
  24187. }
  24188. };
  24189. // plugins/webapp.js
  24190. /**
  24191. * 百度应用
  24192. *
  24193. * @file
  24194. * @since 1.2.6.1
  24195. */
  24196. /**
  24197. * 插入百度应用
  24198. *
  24199. * @command webapp
  24200. * @method execCommand
  24201. * @remind 需要百度APPKey
  24202. * @remind 百度应用主页: <a href="http://app.baidu.com/"
  24203. * target="_blank">http://app.baidu.com/</a>
  24204. * @param {
  24205. * Object } appOptions 应用所需的参数项, 支持的key有: title=>应用标题,
  24206. * width=>应用容器宽度, height=>应用容器高度,logo=>应用logo,url=>应用地址
  24207. * @example ```javascript //editor是编辑器实例 //在编辑器里插入一个“植物大战僵尸”的APP
  24208. * editor.execCommand( 'webapp' , { title: '植物大战僵尸', width: 560,
  24209. * height: 465, logo: '应用展示的图片', url: '百度应用的地址' } ); ```
  24210. */
  24211. // UE.plugins['webapp'] = function () {
  24212. // var me = this;
  24213. // function createInsertStr( obj, toIframe, addParagraph ) {
  24214. // return !toIframe ?
  24215. // (addParagraph ? '<p>' : '') + '<img title="'+obj.title+'" width="' +
  24216. // obj.width + '" height="' + obj.height + '"' +
  24217. // ' src="' + me.options.UEDITOR_HOME_URL +
  24218. // 'themes/default/images/spacer.gif" style="background:url(' + obj.logo+')
  24219. // no-repeat center center; border:1px solid gray;"
  24220. // class="edui-faked-webapp" _url="' + obj.url + '" />' +
  24221. // (addParagraph ? '</p>' : '')
  24222. // :
  24223. // '<iframe class="edui-faked-webapp" title="'+obj.title+'" width="' +
  24224. // obj.width + '" height="' + obj.height + '" scrolling="no" frameborder="0"
  24225. // src="' + obj.url + '" logo_url = '+obj.logo+'></iframe>';
  24226. // }
  24227. //
  24228. // function switchImgAndIframe( img2frame ) {
  24229. // var tmpdiv,
  24230. // nodes = domUtils.getElementsByTagName( me.document, !img2frame ? "iframe"
  24231. // : "img" );
  24232. // for ( var i = 0, node; node = nodes[i++]; ) {
  24233. // if ( node.className != "edui-faked-webapp" ){
  24234. // continue;
  24235. // }
  24236. // tmpdiv = me.document.createElement( "div" );
  24237. // tmpdiv.innerHTML = createInsertStr( img2frame ? {url:node.getAttribute(
  24238. // "_url" ), width:node.width,
  24239. // height:node.height,title:node.title,logo:node.style.backgroundImage.replace("url(","").replace(")","")}
  24240. // : {url:node.getAttribute( "src", 2 ),title:node.title, width:node.width,
  24241. // height:node.height,logo:node.getAttribute("logo_url")}, img2frame ? true
  24242. // : false,false );
  24243. // node.parentNode.replaceChild( tmpdiv.firstChild, node );
  24244. // }
  24245. // }
  24246. //
  24247. // me.addListener( "beforegetcontent", function () {
  24248. // switchImgAndIframe( true );
  24249. // } );
  24250. // me.addListener( 'aftersetcontent', function () {
  24251. // switchImgAndIframe( false );
  24252. // } );
  24253. // me.addListener( 'aftergetcontent', function ( cmdName ) {
  24254. // if ( cmdName == 'aftergetcontent' && me.queryCommandState( 'source' ) ){
  24255. // return;
  24256. // }
  24257. // switchImgAndIframe( false );
  24258. // } );
  24259. //
  24260. // me.commands['webapp'] = {
  24261. // execCommand:function ( cmd, obj ) {
  24262. // me.execCommand( "inserthtml", createInsertStr( obj, false,true ) );
  24263. // }
  24264. // };
  24265. // };
  24266. UE.plugin.register('webapp', function() {
  24267. var me = this;
  24268. function createInsertStr(obj, toEmbed) {
  24269. return !toEmbed ?
  24270. '<img title="' +
  24271. obj.title +
  24272. '" width="' +
  24273. obj.width +
  24274. '" height="' +
  24275. obj.height +
  24276. '"' +
  24277. ' src="' +
  24278. me.options.UEDITOR_HOME_URL +
  24279. 'themes/default/images/spacer.gif" _logo_url="' +
  24280. obj.logo +
  24281. '" style="background:url(' +
  24282. obj.logo +
  24283. ') no-repeat center center; border:1px solid gray;" class="edui-faked-webapp" _url="' +
  24284. obj.url +
  24285. '" ' +
  24286. (obj.align && !obj.cssfloat ? 'align="' +
  24287. obj.align + '"' : '') +
  24288. (obj.cssfloat ? 'style="float:' + obj.cssfloat +
  24289. '"' : '') + '/>' :
  24290. '<iframe class="edui-faked-webapp" title="' +
  24291. obj.title +
  24292. '" ' +
  24293. (obj.align && !obj.cssfloat ? 'align="' +
  24294. obj.align + '"' : '') +
  24295. (obj.cssfloat ? 'style="float:' + obj.cssfloat +
  24296. '"' : '') + 'width="' + obj.width +
  24297. '" height="' + obj.height +
  24298. '" scrolling="no" frameborder="0" src="' +
  24299. obj.url + '" logo_url = "' + obj.logo +
  24300. '"></iframe>'
  24301. }
  24302. return {
  24303. outputRule: function(root) {
  24304. utils.each(root.getNodesByTagName('img'), function(node) {
  24305. var html;
  24306. if(node.getAttr('class') == 'edui-faked-webapp') {
  24307. html = createInsertStr({
  24308. title: node.getAttr('title'),
  24309. 'width': node.getAttr('width'),
  24310. 'height': node.getAttr('height'),
  24311. 'align': node.getAttr('align'),
  24312. 'cssfloat': node.getStyle('float'),
  24313. 'url': node.getAttr("_url"),
  24314. 'logo': node.getAttr('_logo_url')
  24315. }, true);
  24316. var embed = UE.uNode.createElement(html);
  24317. node.parentNode.replaceChild(embed, node);
  24318. }
  24319. })
  24320. },
  24321. inputRule: function(root) {
  24322. utils.each(root.getNodesByTagName('iframe'), function(node) {
  24323. if(node.getAttr('class') == 'edui-faked-webapp') {
  24324. var img = UE.uNode.createElement(createInsertStr({
  24325. title: node.getAttr('title'),
  24326. 'width': node.getAttr('width'),
  24327. 'height': node.getAttr('height'),
  24328. 'align': node.getAttr('align'),
  24329. 'cssfloat': node.getStyle('float'),
  24330. 'url': node.getAttr("src"),
  24331. 'logo': node.getAttr('logo_url')
  24332. }));
  24333. node.parentNode.replaceChild(img, node);
  24334. }
  24335. })
  24336. },
  24337. commands: {
  24338. /**
  24339. * 插入百度应用
  24340. *
  24341. * @command webapp
  24342. * @method execCommand
  24343. * @remind 需要百度APPKey
  24344. * @remind 百度应用主页: <a href="http://app.baidu.com/"
  24345. * target="_blank">http://app.baidu.com/</a>
  24346. * @param {
  24347. * Object } appOptions 应用所需的参数项, 支持的key有:
  24348. * title=>应用标题, width=>应用容器宽度,
  24349. * height=>应用容器高度,logo=>应用logo,url=>应用地址
  24350. * @example ```javascript //editor是编辑器实例 //在编辑器里插入一个“植物大战僵尸”的APP
  24351. * editor.execCommand( 'webapp' , { title: '植物大战僵尸',
  24352. * width: 560, height: 465, logo: '应用展示的图片', url:
  24353. * '百度应用的地址' } ); ```
  24354. */
  24355. 'webapp': {
  24356. execCommand: function(cmd, obj) {
  24357. var me = this,
  24358. str = createInsertStr(utils.extend(obj, {
  24359. align: 'none'
  24360. }), false);
  24361. me.execCommand("inserthtml", str);
  24362. },
  24363. queryCommandState: function() {
  24364. var me = this,
  24365. img = me.selection.getRange()
  24366. .getClosedNode(),
  24367. flag = img &&
  24368. (img.className == "edui-faked-webapp");
  24369. return flag ? 1 : 0;
  24370. }
  24371. }
  24372. }
  24373. }
  24374. });
  24375. // plugins/template.js
  24376. // /import core
  24377. // /import plugins\inserthtml.js
  24378. // /import plugins\cleardoc.js
  24379. // /commands 模板
  24380. // /commandsName template
  24381. // /commandsTitle 模板
  24382. // /commandsDialog dialogs\template
  24383. UE.plugins['template'] = function() {
  24384. UE.commands['template'] = {
  24385. execCommand: function(cmd, obj) {
  24386. obj.html && this.execCommand("inserthtml", obj.html);
  24387. }
  24388. };
  24389. console.log("---------------------")
  24390. console.log(this);
  24391. this.addListener("click", function(type, evt) {
  24392. var el = evt.target || evt.srcElement,
  24393. range = this.selection
  24394. .getRange();
  24395. var tnode = domUtils.findParent(el, function(node) {
  24396. if(node.className && domUtils.hasClass(node, "ue_t")) {
  24397. return node;
  24398. }
  24399. }, true);
  24400. tnode && range.selectNode(tnode).shrinkBoundary().select();
  24401. });
  24402. this.addListener("keydown", function(type, evt) {
  24403. var range = this.selection.getRange();
  24404. if(!range.collapsed) {
  24405. if(!evt.ctrlKey && !evt.metaKey && !evt.shiftKey &&
  24406. !evt.altKey) {
  24407. var tnode = domUtils.findParent(range.startContainer,
  24408. function(node) {
  24409. if(node.className &&
  24410. domUtils.hasClass(node, "ue_t")) {
  24411. return node;
  24412. }
  24413. }, true);
  24414. if(tnode) {
  24415. domUtils.removeClasses(tnode, ["ue_t"]);
  24416. }
  24417. }
  24418. }
  24419. });
  24420. };
  24421. // plugins/music.js
  24422. /**
  24423. * 插入音乐命令
  24424. *
  24425. * @file
  24426. */
  24427. UE.plugin.register('music', function() {
  24428. var me = this;
  24429. function creatInsertStr(url, width, height, align, cssfloat, toEmbed) {
  24430. return !toEmbed ?
  24431. '<img ' +
  24432. (align && !cssfloat ?
  24433. 'align="' + align + '"' :
  24434. '') +
  24435. (cssfloat ? 'style="float:' + cssfloat + '"' : '') +
  24436. ' width="' + width + '" height="' + height +
  24437. '" _url="' + url + '" class="edui-faked-music"' +
  24438. ' src="' + me.options.langPath + me.options.lang +
  24439. '/images/music.png" />' :
  24440. '<embed type="application/x-shockwave-flash" class="edui-faked-music" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
  24441. ' src="' +
  24442. url +
  24443. '" width="' +
  24444. width +
  24445. '" height="' +
  24446. height +
  24447. '" ' +
  24448. (align && !cssfloat ?
  24449. 'align="' + align + '"' :
  24450. '') +
  24451. (cssfloat ? 'style="float:' + cssfloat + '"' : '') +
  24452. ' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >';
  24453. }
  24454. return {
  24455. outputRule: function(root) {
  24456. utils.each(root.getNodesByTagName('img'), function(node) {
  24457. var html;
  24458. if(node.getAttr('class') == 'edui-faked-music') {
  24459. var cssfloat = node.getStyle('float');
  24460. var align = node.getAttr('align');
  24461. html = creatInsertStr(node.getAttr("_url"), node
  24462. .getAttr('width'), node.getAttr('height'),
  24463. align, cssfloat, true);
  24464. var embed = UE.uNode.createElement(html);
  24465. node.parentNode.replaceChild(embed, node);
  24466. }
  24467. })
  24468. },
  24469. inputRule: function(root) {
  24470. utils.each(root.getNodesByTagName('embed'), function(node) {
  24471. if(node.getAttr('class') == 'edui-faked-music') {
  24472. var cssfloat = node.getStyle('float');
  24473. var align = node.getAttr('align');
  24474. html = creatInsertStr(node.getAttr("src"), node
  24475. .getAttr('width'), node.getAttr('height'),
  24476. align, cssfloat, false);
  24477. var img = UE.uNode.createElement(html);
  24478. node.parentNode.replaceChild(img, node);
  24479. }
  24480. })
  24481. },
  24482. commands: {
  24483. /**
  24484. * 插入音乐
  24485. *
  24486. * @command music
  24487. * @method execCommand
  24488. * @param {
  24489. * Object } musicOptions 插入音乐的参数项, 支持的key有:
  24490. * url=>音乐地址;
  24491. * width=>音乐容器宽度;height=>音乐容器高度;align=>音乐文件的对齐方式,
  24492. * 可选值有: left, center, right, none
  24493. * @example ```javascript //editor是编辑器实例 //在编辑器里插入一个“植物大战僵尸”的APP
  24494. * editor.execCommand( 'music' , { width: 400, height:
  24495. * 95, align: "center", url: "音乐地址" } ); ```
  24496. */
  24497. 'music': {
  24498. execCommand: function(cmd, musicObj) {
  24499. var me = this,
  24500. str = creatInsertStr(musicObj.url,
  24501. musicObj.width || 400, musicObj.height || 95,
  24502. "none", false);
  24503. me.execCommand("inserthtml", str);
  24504. },
  24505. queryCommandState: function() {
  24506. var me = this,
  24507. img = me.selection.getRange()
  24508. .getClosedNode(),
  24509. flag = img &&
  24510. (img.className == "edui-faked-music");
  24511. return flag ? 1 : 0;
  24512. }
  24513. }
  24514. }
  24515. }
  24516. });
  24517. // plugins/autoupload.js
  24518. /**
  24519. * @description 1.拖放文件到编辑区域,自动上传并插入到选区 2.插入粘贴板的图片,自动上传并插入到选区
  24520. * @author Jinqn
  24521. * @date 2013-10-14
  24522. */
  24523. UE.plugin.register('autoupload', function() {
  24524. function sendAndInsertFile(file, editor) {
  24525. var me = editor;
  24526. // 模拟数据
  24527. var fieldName, urlPrefix, maxSize, allowFiles, actionUrl, loadingHtml, errorHandler, successHandler, filetype = /image\/\w+/i
  24528. .test(file.type) ? 'image' : 'file',
  24529. loadingId = 'loading_' +
  24530. (+new Date()).toString(36);
  24531. fieldName = me.getOpt(filetype + 'FieldName');
  24532. urlPrefix = me.getOpt(filetype + 'UrlPrefix');
  24533. maxSize = me.getOpt(filetype + 'MaxSize');
  24534. allowFiles = me.getOpt(filetype + 'AllowFiles');
  24535. actionUrl = me.getActionUrl(me.getOpt(filetype + 'ActionName'));
  24536. errorHandler = function(title) {
  24537. var loader = me.document.getElementById(loadingId);
  24538. loader && domUtils.remove(loader);
  24539. me.fireEvent('showmessage', {
  24540. 'id': loadingId,
  24541. 'content': title,
  24542. 'type': 'error',
  24543. 'timeout': 4000
  24544. });
  24545. };
  24546. if(filetype == 'image') {//粘贴图片
  24547. loadingHtml = '<img class="loadingclass" wdimg="true" id="' + loadingId +
  24548. '" src="' + me.options.themePath + me.options.theme +
  24549. '/images/spacer.gif" title="' +
  24550. (me.getLang('autoupload.loading') || '') + '" >';
  24551. successHandler = function(data) {
  24552. var link =data.tokenURL||(urlPrefix+data.url),
  24553. loader = me.document
  24554. .getElementById(loadingId);
  24555. if(loader) {
  24556. loader.setAttribute('src', link);
  24557. loader.setAttribute('_src', link);
  24558. loader.setAttribute('title', data.title || '');
  24559. loader.setAttribute('alt', data.original || '');
  24560. loader.setAttribute('gdlx', "2");
  24561. loader.setAttribute('tplx', "1");
  24562. loader.setAttribute('data',JSON.stringify([{t:data.tokenURL,s:data.url,filetype:data.type}]));
  24563. loader.removeAttribute('id');
  24564. domUtils.removeClasses(loader, 'loadingclass');
  24565. }
  24566. };
  24567. } else {
  24568. loadingHtml = '<p>' + '<img class="loadingclass" wdimg="true" id="' +
  24569. loadingId + '" src="' + me.options.themePath +
  24570. me.options.theme + '/images/spacer.gif" title="' +
  24571. (me.getLang('autoupload.loading') || '') + '" >' +
  24572. '</p>';
  24573. successHandler = function(data) {
  24574. var link = data.tokenURL||(urlPrefix+data.url),
  24575. loader = me.document
  24576. .getElementById(loadingId);
  24577. var rng = me.selection.getRange(),
  24578. bk = rng
  24579. .createBookmark();
  24580. rng.selectNode(loader).select();
  24581. me.execCommand('insertfile', {
  24582. 'url': link
  24583. });
  24584. rng.moveToBookmark(bk).select();
  24585. };
  24586. }
  24587. /* 插入loading的占位符 */
  24588. me.execCommand('inserthtml', loadingHtml);
  24589. /* 判断后端配置是否没有加载成功 */
  24590. if(!me.getOpt(filetype + 'ActionName')) {
  24591. errorHandler(me.getLang('autoupload.errorLoadConfig'));
  24592. return;
  24593. }
  24594. /* 判断文件大小是否超出限制 */
  24595. if(file.size > maxSize) {
  24596. errorHandler(me.getLang('autoupload.exceedSizeError'));
  24597. return;
  24598. }
  24599. /* 判断文件格式是否超出允许 */
  24600. var fileext = file.name ? file.name.substr(file.name
  24601. .lastIndexOf('.')) : '';
  24602. if((fileext && filetype != 'image') ||
  24603. (allowFiles && (allowFiles.join('') + '.')
  24604. .indexOf(fileext.toLowerCase() + '.') == -1)) {
  24605. errorHandler(me.getLang('autoupload.exceedTypeError'));
  24606. return;
  24607. }
  24608. /* 创建Ajax并提交 */
  24609. var xhr = new XMLHttpRequest(),
  24610. fd = new FormData(),
  24611. params = utils
  24612. .serializeParam(me.queryCommandValue('serverparam')) ||
  24613. '',
  24614. url = utils.formatUrl(actionUrl +
  24615. (actionUrl.indexOf('?') == -1 ? '?' : '&') + params);
  24616. fd.append(fieldName, file, file.name ||
  24617. ('blob.' + file.type.substr('image/'.length)));
  24618. fd.append('type', 'ajax');
  24619. xhr.open("post", url, true); // , url + getWdApp(),。去掉 ?wdApplication=,不支持多个应用Lin
  24620. xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
  24621. xhr.addEventListener('load', function(e) {
  24622. try {
  24623. var json = (new Function("return " +
  24624. utils.trim(e.target.response)))();
  24625. if(json.state == 'SUCCESS' && json.url) {
  24626. successHandler(json);
  24627. } else {
  24628. errorHandler(json.state);
  24629. }
  24630. } catch(er) {
  24631. errorHandler(me.getLang('autoupload.loadError'));
  24632. }
  24633. });
  24634. xhr.send(fd);
  24635. }
  24636. function getPasteImage(e) {
  24637. return e.clipboardData && e.clipboardData.items &&
  24638. e.clipboardData.items.length == 1 &&
  24639. /^image\//.test(e.clipboardData.items[0].type) ?
  24640. e.clipboardData.items :
  24641. null;
  24642. }
  24643. function getDropImage(e) {
  24644. return e.dataTransfer && e.dataTransfer.files ?
  24645. e.dataTransfer.files :
  24646. null;
  24647. }
  24648. return {
  24649. outputRule: function(root) {
  24650. utils.each(root.getNodesByTagName('img'), function(n) {
  24651. if(/\b(loaderrorclass)|(bloaderrorclass)\b/.test(n
  24652. .getAttr('class'))) {
  24653. n.parentNode.removeChild(n);
  24654. }
  24655. });
  24656. utils.each(root.getNodesByTagName('p'), function(n) {
  24657. if(/\bloadpara\b/.test(n.getAttr('class'))) {
  24658. n.parentNode.removeChild(n);
  24659. }
  24660. });
  24661. },
  24662. bindEvents: {
  24663. // 插入粘贴板的图片,拖放插入图片
  24664. 'ready': function(e) {
  24665. var me = this;
  24666. if(window.FormData && window.FileReader) {
  24667. domUtils.on(me.body, 'paste drop', function(e) {
  24668. var hasImg = false,
  24669. items;
  24670. // 获取粘贴板文件列表或者拖放文件列表
  24671. items = e.type == 'paste' ?
  24672. getPasteImage(e) :
  24673. getDropImage(e);
  24674. if(items) {
  24675. var len = items.length,
  24676. file;
  24677. while(len--) {
  24678. file = items[len];
  24679. if(file.getAsFile)
  24680. file = file.getAsFile();
  24681. if(file && file.size > 0) {
  24682. sendAndInsertFile(file, me);
  24683. hasImg = true;
  24684. }
  24685. }
  24686. hasImg && e.preventDefault();
  24687. }
  24688. tt = document.querySelectorAll('#baidu_pastebin');
  24689. tt0 = tt[0];
  24690. });
  24691. // 取消拖放图片时出现的文字光标位置提示
  24692. domUtils.on(me.body, 'dragover', function(e) {
  24693. if(e.dataTransfer.types[0] == 'Files') {
  24694. e.preventDefault();
  24695. }
  24696. });
  24697. // 设置loading的样式
  24698. utils
  24699. .cssRule(
  24700. 'loading',
  24701. '.loadingclass{display:inline-block;cursor:default;background: url(\'' +
  24702. this.options.themePath +
  24703. this.options.theme +
  24704. '/images/loading.gif\') no-repeat center center transparent;border:1px solid #cccccc;margin-left:1px;height: 22px;width: 22px;}\n' +
  24705. '.loaderrorclass{display:inline-block;cursor:default;background: url(\'' +
  24706. this.options.themePath +
  24707. this.options.theme +
  24708. '/images/loaderror.png\') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;' +
  24709. '}', this.document);
  24710. }
  24711. }
  24712. }
  24713. }
  24714. });
  24715. // plugins/autosave.js
  24716. UE.plugin.register('autosave', function() {
  24717. var me = this,
  24718. // 无限循环保护
  24719. lastSaveTime = new Date(),
  24720. // 最小保存间隔时间
  24721. MIN_TIME = 20,
  24722. // auto save key
  24723. saveKey = null;
  24724. function save(editor) {
  24725. var saveData;
  24726. if(new Date() - lastSaveTime < MIN_TIME) {
  24727. return;
  24728. }
  24729. if(!editor.hasContents()) {
  24730. // 这里不能调用命令来删除, 会造成事件死循环
  24731. saveKey && me.removePreferences(saveKey);
  24732. return;
  24733. }
  24734. lastSaveTime = new Date();
  24735. editor._saveFlag = null;
  24736. saveData = me.body.innerHTML;
  24737. if(editor.fireEvent("beforeautosave", {
  24738. content: saveData
  24739. }) === false) {
  24740. return;
  24741. }
  24742. me.setPreferences(saveKey, saveData);
  24743. editor.fireEvent("afterautosave", {
  24744. content: saveData
  24745. });
  24746. }
  24747. return {
  24748. defaultOptions: {
  24749. // 默认间隔时间
  24750. saveInterval: 500
  24751. },
  24752. bindEvents: {
  24753. 'ready': function() {
  24754. var _suffix = "-drafts-data",
  24755. key = null;
  24756. if(me.key) {
  24757. key = me.key + _suffix;
  24758. } else {
  24759. key = (me.container.parentNode.id || 'ue-common') +
  24760. _suffix;
  24761. }
  24762. // 页面地址+编辑器ID 保持唯一
  24763. saveKey = (location.protocol + location.host + location.pathname)
  24764. .replace(/[.:\/]/g, '_') +
  24765. key;
  24766. },
  24767. 'contentchange': function() {
  24768. if(!me.getOpt('enableAutoSave')) {
  24769. return;
  24770. }
  24771. if(!saveKey) {
  24772. return;
  24773. }
  24774. if(me._saveFlag) {
  24775. window.clearTimeout(me._saveFlag);
  24776. }
  24777. if(me.options.saveInterval > 0) {
  24778. me._saveFlag = window.setTimeout(function() {
  24779. save(me);
  24780. }, me.options.saveInterval);
  24781. } else {
  24782. save(me);
  24783. }
  24784. }
  24785. },
  24786. commands: {
  24787. 'clearlocaldata': {
  24788. execCommand: function(cmd, name) {
  24789. if(saveKey && me.getPreferences(saveKey)) {
  24790. me.removePreferences(saveKey)
  24791. }
  24792. },
  24793. notNeedUndo: true,
  24794. ignoreContentChange: true
  24795. },
  24796. 'getlocaldata': {
  24797. execCommand: function(cmd, name) {
  24798. return saveKey ? me.getPreferences(saveKey) || '' : '';
  24799. },
  24800. notNeedUndo: true,
  24801. ignoreContentChange: true
  24802. },
  24803. 'drafts': {
  24804. execCommand: function(cmd, name) {
  24805. if(saveKey) {
  24806. me.body.innerHTML = me.getPreferences(saveKey) ||
  24807. '<p>' + domUtils.fillHtml + '</p>';
  24808. me.focus(true);
  24809. }
  24810. },
  24811. queryCommandState: function() {
  24812. return saveKey ? (me.getPreferences(saveKey) === null ?
  24813. -1 :
  24814. 0) : -1;
  24815. },
  24816. notNeedUndo: true,
  24817. ignoreContentChange: true
  24818. }
  24819. }
  24820. }
  24821. });
  24822. // plugins/charts.js
  24823. UE.plugin.register('charts', function() {
  24824. var me = this;
  24825. return {
  24826. bindEvents: {
  24827. 'chartserror': function() {}
  24828. },
  24829. commands: {
  24830. 'charts': {
  24831. execCommand: function(cmd, data) {
  24832. var tableNode = domUtils.findParentByTagName(
  24833. this.selection.getRange().startContainer,
  24834. 'table', true),
  24835. flagText = [],
  24836. config = {};
  24837. if(!tableNode) {
  24838. return false;
  24839. }
  24840. if(!validData(tableNode)) {
  24841. me.fireEvent("chartserror");
  24842. return false;
  24843. }
  24844. config.title = data.title || '';
  24845. config.subTitle = data.subTitle || '';
  24846. config.xTitle = data.xTitle || '';
  24847. config.yTitle = data.yTitle || '';
  24848. config.suffix = data.suffix || '';
  24849. config.tip = data.tip || '';
  24850. // 数据对齐方式
  24851. config.dataFormat = data.tableDataFormat || '';
  24852. // 图表类型
  24853. config.chartType = data.chartType || 0;
  24854. for(var key in config) {
  24855. if(!config.hasOwnProperty(key)) {
  24856. continue;
  24857. }
  24858. flagText.push(key + ":" + config[key]);
  24859. }
  24860. tableNode
  24861. .setAttribute("data-chart", flagText.join(";"));
  24862. domUtils.addClass(tableNode, "edui-charts-table");
  24863. },
  24864. queryCommandState: function(cmd, name) {
  24865. var tableNode = domUtils.findParentByTagName(
  24866. this.selection.getRange().startContainer,
  24867. 'table', true);
  24868. return tableNode && validData(tableNode) ? 0 : -1;
  24869. }
  24870. }
  24871. },
  24872. inputRule: function(root) {
  24873. utils.each(root.getNodesByTagName('table'),
  24874. function(tableNode) {
  24875. if(tableNode.getAttr("data-chart") !== undefined) {
  24876. tableNode.setAttr("style");
  24877. }
  24878. })
  24879. },
  24880. outputRule: function(root) {
  24881. utils.each(root.getNodesByTagName('table'),
  24882. function(tableNode) {
  24883. if(tableNode.getAttr("data-chart") !== undefined) {
  24884. tableNode.setAttr("style", "display: none;");
  24885. }
  24886. })
  24887. }
  24888. }
  24889. function validData(table) {
  24890. var firstRows = null,
  24891. cellCount = 0;
  24892. // 行数不够
  24893. if(table.rows.length < 2) {
  24894. return false;
  24895. }
  24896. // 列数不够
  24897. if(table.rows[0].cells.length < 2) {
  24898. return false;
  24899. }
  24900. // 第一行所有cell必须是th
  24901. firstRows = table.rows[0].cells;
  24902. cellCount = firstRows.length;
  24903. for(var i = 0, cell; cell = firstRows[i]; i++) {
  24904. if(cell.tagName.toLowerCase() !== 'th') {
  24905. return false;
  24906. }
  24907. }
  24908. for(var i = 1, row; row = table.rows[i]; i++) {
  24909. // 每行单元格数不匹配, 返回false
  24910. if(row.cells.length != cellCount) {
  24911. return false;
  24912. }
  24913. // 第一列不是th也返回false
  24914. if(row.cells[0].tagName.toLowerCase() !== 'th') {
  24915. return false;
  24916. }
  24917. for(var j = 1, cell; cell = row.cells[j]; j++) {
  24918. var value = utils
  24919. .trim((cell.innerText || cell.textContent || ''));
  24920. value = value.replace(
  24921. new RegExp(UE.dom.domUtils.fillChar, 'g'), '')
  24922. .replace(/^\s+|\s+$/g, '');
  24923. // 必须是数字
  24924. if(!/^\d*\.?\d+$/.test(value)) {
  24925. return false;
  24926. }
  24927. }
  24928. }
  24929. return true;
  24930. }
  24931. });
  24932. // plugins/section.js
  24933. /**
  24934. * 目录大纲支持插件
  24935. *
  24936. * @file
  24937. * @since 1.3.0
  24938. */
  24939. UE.plugin.register('section', function() {
  24940. /* 目录节点对象 */
  24941. function Section(option) {
  24942. this.tag = '';
  24943. this.level = -1, this.dom = null;
  24944. this.nextSection = null;
  24945. this.previousSection = null;
  24946. this.parentSection = null;
  24947. this.startAddress = [];
  24948. this.endAddress = [];
  24949. this.children = [];
  24950. }
  24951. function getSection(option) {
  24952. var section = new Section();
  24953. return utils.extend(section, option);
  24954. }
  24955. function getNodeFromAddress(startAddress, root) {
  24956. var current = root;
  24957. for(var i = 0; i < startAddress.length; i++) {
  24958. if(!current.childNodes)
  24959. return null;
  24960. current = current.childNodes[startAddress[i]];
  24961. }
  24962. return current;
  24963. }
  24964. var me = this;
  24965. return {
  24966. bindMultiEvents: {
  24967. type: 'aftersetcontent afterscencerestore',
  24968. handler: function() {
  24969. me.fireEvent('updateSections');
  24970. }
  24971. },
  24972. bindEvents: {
  24973. /* 初始化、拖拽、粘贴、执行setcontent之后 */
  24974. 'ready': function() {
  24975. me.fireEvent('updateSections');
  24976. domUtils.on(me.body, 'drop paste', function() {
  24977. me.fireEvent('updateSections');
  24978. });
  24979. },
  24980. /* 执行paragraph命令之后 */
  24981. 'afterexeccommand': function(type, cmd) {
  24982. if(cmd == 'paragraph') {
  24983. me.fireEvent('updateSections');
  24984. }
  24985. },
  24986. /* 部分键盘操作,触发updateSections事件 */
  24987. 'keyup': function(type, e) {
  24988. var me = this,
  24989. range = me.selection.getRange();
  24990. if(range.collapsed != true) {
  24991. me.fireEvent('updateSections');
  24992. } else {
  24993. var keyCode = e.keyCode || e.which;
  24994. if(keyCode == 13 || keyCode == 8 || keyCode == 46) {
  24995. me.fireEvent('updateSections');
  24996. }
  24997. }
  24998. }
  24999. },
  25000. commands: {
  25001. 'getsections': {
  25002. execCommand: function(cmd, levels) {
  25003. var levelFn = levels || ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
  25004. for(var i = 0; i < levelFn.length; i++) {
  25005. if(typeof levelFn[i] == 'string') {
  25006. levelFn[i] = function(fn) {
  25007. return function(node) {
  25008. return node.tagName == fn.toUpperCase()
  25009. };
  25010. }(levelFn[i]);
  25011. } else if(typeof levelFn[i] != 'function') {
  25012. levelFn[i] = function(node) {
  25013. return null;
  25014. }
  25015. }
  25016. }
  25017. function getSectionLevel(node) {
  25018. for(var i = 0; i < levelFn.length; i++) {
  25019. if(levelFn[i](node))
  25020. return i;
  25021. }
  25022. return -1;
  25023. }
  25024. var me = this,
  25025. Directory = getSection({
  25026. 'level': -1,
  25027. 'title': 'root'
  25028. }),
  25029. previous = Directory;
  25030. function traversal(node, Directory) {
  25031. var level, tmpSection = null,
  25032. parent, child, children = node.childNodes;
  25033. for(var i = 0, len = children.length; i < len; i++) {
  25034. child = children[i];
  25035. level = getSectionLevel(child);
  25036. if(level >= 0) {
  25037. var address = me.selection.getRange()
  25038. .selectNode(child)
  25039. .createAddress(true).startAddress,
  25040. current = getSection({
  25041. 'tag': child.tagName,
  25042. 'title': child.innerText ||
  25043. child.textContent || '',
  25044. 'level': level,
  25045. 'dom': child,
  25046. 'startAddress': utils.clone(address, []),
  25047. 'endAddress': utils.clone(address, []),
  25048. 'children': []
  25049. });
  25050. previous.nextSection = current;
  25051. current.previousSection = previous;
  25052. parent = previous;
  25053. while(level <= parent.level) {
  25054. parent = parent.parentSection;
  25055. }
  25056. current.parentSection = parent;
  25057. parent.children.push(current);
  25058. tmpSection = previous = current;
  25059. } else {
  25060. child.nodeType === 1 &&
  25061. traversal(child, Directory);
  25062. tmpSection
  25063. &&
  25064. tmpSection.endAddress[tmpSection.endAddress.length -
  25065. 1]++;
  25066. }
  25067. }
  25068. }
  25069. traversal(me.body, Directory);
  25070. return Directory;
  25071. },
  25072. notNeedUndo: true
  25073. },
  25074. 'movesection': {
  25075. execCommand: function(cmd, sourceSection, targetSection,
  25076. isAfter) {
  25077. var me = this,
  25078. targetAddress, target;
  25079. if(!sourceSection || !targetSection ||
  25080. targetSection.level == -1)
  25081. return;
  25082. targetAddress = isAfter ?
  25083. targetSection.endAddress :
  25084. targetSection.startAddress;
  25085. target = getNodeFromAddress(targetAddress, me.body);
  25086. /* 判断目标地址是否被源章节包含 */
  25087. if(!targetAddress ||
  25088. !target ||
  25089. isContainsAddress(
  25090. sourceSection.startAddress,
  25091. sourceSection.endAddress, targetAddress))
  25092. return;
  25093. var startNode = getNodeFromAddress(
  25094. sourceSection.startAddress, me.body),
  25095. endNode = getNodeFromAddress(
  25096. sourceSection.endAddress, me.body),
  25097. current, nextNode;
  25098. if(isAfter) {
  25099. current = endNode;
  25100. while(current &&
  25101. !(domUtils.getPosition(startNode,
  25102. current) & domUtils.POSITION_FOLLOWING)) {
  25103. nextNode = current.previousSibling;
  25104. domUtils.insertAfter(target, current);
  25105. if(current == startNode)
  25106. break;
  25107. current = nextNode;
  25108. }
  25109. } else {
  25110. current = startNode;
  25111. while(current &&
  25112. !(domUtils.getPosition(current, endNode) & domUtils.POSITION_FOLLOWING)) {
  25113. nextNode = current.nextSibling;
  25114. target.parentNode.insertBefore(current, target);
  25115. if(current == endNode)
  25116. break;
  25117. current = nextNode;
  25118. }
  25119. }
  25120. me.fireEvent('updateSections');
  25121. /* 获取地址的包含关系 */
  25122. function isContainsAddress(startAddress, endAddress,
  25123. addressTarget) {
  25124. var isAfterStartAddress = false,
  25125. isBeforeEndAddress = false;
  25126. for(var i = 0; i < startAddress.length; i++) {
  25127. if(i >= addressTarget.length)
  25128. break;
  25129. if(addressTarget[i] > startAddress[i]) {
  25130. isAfterStartAddress = true;
  25131. break;
  25132. } else if(addressTarget[i] < startAddress[i]) {
  25133. break;
  25134. }
  25135. }
  25136. for(var i = 0; i < endAddress.length; i++) {
  25137. if(i >= addressTarget.length)
  25138. break;
  25139. if(addressTarget[i] < startAddress[i]) {
  25140. isBeforeEndAddress = true;
  25141. break;
  25142. } else if(addressTarget[i] > startAddress[i]) {
  25143. break;
  25144. }
  25145. }
  25146. return isAfterStartAddress && isBeforeEndAddress;
  25147. }
  25148. }
  25149. },
  25150. 'deletesection': {
  25151. execCommand: function(cmd, section, keepChildren) {
  25152. var me = this;
  25153. if(!section)
  25154. return;
  25155. function getNodeFromAddress(startAddress) {
  25156. var current = me.body;
  25157. for(var i = 0; i < startAddress.length; i++) {
  25158. if(!current.childNodes)
  25159. return null;
  25160. current = current.childNodes[startAddress[i]];
  25161. }
  25162. return current;
  25163. }
  25164. var startNode = getNodeFromAddress(section.startAddress),
  25165. endNode = getNodeFromAddress(section.endAddress),
  25166. current = startNode,
  25167. nextNode;
  25168. if(!keepChildren) {
  25169. while(current &&
  25170. domUtils.inDoc(endNode, me.document) &&
  25171. !(domUtils.getPosition(current, endNode) & domUtils.POSITION_FOLLOWING)) {
  25172. nextNode = current.nextSibling;
  25173. domUtils.remove(current);
  25174. current = nextNode;
  25175. }
  25176. } else {
  25177. domUtils.remove(current);
  25178. }
  25179. me.fireEvent('updateSections');
  25180. }
  25181. },
  25182. 'selectsection': {
  25183. execCommand: function(cmd, section) {
  25184. if(!section && !section.dom)
  25185. return false;
  25186. var me = this,
  25187. range = me.selection.getRange(),
  25188. address = {
  25189. 'startAddress': utils.clone(section.startAddress, []),
  25190. 'endAddress': utils.clone(section.endAddress, [])
  25191. };
  25192. address.endAddress[address.endAddress.length - 1]++;
  25193. range.moveToAddress(address).select().scrollToView();
  25194. return true;
  25195. },
  25196. notNeedUndo: true
  25197. },
  25198. 'scrolltosection': {
  25199. execCommand: function(cmd, section) {
  25200. if(!section && !section.dom)
  25201. return false;
  25202. var me = this,
  25203. range = me.selection.getRange(),
  25204. address = {
  25205. 'startAddress': section.startAddress,
  25206. 'endAddress': section.endAddress
  25207. };
  25208. address.endAddress[address.endAddress.length - 1]++;
  25209. range.moveToAddress(address).scrollToView();
  25210. return true;
  25211. },
  25212. notNeedUndo: true
  25213. }
  25214. }
  25215. }
  25216. });
  25217. // plugins/simpleupload.js
  25218. /**
  25219. * @description 简单上传:点击按钮,直接选择文件上传
  25220. * @author Jinqn
  25221. * @date 2014-03-31
  25222. */
  25223. UE.plugin.register('simpleupload', function() {
  25224. var me = this,
  25225. isLoaded = false,
  25226. containerBtn;
  25227. function initUploadBtn() {
  25228. var w = containerBtn.offsetWidth || 20,
  25229. h = containerBtn.offsetHeight ||
  25230. 20,
  25231. btnIframe = document.createElement('iframe'),
  25232. btnStyle = 'display:block;width:' +
  25233. w +
  25234. 'px;height:' +
  25235. h +
  25236. '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;';
  25237. domUtils.on(btnIframe, 'load', function() {
  25238. var timestrap = (+new Date()).toString(36),
  25239. wrapper, btnIframeDoc, btnIframeBody;
  25240. btnIframeDoc = (btnIframe.contentDocument || btnIframe.contentWindow.document);
  25241. btnIframeBody = btnIframeDoc.body;
  25242. wrapper = btnIframeDoc.createElement('div');
  25243. wrapper.innerHTML = '<form id="edui_form_' +
  25244. timestrap +
  25245. '" target="edui_iframe_' +
  25246. timestrap +
  25247. '" method="POST" enctype="multipart/form-data" action="' +
  25248. me.getOpt('serverUrl') +
  25249. '" ' +
  25250. 'style="' +
  25251. btnStyle +
  25252. '">' +
  25253. '<input id="edui_input_' +
  25254. timestrap +
  25255. '" type="file" accept="image/*" name="' +
  25256. me.options.imageFieldName +
  25257. '" ' +
  25258. 'style="' +
  25259. btnStyle +
  25260. '">' +
  25261. '</form>' +
  25262. '<iframe id="edui_iframe_' +
  25263. timestrap +
  25264. '" name="edui_iframe_' +
  25265. timestrap +
  25266. '" style="display:none;width:0;height:0;border:0;margin:0;padding:0;position:absolute;"></iframe>';
  25267. wrapper.className = 'edui-' + me.options.theme;
  25268. wrapper.id = me.ui.id + '_iframeupload';
  25269. btnIframeBody.style.cssText = btnStyle;
  25270. btnIframeBody.style.width = w + 'px';
  25271. btnIframeBody.style.height = h + 'px';
  25272. btnIframeBody.appendChild(wrapper);
  25273. if(btnIframeBody.parentNode) {
  25274. btnIframeBody.parentNode.style.width = w + 'px';
  25275. btnIframeBody.parentNode.style.height = w + 'px';
  25276. }
  25277. var form = btnIframeDoc
  25278. .getElementById('edui_form_' + timestrap);
  25279. var input = btnIframeDoc.getElementById('edui_input_' +
  25280. timestrap);
  25281. var iframe = btnIframeDoc.getElementById('edui_iframe_' +
  25282. timestrap);
  25283. domUtils.on(input, 'change', function() {
  25284. if(!input.value)
  25285. return;
  25286. var loadingId = 'loading_' + (+new Date()).toString(36);
  25287. var params = utils.serializeParam(me
  25288. .queryCommandValue('serverparam')) ||
  25289. '';
  25290. var imageActionUrl = me.getActionUrl(me
  25291. .getOpt('imageActionName'));
  25292. var allowFiles = me.getOpt('imageAllowFiles');
  25293. me.focus();
  25294. me
  25295. .execCommand(
  25296. 'inserthtml',
  25297. '<img class="loadingclass" id="' +
  25298. loadingId +
  25299. '" src="' +
  25300. me.options.themePath +
  25301. me.options.theme +
  25302. '/images/spacer.gif" title="' +
  25303. (me
  25304. .getLang('simpleupload.loading') || '') +
  25305. '" >');
  25306. function callback() {
  25307. try {
  25308. var link, json, loader, body = (iframe.contentDocument || iframe.contentWindow.document).body,
  25309. result = body.innerText ||
  25310. body.textContent || '';
  25311. json = (new Function("return " + result))();
  25312. link = me.options.imageUrlPrefix + json.url;
  25313. if(json.state == 'SUCCESS' && json.url) {
  25314. loader = me.document.getElementById(loadingId);
  25315. loader.setAttribute("srcAttrName", "src");
  25316. loader.setAttribute("tokentag", "true");
  25317. // loader.setAttribute("source", json.url);
  25318. loader.setAttribute('src', json.tokenURL);
  25319. loader.setAttribute('_src', json.tokenURL);
  25320. loader.setAttribute('title', json.title || '');
  25321. loader.setAttribute('alt', json.original || '');
  25322. loader.removeAttribute('id');
  25323. domUtils.removeClasses(loader, 'loadingclass');
  25324. } else {
  25325. showErrorLoader && showErrorLoader(json.state);
  25326. }
  25327. } catch(er) {
  25328. showErrorLoader
  25329. &&
  25330. showErrorLoader(me
  25331. .getLang('simpleupload.loadError'));
  25332. }
  25333. form.reset();
  25334. domUtils.un(iframe, 'load', callback);
  25335. }
  25336. function showErrorLoader(title) {
  25337. if(loadingId) {
  25338. var loader = me.document.getElementById(loadingId);
  25339. loader && domUtils.remove(loader);
  25340. me.fireEvent('showmessage', {
  25341. 'id': loadingId,
  25342. 'content': title,
  25343. 'type': 'error',
  25344. 'timeout': 4000
  25345. });
  25346. }
  25347. }
  25348. /* 判断后端配置是否没有加载成功 */
  25349. if(!me.getOpt('imageActionName')) {
  25350. errorHandler(me.getLang('autoupload.errorLoadConfig'));
  25351. return;
  25352. }
  25353. // 判断文件格式是否错误
  25354. var filename = input.value,
  25355. fileext = filename ? filename
  25356. .substr(filename.lastIndexOf('.')) : '';
  25357. if(!fileext ||
  25358. (allowFiles && (allowFiles.join('') + '.')
  25359. .indexOf(fileext.toLowerCase() + '.') == -1)) {
  25360. showErrorLoader(me
  25361. .getLang('simpleupload.exceedTypeError'));
  25362. return;
  25363. }
  25364. domUtils.on(iframe, 'load', callback);
  25365. form.action = utils.formatUrl(imageActionUrl +
  25366. (imageActionUrl.indexOf('?') == -1 ? '?' : '&') + params); // + params) + getWdApp()。去掉 ?wdApplication=,不支持多个应用Lin
  25367. form.submit();
  25368. });
  25369. var stateTimer;
  25370. me.addListener('selectionchange', function() {
  25371. clearTimeout(stateTimer);
  25372. stateTimer = setTimeout(function() {
  25373. var state = me.queryCommandState('simpleupload');
  25374. if(state == -1) {
  25375. input.disabled = 'disabled';
  25376. } else {
  25377. input.disabled = false;
  25378. }
  25379. }, 400);
  25380. });
  25381. isLoaded = true;
  25382. });
  25383. btnIframe.style.cssText = btnStyle;
  25384. containerBtn.appendChild(btnIframe);
  25385. }
  25386. return {
  25387. bindEvents: {
  25388. 'ready': function() {
  25389. // 设置loading的样式
  25390. utils
  25391. .cssRule(
  25392. 'loading',
  25393. '.loadingclass{display:inline-block;cursor:default;background: url(\'' +
  25394. this.options.themePath +
  25395. this.options.theme +
  25396. '/images/loading.gif\') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;}\n' +
  25397. '.loaderrorclass{display:inline-block;cursor:default;background: url(\'' +
  25398. this.options.themePath +
  25399. this.options.theme +
  25400. '/images/loaderror.png\') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;' +
  25401. '}', this.document);
  25402. },
  25403. /* 初始化简单上传按钮 */
  25404. 'simpleuploadbtnready': function(type, container) {
  25405. containerBtn = container;
  25406. me.afterConfigReady(initUploadBtn);
  25407. }
  25408. },
  25409. outputRule: function(root) {
  25410. utils.each(root.getNodesByTagName('img'), function(n) {
  25411. if(/\b(loaderrorclass)|(bloaderrorclass)\b/.test(n
  25412. .getAttr('class'))) {
  25413. n.parentNode.removeChild(n);
  25414. }
  25415. });
  25416. },
  25417. commands: {
  25418. 'simpleupload': {
  25419. queryCommandState: function() {
  25420. return isLoaded ? 0 : -1;
  25421. }
  25422. }
  25423. }
  25424. }
  25425. });
  25426. // plugins/serverparam.js
  25427. /**
  25428. * 服务器提交的额外参数列表设置插件
  25429. *
  25430. * @file
  25431. * @since 1.2.6.1
  25432. */
  25433. UE.plugin.register('serverparam', function() {
  25434. var me = this,
  25435. serverParam = {};
  25436. return {
  25437. commands: {
  25438. /**
  25439. * 修改服务器提交的额外参数列表,清除所有项
  25440. *
  25441. * @command serverparam
  25442. * @method execCommand
  25443. * @param {
  25444. * String } cmd 命令字符串
  25445. * @example ```javascript editor.execCommand('serverparam');
  25446. * editor.queryCommandValue('serverparam'); //返回空 ```
  25447. */
  25448. /**
  25449. * 修改服务器提交的额外参数列表,删除指定项
  25450. *
  25451. * @command serverparam
  25452. * @method execCommand
  25453. * @param {
  25454. * String } cmd 命令字符串
  25455. * @param {
  25456. * String } key 要清除的属性
  25457. * @example ```javascript editor.execCommand('serverparam',
  25458. * 'name'); //删除属性name ```
  25459. */
  25460. /**
  25461. * 修改服务器提交的额外参数列表,使用键值添加项
  25462. *
  25463. * @command serverparam
  25464. * @method execCommand
  25465. * @param {
  25466. * String } cmd 命令字符串
  25467. * @param {
  25468. * String } key 要添加的属性
  25469. * @param {
  25470. * String } value 要添加属性的值
  25471. * @example ```javascript editor.execCommand('serverparam',
  25472. * 'name', 'hello');
  25473. * editor.queryCommandValue('serverparam'); //返回对象
  25474. * {'name': 'hello'} ```
  25475. */
  25476. /**
  25477. * 修改服务器提交的额外参数列表,传入键值对对象添加多项
  25478. *
  25479. * @command serverparam
  25480. * @method execCommand
  25481. * @param {
  25482. * String } cmd 命令字符串
  25483. * @param {
  25484. * Object } key 传入的键值对对象
  25485. * @example ```javascript editor.execCommand('serverparam',
  25486. * {'name': 'hello'});
  25487. * editor.queryCommandValue('serverparam'); //返回对象
  25488. * {'name': 'hello'} ```
  25489. */
  25490. /**
  25491. * 修改服务器提交的额外参数列表,使用自定义函数添加多项
  25492. *
  25493. * @command serverparam
  25494. * @method execCommand
  25495. * @param {
  25496. * String } cmd 命令字符串
  25497. * @param {
  25498. * Function } key 自定义获取参数的函数
  25499. * @example ```javascript editor.execCommand('serverparam',
  25500. * function(editor){ return {'key': 'value'}; });
  25501. * editor.queryCommandValue('serverparam'); //返回对象
  25502. * {'key': 'value'} ```
  25503. */
  25504. /**
  25505. * 获取服务器提交的额外参数列表
  25506. *
  25507. * @command serverparam
  25508. * @method queryCommandValue
  25509. * @param {
  25510. * String } cmd 命令字符串
  25511. * @example ```javascript editor.queryCommandValue(
  25512. * 'serverparam' ); //返回对象 {'key': 'value'} ```
  25513. */
  25514. 'serverparam': {
  25515. execCommand: function(cmd, key, value) {
  25516. if(key === undefined || key === null) { // 不传参数,清空列表
  25517. serverParam = {};
  25518. } else if(utils.isString(key)) { // 传入键值
  25519. if(value === undefined || value === null) {
  25520. delete serverParam[key];
  25521. } else {
  25522. serverParam[key] = value;
  25523. }
  25524. } else if(utils.isObject(key)) { // 传入对象,覆盖列表项
  25525. utils.extend(serverParam, key, true);
  25526. } else if(utils.isFunction(key)) { // 传入函数,添加列表项
  25527. utils.extend(serverParam, key(), true);
  25528. }
  25529. },
  25530. queryCommandValue: function() {
  25531. return serverParam || {};
  25532. }
  25533. }
  25534. }
  25535. }
  25536. });
  25537. // plugins/insertfile.js
  25538. /**
  25539. * 插入附件
  25540. */
  25541. UE.plugin.register('insertfile', function() {
  25542. var me = this;
  25543. function getFileIcon(url) {
  25544. var ext = url.substr(url.lastIndexOf('.') + 1).toLowerCase(),
  25545. maps = {
  25546. "rar": "icon_rar.gif",
  25547. "zip": "icon_rar.gif",
  25548. "tar": "icon_rar.gif",
  25549. "gz": "icon_rar.gif",
  25550. "bz2": "icon_rar.gif",
  25551. "doc": "icon_doc.gif",
  25552. "docx": "icon_doc.gif",
  25553. "pdf": "icon_pdf.gif",
  25554. "mp3": "icon_mp3.gif",
  25555. "xls": "icon_xls.gif",
  25556. "chm": "icon_chm.gif",
  25557. "ppt": "icon_ppt.gif",
  25558. "pptx": "icon_ppt.gif",
  25559. "avi": "icon_mv.gif",
  25560. "rmvb": "icon_mv.gif",
  25561. "wmv": "icon_mv.gif",
  25562. "flv": "icon_mv.gif",
  25563. "swf": "icon_mv.gif",
  25564. "rm": "icon_mv.gif",
  25565. "exe": "icon_exe.gif",
  25566. "psd": "icon_psd.gif",
  25567. "txt": "icon_txt.gif",
  25568. "jpg": "icon_jpg.gif",
  25569. "png": "icon_jpg.gif",
  25570. "jpeg": "icon_jpg.gif",
  25571. "gif": "icon_jpg.gif",
  25572. "ico": "icon_jpg.gif",
  25573. "bmp": "icon_jpg.gif"
  25574. };
  25575. return maps[ext] ? maps[ext] : maps['txt'];
  25576. }
  25577. return {
  25578. commands: {
  25579. 'insertfile': {
  25580. execCommand: function(command, filelist) {
  25581. filelist = utils.isArray(filelist) ?
  25582. filelist : [filelist];
  25583. var i, item, icon, title, html = '',
  25584. URL = me
  25585. .getOpt('UEDITOR_HOME_URL'),
  25586. iconDir = URL +
  25587. (URL.substr(URL.length - 1) == '/' ? '' : '/') +
  25588. 'dialogs/attachment/fileTypeImages/';
  25589. for(i = 0; i < filelist.length; i++) {
  25590. item = filelist[i];
  25591. icon = iconDir + getFileIcon(item.url);
  25592. title = item.title ||
  25593. item.url.substr(item.url
  25594. .lastIndexOf('/') +
  25595. 1);
  25596. var s = '';
  25597. // if(item.url.lastIndexOf(".pdf") > -1) {
  25598. // // //专门为了pdf改的
  25599. // // var pdfid = "pdf" + Math.round(Math.random() *
  25600. // 1000 + 1, 0);
  25601. // // s = '<!--<a style="font-size:12px;
  25602. // color:#0066cc;" href="' + item.url + '&asfile=0"
  25603. // title="' + title + '">' + title + '</a>-->' +
  25604. // // '<span id="' + pdfid + '" >' +
  25605. // // '<img style="width:200px;height:300px;" src="'
  25606. // + icon + '" _src="' + icon + '" id="img' + pdfid
  25607. // + '"/>' +
  25608. // // '<script wdscript="true"
  25609. // type="text/javascript" src="' +
  25610. // window.UEDITOR_HOME_URL +
  25611. // '/pdfobject.min.js"></script>' +
  25612. // // '<script wdscript="true">if(typeof me ===
  25613. // "undefined"){' +
  25614. // // 'var img=document.getElementById("img' + pdfid
  25615. // + '");var dic=document.getElementById("' + pdfid
  25616. // +
  25617. // '");dic.width=img.width;dic.height=img.height;dic.setAttribute("style",img.getAttribute("style"));dic.style.display="inline-block";'
  25618. // +
  25619. // // 'PDFObject.embed("' + item.url + '", "#' +
  25620. // pdfid + '");' +
  25621. // // '}</script>' + '</span>';
  25622. // // html += s;
  25623. // html+='<p style="line-height: 16px;">' +
  25624. // '<img style="vertical-align: middle;
  25625. // margin-right: 2px;" src="' + icon + '" _src="' +
  25626. // icon + '" />' +
  25627. // '<a style="font-size:12px;
  25628. // color:#0066cc;cursor:pointer;" target="blank_"
  25629. // href="' + item.url + '&asfile=0" title="' + title
  25630. // + '">' + title + '</a>'+
  25631. // '</p>';
  25632. // } else{
  25633. html += '<p style="line-height: 16px;">' +
  25634. '<img style="vertical-align: middle; margin-right: 2px;" src="' +
  25635. icon + '" _src="' + icon + '" />' +
  25636. '<a style="font-size:12px; color:#0066cc;cursor:pointer;" target="blank_" tokentag="true" srcattrname="href"' +
  25637. 'href="' + item.tokenURL + '&asfile=0&withname=0" title="' + title + '">' + title + '</a>' + '</p>';
  25638. }
  25639. // 大改…………………………
  25640. // }
  25641. me.execCommand('insertHtml', html);
  25642. }
  25643. }
  25644. }
  25645. }
  25646. });
  25647. // ui/ui.js
  25648. var baidu = baidu || {};
  25649. baidu.editor = baidu.editor || {};
  25650. UE.ui = baidu.editor.ui = {};
  25651. // ui/uiutils.js
  25652. (function() {
  25653. var browser = baidu.editor.browser,
  25654. domUtils = baidu.editor.dom.domUtils;
  25655. var magic = '$EDITORUI';
  25656. var root = window[magic] = {};
  25657. var uidMagic = 'ID' + magic;
  25658. var uidCount = 0;
  25659. var uiUtils = baidu.editor.ui.uiUtils = {
  25660. uid: function(obj) {
  25661. return(obj ?
  25662. obj[uidMagic] || (obj[uidMagic] = ++uidCount) :
  25663. ++uidCount);
  25664. },
  25665. hook: function(fn, callback) {
  25666. var dg;
  25667. if(fn && fn._callbacks) {
  25668. dg = fn;
  25669. } else {
  25670. dg = function() {
  25671. var q;
  25672. if(fn) {
  25673. q = fn.apply(this, arguments);
  25674. }
  25675. var callbacks = dg._callbacks;
  25676. var k = callbacks.length;
  25677. while(k--) {
  25678. var r = callbacks[k].apply(this, arguments);
  25679. if(q === undefined) {
  25680. q = r;
  25681. }
  25682. }
  25683. return q;
  25684. };
  25685. dg._callbacks = [];
  25686. }
  25687. dg._callbacks.push(callback);
  25688. return dg;
  25689. },
  25690. createElementByHtml: function(html) {
  25691. var el = document.createElement('div');
  25692. el.innerHTML = html;
  25693. el = el.firstChild;
  25694. el.parentNode.removeChild(el);
  25695. return el;
  25696. },
  25697. getViewportElement: function() {
  25698. return(browser.ie && browser.quirks) ?
  25699. document.body :
  25700. document.documentElement;
  25701. },
  25702. getClientRect: function(element) {
  25703. var bcr;
  25704. // trace IE6下在控制编辑器显隐时可能会报错,catch一下
  25705. try {
  25706. bcr = element.getBoundingClientRect();
  25707. } catch(e) {
  25708. bcr = {
  25709. left: 0,
  25710. top: 0,
  25711. height: 0,
  25712. width: 0
  25713. }
  25714. }
  25715. var rect = {
  25716. left: Math.round(bcr.left),
  25717. top: Math.round(bcr.top),
  25718. height: Math.round(bcr.bottom - bcr.top),
  25719. width: Math.round(bcr.right - bcr.left)
  25720. };
  25721. var doc;
  25722. while((doc = element.ownerDocument) !== document &&
  25723. (element = domUtils.getWindow(doc).frameElement)) {
  25724. bcr = element.getBoundingClientRect();
  25725. rect.left += bcr.left;
  25726. rect.top += bcr.top;
  25727. }
  25728. rect.bottom = rect.top + rect.height;
  25729. rect.right = rect.left + rect.width;
  25730. return rect;
  25731. },
  25732. getViewportRect: function() {
  25733. var viewportEl = uiUtils.getViewportElement();
  25734. var width = (window.innerWidth || viewportEl.clientWidth) | 0;
  25735. var height = (window.innerHeight || viewportEl.clientHeight) |
  25736. 0;
  25737. return {
  25738. left: 0,
  25739. top: 0,
  25740. height: height,
  25741. width: width,
  25742. bottom: height,
  25743. right: width
  25744. };
  25745. },
  25746. setViewportOffset: function(element, offset) {
  25747. var rect;
  25748. var fixedLayer = uiUtils.getFixedLayer();
  25749. if(element.parentNode === fixedLayer) {
  25750. element.style.left = offset.left + 'px';
  25751. element.style.top = offset.top + 'px';
  25752. } else {
  25753. domUtils.setViewportOffset(element, offset);
  25754. }
  25755. },
  25756. getEventOffset: function(evt) {
  25757. var el = evt.target || evt.srcElement;
  25758. var rect = uiUtils.getClientRect(el);
  25759. var offset = uiUtils.getViewportOffsetByEvent(evt);
  25760. return {
  25761. left: offset.left - rect.left,
  25762. top: offset.top - rect.top
  25763. };
  25764. },
  25765. getViewportOffsetByEvent: function(evt) {
  25766. var el = evt.target || evt.srcElement;
  25767. var frameEl = domUtils.getWindow(el).frameElement;
  25768. var offset = {
  25769. left: evt.clientX,
  25770. top: evt.clientY
  25771. };
  25772. if(frameEl && el.ownerDocument !== document) {
  25773. var rect = uiUtils.getClientRect(frameEl);
  25774. offset.left += rect.left;
  25775. offset.top += rect.top;
  25776. }
  25777. return offset;
  25778. },
  25779. setGlobal: function(id, obj) {
  25780. root[id] = obj;
  25781. return magic + '["' + id + '"]';
  25782. },
  25783. unsetGlobal: function(id) {
  25784. delete root[id];
  25785. },
  25786. copyAttributes: function(tgt, src) {
  25787. var attributes = src.attributes;
  25788. var k = attributes.length;
  25789. while(k--) {
  25790. var attrNode = attributes[k];
  25791. if(attrNode.nodeName != 'style' &&
  25792. attrNode.nodeName != 'class' &&
  25793. (!browser.ie || attrNode.specified)) {
  25794. tgt.setAttribute(attrNode.nodeName, attrNode.nodeValue);
  25795. }
  25796. }
  25797. if(src.className) {
  25798. domUtils.addClass(tgt, src.className);
  25799. }
  25800. if(src.style.cssText) {
  25801. tgt.style.cssText += ';' + src.style.cssText;
  25802. }
  25803. },
  25804. removeStyle: function(el, styleName) {
  25805. if(el.style.removeProperty) {
  25806. el.style.removeProperty(styleName);
  25807. } else if(el.style.removeAttribute) {
  25808. el.style.removeAttribute(styleName);
  25809. } else
  25810. throw '';
  25811. },
  25812. contains: function(elA, elB) {
  25813. return elA &&
  25814. elB &&
  25815. (elA === elB ? false : (elA.contains ? elA
  25816. .contains(elB) : elA
  25817. .compareDocumentPosition(elB) &
  25818. 16));
  25819. },
  25820. startDrag: function(evt, callbacks, doc) {
  25821. var doc = doc || document;
  25822. var startX = evt.clientX;
  25823. var startY = evt.clientY;
  25824. function handleMouseMove(evt) {
  25825. var x = evt.clientX - startX;
  25826. var y = evt.clientY - startY;
  25827. callbacks.ondragmove(x, y, evt);
  25828. if(evt.stopPropagation) {
  25829. evt.stopPropagation();
  25830. } else {
  25831. evt.cancelBubble = true;
  25832. }
  25833. }
  25834. if(doc.addEventListener) {
  25835. function handleMouseUp(evt) {
  25836. doc.removeEventListener('mousemove', handleMouseMove,
  25837. true);
  25838. doc.removeEventListener('mouseup', handleMouseUp, true);
  25839. window.removeEventListener('mouseup', handleMouseUp,
  25840. true);
  25841. callbacks.ondragstop();
  25842. }
  25843. doc.addEventListener('mousemove', handleMouseMove, true);
  25844. doc.addEventListener('mouseup', handleMouseUp, true);
  25845. window.addEventListener('mouseup', handleMouseUp, true);
  25846. evt.preventDefault();
  25847. } else {
  25848. var elm = evt.srcElement;
  25849. elm.setCapture();
  25850. function releaseCaptrue() {
  25851. elm.releaseCapture();
  25852. elm.detachEvent('onmousemove', handleMouseMove);
  25853. elm.detachEvent('onmouseup', releaseCaptrue);
  25854. elm.detachEvent('onlosecaptrue', releaseCaptrue);
  25855. callbacks.ondragstop();
  25856. }
  25857. elm.attachEvent('onmousemove', handleMouseMove);
  25858. elm.attachEvent('onmouseup', releaseCaptrue);
  25859. elm.attachEvent('onlosecaptrue', releaseCaptrue);
  25860. evt.returnValue = false;
  25861. }
  25862. callbacks.ondragstart();
  25863. },
  25864. getFixedLayer: function() {
  25865. var layer = document.getElementById('edui_fixedlayer');
  25866. if(layer == null) {
  25867. layer = document.createElement('div');
  25868. layer.id = 'edui_fixedlayer';
  25869. document.body.appendChild(layer);
  25870. if(browser.ie && browser.version <= 8) {
  25871. layer.style.position = 'absolute';
  25872. bindFixedLayer();
  25873. setTimeout(updateFixedOffset);
  25874. } else {
  25875. layer.style.position = 'fixed';
  25876. }
  25877. layer.style.left = '0';
  25878. layer.style.top = '0';
  25879. layer.style.width = '0';
  25880. layer.style.height = '0';
  25881. }
  25882. return layer;
  25883. },
  25884. makeUnselectable: function(element) {
  25885. if(browser.opera || (browser.ie && browser.version < 9)) {
  25886. element.unselectable = 'on';
  25887. if(element.hasChildNodes()) {
  25888. for(var i = 0; i < element.childNodes.length; i++) {
  25889. if(element.childNodes[i].nodeType == 1) {
  25890. uiUtils.makeUnselectable(element.childNodes[i]);
  25891. }
  25892. }
  25893. }
  25894. } else {
  25895. if(element.style.MozUserSelect !== undefined) {
  25896. element.style.MozUserSelect = 'none';
  25897. } else if(element.style.WebkitUserSelect !== undefined) {
  25898. element.style.WebkitUserSelect = 'none';
  25899. } else if(element.style.KhtmlUserSelect !== undefined) {
  25900. element.style.KhtmlUserSelect = 'none';
  25901. }
  25902. }
  25903. }
  25904. };
  25905. function updateFixedOffset() {
  25906. var layer = document.getElementById('edui_fixedlayer');
  25907. uiUtils.setViewportOffset(layer, {
  25908. left: 0,
  25909. top: 0
  25910. });
  25911. // layer.style.display = 'none';
  25912. // layer.style.display = 'block';
  25913. // #trace: 1354
  25914. // setTimeout(updateFixedOffset);
  25915. }
  25916. function bindFixedLayer(adjOffset) {
  25917. domUtils.on(window, 'scroll', updateFixedOffset);
  25918. domUtils.on(window, 'resize', baidu.editor.utils.defer(
  25919. updateFixedOffset, 0, true));
  25920. }
  25921. })();
  25922. // ui/uibase.js
  25923. (function() {
  25924. var utils = baidu.editor.utils,
  25925. uiUtils = baidu.editor.ui.uiUtils,
  25926. EventBase = baidu.editor.EventBase,
  25927. UIBase = baidu.editor.ui.UIBase = function() {};
  25928. UIBase.prototype = {
  25929. className: '',
  25930. uiName: '',
  25931. initOptions: function(options) {
  25932. var me = this;
  25933. for(var k in options) {
  25934. me[k] = options[k];
  25935. }
  25936. this.id = this.id || 'edui' + uiUtils.uid();
  25937. },
  25938. initUIBase: function() {
  25939. this._globalKey = utils
  25940. .unhtml(uiUtils.setGlobal(this.id, this));
  25941. },
  25942. render: function(holder) {
  25943. var html = this.renderHtml();
  25944. var el = uiUtils.createElementByHtml(html);
  25945. // by xuheng 给每个node添加class
  25946. var list = domUtils.getElementsByTagName(el, "*");
  25947. var theme = "edui-" + (this.theme || this.editor.options.theme);
  25948. var layer = document.getElementById('edui_fixedlayer');
  25949. for(var i = 0, node; node = list[i++];) {
  25950. domUtils.addClass(node, theme);
  25951. }
  25952. domUtils.addClass(el, theme);
  25953. if(layer) {
  25954. layer.className = "";
  25955. domUtils.addClass(layer, theme);
  25956. }
  25957. var seatEl = this.getDom();
  25958. if(seatEl != null) {
  25959. seatEl.parentNode.replaceChild(el, seatEl);
  25960. uiUtils.copyAttributes(el, seatEl);
  25961. } else {
  25962. if(typeof holder == 'string') {
  25963. holder = document.getElementById(holder);
  25964. }
  25965. holder = holder || uiUtils.getFixedLayer();
  25966. domUtils.addClass(holder, theme);
  25967. holder.appendChild(el);
  25968. }
  25969. this.postRender();
  25970. },
  25971. getDom: function(name) {
  25972. if(!name) {
  25973. return document.getElementById(this.id);
  25974. } else {
  25975. return document.getElementById(this.id + '_' + name);
  25976. }
  25977. },
  25978. postRender: function() {
  25979. this.fireEvent('postrender');
  25980. },
  25981. getHtmlTpl: function() {
  25982. return '';
  25983. },
  25984. formatHtml: function(tpl) {
  25985. var prefix = 'edui-' + this.uiName;
  25986. return(tpl.replace(/##/g, this.id).replace(/%%-/g,
  25987. this.uiName ? prefix + '-' : '').replace(/%%/g,
  25988. (this.uiName ? prefix : '') + ' ' + this.className)
  25989. .replace(/\$\$/g, this._globalKey));
  25990. },
  25991. renderHtml: function() {
  25992. return this.formatHtml(this.getHtmlTpl());
  25993. },
  25994. dispose: function() {
  25995. var box = this.getDom();
  25996. if(box)
  25997. baidu.editor.dom.domUtils.remove(box);
  25998. uiUtils.unsetGlobal(this.id);
  25999. }
  26000. };
  26001. utils.inherits(UIBase, EventBase);
  26002. })();
  26003. // ui/separator.js
  26004. (function() {
  26005. var utils = baidu.editor.utils,
  26006. UIBase = baidu.editor.ui.UIBase,
  26007. Separator = baidu.editor.ui.Separator = function(
  26008. options) {
  26009. this.initOptions(options);
  26010. this.initSeparator();
  26011. };
  26012. Separator.prototype = {
  26013. uiName: 'separator',
  26014. initSeparator: function() {
  26015. this.initUIBase();
  26016. },
  26017. getHtmlTpl: function() {
  26018. return '<div id="##" class="edui-box %%"></div>';
  26019. }
  26020. };
  26021. utils.inherits(Separator, UIBase);
  26022. })();
  26023. // ui/mask.js
  26024. // /import core
  26025. // /import uicore
  26026. (function() {
  26027. var utils = baidu.editor.utils,
  26028. domUtils = baidu.editor.dom.domUtils,
  26029. UIBase = baidu.editor.ui.UIBase,
  26030. uiUtils = baidu.editor.ui.uiUtils;
  26031. var Mask = baidu.editor.ui.Mask = function(options) {
  26032. this.initOptions(options);
  26033. this.initUIBase();
  26034. };
  26035. Mask.prototype = {
  26036. getHtmlTpl: function() {
  26037. return '<div id="##" class="edui-mask %%" onclick="return $$._onClick(event, this);" onmousedown="return $$._onMouseDown(event, this);"></div>';
  26038. },
  26039. postRender: function() {
  26040. var me = this;
  26041. domUtils.on(window, 'resize', function() {
  26042. setTimeout(function() {
  26043. if(!me.isHidden()) {
  26044. me._fill();
  26045. }
  26046. });
  26047. });
  26048. },
  26049. show: function(zIndex) {
  26050. this._fill();
  26051. this.getDom().style.display = '';
  26052. this.getDom().style.zIndex = zIndex;
  26053. },
  26054. hide: function() {
  26055. this.getDom().style.display = 'none';
  26056. this.getDom().style.zIndex = '';
  26057. },
  26058. isHidden: function() {
  26059. return this.getDom().style.display == 'none';
  26060. },
  26061. _onMouseDown: function() {
  26062. return false;
  26063. },
  26064. _onClick: function(e, target) {
  26065. this.fireEvent('click', e, target);
  26066. },
  26067. _fill: function() {
  26068. var el = this.getDom();
  26069. var vpRect = uiUtils.getViewportRect();
  26070. el.style.width = vpRect.width + 'px';
  26071. el.style.height = vpRect.height + 'px';
  26072. }
  26073. };
  26074. utils.inherits(Mask, UIBase);
  26075. })();
  26076. // ui/popup.js
  26077. // /import core
  26078. // /import uicore
  26079. (function() {
  26080. var utils = baidu.editor.utils,
  26081. uiUtils = baidu.editor.ui.uiUtils,
  26082. domUtils = baidu.editor.dom.domUtils,
  26083. UIBase = baidu.editor.ui.UIBase,
  26084. Popup = baidu.editor.ui.Popup = function(
  26085. options) {
  26086. this.initOptions(options);
  26087. this.initPopup();
  26088. };
  26089. var allPopups = [];
  26090. function closeAllPopup(evt, el) {
  26091. for(var i = 0; i < allPopups.length; i++) {
  26092. var pop = allPopups[i];
  26093. if(!pop.isHidden()) {
  26094. if(pop.queryAutoHide(el) !== false) {
  26095. if(evt && /scroll/ig.test(evt.type) &&
  26096. pop.className == "edui-wordpastepop")
  26097. return;
  26098. pop.hide();
  26099. }
  26100. }
  26101. }
  26102. if(allPopups.length)
  26103. pop.editor.fireEvent("afterhidepop");
  26104. }
  26105. Popup.postHide = closeAllPopup;
  26106. var ANCHOR_CLASSES = ['edui-anchor-topleft', 'edui-anchor-topright',
  26107. 'edui-anchor-bottomleft', 'edui-anchor-bottomright'
  26108. ];
  26109. Popup.prototype = {
  26110. SHADOW_RADIUS: 5,
  26111. content: null,
  26112. _hidden: false,
  26113. autoRender: true,
  26114. canSideLeft: true,
  26115. canSideUp: true,
  26116. initPopup: function() {
  26117. this.initUIBase();
  26118. allPopups.push(this);
  26119. },
  26120. getHtmlTpl: function() {
  26121. return '<div id="##" class="edui-popup %%" onmousedown="return false;">' +
  26122. ' <div id="##_body" class="edui-popup-body">' +
  26123. ' <iframe style="position:absolute;z-index:-1;left:0;top:0;background-color: transparent;" frameborder="0" width="100%" height="100%" src="about:blank"></iframe>' +
  26124. ' <div class="edui-shadow"></div>' +
  26125. ' <div id="##_content" class="edui-popup-content floatToolbar-div">' +
  26126. this.getContentHtmlTpl() +
  26127. ' </div>' +
  26128. ' </div>' +
  26129. '</div>';
  26130. },
  26131. getContentHtmlTpl: function() {
  26132. if(this.content) {
  26133. if(typeof this.content == 'string') {
  26134. return this.content;
  26135. }
  26136. return this.content.renderHtml();
  26137. } else {
  26138. return ''
  26139. }
  26140. },
  26141. _UIBase_postRender: UIBase.prototype.postRender,
  26142. postRender: function() {
  26143. if(this.content instanceof UIBase) {
  26144. this.content.postRender();
  26145. }
  26146. // 捕获鼠标滚轮
  26147. if(this.captureWheel && !this.captured) {
  26148. this.captured = true;
  26149. var winHeight = (document.documentElement.clientHeight || document.body.clientHeight) -
  26150. 80,
  26151. _height = this.getDom().offsetHeight,
  26152. _top = uiUtils
  26153. .getClientRect(this.combox.getDom()).top,
  26154. content = this
  26155. .getDom('content'),
  26156. ifr = this.getDom('body')
  26157. .getElementsByTagName('iframe'),
  26158. me = this;
  26159. ifr.length && (ifr = ifr[0]);
  26160. while(_top + _height > winHeight) {
  26161. _height -= 30;
  26162. }
  26163. content.style.height = _height + 'px';
  26164. // 同步更改iframe高度
  26165. ifr && (ifr.style.height = _height + 'px');
  26166. // 阻止在combox上的鼠标滚轮事件, 防止用户的正常操作被误解
  26167. if(window.XMLHttpRequest) {
  26168. domUtils.on(content, ('onmousewheel' in document.body) ?
  26169. 'mousewheel' :
  26170. 'DOMMouseScroll',
  26171. function(e) {
  26172. if(e.preventDefault) {
  26173. e.preventDefault();
  26174. } else {
  26175. e.returnValue = false;
  26176. }
  26177. if(e.wheelDelta) {
  26178. content.scrollTop -= (e.wheelDelta / 120) * 60;
  26179. } else {
  26180. content.scrollTop -= (e.detail / -3) * 60;
  26181. }
  26182. });
  26183. } else {
  26184. // ie6
  26185. domUtils.on(this.getDom(), 'mousewheel', function(e) {
  26186. e.returnValue = false;
  26187. me.getDom('content').scrollTop -= (e.wheelDelta / 120) *
  26188. 60;
  26189. });
  26190. }
  26191. }
  26192. this.fireEvent('postRenderAfter');
  26193. this.hide(true);
  26194. this._UIBase_postRender();
  26195. },
  26196. _doAutoRender: function() {
  26197. if(!this.getDom() && this.autoRender) {
  26198. this.render();
  26199. }
  26200. },
  26201. mesureSize: function() {
  26202. var box = this.getDom('content');
  26203. return uiUtils.getClientRect(box);
  26204. },
  26205. fitSize: function() {
  26206. if(this.captureWheel && this.sized) {
  26207. return this.__size;
  26208. }
  26209. this.sized = true;
  26210. var popBodyEl = this.getDom('body');
  26211. popBodyEl.style.width = '';
  26212. popBodyEl.style.height = '';
  26213. var size = this.mesureSize();
  26214. if(this.captureWheel) {
  26215. popBodyEl.style.width = -(-20 - size.width) + 'px';
  26216. var height = parseInt(this.getDom('content').style.height,
  26217. 10);
  26218. !window.isNaN(height) && (size.height = height);
  26219. } else {
  26220. popBodyEl.style.width = size.width + 'px';
  26221. }
  26222. popBodyEl.style.height = size.height + 'px';
  26223. this.__size = size;
  26224. this.captureWheel &&
  26225. (this.getDom('content').style.overflow = 'auto');
  26226. return size;
  26227. },
  26228. showAnchor: function(element, hoz) {
  26229. this.showAnchorRect(uiUtils.getClientRect(element), hoz);
  26230. },
  26231. showAnchorRect: function(rect, hoz, adj) {
  26232. this._doAutoRender();
  26233. var vpRect = uiUtils.getViewportRect();
  26234. this.getDom().style.visibility = 'hidden';
  26235. this._show();
  26236. var popSize = this.fitSize();
  26237. var sideLeft, sideUp, left, top;
  26238. if(hoz) {
  26239. sideLeft = this.canSideLeft &&
  26240. (rect.right + popSize.width > vpRect.right && rect.left > popSize.width);
  26241. sideUp = this.canSideUp &&
  26242. (rect.top + popSize.height > vpRect.bottom && rect.bottom > popSize.height);
  26243. left = (sideLeft ? rect.left - popSize.width : rect.right);
  26244. top = (sideUp ? rect.bottom - popSize.height : rect.top);
  26245. } else {
  26246. sideLeft = this.canSideLeft &&
  26247. (rect.right + popSize.width > vpRect.right && rect.left > popSize.width);
  26248. sideUp = this.canSideUp &&
  26249. (rect.top + popSize.height > vpRect.bottom && rect.bottom > popSize.height);
  26250. left = (sideLeft ? rect.right - popSize.width : rect.left);
  26251. top = (sideUp ? rect.top - popSize.height : rect.bottom);
  26252. }
  26253. var popEl = this.getDom();
  26254. uiUtils.setViewportOffset(popEl, {
  26255. left: left,
  26256. top: top
  26257. });
  26258. domUtils.removeClasses(popEl, ANCHOR_CLASSES);
  26259. popEl.className += ' ' +
  26260. ANCHOR_CLASSES[(sideUp ? 1 : 0) * 2 +
  26261. (sideLeft ? 1 : 0)];
  26262. if(this.editor) {
  26263. popEl.style.zIndex = this.editor.container.style.zIndex * 1 +
  26264. 10;
  26265. baidu.editor.ui.uiUtils.getFixedLayer().style.zIndex = popEl.style.zIndex -
  26266. 1;
  26267. }
  26268. this.getDom().style.visibility = 'visible';
  26269. },
  26270. showAt: function(offset) {
  26271. var left = offset.left;
  26272. var top = offset.top;
  26273. var rect = {
  26274. left: left,
  26275. top: top,
  26276. right: left,
  26277. bottom: top,
  26278. height: 0,
  26279. width: 0
  26280. };
  26281. this.showAnchorRect(rect, false, true);
  26282. },
  26283. _show: function() {
  26284. if(this._hidden) {
  26285. var box = this.getDom();
  26286. box.style.display = '';
  26287. this._hidden = false;
  26288. // if (box.setActive) {
  26289. // box.setActive();
  26290. // }
  26291. this.fireEvent('show');
  26292. }
  26293. },
  26294. isHidden: function() {
  26295. return this._hidden;
  26296. },
  26297. show: function() {
  26298. this._doAutoRender();
  26299. this._show();
  26300. },
  26301. hide: function(notNofity) {
  26302. if(!this._hidden && this.getDom()) {
  26303. this.getDom().style.display = 'none';
  26304. this._hidden = true;
  26305. if(!notNofity) {
  26306. this.fireEvent('hide');
  26307. }
  26308. }
  26309. },
  26310. queryAutoHide: function(el) {
  26311. return !el || !uiUtils.contains(this.getDom(), el);
  26312. }
  26313. };
  26314. utils.inherits(Popup, UIBase);
  26315. domUtils.on(document, 'mousedown', function(evt) {
  26316. var el = evt.target || evt.srcElement;
  26317. closeAllPopup(evt, el);
  26318. });
  26319. domUtils.on(window, 'scroll', function(evt, el) {
  26320. closeAllPopup(evt, el);
  26321. });
  26322. })();
  26323. // ui/colorpicker.js
  26324. // /import core
  26325. // /import uicore
  26326. (function() {
  26327. var utils = baidu.editor.utils,
  26328. UIBase = baidu.editor.ui.UIBase,
  26329. ColorPicker = baidu.editor.ui.ColorPicker = function(
  26330. options) {
  26331. this.initOptions(options);
  26332. this.noColorText = this.noColorText ||
  26333. this.editor.getLang("clearColor");
  26334. this.initUIBase();
  26335. };
  26336. ColorPicker.prototype = {
  26337. getHtmlTpl: function() {
  26338. return genColorPicker(this.noColorText, this.editor);
  26339. },
  26340. _onTableClick: function(evt) {
  26341. var tgt = evt.target || evt.srcElement;
  26342. var color = tgt.getAttribute('data-color');
  26343. if(color) {
  26344. this.fireEvent('pickcolor', color);
  26345. }
  26346. },
  26347. _onTableOver: function(evt) {
  26348. var tgt = evt.target || evt.srcElement;
  26349. var color = tgt.getAttribute('data-color');
  26350. if(color) {
  26351. this.getDom('preview').style.backgroundColor = color;
  26352. }
  26353. },
  26354. _onTableOut: function() {
  26355. this.getDom('preview').style.backgroundColor = '';
  26356. },
  26357. _onPickNoColor: function() {
  26358. this.fireEvent('picknocolor');
  26359. }
  26360. };
  26361. utils.inherits(ColorPicker, UIBase);
  26362. var COLORS = ('ffffff,000000,eeece1,1f497d,4f81bd,c0504d,9bbb59,8064a2,4bacc6,f79646,' +
  26363. 'f2f2f2,7f7f7f,ddd9c3,c6d9f0,dbe5f1,f2dcdb,ebf1dd,e5e0ec,dbeef3,fdeada,' +
  26364. 'd8d8d8,595959,c4bd97,8db3e2,b8cce4,e5b9b7,d7e3bc,ccc1d9,b7dde8,fbd5b5,' +
  26365. 'bfbfbf,3f3f3f,938953,548dd4,95b3d7,d99694,c3d69b,b2a2c7,92cddc,fac08f,' +
  26366. 'a5a5a5,262626,494429,17365d,366092,953734,76923c,5f497a,31859b,e36c09,' +
  26367. '7f7f7f,0c0c0c,1d1b10,0f243e,244061,632423,4f6128,3f3151,205867,974806,' + 'c00000,ff0000,ffc000,ffff00,92d050,00b050,00b0f0,0070c0,002060,7030a0,')
  26368. .split(',');
  26369. function genColorPicker(noColorText, editor) {
  26370. var html = '<div id="##" class="edui-colorpicker %%">' +
  26371. '<div class="edui-colorpicker-topbar edui-clearfix">' +
  26372. '<div unselectable="on" id="##_preview" class="edui-colorpicker-preview"></div>' +
  26373. '<div unselectable="on" class="edui-colorpicker-nocolor" onclick="$$._onPickNoColor(event, this);">' +
  26374. noColorText +
  26375. '</div>' +
  26376. '</div>' +
  26377. '<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">' +
  26378. '<tr style="border-bottom: 1px solid #ddd;font-size: 13px;line-height: 25px;color:#39C;padding-top: 2px"><td colspan="10">' +
  26379. editor.getLang("themeColor") + '</td> </tr>' +
  26380. '<tr class="edui-colorpicker-tablefirstrow" >';
  26381. for(var i = 0; i < COLORS.length; i++) {
  26382. if(i && i % 10 === 0) {
  26383. html += '</tr>' +
  26384. (i == 60 ?
  26385. '<tr style="border-bottom: 1px solid #ddd;font-size: 13px;line-height: 25px;color:#39C;"><td colspan="10">' +
  26386. editor.getLang("standardColor") +
  26387. '</td></tr>' :
  26388. '') +
  26389. '<tr' +
  26390. (i == 60 ?
  26391. ' class="edui-colorpicker-tablefirstrow"' :
  26392. '') + '>';
  26393. }
  26394. html += i < 70 ?
  26395. '<td style="padding: 0 2px;"><a hidefocus title="' +
  26396. COLORS[i] +
  26397. '" onclick="return false;" href="javascript:" unselectable="on" class="edui-box edui-colorpicker-colorcell"' +
  26398. ' data-color="#' +
  26399. COLORS[i] +
  26400. '"' +
  26401. ' style="background-color:#' +
  26402. COLORS[i] +
  26403. ';border:solid #ccc;' +
  26404. (i < 10 || i >= 60 ?
  26405. 'border-width:1px;' :
  26406. i >= 10 && i < 20 ?
  26407. 'border-width:1px 1px 0 1px;' :
  26408. 'border-width:0 1px 0 1px;') +
  26409. '"' + '></a></td>' :
  26410. '';
  26411. }
  26412. html += '</tr></table></div>';
  26413. return html;
  26414. }
  26415. })();
  26416. // ui/tablepicker.js
  26417. // /import core
  26418. // /import uicore
  26419. (function() {
  26420. var utils = baidu.editor.utils,
  26421. uiUtils = baidu.editor.ui.uiUtils,
  26422. UIBase = baidu.editor.ui.UIBase;
  26423. var TablePicker = baidu.editor.ui.TablePicker = function(options) {
  26424. this.initOptions(options);
  26425. this.initTablePicker();
  26426. };
  26427. TablePicker.prototype = {
  26428. defaultNumRows: 10,
  26429. defaultNumCols: 10,
  26430. maxNumRows: 20,
  26431. maxNumCols: 20,
  26432. numRows: 10,
  26433. numCols: 10,
  26434. lengthOfCellSide: 22,
  26435. initTablePicker: function() {
  26436. this.initUIBase();
  26437. },
  26438. getHtmlTpl: function() {
  26439. var me = this;
  26440. return '<div id="##" class="edui-tablepicker %%">' +
  26441. '<div class="edui-tablepicker-body">' +
  26442. '<div class="edui-infoarea">' +
  26443. '<span id="##_label" class="edui-label"></span>' +
  26444. '</div>' + '<div class="edui-pickarea"' +
  26445. ' onmousemove="$$._onMouseMove(event, this);"' +
  26446. ' onmouseover="$$._onMouseOver(event, this);"' +
  26447. ' onmouseout="$$._onMouseOut(event, this);"' +
  26448. ' onclick="$$._onClick(event, this);"' + '>' +
  26449. '<div id="##_overlay" class="edui-overlay"></div>' +
  26450. '</div>' + '</div>' + '</div>';
  26451. },
  26452. _UIBase_render: UIBase.prototype.render,
  26453. render: function(holder) {
  26454. this._UIBase_render(holder);
  26455. this.getDom('label').innerHTML = '0' +
  26456. this.editor.getLang("t_row") + ' x 0' +
  26457. this.editor.getLang("t_col");
  26458. },
  26459. _track: function(numCols, numRows) {
  26460. var style = this.getDom('overlay').style;
  26461. var sideLen = this.lengthOfCellSide;
  26462. style.width = numCols * sideLen + 'px';
  26463. style.height = numRows * sideLen + 'px';
  26464. var label = this.getDom('label');
  26465. label.innerHTML = numCols + this.editor.getLang("t_col") +
  26466. ' x ' + numRows + this.editor.getLang("t_row");
  26467. this.numCols = numCols;
  26468. this.numRows = numRows;
  26469. },
  26470. _onMouseOver: function(evt, el) {
  26471. var rel = evt.relatedTarget || evt.fromElement;
  26472. if(!uiUtils.contains(el, rel) && el !== rel) {
  26473. this.getDom('label').innerHTML = '0' +
  26474. this.editor.getLang("t_col") + ' x 0' +
  26475. this.editor.getLang("t_row");
  26476. this.getDom('overlay').style.visibility = '';
  26477. }
  26478. },
  26479. _onMouseOut: function(evt, el) {
  26480. var rel = evt.relatedTarget || evt.toElement;
  26481. if(!uiUtils.contains(el, rel) && el !== rel) {
  26482. this.getDom('label').innerHTML = '0' +
  26483. this.editor.getLang("t_col") + ' x 0' +
  26484. this.editor.getLang("t_row");
  26485. this.getDom('overlay').style.visibility = 'hidden';
  26486. }
  26487. },
  26488. _onMouseMove: function(evt, el) {
  26489. var style = this.getDom('overlay').style;
  26490. var offset = uiUtils.getEventOffset(evt);
  26491. var sideLen = this.lengthOfCellSide;
  26492. var numCols = Math.ceil(offset.left / sideLen);
  26493. var numRows = Math.ceil(offset.top / sideLen);
  26494. this._track(numCols, numRows);
  26495. },
  26496. _onClick: function() {
  26497. this.fireEvent('picktable', this.numCols, this.numRows);
  26498. }
  26499. };
  26500. utils.inherits(TablePicker, UIBase);
  26501. })();
  26502. // ui/stateful.js
  26503. (function() {
  26504. var browser = baidu.editor.browser,
  26505. domUtils = baidu.editor.dom.domUtils,
  26506. uiUtils = baidu.editor.ui.uiUtils;
  26507. var TPL_STATEFUL = 'onmousedown="$$.Stateful_onMouseDown(event, this);"' +
  26508. ' onmouseup="$$.Stateful_onMouseUp(event, this);"' +
  26509. (browser.ie ?
  26510. (' onmouseenter="$$.Stateful_onMouseEnter(event, this);"' + ' onmouseleave="$$.Stateful_onMouseLeave(event, this);"') :
  26511. (' onmouseover="$$.Stateful_onMouseOver(event, this);"' + ' onmouseout="$$.Stateful_onMouseOut(event, this);"'));
  26512. baidu.editor.ui.Stateful = {
  26513. alwalysHoverable: false,
  26514. target: null, // 目标元素和this指向dom不一样
  26515. Stateful_init: function() {
  26516. this._Stateful_dGetHtmlTpl = this.getHtmlTpl;
  26517. this.getHtmlTpl = this.Stateful_getHtmlTpl;
  26518. },
  26519. Stateful_getHtmlTpl: function() {
  26520. var tpl = this._Stateful_dGetHtmlTpl();
  26521. // 使用function避免$转义
  26522. return tpl.replace(/stateful/g, function() {
  26523. return TPL_STATEFUL;
  26524. });
  26525. },
  26526. Stateful_onMouseEnter: function(evt, el) {
  26527. this.target = el;
  26528. if(!this.isDisabled() || this.alwalysHoverable) {
  26529. this.addState('hover');
  26530. this.fireEvent('over');
  26531. }
  26532. },
  26533. Stateful_onMouseLeave: function(evt, el) {
  26534. if(!this.isDisabled() || this.alwalysHoverable) {
  26535. this.removeState('hover');
  26536. this.removeState('active');
  26537. this.fireEvent('out');
  26538. }
  26539. },
  26540. Stateful_onMouseOver: function(evt, el) {
  26541. var rel = evt.relatedTarget;
  26542. if(!uiUtils.contains(el, rel) && el !== rel) {
  26543. this.Stateful_onMouseEnter(evt, el);
  26544. }
  26545. },
  26546. Stateful_onMouseOut: function(evt, el) {
  26547. var rel = evt.relatedTarget;
  26548. if(!uiUtils.contains(el, rel) && el !== rel) {
  26549. this.Stateful_onMouseLeave(evt, el);
  26550. }
  26551. },
  26552. Stateful_onMouseDown: function(evt, el) {
  26553. if(!this.isDisabled()) {
  26554. this.addState('active');
  26555. }
  26556. },
  26557. Stateful_onMouseUp: function(evt, el) {
  26558. if(!this.isDisabled()) {
  26559. this.removeState('active');
  26560. }
  26561. },
  26562. Stateful_postRender: function() {
  26563. if(this.disabled && !this.hasState('disabled')) {
  26564. this.addState('disabled');
  26565. }
  26566. },
  26567. hasState: function(state) {
  26568. return domUtils.hasClass(this.getStateDom(), 'edui-state-' +
  26569. state);
  26570. },
  26571. addState: function(state) {
  26572. if(!this.hasState(state)) {
  26573. this.getStateDom().className += ' edui-state-' + state;
  26574. }
  26575. },
  26576. removeState: function(state) {
  26577. if(this.hasState(state)) {
  26578. domUtils.removeClasses(this.getStateDom(), ['edui-state-' +
  26579. state
  26580. ]);
  26581. }
  26582. },
  26583. getStateDom: function() {
  26584. return this.getDom('state');
  26585. },
  26586. isChecked: function() {
  26587. return this.hasState('checked');
  26588. },
  26589. setChecked: function(checked) {
  26590. if(!this.isDisabled() && checked) {
  26591. this.addState('checked');
  26592. } else {
  26593. this.removeState('checked');
  26594. }
  26595. },
  26596. isDisabled: function() {
  26597. return this.hasState('disabled');
  26598. },
  26599. setDisabled: function(disabled) {
  26600. if(disabled) {
  26601. this.removeState('hover');
  26602. this.removeState('checked');
  26603. this.removeState('active');
  26604. this.addState('disabled');
  26605. } else {
  26606. this.removeState('disabled');
  26607. }
  26608. }
  26609. };
  26610. })();
  26611. // ui/button.js
  26612. // /import core
  26613. // /import uicore
  26614. // /import ui/stateful.js
  26615. (function() {
  26616. var utils = baidu.editor.utils,
  26617. UIBase = baidu.editor.ui.UIBase,
  26618. Stateful = baidu.editor.ui.Stateful,
  26619. Button = baidu.editor.ui.Button = function(
  26620. options) {
  26621. if(options.name) {
  26622. var btnName = options.name;
  26623. var cssRules = options.cssRules;
  26624. if(!options.className) {
  26625. options.className = 'edui-for-' + btnName;
  26626. }
  26627. options.cssRules = '.edui-default .edui-for-' + btnName +
  26628. ' .edui-icon {' + cssRules + '}'
  26629. }
  26630. this.initOptions(options);
  26631. this.initButton();
  26632. };
  26633. Button.prototype = {
  26634. uiName: 'button',
  26635. label: '',
  26636. title: '',
  26637. showIcon: true,
  26638. showText: true,
  26639. cssRules: '',
  26640. initButton: function() {
  26641. this.initUIBase();
  26642. this.Stateful_init();
  26643. if(this.cssRules) {
  26644. utils.cssRule('edui-customize-' + this.name + '-style',
  26645. this.cssRules);
  26646. }
  26647. },
  26648. getHtmlTpl: function() {
  26649. return '<div id="##" class="edui-box %%">' +
  26650. '<div id="##_state" stateful>' +
  26651. '<div class="%%-wrap"><div id="##_body" unselectable="on" ' +
  26652. (this.title ? 'title="' + this.title + '"' : '') +
  26653. ' class="%%-body" onmousedown="return $$._onMouseDown(event, this);" onclick="return $$._onClick(event, this);">' +
  26654. (this.showIcon ?
  26655. '<div class="edui-box edui-icon"></div>' :
  26656. '') +
  26657. (this.showText ? '<div class="edui-box edui-label">' +
  26658. this.label + '</div>' : '') + '</div>' +
  26659. '</div>' + '</div></div>';
  26660. },
  26661. postRender: function() {
  26662. this.Stateful_postRender();
  26663. this.setDisabled(this.disabled)
  26664. },
  26665. _onMouseDown: function(e) {
  26666. var target = e.target || e.srcElement,
  26667. tagName = target &&
  26668. target.tagName && target.tagName.toLowerCase();
  26669. if(tagName == 'input' || tagName == 'object' ||
  26670. tagName == 'object') {
  26671. return false;
  26672. }
  26673. },
  26674. _onClick: function() {
  26675. if(!this.isDisabled()) {
  26676. this.fireEvent('click');
  26677. }
  26678. },
  26679. setTitle: function(text) {
  26680. var label = this.getDom('label');
  26681. label.innerHTML = text;
  26682. }
  26683. };
  26684. utils.inherits(Button, UIBase);
  26685. utils.extend(Button.prototype, Stateful);
  26686. })();
  26687. // ui/splitbutton.js
  26688. // /import core
  26689. // /import uicore
  26690. // /import ui/stateful.js
  26691. (function() {
  26692. var utils = baidu.editor.utils,
  26693. uiUtils = baidu.editor.ui.uiUtils,
  26694. domUtils = baidu.editor.dom.domUtils,
  26695. UIBase = baidu.editor.ui.UIBase,
  26696. Stateful = baidu.editor.ui.Stateful,
  26697. SplitButton = baidu.editor.ui.SplitButton = function(
  26698. options) {
  26699. this.initOptions(options);
  26700. this.initSplitButton();
  26701. };
  26702. SplitButton.prototype = {
  26703. popup: null,
  26704. uiName: 'splitbutton',
  26705. title: '',
  26706. initSplitButton: function() {
  26707. this.initUIBase();
  26708. this.Stateful_init();
  26709. var me = this;
  26710. if(this.popup != null) {
  26711. var popup = this.popup;
  26712. this.popup = null;
  26713. this.setPopup(popup);
  26714. }
  26715. },
  26716. _UIBase_postRender: UIBase.prototype.postRender,
  26717. postRender: function() {
  26718. this.Stateful_postRender();
  26719. this._UIBase_postRender();
  26720. },
  26721. setPopup: function(popup) {
  26722. if(this.popup === popup)
  26723. return;
  26724. if(this.popup != null) {
  26725. this.popup.dispose();
  26726. }
  26727. popup.addListener('show', utils.bind(this._onPopupShow, this));
  26728. popup.addListener('hide', utils.bind(this._onPopupHide, this));
  26729. popup.addListener('postrender', utils.bind(function() {
  26730. popup
  26731. .getDom('body')
  26732. .appendChild(uiUtils
  26733. .createElementByHtml('<div id="' +
  26734. this.popup.id +
  26735. '_bordereraser" class="edui-bordereraser edui-background" style="width:' +
  26736. (uiUtils.getClientRect(this
  26737. .getDom()).width + 20) +
  26738. 'px"></div>'));
  26739. popup.getDom().className += ' ' + this.className;
  26740. }, this));
  26741. this.popup = popup;
  26742. },
  26743. _onPopupShow: function() {
  26744. this.addState('opened');
  26745. },
  26746. _onPopupHide: function() {
  26747. this.removeState('opened');
  26748. },
  26749. getHtmlTpl: function() {
  26750. return '<div id="##" class="edui-box %%">' +
  26751. '<div ' +
  26752. (this.title ? 'title="' + this.title + '"' : '') +
  26753. ' id="##_state" stateful><div class="%%-body">' +
  26754. '<div id="##_button_body" class="edui-box edui-button-body" onclick="$$._onButtonClick(event, this);">' +
  26755. '<div class="edui-box edui-icon"></div>' +
  26756. '</div>' +
  26757. '<div class="edui-box edui-splitborder"></div>' +
  26758. '<div class="edui-box edui-arrow" onclick="$$._onArrowClick();"></div>' +
  26759. '</div></div></div>';
  26760. },
  26761. showPopup: function() {
  26762. // 当popup往上弹出的时候,做特殊处理
  26763. var rect = uiUtils.getClientRect(this.getDom());
  26764. rect.top -= this.popup.SHADOW_RADIUS;
  26765. rect.height += this.popup.SHADOW_RADIUS;
  26766. this.popup.showAnchorRect(rect);
  26767. },
  26768. _onArrowClick: function(event, el) {
  26769. if(!this.isDisabled()) {
  26770. this.showPopup();
  26771. }
  26772. },
  26773. _onButtonClick: function() {
  26774. if(!this.isDisabled()) {
  26775. this.fireEvent('buttonclick');
  26776. }
  26777. }
  26778. };
  26779. utils.inherits(SplitButton, UIBase);
  26780. utils.extend(SplitButton.prototype, Stateful, true);
  26781. })();
  26782. // ui/colorbutton.js
  26783. // /import core
  26784. // /import uicore
  26785. // /import ui/colorpicker.js
  26786. // /import ui/popup.js
  26787. // /import ui/splitbutton.js
  26788. (function() {
  26789. var utils = baidu.editor.utils,
  26790. uiUtils = baidu.editor.ui.uiUtils,
  26791. ColorPicker = baidu.editor.ui.ColorPicker,
  26792. Popup = baidu.editor.ui.Popup,
  26793. SplitButton = baidu.editor.ui.SplitButton,
  26794. ColorButton = baidu.editor.ui.ColorButton = function(
  26795. options) {
  26796. this.initOptions(options);
  26797. this.initColorButton();
  26798. };
  26799. ColorButton.prototype = {
  26800. initColorButton: function() {
  26801. var me = this;
  26802. this.popup = new Popup({
  26803. content: new ColorPicker({
  26804. noColorText: me.editor.getLang("clearColor"),
  26805. editor: me.editor,
  26806. onpickcolor: function(t, color) {
  26807. me._onPickColor(color);
  26808. },
  26809. onpicknocolor: function(t, color) {
  26810. me._onPickNoColor(color);
  26811. }
  26812. }),
  26813. editor: me.editor
  26814. });
  26815. this.initSplitButton();
  26816. },
  26817. _SplitButton_postRender: SplitButton.prototype.postRender,
  26818. postRender: function() {
  26819. this._SplitButton_postRender();
  26820. this.getDom('button_body').appendChild(uiUtils
  26821. .createElementByHtml('<div id="' + this.id +
  26822. '_colorlump" class="edui-colorlump"></div>'));
  26823. this.getDom().className += ' edui-colorbutton';
  26824. },
  26825. setColor: function(color) {
  26826. this.getDom('colorlump').style.backgroundColor = color;
  26827. this.color = color;
  26828. },
  26829. _onPickColor: function(color) {
  26830. if(this.fireEvent('pickcolor', color) !== false) {
  26831. this.setColor(color);
  26832. this.popup.hide();
  26833. }
  26834. },
  26835. _onPickNoColor: function(color) {
  26836. if(this.fireEvent('picknocolor') !== false) {
  26837. this.popup.hide();
  26838. }
  26839. }
  26840. };
  26841. utils.inherits(ColorButton, SplitButton);
  26842. })();
  26843. // ui/tablebutton.js
  26844. // /import core
  26845. // /import uicore
  26846. // /import ui/popup.js
  26847. // /import ui/tablepicker.js
  26848. // /import ui/splitbutton.js
  26849. (function() {
  26850. var utils = baidu.editor.utils,
  26851. Popup = baidu.editor.ui.Popup,
  26852. TablePicker = baidu.editor.ui.TablePicker,
  26853. SplitButton = baidu.editor.ui.SplitButton,
  26854. TableButton = baidu.editor.ui.TableButton = function(
  26855. options) {
  26856. this.initOptions(options);
  26857. this.initTableButton();
  26858. };
  26859. TableButton.prototype = {
  26860. initTableButton: function() {
  26861. var me = this;
  26862. this.popup = new Popup({
  26863. content: new TablePicker({
  26864. editor: me.editor,
  26865. onpicktable: function(t, numCols, numRows) {
  26866. me._onPickTable(numCols, numRows);
  26867. }
  26868. }),
  26869. 'editor': me.editor
  26870. });
  26871. this.initSplitButton();
  26872. },
  26873. _onPickTable: function(numCols, numRows) {
  26874. if(this.fireEvent('picktable', numCols, numRows) !== false) {
  26875. this.popup.hide();
  26876. }
  26877. }
  26878. };
  26879. utils.inherits(TableButton, SplitButton);
  26880. })();
  26881. // ui/autotypesetpicker.js
  26882. // /import core
  26883. // /import uicore
  26884. (function() {
  26885. var utils = baidu.editor.utils,
  26886. UIBase = baidu.editor.ui.UIBase;
  26887. var AutoTypeSetPicker = baidu.editor.ui.AutoTypeSetPicker = function(
  26888. options) {
  26889. this.initOptions(options);
  26890. this.initAutoTypeSetPicker();
  26891. };
  26892. AutoTypeSetPicker.prototype = {
  26893. initAutoTypeSetPicker: function() {
  26894. this.initUIBase();
  26895. },
  26896. getHtmlTpl: function() {
  26897. var me = this.editor,
  26898. opt = me.options.autotypeset,
  26899. lang = me
  26900. .getLang("autoTypeSet");
  26901. var textAlignInputName = 'textAlignValue' + me.uid,
  26902. imageBlockInputName = 'imageBlockLineValue' +
  26903. me.uid,
  26904. symbolConverInputName = 'symbolConverValue' +
  26905. me.uid;
  26906. return '<div id="##" class="edui-autotypesetpicker %%">' +
  26907. '<div class="edui-autotypesetpicker-body">' +
  26908. '<table >' +
  26909. '<tr><td nowrap><input type="checkbox" name="mergeEmptyline" ' +
  26910. (opt["mergeEmptyline"] ? "checked" : "") +
  26911. '>' +
  26912. lang.mergeLine +
  26913. '</td><td colspan="2"><input type="checkbox" name="removeEmptyline" ' +
  26914. (opt["removeEmptyline"] ? "checked" : "") +
  26915. '>' +
  26916. lang.delLine +
  26917. '</td></tr>' +
  26918. '<tr><td nowrap><input type="checkbox" name="removeClass" ' +
  26919. (opt["removeClass"] ? "checked" : "") +
  26920. '>' +
  26921. lang.removeFormat +
  26922. '</td><td colspan="2"><input type="checkbox" name="indent" ' +
  26923. (opt["indent"] ? "checked" : "") +
  26924. '>' +
  26925. lang.indent +
  26926. '</td></tr>' +
  26927. '<tr>' +
  26928. '<td nowrap><input type="checkbox" name="textAlign" ' +
  26929. (opt["textAlign"] ? "checked" : "") +
  26930. '>' +
  26931. lang.alignment +
  26932. '</td>' +
  26933. '<td colspan="2" id="' +
  26934. textAlignInputName +
  26935. '">' +
  26936. '<input type="radio" name="' +
  26937. textAlignInputName +
  26938. '" value="left" ' +
  26939. ((opt["textAlign"] && opt["textAlign"] == "left") ?
  26940. "checked" :
  26941. "") +
  26942. '>' +
  26943. me.getLang("justifyleft") +
  26944. '<input type="radio" name="' +
  26945. textAlignInputName +
  26946. '" value="center" ' +
  26947. ((opt["textAlign"] && opt["textAlign"] == "center") ?
  26948. "checked" :
  26949. "") +
  26950. '>' +
  26951. me.getLang("justifycenter") +
  26952. '<input type="radio" name="' +
  26953. textAlignInputName +
  26954. '" value="right" ' +
  26955. ((opt["textAlign"] && opt["textAlign"] == "right") ?
  26956. "checked" :
  26957. "") +
  26958. '>' +
  26959. me.getLang("justifyright") +
  26960. '</td>' +
  26961. '</tr>' +
  26962. '<tr>' +
  26963. '<td nowrap><input type="checkbox" name="imageBlockLine" ' +
  26964. (opt["imageBlockLine"] ? "checked" : "") +
  26965. '>' +
  26966. lang.imageFloat +
  26967. '</td>' +
  26968. '<td nowrap id="' +
  26969. imageBlockInputName +
  26970. '">' +
  26971. '<input type="radio" name="' +
  26972. imageBlockInputName +
  26973. '" value="none" ' +
  26974. ((opt["imageBlockLine"] && opt["imageBlockLine"] == "none") ?
  26975. "checked" :
  26976. "") +
  26977. '>' +
  26978. me.getLang("default") +
  26979. '<input type="radio" name="' +
  26980. imageBlockInputName +
  26981. '" value="left" ' +
  26982. ((opt["imageBlockLine"] && opt["imageBlockLine"] == "left") ?
  26983. "checked" :
  26984. "") +
  26985. '>' +
  26986. me.getLang("justifyleft") +
  26987. '<input type="radio" name="' +
  26988. imageBlockInputName +
  26989. '" value="center" ' +
  26990. ((opt["imageBlockLine"] && opt["imageBlockLine"] == "center") ?
  26991. "checked" :
  26992. "") +
  26993. '>' +
  26994. me.getLang("justifycenter") +
  26995. '<input type="radio" name="' +
  26996. imageBlockInputName +
  26997. '" value="right" ' +
  26998. ((opt["imageBlockLine"] && opt["imageBlockLine"] == "right") ?
  26999. "checked" :
  27000. "") +
  27001. '>' +
  27002. me.getLang("justifyright") +
  27003. '</td>' +
  27004. '</tr>' +
  27005. '<tr><td nowrap><input type="checkbox" name="clearFontSize" ' +
  27006. (opt["clearFontSize"] ? "checked" : "") +
  27007. '>' +
  27008. lang.removeFontsize +
  27009. '</td><td colspan="2"><input type="checkbox" name="clearFontFamily" ' +
  27010. (opt["clearFontFamily"] ? "checked" : "") +
  27011. '>' +
  27012. lang.removeFontFamily +
  27013. '</td></tr>' +
  27014. '<tr><td nowrap colspan="3"><input type="checkbox" name="removeEmptyNode" ' +
  27015. (opt["removeEmptyNode"] ? "checked" : "") +
  27016. '>' +
  27017. lang.removeHtml +
  27018. '</td></tr>' +
  27019. '<tr><td nowrap colspan="3"><input type="checkbox" name="pasteFilter" ' +
  27020. (opt["pasteFilter"] ? "checked" : "") +
  27021. '>' +
  27022. lang.pasteFilter +
  27023. '</td></tr>' +
  27024. '<tr>' +
  27025. '<td nowrap><input type="checkbox" name="symbolConver" ' +
  27026. (opt["bdc2sb"] || opt["tobdc"] ? "checked" : "") +
  27027. '>' + lang.symbol + '</td>' + '<td id="' +
  27028. symbolConverInputName + '">' +
  27029. '<input type="radio" name="bdc" value="bdc2sb" ' +
  27030. (opt["bdc2sb"] ? "checked" : "") + '>' + lang.bdc2sb +
  27031. '<input type="radio" name="bdc" value="tobdc" ' +
  27032. (opt["tobdc"] ? "checked" : "") + '>' + lang.tobdc +
  27033. '' + '</td>' + '<td nowrap align="right"><button >' +
  27034. lang.run + '</button></td>' + '</tr>' + '</table>' +
  27035. '</div>' + '</div>';
  27036. },
  27037. _UIBase_render: UIBase.prototype.render
  27038. };
  27039. utils.inherits(AutoTypeSetPicker, UIBase);
  27040. })();
  27041. // ui/autotypesetbutton.js
  27042. // /import core
  27043. // /import uicore
  27044. // /import ui/popup.js
  27045. // /import ui/autotypesetpicker.js
  27046. // /import ui/splitbutton.js
  27047. (function() {
  27048. var utils = baidu.editor.utils,
  27049. Popup = baidu.editor.ui.Popup,
  27050. AutoTypeSetPicker = baidu.editor.ui.AutoTypeSetPicker,
  27051. SplitButton = baidu.editor.ui.SplitButton,
  27052. AutoTypeSetButton = baidu.editor.ui.AutoTypeSetButton = function(
  27053. options) {
  27054. this.initOptions(options);
  27055. this.initAutoTypeSetButton();
  27056. };
  27057. function getPara(me) {
  27058. var opt = {},
  27059. cont = me.getDom(),
  27060. editorId = me.editor.uid,
  27061. inputType = null,
  27062. attrName = null,
  27063. ipts = domUtils
  27064. .getElementsByTagName(cont, "input");
  27065. for(var i = ipts.length - 1, ipt; ipt = ipts[i--];) {
  27066. inputType = ipt.getAttribute("type");
  27067. if(inputType == "checkbox") {
  27068. attrName = ipt.getAttribute("name");
  27069. opt[attrName] && delete opt[attrName];
  27070. if(ipt.checked) {
  27071. var attrValue = document.getElementById(attrName +
  27072. "Value" + editorId);
  27073. if(attrValue) {
  27074. if(/input/ig.test(attrValue.tagName)) {
  27075. opt[attrName] = attrValue.value;
  27076. } else {
  27077. var iptChilds = attrValue
  27078. .getElementsByTagName("input");
  27079. for(var j = iptChilds.length - 1, iptchild; iptchild = iptChilds[j--];) {
  27080. if(iptchild.checked) {
  27081. opt[attrName] = iptchild.value;
  27082. break;
  27083. }
  27084. }
  27085. }
  27086. } else {
  27087. opt[attrName] = true;
  27088. }
  27089. } else {
  27090. opt[attrName] = false;
  27091. }
  27092. } else {
  27093. opt[ipt.getAttribute("value")] = ipt.checked;
  27094. }
  27095. }
  27096. var selects = domUtils.getElementsByTagName(cont, "select");
  27097. for(var i = 0, si; si = selects[i++];) {
  27098. var attr = si.getAttribute('name');
  27099. opt[attr] = opt[attr] ? si.value : '';
  27100. }
  27101. utils.extend(me.editor.options.autotypeset, opt);
  27102. me.editor.setPreferences('autotypeset', opt);
  27103. }
  27104. AutoTypeSetButton.prototype = {
  27105. initAutoTypeSetButton: function() {
  27106. var me = this;
  27107. this.popup = new Popup({
  27108. // 传入配置参数
  27109. content: new AutoTypeSetPicker({
  27110. editor: me.editor
  27111. }),
  27112. 'editor': me.editor,
  27113. hide: function() {
  27114. if(!this._hidden && this.getDom()) {
  27115. getPara(this);
  27116. this.getDom().style.display = 'none';
  27117. this._hidden = true;
  27118. this.fireEvent('hide');
  27119. }
  27120. }
  27121. });
  27122. var flag = 0;
  27123. this.popup.addListener('postRenderAfter', function() {
  27124. var popupUI = this;
  27125. if(flag)
  27126. return;
  27127. var cont = this.getDom(),
  27128. btn = cont
  27129. .getElementsByTagName('button')[0];
  27130. btn.onclick = function() {
  27131. getPara(popupUI);
  27132. me.editor.execCommand('autotypeset');
  27133. popupUI.hide()
  27134. };
  27135. domUtils.on(cont, 'click', function(e) {
  27136. var target = e.target || e.srcElement,
  27137. editorId = me.editor.uid;
  27138. if(target && target.tagName == 'INPUT') {
  27139. // 点击图片浮动的checkbox,去除对应的radio
  27140. if(target.name == 'imageBlockLine' ||
  27141. target.name == 'textAlign' ||
  27142. target.name == 'symbolConver') {
  27143. var checked = target.checked,
  27144. radioTd = document
  27145. .getElementById(target.name + 'Value' +
  27146. editorId),
  27147. radios = radioTd
  27148. .getElementsByTagName('input'),
  27149. defalutSelect = {
  27150. 'imageBlockLine': 'none',
  27151. 'textAlign': 'left',
  27152. 'symbolConver': 'tobdc'
  27153. };
  27154. for(var i = 0; i < radios.length; i++) {
  27155. if(checked) {
  27156. if(radios[i].value == defalutSelect[target.name]) {
  27157. radios[i].checked = 'checked';
  27158. }
  27159. } else {
  27160. radios[i].checked = false;
  27161. }
  27162. }
  27163. }
  27164. // 点击radio,选中对应的checkbox
  27165. if(target.name == ('imageBlockLineValue' + editorId) ||
  27166. target.name == ('textAlignValue' + editorId) ||
  27167. target.name == 'bdc') {
  27168. var checkboxs = target.parentNode.previousSibling
  27169. .getElementsByTagName('input');
  27170. checkboxs && (checkboxs[0].checked = true);
  27171. }
  27172. getPara(popupUI);
  27173. }
  27174. });
  27175. flag = 1;
  27176. });
  27177. this.initSplitButton();
  27178. }
  27179. };
  27180. utils.inherits(AutoTypeSetButton, SplitButton);
  27181. })();
  27182. // ui/cellalignpicker.js
  27183. // /import core
  27184. // /import uicore
  27185. (function() {
  27186. var utils = baidu.editor.utils,
  27187. Popup = baidu.editor.ui.Popup,
  27188. Stateful = baidu.editor.ui.Stateful,
  27189. UIBase = baidu.editor.ui.UIBase;
  27190. /**
  27191. * 该参数将新增一个参数: selected, 参数类型为一个Object, 形如{ 'align': 'center', 'valign':
  27192. * 'top' }, 表示单元格的初始 对齐状态为: 竖直居上,水平居中; 其中 align的取值为:'center', 'left',
  27193. * 'right'; valign的取值为: 'top', 'middle', 'bottom'
  27194. *
  27195. * @update 2013/4/2 hancong03@baidu.com
  27196. */
  27197. var CellAlignPicker = baidu.editor.ui.CellAlignPicker = function(
  27198. options) {
  27199. this.initOptions(options);
  27200. this.initSelected();
  27201. this.initCellAlignPicker();
  27202. };
  27203. CellAlignPicker.prototype = {
  27204. // 初始化选中状态, 该方法将根据传递进来的参数获取到应该选中的对齐方式图标的索引
  27205. initSelected: function() {
  27206. var status = {
  27207. valign: {
  27208. top: 0,
  27209. middle: 1,
  27210. bottom: 2
  27211. },
  27212. align: {
  27213. left: 0,
  27214. center: 1,
  27215. right: 2
  27216. },
  27217. count: 3
  27218. },
  27219. result = -1;
  27220. if(this.selected) {
  27221. this.selectedIndex = status.valign[this.selected.valign] *
  27222. status.count + status.align[this.selected.align];
  27223. }
  27224. },
  27225. initCellAlignPicker: function() {
  27226. this.initUIBase();
  27227. this.Stateful_init();
  27228. },
  27229. getHtmlTpl: function() {
  27230. var alignType = ['left', 'center', 'right'],
  27231. COUNT = 9,
  27232. tempClassName = null,
  27233. tempIndex = -1,
  27234. tmpl = [];
  27235. for(var i = 0; i < COUNT; i++) {
  27236. tempClassName = this.selectedIndex === i ?
  27237. ' class="edui-cellalign-selected" ' :
  27238. '';
  27239. tempIndex = i % 3;
  27240. tempIndex === 0 && tmpl.push('<tr>');
  27241. tmpl.push('<td index="' + i + '" ' + tempClassName +
  27242. ' stateful><div class="edui-icon edui-' +
  27243. alignType[tempIndex] + '"></div></td>');
  27244. tempIndex === 2 && tmpl.push('</tr>');
  27245. }
  27246. return '<div id="##" class="edui-cellalignpicker %%">' +
  27247. '<div class="edui-cellalignpicker-body">' +
  27248. '<table onclick="$$._onClick(event);">' +
  27249. tmpl.join('') + '</table>' + '</div>' + '</div>';
  27250. },
  27251. getStateDom: function() {
  27252. return this.target;
  27253. },
  27254. _onClick: function(evt) {
  27255. var target = evt.target || evt.srcElement;
  27256. if(/icon/.test(target.className)) {
  27257. this.items[target.parentNode.getAttribute("index")]
  27258. .onclick();
  27259. Popup.postHide(evt);
  27260. }
  27261. },
  27262. _UIBase_render: UIBase.prototype.render
  27263. };
  27264. utils.inherits(CellAlignPicker, UIBase);
  27265. utils.extend(CellAlignPicker.prototype, Stateful, true);
  27266. })();
  27267. // ui/pastepicker.js
  27268. // /import core
  27269. // /import uicore
  27270. (function() {
  27271. var utils = baidu.editor.utils,
  27272. Stateful = baidu.editor.ui.Stateful,
  27273. uiUtils = baidu.editor.ui.uiUtils,
  27274. UIBase = baidu.editor.ui.UIBase;
  27275. var PastePicker = baidu.editor.ui.PastePicker = function(options) {
  27276. this.initOptions(options);
  27277. this.initPastePicker();
  27278. };
  27279. PastePicker.prototype = {
  27280. initPastePicker: function() {
  27281. this.initUIBase();
  27282. this.Stateful_init();
  27283. },
  27284. getHtmlTpl: function() {
  27285. return '<div class="edui-pasteicon" onclick="$$._onClick(this)"></div>' +
  27286. '<div class="edui-pastecontainer">' +
  27287. '<div class="edui-title">' +
  27288. this.editor.getLang("pasteOpt") +
  27289. '</div>' +
  27290. '<div class="edui-button">' +
  27291. '<div title="' +
  27292. this.editor.getLang("pasteSourceFormat") +
  27293. '" onclick="$$.format(false)" stateful>' +
  27294. '<div class="edui-richtxticon"></div></div>' +
  27295. '<div title="' +
  27296. this.editor.getLang("tagFormat") +
  27297. '" onclick="$$.format(2)" stateful>' +
  27298. '<div class="edui-tagicon"></div></div>' +
  27299. '<div title="' +
  27300. this.editor.getLang("pasteTextFormat") +
  27301. '" onclick="$$.format(true)" stateful>' +
  27302. '<div class="edui-plaintxticon"></div></div>' +
  27303. '</div>' + '</div>' + '</div>'
  27304. },
  27305. getStateDom: function() {
  27306. return this.target;
  27307. },
  27308. format: function(param) {
  27309. this.editor.ui._isTransfer = true;
  27310. this.editor.fireEvent('pasteTransfer', param);
  27311. },
  27312. _onClick: function(cur) {
  27313. var node = domUtils.getNextDomNode(cur),
  27314. screenHt = uiUtils
  27315. .getViewportRect().height,
  27316. subPop = uiUtils
  27317. .getClientRect(node);
  27318. if((subPop.top + subPop.height) > screenHt)
  27319. node.style.top = (-subPop.height - cur.offsetHeight) + "px";
  27320. else
  27321. node.style.top = "";
  27322. if(/hidden/ig.test(domUtils.getComputedStyle(node,
  27323. "visibility"))) {
  27324. node.style.visibility = "visible";
  27325. domUtils.addClass(cur, "edui-state-opened");
  27326. } else {
  27327. node.style.visibility = "hidden";
  27328. domUtils.removeClasses(cur, "edui-state-opened")
  27329. }
  27330. },
  27331. _UIBase_render: UIBase.prototype.render
  27332. };
  27333. utils.inherits(PastePicker, UIBase);
  27334. utils.extend(PastePicker.prototype, Stateful, true);
  27335. })();
  27336. // ui/toolbar.js
  27337. (function() {
  27338. var utils = baidu.editor.utils,
  27339. uiUtils = baidu.editor.ui.uiUtils,
  27340. UIBase = baidu.editor.ui.UIBase,
  27341. Toolbar = baidu.editor.ui.Toolbar = function(
  27342. options) {
  27343. this.initOptions(options);
  27344. this.initToolbar();
  27345. };
  27346. Toolbar.prototype = {
  27347. items: null,
  27348. initToolbar: function() {
  27349. this.items = this.items || [];
  27350. this.initUIBase();
  27351. },
  27352. add: function(item, index) {
  27353. if(index === undefined) {
  27354. this.items.push(item);
  27355. } else {
  27356. this.items.splice(index, 0, item)
  27357. }
  27358. },
  27359. getHtmlTpl: function() {
  27360. var buff = [];
  27361. var hl = [];
  27362. var isHide = false;
  27363. for(var i = 0; i < this.items.length; i++) {
  27364. if(!isHide) {
  27365. isHide = (this.items[i].className == "edui-for-showall");
  27366. buff[i] = this.items[i].renderHtml();
  27367. } else {
  27368. hl[i - buff.length] = this.items[i].renderHtml();
  27369. }
  27370. }
  27371. return '<div id="##" class="edui-toolbar %%" onselectstart="return false;" onmousedown="return $$._onMouseDown(event, this);">' +
  27372. buff.join('') +
  27373. '<div id="hideTools" style="display:none;" class="hideTools edui-toolbar %%" onselectstart="return false;" onmousedown="return $$._onMouseDown(event, this);">' +
  27374. hl.join('') + '</div>' + '</div>'
  27375. },
  27376. postRender: function() {
  27377. var box = this.getDom();
  27378. for(var i = 0; i < this.items.length; i++) {
  27379. this.items[i].postRender();
  27380. }
  27381. uiUtils.makeUnselectable(box);
  27382. },
  27383. _onMouseDown: function(e) {
  27384. var target = e.target || e.srcElement,
  27385. tagName = target &&
  27386. target.tagName && target.tagName.toLowerCase();
  27387. if(tagName == 'input' || tagName == 'object' ||
  27388. tagName == 'object') {
  27389. return false;
  27390. }
  27391. }
  27392. };
  27393. utils.inherits(Toolbar, UIBase);
  27394. })();
  27395. // ui/menu.js
  27396. // /import core
  27397. // /import uicore
  27398. // /import ui\popup.js
  27399. // /import ui\stateful.js
  27400. (function() {
  27401. var utils = baidu.editor.utils,
  27402. domUtils = baidu.editor.dom.domUtils,
  27403. uiUtils = baidu.editor.ui.uiUtils,
  27404. UIBase = baidu.editor.ui.UIBase,
  27405. Popup = baidu.editor.ui.Popup,
  27406. Stateful = baidu.editor.ui.Stateful,
  27407. CellAlignPicker = baidu.editor.ui.CellAlignPicker,
  27408. Menu = baidu.editor.ui.Menu = function(options) {
  27409. this.initOptions(options);
  27410. this.initMenu();
  27411. };
  27412. var menuSeparator = {
  27413. renderHtml: function() {
  27414. return '<div class="edui-menuitem edui-menuseparator"><div class="edui-menuseparator-inner"></div></div>';
  27415. },
  27416. postRender: function() {},
  27417. queryAutoHide: function() {
  27418. return true;
  27419. }
  27420. };
  27421. Menu.prototype = {
  27422. items: null,
  27423. uiName: 'menu',
  27424. initMenu: function() {
  27425. this.items = this.items || [];
  27426. this.initPopup();
  27427. this.initItems();
  27428. },
  27429. initItems: function() {
  27430. for(var i = 0; i < this.items.length; i++) {
  27431. var item = this.items[i];
  27432. if(item == '-') {
  27433. this.items[i] = this.getSeparator();
  27434. } else if(!(item instanceof MenuItem)) {
  27435. item.editor = this.editor;
  27436. item.theme = this.editor.options.theme;
  27437. this.items[i] = this.createItem(item);
  27438. }
  27439. }
  27440. },
  27441. getSeparator: function() {
  27442. return menuSeparator;
  27443. },
  27444. createItem: function(item) {
  27445. // 新增一个参数menu, 该参数存储了menuItem所对应的menu引用
  27446. item.menu = this;
  27447. return new MenuItem(item);
  27448. },
  27449. _Popup_getContentHtmlTpl: Popup.prototype.getContentHtmlTpl,
  27450. getContentHtmlTpl: function() {
  27451. if(this.items.length == 0) {
  27452. return this._Popup_getContentHtmlTpl();
  27453. }
  27454. var buff = [];
  27455. for(var i = 0; i < this.items.length; i++) {
  27456. var item = this.items[i];
  27457. buff[i] = item.renderHtml();
  27458. }
  27459. return('<div class="%%-body">' + buff.join('') + '</div>');
  27460. },
  27461. _Popup_postRender: Popup.prototype.postRender,
  27462. postRender: function() {
  27463. var me = this;
  27464. for(var i = 0; i < this.items.length; i++) {
  27465. var item = this.items[i];
  27466. item.ownerMenu = this;
  27467. item.postRender();
  27468. }
  27469. domUtils.on(this.getDom(), 'mouseover', function(evt) {
  27470. evt = evt || event;
  27471. var rel = evt.relatedTarget || evt.fromElement;
  27472. var el = me.getDom();
  27473. if(!uiUtils.contains(el, rel) && el !== rel) {
  27474. me.fireEvent('over');
  27475. }
  27476. });
  27477. this._Popup_postRender();
  27478. },
  27479. queryAutoHide: function(el) {
  27480. if(el) {
  27481. if(uiUtils.contains(this.getDom(), el)) {
  27482. return false;
  27483. }
  27484. for(var i = 0; i < this.items.length; i++) {
  27485. var item = this.items[i];
  27486. if(item.queryAutoHide(el) === false) {
  27487. return false;
  27488. }
  27489. }
  27490. }
  27491. },
  27492. clearItems: function() {
  27493. for(var i = 0; i < this.items.length; i++) {
  27494. var item = this.items[i];
  27495. clearTimeout(item._showingTimer);
  27496. clearTimeout(item._closingTimer);
  27497. if(item.subMenu) {
  27498. item.subMenu.destroy();
  27499. }
  27500. }
  27501. this.items = [];
  27502. },
  27503. destroy: function() {
  27504. if(this.getDom()) {
  27505. domUtils.remove(this.getDom());
  27506. }
  27507. this.clearItems();
  27508. },
  27509. dispose: function() {
  27510. this.destroy();
  27511. }
  27512. };
  27513. utils.inherits(Menu, Popup);
  27514. /**
  27515. * @update 2013/04/03 hancong03 新增一个参数menu, 该参数存储了menuItem所对应的menu引用
  27516. * @type {Function}
  27517. */
  27518. var MenuItem = baidu.editor.ui.MenuItem = function(options) {
  27519. this.initOptions(options);
  27520. this.initUIBase();
  27521. this.Stateful_init();
  27522. if(this.subMenu && !(this.subMenu instanceof Menu)) {
  27523. if(options.className &&
  27524. options.className.indexOf("aligntd") != -1) {
  27525. var me = this;
  27526. // 获取单元格对齐初始状态
  27527. this.subMenu.selected = this.editor
  27528. .queryCommandValue('cellalignment');
  27529. this.subMenu = new Popup({
  27530. content: new CellAlignPicker(this.subMenu),
  27531. parentMenu: me,
  27532. editor: me.editor,
  27533. destroy: function() {
  27534. if(this.getDom()) {
  27535. domUtils.remove(this.getDom());
  27536. }
  27537. }
  27538. });
  27539. this.subMenu.addListener("postRenderAfter", function() {
  27540. domUtils.on(this.getDom(), "mouseover", function() {
  27541. me.addState('opened');
  27542. });
  27543. });
  27544. } else {
  27545. this.subMenu = new Menu(this.subMenu);
  27546. }
  27547. }
  27548. };
  27549. MenuItem.prototype = {
  27550. label: '',
  27551. subMenu: null,
  27552. ownerMenu: null,
  27553. uiName: 'menuitem',
  27554. alwalysHoverable: true,
  27555. getHtmlTpl: function() {
  27556. return '<div id="##" class="%%" stateful onclick="$$._onClick(event, this);">' +
  27557. '<div class="%%-body">' +
  27558. this.renderLabelHtml() +
  27559. '</div>' + '</div>';
  27560. },
  27561. postRender: function() {
  27562. var me = this;
  27563. this.addListener('over', function() {
  27564. me.ownerMenu.fireEvent('submenuover', me);
  27565. if(me.subMenu) {
  27566. me.delayShowSubMenu();
  27567. }
  27568. });
  27569. if(this.subMenu) {
  27570. this.getDom().className += ' edui-hassubmenu';
  27571. this.subMenu.render();
  27572. this.addListener('out', function() {
  27573. me.delayHideSubMenu();
  27574. });
  27575. this.subMenu.addListener('over', function() {
  27576. clearTimeout(me._closingTimer);
  27577. me._closingTimer = null;
  27578. me.addState('opened');
  27579. });
  27580. this.ownerMenu.addListener('hide', function() {
  27581. me.hideSubMenu();
  27582. });
  27583. this.ownerMenu.addListener('submenuover', function(t,
  27584. subMenu) {
  27585. if(subMenu !== me) {
  27586. me.delayHideSubMenu();
  27587. }
  27588. });
  27589. this.subMenu._bakQueryAutoHide = this.subMenu.queryAutoHide;
  27590. this.subMenu.queryAutoHide = function(el) {
  27591. if(el && uiUtils.contains(me.getDom(), el)) {
  27592. return false;
  27593. }
  27594. return this._bakQueryAutoHide(el);
  27595. };
  27596. }
  27597. this.getDom().style.tabIndex = '-1';
  27598. uiUtils.makeUnselectable(this.getDom());
  27599. this.Stateful_postRender();
  27600. },
  27601. delayShowSubMenu: function() {
  27602. var me = this;
  27603. if(!me.isDisabled()) {
  27604. me.addState('opened');
  27605. clearTimeout(me._showingTimer);
  27606. clearTimeout(me._closingTimer);
  27607. me._closingTimer = null;
  27608. me._showingTimer = setTimeout(function() {
  27609. me.showSubMenu();
  27610. }, 250);
  27611. }
  27612. },
  27613. delayHideSubMenu: function() {
  27614. var me = this;
  27615. if(!me.isDisabled()) {
  27616. me.removeState('opened');
  27617. clearTimeout(me._showingTimer);
  27618. if(!me._closingTimer) {
  27619. me._closingTimer = setTimeout(function() {
  27620. if(!me.hasState('opened')) {
  27621. me.hideSubMenu();
  27622. }
  27623. me._closingTimer = null;
  27624. }, 400);
  27625. }
  27626. }
  27627. },
  27628. renderLabelHtml: function() {
  27629. return '<div class="edui-arrow"></div>' +
  27630. '<div class="edui-box edui-icon"></div>' +
  27631. '<div class="edui-box edui-label %%-label">' +
  27632. (this.label || '') + '</div>';
  27633. },
  27634. getStateDom: function() {
  27635. return this.getDom();
  27636. },
  27637. queryAutoHide: function(el) {
  27638. if(this.subMenu && this.hasState('opened')) {
  27639. return this.subMenu.queryAutoHide(el);
  27640. }
  27641. },
  27642. _onClick: function(event, this_) {
  27643. if(this.hasState('disabled'))
  27644. return;
  27645. if(this.fireEvent('click', event, this_) !== false) {
  27646. if(this.subMenu) {
  27647. this.showSubMenu();
  27648. } else {
  27649. Popup.postHide(event);
  27650. }
  27651. }
  27652. },
  27653. showSubMenu: function() {
  27654. var rect = uiUtils.getClientRect(this.getDom());
  27655. rect.right -= 5;
  27656. rect.left += 2;
  27657. rect.width -= 7;
  27658. rect.top -= 4;
  27659. rect.bottom += 4;
  27660. rect.height += 8;
  27661. this.subMenu.showAnchorRect(rect, true, true);
  27662. },
  27663. hideSubMenu: function() {
  27664. this.subMenu.hide();
  27665. }
  27666. };
  27667. utils.inherits(MenuItem, UIBase);
  27668. utils.extend(MenuItem.prototype, Stateful, true);
  27669. })();
  27670. // ui/combox.js
  27671. // /import core
  27672. // /import uicore
  27673. // /import ui/menu.js
  27674. // /import ui/splitbutton.js
  27675. (function() {
  27676. // todo: menu和item提成通用list
  27677. var utils = baidu.editor.utils,
  27678. uiUtils = baidu.editor.ui.uiUtils,
  27679. Menu = baidu.editor.ui.Menu,
  27680. SplitButton = baidu.editor.ui.SplitButton,
  27681. Combox = baidu.editor.ui.Combox = function(
  27682. options) {
  27683. this.initOptions(options);
  27684. this.initCombox();
  27685. };
  27686. Combox.prototype = {
  27687. uiName: 'combox',
  27688. onbuttonclick: function() {
  27689. this.showPopup();
  27690. },
  27691. initCombox: function() {
  27692. var me = this;
  27693. this.items = this.items || [];
  27694. for(var i = 0; i < this.items.length; i++) {
  27695. var item = this.items[i];
  27696. item.uiName = 'listitem';
  27697. item.index = i;
  27698. item.onclick = function() {
  27699. me.selectByIndex(this.index);
  27700. };
  27701. }
  27702. this.popup = new Menu({
  27703. items: this.items,
  27704. uiName: 'list',
  27705. editor: this.editor,
  27706. captureWheel: true,
  27707. combox: this
  27708. });
  27709. this.initSplitButton();
  27710. },
  27711. _SplitButton_postRender: SplitButton.prototype.postRender,
  27712. postRender: function() {
  27713. this._SplitButton_postRender();
  27714. this.setLabel(this.label || '');
  27715. this.setValue(this.initValue || '');
  27716. },
  27717. showPopup: function() {
  27718. var rect = uiUtils.getClientRect(this.getDom());
  27719. rect.top += 1;
  27720. rect.bottom -= 1;
  27721. rect.height -= 2;
  27722. this.popup.showAnchorRect(rect);
  27723. },
  27724. getValue: function() {
  27725. return this.value;
  27726. },
  27727. setValue: function(value) {
  27728. var index = this.indexByValue(value);
  27729. if(index != -1) {
  27730. this.selectedIndex = index;
  27731. this.setLabel(this.items[index].label);
  27732. this.value = this.items[index].value;
  27733. } else {
  27734. this.selectedIndex = -1;
  27735. this.setLabel(this.getLabelForUnknowValue(value));
  27736. this.value = value;
  27737. }
  27738. },
  27739. setLabel: function(label) {
  27740. this.getDom('button_body').innerHTML = label;
  27741. this.label = label;
  27742. },
  27743. getLabelForUnknowValue: function(value) {
  27744. return value;
  27745. },
  27746. indexByValue: function(value) {
  27747. for(var i = 0; i < this.items.length; i++) {
  27748. if(value == this.items[i].value) {
  27749. return i;
  27750. }
  27751. }
  27752. return -1;
  27753. },
  27754. getItem: function(index) {
  27755. return this.items[index];
  27756. },
  27757. selectByIndex: function(index) {
  27758. if(index < this.items.length &&
  27759. this.fireEvent('select', index) !== false) {
  27760. this.selectedIndex = index;
  27761. this.value = this.items[index].value;
  27762. this.setLabel(this.items[index].label);
  27763. }
  27764. }
  27765. };
  27766. utils.inherits(Combox, SplitButton);
  27767. })();
  27768. // ui/dialog.js
  27769. // /import core
  27770. // /import uicore
  27771. // /import ui/mask.js
  27772. // /import ui/button.js
  27773. (function() {
  27774. var utils = baidu.editor.utils,
  27775. domUtils = baidu.editor.dom.domUtils,
  27776. uiUtils = baidu.editor.ui.uiUtils,
  27777. Mask = baidu.editor.ui.Mask,
  27778. UIBase = baidu.editor.ui.UIBase,
  27779. Button = baidu.editor.ui.Button,
  27780. Dialog = baidu.editor.ui.Dialog = function(
  27781. options) {
  27782. if(options.name) {
  27783. var name = options.name;
  27784. var cssRules = options.cssRules;
  27785. if(!options.className) {
  27786. options.className = 'edui-for-' + name;
  27787. }
  27788. if(cssRules) {
  27789. options.cssRules = '.edui-default .edui-for-' + name +
  27790. ' .edui-dialog-content {' + cssRules + '}'
  27791. }
  27792. }
  27793. this.initOptions(utils.extend({
  27794. autoReset: true,
  27795. draggable: true,
  27796. onok: function() {},
  27797. oncancel: function() {},
  27798. onclose: function(t, ok) {
  27799. return ok ? this.onok() : this.oncancel();
  27800. },
  27801. // 是否控制dialog中的scroll事件, 默认为不阻止
  27802. holdScroll: false
  27803. }, options));
  27804. this.initDialog();
  27805. };
  27806. var modalMask;
  27807. var dragMask;
  27808. var activeDialog;
  27809. Dialog.prototype = {
  27810. draggable: false,
  27811. uiName: 'dialog',
  27812. initDialog: function() {
  27813. var me = this,
  27814. theme = this.editor.options.theme;
  27815. if(this.cssRules) {
  27816. utils.cssRule('edui-customize-' + this.name + '-style',
  27817. this.cssRules);
  27818. }
  27819. this.initUIBase();
  27820. this.modalMask = (modalMask || (modalMask = new Mask({
  27821. className: 'edui-dialog-modalmask',
  27822. theme: theme,
  27823. onclick: function() {
  27824. activeDialog && activeDialog.close(false);
  27825. }
  27826. })));
  27827. this.dragMask = (dragMask || (dragMask = new Mask({
  27828. className: 'edui-dialog-dragmask',
  27829. theme: theme
  27830. })));
  27831. this.closeButton = new Button({
  27832. className: 'edui-dialog-closebutton',
  27833. title: me.closeDialog,
  27834. theme: theme,
  27835. onclick: function() {
  27836. me.close(false);
  27837. }
  27838. });
  27839. this.fullscreen && this.initResizeEvent();
  27840. if(this.buttons) {
  27841. for(var i = 0; i < this.buttons.length; i++) {
  27842. if(!(this.buttons[i] instanceof Button)) {
  27843. this.buttons[i] = new Button(utils.extend(
  27844. this.buttons[i], {
  27845. editor: this.editor
  27846. }, true));
  27847. }
  27848. }
  27849. }
  27850. },
  27851. initResizeEvent: function() {
  27852. var me = this;
  27853. domUtils.on(window, "resize", function() {
  27854. if(me._hidden || me._hidden === undefined) {
  27855. return;
  27856. }
  27857. if(me.__resizeTimer) {
  27858. window.clearTimeout(me.__resizeTimer);
  27859. }
  27860. me.__resizeTimer = window.setTimeout(function() {
  27861. me.__resizeTimer = null;
  27862. var dialogWrapNode = me.getDom(),
  27863. contentNode = me
  27864. .getDom('content'),
  27865. wrapRect = UE.ui.uiUtils
  27866. .getClientRect(dialogWrapNode),
  27867. contentRect = UE.ui.uiUtils
  27868. .getClientRect(contentNode),
  27869. vpRect = uiUtils
  27870. .getViewportRect();
  27871. contentNode.style.width = (vpRect.width -
  27872. wrapRect.width + contentRect.width) +
  27873. "px";
  27874. contentNode.style.height = (vpRect.height -
  27875. wrapRect.height + contentRect.height) +
  27876. "px";
  27877. dialogWrapNode.style.width = vpRect.width + "px";
  27878. dialogWrapNode.style.height = vpRect.height + "px";
  27879. me.fireEvent("resize");
  27880. }, 100);
  27881. });
  27882. },
  27883. fitSize: function() {
  27884. var popBodyEl = this.getDom('body');
  27885. // if (!(baidu.editor.browser.ie && baidu.editor.browser.version
  27886. // == 7)) {
  27887. // uiUtils.removeStyle(popBodyEl, 'width');
  27888. // uiUtils.removeStyle(popBodyEl, 'height');
  27889. // }
  27890. var size = this.mesureSize();
  27891. popBodyEl.style.width = size.width + 'px';
  27892. popBodyEl.style.height = size.height + 'px';
  27893. return size;
  27894. },
  27895. safeSetOffset: function(offset) {
  27896. var me = this;
  27897. var el = me.getDom();
  27898. var vpRect = uiUtils.getViewportRect();
  27899. var rect = uiUtils.getClientRect(el);
  27900. var left = offset.left;
  27901. if(left + rect.width > vpRect.right) {
  27902. left = vpRect.right - rect.width;
  27903. }
  27904. var top = offset.top;
  27905. if(top + rect.height > vpRect.bottom) {
  27906. top = vpRect.bottom - rect.height;
  27907. }
  27908. el.style.left = Math.max(left, 0) + 'px';
  27909. el.style.top = Math.max(top, 0) + 'px';
  27910. },
  27911. showAtCenter: function() {
  27912. var vpRect = uiUtils.getViewportRect();
  27913. if(!this.fullscreen) {
  27914. this.getDom().style.display = '';
  27915. var popSize = this.fitSize();
  27916. var titleHeight = this.getDom('titlebar').offsetHeight | 0;
  27917. var left = vpRect.width / 2 - popSize.width / 2;
  27918. var top = vpRect.height / 2 -
  27919. (popSize.height - titleHeight) / 2 - titleHeight;
  27920. var popEl = this.getDom();
  27921. this.safeSetOffset({
  27922. left: Math.max(left | 0, 0),
  27923. top: Math.max(top | 0, 0)
  27924. });
  27925. if(!domUtils.hasClass(popEl, 'edui-state-centered')) {
  27926. popEl.className += ' edui-state-centered';
  27927. }
  27928. } else {
  27929. var dialogWrapNode = this.getDom(),
  27930. contentNode = this
  27931. .getDom('content');
  27932. dialogWrapNode.style.display = "block";
  27933. var wrapRect = UE.ui.uiUtils.getClientRect(dialogWrapNode),
  27934. contentRect = UE.ui.uiUtils
  27935. .getClientRect(contentNode);
  27936. dialogWrapNode.style.left = "-100000px";
  27937. contentNode.style.width = (vpRect.width - wrapRect.width + contentRect.width) +
  27938. "px";
  27939. contentNode.style.height = (vpRect.height - wrapRect.height + contentRect.height) +
  27940. "px";
  27941. dialogWrapNode.style.width = vpRect.width + "px";
  27942. dialogWrapNode.style.height = vpRect.height + "px";
  27943. dialogWrapNode.style.left = 0;
  27944. // 保存环境的overflow值
  27945. this._originalContext = {
  27946. html: {
  27947. overflowX: document.documentElement.style.overflowX,
  27948. overflowY: document.documentElement.style.overflowY
  27949. },
  27950. body: {
  27951. overflowX: document.body.style.overflowX,
  27952. overflowY: document.body.style.overflowY
  27953. }
  27954. };
  27955. document.documentElement.style.overflowX = 'hidden';
  27956. document.documentElement.style.overflowY = 'hidden';
  27957. document.body.style.overflowX = 'hidden';
  27958. document.body.style.overflowY = 'hidden';
  27959. }
  27960. this._show();
  27961. },
  27962. getContentHtml: function() {
  27963. var contentHtml = '';
  27964. if(typeof this.content == 'string') {
  27965. contentHtml = this.content;
  27966. } else if(this.iframeUrl) {
  27967. contentHtml = '<span id="' +
  27968. this.id +
  27969. '_contmask" class="dialogcontmask"></span><iframe id="' +
  27970. this.id +
  27971. '_iframe" class="%%-iframe" height="100%" width="100%" frameborder="0" src="' +
  27972. this.iframeUrl + '"></iframe>';
  27973. }
  27974. return contentHtml;
  27975. },
  27976. getHtmlTpl: function() {
  27977. var footHtml = '';
  27978. if(this.buttons) {
  27979. var buff = [];
  27980. for(var i = 0; i < this.buttons.length; i++) {
  27981. buff[i] = this.buttons[i].renderHtml();
  27982. }
  27983. footHtml = '<div class="%%-foot">' +
  27984. '<div id="##_buttons" class="%%-buttons">' +
  27985. buff.join('') + '</div>' + '</div>';
  27986. }
  27987. return '<div id="##" class="%%"><div ' +
  27988. (!this.fullscreen ?
  27989. 'class="%%"' :
  27990. 'class="%%-wrap edui-dialog-fullscreen-flag"') +
  27991. '><div id="##_body" class="%%-body">' +
  27992. '<div class="%%-shadow"></div>' +
  27993. '<div id="##_titlebar" class="%%-titlebar">' +
  27994. '<div class="%%-draghandle" onmousedown="$$._onTitlebarMouseDown(event, this);">' +
  27995. '<span class="%%-caption">' + (this.title || '') +
  27996. '</span>' + '</div>' + this.closeButton.renderHtml() +
  27997. '</div>' + '<div id="##_content" class="%%-content">' +
  27998. (this.autoReset ? '' : this.getContentHtml()) +
  27999. '</div>' + footHtml + '</div></div></div>';
  28000. },
  28001. postRender: function() {
  28002. // todo: 保持居中/记住上次关闭位置选项
  28003. if(!this.modalMask.getDom()) {
  28004. this.modalMask.render();
  28005. this.modalMask.hide();
  28006. }
  28007. if(!this.dragMask.getDom()) {
  28008. this.dragMask.render();
  28009. this.dragMask.hide();
  28010. }
  28011. var me = this;
  28012. this.addListener('show', function() {
  28013. me.modalMask.show(this.getDom().style.zIndex - 2);
  28014. });
  28015. this.addListener('hide', function() {
  28016. me.modalMask.hide();
  28017. });
  28018. if(this.buttons) {
  28019. for(var i = 0; i < this.buttons.length; i++) {
  28020. this.buttons[i].postRender();
  28021. }
  28022. }
  28023. domUtils.on(window, 'resize', function() {
  28024. setTimeout(function() {
  28025. if(!me.isHidden()) {
  28026. me
  28027. .safeSetOffset(uiUtils.getClientRect(me
  28028. .getDom()));
  28029. }
  28030. });
  28031. });
  28032. // hold住scroll事件,防止dialog的滚动影响页面
  28033. // if( this.holdScroll ) {
  28034. //
  28035. // if( !me.iframeUrl ) {
  28036. // domUtils.on( document.getElementById( me.id + "_iframe"),
  28037. // !browser.gecko ? "mousewheel" : "DOMMouseScroll",
  28038. // function(e){
  28039. // domUtils.preventDefault(e);
  28040. // } );
  28041. // } else {
  28042. // me.addListener('dialogafterreset', function(){
  28043. // window.setTimeout(function(){
  28044. // var iframeWindow = document.getElementById( me.id +
  28045. // "_iframe").contentWindow;
  28046. //
  28047. // if( browser.ie ) {
  28048. //
  28049. // var timer = window.setInterval(function(){
  28050. //
  28051. // if( iframeWindow.document && iframeWindow.document.body ) {
  28052. // window.clearInterval( timer );
  28053. // timer = null;
  28054. // domUtils.on( iframeWindow.document.body, !browser.gecko ?
  28055. // "mousewheel" : "DOMMouseScroll", function(e){
  28056. // domUtils.preventDefault(e);
  28057. // } );
  28058. // }
  28059. //
  28060. // }, 100);
  28061. //
  28062. // } else {
  28063. // domUtils.on( iframeWindow, !browser.gecko ? "mousewheel" :
  28064. // "DOMMouseScroll", function(e){
  28065. // domUtils.preventDefault(e);
  28066. // } );
  28067. // }
  28068. //
  28069. // }, 1);
  28070. // });
  28071. // }
  28072. //
  28073. // }
  28074. this._hide();
  28075. },
  28076. mesureSize: function() {
  28077. var body = this.getDom('body');
  28078. var width = uiUtils.getClientRect(this.getDom('content')).width;
  28079. var dialogBodyStyle = body.style;
  28080. dialogBodyStyle.width = width;
  28081. return uiUtils.getClientRect(body);
  28082. },
  28083. _onTitlebarMouseDown: function(evt, el) {
  28084. if(this.draggable) {
  28085. var rect;
  28086. var vpRect = uiUtils.getViewportRect();
  28087. var me = this;
  28088. uiUtils.startDrag(evt, {
  28089. ondragstart: function() {
  28090. rect = uiUtils.getClientRect(me.getDom());
  28091. me.getDom('contmask').style.visibility = 'visible';
  28092. me.dragMask.show(me.getDom().style.zIndex - 1);
  28093. },
  28094. ondragmove: function(x, y) {
  28095. var left = rect.left + x;
  28096. var top = rect.top + y;
  28097. me.safeSetOffset({
  28098. left: left,
  28099. top: top
  28100. });
  28101. },
  28102. ondragstop: function() {
  28103. me.getDom('contmask').style.visibility = 'hidden';
  28104. domUtils.removeClasses(me.getDom(), ['edui-state-centered']);
  28105. me.dragMask.hide();
  28106. }
  28107. });
  28108. }
  28109. },
  28110. reset: function() {
  28111. this.getDom('content').innerHTML = this.getContentHtml();
  28112. this.fireEvent('dialogafterreset');
  28113. },
  28114. _show: function() {
  28115. if(this._hidden) {
  28116. this.getDom().style.display = '';
  28117. // 要高过编辑器的zindxe
  28118. this.editor.container.style.zIndex &&
  28119. (this.getDom().style.zIndex = this.editor.container.style.zIndex *
  28120. 1 + 10);
  28121. this._hidden = false;
  28122. this.fireEvent('show');
  28123. baidu.editor.ui.uiUtils.getFixedLayer().style.zIndex = this
  28124. .getDom().style.zIndex -
  28125. 4;
  28126. }
  28127. },
  28128. isHidden: function() {
  28129. return this._hidden;
  28130. },
  28131. _hide: function() {
  28132. if(!this._hidden) {
  28133. var wrapNode = this.getDom();
  28134. wrapNode.style.display = 'none';
  28135. wrapNode.style.zIndex = '';
  28136. wrapNode.style.width = '';
  28137. wrapNode.style.height = '';
  28138. this._hidden = true;
  28139. this.fireEvent('hide');
  28140. }
  28141. },
  28142. open: function() {
  28143. if(this.autoReset) {
  28144. // 有可能还没有渲染
  28145. try {
  28146. this.reset();
  28147. } catch(e) {
  28148. this.render();
  28149. this.open()
  28150. }
  28151. }
  28152. this.showAtCenter();
  28153. if(this.iframeUrl) {
  28154. try {
  28155. this.getDom('iframe').focus();
  28156. } catch(ex) {}
  28157. }
  28158. activeDialog = this;
  28159. },
  28160. _onCloseButtonClick: function(evt, el) {
  28161. this.close(false);
  28162. },
  28163. close: function(ok) {
  28164. if(this.fireEvent('close', ok) !== false) {
  28165. // 还原环境
  28166. if(this.fullscreen) {
  28167. document.documentElement.style.overflowX = this._originalContext.html.overflowX;
  28168. document.documentElement.style.overflowY = this._originalContext.html.overflowY;
  28169. document.body.style.overflowX = this._originalContext.body.overflowX;
  28170. document.body.style.overflowY = this._originalContext.body.overflowY;
  28171. delete this._originalContext;
  28172. }
  28173. this._hide();
  28174. // 销毁content
  28175. var content = this.getDom('content');
  28176. var iframe = this.getDom('iframe');
  28177. if(content && iframe) {
  28178. var doc = iframe.contentDocument ||
  28179. iframe.contentWindow.document;
  28180. doc && (doc.body.innerHTML = '');
  28181. domUtils.remove(content);
  28182. }
  28183. }
  28184. }
  28185. };
  28186. utils.inherits(Dialog, UIBase);
  28187. })();
  28188. // ui/menubutton.js
  28189. // /import core
  28190. // /import uicore
  28191. // /import ui/menu.js
  28192. // /import ui/splitbutton.js
  28193. (function() {
  28194. var utils = baidu.editor.utils,
  28195. Menu = baidu.editor.ui.Menu,
  28196. SplitButton = baidu.editor.ui.SplitButton,
  28197. MenuButton = baidu.editor.ui.MenuButton = function(
  28198. options) {
  28199. this.initOptions(options);
  28200. this.initMenuButton();
  28201. };
  28202. MenuButton.prototype = {
  28203. initMenuButton: function() {
  28204. var me = this;
  28205. this.uiName = "menubutton";
  28206. this.popup = new Menu({
  28207. items: me.items,
  28208. className: me.className,
  28209. editor: me.editor
  28210. });
  28211. this.popup.addListener('show', function() {
  28212. var list = this;
  28213. for(var i = 0; i < list.items.length; i++) {
  28214. list.items[i].removeState('checked');
  28215. if(list.items[i].value == me._value) {
  28216. list.items[i].addState('checked');
  28217. this.value = me._value;
  28218. }
  28219. }
  28220. });
  28221. this.initSplitButton();
  28222. },
  28223. setValue: function(value) {
  28224. this._value = value;
  28225. }
  28226. };
  28227. utils.inherits(MenuButton, SplitButton);
  28228. })();
  28229. // ui/multiMenu.js
  28230. // /import core
  28231. // /import uicore
  28232. // /commands 表情
  28233. (function() {
  28234. var utils = baidu.editor.utils,
  28235. Popup = baidu.editor.ui.Popup,
  28236. SplitButton = baidu.editor.ui.SplitButton,
  28237. MultiMenuPop = baidu.editor.ui.MultiMenuPop = function(
  28238. options) {
  28239. this.initOptions(options);
  28240. this.initMultiMenu();
  28241. };
  28242. MultiMenuPop.prototype = {
  28243. initMultiMenu: function() {
  28244. var me = this;
  28245. this.popup = new Popup({
  28246. content: '',
  28247. editor: me.editor,
  28248. iframe_rendered: false,
  28249. onshow: function() {
  28250. if(!this.iframe_rendered) {
  28251. this.iframe_rendered = true;
  28252. this.getDom('content').innerHTML = '<iframe id="' +
  28253. me.id + '_iframe" src="' + me.iframeUrl +
  28254. '" frameborder="0"></iframe>';
  28255. me.editor.container.style.zIndex &&
  28256. (this.getDom().style.zIndex = me.editor.container.style.zIndex *
  28257. 1 + 1);
  28258. }
  28259. }
  28260. // canSideUp:false,
  28261. // canSideLeft:false
  28262. });
  28263. this.onbuttonclick = function() {
  28264. this.showPopup();
  28265. };
  28266. this.initSplitButton();
  28267. }
  28268. };
  28269. utils.inherits(MultiMenuPop, SplitButton);
  28270. })();
  28271. // ui/shortcutmenu.js
  28272. (function() {
  28273. var UI = baidu.editor.ui,
  28274. UIBase = UI.UIBase,
  28275. uiUtils = UI.uiUtils,
  28276. utils = baidu.editor.utils,
  28277. domUtils = baidu.editor.dom.domUtils;
  28278. var allMenus = [], // 存储所有快捷菜单
  28279. timeID, isSubMenuShow = false; // 是否有子pop显示
  28280. var ShortCutMenu = UI.ShortCutMenu = function(options) {
  28281. this.initOptions(options);
  28282. this.initShortCutMenu();
  28283. };
  28284. ShortCutMenu.postHide = hideAllMenu;
  28285. ShortCutMenu.prototype = {
  28286. isHidden: true,
  28287. SPACE: 5,
  28288. initShortCutMenu: function() {
  28289. this.items = this.items || [];
  28290. this.initUIBase();
  28291. this.initItems();
  28292. this.initEvent();
  28293. allMenus.push(this);
  28294. },
  28295. initEvent: function() {
  28296. var me = this,
  28297. doc = me.editor.document;
  28298. domUtils.on(doc, "mousemove", function(e) {
  28299. if(me.isHidden === false) {
  28300. // 有pop显示就不隐藏快捷菜单
  28301. if(me.getSubMenuMark() ||
  28302. me.eventType == "contextmenu")
  28303. return;
  28304. var flag = true,
  28305. el = me.getDom(),
  28306. wt = el.offsetWidth,
  28307. ht = el.offsetHeight,
  28308. distanceX = wt /
  28309. 2 + me.SPACE, // 距离中心X标准
  28310. distanceY = ht / 2, // 距离中心Y标准
  28311. x = Math.abs(e.screenX - me.left), // 离中心距离横坐标
  28312. y = Math.abs(e.screenY - me.top); // 离中心距离纵坐标
  28313. clearTimeout(timeID);
  28314. timeID = setTimeout(function() {
  28315. if(y > 0 && y < distanceY) {
  28316. me.setOpacity(el, "1");
  28317. } else if(y > distanceY && y < distanceY + 70) {
  28318. me.setOpacity(el, "0.5");
  28319. flag = false;
  28320. } else if(y > distanceY + 70 &&
  28321. y < distanceY + 140) {
  28322. me.hide();
  28323. }
  28324. if(flag && x > 0 && x < distanceX) {
  28325. me.setOpacity(el, "1")
  28326. } else if(x > distanceX && x < distanceX + 70) {
  28327. me.setOpacity(el, "0.5")
  28328. } else if(x > distanceX + 70 &&
  28329. x < distanceX + 140) {
  28330. me.hide();
  28331. }
  28332. });
  28333. }
  28334. });
  28335. // ie\ff下 mouseout不准
  28336. if(browser.chrome) {
  28337. domUtils.on(doc, "mouseout", function(e) {
  28338. var relatedTgt = e.relatedTarget || e.toElement;
  28339. if(relatedTgt == null || relatedTgt.tagName == "HTML") {
  28340. me.hide();
  28341. }
  28342. });
  28343. }
  28344. me.editor.addListener("afterhidepop", function() {
  28345. if(!me.isHidden) {
  28346. isSubMenuShow = true;
  28347. }
  28348. });
  28349. },
  28350. initItems: function() {
  28351. if(utils.isArray(this.items)) {
  28352. for(var i = 0, len = this.items.length; i < len; i++) {
  28353. var item = this.items[i].toLowerCase();
  28354. if(UI[item]) {
  28355. this.items[i] = new UI[item](this.editor);
  28356. this.items[i].className += " edui-shortcutsubmenu ";
  28357. }
  28358. }
  28359. }
  28360. },
  28361. setOpacity: function(el, value) {
  28362. if(browser.ie && browser.version < 9) {
  28363. el.style.filter = "alpha(opacity = " + parseFloat(value) *
  28364. 100 + ");"
  28365. } else {
  28366. el.style.opacity = value;
  28367. }
  28368. },
  28369. getSubMenuMark: function() {
  28370. isSubMenuShow = false;
  28371. var layerEle = uiUtils.getFixedLayer();
  28372. var list = domUtils.getElementsByTagName(layerEle, "div",
  28373. function(node) {
  28374. return domUtils.hasClass(node,
  28375. "edui-shortcutsubmenu edui-popup")
  28376. });
  28377. for(var i = 0, node; node = list[i++];) {
  28378. if(node.style.display != "none") {
  28379. isSubMenuShow = true;
  28380. }
  28381. }
  28382. return isSubMenuShow;
  28383. },
  28384. show: function(e, hasContextmenu) {
  28385. var me = this,
  28386. offset = {},
  28387. el = this.getDom(),
  28388. fixedlayer = uiUtils
  28389. .getFixedLayer();
  28390. function setPos(offset) {
  28391. if(offset.left < 0) {
  28392. offset.left = 0;
  28393. }
  28394. if(offset.top < 0) {
  28395. offset.top = 0;
  28396. }
  28397. el.style.cssText = "position:absolute;left:" + offset.left +
  28398. "px;top:" + offset.top + "px;";
  28399. }
  28400. function setPosByCxtMenu(menu) {
  28401. if(!menu.tagName) {
  28402. menu = menu.getDom();
  28403. }
  28404. offset.left = parseInt(menu.style.left);
  28405. offset.top = parseInt(menu.style.top);
  28406. offset.top -= el.offsetHeight + 15;
  28407. setPos(offset);
  28408. }
  28409. me.eventType = e.type;
  28410. el.style.cssText = "display:block;left:-9999px";
  28411. if(e.type == "contextmenu" && hasContextmenu) {
  28412. var menu = domUtils.getElementsByTagName(fixedlayer, "div",
  28413. "edui-contextmenu")[0];
  28414. if(menu) {
  28415. setPosByCxtMenu(menu)
  28416. } else {
  28417. me.editor.addListener("aftershowcontextmenu", function(
  28418. type, menu) {
  28419. setPosByCxtMenu(menu);
  28420. });
  28421. }
  28422. } else {
  28423. offset = uiUtils.getViewportOffsetByEvent(e);
  28424. offset.top -= el.offsetHeight + me.SPACE;
  28425. offset.left += me.SPACE + 20;
  28426. setPos(offset);
  28427. me.setOpacity(el, 0.2);
  28428. }
  28429. me.isHidden = false;
  28430. me.left = e.screenX + el.offsetWidth / 2 - me.SPACE;
  28431. me.top = e.screenY - (el.offsetHeight / 2) - me.SPACE;
  28432. if(me.editor) {
  28433. el.style.zIndex = me.editor.container.style.zIndex * 1 + 10;
  28434. fixedlayer.style.zIndex = el.style.zIndex - 1;
  28435. }
  28436. },
  28437. hide: function() {
  28438. if(this.getDom()) {
  28439. this.getDom().style.display = "none";
  28440. }
  28441. this.isHidden = true;
  28442. },
  28443. postRender: function() {
  28444. if(utils.isArray(this.items)) {
  28445. for(var i = 0, item; item = this.items[i++];) {
  28446. item.postRender();
  28447. }
  28448. }
  28449. },
  28450. getHtmlTpl: function() {
  28451. var buff;
  28452. if(utils.isArray(this.items)) {
  28453. buff = [];
  28454. for(var i = 0; i < this.items.length; i++) {
  28455. buff[i] = this.items[i].renderHtml();
  28456. }
  28457. buff = buff.join("");
  28458. } else {
  28459. buff = this.items;
  28460. }
  28461. return '<div id="##" class="%% edui-toolbar" data-src="shortcutmenu" onmousedown="return false;" onselectstart="return false;" >' +
  28462. buff + '</div>';
  28463. }
  28464. };
  28465. utils.inherits(ShortCutMenu, UIBase);
  28466. function hideAllMenu(e) {
  28467. var tgt = e.target || e.srcElement,
  28468. cur = domUtils.findParent(tgt,
  28469. function(node) {
  28470. return domUtils.hasClass(node, "edui-shortcutmenu") ||
  28471. domUtils.hasClass(node, "edui-popup");
  28472. }, true);
  28473. if(!cur) {
  28474. for(var i = 0, menu; menu = allMenus[i++];) {
  28475. menu.hide()
  28476. }
  28477. }
  28478. }
  28479. domUtils.on(document, 'mousedown', function(e) {
  28480. hideAllMenu(e);
  28481. });
  28482. domUtils.on(window, 'scroll', function(e) {
  28483. hideAllMenu(e);
  28484. });
  28485. })();
  28486. // ui/breakline.js
  28487. (function() {
  28488. var utils = baidu.editor.utils,
  28489. UIBase = baidu.editor.ui.UIBase,
  28490. Breakline = baidu.editor.ui.Breakline = function(
  28491. options) {
  28492. this.initOptions(options);
  28493. this.initSeparator();
  28494. };
  28495. Breakline.prototype = {
  28496. uiName: 'Breakline',
  28497. initSeparator: function() {
  28498. this.initUIBase();
  28499. },
  28500. getHtmlTpl: function() {
  28501. return '<br/>';
  28502. }
  28503. };
  28504. utils.inherits(Breakline, UIBase);
  28505. })();
  28506. // ui/message.js
  28507. // /import core
  28508. // /import uicore
  28509. (function() {
  28510. var utils = baidu.editor.utils,
  28511. domUtils = baidu.editor.dom.domUtils,
  28512. UIBase = baidu.editor.ui.UIBase,
  28513. Message = baidu.editor.ui.Message = function(
  28514. options) {
  28515. this.initOptions(options);
  28516. this.initMessage();
  28517. };
  28518. Message.prototype = {
  28519. initMessage: function() {
  28520. this.initUIBase();
  28521. },
  28522. getHtmlTpl: function() {
  28523. return '<div id="##" class="edui-message %%">' +
  28524. ' <div id="##_closer" class="edui-message-closer">×</div>' +
  28525. ' <div id="##_body" class="edui-message-body edui-message-type-info">' +
  28526. ' <iframe style="position:absolute;z-index:-1;left:0;top:0;background-color: transparent;" frameborder="0" width="100%" height="100%" src="about:blank"></iframe>' +
  28527. ' <div class="edui-shadow"></div>' +
  28528. ' <div id="##_content" class="edui-message-content">' +
  28529. ' </div>' + ' </div>' + '</div>';
  28530. },
  28531. reset: function(opt) {
  28532. var me = this;
  28533. if(!opt.keepshow) {
  28534. clearTimeout(this.timer);
  28535. me.timer = setTimeout(function() {
  28536. me.hide();
  28537. }, opt.timeout || 4000);
  28538. }
  28539. opt.content !== undefined && me.setContent(opt.content);
  28540. opt.type !== undefined && me.setType(opt.type);
  28541. me.show();
  28542. },
  28543. postRender: function() {
  28544. var me = this,
  28545. closer = this.getDom('closer');
  28546. closer && domUtils.on(closer, 'click', function() {
  28547. me.hide();
  28548. });
  28549. },
  28550. setContent: function(content) {
  28551. this.getDom('content').innerHTML = content;
  28552. },
  28553. setType: function(type) {
  28554. type = type || 'info';
  28555. var body = this.getDom('body');
  28556. body.className = body.className
  28557. .replace(/edui-message-type-[\w-]+/,
  28558. 'edui-message-type-' + type);
  28559. },
  28560. getContent: function() {
  28561. return this.getDom('content').innerHTML;
  28562. },
  28563. getType: function() {
  28564. var arr = this.getDom('body')
  28565. .match(/edui-message-type-([\w-]+)/);
  28566. return arr ? arr[1] : '';
  28567. },
  28568. show: function() {
  28569. this.getDom().style.display = 'block';
  28570. },
  28571. hide: function() {
  28572. var dom = this.getDom();
  28573. if(dom) {
  28574. dom.style.display = 'none';
  28575. dom.parentNode && dom.parentNode.removeChild(dom);
  28576. }
  28577. }
  28578. };
  28579. utils.inherits(Message, UIBase);
  28580. })();
  28581. // adapter/editorui.js
  28582. // ui跟编辑器的适配層
  28583. // 那个按钮弹出是dialog,是下拉筐等都是在这个js中配置
  28584. // 自己写的ui也要在这里配置,放到baidu.editor.ui下边,当编辑器实例化的时候会根据ueditor.config中的toolbars找到相应的进行实例化
  28585. (function() {
  28586. var utils = baidu.editor.utils;
  28587. var editorui = baidu.editor.ui;
  28588. var _Dialog = editorui.Dialog;
  28589. editorui.buttons = {};
  28590. editorui.Dialog = function(options) {
  28591. var dialog = new _Dialog(options);
  28592. dialog.addListener('hide', function() {
  28593. if(dialog.editor) {
  28594. var editor = dialog.editor;
  28595. try {
  28596. if(browser.gecko) {
  28597. var y = editor.window.scrollY,
  28598. x = editor.window.scrollX;
  28599. editor.body.focus();
  28600. editor.window.scrollTo(x, y);
  28601. } else {
  28602. editor.focus();
  28603. }
  28604. } catch(ex) {}
  28605. }
  28606. });
  28607. return dialog;
  28608. };
  28609. var iframeUrlMap = {
  28610. 'anchor': '~/dialogs/anchor/anchor.html',
  28611. 'insertimage': '~/dialogs/image/image.html',
  28612. 'link': '~/dialogs/link/link.html',
  28613. 'spechars': '~/dialogs/spechars/spechars.html',
  28614. 'searchreplace': '~/dialogs/searchreplace/searchreplace.html',
  28615. 'map': '~/dialogs/map/map.html',
  28616. 'gmap': '~/dialogs/gmap/gmap.html',
  28617. 'insertvideo': '~/dialogs/video/video.html',
  28618. 'help': '~/dialogs/help/help.html',
  28619. 'preview': '~/dialogs/preview/preview.html',
  28620. 'emotion': '~/dialogs/emotion/emotion.html',
  28621. 'wordimage': '~/dialogs/wordimage/wordimage.html',
  28622. 'attachment': '~/dialogs/attachment/attachment.html',
  28623. 'insertframe': '~/dialogs/insertframe/insertframe.html',
  28624. 'edittip': '~/dialogs/table/edittip.html',
  28625. 'edittable': '~/dialogs/table/edittable.html',
  28626. 'edittd': '~/dialogs/table/edittd.html',
  28627. 'webapp': '~/dialogs/webapp/webapp.html',
  28628. 'snapscreen': '~/dialogs/snapscreen/snapscreen.html',
  28629. 'scrawl': '~/dialogs/scrawl/scrawl.html',
  28630. 'music': '~/dialogs/music/music.html',
  28631. 'template': '~/dialogs/template/template.html',
  28632. 'background': '~/dialogs/background/background.html',
  28633. 'charts': '~/dialogs/charts/charts.html'
  28634. };
  28635. // 为工具栏添加按钮,以下都是统一的按钮触发命令,所以写在一起
  28636. var btnCmds = ['undo', 'redo', 'formatmatch', 'bold', 'italic',
  28637. 'underline', 'fontborder', 'touppercase', 'tolowercase',
  28638. 'strikethrough', 'subscript', 'superscript', 'source',
  28639. 'indent', 'outdent', 'blockquote', 'pasteplain', 'pagebreak',
  28640. 'selectall', 'print', 'horizontal', 'removeformat', 'time',
  28641. 'date', 'unlink', 'insertparagraphbeforetable', 'insertrow',
  28642. 'insertcol', 'mergeright', 'mergedown', 'deleterow',
  28643. 'deletecol', 'splittorows', 'splittocols', 'splittocells',
  28644. 'mergecells', 'deletetable', 'drafts', 'showall'
  28645. ];
  28646. for(var i = 0, ci; ci = btnCmds[i++];) {
  28647. ci = ci.toLowerCase();
  28648. editorui[ci] = function(cmd) {
  28649. return function(editor) {
  28650. var ui = new editorui.Button({
  28651. className: 'edui-for-' + cmd,
  28652. title: editor.options.labelMap[cmd] ||
  28653. editor.getLang("labelMap." + cmd) || '',
  28654. onclick: function() {
  28655. editor.execCommand(cmd);
  28656. },
  28657. theme: editor.options.theme,
  28658. showText: false
  28659. });
  28660. editorui.buttons[cmd] = ui;
  28661. editor.addListener('selectionchange', function(type,
  28662. causeByUi, uiReady) {
  28663. var state = editor.queryCommandState(cmd);
  28664. if(state == -1) {
  28665. ui.setDisabled(true);
  28666. ui.setChecked(false);
  28667. } else {
  28668. if(!uiReady) {
  28669. ui.setDisabled(false);
  28670. ui.setChecked(state);
  28671. }
  28672. }
  28673. });
  28674. return ui;
  28675. };
  28676. }(ci);
  28677. }
  28678. // 清除文档
  28679. editorui.cleardoc = function(editor) {
  28680. var ui = new editorui.Button({
  28681. className: 'edui-for-cleardoc',
  28682. title: editor.options.labelMap.cleardoc ||
  28683. editor.getLang("labelMap.cleardoc") || '',
  28684. theme: editor.options.theme,
  28685. onclick: function() {
  28686. if(confirm(editor.getLang("confirmClear"))) {
  28687. editor.execCommand('cleardoc');
  28688. }
  28689. }
  28690. });
  28691. editorui.buttons["cleardoc"] = ui;
  28692. editor.addListener('selectionchange', function() {
  28693. ui.setDisabled(editor.queryCommandState('cleardoc') == -1);
  28694. });
  28695. return ui;
  28696. };
  28697. // 排版,图片排版,文字方向
  28698. var typeset = {
  28699. 'justify': ['left', 'right', 'center', 'justify'],
  28700. 'imagefloat': ['none', 'left', 'center', 'right'],
  28701. 'directionality': ['ltr', 'rtl']
  28702. };
  28703. for(var p in typeset) {
  28704. (function(cmd, val) {
  28705. for(var i = 0, ci; ci = val[i++];) {
  28706. (function(cmd2) {
  28707. editorui[cmd.replace('float', '') + cmd2] = function(
  28708. editor) {
  28709. var ui = new editorui.Button({
  28710. className: 'edui-for-' +
  28711. cmd.replace('float', '') + cmd2,
  28712. title: editor.options.labelMap[cmd.replace(
  28713. 'float', '') +
  28714. cmd2] ||
  28715. editor.getLang("labelMap." +
  28716. cmd.replace('float', '') +
  28717. cmd2) || '',
  28718. theme: editor.options.theme,
  28719. onclick: function() {
  28720. editor.execCommand(cmd, cmd2);
  28721. }
  28722. });
  28723. editorui.buttons[cmd] = ui;
  28724. editor.addListener('selectionchange', function(
  28725. type, causeByUi, uiReady) {
  28726. ui
  28727. .setDisabled(editor
  28728. .queryCommandState(cmd) == -1);
  28729. ui
  28730. .setChecked(editor
  28731. .queryCommandValue(cmd) == cmd2 &&
  28732. !uiReady);
  28733. });
  28734. return ui;
  28735. };
  28736. })(ci)
  28737. }
  28738. })(p, typeset[p])
  28739. }
  28740. // 字体颜色和背景颜色
  28741. for(var i = 0, ci; ci = ['backcolor', 'forecolor'][i++];) {
  28742. editorui[ci] = function(cmd) {
  28743. return function(editor) {
  28744. var ui = new editorui.ColorButton({
  28745. className: 'edui-for-' + cmd,
  28746. color: 'default',
  28747. title: editor.options.labelMap[cmd] ||
  28748. editor.getLang("labelMap." + cmd) || '',
  28749. editor: editor,
  28750. onpickcolor: function(t, color) {
  28751. editor.execCommand(cmd, color);
  28752. },
  28753. onpicknocolor: function() {
  28754. editor.execCommand(cmd, 'default');
  28755. this.setColor('transparent');
  28756. this.color = 'default';
  28757. },
  28758. onbuttonclick: function() {
  28759. editor.execCommand(cmd, this.color);
  28760. }
  28761. });
  28762. editorui.buttons[cmd] = ui;
  28763. editor.addListener('selectionchange', function() {
  28764. ui.setDisabled(editor.queryCommandState(cmd) == -1);
  28765. });
  28766. return ui;
  28767. };
  28768. }(ci);
  28769. }
  28770. var dialogBtns = {
  28771. noOk: ['searchreplace', 'help', 'spechars', 'webapp', 'preview'],
  28772. ok: ['attachment', 'anchor', 'link', 'insertimage', 'map', 'gmap',
  28773. 'insertframe', 'wordimage', 'insertvideo', 'insertframe',
  28774. 'edittip', 'edittable', 'edittd', 'scrawl', 'template',
  28775. 'music', 'background', 'charts'
  28776. ]
  28777. };
  28778. for(var p in dialogBtns) {
  28779. (function(type, vals) {
  28780. for(var i = 0, ci; ci = vals[i++];) {
  28781. // todo opera下存在问题
  28782. if(browser.opera && ci === "searchreplace") {
  28783. continue;
  28784. }
  28785. (function(cmd) {
  28786. editorui[cmd] = function(editor, iframeUrl, title) {
  28787. iframeUrl = iframeUrl ||
  28788. (editor.options.iframeUrlMap || {})[cmd] ||
  28789. iframeUrlMap[cmd];
  28790. title = editor.options.labelMap[cmd] ||
  28791. editor.getLang("labelMap." + cmd) || '';
  28792. var dialog;
  28793. // 没有iframeUrl不创建dialog
  28794. if(iframeUrl) {
  28795. dialog = new editorui.Dialog(utils.extend({
  28796. iframeUrl: editor.ui.mapUrl(iframeUrl),
  28797. editor: editor,
  28798. className: 'edui-for-' + cmd,
  28799. title: title,
  28800. holdScroll: cmd === 'insertimage',
  28801. fullscreen: /charts|preview/.test(cmd),
  28802. closeDialog: editor.getLang("closeDialog")
  28803. }, type == 'ok' ? {
  28804. buttons: [{
  28805. className: 'edui-okbutton',
  28806. label: editor.getLang("ok"),
  28807. editor: editor,
  28808. onclick: function() {
  28809. dialog.close(true);
  28810. }
  28811. }, {
  28812. className: 'edui-cancelbutton',
  28813. label: editor.getLang("cancel"),
  28814. editor: editor,
  28815. onclick: function() {
  28816. dialog.close(false);
  28817. }
  28818. }]
  28819. } : {}));
  28820. editor.ui._dialogs[cmd + "Dialog"] = dialog;
  28821. }
  28822. var ui = new editorui.Button({
  28823. className: 'edui-for-' + cmd,
  28824. title: title,
  28825. onclick: function() {
  28826. if(dialog) {
  28827. switch(cmd) {
  28828. case "wordimage":
  28829. var images = editor
  28830. .execCommand("wordimage");
  28831. if(images && images.length) {
  28832. dialog.render();
  28833. dialog.open();
  28834. }
  28835. break;
  28836. case "scrawl":
  28837. if(editor
  28838. .queryCommandState("scrawl") != -1) {
  28839. dialog.render();
  28840. dialog.open();
  28841. }
  28842. break;
  28843. default:
  28844. dialog.render();
  28845. dialog.open();
  28846. }
  28847. }
  28848. },
  28849. theme: editor.options.theme,
  28850. disabled: (cmd == 'scrawl' && editor
  28851. .queryCommandState("scrawl") == -1) ||
  28852. (cmd == 'charts')
  28853. });
  28854. editorui.buttons[cmd] = ui;
  28855. editor.addListener('selectionchange', function() {
  28856. // 只存在于右键菜单而无工具栏按钮的ui不需要检测状态
  28857. var unNeedCheckState = {
  28858. 'edittable': 1
  28859. };
  28860. if(cmd in unNeedCheckState)
  28861. return;
  28862. var state = editor.queryCommandState(cmd);
  28863. if(ui.getDom()) {
  28864. ui.setDisabled(state == -1);
  28865. ui.setChecked(state);
  28866. }
  28867. });
  28868. return ui;
  28869. };
  28870. })(ci.toLowerCase())
  28871. }
  28872. })(p, dialogBtns[p]);
  28873. }
  28874. editorui.snapscreen = function(editor, iframeUrl, title) {
  28875. title = editor.options.labelMap['snapscreen'] ||
  28876. editor.getLang("labelMap.snapscreen") || '';
  28877. var ui = new editorui.Button({
  28878. className: 'edui-for-snapscreen',
  28879. title: title,
  28880. onclick: function() {
  28881. editor.execCommand("snapscreen");
  28882. },
  28883. theme: editor.options.theme
  28884. });
  28885. editorui.buttons['snapscreen'] = ui;
  28886. iframeUrl = iframeUrl ||
  28887. (editor.options.iframeUrlMap || {})["snapscreen"] ||
  28888. iframeUrlMap["snapscreen"];
  28889. if(iframeUrl) {
  28890. var dialog = new editorui.Dialog({
  28891. iframeUrl: editor.ui.mapUrl(iframeUrl),
  28892. editor: editor,
  28893. className: 'edui-for-snapscreen',
  28894. title: title,
  28895. buttons: [{
  28896. className: 'edui-okbutton',
  28897. label: editor.getLang("ok"),
  28898. editor: editor,
  28899. onclick: function() {
  28900. dialog.close(true);
  28901. }
  28902. }, {
  28903. className: 'edui-cancelbutton',
  28904. label: editor.getLang("cancel"),
  28905. editor: editor,
  28906. onclick: function() {
  28907. dialog.close(false);
  28908. }
  28909. }]
  28910. });
  28911. dialog.render();
  28912. editor.ui._dialogs["snapscreenDialog"] = dialog;
  28913. }
  28914. editor.addListener('selectionchange', function() {
  28915. ui.setDisabled(editor.queryCommandState('snapscreen') == -1);
  28916. });
  28917. return ui;
  28918. };
  28919. editorui.insertcode = function(editor, list, title) {
  28920. list = editor.options['insertcode'] || [];
  28921. title = editor.options.labelMap['insertcode'] ||
  28922. editor.getLang("labelMap.insertcode") || '';
  28923. // if (!list.length) return;
  28924. var items = [];
  28925. utils.each(list, function(key, val) {
  28926. items.push({
  28927. label: key,
  28928. value: val,
  28929. theme: editor.options.theme,
  28930. renderLabelHtml: function() {
  28931. return '<div class="edui-label %%-label" >' +
  28932. (this.label || '') + '</div>';
  28933. }
  28934. });
  28935. });
  28936. var ui = new editorui.Combox({
  28937. editor: editor,
  28938. items: items,
  28939. onselect: function(t, index) {
  28940. editor.execCommand('insertcode', this.items[index].value);
  28941. },
  28942. onbuttonclick: function() {
  28943. this.showPopup();
  28944. },
  28945. title: title,
  28946. initValue: title,
  28947. className: 'edui-for-insertcode',
  28948. indexByValue: function(value) {
  28949. if(value) {
  28950. for(var i = 0, ci; ci = this.items[i]; i++) {
  28951. if(ci.value.indexOf(value) != -1)
  28952. return i;
  28953. }
  28954. }
  28955. return -1;
  28956. }
  28957. });
  28958. editorui.buttons['insertcode'] = ui;
  28959. editor.addListener('selectionchange', function(type, causeByUi,
  28960. uiReady) {
  28961. if(!uiReady) {
  28962. var state = editor.queryCommandState('insertcode');
  28963. if(state == -1) {
  28964. ui.setDisabled(true);
  28965. } else {
  28966. ui.setDisabled(false);
  28967. var value = editor.queryCommandValue('insertcode');
  28968. if(!value) {
  28969. ui.setValue(title);
  28970. return;
  28971. }
  28972. // trace:1871 ie下从源码模式切换回来时,字体会带单引号,而且会有逗号
  28973. value
  28974. &&
  28975. (value = value.replace(/['"]/g, '')
  28976. .split(',')[0]);
  28977. ui.setValue(value);
  28978. }
  28979. }
  28980. });
  28981. return ui;
  28982. };
  28983. editorui.fontfamily = function(editor, list, title) {
  28984. list = editor.options['fontfamily'] || [];
  28985. title = editor.options.labelMap['fontfamily'] ||
  28986. editor.getLang("labelMap.fontfamily") || '';
  28987. if(!list.length)
  28988. return;
  28989. for(var i = 0, ci, items = []; ci = list[i]; i++) {
  28990. var langLabel = editor.getLang('fontfamily')[ci.name] || "";
  28991. (function(key, val) {
  28992. items.push({
  28993. label: key,
  28994. value: val,
  28995. theme: editor.options.theme,
  28996. renderLabelHtml: function() {
  28997. return '<div class="edui-label %%-label" style="font-family:' +
  28998. utils.unhtml(this.value) +
  28999. '">' +
  29000. (this.label || '') + '</div>';
  29001. }
  29002. });
  29003. })(ci.label || langLabel, ci.val)
  29004. }
  29005. var ui = new editorui.Combox({
  29006. editor: editor,
  29007. items: items,
  29008. onselect: function(t, index) {
  29009. editor.execCommand('FontFamily', this.items[index].value);
  29010. },
  29011. onbuttonclick: function() {
  29012. this.showPopup();
  29013. },
  29014. title: title,
  29015. initValue: title,
  29016. className: 'edui-for-fontfamily',
  29017. indexByValue: function(value) {
  29018. if(value) {
  29019. for(var i = 0, ci; ci = this.items[i]; i++) {
  29020. if(ci.value.indexOf(value) != -1)
  29021. return i;
  29022. }
  29023. }
  29024. return -1;
  29025. }
  29026. });
  29027. editorui.buttons['fontfamily'] = ui;
  29028. editor.addListener('selectionchange', function(type, causeByUi,
  29029. uiReady) {
  29030. if(!uiReady) {
  29031. var state = editor.queryCommandState('FontFamily');
  29032. if(state == -1) {
  29033. ui.setDisabled(true);
  29034. } else {
  29035. ui.setDisabled(false);
  29036. var value = editor.queryCommandValue('FontFamily');
  29037. // trace:1871 ie下从源码模式切换回来时,字体会带单引号,而且会有逗号
  29038. value
  29039. &&
  29040. (value = value.replace(/['"]/g, '')
  29041. .split(',')[0]);
  29042. ui.setValue(value);
  29043. }
  29044. }
  29045. });
  29046. return ui;
  29047. };
  29048. editorui.fontsize = function(editor, list, title) {
  29049. title = editor.options.labelMap['fontsize'] ||
  29050. editor.getLang("labelMap.fontsize") || '';
  29051. list = list || editor.options['fontsize'] || [];
  29052. if(!list.length)
  29053. return;
  29054. var items = [];
  29055. for(var i = 0; i < list.length; i++) {
  29056. var size = list[i] + 'px';
  29057. items.push({
  29058. label: size,
  29059. value: size,
  29060. theme: editor.options.theme,
  29061. renderLabelHtml: function() {
  29062. return '<div class="edui-label %%-label" style="line-height:1;font-size:' +
  29063. this.value +
  29064. '">' +
  29065. (this.label || '') +
  29066. '</div>';
  29067. }
  29068. });
  29069. }
  29070. var ui = new editorui.Combox({
  29071. editor: editor,
  29072. items: items,
  29073. title: title,
  29074. initValue: title,
  29075. onselect: function(t, index) {
  29076. editor.execCommand('FontSize', this.items[index].value);
  29077. },
  29078. onbuttonclick: function() {
  29079. this.showPopup();
  29080. },
  29081. className: 'edui-for-fontsize'
  29082. });
  29083. editorui.buttons['fontsize'] = ui;
  29084. editor.addListener('selectionchange', function(type, causeByUi,
  29085. uiReady) {
  29086. if(!uiReady) {
  29087. var state = editor.queryCommandState('FontSize');
  29088. if(state == -1) {
  29089. ui.setDisabled(true);
  29090. } else {
  29091. ui.setDisabled(false);
  29092. ui.setValue(editor.queryCommandValue('FontSize'));
  29093. }
  29094. }
  29095. });
  29096. return ui;
  29097. };
  29098. editorui.paragraph = function(editor, list, title) {
  29099. title = editor.options.labelMap['paragraph'] ||
  29100. editor.getLang("labelMap.paragraph") || '';
  29101. list = editor.options['paragraph'] || [];
  29102. if(utils.isEmptyObject(list))
  29103. return;
  29104. var items = [];
  29105. for(var i in list) {
  29106. items.push({
  29107. value: i,
  29108. label: list[i] || editor.getLang("paragraph")[i],
  29109. theme: editor.options.theme,
  29110. renderLabelHtml: function() {
  29111. return '<div class="edui-label %%-label"><span class="edui-for-' +
  29112. this.value +
  29113. '">' +
  29114. (this.label || '') +
  29115. '</span></div>';
  29116. }
  29117. })
  29118. }
  29119. var ui = new editorui.Combox({
  29120. editor: editor,
  29121. items: items,
  29122. title: title,
  29123. initValue: title,
  29124. className: 'edui-for-paragraph',
  29125. onselect: function(t, index) {
  29126. editor.execCommand('Paragraph', this.items[index].value);
  29127. },
  29128. onbuttonclick: function() {
  29129. this.showPopup();
  29130. }
  29131. });
  29132. editorui.buttons['paragraph'] = ui;
  29133. editor.addListener('selectionchange', function(type, causeByUi,
  29134. uiReady) {
  29135. if(!uiReady) {
  29136. var state = editor.queryCommandState('Paragraph');
  29137. if(state == -1) {
  29138. ui.setDisabled(true);
  29139. } else {
  29140. ui.setDisabled(false);
  29141. var value = editor.queryCommandValue('Paragraph');
  29142. var index = ui.indexByValue(value);
  29143. if(index != -1) {
  29144. ui.setValue(value);
  29145. } else {
  29146. ui.setValue(ui.initValue);
  29147. }
  29148. }
  29149. }
  29150. });
  29151. return ui;
  29152. };
  29153. // 自定义标题
  29154. editorui.customstyle = function(editor) {
  29155. var list = editor.options['customstyle'] || [],
  29156. title = editor.options.labelMap['customstyle'] ||
  29157. editor.getLang("labelMap.customstyle") || '';
  29158. if(!list.length)
  29159. return;
  29160. var langCs = editor.getLang('customstyle');
  29161. for(var i = 0, items = [], t; t = list[i++];) {
  29162. (function(t) {
  29163. var ck = {};
  29164. ck.label = t.label ? t.label : langCs[t.name];
  29165. ck.style = t.style;
  29166. ck.className = t.className;
  29167. ck.tag = t.tag;
  29168. items.push({
  29169. label: ck.label,
  29170. value: ck,
  29171. theme: editor.options.theme,
  29172. renderLabelHtml: function() {
  29173. return '<div class="edui-label %%-label">' +
  29174. '<' +
  29175. ck.tag +
  29176. ' ' +
  29177. (ck.className ? ' class="' + ck.className +
  29178. '"' : "") +
  29179. (ck.style ?
  29180. ' style="' + ck.style + '"' :
  29181. "") + '>' + ck.label + "<\/" +
  29182. ck.tag + ">" + '</div>';
  29183. }
  29184. });
  29185. })(t);
  29186. }
  29187. var ui = new editorui.Combox({
  29188. editor: editor,
  29189. items: items,
  29190. title: title,
  29191. initValue: title,
  29192. className: 'edui-for-customstyle',
  29193. onselect: function(t, index) {
  29194. editor.execCommand('customstyle', this.items[index].value);
  29195. },
  29196. onbuttonclick: function() {
  29197. this.showPopup();
  29198. },
  29199. indexByValue: function(value) {
  29200. for(var i = 0, ti; ti = this.items[i++];) {
  29201. if(ti.label == value) {
  29202. return i - 1
  29203. }
  29204. }
  29205. return -1;
  29206. }
  29207. });
  29208. editorui.buttons['customstyle'] = ui;
  29209. editor.addListener('selectionchange', function(type, causeByUi,
  29210. uiReady) {
  29211. if(!uiReady) {
  29212. var state = editor.queryCommandState('customstyle');
  29213. if(state == -1) {
  29214. ui.setDisabled(true);
  29215. } else {
  29216. ui.setDisabled(false);
  29217. var value = editor.queryCommandValue('customstyle');
  29218. var index = ui.indexByValue(value);
  29219. if(index != -1) {
  29220. ui.setValue(value);
  29221. } else {
  29222. ui.setValue(ui.initValue);
  29223. }
  29224. }
  29225. }
  29226. });
  29227. return ui;
  29228. };
  29229. editorui.inserttable = function(editor, iframeUrl, title) {
  29230. title = editor.options.labelMap['inserttable'] ||
  29231. editor.getLang("labelMap.inserttable") || '';
  29232. var ui = new editorui.TableButton({
  29233. editor: editor,
  29234. title: title,
  29235. className: 'edui-for-inserttable',
  29236. onpicktable: function(t, numCols, numRows) {
  29237. editor.execCommand('InsertTable', {
  29238. numRows: numRows,
  29239. numCols: numCols,
  29240. border: 1
  29241. });
  29242. },
  29243. onbuttonclick: function() {
  29244. this.showPopup();
  29245. }
  29246. });
  29247. editorui.buttons['inserttable'] = ui;
  29248. editor.addListener('selectionchange', function() {
  29249. ui.setDisabled(editor.queryCommandState('inserttable') == -1);
  29250. });
  29251. return ui;
  29252. };
  29253. editorui.lineheight = function(editor) {
  29254. var val = editor.options.lineheight || [];
  29255. if(!val.length)
  29256. return;
  29257. for(var i = 0, ci, items = []; ci = val[i++];) {
  29258. items.push({
  29259. // todo:写死了
  29260. label: ci,
  29261. value: ci,
  29262. theme: editor.options.theme,
  29263. onclick: function() {
  29264. editor.execCommand("lineheight", this.value);
  29265. }
  29266. })
  29267. }
  29268. var ui = new editorui.MenuButton({
  29269. editor: editor,
  29270. className: 'edui-for-lineheight',
  29271. title: editor.options.labelMap['lineheight'] ||
  29272. editor.getLang("labelMap.lineheight") || '',
  29273. items: items,
  29274. onbuttonclick: function() {
  29275. var value = editor.queryCommandValue('LineHeight') ||
  29276. this.value;
  29277. editor.execCommand("LineHeight", value);
  29278. }
  29279. });
  29280. editorui.buttons['lineheight'] = ui;
  29281. editor.addListener('selectionchange', function() {
  29282. var state = editor.queryCommandState('LineHeight');
  29283. if(state == -1) {
  29284. ui.setDisabled(true);
  29285. } else {
  29286. ui.setDisabled(false);
  29287. var value = editor.queryCommandValue('LineHeight');
  29288. value && ui.setValue((value + '').replace(/cm/, ''));
  29289. ui.setChecked(state)
  29290. }
  29291. });
  29292. return ui;
  29293. };
  29294. var rowspacings = ['top', 'bottom'];
  29295. for(var r = 0, ri; ri = rowspacings[r++];) {
  29296. (function(cmd) {
  29297. editorui['rowspacing' + cmd] = function(editor) {
  29298. var val = editor.options['rowspacing' + cmd] || [];
  29299. if(!val.length)
  29300. return null;
  29301. for(var i = 0, ci, items = []; ci = val[i++];) {
  29302. items.push({
  29303. label: ci,
  29304. value: ci,
  29305. theme: editor.options.theme,
  29306. onclick: function() {
  29307. editor.execCommand("rowspacing", this.value,
  29308. cmd);
  29309. }
  29310. })
  29311. }
  29312. var ui = new editorui.MenuButton({
  29313. editor: editor,
  29314. className: 'edui-for-rowspacing' + cmd,
  29315. title: editor.options.labelMap['rowspacing' + cmd] ||
  29316. editor.getLang("labelMap.rowspacing" + cmd) ||
  29317. '',
  29318. items: items,
  29319. onbuttonclick: function() {
  29320. var value = editor.queryCommandValue('rowspacing',
  29321. cmd) ||
  29322. this.value;
  29323. editor.execCommand("rowspacing", value, cmd);
  29324. }
  29325. });
  29326. editorui.buttons[cmd] = ui;
  29327. editor.addListener('selectionchange', function() {
  29328. var state = editor.queryCommandState('rowspacing', cmd);
  29329. if(state == -1) {
  29330. ui.setDisabled(true);
  29331. } else {
  29332. ui.setDisabled(false);
  29333. var value = editor.queryCommandValue('rowspacing',
  29334. cmd);
  29335. value && ui.setValue((value + '').replace(/%/, ''));
  29336. ui.setChecked(state)
  29337. }
  29338. });
  29339. return ui;
  29340. }
  29341. })(ri)
  29342. }
  29343. // 有序,无序列表
  29344. var lists = ['insertorderedlist', 'insertunorderedlist'];
  29345. for(var l = 0, cl; cl = lists[l++];) {
  29346. (function(cmd) {
  29347. editorui[cmd] = function(editor) {
  29348. var vals = editor.options[cmd],
  29349. _onMenuClick = function() {
  29350. editor.execCommand(cmd, this.value);
  29351. },
  29352. items = [];
  29353. for(var i in vals) {
  29354. items.push({
  29355. label: vals[i] || editor.getLang()[cmd][i] || "",
  29356. value: i,
  29357. theme: editor.options.theme,
  29358. onclick: _onMenuClick
  29359. })
  29360. }
  29361. var ui = new editorui.MenuButton({
  29362. editor: editor,
  29363. className: 'edui-for-' + cmd,
  29364. title: editor.getLang("labelMap." + cmd) || '',
  29365. 'items': items,
  29366. onbuttonclick: function() {
  29367. var value = editor.queryCommandValue(cmd) ||
  29368. this.value;
  29369. editor.execCommand(cmd, value);
  29370. }
  29371. });
  29372. editorui.buttons[cmd] = ui;
  29373. editor.addListener('selectionchange', function() {
  29374. var state = editor.queryCommandState(cmd);
  29375. if(state == -1) {
  29376. ui.setDisabled(true);
  29377. } else {
  29378. ui.setDisabled(false);
  29379. var value = editor.queryCommandValue(cmd);
  29380. ui.setValue(value);
  29381. ui.setChecked(state)
  29382. }
  29383. });
  29384. return ui;
  29385. };
  29386. })(cl)
  29387. }
  29388. editorui.fullscreen = function(editor, title) {
  29389. title = editor.options.labelMap['fullscreen'] ||
  29390. editor.getLang("labelMap.fullscreen") || '';
  29391. var ui = new editorui.Button({
  29392. className: 'edui-for-fullscreen',
  29393. title: title,
  29394. theme: editor.options.theme,
  29395. onclick: function() {
  29396. if(editor.ui) {
  29397. editor.ui.setFullScreen(!editor.ui.isFullScreen());
  29398. }
  29399. this.setChecked(editor.ui.isFullScreen());
  29400. }
  29401. });
  29402. editorui.buttons['fullscreen'] = ui;
  29403. editor.addListener('selectionchange', function() {
  29404. var state = editor.queryCommandState('fullscreen');
  29405. ui.setDisabled(state == -1);
  29406. ui.setChecked(editor.ui.isFullScreen());
  29407. });
  29408. return ui;
  29409. };
  29410. // 表情
  29411. editorui["emotion"] = function(editor, iframeUrl) {
  29412. var cmd = "emotion";
  29413. var ui = new editorui.MultiMenuPop({
  29414. title: editor.options.labelMap[cmd] ||
  29415. editor.getLang("labelMap." + cmd + "") || '',
  29416. editor: editor,
  29417. className: 'edui-for-' + cmd,
  29418. iframeUrl: editor.ui.mapUrl(iframeUrl ||
  29419. (editor.options.iframeUrlMap || {})[cmd] ||
  29420. iframeUrlMap[cmd])
  29421. });
  29422. editorui.buttons[cmd] = ui;
  29423. editor.addListener('selectionchange', function() {
  29424. ui.setDisabled(editor.queryCommandState(cmd) == -1)
  29425. });
  29426. return ui;
  29427. };
  29428. /**
  29429. * showall
  29430. */
  29431. editorui["showall"] = function(editor) {
  29432. var cmd = "showall";
  29433. var ui = new editorui.Button({
  29434. title: editor.options.labelMap[cmd] || '更多功能',
  29435. editor: editor,
  29436. className: 'edui-for-' + cmd,
  29437. onclick: function() {
  29438. editor.execCommand('showall')
  29439. }
  29440. });
  29441. editorui.buttons[cmd] = ui;
  29442. editor.addListener('selectionchange', function() {
  29443. ui.setChecked($("#" + this.options.editor.key + " .hideTools").css("display") != 'none');
  29444. });
  29445. return ui;
  29446. };
  29447. editorui.autotypeset = function(editor) {
  29448. var ui = new editorui.AutoTypeSetButton({
  29449. editor: editor,
  29450. title: editor.options.labelMap['autotypeset'] ||
  29451. editor.getLang("labelMap.autotypeset") || '',
  29452. className: 'edui-for-autotypeset',
  29453. onbuttonclick: function() {
  29454. editor.execCommand('autotypeset')
  29455. }
  29456. });
  29457. editorui.buttons['autotypeset'] = ui;
  29458. editor.addListener('selectionchange', function() {
  29459. ui.setDisabled(editor.queryCommandState('autotypeset') == -1);
  29460. });
  29461. return ui;
  29462. };
  29463. /* 简单上传插件 */
  29464. editorui["simpleupload"] = function(editor) {
  29465. var name = 'simpleupload',
  29466. ui = new editorui.Button({
  29467. className: 'edui-for-' + name,
  29468. title: editor.options.labelMap[name] ||
  29469. editor.getLang("labelMap." + name) || '',
  29470. onclick: function() {},
  29471. theme: editor.options.theme,
  29472. showText: false
  29473. });
  29474. editorui.buttons[name] = ui;
  29475. editor.addListener('ready', function() {
  29476. var b = ui.getDom('body'),
  29477. iconSpan = b.children[0];
  29478. editor.fireEvent('simpleuploadbtnready', iconSpan);
  29479. });
  29480. editor.addListener('selectionchange', function(type, causeByUi,
  29481. uiReady) {
  29482. var state = editor.queryCommandState(name);
  29483. if(state == -1) {
  29484. ui.setDisabled(true);
  29485. ui.setChecked(false);
  29486. } else {
  29487. if(!uiReady) {
  29488. ui.setDisabled(false);
  29489. ui.setChecked(state);
  29490. }
  29491. }
  29492. });
  29493. return ui;
  29494. };
  29495. })();
  29496. // adapter/editor.js
  29497. // /import core
  29498. // /commands 全屏
  29499. // /commandsName FullScreen
  29500. // /commandsTitle 全屏
  29501. (function() {
  29502. var utils = baidu.editor.utils,
  29503. uiUtils = baidu.editor.ui.uiUtils,
  29504. UIBase = baidu.editor.ui.UIBase,
  29505. domUtils = baidu.editor.dom.domUtils;
  29506. var nodeStack = [];
  29507. function EditorUI(options) {
  29508. this.initOptions(options);
  29509. this.initEditorUI();
  29510. }
  29511. EditorUI.prototype = {
  29512. uiName: 'editor',
  29513. initEditorUI: function() {
  29514. this.editor.ui = this;
  29515. this._dialogs = {};
  29516. this.initUIBase();
  29517. this._initToolbars();
  29518. var editor = this.editor,
  29519. me = this;
  29520. editor.addListener('ready', function() {
  29521. // 提供getDialog方法
  29522. editor.getDialog = function(name) {
  29523. return editor.ui._dialogs[name + "Dialog"];
  29524. };
  29525. domUtils.on(editor.window, 'scroll', function(evt) {
  29526. baidu.editor.ui.Popup.postHide(evt);
  29527. });
  29528. // 提供编辑器实时宽高(全屏时宽高不变化)
  29529. editor.ui._actualFrameWidth = editor.options.initialFrameWidth;
  29530. UE.browser.ie &&
  29531. UE.browser.version === 6 &&
  29532. editor.container.ownerDocument.execCommand(
  29533. "BackgroundImageCache", false, true);
  29534. // display bottom-bar label based on config
  29535. if(editor.options.elementPathEnabled) {
  29536. editor.ui.getDom('elementpath').innerHTML = '<div class="edui-editor-breadcrumb">' +
  29537. editor.getLang("elementPathTip") + ':</div>';
  29538. }
  29539. if(editor.options.wordCount) {
  29540. function countFn() {
  29541. setCount(editor, me);
  29542. domUtils.un(editor.document, "click",
  29543. arguments.callee);
  29544. }
  29545. domUtils.on(editor.document, "click", countFn);
  29546. editor.ui.getDom('wordcount').innerHTML = editor
  29547. .getLang("wordCountTip");
  29548. }
  29549. editor.ui._scale();
  29550. if(editor.options.scaleEnabled) {
  29551. if(editor.autoHeightEnabled) {
  29552. editor.disableAutoHeight();
  29553. }
  29554. me.enableScale();
  29555. } else {
  29556. me.disableScale();
  29557. }
  29558. if(!editor.options.elementPathEnabled &&
  29559. !editor.options.wordCount &&
  29560. !editor.options.scaleEnabled) {
  29561. editor.ui.getDom('elementpath').style.display = "none";
  29562. editor.ui.getDom('wordcount').style.display = "none";
  29563. editor.ui.getDom('scale').style.display = "none";
  29564. }
  29565. if(!editor.selection.isFocus())
  29566. return;
  29567. editor.fireEvent('selectionchange', false, true);
  29568. });
  29569. editor.addListener('mousedown', function(t, evt) {
  29570. var el = evt.target || evt.srcElement;
  29571. baidu.editor.ui.Popup.postHide(evt, el);
  29572. baidu.editor.ui.ShortCutMenu.postHide(evt);
  29573. });
  29574. editor.addListener("delcells", function() {
  29575. if(UE.ui['edittip']) {
  29576. new UE.ui['edittip'](editor);
  29577. }
  29578. editor.getDialog('edittip').open();
  29579. });
  29580. var pastePop, isPaste = false,
  29581. timer;
  29582. editor.addListener("afterpaste", function() {
  29583. if(editor.queryCommandState('pasteplain'))
  29584. return;
  29585. if(baidu.editor.ui.PastePicker) {
  29586. pastePop = new baidu.editor.ui.Popup({
  29587. content: new baidu.editor.ui.PastePicker({
  29588. editor: editor
  29589. }),
  29590. editor: editor,
  29591. className: 'edui-wordpastepop'
  29592. });
  29593. pastePop.render();
  29594. }
  29595. isPaste = true;
  29596. });
  29597. editor.addListener("afterinserthtml", function() {
  29598. clearTimeout(timer);
  29599. timer = setTimeout(function() {
  29600. if(pastePop && (isPaste || editor.ui._isTransfer)) {
  29601. if(pastePop.isHidden()) {
  29602. var span = domUtils.createElement(
  29603. editor.document, 'span', {
  29604. 'style': "line-height:0px;",
  29605. 'innerHTML': '\ufeff'
  29606. }),
  29607. range = editor.selection.getRange();
  29608. range.insertNode(span);
  29609. var tmp = getDomNode(span, 'firstChild',
  29610. 'previousSibling');
  29611. tmp
  29612. &&
  29613. pastePop
  29614. .showAnchor(tmp.nodeType == 3 ?
  29615. tmp.parentNode :
  29616. tmp);
  29617. domUtils.remove(span);
  29618. } else {
  29619. pastePop.show();
  29620. }
  29621. delete editor.ui._isTransfer;
  29622. isPaste = false;
  29623. }
  29624. }, 200)
  29625. });
  29626. editor.addListener('contextmenu', function(t, evt) {
  29627. baidu.editor.ui.Popup.postHide(evt);
  29628. });
  29629. editor.addListener('keydown', function(t, evt) {
  29630. if(pastePop)
  29631. pastePop.dispose(evt);
  29632. var keyCode = evt.keyCode || evt.which;
  29633. if(evt.altKey && keyCode == 90) {
  29634. UE.ui.buttons['fullscreen'].onclick();
  29635. }
  29636. });
  29637. editor.addListener('wordcount', function(type) {
  29638. setCount(this, me);
  29639. });
  29640. function setCount(editor, ui) {
  29641. editor.setOpt({
  29642. wordCount: true,
  29643. maximumWords: 10000,
  29644. wordCountMsg: editor.options.wordCountMsg ||
  29645. editor.getLang("wordCountMsg"),
  29646. wordOverFlowMsg: editor.options.wordOverFlowMsg ||
  29647. editor.getLang("wordOverFlowMsg")
  29648. });
  29649. var opt = editor.options,
  29650. max = opt.maximumWords,
  29651. msg = opt.wordCountMsg,
  29652. errMsg = opt.wordOverFlowMsg,
  29653. countDom = ui
  29654. .getDom('wordcount');
  29655. if(!opt.wordCount) {
  29656. return;
  29657. }
  29658. var count = editor.getContentLength(true);
  29659. if(count > max) {
  29660. countDom.innerHTML = errMsg;
  29661. editor.fireEvent("wordcountoverflow");
  29662. } else {
  29663. countDom.innerHTML = msg.replace("{#leave}",
  29664. max - count).replace("{#count}", count);
  29665. }
  29666. }
  29667. editor.addListener('selectionchange', function() {
  29668. if(editor.options.elementPathEnabled) {
  29669. me[(editor.queryCommandState('elementpath') == -1 ?
  29670. 'dis' :
  29671. 'en') +
  29672. 'ableElementPath']()
  29673. }
  29674. if(editor.options.scaleEnabled) {
  29675. me[(editor.queryCommandState('scale') == -1 ?
  29676. 'dis' :
  29677. 'en') +
  29678. 'ableScale']();
  29679. }
  29680. }); //图片popup
  29681. var popup = new baidu.editor.ui.Popup({
  29682. editor: editor,
  29683. content: '',
  29684. className: 'edui-bubble',
  29685. _onEditButtonClick: function() {
  29686. this.hide();
  29687. editor.ui._dialogs.linkDialog.open();
  29688. },
  29689. _onImgEditButtonClick: function(name) {
  29690. this.hide();
  29691. editor.ui._dialogs[name] &&
  29692. editor.ui._dialogs[name].open();
  29693. },
  29694. _onImgSetFloat: function(value) {
  29695. this.hide();
  29696. editor.execCommand("imagefloat", value);
  29697. },
  29698. _setIframeAlign: function(value) {
  29699. var frame = popup.anchorEl;
  29700. var newFrame = frame.cloneNode(true);
  29701. switch(value) {
  29702. case -2:
  29703. newFrame.setAttribute("align", "");
  29704. break;
  29705. case -1:
  29706. newFrame.setAttribute("align", "left");
  29707. break;
  29708. case 1:
  29709. newFrame.setAttribute("align", "right");
  29710. break;
  29711. }
  29712. frame.parentNode.insertBefore(newFrame, frame);
  29713. domUtils.remove(frame);
  29714. popup.anchorEl = newFrame;
  29715. popup.showAnchor(popup.anchorEl);
  29716. },
  29717. _updateIframe: function() {
  29718. var frame = editor._iframe = popup.anchorEl;
  29719. if(domUtils.hasClass(frame, 'ueditor_baidumap')) {
  29720. editor.selection.getRange().selectNode(frame)
  29721. .select();
  29722. editor.ui._dialogs.mapDialog.open();
  29723. popup.hide();
  29724. } else {
  29725. editor.ui._dialogs.insertframeDialog.open();
  29726. popup.hide();
  29727. }
  29728. },
  29729. _onRemoveButtonClick: function(cmdName) {
  29730. editor.execCommand(cmdName);
  29731. this.hide();
  29732. },
  29733. queryAutoHide: function(el) {
  29734. if(el && el.ownerDocument == editor.document) {
  29735. if(el.tagName.toLowerCase() == 'img' ||
  29736. domUtils.findParentByTagName(el, 'a',
  29737. true)) {
  29738. return el !== popup.anchorEl;
  29739. }
  29740. }
  29741. return baidu.editor.ui.Popup.prototype.queryAutoHide
  29742. .call(this, el);
  29743. }
  29744. });
  29745. popup.render();
  29746. if(editor.options.imagePopup) {
  29747. editor.addListener('mouseover', function(t, evt) {
  29748. evt = evt || window.event;
  29749. var el = evt.target || evt.srcElement;
  29750. if(editor.ui._dialogs.insertframeDialog &&
  29751. /iframe/ig.test(el.tagName)) {
  29752. var html = popup
  29753. .formatHtml('<nobr>' +
  29754. editor.getLang("property") +
  29755. ': <span onclick=$$._setIframeAlign(-2) class="edui-clickable">' +
  29756. editor.getLang("default") +
  29757. '</span>&nbsp;&nbsp;<span onclick=$$._setIframeAlign(-1) class="edui-clickable">' +
  29758. editor.getLang("justifyleft") +
  29759. '</span>&nbsp;&nbsp;<span onclick=$$._setIframeAlign(1) class="edui-clickable">' +
  29760. editor.getLang("justifyright") +
  29761. '</span>&nbsp;&nbsp;' +
  29762. ' <span onclick="$$._updateIframe( this);" class="edui-clickable">' +
  29763. editor.getLang("modify") +
  29764. '</span></nobr>');
  29765. if(html) {
  29766. popup.getDom('content').innerHTML = html;
  29767. popup.anchorEl = el;
  29768. popup.showAnchor(popup.anchorEl);
  29769. } else {
  29770. popup.hide();
  29771. }
  29772. }
  29773. });
  29774. editor.addListener('selectionchange',
  29775. function(t, causeByUi) {
  29776. if(!causeByUi)
  29777. return;
  29778. var html = '',
  29779. str = "",
  29780. img = editor.selection
  29781. .getRange().getClosedNode(),
  29782. dialogs = editor.ui._dialogs;
  29783. if(img && img.tagName == 'IMG') {
  29784. var dialogName = 'insertimageDialog';
  29785. if(img.className
  29786. .indexOf("edui-faked-video") != -1 ||
  29787. img.className
  29788. .indexOf("edui-upload-video") != -1) {
  29789. dialogName = "insertvideoDialog"
  29790. }
  29791. if(img.className
  29792. .indexOf("edui-faked-webapp") != -1) {
  29793. dialogName = "webappDialog"
  29794. }
  29795. if(img.src
  29796. .indexOf("http://api.map.baidu.com") != -1) {
  29797. dialogName = "mapDialog"
  29798. }
  29799. if(img.className
  29800. .indexOf("edui-faked-music") != -1) {
  29801. dialogName = "musicDialog"
  29802. }
  29803. if(img.src
  29804. .indexOf("http://maps.google.com/maps/api/staticmap") != -1) {
  29805. dialogName = "gmapDialog"
  29806. }
  29807. if(img.getAttribute("anchorname")) {
  29808. dialogName = "anchorDialog";
  29809. html = popup
  29810. .formatHtml('<nobr>' +
  29811. editor
  29812. .getLang("property") +
  29813. ': <span onclick=$$._onImgEditButtonClick("anchorDialog") class="edui-clickable">' +
  29814. editor
  29815. .getLang("modify") +
  29816. '</span>&nbsp;&nbsp;' +
  29817. '<span onclick=$$._onRemoveButtonClick(\'anchor\') class="edui-clickable">' +
  29818. editor
  29819. .getLang("delete") +
  29820. '</span></nobr>');
  29821. }
  29822. if(img.getAttribute("word_img")) {
  29823. // todo 放到dialog去做查询
  29824. editor.word_img = [img
  29825. .getAttribute("word_img")
  29826. ];
  29827. dialogName = "wordimageDialog"
  29828. }
  29829. if(domUtils.hasClass(img, 'loadingclass') ||
  29830. domUtils.hasClass(img,
  29831. 'loaderrorclass')) {
  29832. dialogName = "";
  29833. }
  29834. if(img.getAttribute("wdimg")){
  29835. dialogName="wdimageDialog"
  29836. }
  29837. if(!dialogs[dialogName]) {
  29838. return;
  29839. }
  29840. // str = '<nobr>' + editor.getLang("property") + ': ' +
  29841. // '<span onclick=$$._onImgSetFloat("none") class="edui-clickable">' + editor.getLang("default") + '</span>&nbsp;&nbsp;' +
  29842. // '<span onclick=$$._onImgSetFloat("left") class="edui-clickable">' + editor.getLang("justifyleft") + '</span>&nbsp;&nbsp;' +
  29843. // '<span onclick=$$._onImgSetFloat("right") class="edui-clickable">' + editor.getLang("justifyright") + '</span>&nbsp;&nbsp;' +
  29844. // '<span onclick=$$._onImgSetFloat("center") class="edui-clickable">' + editor.getLang("justifycenter") + '</span>&nbsp;&nbsp;' +
  29845. // '<span onclick="$$._onImgEditButtonClick(\'' + dialogName + '\');" class="edui-clickable">' + editor.getLang("modify") + '</span></nobr>';
  29846. // + editor.getLang("property") + ': '
  29847. str = '<nobr>' +
  29848. // ' + editor.getLang("default") + ' ,' + editor.getLang("justifyleft") + ',' + editor.getLang("justifyright") + ' ,' + editor.getLang("justifycenter") + ' , ' + editor.getLang("modify") + '
  29849. '<div class="toolbar-button icon-justifyDefault" onclick=$$._onImgSetFloat("none") class="edui-clickable" value="">顺排</div>' +
  29850. '<div class="toolbar-button icon-imageLeft" onclick=$$._onImgSetFloat("left") class="edui-clickable" value="">左环绕</div>' +
  29851. '<div class="toolbar-button icon-imageRight" onclick=$$._onImgSetFloat("right") class="edui-clickable" value="">右环绕</div>' +
  29852. '<div class="toolbar-button icon-imageCenter" onclick=$$._onImgSetFloat("center") class="edui-clickable" value="">居中</div>' +
  29853. '<div class="toolbar-button icon-change" onclick="$$._onImgEditButtonClick(\'' + dialogName + '\');" class="edui-clickable" value="">修改</div></nobr>'+
  29854. '<div class="toolbar-button icon-change" onclick="$$._onImgEditButtonClick(\'wdimageEditDialog\');" class="edui-clickable" value="">编辑部件</div></nobr>';
  29855. !html && (html = popup.formatHtml(str))
  29856. }
  29857. if(editor.ui._dialogs.linkDialog) {
  29858. var link = editor.queryCommandValue('link');
  29859. var url;
  29860. if(link &&
  29861. (url = (link
  29862. .getAttribute('_href') || link
  29863. .getAttribute('href', 2)))) {
  29864. var txt = url;
  29865. if(url.length > 30) {
  29866. txt = url.substring(0, 20) + "...";
  29867. }
  29868. if(html) {
  29869. html += '<div style="height:5px;"></div>'
  29870. }
  29871. html += popup
  29872. .formatHtml('<nobr>' +
  29873. editor
  29874. .getLang("anthorMsg") +
  29875. ': <a target="_blank" href="' +
  29876. url +
  29877. '" title="' +
  29878. url +
  29879. '" >' +
  29880. txt +
  29881. '</a>' +
  29882. ' <span class="edui-clickable" onclick="$$._onEditButtonClick();">' +
  29883. editor
  29884. .getLang("modify") +
  29885. '</span>' +
  29886. ' <span class="edui-clickable" onclick="$$._onRemoveButtonClick(\'unlink\');"> ' +
  29887. editor
  29888. .getLang("clear") +
  29889. '</span></nobr>');
  29890. popup.showAnchor(link);
  29891. }
  29892. }
  29893. if(html) {
  29894. popup.getDom('content').innerHTML = html;
  29895. popup.anchorEl = img || link;
  29896. popup.showAnchor(popup.anchorEl);
  29897. } else {
  29898. popup.hide();
  29899. }
  29900. });
  29901. }
  29902. },
  29903. _initToolbars: function() {
  29904. var editor = this.editor;
  29905. var toolbars = this.toolbars || [];
  29906. var toolbarUis = [];
  29907. for(var i = 0; i < toolbars.length; i++) {
  29908. var toolbar = toolbars[i];
  29909. var toolbarUi = new baidu.editor.ui.Toolbar({
  29910. theme: editor.options.theme
  29911. });
  29912. for(var j = 0; j < toolbar.length; j++) {
  29913. var toolbarItem = toolbar[j];
  29914. var toolbarItemUi = null;
  29915. if(typeof toolbarItem == 'string') {
  29916. toolbarItem = toolbarItem.toLowerCase();
  29917. if(toolbarItem == '|') {
  29918. toolbarItem = 'Separator';
  29919. }
  29920. if(toolbarItem == '||') {
  29921. toolbarItem = 'Breakline';
  29922. }
  29923. if(baidu.editor.ui[toolbarItem]) {
  29924. toolbarItemUi = new baidu.editor.ui[toolbarItem](editor);
  29925. }
  29926. // fullscreen这里单独处理一下,放到首行去
  29927. if(toolbarItem == 'fullscreen') {
  29928. if(toolbarUis && toolbarUis[0]) {
  29929. toolbarUis[0].items.splice(0, 0,
  29930. toolbarItemUi);
  29931. } else {
  29932. toolbarItemUi
  29933. &&
  29934. toolbarUi.items.splice(0, 0,
  29935. toolbarItemUi);
  29936. }
  29937. continue;
  29938. }
  29939. } else {
  29940. toolbarItemUi = toolbarItem;
  29941. }
  29942. if(toolbarItemUi && toolbarItemUi.id) {
  29943. toolbarUi.add(toolbarItemUi);
  29944. }
  29945. }
  29946. toolbarUis[i] = toolbarUi;
  29947. }
  29948. // 接受外部定制的UI
  29949. utils.each(UE._customizeUI, function(obj, key) {
  29950. var itemUI, index;
  29951. if(obj.id && obj.id != editor.key) {
  29952. return false;
  29953. }
  29954. itemUI = obj.execFn.call(editor, editor, key);
  29955. if(itemUI) {
  29956. index = obj.index;
  29957. if(index === undefined) {
  29958. index = toolbarUi.items.length;
  29959. }
  29960. // console.log(itemUI);
  29961. // console.log(index);
  29962. toolbarUi.add(itemUI, index)
  29963. }
  29964. });
  29965. this.toolbars = toolbarUis;
  29966. },
  29967. getHtmlTpl: function() {
  29968. /**
  29969. * 隐藏按钮区域 zmc 2017-9-18 ueditor扩展
  29970. */
  29971. return '<div id="##" class="%%" >' +
  29972. '<div id="##_toolbarbox" class="%%-toolbarbox" style="">' +
  29973. (this.toolbars.length ?
  29974. '<div id="##_toolbarboxouter" class="%%-toolbarboxouter"><div class="%%-toolbarboxinner">' +
  29975. this.renderToolbarBoxHtml() +
  29976. '</div></div>' :
  29977. '') +
  29978. '<div id="##_toolbarmsg" class="%%-toolbarmsg" style="display:none;">' +
  29979. '<div id = "##_upload_dialog" class="%%-toolbarmsg-upload" onclick="$$.showWordImageDialog();">' +
  29980. this.editor.getLang("clickToUpload") +
  29981. '</div>' +
  29982. '<div class="%%-toolbarmsg-close" onclick="$$.hideToolbarMsg();">x</div>' +
  29983. '<div id="##_toolbarmsg_label" class="%%-toolbarmsg-label"></div>' +
  29984. '<div style="height:0;overflow:hidden;clear:both;"></div>' +
  29985. '</div>' +
  29986. '<div id="##_message_holder" class="%%-messageholder"></div>' +
  29987. '</div>' +
  29988. '<div id="##_iframeholder" class="%%-iframeholder">' +
  29989. '</div>' +
  29990. // modify wdcount by matao
  29991. //隐藏字数统计--zmc--2017-9-18 ueditor扩展
  29992. '<div id="##_bottombar" class="%%-bottomContainer" style="display:none"><table><tr>' +
  29993. '<td id="##_elementpath" class="%%-bottombar"></td>' +
  29994. '<td id="##_wordcount" class="%%-wordcount"></td>' +
  29995. '<td id="##_scale" class="%%-scale"><div class="%%-icon"></div></td>' +
  29996. '</tr></table></div>' +
  29997. '<div id="##_scalelayer"></div>' +
  29998. '</div>';
  29999. },
  30000. showWordImageDialog: function() {
  30001. this._dialogs['wordimageDialog'].open();
  30002. },
  30003. renderToolbarBoxHtml: function() {
  30004. var buff = [];
  30005. for(var i = 0; i < this.toolbars.length; i++) {
  30006. buff.push(this.toolbars[i].renderHtml());
  30007. }
  30008. return buff.join('');
  30009. },
  30010. setFullScreen: function(fullscreen) {
  30011. var editor = this.editor,
  30012. container = editor.container.parentNode.parentNode;
  30013. if(this._fullscreen != fullscreen) {
  30014. this._fullscreen = fullscreen;
  30015. this.editor.fireEvent('beforefullscreenchange', fullscreen);
  30016. if(baidu.editor.browser.gecko) {
  30017. var bk = editor.selection.getRange().createBookmark();
  30018. }
  30019. if(fullscreen) {
  30020. while(container.tagName != "BODY") {
  30021. var position = baidu.editor.dom.domUtils
  30022. .getComputedStyle(container, "position");
  30023. nodeStack.push(position);
  30024. container.style.position = "static";
  30025. container = container.parentNode;
  30026. }
  30027. this._bakHtmlOverflow = document.documentElement.style.overflow;
  30028. this._bakBodyOverflow = document.body.style.overflow;
  30029. this._bakAutoHeight = this.editor.autoHeightEnabled;
  30030. this._bakScrollTop = Math.max(
  30031. document.documentElement.scrollTop,
  30032. document.body.scrollTop);
  30033. this._bakEditorContaninerWidth = editor.iframe.parentNode.offsetWidth;
  30034. if(this._bakAutoHeight) {
  30035. // 当全屏时不能执行自动长高
  30036. editor.autoHeightEnabled = false;
  30037. this.editor.disableAutoHeight();
  30038. }
  30039. document.documentElement.style.overflowX = 'hidden';
  30040. // 修复,滚动条不收起的问题
  30041. window.scrollTo(0, window.scrollY);
  30042. this._bakCssText = this.getDom().style.cssText;
  30043. this._bakCssText1 = this.getDom('iframeholder').style.cssText;
  30044. editor.iframe.parentNode.style.width = '';
  30045. this._updateFullScreen();
  30046. } else {
  30047. while(container.tagName != "BODY") {
  30048. container.style.position = nodeStack.shift();
  30049. container = container.parentNode;
  30050. }
  30051. this.getDom().style.cssText = this._bakCssText;
  30052. this.getDom('iframeholder').style.cssText = this._bakCssText1;
  30053. if(this._bakAutoHeight) {
  30054. editor.autoHeightEnabled = true;
  30055. this.editor.enableAutoHeight();
  30056. }
  30057. document.documentElement.style.overflow = this._bakHtmlOverflow;
  30058. document.body.style.overflow = this._bakBodyOverflow;
  30059. editor.iframe.parentNode.style.width = this._bakEditorContaninerWidth +
  30060. 'px';
  30061. window.scrollTo(0, this._bakScrollTop);
  30062. }
  30063. if(browser.gecko && editor.body.contentEditable === 'true') {
  30064. var input = document.createElement('input');
  30065. document.body.appendChild(input);
  30066. editor.body.contentEditable = false;
  30067. setTimeout(function() {
  30068. input.focus();
  30069. setTimeout(function() {
  30070. editor.body.contentEditable = true;
  30071. editor.fireEvent('fullscreenchanged',
  30072. fullscreen);
  30073. editor.selection.getRange().moveToBookmark(bk)
  30074. .select(true);
  30075. baidu.editor.dom.domUtils.remove(input);
  30076. fullscreen && window.scroll(0, 0);
  30077. }, 0)
  30078. }, 0)
  30079. }
  30080. if(editor.body.contentEditable === 'true') {
  30081. this.editor.fireEvent('fullscreenchanged', fullscreen);
  30082. this.triggerLayout();
  30083. }
  30084. }
  30085. },
  30086. _updateFullScreen: function() {
  30087. if(this._fullscreen) {
  30088. var vpRect = uiUtils.getViewportRect();
  30089. this.getDom().style.cssText = 'border:0;position:absolute;left:0;top:' +
  30090. (this.editor.options.topOffset || 0) +
  30091. 'px;width:' +
  30092. vpRect.width +
  30093. 'px;height:' +
  30094. vpRect.height +
  30095. 'px;z-index:' +
  30096. (this.getDom().style.zIndex * 1 + 100);
  30097. uiUtils.setViewportOffset(this.getDom(), {
  30098. left: 0,
  30099. top: this.editor.options.topOffset || 0
  30100. });
  30101. this.editor.setHeight(vpRect.height -
  30102. this.getDom('toolbarbox').offsetHeight -
  30103. this.getDom('bottombar').offsetHeight -
  30104. (this.editor.options.topOffset || 0), true);
  30105. // 不手动调一下,会导致全屏失效
  30106. if(browser.gecko) {
  30107. try {
  30108. window.onresize();
  30109. } catch(e) {
  30110. }
  30111. }
  30112. }
  30113. },
  30114. _updateElementPath: function() {
  30115. var bottom = this.getDom('elementpath'),
  30116. list;
  30117. if(this.elementPathEnabled &&
  30118. (list = this.editor.queryCommandValue('elementpath'))) {
  30119. var buff = [];
  30120. for(var i = 0, ci; ci = list[i]; i++) {
  30121. buff[i] = this
  30122. .formatHtml('<span unselectable="on" onclick="$$.editor.execCommand(&quot;elementpath&quot;, &quot;' +
  30123. i + '&quot;);">' + ci + '</span>');
  30124. }
  30125. bottom.innerHTML = '<div class="edui-editor-breadcrumb" onmousedown="return false;">' +
  30126. this.editor.getLang("elementPathTip") +
  30127. ': ' +
  30128. buff.join(' &gt; ') + '</div>';
  30129. } else {
  30130. bottom.style.display = 'none'
  30131. }
  30132. },
  30133. disableElementPath: function() {
  30134. var bottom = this.getDom('elementpath');
  30135. bottom.innerHTML = '';
  30136. bottom.style.display = 'none';
  30137. this.elementPathEnabled = false;
  30138. },
  30139. enableElementPath: function() {
  30140. var bottom = this.getDom('elementpath');
  30141. bottom.style.display = '';
  30142. this.elementPathEnabled = true;
  30143. this._updateElementPath();
  30144. },
  30145. _scale: function() {
  30146. var doc = document,
  30147. editor = this.editor,
  30148. editorHolder = editor.container,
  30149. editorDocument = editor.document,
  30150. toolbarBox = this
  30151. .getDom("toolbarbox"),
  30152. bottombar = this
  30153. .getDom("bottombar"),
  30154. scale = this.getDom("scale"),
  30155. scalelayer = this
  30156. .getDom("scalelayer");
  30157. var isMouseMove = false,
  30158. position = null,
  30159. minEditorHeight = 0,
  30160. minEditorWidth = editor.options.minFrameWidth,
  30161. pageX = 0,
  30162. pageY = 0,
  30163. scaleWidth = 0,
  30164. scaleHeight = 0;
  30165. function down() {
  30166. position = domUtils.getXY(editorHolder);
  30167. if(!minEditorHeight) {
  30168. minEditorHeight = editor.options.minFrameHeight +
  30169. toolbarBox.offsetHeight +
  30170. bottombar.offsetHeight;
  30171. }
  30172. scalelayer.style.cssText = "position:absolute;left:0;display:;top:0;background-color:#41ABFF;opacity:0.4;filter: Alpha(opacity=40);width:" +
  30173. editorHolder.offsetWidth +
  30174. "px;height:" +
  30175. editorHolder.offsetHeight +
  30176. "px;z-index:" +
  30177. (editor.options.zIndex + 1);
  30178. domUtils.on(doc, "mousemove", move);
  30179. domUtils.on(editorDocument, "mouseup", up);
  30180. domUtils.on(doc, "mouseup", up);
  30181. }
  30182. var me = this;
  30183. // by xuheng 全屏时关掉缩放
  30184. this.editor.addListener('fullscreenchanged', function(e,
  30185. fullScreen) {
  30186. if(fullScreen) {
  30187. me.disableScale();
  30188. } else {
  30189. if(me.editor.options.scaleEnabled) {
  30190. me.enableScale();
  30191. var tmpNode = me.editor.document
  30192. .createElement('span');
  30193. me.editor.body.appendChild(tmpNode);
  30194. me.editor.body.style.height = Math.max(domUtils
  30195. .getXY(tmpNode).y,
  30196. me.editor.iframe.offsetHeight - 20) +
  30197. 'px';
  30198. domUtils.remove(tmpNode)
  30199. }
  30200. }
  30201. });
  30202. function move(event) {
  30203. clearSelection();
  30204. var e = event || window.event;
  30205. pageX = e.pageX ||
  30206. (doc.documentElement.scrollLeft + e.clientX);
  30207. pageY = e.pageY ||
  30208. (doc.documentElement.scrollTop + e.clientY);
  30209. scaleWidth = pageX - position.x;
  30210. scaleHeight = pageY - position.y;
  30211. if(scaleWidth >= minEditorWidth) {
  30212. isMouseMove = true;
  30213. scalelayer.style.width = scaleWidth + 'px';
  30214. }
  30215. if(scaleHeight >= minEditorHeight) {
  30216. isMouseMove = true;
  30217. scalelayer.style.height = scaleHeight + "px";
  30218. }
  30219. }
  30220. function up() {
  30221. if(isMouseMove) {
  30222. isMouseMove = false;
  30223. editor.ui._actualFrameWidth = scalelayer.offsetWidth -
  30224. 2;
  30225. editorHolder.style.width = editor.ui._actualFrameWidth +
  30226. 'px';
  30227. editor.setHeight(scalelayer.offsetHeight -
  30228. bottombar.offsetHeight -
  30229. toolbarBox.offsetHeight - 2, true);
  30230. }
  30231. if(scalelayer) {
  30232. scalelayer.style.display = "none";
  30233. }
  30234. clearSelection();
  30235. domUtils.un(doc, "mousemove", move);
  30236. domUtils.un(editorDocument, "mouseup", up);
  30237. domUtils.un(doc, "mouseup", up);
  30238. }
  30239. function clearSelection() {
  30240. if(browser.ie)
  30241. doc.selection.clear();
  30242. else
  30243. window.getSelection().removeAllRanges();
  30244. }
  30245. this.enableScale = function() {
  30246. // trace:2868
  30247. if(editor.queryCommandState("source") == 1)
  30248. return;
  30249. scale.style.display = "";
  30250. this.scaleEnabled = true;
  30251. domUtils.on(scale, "mousedown", down);
  30252. };
  30253. this.disableScale = function() {
  30254. scale.style.display = "none";
  30255. this.scaleEnabled = false;
  30256. domUtils.un(scale, "mousedown", down);
  30257. };
  30258. },
  30259. isFullScreen: function() {
  30260. return this._fullscreen;
  30261. },
  30262. postRender: function() {
  30263. UIBase.prototype.postRender.call(this);
  30264. for(var i = 0; i < this.toolbars.length; i++) {
  30265. this.toolbars[i].postRender();
  30266. }
  30267. var me = this;
  30268. var timerId, domUtils = baidu.editor.dom.domUtils,
  30269. updateFullScreenTime = function() {
  30270. clearTimeout(timerId);
  30271. timerId = setTimeout(function() {
  30272. me._updateFullScreen();
  30273. });
  30274. };
  30275. domUtils.on(window, 'resize', updateFullScreenTime);
  30276. me.addListener('destroy', function() {
  30277. domUtils.un(window, 'resize', updateFullScreenTime);
  30278. clearTimeout(timerId);
  30279. })
  30280. },
  30281. showToolbarMsg: function(msg, flag) {
  30282. this.getDom('toolbarmsg_label').innerHTML = msg;
  30283. this.getDom('toolbarmsg').style.display = '';
  30284. //
  30285. if(!flag) {
  30286. var w = this.getDom('upload_dialog');
  30287. w.style.display = 'none';
  30288. }
  30289. },
  30290. hideToolbarMsg: function() {
  30291. this.getDom('toolbarmsg').style.display = 'none';
  30292. },
  30293. mapUrl: function(url) {
  30294. return url ? url.replace('~/',
  30295. this.editor.options.UEDITOR_HOME_URL || '') : ''
  30296. },
  30297. triggerLayout: function() {
  30298. var dom = this.getDom();
  30299. if(dom.style.zoom == '1') {
  30300. dom.style.zoom = '100%';
  30301. } else {
  30302. dom.style.zoom = '1';
  30303. }
  30304. }
  30305. };
  30306. utils.inherits(EditorUI, baidu.editor.ui.UIBase);
  30307. var instances = {};
  30308. UE.ui.Editor = function(options) {
  30309. var editor = new UE.Editor(options);
  30310. editor.options.editor = editor;
  30311. utils.loadFile(document, {
  30312. href: editor.options.themePath + editor.options.theme +
  30313. "/css/ueditor.css",
  30314. tag: "link",
  30315. type: "text/css",
  30316. rel: "stylesheet"
  30317. });
  30318. var oldRender = editor.render;
  30319. editor.render = function(holder) {
  30320. if(holder.constructor === String) {
  30321. editor.key = holder;
  30322. instances[holder] = editor;
  30323. }
  30324. utils.domReady(function() {
  30325. editor.langIsReady ? renderUI() : editor.addListener(
  30326. "langReady", renderUI);
  30327. function renderUI() {
  30328. editor.setOpt({
  30329. labelMap: editor.options.labelMap ||
  30330. editor.getLang('labelMap')
  30331. });
  30332. new EditorUI(editor.options);
  30333. if(holder) {
  30334. if(holder.constructor === String) {
  30335. holder = document.getElementById(holder);
  30336. }
  30337. holder
  30338. &&
  30339. holder.getAttribute('name') &&
  30340. (editor.options.textarea = holder
  30341. .getAttribute('name'));
  30342. if(holder &&
  30343. /script|textarea/ig.test(holder.tagName)) {
  30344. var newDiv = document.createElement('div');
  30345. holder.parentNode.insertBefore(newDiv, holder);
  30346. var cont = holder.value || holder.innerHTML;
  30347. editor.options.initialContent = /^[\t\r\n ]*$/
  30348. .test(cont) ?
  30349. editor.options.initialContent :
  30350. cont.replace(/>[\n\r\t]+([ ]{4})+/g,
  30351. '>').replace(
  30352. /[\n\r\t]+([ ]{4})+</g, '<')
  30353. .replace(/>[\n\r\t]+</g, '><');
  30354. holder.className &&
  30355. (newDiv.className = holder.className);
  30356. holder.style.cssText &&
  30357. (newDiv.style.cssText = holder.style.cssText);
  30358. if(/textarea/i.test(holder.tagName)) {
  30359. editor.textarea = holder;
  30360. editor.textarea.style.display = 'none';
  30361. } else {
  30362. holder.parentNode.removeChild(holder);
  30363. }
  30364. if(holder.id) {
  30365. newDiv.id = holder.id;
  30366. domUtils.removeAttributes(holder, 'id');
  30367. }
  30368. holder = newDiv;
  30369. holder.innerHTML = '';
  30370. }
  30371. }
  30372. domUtils.addClass(holder, "edui-" +
  30373. editor.options.theme);
  30374. /// 增加。Lin
  30375. // domUtils.addData("data-ss-nr-obj-name", "${ssObjName}");
  30376. // data-ss-nr-obj-id="${ssObjId}")
  30377. ///
  30378. editor.ui.render(holder);
  30379. var opt = editor.options;
  30380. // 给实例添加一个编辑器的容器引用
  30381. editor.container = editor.ui.getDom();
  30382. var parents = domUtils.findParents(holder, true);
  30383. var displays = [];
  30384. for(var i = 0, ci; ci = parents[i]; i++) {
  30385. displays[i] = ci.style.display;
  30386. ci.style.display = 'block'
  30387. }
  30388. if(opt.initialFrameWidth) {
  30389. opt.minFrameWidth = opt.initialFrameWidth;
  30390. } else {
  30391. opt.minFrameWidth = opt.initialFrameWidth = holder.offsetWidth;
  30392. var styleWidth = holder.style.width;
  30393. if(/%$/.test(styleWidth)) {
  30394. opt.initialFrameWidth = styleWidth;
  30395. }
  30396. }
  30397. if(opt.initialFrameHeight) {
  30398. opt.minFrameHeight = opt.initialFrameHeight;
  30399. } else {
  30400. var h=holder.offsetHeight;
  30401. h = h <= 100 ? 170 : h;
  30402. opt.initialFrameHeight = opt.minFrameHeight = h;
  30403. }
  30404. for(var i = 0, ci; ci = parents[i]; i++) {
  30405. ci.style.display = displays[i]
  30406. }
  30407. // 编辑器最外容器设置了高度,会导致,编辑器不占位
  30408. // todo 先去掉,没有找到原因
  30409. if(holder.style.height) {
  30410. holder.style.height = ''
  30411. }
  30412. editor.container.style.width = opt.initialFrameWidth +
  30413. (/%$/.test(opt.initialFrameWidth) ? '' : 'px');
  30414. editor.container.style.zIndex = opt.zIndex;
  30415. //外围边框线去掉
  30416. editor.container.style.border = "none";
  30417. oldRender
  30418. .call(editor, editor.ui.getDom('iframeholder'));
  30419. editor.fireEvent("afteruiready");
  30420. }
  30421. })
  30422. };
  30423. return editor;
  30424. };
  30425. /**
  30426. * @file
  30427. * @name UE
  30428. * @short UE
  30429. * @desc UEditor的顶部命名空间
  30430. */
  30431. /**
  30432. * @name getEditor
  30433. * @since 1.2.4+
  30434. * @grammar UE.getEditor(id,[opt]) => Editor实例
  30435. * @desc 提供一个全局的方法得到编辑器实例 * ''id'' 放置编辑器的容器id, 如果容器下的编辑器已经存在,就直接返回 *
  30436. * ''opt'' 编辑器的可选参数
  30437. * @example UE.getEditor('containerId',{onready:function(){//创建一个编辑器实例
  30438. * this.setContent('hello') }}); UE.getEditor('containerId');
  30439. * //返回刚创建的实例
  30440. *
  30441. */
  30442. UE.getEditor = function(id, opt) {
  30443. // console.log(instances);
  30444. var editor = instances[id];
  30445. if(!editor) {
  30446. editor = instances[id] = new UE.ui.Editor(opt);
  30447. editor.render(id);
  30448. }
  30449. return editor;
  30450. };
  30451. UE.delEditor = function(id) {
  30452. var editor;
  30453. if(editor = instances[id]) {
  30454. editor.key && editor.destroy();
  30455. delete instances[id]
  30456. }
  30457. };
  30458. UE.registerUI = function(uiName, fn, index, editorId) {
  30459. utils.each(uiName.split(/\s+/), function(name) {
  30460. UE._customizeUI[name] = {
  30461. id: editorId,
  30462. execFn: fn,
  30463. index: index
  30464. };
  30465. })
  30466. }
  30467. })();
  30468. // adapter/message.js
  30469. UE.registerUI('message', function(editor) {
  30470. var editorui = baidu.editor.ui;
  30471. var Message = editorui.Message;
  30472. var holder;
  30473. var _messageItems = [];
  30474. var me = editor;
  30475. me.addListener('ready', function() {
  30476. holder = document.getElementById(me.ui.id + '_message_holder');
  30477. updateHolderPos();
  30478. setTimeout(function() {
  30479. updateHolderPos();
  30480. }, 500);
  30481. });
  30482. me.addListener('showmessage', function(type, opt) {
  30483. opt = utils.isString(opt) ? {
  30484. 'content': opt
  30485. } : opt;
  30486. var message = new Message({
  30487. 'timeout': opt.timeout,
  30488. 'type': opt.type,
  30489. 'content': opt.content,
  30490. 'keepshow': opt.keepshow,
  30491. 'editor': me
  30492. }),
  30493. mid = opt.id || ('msg_' + (+new Date()).toString(36));
  30494. message.render(holder);
  30495. _messageItems[mid] = message;
  30496. message.reset(opt);
  30497. updateHolderPos();
  30498. return mid;
  30499. });
  30500. me.addListener('updatemessage', function(type, id, opt) {
  30501. opt = utils.isString(opt) ? {
  30502. 'content': opt
  30503. } : opt;
  30504. var message = _messageItems[id];
  30505. message.render(holder);
  30506. message && message.reset(opt);
  30507. });
  30508. me.addListener('hidemessage', function(type, id) {
  30509. var message = _messageItems[id];
  30510. message && message.hide();
  30511. });
  30512. function updateHolderPos() {
  30513. var toolbarbox = me.ui.getDom('toolbarbox');
  30514. if(toolbarbox) {
  30515. holder.style.top = toolbarbox.offsetHeight + 3 + 'px';
  30516. }
  30517. holder.style.zIndex = Math.max(me.options.zIndex,
  30518. me.iframe.style.zIndex) +
  30519. 1;
  30520. }
  30521. });
  30522. // adapter/autosave.js
  30523. UE.registerUI('autosave', function(editor) {
  30524. var timer = null,
  30525. uid = null;
  30526. editor.on('afterautosave', function() {
  30527. clearTimeout(timer);
  30528. timer = setTimeout(function() {
  30529. if(uid) {
  30530. editor.trigger('hidemessage', uid);
  30531. }
  30532. uid = editor.trigger('showmessage', {
  30533. content: editor.getLang('autosave.success'),
  30534. timeout: 2000
  30535. });
  30536. }, 2000)
  30537. })
  30538. });
  30539. })();