ueditor.all.js 1.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445
  1. /*!
  2. * UEditor
  3. * version: ueditor
  4. * build: Tue Aug 25 2015 15:23:01 GMT+0800 (CST)
  5. */
  6. (function(){
  7. // editor.js
  8. UEDITOR_CONFIG = window.UEDITOR_CONFIG || {};
  9. var baidu = window.baidu || {};
  10. window.baidu = baidu;
  11. window.UE = baidu.editor = window.UE || {};
  12. UE.plugins = {};
  13. UE.commands = {};
  14. UE.instants = {};
  15. UE.I18N = {};
  16. UE._customizeUI = {};
  17. UE.version = "1.4.3";
  18. var dom = UE.dom = {};
  19. // core/browser.js
  20. /**
  21. * 浏览器判断模块
  22. * @file
  23. * @module UE.browser
  24. * @since 1.2.6.1
  25. */
  26. /**
  27. * 提供浏览器检测的模块
  28. * @unfile
  29. * @module UE.browser
  30. */
  31. var browser = UE.browser = function(){
  32. var agent = navigator.userAgent.toLowerCase(),
  33. opera = window.opera,
  34. browser = {
  35. /**
  36. * @property {boolean} ie 检测当前浏览器是否为IE
  37. * @example
  38. * ```javascript
  39. * if ( UE.browser.ie ) {
  40. * console.log( '当前浏览器是IE' );
  41. * }
  42. * ```
  43. */
  44. ie : /(msie\s|trident.*rv:)([\w.]+)/.test(agent),
  45. /**
  46. * @property {boolean} opera 检测当前浏览器是否为Opera
  47. * @example
  48. * ```javascript
  49. * if ( UE.browser.opera ) {
  50. * console.log( '当前浏览器是Opera' );
  51. * }
  52. * ```
  53. */
  54. opera : ( !!opera && opera.version ),
  55. /**
  56. * @property {boolean} webkit 检测当前浏览器是否是webkit内核的浏览器
  57. * @example
  58. * ```javascript
  59. * if ( UE.browser.webkit ) {
  60. * console.log( '当前浏览器是webkit内核浏览器' );
  61. * }
  62. * ```
  63. */
  64. webkit : ( agent.indexOf( ' applewebkit/' ) > -1 ),
  65. /**
  66. * @property {boolean} mac 检测当前浏览器是否是运行在mac平台下
  67. * @example
  68. * ```javascript
  69. * if ( UE.browser.mac ) {
  70. * console.log( '当前浏览器运行在mac平台下' );
  71. * }
  72. * ```
  73. */
  74. mac : ( agent.indexOf( 'macintosh' ) > -1 ),
  75. /**
  76. * @property {boolean} quirks 检测当前浏览器是否处于“怪异模式”下
  77. * @example
  78. * ```javascript
  79. * if ( UE.browser.quirks ) {
  80. * console.log( '当前浏览器运行处于“怪异模式”' );
  81. * }
  82. * ```
  83. */
  84. quirks : ( document.compatMode == 'BackCompat' )
  85. };
  86. /**
  87. * @property {boolean} gecko 检测当前浏览器内核是否是gecko内核
  88. * @example
  89. * ```javascript
  90. * if ( UE.browser.gecko ) {
  91. * console.log( '当前浏览器内核是gecko内核' );
  92. * }
  93. * ```
  94. */
  95. browser.gecko =( navigator.product == 'Gecko' && !browser.webkit && !browser.opera && !browser.ie);
  96. var version = 0;
  97. // Internet Explorer 6.0+
  98. if ( browser.ie ){
  99. var v1 = agent.match(/(?:msie\s([\w.]+))/);
  100. var v2 = agent.match(/(?:trident.*rv:([\w.]+))/);
  101. if(v1 && v2 && v1[1] && v2[1]){
  102. version = Math.max(v1[1]*1,v2[1]*1);
  103. }else if(v1 && v1[1]){
  104. version = v1[1]*1;
  105. }else if(v2 && v2[1]){
  106. version = v2[1]*1;
  107. }else{
  108. version = 0;
  109. }
  110. browser.ie11Compat = document.documentMode == 11;
  111. /**
  112. * @property { boolean } ie9Compat 检测浏览器模式是否为 IE9 兼容模式
  113. * @warning 如果浏览器不是IE, 则该值为undefined
  114. * @example
  115. * ```javascript
  116. * if ( UE.browser.ie9Compat ) {
  117. * console.log( '当前浏览器运行在IE9兼容模式下' );
  118. * }
  119. * ```
  120. */
  121. browser.ie9Compat = document.documentMode == 9;
  122. /**
  123. * @property { boolean } ie8 检测浏览器是否是IE8浏览器
  124. * @warning 如果浏览器不是IE, 则该值为undefined
  125. * @example
  126. * ```javascript
  127. * if ( UE.browser.ie8 ) {
  128. * console.log( '当前浏览器是IE8浏览器' );
  129. * }
  130. * ```
  131. */
  132. browser.ie8 = !!document.documentMode;
  133. /**
  134. * @property { boolean } ie8Compat 检测浏览器模式是否为 IE8 兼容模式
  135. * @warning 如果浏览器不是IE, 则该值为undefined
  136. * @example
  137. * ```javascript
  138. * if ( UE.browser.ie8Compat ) {
  139. * console.log( '当前浏览器运行在IE8兼容模式下' );
  140. * }
  141. * ```
  142. */
  143. browser.ie8Compat = document.documentMode == 8;
  144. /**
  145. * @property { boolean } ie7Compat 检测浏览器模式是否为 IE7 兼容模式
  146. * @warning 如果浏览器不是IE, 则该值为undefined
  147. * @example
  148. * ```javascript
  149. * if ( UE.browser.ie7Compat ) {
  150. * console.log( '当前浏览器运行在IE7兼容模式下' );
  151. * }
  152. * ```
  153. */
  154. browser.ie7Compat = ( ( version == 7 && !document.documentMode )
  155. || document.documentMode == 7 );
  156. /**
  157. * @property { boolean } ie6Compat 检测浏览器模式是否为 IE6 模式 或者怪异模式
  158. * @warning 如果浏览器不是IE, 则该值为undefined
  159. * @example
  160. * ```javascript
  161. * if ( UE.browser.ie6Compat ) {
  162. * console.log( '当前浏览器运行在IE6模式或者怪异模式下' );
  163. * }
  164. * ```
  165. */
  166. browser.ie6Compat = ( version < 7 || browser.quirks );
  167. browser.ie9above = version > 8;
  168. browser.ie9below = version < 9;
  169. browser.ie11above = version > 10;
  170. browser.ie11below = version < 11;
  171. }
  172. // Gecko.
  173. if ( browser.gecko ){
  174. var geckoRelease = agent.match( /rv:([\d\.]+)/ );
  175. if ( geckoRelease )
  176. {
  177. geckoRelease = geckoRelease[1].split( '.' );
  178. version = geckoRelease[0] * 10000 + ( geckoRelease[1] || 0 ) * 100 + ( geckoRelease[2] || 0 ) * 1;
  179. }
  180. }
  181. /**
  182. * @property { Number } chrome 检测当前浏览器是否为Chrome, 如果是,则返回Chrome的大版本号
  183. * @warning 如果浏览器不是chrome, 则该值为undefined
  184. * @example
  185. * ```javascript
  186. * if ( UE.browser.chrome ) {
  187. * console.log( '当前浏览器是Chrome' );
  188. * }
  189. * ```
  190. */
  191. if (/chrome\/(\d+\.\d)/i.test(agent)) {
  192. browser.chrome = + RegExp['\x241'];
  193. }
  194. /**
  195. * @property { Number } safari 检测当前浏览器是否为Safari, 如果是,则返回Safari的大版本号
  196. * @warning 如果浏览器不是safari, 则该值为undefined
  197. * @example
  198. * ```javascript
  199. * if ( UE.browser.safari ) {
  200. * console.log( '当前浏览器是Safari' );
  201. * }
  202. * ```
  203. */
  204. if(/(\d+\.\d)?(?:\.\d)?\s+safari\/?(\d+\.\d+)?/i.test(agent) && !/chrome/i.test(agent)){
  205. browser.safari = + (RegExp['\x241'] || RegExp['\x242']);
  206. }
  207. // Opera 9.50+
  208. if ( browser.opera )
  209. version = parseFloat( opera.version() );
  210. // WebKit 522+ (Safari 3+)
  211. if ( browser.webkit )
  212. version = parseFloat( agent.match( / applewebkit\/(\d+)/ )[1] );
  213. /**
  214. * @property { Number } version 检测当前浏览器版本号
  215. * @remind
  216. * <ul>
  217. * <li>IE系列返回值为5,6,7,8,9,10等</li>
  218. * <li>gecko系列会返回10900,158900等</li>
  219. * <li>webkit系列会返回其build号 (如 522等)</li>
  220. * </ul>
  221. * @example
  222. * ```javascript
  223. * console.log( '当前浏览器版本号是: ' + UE.browser.version );
  224. * ```
  225. */
  226. browser.version = version;
  227. /**
  228. * @property { boolean } isCompatible 检测当前浏览器是否能够与UEditor良好兼容
  229. * @example
  230. * ```javascript
  231. * if ( UE.browser.isCompatible ) {
  232. * console.log( '浏览器与UEditor能够良好兼容' );
  233. * }
  234. * ```
  235. */
  236. browser.isCompatible =
  237. !browser.mobile && (
  238. ( browser.ie && version >= 6 ) ||
  239. ( browser.gecko && version >= 10801 ) ||
  240. ( browser.opera && version >= 9.5 ) ||
  241. ( browser.air && version >= 1 ) ||
  242. ( browser.webkit && version >= 522 ) ||
  243. false );
  244. return browser;
  245. }();
  246. //快捷方式
  247. var ie = browser.ie,
  248. webkit = browser.webkit,
  249. gecko = browser.gecko,
  250. opera = browser.opera;
  251. // core/utils.js
  252. /**
  253. * 工具函数包
  254. * @file
  255. * @module UE.utils
  256. * @since 1.2.6.1
  257. */
  258. /**
  259. * UEditor封装使用的静态工具函数
  260. * @module UE.utils
  261. * @unfile
  262. */
  263. var utils = UE.utils = {
  264. /**
  265. * 用给定的迭代器遍历对象
  266. * @method each
  267. * @param { Object } obj 需要遍历的对象
  268. * @param { Function } iterator 迭代器, 该方法接受两个参数, 第一个参数是当前所处理的value, 第二个参数是当前遍历对象的key
  269. * @example
  270. * ```javascript
  271. * var demoObj = {
  272. * key1: 1,
  273. * key2: 2
  274. * };
  275. *
  276. * //output: key1: 1, key2: 2
  277. * UE.utils.each( demoObj, funciton ( value, key ) {
  278. *
  279. * console.log( key + ":" + value );
  280. *
  281. * } );
  282. * ```
  283. */
  284. /**
  285. * 用给定的迭代器遍历数组或类数组对象
  286. * @method each
  287. * @param { Array } array 需要遍历的数组或者类数组
  288. * @param { Function } iterator 迭代器, 该方法接受两个参数, 第一个参数是当前所处理的value, 第二个参数是当前遍历对象的key
  289. * @example
  290. * ```javascript
  291. * var divs = document.getElmentByTagNames( "div" );
  292. *
  293. * //output: 0: DIV, 1: DIV ...
  294. * UE.utils.each( divs, funciton ( value, key ) {
  295. *
  296. * console.log( key + ":" + value.tagName );
  297. *
  298. * } );
  299. * ```
  300. */
  301. each : function(obj, iterator, context) {
  302. if (obj == null) return;
  303. if (obj.length === +obj.length) {
  304. for (var i = 0, l = obj.length; i < l; i++) {
  305. if(iterator.call(context, obj[i], i, obj) === false)
  306. return false;
  307. }
  308. } else {
  309. for (var key in obj) {
  310. if (obj.hasOwnProperty(key)) {
  311. if(iterator.call(context, obj[key], key, obj) === false)
  312. return false;
  313. }
  314. }
  315. }
  316. },
  317. /**
  318. * 以给定对象作为原型创建一个新对象
  319. * @method makeInstance
  320. * @param { Object } protoObject 该对象将作为新创建对象的原型
  321. * @return { Object } 新的对象, 该对象的原型是给定的protoObject对象
  322. * @example
  323. * ```javascript
  324. *
  325. * var protoObject = { sayHello: function () { console.log('Hello UEditor!'); } };
  326. *
  327. * var newObject = UE.utils.makeInstance( protoObject );
  328. * //output: Hello UEditor!
  329. * newObject.sayHello();
  330. * ```
  331. */
  332. makeInstance:function (obj) {
  333. var noop = new Function();
  334. noop.prototype = obj;
  335. obj = new noop;
  336. noop.prototype = null;
  337. return obj;
  338. },
  339. /**
  340. * 将source对象中的属性扩展到target对象上
  341. * @method extend
  342. * @remind 该方法将强制把source对象上的属性复制到target对象上
  343. * @see UE.utils.extend(Object,Object,Boolean)
  344. * @param { Object } target 目标对象, 新的属性将附加到该对象上
  345. * @param { Object } source 源对象, 该对象的属性会被附加到target对象上
  346. * @return { Object } 返回target对象
  347. * @example
  348. * ```javascript
  349. *
  350. * var target = { name: 'target', sex: 1 },
  351. * source = { name: 'source', age: 17 };
  352. *
  353. * UE.utils.extend( target, source );
  354. *
  355. * //output: { name: 'source', sex: 1, age: 17 }
  356. * console.log( target );
  357. *
  358. * ```
  359. */
  360. /**
  361. * 将source对象中的属性扩展到target对象上, 根据指定的isKeepTarget值决定是否保留目标对象中与
  362. * 源对象属性名相同的属性值。
  363. * @method extend
  364. * @param { Object } target 目标对象, 新的属性将附加到该对象上
  365. * @param { Object } source 源对象, 该对象的属性会被附加到target对象上
  366. * @param { Boolean } isKeepTarget 是否保留目标对象中与源对象中属性名相同的属性
  367. * @return { Object } 返回target对象
  368. * @example
  369. * ```javascript
  370. *
  371. * var target = { name: 'target', sex: 1 },
  372. * source = { name: 'source', age: 17 };
  373. *
  374. * UE.utils.extend( target, source, true );
  375. *
  376. * //output: { name: 'target', sex: 1, age: 17 }
  377. * console.log( target );
  378. *
  379. * ```
  380. */
  381. extend:function (t, s, b) {
  382. if (s) {
  383. for (var k in s) {
  384. if (!b || !t.hasOwnProperty(k)) {
  385. t[k] = s[k];
  386. }
  387. }
  388. }
  389. return t;
  390. },
  391. /**
  392. * 将给定的多个对象的属性复制到目标对象target上
  393. * @method extend2
  394. * @remind 该方法将强制把源对象上的属性复制到target对象上
  395. * @remind 该方法支持两个及以上的参数, 从第二个参数开始, 其属性都会被复制到第一个参数上。 如果遇到同名的属性,
  396. * 将会覆盖掉之前的值。
  397. * @param { Object } target 目标对象, 新的属性将附加到该对象上
  398. * @param { Object... } source 源对象, 支持多个对象, 该对象的属性会被附加到target对象上
  399. * @return { Object } 返回target对象
  400. * @example
  401. * ```javascript
  402. *
  403. * var target = {},
  404. * source1 = { name: 'source', age: 17 },
  405. * source2 = { title: 'dev' };
  406. *
  407. * UE.utils.extend2( target, source1, source2 );
  408. *
  409. * //output: { name: 'source', age: 17, title: 'dev' }
  410. * console.log( target );
  411. *
  412. * ```
  413. */
  414. extend2:function (t) {
  415. var a = arguments;
  416. for (var i = 1; i < a.length; i++) {
  417. var x = a[i];
  418. for (var k in x) {
  419. if (!t.hasOwnProperty(k)) {
  420. t[k] = x[k];
  421. }
  422. }
  423. }
  424. return t;
  425. },
  426. /**
  427. * 模拟继承机制, 使得subClass继承自superClass
  428. * @method inherits
  429. * @param { Object } subClass 子类对象
  430. * @param { Object } superClass 超类对象
  431. * @warning 该方法只能让subClass继承超类的原型, subClass对象自身的属性和方法不会被继承
  432. * @return { Object } 继承superClass后的子类对象
  433. * @example
  434. * ```javascript
  435. * function SuperClass(){
  436. * this.name = "小李";
  437. * }
  438. *
  439. * SuperClass.prototype = {
  440. * hello:function(str){
  441. * console.log(this.name + str);
  442. * }
  443. * }
  444. *
  445. * function SubClass(){
  446. * this.name = "小张";
  447. * }
  448. *
  449. * UE.utils.inherits(SubClass,SuperClass);
  450. *
  451. * var sub = new SubClass();
  452. * //output: '小张早上好!
  453. * sub.hello("早上好!");
  454. * ```
  455. */
  456. inherits:function (subClass, superClass) {
  457. var oldP = subClass.prototype,
  458. newP = utils.makeInstance(superClass.prototype);
  459. utils.extend(newP, oldP, true);
  460. subClass.prototype = newP;
  461. return (newP.constructor = subClass);
  462. },
  463. /**
  464. * 用指定的context对象作为函数fn的上下文
  465. * @method bind
  466. * @param { Function } fn 需要绑定上下文的函数对象
  467. * @param { Object } content 函数fn新的上下文对象
  468. * @return { Function } 一个新的函数, 该函数作为原始函数fn的代理, 将完成fn的上下文调换工作。
  469. * @example
  470. * ```javascript
  471. *
  472. * var name = 'window',
  473. * newTest = null;
  474. *
  475. * function test () {
  476. * console.log( this.name );
  477. * }
  478. *
  479. * newTest = UE.utils.bind( test, { name: 'object' } );
  480. *
  481. * //output: object
  482. * newTest();
  483. *
  484. * //output: window
  485. * test();
  486. *
  487. * ```
  488. */
  489. bind:function (fn, context) {
  490. return function () {
  491. return fn.apply(context, arguments);
  492. };
  493. },
  494. /**
  495. * 创建延迟指定时间后执行的函数fn
  496. * @method defer
  497. * @param { Function } fn 需要延迟执行的函数对象
  498. * @param { int } delay 延迟的时间, 单位是毫秒
  499. * @warning 该方法的时间控制是不精确的,仅仅只能保证函数的执行是在给定的时间之后,
  500. * 而不能保证刚好到达延迟时间时执行。
  501. * @return { Function } 目标函数fn的代理函数, 只有执行该函数才能起到延时效果
  502. * @example
  503. * ```javascript
  504. * var start = 0;
  505. *
  506. * function test(){
  507. * console.log( new Date() - start );
  508. * }
  509. *
  510. * var testDefer = UE.utils.defer( test, 1000 );
  511. * //
  512. * start = new Date();
  513. * //output: (大约在1000毫秒之后输出) 1000
  514. * testDefer();
  515. * ```
  516. */
  517. /**
  518. * 创建延迟指定时间后执行的函数fn, 如果在延迟时间内再次执行该方法, 将会根据指定的exclusion的值,
  519. * 决定是否取消前一次函数的执行, 如果exclusion的值为true, 则取消执行,反之,将继续执行前一个方法。
  520. * @method defer
  521. * @param { Function } fn 需要延迟执行的函数对象
  522. * @param { int } delay 延迟的时间, 单位是毫秒
  523. * @param { Boolean } exclusion 如果在延迟时间内再次执行该函数,该值将决定是否取消执行前一次函数的执行,
  524. * 值为true表示取消执行, 反之则将在执行前一次函数之后才执行本次函数调用。
  525. * @warning 该方法的时间控制是不精确的,仅仅只能保证函数的执行是在给定的时间之后,
  526. * 而不能保证刚好到达延迟时间时执行。
  527. * @return { Function } 目标函数fn的代理函数, 只有执行该函数才能起到延时效果
  528. * @example
  529. * ```javascript
  530. *
  531. * function test(){
  532. * console.log(1);
  533. * }
  534. *
  535. * var testDefer = UE.utils.defer( test, 1000, true );
  536. *
  537. * //output: (两次调用仅有一次输出) 1
  538. * testDefer();
  539. * testDefer();
  540. * ```
  541. */
  542. defer:function (fn, delay, exclusion) {
  543. var timerID;
  544. return function () {
  545. if (exclusion) {
  546. clearTimeout(timerID);
  547. }
  548. timerID = setTimeout(fn, delay);
  549. };
  550. },
  551. /**
  552. * 获取元素item在数组array中首次出现的位置, 如果未找到item, 则返回-1
  553. * @method indexOf
  554. * @remind 该方法的匹配过程使用的是恒等“===”
  555. * @param { Array } array 需要查找的数组对象
  556. * @param { * } item 需要在目标数组中查找的值
  557. * @return { int } 返回item在目标数组array中首次出现的位置, 如果在数组中未找到item, 则返回-1
  558. * @example
  559. * ```javascript
  560. * var item = 1,
  561. * arr = [ 3, 4, 6, 8, 1, 1, 2 ];
  562. *
  563. * //output: 4
  564. * console.log( UE.utils.indexOf( arr, item ) );
  565. * ```
  566. */
  567. /**
  568. * 获取元素item数组array中首次出现的位置, 如果未找到item, 则返回-1。通过start的值可以指定搜索的起始位置。
  569. * @method indexOf
  570. * @remind 该方法的匹配过程使用的是恒等“===”
  571. * @param { Array } array 需要查找的数组对象
  572. * @param { * } item 需要在目标数组中查找的值
  573. * @param { int } start 搜索的起始位置
  574. * @return { int } 返回item在目标数组array中的start位置之后首次出现的位置, 如果在数组中未找到item, 则返回-1
  575. * @example
  576. * ```javascript
  577. * var item = 1,
  578. * arr = [ 3, 4, 6, 8, 1, 2, 8, 3, 2, 1, 1, 4 ];
  579. *
  580. * //output: 9
  581. * console.log( UE.utils.indexOf( arr, item, 5 ) );
  582. * ```
  583. */
  584. indexOf:function (array, item, start) {
  585. var index = -1;
  586. start = this.isNumber(start) ? start : 0;
  587. this.each(array, function (v, i) {
  588. if (i >= start && v === item) {
  589. index = i;
  590. return false;
  591. }
  592. });
  593. return index;
  594. },
  595. /**
  596. * 移除数组array中所有的元素item
  597. * @method removeItem
  598. * @param { Array } array 要移除元素的目标数组
  599. * @param { * } item 将要被移除的元素
  600. * @remind 该方法的匹配过程使用的是恒等“===”
  601. * @example
  602. * ```javascript
  603. * var arr = [ 4, 5, 7, 1, 3, 4, 6 ];
  604. *
  605. * UE.utils.removeItem( arr, 4 );
  606. * //output: [ 5, 7, 1, 3, 6 ]
  607. * console.log( arr );
  608. *
  609. * ```
  610. */
  611. removeItem:function (array, item) {
  612. for (var i = 0, l = array.length; i < l; i++) {
  613. if (array[i] === item) {
  614. array.splice(i, 1);
  615. i--;
  616. }
  617. }
  618. },
  619. /**
  620. * 删除字符串str的首尾空格
  621. * @method trim
  622. * @param { String } str 需要删除首尾空格的字符串
  623. * @return { String } 删除了首尾的空格后的字符串
  624. * @example
  625. * ```javascript
  626. *
  627. * var str = " UEdtior ";
  628. *
  629. * //output: 9
  630. * console.log( str.length );
  631. *
  632. * //output: 7
  633. * console.log( UE.utils.trim( " UEdtior " ).length );
  634. *
  635. * //output: 9
  636. * console.log( str.length );
  637. *
  638. * ```
  639. */
  640. trim:function (str) {
  641. return str.replace(/(^[ \t\n\r]+)|([ \t\n\r]+$)/g, '');
  642. },
  643. /**
  644. * 将字符串str以','分隔成数组后,将该数组转换成哈希对象, 其生成的hash对象的key为数组中的元素, value为1
  645. * @method listToMap
  646. * @warning 该方法在生成的hash对象中,会为每一个key同时生成一个另一个全大写的key。
  647. * @param { String } str 该字符串将被以','分割为数组, 然后进行转化
  648. * @return { Object } 转化之后的hash对象
  649. * @example
  650. * ```javascript
  651. *
  652. * //output: Object {UEdtior: 1, UEDTIOR: 1, Hello: 1, HELLO: 1}
  653. * console.log( UE.utils.listToMap( 'UEdtior,Hello' ) );
  654. *
  655. * ```
  656. */
  657. /**
  658. * 将字符串数组转换成哈希对象, 其生成的hash对象的key为数组中的元素, value为1
  659. * @method listToMap
  660. * @warning 该方法在生成的hash对象中,会为每一个key同时生成一个另一个全大写的key。
  661. * @param { Array } arr 字符串数组
  662. * @return { Object } 转化之后的hash对象
  663. * @example
  664. * ```javascript
  665. *
  666. * //output: Object {UEdtior: 1, UEDTIOR: 1, Hello: 1, HELLO: 1}
  667. * console.log( UE.utils.listToMap( [ 'UEdtior', 'Hello' ] ) );
  668. *
  669. * ```
  670. */
  671. listToMap:function (list) {
  672. if (!list)return {};
  673. list = utils.isArray(list) ? list : list.split(',');
  674. for (var i = 0, ci, obj = {}; ci = list[i++];) {
  675. obj[ci.toUpperCase()] = obj[ci] = 1;
  676. }
  677. return obj;
  678. },
  679. /**
  680. * 将str中的html符号转义,将转义“',&,<,",>”五个字符
  681. * @method unhtml
  682. * @param { String } str 需要转义的字符串
  683. * @return { String } 转义后的字符串
  684. * @example
  685. * ```javascript
  686. * var html = '<body>&</body>';
  687. *
  688. * //output: &lt;body&gt;&amp;&lt;/body&gt;
  689. * console.log( UE.utils.unhtml( html ) );
  690. *
  691. * ```
  692. */
  693. unhtml:function (str, reg) {
  694. return str ? str.replace(reg || /[&<">'](?:(amp|lt|quot|gt|#39|nbsp|#\d+);)?/g, function (a, b) {
  695. if (b) {
  696. return a;
  697. } else {
  698. return {
  699. '<':'&lt;',
  700. '&':'&amp;',
  701. '"':'&quot;',
  702. '>':'&gt;',
  703. "'":'&#39;'
  704. }[a]
  705. }
  706. }) : '';
  707. },
  708. /**
  709. * 将str中的转义字符还原成html字符
  710. * @see UE.utils.unhtml(String);
  711. * @method html
  712. * @param { String } str 需要逆转义的字符串
  713. * @return { String } 逆转义后的字符串
  714. * @example
  715. * ```javascript
  716. *
  717. * var str = '&lt;body&gt;&amp;&lt;/body&gt;';
  718. *
  719. * //output: <body>&</body>
  720. * console.log( UE.utils.html( str ) );
  721. *
  722. * ```
  723. */
  724. html:function (str) {
  725. return str ? str.replace(/&((g|l|quo)t|amp|#39|nbsp);/g, function (m) {
  726. return {
  727. '&lt;':'<',
  728. '&amp;':'&',
  729. '&quot;':'"',
  730. '&gt;':'>',
  731. '&#39;':"'",
  732. '&nbsp;':' '
  733. }[m]
  734. }) : '';
  735. },
  736. /**
  737. * 将css样式转换为驼峰的形式
  738. * @method cssStyleToDomStyle
  739. * @param { String } cssName 需要转换的css样式名
  740. * @return { String } 转换成驼峰形式后的css样式名
  741. * @example
  742. * ```javascript
  743. *
  744. * var str = 'border-top';
  745. *
  746. * //output: borderTop
  747. * console.log( UE.utils.cssStyleToDomStyle( str ) );
  748. *
  749. * ```
  750. */
  751. cssStyleToDomStyle:function () {
  752. var test = document.createElement('div').style,
  753. cache = {
  754. 'float':test.cssFloat != undefined ? 'cssFloat' : test.styleFloat != undefined ? 'styleFloat' : 'float'
  755. };
  756. return function (cssName) {
  757. return cache[cssName] || (cache[cssName] = cssName.toLowerCase().replace(/-./g, function (match) {
  758. return match.charAt(1).toUpperCase();
  759. }));
  760. };
  761. }(),
  762. /**
  763. * 动态加载文件到doc中
  764. * @method loadFile
  765. * @param { DomDocument } document 需要加载资源文件的文档对象
  766. * @param { Object } options 加载资源文件的属性集合, 取值请参考代码示例
  767. * @example
  768. * ```javascript
  769. *
  770. * UE.utils.loadFile( document, {
  771. * src:"test.js",
  772. * tag:"script",
  773. * type:"text/javascript",
  774. * defer:"defer"
  775. * } );
  776. *
  777. * ```
  778. */
  779. /**
  780. * 动态加载文件到doc中,加载成功后执行的回调函数fn
  781. * @method loadFile
  782. * @param { DomDocument } document 需要加载资源文件的文档对象
  783. * @param { Object } options 加载资源文件的属性集合, 该集合支持的值是script标签和style标签支持的所有属性。
  784. * @param { Function } fn 资源文件加载成功之后执行的回调
  785. * @warning 对于在同一个文档中多次加载同一URL的文件, 该方法会在第一次加载之后缓存该请求,
  786. * 在此之后的所有同一URL的请求, 将会直接触发回调。
  787. * @example
  788. * ```javascript
  789. *
  790. * UE.utils.loadFile( document, {
  791. * src:"test.js",
  792. * tag:"script",
  793. * type:"text/javascript",
  794. * defer:"defer"
  795. * }, function () {
  796. * console.log('加载成功');
  797. * } );
  798. *
  799. * ```
  800. */
  801. loadFile:function () {
  802. var tmpList = [];
  803. function getItem(doc, obj) {
  804. try {
  805. for (var i = 0, ci; ci = tmpList[i++];) {
  806. if (ci.doc === doc && ci.url == (obj.src || obj.href)) {
  807. return ci;
  808. }
  809. }
  810. } catch (e) {
  811. return null;
  812. }
  813. }
  814. return function (doc, obj, fn) {
  815. var item = getItem(doc, obj);
  816. if (item) {
  817. if (item.ready) {
  818. fn && fn();
  819. } else {
  820. item.funs.push(fn)
  821. }
  822. return;
  823. }
  824. tmpList.push({
  825. doc:doc,
  826. url:obj.src || obj.href,
  827. funs:[fn]
  828. });
  829. if (!doc.body) {
  830. var html = [];
  831. for (var p in obj) {
  832. if (p == 'tag')continue;
  833. html.push(p + '="' + obj[p] + '"')
  834. }
  835. doc.write('<' + obj.tag + ' ' + html.join(' ') + ' ></' + obj.tag + '>');
  836. return;
  837. }
  838. if (obj.id && doc.getElementById(obj.id)) {
  839. return;
  840. }
  841. var element = doc.createElement(obj.tag);
  842. delete obj.tag;
  843. for (var p in obj) {
  844. element.setAttribute(p, obj[p]);
  845. }
  846. element.onload = element.onreadystatechange = function () {
  847. if (!this.readyState || /loaded|complete/.test(this.readyState)) {
  848. item = getItem(doc, obj);
  849. if (item.funs.length > 0) {
  850. item.ready = 1;
  851. for (var fi; fi = item.funs.pop();) {
  852. fi();
  853. }
  854. }
  855. element.onload = element.onreadystatechange = null;
  856. }
  857. };
  858. element.onerror = function () {
  859. throw Error('The load ' + (obj.href || obj.src) + ' fails,check the url settings of file ueditor.config.js ')
  860. };
  861. doc.getElementsByTagName("head")[0].appendChild(element);
  862. }
  863. }(),
  864. /**
  865. * 判断obj对象是否为空
  866. * @method isEmptyObject
  867. * @param { * } obj 需要判断的对象
  868. * @remind 如果判断的对象是NULL, 将直接返回true, 如果是数组且为空, 返回true, 如果是字符串, 且字符串为空,
  869. * 返回true, 如果是普通对象, 且该对象没有任何实例属性, 返回true
  870. * @return { Boolean } 对象是否为空
  871. * @example
  872. * ```javascript
  873. *
  874. * //output: true
  875. * console.log( UE.utils.isEmptyObject( {} ) );
  876. *
  877. * //output: true
  878. * console.log( UE.utils.isEmptyObject( [] ) );
  879. *
  880. * //output: true
  881. * console.log( UE.utils.isEmptyObject( "" ) );
  882. *
  883. * //output: false
  884. * console.log( UE.utils.isEmptyObject( { key: 1 } ) );
  885. *
  886. * //output: false
  887. * console.log( UE.utils.isEmptyObject( [1] ) );
  888. *
  889. * //output: false
  890. * console.log( UE.utils.isEmptyObject( "1" ) );
  891. *
  892. * ```
  893. */
  894. isEmptyObject:function (obj) {
  895. if (obj == null) return true;
  896. if (this.isArray(obj) || this.isString(obj)) return obj.length === 0;
  897. for (var key in obj) if (obj.hasOwnProperty(key)) return false;
  898. return true;
  899. },
  900. /**
  901. * 把rgb格式的颜色值转换成16进制格式
  902. * @method fixColor
  903. * @param { String } rgb格式的颜色值
  904. * @param { String }
  905. * @example
  906. * rgb(255,255,255) => "#ffffff"
  907. */
  908. fixColor:function (name, value) {
  909. if (/color/i.test(name) && /rgba?/.test(value)) {
  910. var array = value.split(",");
  911. if (array.length > 3)
  912. return "";
  913. value = "#";
  914. for (var i = 0, color; color = array[i++];) {
  915. color = parseInt(color.replace(/[^\d]/gi, ''), 10).toString(16);
  916. value += color.length == 1 ? "0" + color : color;
  917. }
  918. value = value.toUpperCase();
  919. }
  920. return value;
  921. },
  922. /**
  923. * 只针对border,padding,margin做了处理,因为性能问题
  924. * @public
  925. * @function
  926. * @param {String} val style字符串
  927. */
  928. optCss:function (val) {
  929. var padding, margin, border;
  930. val = val.replace(/(padding|margin|border)\-([^:]+):([^;]+);?/gi, function (str, key, name, val) {
  931. if (val.split(' ').length == 1) {
  932. switch (key) {
  933. case 'padding':
  934. !padding && (padding = {});
  935. padding[name] = val;
  936. return '';
  937. case 'margin':
  938. !margin && (margin = {});
  939. margin[name] = val;
  940. return '';
  941. case 'border':
  942. return val == 'initial' ? '' : str;
  943. }
  944. }
  945. return str;
  946. });
  947. function opt(obj, name) {
  948. if (!obj) {
  949. return '';
  950. }
  951. var t = obj.top , b = obj.bottom, l = obj.left, r = obj.right, val = '';
  952. if (!t || !l || !b || !r) {
  953. for (var p in obj) {
  954. val += ';' + name + '-' + p + ':' + obj[p] + ';';
  955. }
  956. } else {
  957. val += ';' + name + ':' +
  958. (t == b && b == l && l == r ? t :
  959. t == b && l == r ? (t + ' ' + l) :
  960. l == r ? (t + ' ' + l + ' ' + b) : (t + ' ' + r + ' ' + b + ' ' + l)) + ';'
  961. }
  962. return val;
  963. }
  964. val += opt(padding, 'padding') + opt(margin, 'margin');
  965. return val.replace(/^[ \n\r\t;]*|[ \n\r\t]*$/, '').replace(/;([ \n\r\t]+)|\1;/g, ';')
  966. .replace(/(&((l|g)t|quot|#39))?;{2,}/g, function (a, b) {
  967. return b ? b + ";;" : ';'
  968. });
  969. },
  970. /**
  971. * 克隆对象
  972. * @method clone
  973. * @param { Object } source 源对象
  974. * @return { Object } source的一个副本
  975. */
  976. /**
  977. * 深度克隆对象,将source的属性克隆到target对象, 会覆盖target重名的属性。
  978. * @method clone
  979. * @param { Object } source 源对象
  980. * @param { Object } target 目标对象
  981. * @return { Object } 附加了source对象所有属性的target对象
  982. */
  983. clone:function (source, target) {
  984. var tmp;
  985. target = target || {};
  986. for (var i in source) {
  987. if (source.hasOwnProperty(i)) {
  988. tmp = source[i];
  989. if (typeof tmp == 'object') {
  990. target[i] = utils.isArray(tmp) ? [] : {};
  991. utils.clone(source[i], target[i])
  992. } else {
  993. target[i] = tmp;
  994. }
  995. }
  996. }
  997. return target;
  998. },
  999. /**
  1000. * 把cm/pt为单位的值转换为px为单位的值
  1001. * @method transUnitToPx
  1002. * @param { String } 待转换的带单位的字符串
  1003. * @return { String } 转换为px为计量单位的值的字符串
  1004. * @example
  1005. * ```javascript
  1006. *
  1007. * //output: 500px
  1008. * console.log( UE.utils.transUnitToPx( '20cm' ) );
  1009. *
  1010. * //output: 27px
  1011. * console.log( UE.utils.transUnitToPx( '20pt' ) );
  1012. *
  1013. * ```
  1014. */
  1015. transUnitToPx:function (val) {
  1016. if (!/(pt|cm)/.test(val)) {
  1017. return val
  1018. }
  1019. var unit;
  1020. val.replace(/([\d.]+)(\w+)/, function (str, v, u) {
  1021. val = v;
  1022. unit = u;
  1023. });
  1024. switch (unit) {
  1025. case 'cm':
  1026. val = parseFloat(val) * 25;
  1027. break;
  1028. case 'pt':
  1029. val = Math.round(parseFloat(val) * 96 / 72);
  1030. }
  1031. return val + (val ? 'px' : '');
  1032. },
  1033. /**
  1034. * 在dom树ready之后执行给定的回调函数
  1035. * @method domReady
  1036. * @remind 如果在执行该方法的时候, dom树已经ready, 那么回调函数将立刻执行
  1037. * @param { Function } fn dom树ready之后的回调函数
  1038. * @example
  1039. * ```javascript
  1040. *
  1041. * UE.utils.domReady( function () {
  1042. *
  1043. * console.log('123');
  1044. *
  1045. * } );
  1046. *
  1047. * ```
  1048. */
  1049. domReady:function () {
  1050. var fnArr = [];
  1051. function doReady(doc) {
  1052. //确保onready只执行一次
  1053. doc.isReady = true;
  1054. for (var ci; ci = fnArr.pop(); ci()) {
  1055. }
  1056. }
  1057. return function (onready, win) {
  1058. win = win || window;
  1059. var doc = win.document;
  1060. onready && fnArr.push(onready);
  1061. if (doc.readyState === "complete") {
  1062. doReady(doc);
  1063. } else {
  1064. doc.isReady && doReady(doc);
  1065. if (browser.ie && browser.version != 11) {
  1066. (function () {
  1067. if (doc.isReady) return;
  1068. try {
  1069. doc.documentElement.doScroll("left");
  1070. } catch (error) {
  1071. setTimeout(arguments.callee, 0);
  1072. return;
  1073. }
  1074. doReady(doc);
  1075. })();
  1076. win.attachEvent('onload', function () {
  1077. doReady(doc)
  1078. });
  1079. } else {
  1080. doc.addEventListener("DOMContentLoaded", function () {
  1081. doc.removeEventListener("DOMContentLoaded", arguments.callee, false);
  1082. doReady(doc);
  1083. }, false);
  1084. win.addEventListener('load', function () {
  1085. doReady(doc)
  1086. }, false);
  1087. }
  1088. }
  1089. }
  1090. }(),
  1091. /**
  1092. * 动态添加css样式
  1093. * @method cssRule
  1094. * @param { String } 节点名称
  1095. * @grammar UE.utils.cssRule('添加的样式的节点名称',['样式','放到哪个document上'])
  1096. * @grammar UE.utils.cssRule('body','body{background:#ccc}') => null //给body添加背景颜色
  1097. * @grammar UE.utils.cssRule('body') =>样式的字符串 //取得key值为body的样式的内容,如果没有找到key值先关的样式将返回空,例如刚才那个背景颜色,将返回 body{background:#ccc}
  1098. * @grammar UE.utils.cssRule('body',document) => 返回指定key的样式,并且指定是哪个document
  1099. * @grammar UE.utils.cssRule('body','') =>null //清空给定的key值的背景颜色
  1100. */
  1101. cssRule:browser.ie && browser.version != 11 ? function (key, style, doc) {
  1102. var indexList, index;
  1103. if(style === undefined || style && style.nodeType && style.nodeType == 9){
  1104. //获取样式
  1105. doc = style && style.nodeType && style.nodeType == 9 ? style : (doc || document);
  1106. indexList = doc.indexList || (doc.indexList = {});
  1107. index = indexList[key];
  1108. if(index !== undefined){
  1109. return doc.styleSheets[index].cssText
  1110. }
  1111. return undefined;
  1112. }
  1113. doc = doc || document;
  1114. indexList = doc.indexList || (doc.indexList = {});
  1115. index = indexList[key];
  1116. //清除样式
  1117. if(style === ''){
  1118. if(index!== undefined){
  1119. doc.styleSheets[index].cssText = '';
  1120. delete indexList[key];
  1121. return true
  1122. }
  1123. return false;
  1124. }
  1125. //添加样式
  1126. if(index!== undefined){
  1127. sheetStyle = doc.styleSheets[index];
  1128. }else{
  1129. sheetStyle = doc.createStyleSheet('', index = doc.styleSheets.length);
  1130. indexList[key] = index;
  1131. }
  1132. sheetStyle.cssText = style;
  1133. }: function (key, style, doc) {
  1134. var head, node;
  1135. if(style === undefined || style && style.nodeType && style.nodeType == 9){
  1136. //获取样式
  1137. doc = style && style.nodeType && style.nodeType == 9 ? style : (doc || document);
  1138. node = doc.getElementById(key);
  1139. return node ? node.innerHTML : undefined;
  1140. }
  1141. doc = doc || document;
  1142. node = doc.getElementById(key);
  1143. //清除样式
  1144. if(style === ''){
  1145. if(node){
  1146. node.parentNode.removeChild(node);
  1147. return true
  1148. }
  1149. return false;
  1150. }
  1151. //添加样式
  1152. if(node){
  1153. node.innerHTML = style;
  1154. }else{
  1155. node = doc.createElement('style');
  1156. node.id = key;
  1157. node.innerHTML = style;
  1158. doc.getElementsByTagName('head')[0].appendChild(node);
  1159. }
  1160. },
  1161. sort:function(array,compareFn){
  1162. compareFn = compareFn || function(item1, item2){ return item1.localeCompare(item2);};
  1163. for(var i= 0,len = array.length; i<len; i++){
  1164. for(var j = i,length = array.length; j<length; j++){
  1165. if(compareFn(array[i], array[j]) > 0){
  1166. var t = array[i];
  1167. array[i] = array[j];
  1168. array[j] = t;
  1169. }
  1170. }
  1171. }
  1172. return array;
  1173. },
  1174. serializeParam:function (json) {
  1175. var strArr = [];
  1176. for (var i in json) {
  1177. //忽略默认的几个参数
  1178. if(i=="method" || i=="timeout" || i=="async") continue;
  1179. //传递过来的对象和函数不在提交之列
  1180. if (!((typeof json[i]).toLowerCase() == "function" || (typeof json[i]).toLowerCase() == "object")) {
  1181. strArr.push( encodeURIComponent(i) + "="+encodeURIComponent(json[i]) );
  1182. } else if (utils.isArray(json[i])) {
  1183. //支持传数组内容
  1184. for(var j = 0; j < json[i].length; j++) {
  1185. strArr.push( encodeURIComponent(i) + "[]="+encodeURIComponent(json[i][j]) );
  1186. }
  1187. }
  1188. }
  1189. return strArr.join("&");
  1190. },
  1191. formatUrl:function (url) {
  1192. var u = url.replace(/&&/g, '&');
  1193. u = u.replace(/\?&/g, '?');
  1194. u = u.replace(/&$/g, '');
  1195. u = u.replace(/&#/g, '#');
  1196. u = u.replace(/&+/g, '&');
  1197. return u;
  1198. },
  1199. isCrossDomainUrl:function (url) {
  1200. var a = document.createElement('a');
  1201. a.href = url;
  1202. if (browser.ie) {
  1203. a.href = a.href;
  1204. }
  1205. return !(a.protocol == location.protocol && a.hostname == location.hostname &&
  1206. (a.port == location.port || (a.port == '80' && location.port == '') || (a.port == '' && location.port == '80')));
  1207. },
  1208. clearEmptyAttrs : function(obj){
  1209. for(var p in obj){
  1210. if(obj[p] === ''){
  1211. delete obj[p]
  1212. }
  1213. }
  1214. return obj;
  1215. },
  1216. str2json : function(s){
  1217. if (!utils.isString(s)) return null;
  1218. if (window.JSON) {
  1219. return JSON.parse(s);
  1220. } else {
  1221. return (new Function("return " + utils.trim(s || '')))();
  1222. }
  1223. },
  1224. json2str : (function(){
  1225. if (window.JSON) {
  1226. return JSON.stringify;
  1227. } else {
  1228. var escapeMap = {
  1229. "\b": '\\b',
  1230. "\t": '\\t',
  1231. "\n": '\\n',
  1232. "\f": '\\f',
  1233. "\r": '\\r',
  1234. '"' : '\\"',
  1235. "\\": '\\\\'
  1236. };
  1237. function encodeString(source) {
  1238. if (/["\\\x00-\x1f]/.test(source)) {
  1239. source = source.replace(
  1240. /["\\\x00-\x1f]/g,
  1241. function (match) {
  1242. var c = escapeMap[match];
  1243. if (c) {
  1244. return c;
  1245. }
  1246. c = match.charCodeAt();
  1247. return "\\u00"
  1248. + Math.floor(c / 16).toString(16)
  1249. + (c % 16).toString(16);
  1250. });
  1251. }
  1252. return '"' + source + '"';
  1253. }
  1254. function encodeArray(source) {
  1255. var result = ["["],
  1256. l = source.length,
  1257. preComma, i, item;
  1258. for (i = 0; i < l; i++) {
  1259. item = source[i];
  1260. switch (typeof item) {
  1261. case "undefined":
  1262. case "function":
  1263. case "unknown":
  1264. break;
  1265. default:
  1266. if(preComma) {
  1267. result.push(',');
  1268. }
  1269. result.push(utils.json2str(item));
  1270. preComma = 1;
  1271. }
  1272. }
  1273. result.push("]");
  1274. return result.join("");
  1275. }
  1276. function pad(source) {
  1277. return source < 10 ? '0' + source : source;
  1278. }
  1279. function encodeDate(source){
  1280. return '"' + source.getFullYear() + "-"
  1281. + pad(source.getMonth() + 1) + "-"
  1282. + pad(source.getDate()) + "T"
  1283. + pad(source.getHours()) + ":"
  1284. + pad(source.getMinutes()) + ":"
  1285. + pad(source.getSeconds()) + '"';
  1286. }
  1287. return function (value) {
  1288. switch (typeof value) {
  1289. case 'undefined':
  1290. return 'undefined';
  1291. case 'number':
  1292. return isFinite(value) ? String(value) : "null";
  1293. case 'string':
  1294. return encodeString(value);
  1295. case 'boolean':
  1296. return String(value);
  1297. default:
  1298. if (value === null) {
  1299. return 'null';
  1300. } else if (utils.isArray(value)) {
  1301. return encodeArray(value);
  1302. } else if (utils.isDate(value)) {
  1303. return encodeDate(value);
  1304. } else {
  1305. var result = ['{'],
  1306. encode = utils.json2str,
  1307. preComma,
  1308. item;
  1309. for (var key in value) {
  1310. if (Object.prototype.hasOwnProperty.call(value, key)) {
  1311. item = value[key];
  1312. switch (typeof item) {
  1313. case 'undefined':
  1314. case 'unknown':
  1315. case 'function':
  1316. break;
  1317. default:
  1318. if (preComma) {
  1319. result.push(',');
  1320. }
  1321. preComma = 1;
  1322. result.push(encode(key) + ':' + encode(item));
  1323. }
  1324. }
  1325. }
  1326. result.push('}');
  1327. return result.join('');
  1328. }
  1329. }
  1330. };
  1331. }
  1332. })()
  1333. };
  1334. /**
  1335. * 判断给定的对象是否是字符串
  1336. * @method isString
  1337. * @param { * } object 需要判断的对象
  1338. * @return { Boolean } 给定的对象是否是字符串
  1339. */
  1340. /**
  1341. * 判断给定的对象是否是数组
  1342. * @method isArray
  1343. * @param { * } object 需要判断的对象
  1344. * @return { Boolean } 给定的对象是否是数组
  1345. */
  1346. /**
  1347. * 判断给定的对象是否是一个Function
  1348. * @method isFunction
  1349. * @param { * } object 需要判断的对象
  1350. * @return { Boolean } 给定的对象是否是Function
  1351. */
  1352. /**
  1353. * 判断给定的对象是否是Number
  1354. * @method isNumber
  1355. * @param { * } object 需要判断的对象
  1356. * @return { Boolean } 给定的对象是否是Number
  1357. */
  1358. /**
  1359. * 判断给定的对象是否是一个正则表达式
  1360. * @method isRegExp
  1361. * @param { * } object 需要判断的对象
  1362. * @return { Boolean } 给定的对象是否是正则表达式
  1363. */
  1364. /**
  1365. * 判断给定的对象是否是一个普通对象
  1366. * @method isObject
  1367. * @param { * } object 需要判断的对象
  1368. * @return { Boolean } 给定的对象是否是普通对象
  1369. */
  1370. utils.each(['String', 'Function', 'Array', 'Number', 'RegExp', 'Object', 'Date'], function (v) {
  1371. UE.utils['is' + v] = function (obj) {
  1372. return Object.prototype.toString.apply(obj) == '[object ' + v + ']';
  1373. }
  1374. });
  1375. // core/EventBase.js
  1376. /**
  1377. * UE采用的事件基类
  1378. * @file
  1379. * @module UE
  1380. * @class EventBase
  1381. * @since 1.2.6.1
  1382. */
  1383. /**
  1384. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  1385. * @unfile
  1386. * @module UE
  1387. */
  1388. /**
  1389. * UE采用的事件基类,继承此类的对应类将获取addListener,removeListener,fireEvent方法。
  1390. * 在UE中,Editor以及所有ui实例都继承了该类,故可以在对应的ui对象以及editor对象上使用上述方法。
  1391. * @unfile
  1392. * @module UE
  1393. * @class EventBase
  1394. */
  1395. /**
  1396. * 通过此构造器,子类可以继承EventBase获取事件监听的方法
  1397. * @constructor
  1398. * @example
  1399. * ```javascript
  1400. * UE.EventBase.call(editor);
  1401. * ```
  1402. */
  1403. var EventBase = UE.EventBase = function () {};
  1404. EventBase.prototype = {
  1405. /**
  1406. * 注册事件监听器
  1407. * @method addListener
  1408. * @param { String } types 监听的事件名称,同时监听多个事件使用空格分隔
  1409. * @param { Function } fn 监听的事件被触发时,会执行该回调函数
  1410. * @waining 事件被触发时,监听的函数假如返回的值恒等于true,回调函数的队列中后面的函数将不执行
  1411. * @example
  1412. * ```javascript
  1413. * editor.addListener('selectionchange',function(){
  1414. * console.log("选区已经变化!");
  1415. * })
  1416. * editor.addListener('beforegetcontent aftergetcontent',function(type){
  1417. * if(type == 'beforegetcontent'){
  1418. * //do something
  1419. * }else{
  1420. * //do something
  1421. * }
  1422. * console.log(this.getContent) // this是注册的事件的编辑器实例
  1423. * })
  1424. * ```
  1425. * @see UE.EventBase:fireEvent(String)
  1426. */
  1427. addListener:function (types, listener) {
  1428. types = utils.trim(types).split(/\s+/);
  1429. for (var i = 0, ti; ti = types[i++];) {
  1430. getListener(this, ti, true).push(listener);
  1431. }
  1432. },
  1433. on : function(types, listener){
  1434. return this.addListener(types,listener);
  1435. },
  1436. off : function(types, listener){
  1437. return this.removeListener(types, listener)
  1438. },
  1439. trigger:function(){
  1440. return this.fireEvent.apply(this,arguments);
  1441. },
  1442. /**
  1443. * 移除事件监听器
  1444. * @method removeListener
  1445. * @param { String } types 移除的事件名称,同时移除多个事件使用空格分隔
  1446. * @param { Function } fn 移除监听事件的函数引用
  1447. * @example
  1448. * ```javascript
  1449. * //changeCallback为方法体
  1450. * editor.removeListener("selectionchange",changeCallback);
  1451. * ```
  1452. */
  1453. removeListener:function (types, listener) {
  1454. types = utils.trim(types).split(/\s+/);
  1455. for (var i = 0, ti; ti = types[i++];) {
  1456. utils.removeItem(getListener(this, ti) || [], listener);
  1457. }
  1458. },
  1459. /**
  1460. * 触发事件
  1461. * @method fireEvent
  1462. * @param { String } types 触发的事件名称,同时触发多个事件使用空格分隔
  1463. * @remind 该方法会触发addListener
  1464. * @return { * } 返回触发事件的队列中,最后执行的回调函数的返回值
  1465. * @example
  1466. * ```javascript
  1467. * editor.fireEvent("selectionchange");
  1468. * ```
  1469. */
  1470. /**
  1471. * 触发事件
  1472. * @method fireEvent
  1473. * @param { String } types 触发的事件名称,同时触发多个事件使用空格分隔
  1474. * @param { *... } options 可选参数,可以传入一个或多个参数,会传给事件触发的回调函数
  1475. * @return { * } 返回触发事件的队列中,最后执行的回调函数的返回值
  1476. * @example
  1477. * ```javascript
  1478. *
  1479. * editor.addListener( "selectionchange", function ( type, arg1, arg2 ) {
  1480. *
  1481. * console.log( arg1 + " " + arg2 );
  1482. *
  1483. * } );
  1484. *
  1485. * //触发selectionchange事件, 会执行上面的事件监听器
  1486. * //output: Hello World
  1487. * editor.fireEvent("selectionchange", "Hello", "World");
  1488. * ```
  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])continue;
  1500. t = listeners[k].apply(this, arguments);
  1501. if(t === true){
  1502. return t;
  1503. }
  1504. if (t !== undefined) {
  1505. r = t;
  1506. }
  1507. }
  1508. }
  1509. if (t = this['on' + ti.toLowerCase()]) {
  1510. r = t.apply(this, arguments);
  1511. }
  1512. }
  1513. return r;
  1514. }
  1515. };
  1516. /**
  1517. * 获得对象所拥有监听类型的所有监听器
  1518. * @unfile
  1519. * @module UE
  1520. * @since 1.2.6.1
  1521. * @method getListener
  1522. * @public
  1523. * @param { Object } obj 查询监听器的对象
  1524. * @param { String } type 事件类型
  1525. * @param { Boolean } force 为true且当前所有type类型的侦听器不存在时,创建一个空监听器数组
  1526. * @return { Array } 监听器数组
  1527. */
  1528. function getListener(obj, type, force) {
  1529. var allListeners;
  1530. type = type.toLowerCase();
  1531. return ( ( allListeners = ( obj.__allListeners || force && ( obj.__allListeners = {} ) ) )
  1532. && ( allListeners[type] || force && ( allListeners[type] = [] ) ) );
  1533. }
  1534. // core/dtd.js
  1535. ///import editor.js
  1536. ///import core/dom/dom.js
  1537. ///import core/utils.js
  1538. /**
  1539. * dtd html语义化的体现类
  1540. * @constructor
  1541. * @namespace dtd
  1542. */
  1543. var dtd = dom.dtd = (function() {
  1544. function _( s ) {
  1545. for (var k in s) {
  1546. s[k.toUpperCase()] = s[k];
  1547. }
  1548. return s;
  1549. }
  1550. var X = utils.extend2;
  1551. var A = _({isindex:1,fieldset:1}),
  1552. B = _({input:1,button:1,select:1,textarea:1,label:1}),
  1553. C = X( _({a:1}), B ),
  1554. D = X( {iframe:1}, C ),
  1555. E = _({hr:1,ul:1,menu:1,div:1,blockquote:1,noscript:1,table:1,center:1,address:1,dir:1,pre:1,h5:1,dl:1,h4:1,noframes:1,h6:1,ol:1,h1:1,h3:1,h2:1}),
  1556. F = _({ins:1,del:1,script:1,style:1}),
  1557. G = X( _({b:1,acronym:1,bdo:1,'var':1,'#':1,abbr:1,code:1,br:1,i:1,cite:1,kbd:1,u:1,strike:1,s:1,tt:1,strong:1,q:1,samp:1,em:1,dfn:1,span:1}), F ),
  1558. H = X( _({sub:1,img:1,embed:1,object:1,sup:1,basefont:1,map:1,applet:1,font:1,big:1,small:1}), G ),
  1559. I = X( _({p:1}), H ),
  1560. J = X( _({iframe:1}), H, B ),
  1561. K = _({img:1,embed:1,noscript:1,br:1,kbd:1,center:1,button:1,basefont:1,h5:1,h4:1,samp:1,h6:1,ol:1,h1:1,h3:1,h2:1,form:1,font:1,'#':1,select:1,menu:1,ins:1,abbr:1,label:1,code:1,table:1,script:1,cite:1,input:1,iframe:1,strong:1,textarea:1,noframes:1,big:1,small:1,span:1,hr:1,sub:1,bdo:1,'var':1,div:1,object:1,sup:1,strike:1,dir:1,map:1,dl:1,applet:1,del:1,isindex:1,fieldset:1,ul:1,b:1,acronym:1,a:1,blockquote:1,i:1,u:1,s:1,tt:1,address:1,q:1,pre:1,p:1,em:1,dfn:1}),
  1562. L = X( _({a:0}), J ),//a不能被切开,所以把他
  1563. M = _({tr:1}),
  1564. N = _({'#':1}),
  1565. O = X( _({param:1}), K ),
  1566. P = X( _({form:1}), A, D, E, I ),
  1567. Q = _({li:1,ol:1,ul:1}),
  1568. R = _({style:1,script:1}),
  1569. S = _({base:1,link:1,meta:1,title:1}),
  1570. T = X( S, R ),
  1571. U = _({head:1,body:1}),
  1572. V = _({html:1});
  1573. var block = _({address:1,blockquote:1,center:1,dir:1,div:1,dl:1,fieldset:1,form:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,hr:1,isindex:1,menu:1,noframes:1,ol:1,p:1,pre:1,table:1,ul:1}),
  1574. empty = _({area:1,base:1,basefont:1,br:1,col:1,command:1,dialog:1,embed:1,hr:1,img:1,input:1,isindex:1,keygen:1,link:1,meta:1,param:1,source:1,track:1,wbr:1});
  1575. return _({
  1576. // $ 表示自定的属性
  1577. // body外的元素列表.
  1578. $nonBodyContent: X( V, U, S ),
  1579. //块结构元素列表
  1580. $block : block,
  1581. //内联元素列表
  1582. $inline : L,
  1583. $inlineWithA : X(_({a:1}),L),
  1584. $body : X( _({script:1,style:1}), block ),
  1585. $cdata : _({script:1,style:1}),
  1586. //自闭和元素
  1587. $empty : empty,
  1588. //不是自闭合,但不能让range选中里边
  1589. $nonChild : _({iframe:1,textarea:1}),
  1590. //列表元素列表
  1591. $listItem : _({dd:1,dt:1,li:1}),
  1592. //列表根元素列表
  1593. $list: _({ul:1,ol:1,dl:1}),
  1594. //不能认为是空的元素
  1595. $isNotEmpty : _({table:1,ul:1,ol:1,dl:1,iframe:1,area:1,base:1,col:1,hr:1,img:1,embed:1,input:1,link:1,meta:1,param:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1}),
  1596. //如果没有子节点就可以删除的元素列表,像span,a
  1597. $removeEmpty : _({a:1,abbr:1,acronym:1,address:1,b:1,bdo:1,big:1,cite:1,code:1,del:1,dfn:1,em:1,font:1,i:1,ins:1,label:1,kbd:1,q:1,s:1,samp:1,small:1,span:1,strike:1,strong:1,sub:1,sup:1,tt:1,u:1,'var':1}),
  1598. $removeEmptyBlock : _({'p':1,'div':1}),
  1599. //在table元素里的元素列表
  1600. $tableContent : _({caption:1,col:1,colgroup:1,tbody:1,td:1,tfoot:1,th:1,thead:1,tr:1,table:1}),
  1601. //不转换的标签
  1602. $notTransContent : _({pre:1,script:1,style:1,textarea:1}),
  1603. html: U,
  1604. head: T,
  1605. style: N,
  1606. script: N,
  1607. body: P,
  1608. base: {},
  1609. link: {},
  1610. meta: {},
  1611. title: N,
  1612. col : {},
  1613. tr : _({td:1,th:1}),
  1614. img : {},
  1615. embed: {},
  1616. colgroup : _({thead:1,col:1,tbody:1,tr:1,tfoot:1}),
  1617. noscript : P,
  1618. td : P,
  1619. br : {},
  1620. th : P,
  1621. center : P,
  1622. kbd : L,
  1623. button : X( I, E ),
  1624. basefont : {},
  1625. h5 : L,
  1626. h4 : L,
  1627. samp : L,
  1628. h6 : L,
  1629. ol : Q,
  1630. h1 : L,
  1631. h3 : L,
  1632. option : N,
  1633. h2 : L,
  1634. form : X( A, D, E, I ),
  1635. select : _({optgroup:1,option:1}),
  1636. font : L,
  1637. ins : L,
  1638. menu : Q,
  1639. abbr : L,
  1640. label : L,
  1641. table : _({thead:1,col:1,tbody:1,tr:1,colgroup:1,caption:1,tfoot:1}),
  1642. code : L,
  1643. tfoot : M,
  1644. cite : L,
  1645. li : P,
  1646. input : {},
  1647. iframe : P,
  1648. strong : L,
  1649. textarea : N,
  1650. noframes : P,
  1651. big : L,
  1652. small : L,
  1653. //trace:
  1654. span :_({'#':1,br:1,b:1,strong:1,u:1,i:1,em:1,sub:1,sup:1,strike:1,span:1}),
  1655. hr : L,
  1656. dt : L,
  1657. sub : L,
  1658. optgroup : _({option:1}),
  1659. param : {},
  1660. bdo : L,
  1661. 'var' : L,
  1662. div : P,
  1663. object : O,
  1664. sup : L,
  1665. dd : P,
  1666. strike : L,
  1667. area : {},
  1668. dir : Q,
  1669. map : X( _({area:1,form:1,p:1}), A, F, E ),
  1670. applet : O,
  1671. dl : _({dt:1,dd:1}),
  1672. del : L,
  1673. isindex : {},
  1674. fieldset : X( _({legend:1}), K ),
  1675. thead : M,
  1676. ul : Q,
  1677. acronym : L,
  1678. b : L,
  1679. a : X( _({a:1}), J ),
  1680. blockquote :X(_({td:1,tr:1,tbody:1,li:1}),P),
  1681. caption : L,
  1682. i : L,
  1683. u : L,
  1684. tbody : M,
  1685. s : L,
  1686. address : X( D, I ),
  1687. tt : L,
  1688. legend : L,
  1689. q : L,
  1690. pre : X( G, C ),
  1691. p : X(_({'a':1}),L),
  1692. em :L,
  1693. dfn : L
  1694. });
  1695. })();
  1696. // core/domUtils.js
  1697. /**
  1698. * Dom操作工具包
  1699. * @file
  1700. * @module UE.dom.domUtils
  1701. * @since 1.2.6.1
  1702. */
  1703. /**
  1704. * Dom操作工具包
  1705. * @unfile
  1706. * @module UE.dom.domUtils
  1707. */
  1708. function getDomNode(node, start, ltr, startFromChild, fn, guard) {
  1709. var tmpNode = startFromChild && node[start],
  1710. parent;
  1711. !tmpNode && (tmpNode = node[ltr]);
  1712. while (!tmpNode && (parent = (parent || node).parentNode)) {
  1713. if (parent.tagName == 'BODY' || guard && !guard(parent)) {
  1714. return null;
  1715. }
  1716. tmpNode = parent[ltr];
  1717. }
  1718. if (tmpNode && fn && !fn(tmpNode)) {
  1719. return getDomNode(tmpNode, start, ltr, false, fn);
  1720. }
  1721. return tmpNode;
  1722. }
  1723. var attrFix = ie && browser.version < 9 ? {
  1724. tabindex:"tabIndex",
  1725. readonly:"readOnly",
  1726. "for":"htmlFor",
  1727. "class":"className",
  1728. maxlength:"maxLength",
  1729. cellspacing:"cellSpacing",
  1730. cellpadding:"cellPadding",
  1731. rowspan:"rowSpan",
  1732. colspan:"colSpan",
  1733. usemap:"useMap",
  1734. frameborder:"frameBorder"
  1735. } : {
  1736. tabindex:"tabIndex",
  1737. readonly:"readOnly"
  1738. },
  1739. styleBlock = utils.listToMap([
  1740. '-webkit-box', '-moz-box', 'block' ,
  1741. 'list-item' , 'table' , 'table-row-group' ,
  1742. 'table-header-group', 'table-footer-group' ,
  1743. 'table-row' , 'table-column-group' , 'table-column' ,
  1744. 'table-cell' , 'table-caption'
  1745. ]);
  1746. var domUtils = dom.domUtils = {
  1747. //节点常量
  1748. NODE_ELEMENT:1,
  1749. NODE_DOCUMENT:9,
  1750. NODE_TEXT:3,
  1751. NODE_COMMENT:8,
  1752. NODE_DOCUMENT_FRAGMENT:11,
  1753. //位置关系
  1754. POSITION_IDENTICAL:0,
  1755. POSITION_DISCONNECTED:1,
  1756. POSITION_FOLLOWING:2,
  1757. POSITION_PRECEDING:4,
  1758. POSITION_IS_CONTAINED:8,
  1759. POSITION_CONTAINS:16,
  1760. //ie6使用其他的会有一段空白出现
  1761. fillChar:ie && browser.version == '6' ? '\ufeff' : '\u200B',
  1762. //-------------------------Node部分--------------------------------
  1763. keys:{
  1764. /*Backspace*/ 8:1, /*Delete*/ 46:1,
  1765. /*Shift*/ 16:1, /*Ctrl*/ 17:1, /*Alt*/ 18:1,
  1766. 37:1, 38:1, 39:1, 40:1,
  1767. 13:1 /*enter*/
  1768. },
  1769. /**
  1770. * 获取节点A相对于节点B的位置关系
  1771. * @method getPosition
  1772. * @param { Node } nodeA 需要查询位置关系的节点A
  1773. * @param { Node } nodeB 需要查询位置关系的节点B
  1774. * @return { Number } 节点A与节点B的关系
  1775. * @example
  1776. * ```javascript
  1777. * //output: 20
  1778. * var position = UE.dom.domUtils.getPosition( document.documentElement, document.body );
  1779. *
  1780. * switch ( position ) {
  1781. *
  1782. * //0
  1783. * case UE.dom.domUtils.POSITION_IDENTICAL:
  1784. * console.log('元素相同');
  1785. * break;
  1786. * //1
  1787. * case UE.dom.domUtils.POSITION_DISCONNECTED:
  1788. * console.log('两个节点在不同的文档中');
  1789. * break;
  1790. * //2
  1791. * case UE.dom.domUtils.POSITION_FOLLOWING:
  1792. * console.log('节点A在节点B之后');
  1793. * break;
  1794. * //4
  1795. * case UE.dom.domUtils.POSITION_PRECEDING;
  1796. * console.log('节点A在节点B之前');
  1797. * break;
  1798. * //8
  1799. * case UE.dom.domUtils.POSITION_IS_CONTAINED:
  1800. * console.log('节点A被节点B包含');
  1801. * break;
  1802. * case 10:
  1803. * console.log('节点A被节点B包含且节点A在节点B之后');
  1804. * break;
  1805. * //16
  1806. * case UE.dom.domUtils.POSITION_CONTAINS:
  1807. * console.log('节点A包含节点B');
  1808. * break;
  1809. * case 20:
  1810. * console.log('节点A包含节点B且节点A在节点B之前');
  1811. * break;
  1812. *
  1813. * }
  1814. * ```
  1815. */
  1816. getPosition:function (nodeA, nodeB) {
  1817. // 如果两个节点是同一个节点
  1818. if (nodeA === nodeB) {
  1819. // domUtils.POSITION_IDENTICAL
  1820. return 0;
  1821. }
  1822. var node,
  1823. parentsA = [nodeA],
  1824. parentsB = [nodeB];
  1825. node = nodeA;
  1826. while (node = node.parentNode) {
  1827. // 如果nodeB是nodeA的祖先节点
  1828. if (node === nodeB) {
  1829. // domUtils.POSITION_IS_CONTAINED + domUtils.POSITION_FOLLOWING
  1830. return 10;
  1831. }
  1832. parentsA.push(node);
  1833. }
  1834. node = nodeB;
  1835. while (node = node.parentNode) {
  1836. // 如果nodeA是nodeB的祖先节点
  1837. if (node === nodeA) {
  1838. // domUtils.POSITION_CONTAINS + domUtils.POSITION_PRECEDING
  1839. return 20;
  1840. }
  1841. parentsB.push(node);
  1842. }
  1843. parentsA.reverse();
  1844. parentsB.reverse();
  1845. if (parentsA[0] !== parentsB[0]) {
  1846. // domUtils.POSITION_DISCONNECTED
  1847. return 1;
  1848. }
  1849. var i = -1;
  1850. while (i++, parentsA[i] === parentsB[i]) {
  1851. }
  1852. nodeA = parentsA[i];
  1853. nodeB = parentsB[i];
  1854. while (nodeA = nodeA.nextSibling) {
  1855. if (nodeA === nodeB) {
  1856. // domUtils.POSITION_PRECEDING
  1857. return 4
  1858. }
  1859. }
  1860. // domUtils.POSITION_FOLLOWING
  1861. return 2;
  1862. },
  1863. /**
  1864. * 检测节点node在父节点中的索引位置
  1865. * @method getNodeIndex
  1866. * @param { Node } node 需要检测的节点对象
  1867. * @return { Number } 该节点在父节点中的位置
  1868. * @see UE.dom.domUtils.getNodeIndex(Node,Boolean)
  1869. */
  1870. /**
  1871. * 检测节点node在父节点中的索引位置, 根据给定的mergeTextNode参数决定是否要合并多个连续的文本节点为一个节点
  1872. * @method getNodeIndex
  1873. * @param { Node } node 需要检测的节点对象
  1874. * @param { Boolean } mergeTextNode 是否合并多个连续的文本节点为一个节点
  1875. * @return { Number } 该节点在父节点中的位置
  1876. * @example
  1877. * ```javascript
  1878. *
  1879. * var node = document.createElement("div");
  1880. *
  1881. * node.appendChild( document.createTextNode( "hello" ) );
  1882. * node.appendChild( document.createTextNode( "world" ) );
  1883. * node.appendChild( node = document.createElement( "div" ) );
  1884. *
  1885. * //output: 2
  1886. * console.log( UE.dom.domUtils.getNodeIndex( node ) );
  1887. *
  1888. * //output: 1
  1889. * console.log( UE.dom.domUtils.getNodeIndex( node, true ) );
  1890. *
  1891. * ```
  1892. */
  1893. getNodeIndex:function (node, ignoreTextNode) {
  1894. var preNode = node,
  1895. i = 0;
  1896. while (preNode = preNode.previousSibling) {
  1897. if (ignoreTextNode && preNode.nodeType == 3) {
  1898. if(preNode.nodeType != preNode.nextSibling.nodeType ){
  1899. i++;
  1900. }
  1901. continue;
  1902. }
  1903. i++;
  1904. }
  1905. return i;
  1906. },
  1907. /**
  1908. * 检测节点node是否在给定的document对象上
  1909. * @method inDoc
  1910. * @param { Node } node 需要检测的节点对象
  1911. * @param { DomDocument } doc 需要检测的document对象
  1912. * @return { Boolean } 该节点node是否在给定的document的dom树上
  1913. * @example
  1914. * ```javascript
  1915. *
  1916. * var node = document.createElement("div");
  1917. *
  1918. * //output: false
  1919. * console.log( UE.do.domUtils.inDoc( node, document ) );
  1920. *
  1921. * document.body.appendChild( node );
  1922. *
  1923. * //output: true
  1924. * console.log( UE.do.domUtils.inDoc( node, document ) );
  1925. *
  1926. * ```
  1927. */
  1928. inDoc:function (node, doc) {
  1929. return domUtils.getPosition(node, doc) == 10;
  1930. },
  1931. /**
  1932. * 根据给定的过滤规则filterFn, 查找符合该过滤规则的node节点的第一个祖先节点,
  1933. * 查找的起点是给定node节点的父节点。
  1934. * @method findParent
  1935. * @param { Node } node 需要查找的节点
  1936. * @param { Function } filterFn 自定义的过滤方法。
  1937. * @warning 查找的终点是到body节点为止
  1938. * @remind 自定义的过滤方法filterFn接受一个Node对象作为参数, 该对象代表当前执行检测的祖先节点。 如果该
  1939. * 节点满足过滤条件, 则要求返回true, 这时将直接返回该节点作为findParent()的结果, 否则, 请返回false。
  1940. * @return { Node | Null } 如果找到符合过滤条件的节点, 就返回该节点, 否则返回NULL
  1941. * @example
  1942. * ```javascript
  1943. * var filterNode = UE.dom.domUtils.findParent( document.body.firstChild, function ( node ) {
  1944. *
  1945. * //由于查找的终点是body节点, 所以永远也不会匹配当前过滤器的条件, 即这里永远会返回false
  1946. * return node.tagName === "HTML";
  1947. *
  1948. * } );
  1949. *
  1950. * //output: true
  1951. * console.log( filterNode === null );
  1952. * ```
  1953. */
  1954. /**
  1955. * 根据给定的过滤规则filterFn, 查找符合该过滤规则的node节点的第一个祖先节点,
  1956. * 如果includeSelf的值为true,则查找的起点是给定的节点node, 否则, 起点是node的父节点
  1957. * @method findParent
  1958. * @param { Node } node 需要查找的节点
  1959. * @param { Function } filterFn 自定义的过滤方法。
  1960. * @param { Boolean } includeSelf 查找过程是否包含自身
  1961. * @warning 查找的终点是到body节点为止
  1962. * @remind 自定义的过滤方法filterFn接受一个Node对象作为参数, 该对象代表当前执行检测的祖先节点。 如果该
  1963. * 节点满足过滤条件, 则要求返回true, 这时将直接返回该节点作为findParent()的结果, 否则, 请返回false。
  1964. * @remind 如果includeSelf为true, 则过滤器第一次执行时的参数会是节点本身。
  1965. * 反之, 过滤器第一次执行时的参数将是该节点的父节点。
  1966. * @return { Node | Null } 如果找到符合过滤条件的节点, 就返回该节点, 否则返回NULL
  1967. * @example
  1968. * ```html
  1969. * <body>
  1970. *
  1971. * <div id="test">
  1972. * </div>
  1973. *
  1974. * <script type="text/javascript">
  1975. *
  1976. * //output: DIV, BODY
  1977. * var filterNode = UE.dom.domUtils.findParent( document.getElementById( "test" ), function ( node ) {
  1978. *
  1979. * console.log( node.tagName );
  1980. * return false;
  1981. *
  1982. * }, true );
  1983. *
  1984. * </script>
  1985. * </body>
  1986. * ```
  1987. */
  1988. findParent:function (node, filterFn, includeSelf) {
  1989. if (node && !domUtils.isBody(node)) {
  1990. node = includeSelf ? node : node.parentNode;
  1991. while (node) {
  1992. if (!filterFn || filterFn(node) || domUtils.isBody(node)) {
  1993. return filterFn && !filterFn(node) && domUtils.isBody(node) ? null : node;
  1994. }
  1995. node = node.parentNode;
  1996. }
  1997. }
  1998. return null;
  1999. },
  2000. /**
  2001. * 查找node的节点名为tagName的第一个祖先节点, 查找的起点是node节点的父节点。
  2002. * @method findParentByTagName
  2003. * @param { Node } node 需要查找的节点对象
  2004. * @param { Array } tagNames 需要查找的父节点的名称数组
  2005. * @warning 查找的终点是到body节点为止
  2006. * @return { Node | NULL } 如果找到符合条件的节点, 则返回该节点, 否则返回NULL
  2007. * @example
  2008. * ```javascript
  2009. * var node = UE.dom.domUtils.findParentByTagName( document.getElementsByTagName("div")[0], [ "BODY" ] );
  2010. * //output: BODY
  2011. * console.log( node.tagName );
  2012. * ```
  2013. */
  2014. /**
  2015. * 查找node的节点名为tagName的祖先节点, 如果includeSelf的值为true,则查找的起点是给定的节点node,
  2016. * 否则, 起点是node的父节点。
  2017. * @method findParentByTagName
  2018. * @param { Node } node 需要查找的节点对象
  2019. * @param { Array } tagNames 需要查找的父节点的名称数组
  2020. * @param { Boolean } includeSelf 查找过程是否包含node节点自身
  2021. * @warning 查找的终点是到body节点为止
  2022. * @return { Node | NULL } 如果找到符合条件的节点, 则返回该节点, 否则返回NULL
  2023. * @example
  2024. * ```javascript
  2025. * var queryTarget = document.getElementsByTagName("div")[0];
  2026. * var node = UE.dom.domUtils.findParentByTagName( queryTarget, [ "DIV" ], true );
  2027. * //output: true
  2028. * console.log( queryTarget === node );
  2029. * ```
  2030. */
  2031. findParentByTagName:function (node, tagNames, includeSelf, excludeFn) {
  2032. tagNames = utils.listToMap(utils.isArray(tagNames) ? tagNames : [tagNames]);
  2033. return domUtils.findParent(node, function (node) {
  2034. return tagNames[node.tagName] && !(excludeFn && excludeFn(node));
  2035. }, includeSelf);
  2036. },
  2037. /**
  2038. * 查找节点node的祖先节点集合, 查找的起点是给定节点的父节点,结果集中不包含给定的节点。
  2039. * @method findParents
  2040. * @param { Node } node 需要查找的节点对象
  2041. * @return { Array } 给定节点的祖先节点数组
  2042. * @grammar UE.dom.domUtils.findParents(node) => Array //返回一个祖先节点数组集合,不包含自身
  2043. * @grammar UE.dom.domUtils.findParents(node,includeSelf) => Array //返回一个祖先节点数组集合,includeSelf指定是否包含自身
  2044. * @grammar UE.dom.domUtils.findParents(node,includeSelf,filterFn) => Array //返回一个祖先节点数组集合,filterFn指定过滤条件,返回true的node将被选取
  2045. * @grammar UE.dom.domUtils.findParents(node,includeSelf,filterFn,closerFirst) => Array //返回一个祖先节点数组集合,closerFirst为true的话,node的直接父亲节点是数组的第0个
  2046. */
  2047. /**
  2048. * 查找节点node的祖先节点集合, 如果includeSelf的值为true,
  2049. * 则返回的结果集中允许出现当前给定的节点, 否则, 该节点不会出现在其结果集中。
  2050. * @method findParents
  2051. * @param { Node } node 需要查找的节点对象
  2052. * @param { Boolean } includeSelf 查找的结果中是否允许包含当前查找的节点对象
  2053. * @return { Array } 给定节点的祖先节点数组
  2054. */
  2055. findParents:function (node, includeSelf, filterFn, closerFirst) {
  2056. var parents = includeSelf && ( filterFn && filterFn(node) || !filterFn ) ? [node] : [];
  2057. while (node = domUtils.findParent(node, filterFn)) {
  2058. parents.push(node);
  2059. }
  2060. return closerFirst ? parents : parents.reverse();
  2061. },
  2062. /**
  2063. * 在节点node后面插入新节点newNode
  2064. * @method insertAfter
  2065. * @param { Node } node 目标节点
  2066. * @param { Node } newNode 新插入的节点, 该节点将置于目标节点之后
  2067. * @return { Node } 新插入的节点
  2068. */
  2069. insertAfter:function (node, newNode) {
  2070. return node.nextSibling ? node.parentNode.insertBefore(newNode, node.nextSibling):
  2071. node.parentNode.appendChild(newNode);
  2072. },
  2073. /**
  2074. * 删除节点node及其下属的所有节点
  2075. * @method remove
  2076. * @param { Node } node 需要删除的节点对象
  2077. * @return { Node } 返回刚删除的节点对象
  2078. * @example
  2079. * ```html
  2080. * <div id="test">
  2081. * <div id="child">你好</div>
  2082. * </div>
  2083. * <script>
  2084. * UE.dom.domUtils.remove( document.body, false );
  2085. * //output: false
  2086. * console.log( document.getElementById( "child" ) !== null );
  2087. * </script>
  2088. * ```
  2089. */
  2090. /**
  2091. * 删除节点node,并根据keepChildren的值决定是否保留子节点
  2092. * @method remove
  2093. * @param { Node } node 需要删除的节点对象
  2094. * @param { Boolean } keepChildren 是否需要保留子节点
  2095. * @return { Node } 返回刚删除的节点对象
  2096. * @example
  2097. * ```html
  2098. * <div id="test">
  2099. * <div id="child">你好</div>
  2100. * </div>
  2101. * <script>
  2102. * UE.dom.domUtils.remove( document.body, true );
  2103. * //output: true
  2104. * console.log( document.getElementById( "child" ) !== null );
  2105. * </script>
  2106. * ```
  2107. */
  2108. remove:function (node, keepChildren) {
  2109. var parent = node.parentNode,
  2110. child;
  2111. if (parent) {
  2112. if (keepChildren && node.hasChildNodes()) {
  2113. while (child = node.firstChild) {
  2114. parent.insertBefore(child, node);
  2115. }
  2116. }
  2117. parent.removeChild(node);
  2118. }
  2119. return node;
  2120. },
  2121. /**
  2122. * 取得node节点的下一个兄弟节点, 如果该节点其后没有兄弟节点, 则递归查找其父节点之后的第一个兄弟节点,
  2123. * 直到找到满足条件的节点或者递归到BODY节点之后才会结束。
  2124. * @method getNextDomNode
  2125. * @param { Node } node 需要获取其后的兄弟节点的节点对象
  2126. * @return { Node | NULL } 如果找满足条件的节点, 则返回该节点, 否则返回NULL
  2127. * @example
  2128. * ```html
  2129. * <body>
  2130. * <div id="test">
  2131. * <span></span>
  2132. * </div>
  2133. * <i>xxx</i>
  2134. * </body>
  2135. * <script>
  2136. *
  2137. * //output: i节点
  2138. * console.log( UE.dom.domUtils.getNextDomNode( document.getElementById( "test" ) ) );
  2139. *
  2140. * </script>
  2141. * ```
  2142. * @example
  2143. * ```html
  2144. * <body>
  2145. * <div>
  2146. * <span></span>
  2147. * <i id="test">xxx</i>
  2148. * </div>
  2149. * <b>xxx</b>
  2150. * </body>
  2151. * <script>
  2152. *
  2153. * //由于id为test的i节点之后没有兄弟节点, 则查找其父节点(div)后面的兄弟节点
  2154. * //output: b节点
  2155. * console.log( UE.dom.domUtils.getNextDomNode( document.getElementById( "test" ) ) );
  2156. *
  2157. * </script>
  2158. * ```
  2159. */
  2160. /**
  2161. * 取得node节点的下一个兄弟节点, 如果startFromChild的值为ture,则先获取其子节点,
  2162. * 如果有子节点则直接返回第一个子节点;如果没有子节点或者startFromChild的值为false,
  2163. * 则执行<a href="#UE.dom.domUtils.getNextDomNode(Node)">getNextDomNode(Node node)</a>的查找过程。
  2164. * @method getNextDomNode
  2165. * @param { Node } node 需要获取其后的兄弟节点的节点对象
  2166. * @param { Boolean } startFromChild 查找过程是否从其子节点开始
  2167. * @return { Node | NULL } 如果找满足条件的节点, 则返回该节点, 否则返回NULL
  2168. * @see UE.dom.domUtils.getNextDomNode(Node)
  2169. */
  2170. getNextDomNode:function (node, startFromChild, filterFn, guard) {
  2171. return getDomNode(node, 'firstChild', 'nextSibling', startFromChild, filterFn, guard);
  2172. },
  2173. getPreDomNode:function (node, startFromChild, filterFn, guard) {
  2174. return getDomNode(node, 'lastChild', 'previousSibling', startFromChild, filterFn, guard);
  2175. },
  2176. /**
  2177. * 检测节点node是否属是UEditor定义的bookmark节点
  2178. * @method isBookmarkNode
  2179. * @private
  2180. * @param { Node } node 需要检测的节点对象
  2181. * @return { Boolean } 是否是bookmark节点
  2182. * @example
  2183. * ```html
  2184. * <span id="_baidu_bookmark_1"></span>
  2185. * <script>
  2186. * var bookmarkNode = document.getElementById("_baidu_bookmark_1");
  2187. * //output: true
  2188. * console.log( UE.dom.domUtils.isBookmarkNode( bookmarkNode ) );
  2189. * </script>
  2190. * ```
  2191. */
  2192. isBookmarkNode:function (node) {
  2193. return node.nodeType == 1 && node.id && /^_baidu_bookmark_/i.test(node.id);
  2194. },
  2195. /**
  2196. * 获取节点node所属的window对象
  2197. * @method getWindow
  2198. * @param { Node } node 节点对象
  2199. * @return { Window } 当前节点所属的window对象
  2200. * @example
  2201. * ```javascript
  2202. * //output: true
  2203. * console.log( UE.dom.domUtils.getWindow( document.body ) === window );
  2204. * ```
  2205. */
  2206. getWindow:function (node) {
  2207. var doc = node.ownerDocument || node;
  2208. return doc.defaultView || doc.parentWindow;
  2209. },
  2210. /**
  2211. * 获取离nodeA与nodeB最近的公共的祖先节点
  2212. * @method getCommonAncestor
  2213. * @param { Node } nodeA 第一个节点
  2214. * @param { Node } nodeB 第二个节点
  2215. * @remind 如果给定的两个节点是同一个节点, 将直接返回该节点。
  2216. * @return { Node | NULL } 如果未找到公共节点, 返回NULL, 否则返回最近的公共祖先节点。
  2217. * @example
  2218. * ```javascript
  2219. * var commonAncestor = UE.dom.domUtils.getCommonAncestor( document.body, document.body.firstChild );
  2220. * //output: true
  2221. * console.log( commonAncestor.tagName.toLowerCase() === 'body' );
  2222. * ```
  2223. */
  2224. getCommonAncestor:function (nodeA, nodeB) {
  2225. if (nodeA === nodeB)
  2226. return nodeA;
  2227. var parentsA = [nodeA] , parentsB = [nodeB], parent = nodeA, i = -1;
  2228. while (parent = parent.parentNode) {
  2229. if (parent === nodeB) {
  2230. return parent;
  2231. }
  2232. parentsA.push(parent);
  2233. }
  2234. parent = nodeB;
  2235. while (parent = parent.parentNode) {
  2236. if (parent === nodeA)
  2237. return parent;
  2238. parentsB.push(parent);
  2239. }
  2240. parentsA.reverse();
  2241. parentsB.reverse();
  2242. while (i++, parentsA[i] === parentsB[i]) {
  2243. }
  2244. return i == 0 ? null : parentsA[i - 1];
  2245. },
  2246. /**
  2247. * 清除node节点左右连续为空的兄弟inline节点
  2248. * @method clearEmptySibling
  2249. * @param { Node } node 执行的节点对象, 如果该节点的左右连续的兄弟节点是空的inline节点,
  2250. * 则这些兄弟节点将被删除
  2251. * @grammar UE.dom.domUtils.clearEmptySibling(node,ignoreNext) //ignoreNext指定是否忽略右边空节点
  2252. * @grammar UE.dom.domUtils.clearEmptySibling(node,ignoreNext,ignorePre) //ignorePre指定是否忽略左边空节点
  2253. * @example
  2254. * ```html
  2255. * <body>
  2256. * <div></div>
  2257. * <span id="test"></span>
  2258. * <i></i>
  2259. * <b></b>
  2260. * <em>xxx</em>
  2261. * <span></span>
  2262. * </body>
  2263. * <script>
  2264. *
  2265. * UE.dom.domUtils.clearEmptySibling( document.getElementById( "test" ) );
  2266. *
  2267. * //output: <div></div><span id="test"></span><em>xxx</em><span></span>
  2268. * console.log( document.body.innerHTML );
  2269. *
  2270. * </script>
  2271. * ```
  2272. */
  2273. /**
  2274. * 清除node节点左右连续为空的兄弟inline节点, 如果ignoreNext的值为true,
  2275. * 则忽略对右边兄弟节点的操作。
  2276. * @method clearEmptySibling
  2277. * @param { Node } node 执行的节点对象, 如果该节点的左右连续的兄弟节点是空的inline节点,
  2278. * @param { Boolean } ignoreNext 是否忽略忽略对右边的兄弟节点的操作
  2279. * 则这些兄弟节点将被删除
  2280. * @see UE.dom.domUtils.clearEmptySibling(Node)
  2281. */
  2282. /**
  2283. * 清除node节点左右连续为空的兄弟inline节点, 如果ignoreNext的值为true,
  2284. * 则忽略对右边兄弟节点的操作, 如果ignorePre的值为true,则忽略对左边兄弟节点的操作。
  2285. * @method clearEmptySibling
  2286. * @param { Node } node 执行的节点对象, 如果该节点的左右连续的兄弟节点是空的inline节点,
  2287. * @param { Boolean } ignoreNext 是否忽略忽略对右边的兄弟节点的操作
  2288. * @param { Boolean } ignorePre 是否忽略忽略对左边的兄弟节点的操作
  2289. * 则这些兄弟节点将被删除
  2290. * @see UE.dom.domUtils.clearEmptySibling(Node)
  2291. */
  2292. clearEmptySibling:function (node, ignoreNext, ignorePre) {
  2293. function clear(next, dir) {
  2294. var tmpNode;
  2295. while (next && !domUtils.isBookmarkNode(next) && (domUtils.isEmptyInlineElement(next)
  2296. //这里不能把空格算进来会吧空格干掉,出现文字间的空格丢掉了
  2297. || !new RegExp('[^\t\n\r' + domUtils.fillChar + ']').test(next.nodeValue) )) {
  2298. tmpNode = next[dir];
  2299. domUtils.remove(next);
  2300. next = tmpNode;
  2301. }
  2302. }
  2303. !ignoreNext && clear(node.nextSibling, 'nextSibling');
  2304. !ignorePre && clear(node.previousSibling, 'previousSibling');
  2305. },
  2306. /**
  2307. * 将一个文本节点textNode拆分成两个文本节点,offset指定拆分位置
  2308. * @method split
  2309. * @param { Node } textNode 需要拆分的文本节点对象
  2310. * @param { int } offset 需要拆分的位置, 位置计算从0开始
  2311. * @return { Node } 拆分后形成的新节点
  2312. * @example
  2313. * ```html
  2314. * <div id="test">abcdef</div>
  2315. * <script>
  2316. * var newNode = UE.dom.domUtils.split( document.getElementById( "test" ).firstChild, 3 );
  2317. * //output: def
  2318. * console.log( newNode.nodeValue );
  2319. * </script>
  2320. * ```
  2321. */
  2322. split:function (node, offset) {
  2323. var doc = node.ownerDocument;
  2324. if (browser.ie && offset == node.nodeValue.length) {
  2325. var next = doc.createTextNode('');
  2326. return domUtils.insertAfter(node, next);
  2327. }
  2328. var retval = node.splitText(offset);
  2329. //ie8下splitText不会跟新childNodes,我们手动触发他的更新
  2330. if (browser.ie8) {
  2331. var tmpNode = doc.createTextNode('');
  2332. domUtils.insertAfter(retval, tmpNode);
  2333. domUtils.remove(tmpNode);
  2334. }
  2335. return retval;
  2336. },
  2337. /**
  2338. * 检测文本节点textNode是否为空节点(包括空格、换行、占位符等字符)
  2339. * @method isWhitespace
  2340. * @param { Node } node 需要检测的节点对象
  2341. * @return { Boolean } 检测的节点是否为空
  2342. * @example
  2343. * ```html
  2344. * <div id="test">
  2345. *
  2346. * </div>
  2347. * <script>
  2348. * //output: true
  2349. * console.log( UE.dom.domUtils.isWhitespace( document.getElementById("test").firstChild ) );
  2350. * </script>
  2351. * ```
  2352. */
  2353. isWhitespace:function (node) {
  2354. return !new RegExp('[^ \t\n\r' + domUtils.fillChar + ']').test(node.nodeValue);
  2355. },
  2356. /**
  2357. * 获取元素element相对于viewport的位置坐标
  2358. * @method getXY
  2359. * @param { Node } element 需要计算位置的节点对象
  2360. * @return { Object } 返回形如{x:left,y:top}的一个key-value映射对象, 其中键x代表水平偏移距离,
  2361. * y代表垂直偏移距离。
  2362. *
  2363. * @example
  2364. * ```javascript
  2365. * var location = UE.dom.domUtils.getXY( document.getElementById("test") );
  2366. * //output: test的坐标为: 12, 24
  2367. * console.log( 'test的坐标为: ', location.x, ',', location.y );
  2368. * ```
  2369. */
  2370. getXY:function (element) {
  2371. var x = 0, y = 0;
  2372. while (element.offsetParent) {
  2373. y += element.offsetTop;
  2374. x += element.offsetLeft;
  2375. element = element.offsetParent;
  2376. }
  2377. return { 'x':x, 'y':y};
  2378. },
  2379. /**
  2380. * 为元素element绑定原生DOM事件,type为事件类型,handler为处理函数
  2381. * @method on
  2382. * @param { Node } element 需要绑定事件的节点对象
  2383. * @param { String } type 绑定的事件类型
  2384. * @param { Function } handler 事件处理器
  2385. * @example
  2386. * ```javascript
  2387. * UE.dom.domUtils.on(document.body,"click",function(e){
  2388. * //e为事件对象,this为被点击元素对戏那个
  2389. * });
  2390. * ```
  2391. */
  2392. /**
  2393. * 为元素element绑定原生DOM事件,type为事件类型,handler为处理函数
  2394. * @method on
  2395. * @param { Node } element 需要绑定事件的节点对象
  2396. * @param { Array } type 绑定的事件类型数组
  2397. * @param { Function } handler 事件处理器
  2398. * @example
  2399. * ```javascript
  2400. * UE.dom.domUtils.on(document.body,["click","mousedown"],function(evt){
  2401. * //evt为事件对象,this为被点击元素对象
  2402. * });
  2403. * ```
  2404. */
  2405. on:function (element, type, handler) {
  2406. var types = utils.isArray(type) ? type : utils.trim(type).split(/\s+/),
  2407. k = types.length;
  2408. if (k) while (k--) {
  2409. type = types[k];
  2410. if (element.addEventListener) {
  2411. element.addEventListener(type, handler, false);
  2412. } else {
  2413. if (!handler._d) {
  2414. handler._d = {
  2415. els : []
  2416. };
  2417. }
  2418. var key = type + handler.toString(),index = utils.indexOf(handler._d.els,element);
  2419. if (!handler._d[key] || index == -1) {
  2420. if(index == -1){
  2421. handler._d.els.push(element);
  2422. }
  2423. if(!handler._d[key]){
  2424. handler._d[key] = function (evt) {
  2425. return handler.call(evt.srcElement, evt || window.event);
  2426. };
  2427. }
  2428. element.attachEvent('on' + type, handler._d[key]);
  2429. }
  2430. }
  2431. }
  2432. element = null;
  2433. },
  2434. /**
  2435. * 解除DOM事件绑定
  2436. * @method un
  2437. * @param { Node } element 需要解除事件绑定的节点对象
  2438. * @param { String } type 需要接触绑定的事件类型
  2439. * @param { Function } handler 对应的事件处理器
  2440. * @example
  2441. * ```javascript
  2442. * UE.dom.domUtils.un(document.body,"click",function(evt){
  2443. * //evt为事件对象,this为被点击元素对象
  2444. * });
  2445. * ```
  2446. */
  2447. /**
  2448. * 解除DOM事件绑定
  2449. * @method un
  2450. * @param { Node } element 需要解除事件绑定的节点对象
  2451. * @param { Array } type 需要接触绑定的事件类型数组
  2452. * @param { Function } handler 对应的事件处理器
  2453. * @example
  2454. * ```javascript
  2455. * UE.dom.domUtils.un(document.body, ["click","mousedown"],function(evt){
  2456. * //evt为事件对象,this为被点击元素对象
  2457. * });
  2458. * ```
  2459. */
  2460. un:function (element, type, handler) {
  2461. var types = utils.isArray(type) ? type : utils.trim(type).split(/\s+/),
  2462. k = types.length;
  2463. if (k) while (k--) {
  2464. type = types[k];
  2465. if (element.removeEventListener) {
  2466. element.removeEventListener(type, handler, false);
  2467. } else {
  2468. var key = type + handler.toString();
  2469. try{
  2470. element.detachEvent('on' + type, handler._d ? handler._d[key] : handler);
  2471. }catch(e){}
  2472. if (handler._d && handler._d[key]) {
  2473. var index = utils.indexOf(handler._d.els,element);
  2474. if(index!=-1){
  2475. handler._d.els.splice(index,1);
  2476. }
  2477. handler._d.els.length == 0 && delete handler._d[key];
  2478. }
  2479. }
  2480. }
  2481. },
  2482. /**
  2483. * 比较节点nodeA与节点nodeB是否具有相同的标签名、属性名以及属性值
  2484. * @method isSameElement
  2485. * @param { Node } nodeA 需要比较的节点
  2486. * @param { Node } nodeB 需要比较的节点
  2487. * @return { Boolean } 两个节点是否具有相同的标签名、属性名以及属性值
  2488. * @example
  2489. * ```html
  2490. * <span style="font-size:12px">ssss</span>
  2491. * <span style="font-size:12px">bbbbb</span>
  2492. * <span style="font-size:13px">ssss</span>
  2493. * <span style="font-size:14px">bbbbb</span>
  2494. *
  2495. * <script>
  2496. *
  2497. * var nodes = document.getElementsByTagName( "span" );
  2498. *
  2499. * //output: true
  2500. * console.log( UE.dom.domUtils.isSameElement( nodes[0], nodes[1] ) );
  2501. *
  2502. * //output: false
  2503. * console.log( UE.dom.domUtils.isSameElement( nodes[2], nodes[3] ) );
  2504. *
  2505. * </script>
  2506. * ```
  2507. */
  2508. isSameElement:function (nodeA, nodeB) {
  2509. if (nodeA.tagName != nodeB.tagName) {
  2510. return false;
  2511. }
  2512. var thisAttrs = nodeA.attributes,
  2513. otherAttrs = nodeB.attributes;
  2514. if (!ie && thisAttrs.length != otherAttrs.length) {
  2515. return false;
  2516. }
  2517. var attrA, attrB, al = 0, bl = 0;
  2518. for (var i = 0; attrA = thisAttrs[i++];) {
  2519. if (attrA.nodeName == 'style') {
  2520. if (attrA.specified) {
  2521. al++;
  2522. }
  2523. if (domUtils.isSameStyle(nodeA, nodeB)) {
  2524. continue;
  2525. } else {
  2526. return false;
  2527. }
  2528. }
  2529. if (ie) {
  2530. if (attrA.specified) {
  2531. al++;
  2532. attrB = otherAttrs.getNamedItem(attrA.nodeName);
  2533. } else {
  2534. continue;
  2535. }
  2536. } else {
  2537. attrB = nodeB.attributes[attrA.nodeName];
  2538. }
  2539. if (!attrB.specified || attrA.nodeValue != attrB.nodeValue) {
  2540. return false;
  2541. }
  2542. }
  2543. // 有可能attrB的属性包含了attrA的属性之外还有自己的属性
  2544. if (ie) {
  2545. for (i = 0; attrB = otherAttrs[i++];) {
  2546. if (attrB.specified) {
  2547. bl++;
  2548. }
  2549. }
  2550. if (al != bl) {
  2551. return false;
  2552. }
  2553. }
  2554. return true;
  2555. },
  2556. /**
  2557. * 判断节点nodeA与节点nodeB的元素的style属性是否一致
  2558. * @method isSameStyle
  2559. * @param { Node } nodeA 需要比较的节点
  2560. * @param { Node } nodeB 需要比较的节点
  2561. * @return { Boolean } 两个节点是否具有相同的style属性值
  2562. * @example
  2563. * ```html
  2564. * <span style="font-size:12px">ssss</span>
  2565. * <span style="font-size:12px">bbbbb</span>
  2566. * <span style="font-size:13px">ssss</span>
  2567. * <span style="font-size:14px">bbbbb</span>
  2568. *
  2569. * <script>
  2570. *
  2571. * var nodes = document.getElementsByTagName( "span" );
  2572. *
  2573. * //output: true
  2574. * console.log( UE.dom.domUtils.isSameStyle( nodes[0], nodes[1] ) );
  2575. *
  2576. * //output: false
  2577. * console.log( UE.dom.domUtils.isSameStyle( nodes[2], nodes[3] ) );
  2578. *
  2579. * </script>
  2580. * ```
  2581. */
  2582. isSameStyle:function (nodeA, nodeB) {
  2583. var styleA = nodeA.style.cssText.replace(/( ?; ?)/g, ';').replace(/( ?: ?)/g, ':'),
  2584. styleB = nodeB.style.cssText.replace(/( ?; ?)/g, ';').replace(/( ?: ?)/g, ':');
  2585. if (browser.opera) {
  2586. styleA = nodeA.style;
  2587. styleB = nodeB.style;
  2588. if (styleA.length != styleB.length)
  2589. return false;
  2590. for (var p in styleA) {
  2591. if (/^(\d+|csstext)$/i.test(p)) {
  2592. continue;
  2593. }
  2594. if (styleA[p] != styleB[p]) {
  2595. return false;
  2596. }
  2597. }
  2598. return true;
  2599. }
  2600. if (!styleA || !styleB) {
  2601. return styleA == styleB;
  2602. }
  2603. styleA = styleA.split(';');
  2604. styleB = styleB.split(';');
  2605. if (styleA.length != styleB.length) {
  2606. return false;
  2607. }
  2608. for (var i = 0, ci; ci = styleA[i++];) {
  2609. if (utils.indexOf(styleB, ci) == -1) {
  2610. return false;
  2611. }
  2612. }
  2613. return true;
  2614. },
  2615. /**
  2616. * 检查节点node是否为block元素
  2617. * @method isBlockElm
  2618. * @param { Node } node 需要检测的节点对象
  2619. * @return { Boolean } 是否是block元素节点
  2620. * @warning 该方法的判断规则如下: 如果该元素原本是block元素, 则不论该元素当前的css样式是什么都会返回true;
  2621. * 否则,检测该元素的css样式, 如果该元素当前是block元素, 则返回true。 其余情况下都返回false。
  2622. * @example
  2623. * ```html
  2624. * <span id="test1" style="display: block"></span>
  2625. * <span id="test2"></span>
  2626. * <div id="test3" style="display: inline"></div>
  2627. *
  2628. * <script>
  2629. *
  2630. * //output: true
  2631. * console.log( UE.dom.domUtils.isBlockElm( document.getElementById("test1") ) );
  2632. *
  2633. * //output: false
  2634. * console.log( UE.dom.domUtils.isBlockElm( document.getElementById("test2") ) );
  2635. *
  2636. * //output: true
  2637. * console.log( UE.dom.domUtils.isBlockElm( document.getElementById("test3") ) );
  2638. *
  2639. * </script>
  2640. * ```
  2641. */
  2642. isBlockElm:function (node) {
  2643. return node.nodeType == 1 && (dtd.$block[node.tagName] || styleBlock[domUtils.getComputedStyle(node, 'display')]) && !dtd.$nonChild[node.tagName];
  2644. },
  2645. /**
  2646. * 检测node节点是否为body节点
  2647. * @method isBody
  2648. * @param { Element } node 需要检测的dom元素
  2649. * @return { Boolean } 给定的元素是否是body元素
  2650. * @example
  2651. * ```javascript
  2652. * //output: true
  2653. * console.log( UE.dom.domUtils.isBody( document.body ) );
  2654. * ```
  2655. */
  2656. isBody:function (node) {
  2657. return node && node.nodeType == 1 && node.tagName.toLowerCase() == 'body';
  2658. },
  2659. /**
  2660. * 以node节点为分界,将该节点的指定祖先节点parent拆分成两个独立的节点,
  2661. * 拆分形成的两个节点之间是node节点
  2662. * @method breakParent
  2663. * @param { Node } node 作为分界的节点对象
  2664. * @param { Node } parent 该节点必须是node节点的祖先节点, 且是block节点。
  2665. * @return { Node } 给定的node分界节点
  2666. * @example
  2667. * ```javascript
  2668. *
  2669. * var node = document.createElement("span"),
  2670. * wrapNode = document.createElement( "div" ),
  2671. * parent = document.createElement("p");
  2672. *
  2673. * parent.appendChild( node );
  2674. * wrapNode.appendChild( parent );
  2675. *
  2676. * //拆分前
  2677. * //output: <p><span></span></p>
  2678. * console.log( wrapNode.innerHTML );
  2679. *
  2680. *
  2681. * UE.dom.domUtils.breakParent( node, parent );
  2682. * //拆分后
  2683. * //output: <p></p><span></span><p></p>
  2684. * console.log( wrapNode.innerHTML );
  2685. *
  2686. * ```
  2687. */
  2688. breakParent:function (node, parent) {
  2689. var tmpNode,
  2690. parentClone = node,
  2691. clone = node,
  2692. leftNodes,
  2693. rightNodes;
  2694. do {
  2695. parentClone = parentClone.parentNode;
  2696. if (leftNodes) {
  2697. tmpNode = parentClone.cloneNode(false);
  2698. tmpNode.appendChild(leftNodes);
  2699. leftNodes = tmpNode;
  2700. tmpNode = parentClone.cloneNode(false);
  2701. tmpNode.appendChild(rightNodes);
  2702. rightNodes = tmpNode;
  2703. } else {
  2704. leftNodes = parentClone.cloneNode(false);
  2705. rightNodes = leftNodes.cloneNode(false);
  2706. }
  2707. while (tmpNode = clone.previousSibling) {
  2708. leftNodes.insertBefore(tmpNode, leftNodes.firstChild);
  2709. }
  2710. while (tmpNode = clone.nextSibling) {
  2711. rightNodes.appendChild(tmpNode);
  2712. }
  2713. clone = parentClone;
  2714. } while (parent !== parentClone);
  2715. tmpNode = parent.parentNode;
  2716. tmpNode.insertBefore(leftNodes, parent);
  2717. tmpNode.insertBefore(rightNodes, parent);
  2718. tmpNode.insertBefore(node, rightNodes);
  2719. domUtils.remove(parent);
  2720. return node;
  2721. },
  2722. /**
  2723. * 检查节点node是否是空inline节点
  2724. * @method isEmptyInlineElement
  2725. * @param { Node } node 需要检测的节点对象
  2726. * @return { Number } 如果给定的节点是空的inline节点, 则返回1, 否则返回0。
  2727. * @example
  2728. * ```html
  2729. * <b><i></i></b> => 1
  2730. * <b><i></i><u></u></b> => 1
  2731. * <b></b> => 1
  2732. * <b>xx<i></i></b> => 0
  2733. * ```
  2734. */
  2735. isEmptyInlineElement:function (node) {
  2736. if (node.nodeType != 1 || !dtd.$removeEmpty[ node.tagName ]) {
  2737. return 0;
  2738. }
  2739. node = node.firstChild;
  2740. while (node) {
  2741. //如果是创建的bookmark就跳过
  2742. if (domUtils.isBookmarkNode(node)) {
  2743. return 0;
  2744. }
  2745. if (node.nodeType == 1 && !domUtils.isEmptyInlineElement(node) ||
  2746. node.nodeType == 3 && !domUtils.isWhitespace(node)
  2747. ) {
  2748. return 0;
  2749. }
  2750. node = node.nextSibling;
  2751. }
  2752. return 1;
  2753. },
  2754. /**
  2755. * 删除node节点下首尾两端的空白文本子节点
  2756. * @method trimWhiteTextNode
  2757. * @param { Element } node 需要执行删除操作的元素对象
  2758. * @example
  2759. * ```javascript
  2760. * var node = document.createElement("div");
  2761. *
  2762. * node.appendChild( document.createTextNode( "" ) );
  2763. *
  2764. * node.appendChild( document.createElement("div") );
  2765. *
  2766. * node.appendChild( document.createTextNode( "" ) );
  2767. *
  2768. * //3
  2769. * console.log( node.childNodes.length );
  2770. *
  2771. * UE.dom.domUtils.trimWhiteTextNode( node );
  2772. *
  2773. * //1
  2774. * console.log( node.childNodes.length );
  2775. * ```
  2776. */
  2777. trimWhiteTextNode:function (node) {
  2778. function remove(dir) {
  2779. var child;
  2780. while ((child = node[dir]) && child.nodeType == 3 && domUtils.isWhitespace(child)) {
  2781. node.removeChild(child);
  2782. }
  2783. }
  2784. remove('firstChild');
  2785. remove('lastChild');
  2786. },
  2787. /**
  2788. * 合并node节点下相同的子节点
  2789. * @name mergeChild
  2790. * @desc
  2791. * UE.dom.domUtils.mergeChild(node,tagName) //tagName要合并的子节点的标签
  2792. * @example
  2793. * <p><span style="font-size:12px;">xx<span style="font-size:12px;">aa</span>xx</span></p>
  2794. * ==> UE.dom.domUtils.mergeChild(node,'span')
  2795. * <p><span style="font-size:12px;">xxaaxx</span></p>
  2796. */
  2797. mergeChild:function (node, tagName, attrs) {
  2798. var list = domUtils.getElementsByTagName(node, node.tagName.toLowerCase());
  2799. for (var i = 0, ci; ci = list[i++];) {
  2800. if (!ci.parentNode || domUtils.isBookmarkNode(ci)) {
  2801. continue;
  2802. }
  2803. //span单独处理
  2804. if (ci.tagName.toLowerCase() == 'span') {
  2805. if (node === ci.parentNode) {
  2806. domUtils.trimWhiteTextNode(node);
  2807. if (node.childNodes.length == 1) {
  2808. node.style.cssText = ci.style.cssText + ";" + node.style.cssText;
  2809. domUtils.remove(ci, true);
  2810. continue;
  2811. }
  2812. }
  2813. ci.style.cssText = node.style.cssText + ';' + ci.style.cssText;
  2814. if (attrs) {
  2815. var style = attrs.style;
  2816. if (style) {
  2817. style = style.split(';');
  2818. for (var j = 0, s; s = style[j++];) {
  2819. ci.style[utils.cssStyleToDomStyle(s.split(':')[0])] = s.split(':')[1];
  2820. }
  2821. }
  2822. }
  2823. if (domUtils.isSameStyle(ci, node)) {
  2824. domUtils.remove(ci, true);
  2825. }
  2826. continue;
  2827. }
  2828. if (domUtils.isSameElement(node, ci)) {
  2829. domUtils.remove(ci, true);
  2830. }
  2831. }
  2832. },
  2833. /**
  2834. * 原生方法getElementsByTagName的封装
  2835. * @method getElementsByTagName
  2836. * @param { Node } node 目标节点对象
  2837. * @param { String } tagName 需要查找的节点的tagName, 多个tagName以空格分割
  2838. * @return { Array } 符合条件的节点集合
  2839. */
  2840. getElementsByTagName:function (node, name,filter) {
  2841. if(filter && utils.isString(filter)){
  2842. var className = filter;
  2843. filter = function(node){return domUtils.hasClass(node,className)}
  2844. }
  2845. name = utils.trim(name).replace(/[ ]{2,}/g,' ').split(' ');
  2846. var arr = [];
  2847. for(var n = 0,ni;ni=name[n++];){
  2848. var list = node.getElementsByTagName(ni);
  2849. for (var i = 0, ci; ci = list[i++];) {
  2850. if(!filter || filter(ci))
  2851. arr.push(ci);
  2852. }
  2853. }
  2854. return arr;
  2855. },
  2856. /**
  2857. * 将节点node提取到父节点上
  2858. * @method mergeToParent
  2859. * @param { Element } node 需要提取的元素对象
  2860. * @example
  2861. * ```html
  2862. * <div id="parent">
  2863. * <div id="sub">
  2864. * <span id="child"></span>
  2865. * </div>
  2866. * </div>
  2867. *
  2868. * <script>
  2869. *
  2870. * var child = document.getElementById( "child" );
  2871. *
  2872. * //output: sub
  2873. * console.log( child.parentNode.id );
  2874. *
  2875. * UE.dom.domUtils.mergeToParent( child );
  2876. *
  2877. * //output: parent
  2878. * console.log( child.parentNode.id );
  2879. *
  2880. * </script>
  2881. * ```
  2882. */
  2883. mergeToParent:function (node) {
  2884. var parent = node.parentNode;
  2885. while (parent && dtd.$removeEmpty[parent.tagName]) {
  2886. if (parent.tagName == node.tagName || parent.tagName == 'A') {//针对a标签单独处理
  2887. domUtils.trimWhiteTextNode(parent);
  2888. //span需要特殊处理 不处理这样的情况 <span stlye="color:#fff">xxx<span style="color:#ccc">xxx</span>xxx</span>
  2889. if (parent.tagName == 'SPAN' && !domUtils.isSameStyle(parent, node)
  2890. || (parent.tagName == 'A' && node.tagName == 'SPAN')) {
  2891. if (parent.childNodes.length > 1 || parent !== node.parentNode) {
  2892. node.style.cssText = parent.style.cssText + ";" + node.style.cssText;
  2893. parent = parent.parentNode;
  2894. continue;
  2895. } else {
  2896. parent.style.cssText += ";" + node.style.cssText;
  2897. //trace:952 a标签要保持下划线
  2898. if (parent.tagName == 'A') {
  2899. parent.style.textDecoration = 'underline';
  2900. }
  2901. }
  2902. }
  2903. if (parent.tagName != 'A') {
  2904. parent === node.parentNode && domUtils.remove(node, true);
  2905. break;
  2906. }
  2907. }
  2908. parent = parent.parentNode;
  2909. }
  2910. },
  2911. /**
  2912. * 合并节点node的左右兄弟节点
  2913. * @method mergeSibling
  2914. * @param { Element } node 需要合并的目标节点
  2915. * @example
  2916. * ```html
  2917. * <b>xxxx</b><b id="test">ooo</b><b>xxxx</b>
  2918. *
  2919. * <script>
  2920. * var demoNode = document.getElementById("test");
  2921. * UE.dom.domUtils.mergeSibling( demoNode );
  2922. * //output: xxxxoooxxxx
  2923. * console.log( demoNode.innerHTML );
  2924. * </script>
  2925. * ```
  2926. */
  2927. /**
  2928. * 合并节点node的左右兄弟节点, 可以根据给定的条件选择是否忽略合并左节点。
  2929. * @method mergeSibling
  2930. * @param { Element } node 需要合并的目标节点
  2931. * @param { Boolean } ignorePre 是否忽略合并左节点
  2932. * @example
  2933. * ```html
  2934. * <b>xxxx</b><b id="test">ooo</b><b>xxxx</b>
  2935. *
  2936. * <script>
  2937. * var demoNode = document.getElementById("test");
  2938. * UE.dom.domUtils.mergeSibling( demoNode, true );
  2939. * //output: oooxxxx
  2940. * console.log( demoNode.innerHTML );
  2941. * </script>
  2942. * ```
  2943. */
  2944. /**
  2945. * 合并节点node的左右兄弟节点,可以根据给定的条件选择是否忽略合并左右节点。
  2946. * @method mergeSibling
  2947. * @param { Element } node 需要合并的目标节点
  2948. * @param { Boolean } ignorePre 是否忽略合并左节点
  2949. * @param { Boolean } ignoreNext 是否忽略合并右节点
  2950. * @remind 如果同时忽略左右节点, 则该操作什么也不会做
  2951. * @example
  2952. * ```html
  2953. * <b>xxxx</b><b id="test">ooo</b><b>xxxx</b>
  2954. *
  2955. * <script>
  2956. * var demoNode = document.getElementById("test");
  2957. * UE.dom.domUtils.mergeSibling( demoNode, false, true );
  2958. * //output: xxxxooo
  2959. * console.log( demoNode.innerHTML );
  2960. * </script>
  2961. * ```
  2962. */
  2963. mergeSibling:function (node, ignorePre, ignoreNext) {
  2964. function merge(rtl, start, node) {
  2965. var next;
  2966. if ((next = node[rtl]) && !domUtils.isBookmarkNode(next) && next.nodeType == 1 && domUtils.isSameElement(node, next)) {
  2967. while (next.firstChild) {
  2968. if (start == 'firstChild') {
  2969. node.insertBefore(next.lastChild, node.firstChild);
  2970. } else {
  2971. node.appendChild(next.firstChild);
  2972. }
  2973. }
  2974. domUtils.remove(next);
  2975. }
  2976. }
  2977. !ignorePre && merge('previousSibling', 'firstChild', node);
  2978. !ignoreNext && merge('nextSibling', 'lastChild', node);
  2979. },
  2980. /**
  2981. * 设置节点node及其子节点不会被选中
  2982. * @method unSelectable
  2983. * @param { Element } node 需要执行操作的dom元素
  2984. * @remind 执行该操作后的节点, 将不能被鼠标选中
  2985. * @example
  2986. * ```javascript
  2987. * UE.dom.domUtils.unSelectable( document.body );
  2988. * ```
  2989. */
  2990. unSelectable:ie && browser.ie9below || browser.opera ? function (node) {
  2991. //for ie9
  2992. node.onselectstart = function () {
  2993. return false;
  2994. };
  2995. node.onclick = node.onkeyup = node.onkeydown = function () {
  2996. return false;
  2997. };
  2998. node.unselectable = 'on';
  2999. node.setAttribute("unselectable", "on");
  3000. for (var i = 0, ci; ci = node.all[i++];) {
  3001. switch (ci.tagName.toLowerCase()) {
  3002. case 'iframe' :
  3003. case 'textarea' :
  3004. case 'input' :
  3005. case 'select' :
  3006. break;
  3007. default :
  3008. ci.unselectable = 'on';
  3009. node.setAttribute("unselectable", "on");
  3010. }
  3011. }
  3012. } : function (node) {
  3013. node.style.MozUserSelect =
  3014. node.style.webkitUserSelect =
  3015. node.style.msUserSelect =
  3016. node.style.KhtmlUserSelect = 'none';
  3017. },
  3018. /**
  3019. * 删除节点node上的指定属性名称的属性
  3020. * @method removeAttributes
  3021. * @param { Node } node 需要删除属性的节点对象
  3022. * @param { String } attrNames 可以是空格隔开的多个属性名称,该操作将会依次删除相应的属性
  3023. * @example
  3024. * ```html
  3025. * <div id="wrap">
  3026. * <span style="font-size:14px;" id="test" name="followMe">xxxxx</span>
  3027. * </div>
  3028. *
  3029. * <script>
  3030. *
  3031. * UE.dom.domUtils.removeAttributes( document.getElementById( "test" ), "id name" );
  3032. *
  3033. * //output: <span style="font-size:14px;">xxxxx</span>
  3034. * console.log( document.getElementById("wrap").innerHTML );
  3035. *
  3036. * </script>
  3037. * ```
  3038. */
  3039. /**
  3040. * 删除节点node上的指定属性名称的属性
  3041. * @method removeAttributes
  3042. * @param { Node } node 需要删除属性的节点对象
  3043. * @param { Array } attrNames 需要删除的属性名数组
  3044. * @example
  3045. * ```html
  3046. * <div id="wrap">
  3047. * <span style="font-size:14px;" id="test" name="followMe">xxxxx</span>
  3048. * </div>
  3049. *
  3050. * <script>
  3051. *
  3052. * UE.dom.domUtils.removeAttributes( document.getElementById( "test" ), ["id", "name"] );
  3053. *
  3054. * //output: <span style="font-size:14px;">xxxxx</span>
  3055. * console.log( document.getElementById("wrap").innerHTML );
  3056. *
  3057. * </script>
  3058. * ```
  3059. */
  3060. removeAttributes:function (node, attrNames) {
  3061. attrNames = utils.isArray(attrNames) ? attrNames : utils.trim(attrNames).replace(/[ ]{2,}/g,' ').split(' ');
  3062. for (var i = 0, ci; ci = attrNames[i++];) {
  3063. ci = attrFix[ci] || ci;
  3064. switch (ci) {
  3065. case 'className':
  3066. node[ci] = '';
  3067. break;
  3068. case 'style':
  3069. node.style.cssText = '';
  3070. var val = node.getAttributeNode('style');
  3071. !browser.ie && val && node.removeAttributeNode(val);
  3072. }
  3073. node.removeAttribute(ci);
  3074. }
  3075. },
  3076. /**
  3077. * 在doc下创建一个标签名为tag,属性为attrs的元素
  3078. * @method createElement
  3079. * @param { DomDocument } doc 新创建的元素属于该document节点创建
  3080. * @param { String } tagName 需要创建的元素的标签名
  3081. * @param { Object } attrs 新创建的元素的属性key-value集合
  3082. * @return { Element } 新创建的元素对象
  3083. * @example
  3084. * ```javascript
  3085. * var ele = UE.dom.domUtils.createElement( document, 'div', {
  3086. * id: 'test'
  3087. * } );
  3088. *
  3089. * //output: DIV
  3090. * console.log( ele.tagName );
  3091. *
  3092. * //output: test
  3093. * console.log( ele.id );
  3094. *
  3095. * ```
  3096. */
  3097. createElement:function (doc, tag, attrs) {
  3098. return domUtils.setAttributes(doc.createElement(tag), attrs)
  3099. },
  3100. /**
  3101. * 为节点node添加属性attrs,attrs为属性键值对
  3102. * @method setAttributes
  3103. * @param { Element } node 需要设置属性的元素对象
  3104. * @param { Object } attrs 需要设置的属性名-值对
  3105. * @return { Element } 设置属性的元素对象
  3106. * @example
  3107. * ```html
  3108. * <span id="test"></span>
  3109. *
  3110. * <script>
  3111. *
  3112. * var testNode = UE.dom.domUtils.setAttributes( document.getElementById( "test" ), {
  3113. * id: 'demo'
  3114. * } );
  3115. *
  3116. * //output: demo
  3117. * console.log( testNode.id );
  3118. *
  3119. * </script>
  3120. *
  3121. */
  3122. setAttributes:function (node, attrs) {
  3123. for (var attr in attrs) {
  3124. if(attrs.hasOwnProperty(attr)){
  3125. var value = attrs[attr];
  3126. switch (attr) {
  3127. case 'class':
  3128. //ie下要这样赋值,setAttribute不起作用
  3129. node.className = value;
  3130. break;
  3131. case 'style' :
  3132. node.style.cssText = node.style.cssText + ";" + value;
  3133. break;
  3134. case 'innerHTML':
  3135. node[attr] = value;
  3136. break;
  3137. case 'value':
  3138. node.value = value;
  3139. break;
  3140. default:
  3141. node.setAttribute(attrFix[attr] || attr, value);
  3142. }
  3143. }
  3144. }
  3145. return node;
  3146. },
  3147. /**
  3148. * 获取元素element经过计算后的样式值
  3149. * @method getComputedStyle
  3150. * @param { Element } element 需要获取样式的元素对象
  3151. * @param { String } styleName 需要获取的样式名
  3152. * @return { String } 获取到的样式值
  3153. * @example
  3154. * ```html
  3155. * <style type="text/css">
  3156. * #test {
  3157. * font-size: 15px;
  3158. * }
  3159. * </style>
  3160. *
  3161. * <span id="test"></span>
  3162. *
  3163. * <script>
  3164. * //output: 15px
  3165. * console.log( UE.dom.domUtils.getComputedStyle( document.getElementById( "test" ), 'font-size' ) );
  3166. * </script>
  3167. * ```
  3168. */
  3169. getComputedStyle:function (element, styleName) {
  3170. //一下的属性单独处理
  3171. var pros = 'width height top left';
  3172. if(pros.indexOf(styleName) > -1){
  3173. return element['offset' + styleName.replace(/^\w/,function(s){return s.toUpperCase()})] + 'px';
  3174. }
  3175. //忽略文本节点
  3176. if (element.nodeType == 3) {
  3177. element = element.parentNode;
  3178. }
  3179. //ie下font-size若body下定义了font-size,则从currentStyle里会取到这个font-size. 取不到实际值,故此修改.
  3180. if (browser.ie && browser.version < 9 && styleName == 'font-size' && !element.style.fontSize &&
  3181. !dtd.$empty[element.tagName] && !dtd.$nonChild[element.tagName]) {
  3182. var span = element.ownerDocument.createElement('span');
  3183. span.style.cssText = 'padding:0;border:0;font-family:simsun;';
  3184. span.innerHTML = '.';
  3185. element.appendChild(span);
  3186. var result = span.offsetHeight;
  3187. element.removeChild(span);
  3188. span = null;
  3189. return result + 'px';
  3190. }
  3191. try {
  3192. var value = domUtils.getStyle(element, styleName) ||
  3193. (window.getComputedStyle ? domUtils.getWindow(element).getComputedStyle(element, '').getPropertyValue(styleName) :
  3194. ( element.currentStyle || element.style )[utils.cssStyleToDomStyle(styleName)]);
  3195. } catch (e) {
  3196. return "";
  3197. }
  3198. return utils.transUnitToPx(utils.fixColor(styleName, value));
  3199. },
  3200. /**
  3201. * 删除元素element指定的className
  3202. * @method removeClasses
  3203. * @param { Element } ele 需要删除class的元素节点
  3204. * @param { String } classNames 需要删除的className, 多个className之间以空格分开
  3205. * @example
  3206. * ```html
  3207. * <span id="test" class="test1 test2 test3">xxx</span>
  3208. *
  3209. * <script>
  3210. *
  3211. * var testNode = document.getElementById( "test" );
  3212. * UE.dom.domUtils.removeClasses( testNode, "test1 test2" );
  3213. *
  3214. * //output: test3
  3215. * console.log( testNode.className );
  3216. *
  3217. * </script>
  3218. * ```
  3219. */
  3220. /**
  3221. * 删除元素element指定的className
  3222. * @method removeClasses
  3223. * @param { Element } ele 需要删除class的元素节点
  3224. * @param { Array } classNames 需要删除的className数组
  3225. * @example
  3226. * ```html
  3227. * <span id="test" class="test1 test2 test3">xxx</span>
  3228. *
  3229. * <script>
  3230. *
  3231. * var testNode = document.getElementById( "test" );
  3232. * UE.dom.domUtils.removeClasses( testNode, ["test1", "test2"] );
  3233. *
  3234. * //output: test3
  3235. * console.log( testNode.className );
  3236. *
  3237. * </script>
  3238. * ```
  3239. */
  3240. removeClasses:function (elm, classNames) {
  3241. classNames = utils.isArray(classNames) ? classNames :
  3242. utils.trim(classNames).replace(/[ ]{2,}/g,' ').split(' ');
  3243. for(var i = 0,ci,cls = elm.className;ci=classNames[i++];){
  3244. cls = cls.replace(new RegExp('\\b' + ci + '\\b'),'')
  3245. }
  3246. cls = utils.trim(cls).replace(/[ ]{2,}/g,' ');
  3247. if(cls){
  3248. elm.className = cls;
  3249. }else{
  3250. domUtils.removeAttributes(elm,['class']);
  3251. }
  3252. },
  3253. /**
  3254. * 给元素element添加className
  3255. * @method addClass
  3256. * @param { Node } ele 需要增加className的元素
  3257. * @param { String } classNames 需要添加的className, 多个className之间以空格分割
  3258. * @remind 相同的类名不会被重复添加
  3259. * @example
  3260. * ```html
  3261. * <span id="test" class="cls1 cls2"></span>
  3262. *
  3263. * <script>
  3264. * var testNode = document.getElementById("test");
  3265. *
  3266. * UE.dom.domUtils.addClass( testNode, "cls2 cls3 cls4" );
  3267. *
  3268. * //output: cl1 cls2 cls3 cls4
  3269. * console.log( testNode.className );
  3270. *
  3271. * <script>
  3272. * ```
  3273. */
  3274. /**
  3275. * 给元素element添加className
  3276. * @method addClass
  3277. * @param { Node } ele 需要增加className的元素
  3278. * @param { Array } classNames 需要添加的className的数组
  3279. * @remind 相同的类名不会被重复添加
  3280. * @example
  3281. * ```html
  3282. * <span id="test" class="cls1 cls2"></span>
  3283. *
  3284. * <script>
  3285. * var testNode = document.getElementById("test");
  3286. *
  3287. * UE.dom.domUtils.addClass( testNode, ["cls2", "cls3", "cls4"] );
  3288. *
  3289. * //output: cl1 cls2 cls3 cls4
  3290. * console.log( testNode.className );
  3291. *
  3292. * <script>
  3293. * ```
  3294. */
  3295. addClass:function (elm, classNames) {
  3296. if(!elm)return;
  3297. classNames = utils.trim(classNames).replace(/[ ]{2,}/g,' ').split(' ');
  3298. for(var i = 0,ci,cls = elm.className;ci=classNames[i++];){
  3299. if(!new RegExp('\\b' + ci + '\\b').test(cls)){
  3300. cls += ' ' + ci;
  3301. }
  3302. }
  3303. elm.className = utils.trim(cls);
  3304. },
  3305. /**
  3306. * 判断元素element是否包含给定的样式类名className
  3307. * @method hasClass
  3308. * @param { Node } ele 需要检测的元素
  3309. * @param { String } classNames 需要检测的className, 多个className之间用空格分割
  3310. * @return { Boolean } 元素是否包含所有给定的className
  3311. * @example
  3312. * ```html
  3313. * <span id="test1" class="cls1 cls2"></span>
  3314. *
  3315. * <script>
  3316. * var test1 = document.getElementById("test1");
  3317. *
  3318. * //output: false
  3319. * console.log( UE.dom.domUtils.hasClass( test1, "cls2 cls1 cls3" ) );
  3320. *
  3321. * //output: true
  3322. * console.log( UE.dom.domUtils.hasClass( test1, "cls2 cls1" ) );
  3323. * </script>
  3324. * ```
  3325. */
  3326. /**
  3327. * 判断元素element是否包含给定的样式类名className
  3328. * @method hasClass
  3329. * @param { Node } ele 需要检测的元素
  3330. * @param { Array } classNames 需要检测的className数组
  3331. * @return { Boolean } 元素是否包含所有给定的className
  3332. * @example
  3333. * ```html
  3334. * <span id="test1" class="cls1 cls2"></span>
  3335. *
  3336. * <script>
  3337. * var test1 = document.getElementById("test1");
  3338. *
  3339. * //output: false
  3340. * console.log( UE.dom.domUtils.hasClass( test1, [ "cls2", "cls1", "cls3" ] ) );
  3341. *
  3342. * //output: true
  3343. * console.log( UE.dom.domUtils.hasClass( test1, [ "cls2", "cls1" ]) );
  3344. * </script>
  3345. * ```
  3346. */
  3347. hasClass:function (element, className) {
  3348. if(utils.isRegExp(className)){
  3349. return className.test(element.className)
  3350. }
  3351. className = utils.trim(className).replace(/[ ]{2,}/g,' ').split(' ');
  3352. for(var i = 0,ci,cls = element.className;ci=className[i++];){
  3353. if(!new RegExp('\\b' + ci + '\\b','i').test(cls)){
  3354. return false;
  3355. }
  3356. }
  3357. return i - 1 == className.length;
  3358. },
  3359. /**
  3360. * 阻止事件默认行为
  3361. * @method preventDefault
  3362. * @param { Event } evt 需要阻止默认行为的事件对象
  3363. * @example
  3364. * ```javascript
  3365. * UE.dom.domUtils.preventDefault( evt );
  3366. * ```
  3367. */
  3368. preventDefault:function (evt) {
  3369. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  3370. },
  3371. /**
  3372. * 删除元素element指定的样式
  3373. * @method removeStyle
  3374. * @param { Element } element 需要删除样式的元素
  3375. * @param { String } styleName 需要删除的样式名
  3376. * @example
  3377. * ```html
  3378. * <span id="test" style="color: red; background: blue;"></span>
  3379. *
  3380. * <script>
  3381. *
  3382. * var testNode = document.getElementById("test");
  3383. *
  3384. * UE.dom.domUtils.removeStyle( testNode, 'color' );
  3385. *
  3386. * //output: background: blue;
  3387. * console.log( testNode.style.cssText );
  3388. *
  3389. * </script>
  3390. * ```
  3391. */
  3392. removeStyle:function (element, name) {
  3393. if(browser.ie ){
  3394. //针对color先单独处理一下
  3395. if(name == 'color'){
  3396. name = '(^|;)' + name;
  3397. }
  3398. element.style.cssText = element.style.cssText.replace(new RegExp(name + '[^:]*:[^;]+;?','ig'),'')
  3399. }else{
  3400. if (element.style.removeProperty) {
  3401. element.style.removeProperty (name);
  3402. }else {
  3403. element.style.removeAttribute (utils.cssStyleToDomStyle(name));
  3404. }
  3405. }
  3406. if (!element.style.cssText) {
  3407. domUtils.removeAttributes(element, ['style']);
  3408. }
  3409. },
  3410. /**
  3411. * 获取元素element的style属性的指定值
  3412. * @method getStyle
  3413. * @param { Element } element 需要获取属性值的元素
  3414. * @param { String } styleName 需要获取的style的名称
  3415. * @warning 该方法仅获取元素style属性中所标明的值
  3416. * @return { String } 该元素包含指定的style属性值
  3417. * @example
  3418. * ```html
  3419. * <div id="test" style="color: red;"></div>
  3420. *
  3421. * <script>
  3422. *
  3423. * var testNode = document.getElementById( "test" );
  3424. *
  3425. * //output: red
  3426. * console.log( UE.dom.domUtils.getStyle( testNode, "color" ) );
  3427. *
  3428. * //output: ""
  3429. * console.log( UE.dom.domUtils.getStyle( testNode, "background" ) );
  3430. *
  3431. * </script>
  3432. * ```
  3433. */
  3434. getStyle:function (element, name) {
  3435. var value = element.style[ utils.cssStyleToDomStyle(name) ];
  3436. return utils.fixColor(name, value);
  3437. },
  3438. /**
  3439. * 为元素element设置样式属性值
  3440. * @method setStyle
  3441. * @param { Element } element 需要设置样式的元素
  3442. * @param { String } styleName 样式名
  3443. * @param { String } styleValue 样式值
  3444. * @example
  3445. * ```html
  3446. * <div id="test"></div>
  3447. *
  3448. * <script>
  3449. *
  3450. * var testNode = document.getElementById( "test" );
  3451. *
  3452. * //output: ""
  3453. * console.log( testNode.style.color );
  3454. *
  3455. * UE.dom.domUtils.setStyle( testNode, 'color', 'red' );
  3456. * //output: "red"
  3457. * console.log( testNode.style.color );
  3458. *
  3459. * </script>
  3460. * ```
  3461. */
  3462. setStyle:function (element, name, value) {
  3463. element.style[utils.cssStyleToDomStyle(name)] = value;
  3464. if(!utils.trim(element.style.cssText)){
  3465. this.removeAttributes(element,'style')
  3466. }
  3467. },
  3468. /**
  3469. * 为元素element设置多个样式属性值
  3470. * @method setStyles
  3471. * @param { Element } element 需要设置样式的元素
  3472. * @param { Object } styles 样式名值对
  3473. * @example
  3474. * ```html
  3475. * <div id="test"></div>
  3476. *
  3477. * <script>
  3478. *
  3479. * var testNode = document.getElementById( "test" );
  3480. *
  3481. * //output: ""
  3482. * console.log( testNode.style.color );
  3483. *
  3484. * UE.dom.domUtils.setStyles( testNode, {
  3485. * 'color': 'red'
  3486. * } );
  3487. * //output: "red"
  3488. * console.log( testNode.style.color );
  3489. *
  3490. * </script>
  3491. * ```
  3492. */
  3493. setStyles:function (element, styles) {
  3494. for (var name in styles) {
  3495. if (styles.hasOwnProperty(name)) {
  3496. domUtils.setStyle(element, name, styles[name]);
  3497. }
  3498. }
  3499. },
  3500. /**
  3501. * 删除_moz_dirty属性
  3502. * @private
  3503. * @method removeDirtyAttr
  3504. */
  3505. removeDirtyAttr:function (node) {
  3506. for (var i = 0, ci, nodes = node.getElementsByTagName('*'); ci = nodes[i++];) {
  3507. ci.removeAttribute('_moz_dirty');
  3508. }
  3509. node.removeAttribute('_moz_dirty');
  3510. },
  3511. /**
  3512. * 获取子节点的数量
  3513. * @method getChildCount
  3514. * @param { Element } node 需要检测的元素
  3515. * @return { Number } 给定的node元素的子节点数量
  3516. * @example
  3517. * ```html
  3518. * <div id="test">
  3519. * <span></span>
  3520. * </div>
  3521. *
  3522. * <script>
  3523. *
  3524. * //output: 3
  3525. * console.log( UE.dom.domUtils.getChildCount( document.getElementById("test") ) );
  3526. *
  3527. * </script>
  3528. * ```
  3529. */
  3530. /**
  3531. * 根据给定的过滤规则, 获取符合条件的子节点的数量
  3532. * @method getChildCount
  3533. * @param { Element } node 需要检测的元素
  3534. * @param { Function } fn 过滤器, 要求对符合条件的子节点返回true, 反之则要求返回false
  3535. * @return { Number } 符合过滤条件的node元素的子节点数量
  3536. * @example
  3537. * ```html
  3538. * <div id="test">
  3539. * <span></span>
  3540. * </div>
  3541. *
  3542. * <script>
  3543. *
  3544. * //output: 1
  3545. * console.log( UE.dom.domUtils.getChildCount( document.getElementById("test"), function ( node ) {
  3546. *
  3547. * return node.nodeType === 1;
  3548. *
  3549. * } ) );
  3550. *
  3551. * </script>
  3552. * ```
  3553. */
  3554. getChildCount:function (node, fn) {
  3555. var count = 0, first = node.firstChild;
  3556. fn = fn || function () {
  3557. return 1;
  3558. };
  3559. while (first) {
  3560. if (fn(first)) {
  3561. count++;
  3562. }
  3563. first = first.nextSibling;
  3564. }
  3565. return count;
  3566. },
  3567. /**
  3568. * 判断给定节点是否为空节点
  3569. * @method isEmptyNode
  3570. * @param { Node } node 需要检测的节点对象
  3571. * @return { Boolean } 节点是否为空
  3572. * @example
  3573. * ```javascript
  3574. * UE.dom.domUtils.isEmptyNode( document.body );
  3575. * ```
  3576. */
  3577. isEmptyNode:function (node) {
  3578. return !node.firstChild || domUtils.getChildCount(node, function (node) {
  3579. return !domUtils.isBr(node) && !domUtils.isBookmarkNode(node) && !domUtils.isWhitespace(node)
  3580. }) == 0
  3581. },
  3582. clearSelectedArr:function (nodes) {
  3583. var node;
  3584. while (node = nodes.pop()) {
  3585. domUtils.removeAttributes(node, ['class']);
  3586. }
  3587. },
  3588. /**
  3589. * 将显示区域滚动到指定节点的位置
  3590. * @method scrollToView
  3591. * @param {Node} node 节点
  3592. * @param {window} win window对象
  3593. * @param {Number} offsetTop 距离上方的偏移量
  3594. */
  3595. scrollToView:function (node, win, offsetTop) {
  3596. var getViewPaneSize = function () {
  3597. var doc = win.document,
  3598. mode = doc.compatMode == 'CSS1Compat';
  3599. return {
  3600. width:( mode ? doc.documentElement.clientWidth : doc.body.clientWidth ) || 0,
  3601. height:( mode ? doc.documentElement.clientHeight : doc.body.clientHeight ) || 0
  3602. };
  3603. },
  3604. getScrollPosition = function (win) {
  3605. if ('pageXOffset' in win) {
  3606. return {
  3607. x:win.pageXOffset || 0,
  3608. y:win.pageYOffset || 0
  3609. };
  3610. }
  3611. else {
  3612. var doc = win.document;
  3613. return {
  3614. x:doc.documentElement.scrollLeft || doc.body.scrollLeft || 0,
  3615. y:doc.documentElement.scrollTop || doc.body.scrollTop || 0
  3616. };
  3617. }
  3618. };
  3619. var winHeight = getViewPaneSize().height, offset = winHeight * -1 + offsetTop;
  3620. offset += (node.offsetHeight || 0);
  3621. var elementPosition = domUtils.getXY(node);
  3622. offset += elementPosition.y;
  3623. var currentScroll = getScrollPosition(win).y;
  3624. // offset += 50;
  3625. if (offset > currentScroll || offset < currentScroll - winHeight) {
  3626. win.scrollTo(0, offset + (offset < 0 ? -20 : 20));
  3627. }
  3628. },
  3629. /**
  3630. * 判断给定节点是否为br
  3631. * @method isBr
  3632. * @param { Node } node 需要判断的节点对象
  3633. * @return { Boolean } 给定的节点是否是br节点
  3634. */
  3635. isBr:function (node) {
  3636. return node.nodeType == 1 && node.tagName == 'BR';
  3637. },
  3638. /**
  3639. * 判断给定的节点是否是一个“填充”节点
  3640. * @private
  3641. * @method isFillChar
  3642. * @param { Node } node 需要判断的节点
  3643. * @param { Boolean } isInStart 是否从节点内容的开始位置匹配
  3644. * @returns { Boolean } 节点是否是填充节点
  3645. */
  3646. isFillChar:function (node,isInStart) {
  3647. if(node.nodeType != 3)
  3648. return false;
  3649. var text = node.nodeValue;
  3650. if(isInStart){
  3651. return new RegExp('^' + domUtils.fillChar).test(text)
  3652. }
  3653. return !text.replace(new RegExp(domUtils.fillChar,'g'), '').length
  3654. },
  3655. isStartInblock:function (range) {
  3656. var tmpRange = range.cloneRange(),
  3657. flag = 0,
  3658. start = tmpRange.startContainer,
  3659. tmp;
  3660. if(start.nodeType == 1 && start.childNodes[tmpRange.startOffset]){
  3661. start = start.childNodes[tmpRange.startOffset];
  3662. var pre = start.previousSibling;
  3663. while(pre && domUtils.isFillChar(pre)){
  3664. start = pre;
  3665. pre = pre.previousSibling;
  3666. }
  3667. }
  3668. if(this.isFillChar(start,true) && tmpRange.startOffset == 1){
  3669. tmpRange.setStartBefore(start);
  3670. start = tmpRange.startContainer;
  3671. }
  3672. while (start && domUtils.isFillChar(start)) {
  3673. tmp = start;
  3674. start = start.previousSibling
  3675. }
  3676. if (tmp) {
  3677. tmpRange.setStartBefore(tmp);
  3678. start = tmpRange.startContainer;
  3679. }
  3680. if (start.nodeType == 1 && domUtils.isEmptyNode(start) && tmpRange.startOffset == 1) {
  3681. tmpRange.setStart(start, 0).collapse(true);
  3682. }
  3683. while (!tmpRange.startOffset) {
  3684. start = tmpRange.startContainer;
  3685. if (domUtils.isBlockElm(start) || domUtils.isBody(start)) {
  3686. flag = 1;
  3687. break;
  3688. }
  3689. var pre = tmpRange.startContainer.previousSibling,
  3690. tmpNode;
  3691. if (!pre) {
  3692. tmpRange.setStartBefore(tmpRange.startContainer);
  3693. } else {
  3694. while (pre && domUtils.isFillChar(pre)) {
  3695. tmpNode = pre;
  3696. pre = pre.previousSibling;
  3697. }
  3698. if (tmpNode) {
  3699. tmpRange.setStartBefore(tmpNode);
  3700. } else {
  3701. tmpRange.setStartBefore(tmpRange.startContainer);
  3702. }
  3703. }
  3704. }
  3705. return flag && !domUtils.isBody(tmpRange.startContainer) ? 1 : 0;
  3706. },
  3707. /**
  3708. * 判断给定的元素是否是一个空元素
  3709. * @method isEmptyBlock
  3710. * @param { Element } node 需要判断的元素
  3711. * @return { Boolean } 是否是空元素
  3712. * @example
  3713. * ```html
  3714. * <div id="test"></div>
  3715. *
  3716. * <script>
  3717. * //output: true
  3718. * console.log( UE.dom.domUtils.isEmptyBlock( document.getElementById("test") ) );
  3719. * </script>
  3720. * ```
  3721. */
  3722. /**
  3723. * 根据指定的判断规则判断给定的元素是否是一个空元素
  3724. * @method isEmptyBlock
  3725. * @param { Element } node 需要判断的元素
  3726. * @param { RegExp } reg 对内容执行判断的正则表达式对象
  3727. * @return { Boolean } 是否是空元素
  3728. */
  3729. isEmptyBlock:function (node,reg) {
  3730. if(node.nodeType != 1)
  3731. return 0;
  3732. reg = reg || new RegExp('[ \xa0\t\r\n' + domUtils.fillChar + ']', 'g');
  3733. if (node[browser.ie ? 'innerText' : 'textContent'].replace(reg, '').length > 0) {
  3734. return 0;
  3735. }
  3736. for (var n in dtd.$isNotEmpty) {
  3737. if (node.getElementsByTagName(n).length) {
  3738. return 0;
  3739. }
  3740. }
  3741. return 1;
  3742. },
  3743. /**
  3744. * 移动元素使得该元素的位置移动指定的偏移量的距离
  3745. * @method setViewportOffset
  3746. * @param { Element } element 需要设置偏移量的元素
  3747. * @param { Object } offset 偏移量, 形如{ left: 100, top: 50 }的一个键值对, 表示该元素将在
  3748. * 现有的位置上向水平方向偏移offset.left的距离, 在竖直方向上偏移
  3749. * offset.top的距离
  3750. * @example
  3751. * ```html
  3752. * <div id="test" style="top: 100px; left: 50px; position: absolute;"></div>
  3753. *
  3754. * <script>
  3755. *
  3756. * var testNode = document.getElementById("test");
  3757. *
  3758. * UE.dom.domUtils.setViewportOffset( testNode, {
  3759. * left: 200,
  3760. * top: 50
  3761. * } );
  3762. *
  3763. * //output: top: 300px; left: 100px; position: absolute;
  3764. * console.log( testNode.style.cssText );
  3765. *
  3766. * </script>
  3767. * ```
  3768. */
  3769. setViewportOffset:function (element, offset) {
  3770. var left = parseInt(element.style.left) | 0;
  3771. var top = parseInt(element.style.top) | 0;
  3772. var rect = element.getBoundingClientRect();
  3773. var offsetLeft = offset.left - rect.left;
  3774. var offsetTop = offset.top - rect.top;
  3775. if (offsetLeft) {
  3776. element.style.left = left + offsetLeft + 'px';
  3777. }
  3778. if (offsetTop) {
  3779. element.style.top = top + offsetTop + 'px';
  3780. }
  3781. },
  3782. /**
  3783. * 用“填充字符”填充节点
  3784. * @method fillNode
  3785. * @private
  3786. * @param { DomDocument } doc 填充的节点所在的docment对象
  3787. * @param { Node } node 需要填充的节点对象
  3788. * @example
  3789. * ```html
  3790. * <div id="test"></div>
  3791. *
  3792. * <script>
  3793. * var testNode = document.getElementById("test");
  3794. *
  3795. * //output: 0
  3796. * console.log( testNode.childNodes.length );
  3797. *
  3798. * UE.dom.domUtils.fillNode( document, testNode );
  3799. *
  3800. * //output: 1
  3801. * console.log( testNode.childNodes.length );
  3802. *
  3803. * </script>
  3804. * ```
  3805. */
  3806. fillNode:function (doc, node) {
  3807. var tmpNode = browser.ie ? doc.createTextNode(domUtils.fillChar) : doc.createElement('br');
  3808. node.innerHTML = '';
  3809. node.appendChild(tmpNode);
  3810. },
  3811. /**
  3812. * 把节点src的所有子节点追加到另一个节点tag上去
  3813. * @method moveChild
  3814. * @param { Node } src 源节点, 该节点下的所有子节点将被移除
  3815. * @param { Node } tag 目标节点, 从源节点移除的子节点将被追加到该节点下
  3816. * @example
  3817. * ```html
  3818. * <div id="test1">
  3819. * <span></span>
  3820. * </div>
  3821. * <div id="test2">
  3822. * <div></div>
  3823. * </div>
  3824. *
  3825. * <script>
  3826. *
  3827. * var test1 = document.getElementById("test1"),
  3828. * test2 = document.getElementById("test2");
  3829. *
  3830. * UE.dom.domUtils.moveChild( test1, test2 );
  3831. *
  3832. * //output: ""(空字符串)
  3833. * console.log( test1.innerHTML );
  3834. *
  3835. * //output: "<div></div><span></span>"
  3836. * console.log( test2.innerHTML );
  3837. *
  3838. * </script>
  3839. * ```
  3840. */
  3841. /**
  3842. * 把节点src的所有子节点移动到另一个节点tag上去, 可以通过dir参数控制附加的行为是“追加”还是“插入顶部”
  3843. * @method moveChild
  3844. * @param { Node } src 源节点, 该节点下的所有子节点将被移除
  3845. * @param { Node } tag 目标节点, 从源节点移除的子节点将被附加到该节点下
  3846. * @param { Boolean } dir 附加方式, 如果为true, 则附加进去的节点将被放到目标节点的顶部, 反之,则放到末尾
  3847. * @example
  3848. * ```html
  3849. * <div id="test1">
  3850. * <span></span>
  3851. * </div>
  3852. * <div id="test2">
  3853. * <div></div>
  3854. * </div>
  3855. *
  3856. * <script>
  3857. *
  3858. * var test1 = document.getElementById("test1"),
  3859. * test2 = document.getElementById("test2");
  3860. *
  3861. * UE.dom.domUtils.moveChild( test1, test2, true );
  3862. *
  3863. * //output: ""(空字符串)
  3864. * console.log( test1.innerHTML );
  3865. *
  3866. * //output: "<span></span><div></div>"
  3867. * console.log( test2.innerHTML );
  3868. *
  3869. * </script>
  3870. * ```
  3871. */
  3872. moveChild:function (src, tag, dir) {
  3873. while (src.firstChild) {
  3874. if (dir && tag.firstChild) {
  3875. tag.insertBefore(src.lastChild, tag.firstChild);
  3876. } else {
  3877. tag.appendChild(src.firstChild);
  3878. }
  3879. }
  3880. },
  3881. /**
  3882. * 判断节点的标签上是否不存在任何属性
  3883. * @method hasNoAttributes
  3884. * @private
  3885. * @param { Node } node 需要检测的节点对象
  3886. * @return { Boolean } 节点是否不包含任何属性
  3887. * @example
  3888. * ```html
  3889. * <div id="test"><span>xxxx</span></div>
  3890. *
  3891. * <script>
  3892. *
  3893. * //output: false
  3894. * console.log( UE.dom.domUtils.hasNoAttributes( document.getElementById("test") ) );
  3895. *
  3896. * //output: true
  3897. * console.log( UE.dom.domUtils.hasNoAttributes( document.getElementById("test").firstChild ) );
  3898. *
  3899. * </script>
  3900. * ```
  3901. */
  3902. hasNoAttributes:function (node) {
  3903. return browser.ie ? /^<\w+\s*?>/.test(node.outerHTML) : node.attributes.length == 0;
  3904. },
  3905. /**
  3906. * 检测节点是否是UEditor所使用的辅助节点
  3907. * @method isCustomeNode
  3908. * @private
  3909. * @param { Node } node 需要检测的节点
  3910. * @remind 辅助节点是指编辑器要完成工作临时添加的节点, 在输出的时候将会从编辑器内移除, 不会影响最终的结果。
  3911. * @return { Boolean } 给定的节点是否是一个辅助节点
  3912. */
  3913. isCustomeNode:function (node) {
  3914. return node.nodeType == 1 && node.getAttribute('_ue_custom_node_');
  3915. },
  3916. /**
  3917. * 检测节点的标签是否是给定的标签
  3918. * @method isTagNode
  3919. * @param { Node } node 需要检测的节点对象
  3920. * @param { String } tagName 标签
  3921. * @return { Boolean } 节点的标签是否是给定的标签
  3922. * @example
  3923. * ```html
  3924. * <div id="test"></div>
  3925. *
  3926. * <script>
  3927. *
  3928. * //output: true
  3929. * console.log( UE.dom.domUtils.isTagNode( document.getElementById("test"), "div" ) );
  3930. *
  3931. * </script>
  3932. * ```
  3933. */
  3934. isTagNode:function (node, tagNames) {
  3935. return node.nodeType == 1 && new RegExp('\\b' + node.tagName + '\\b','i').test(tagNames)
  3936. },
  3937. /**
  3938. * 给定一个节点数组,在通过指定的过滤器过滤后, 获取其中满足过滤条件的第一个节点
  3939. * @method filterNodeList
  3940. * @param { Array } nodeList 需要过滤的节点数组
  3941. * @param { Function } fn 过滤器, 对符合条件的节点, 执行结果返回true, 反之则返回false
  3942. * @return { Node | NULL } 如果找到符合过滤条件的节点, 则返回该节点, 否则返回NULL
  3943. * @example
  3944. * ```javascript
  3945. * var divNodes = document.getElementsByTagName("div");
  3946. * divNodes = [].slice.call( divNodes, 0 );
  3947. *
  3948. * //output: null
  3949. * console.log( UE.dom.domUtils.filterNodeList( divNodes, function ( node ) {
  3950. * return node.tagName.toLowerCase() !== 'div';
  3951. * } ) );
  3952. * ```
  3953. */
  3954. /**
  3955. * 给定一个节点数组nodeList和一组标签名tagNames, 获取其中能够匹配标签名的节点集合中的第一个节点
  3956. * @method filterNodeList
  3957. * @param { Array } nodeList 需要过滤的节点数组
  3958. * @param { String } tagNames 需要匹配的标签名, 多个标签名之间用空格分割
  3959. * @return { Node | NULL } 如果找到标签名匹配的节点, 则返回该节点, 否则返回NULL
  3960. * @example
  3961. * ```javascript
  3962. * var divNodes = document.getElementsByTagName("div");
  3963. * divNodes = [].slice.call( divNodes, 0 );
  3964. *
  3965. * //output: null
  3966. * console.log( UE.dom.domUtils.filterNodeList( divNodes, 'a span' ) );
  3967. * ```
  3968. */
  3969. /**
  3970. * 给定一个节点数组,在通过指定的过滤器过滤后, 如果参数forAll为true, 则会返回所有满足过滤
  3971. * 条件的节点集合, 否则, 返回满足条件的节点集合中的第一个节点
  3972. * @method filterNodeList
  3973. * @param { Array } nodeList 需要过滤的节点数组
  3974. * @param { Function } fn 过滤器, 对符合条件的节点, 执行结果返回true, 反之则返回false
  3975. * @param { Boolean } forAll 是否返回整个节点数组, 如果该参数为false, 则返回节点集合中的第一个节点
  3976. * @return { Array | Node | NULL } 如果找到符合过滤条件的节点, 则根据参数forAll的值决定返回满足
  3977. * 过滤条件的节点数组或第一个节点, 否则返回NULL
  3978. * @example
  3979. * ```javascript
  3980. * var divNodes = document.getElementsByTagName("div");
  3981. * divNodes = [].slice.call( divNodes, 0 );
  3982. *
  3983. * //output: 3(假定有3个div)
  3984. * console.log( divNodes.length );
  3985. *
  3986. * var nodes = UE.dom.domUtils.filterNodeList( divNodes, function ( node ) {
  3987. * return node.tagName.toLowerCase() === 'div';
  3988. * }, true );
  3989. *
  3990. * //output: 3
  3991. * console.log( nodes.length );
  3992. *
  3993. * var node = UE.dom.domUtils.filterNodeList( divNodes, function ( node ) {
  3994. * return node.tagName.toLowerCase() === 'div';
  3995. * }, false );
  3996. *
  3997. * //output: div
  3998. * console.log( node.nodeName );
  3999. * ```
  4000. */
  4001. filterNodeList : function(nodelist,filter,forAll){
  4002. var results = [];
  4003. if(!utils .isFunction(filter)){
  4004. var str = filter;
  4005. filter = function(n){
  4006. return utils.indexOf(utils.isArray(str) ? str:str.split(' '), n.tagName.toLowerCase()) != -1
  4007. };
  4008. }
  4009. utils.each(nodelist,function(n){
  4010. filter(n) && results.push(n)
  4011. });
  4012. return results.length == 0 ? null : results.length == 1 || !forAll ? results[0] : results
  4013. },
  4014. /**
  4015. * 查询给定的range选区是否在给定的node节点内,且在该节点的最末尾
  4016. * @method isInNodeEndBoundary
  4017. * @param { UE.dom.Range } rng 需要判断的range对象, 该对象的startContainer不能为NULL
  4018. * @param node 需要检测的节点对象
  4019. * @return { Number } 如果给定的选取range对象是在node内部的最末端, 则返回1, 否则返回0
  4020. */
  4021. isInNodeEndBoundary : function (rng,node){
  4022. var start = rng.startContainer;
  4023. if(start.nodeType == 3 && rng.startOffset != start.nodeValue.length){
  4024. return 0;
  4025. }
  4026. if(start.nodeType == 1 && rng.startOffset != start.childNodes.length){
  4027. return 0;
  4028. }
  4029. while(start !== node){
  4030. if(start.nextSibling){
  4031. return 0
  4032. };
  4033. start = start.parentNode;
  4034. }
  4035. return 1;
  4036. },
  4037. isBoundaryNode : function (node,dir){
  4038. var tmp;
  4039. while(!domUtils.isBody(node)){
  4040. tmp = node;
  4041. node = node.parentNode;
  4042. if(tmp !== node[dir]){
  4043. return false;
  4044. }
  4045. }
  4046. return true;
  4047. },
  4048. fillHtml : browser.ie11below ? '&nbsp;' : '<br/>'
  4049. };
  4050. var fillCharReg = new RegExp(domUtils.fillChar, 'g');
  4051. // core/Range.js
  4052. /**
  4053. * Range封装
  4054. * @file
  4055. * @module UE.dom
  4056. * @class Range
  4057. * @since 1.2.6.1
  4058. */
  4059. /**
  4060. * dom操作封装
  4061. * @unfile
  4062. * @module UE.dom
  4063. */
  4064. /**
  4065. * Range实现类,本类是UEditor底层核心类,封装不同浏览器之间的Range操作。
  4066. * @unfile
  4067. * @module UE.dom
  4068. * @class Range
  4069. */
  4070. (function () {
  4071. var guid = 0,
  4072. fillChar = domUtils.fillChar,
  4073. fillData;
  4074. /**
  4075. * 更新range的collapse状态
  4076. * @param {Range} range range对象
  4077. */
  4078. function updateCollapse(range) {
  4079. range.collapsed =
  4080. range.startContainer && range.endContainer &&
  4081. range.startContainer === range.endContainer &&
  4082. range.startOffset == range.endOffset;
  4083. }
  4084. function selectOneNode(rng){
  4085. return !rng.collapsed && rng.startContainer.nodeType == 1 && rng.startContainer === rng.endContainer && rng.endOffset - rng.startOffset == 1
  4086. }
  4087. function setEndPoint(toStart, node, offset, range) {
  4088. //如果node是自闭合标签要处理
  4089. if (node.nodeType == 1 && (dtd.$empty[node.tagName] || dtd.$nonChild[node.tagName])) {
  4090. offset = domUtils.getNodeIndex(node) + (toStart ? 0 : 1);
  4091. node = node.parentNode;
  4092. }
  4093. if (toStart) {
  4094. range.startContainer = node;
  4095. range.startOffset = offset;
  4096. if (!range.endContainer) {
  4097. range.collapse(true);
  4098. }
  4099. } else {
  4100. range.endContainer = node;
  4101. range.endOffset = offset;
  4102. if (!range.startContainer) {
  4103. range.collapse(false);
  4104. }
  4105. }
  4106. updateCollapse(range);
  4107. return range;
  4108. }
  4109. function execContentsAction(range, action) {
  4110. //调整边界
  4111. //range.includeBookmark();
  4112. var start = range.startContainer,
  4113. end = range.endContainer,
  4114. startOffset = range.startOffset,
  4115. endOffset = range.endOffset,
  4116. doc = range.document,
  4117. frag = doc.createDocumentFragment(),
  4118. tmpStart, tmpEnd;
  4119. if (start.nodeType == 1) {
  4120. start = start.childNodes[startOffset] || (tmpStart = start.appendChild(doc.createTextNode('')));
  4121. }
  4122. if (end.nodeType == 1) {
  4123. end = end.childNodes[endOffset] || (tmpEnd = end.appendChild(doc.createTextNode('')));
  4124. }
  4125. if (start === end && start.nodeType == 3) {
  4126. frag.appendChild(doc.createTextNode(start.substringData(startOffset, endOffset - startOffset)));
  4127. //is not clone
  4128. if (action) {
  4129. start.deleteData(startOffset, endOffset - startOffset);
  4130. range.collapse(true);
  4131. }
  4132. return frag;
  4133. }
  4134. var current, currentLevel, clone = frag,
  4135. startParents = domUtils.findParents(start, true), endParents = domUtils.findParents(end, true);
  4136. for (var i = 0; startParents[i] == endParents[i];) {
  4137. i++;
  4138. }
  4139. for (var j = i, si; si = startParents[j]; j++) {
  4140. current = si.nextSibling;
  4141. if (si == start) {
  4142. if (!tmpStart) {
  4143. if (range.startContainer.nodeType == 3) {
  4144. clone.appendChild(doc.createTextNode(start.nodeValue.slice(startOffset)));
  4145. //is not clone
  4146. if (action) {
  4147. start.deleteData(startOffset, start.nodeValue.length - startOffset);
  4148. }
  4149. } else {
  4150. clone.appendChild(!action ? start.cloneNode(true) : start);
  4151. }
  4152. }
  4153. } else {
  4154. currentLevel = si.cloneNode(false);
  4155. clone.appendChild(currentLevel);
  4156. }
  4157. while (current) {
  4158. if (current === end || current === endParents[j]) {
  4159. break;
  4160. }
  4161. si = current.nextSibling;
  4162. clone.appendChild(!action ? current.cloneNode(true) : current);
  4163. current = si;
  4164. }
  4165. clone = currentLevel;
  4166. }
  4167. clone = frag;
  4168. if (!startParents[i]) {
  4169. clone.appendChild(startParents[i - 1].cloneNode(false));
  4170. clone = clone.firstChild;
  4171. }
  4172. for (var j = i, ei; ei = endParents[j]; j++) {
  4173. current = ei.previousSibling;
  4174. if (ei == end) {
  4175. if (!tmpEnd && range.endContainer.nodeType == 3) {
  4176. clone.appendChild(doc.createTextNode(end.substringData(0, endOffset)));
  4177. //is not clone
  4178. if (action) {
  4179. end.deleteData(0, endOffset);
  4180. }
  4181. }
  4182. } else {
  4183. currentLevel = ei.cloneNode(false);
  4184. clone.appendChild(currentLevel);
  4185. }
  4186. //如果两端同级,右边第一次已经被开始做了
  4187. if (j != i || !startParents[i]) {
  4188. while (current) {
  4189. if (current === start) {
  4190. break;
  4191. }
  4192. ei = current.previousSibling;
  4193. clone.insertBefore(!action ? current.cloneNode(true) : current, clone.firstChild);
  4194. current = ei;
  4195. }
  4196. }
  4197. clone = currentLevel;
  4198. }
  4199. if (action) {
  4200. range.setStartBefore(!endParents[i] ? endParents[i - 1] : !startParents[i] ? startParents[i - 1] : endParents[i]).collapse(true);
  4201. }
  4202. tmpStart && domUtils.remove(tmpStart);
  4203. tmpEnd && domUtils.remove(tmpEnd);
  4204. return frag;
  4205. }
  4206. /**
  4207. * 创建一个跟document绑定的空的Range实例
  4208. * @constructor
  4209. * @param { Document } document 新建的选区所属的文档对象
  4210. */
  4211. /**
  4212. * @property { Node } startContainer 当前Range的开始边界的容器节点, 可以是一个元素节点或者是文本节点
  4213. */
  4214. /**
  4215. * @property { Node } startOffset 当前Range的开始边界容器节点的偏移量, 如果是元素节点,
  4216. * 该值就是childNodes中的第几个节点, 如果是文本节点就是文本内容的第几个字符
  4217. */
  4218. /**
  4219. * @property { Node } endContainer 当前Range的结束边界的容器节点, 可以是一个元素节点或者是文本节点
  4220. */
  4221. /**
  4222. * @property { Node } endOffset 当前Range的结束边界容器节点的偏移量, 如果是元素节点,
  4223. * 该值就是childNodes中的第几个节点, 如果是文本节点就是文本内容的第几个字符
  4224. */
  4225. /**
  4226. * @property { Boolean } collapsed 当前Range是否闭合
  4227. * @default true
  4228. * @remind Range是闭合的时候, startContainer === endContainer && startOffset === endOffset
  4229. */
  4230. /**
  4231. * @property { Document } document 当前Range所属的Document对象
  4232. * @remind 不同range的的document属性可以是不同的
  4233. */
  4234. var Range = dom.Range = function (document) {
  4235. var me = this;
  4236. me.startContainer =
  4237. me.startOffset =
  4238. me.endContainer =
  4239. me.endOffset = null;
  4240. me.document = document;
  4241. me.collapsed = true;
  4242. };
  4243. /**
  4244. * 删除fillData
  4245. * @param doc
  4246. * @param excludeNode
  4247. */
  4248. function removeFillData(doc, excludeNode) {
  4249. try {
  4250. if (fillData && domUtils.inDoc(fillData, doc)) {
  4251. if (!fillData.nodeValue.replace(fillCharReg, '').length) {
  4252. var tmpNode = fillData.parentNode;
  4253. domUtils.remove(fillData);
  4254. while (tmpNode && domUtils.isEmptyInlineElement(tmpNode) &&
  4255. //safari的contains有bug
  4256. (browser.safari ? !(domUtils.getPosition(tmpNode,excludeNode) & domUtils.POSITION_CONTAINS) : !tmpNode.contains(excludeNode))
  4257. ) {
  4258. fillData = tmpNode.parentNode;
  4259. domUtils.remove(tmpNode);
  4260. tmpNode = fillData;
  4261. }
  4262. } else {
  4263. fillData.nodeValue = fillData.nodeValue.replace(fillCharReg, '');
  4264. }
  4265. }
  4266. } catch (e) {
  4267. }
  4268. }
  4269. /**
  4270. * @param node
  4271. * @param dir
  4272. */
  4273. function mergeSibling(node, dir) {
  4274. var tmpNode;
  4275. node = node[dir];
  4276. while (node && domUtils.isFillChar(node)) {
  4277. tmpNode = node[dir];
  4278. domUtils.remove(node);
  4279. node = tmpNode;
  4280. }
  4281. }
  4282. Range.prototype = {
  4283. /**
  4284. * 克隆选区的内容到一个DocumentFragment里
  4285. * @method cloneContents
  4286. * @return { DocumentFragment | NULL } 如果选区是闭合的将返回null, 否则, 返回包含所clone内容的DocumentFragment元素
  4287. * @example
  4288. * ```html
  4289. * <body>
  4290. * <!-- 中括号表示选区 -->
  4291. * <b>x<i>x[x</i>xx]x</b>
  4292. *
  4293. * <script>
  4294. * //range是已选中的选区
  4295. * var fragment = range.cloneContents(),
  4296. * node = document.createElement("div");
  4297. *
  4298. * node.appendChild( fragment );
  4299. *
  4300. * //output: <i>x</i>xx
  4301. * console.log( node.innerHTML );
  4302. *
  4303. * </script>
  4304. * </body>
  4305. * ```
  4306. */
  4307. cloneContents:function () {
  4308. return this.collapsed ? null : execContentsAction(this, 0);
  4309. },
  4310. /**
  4311. * 删除当前选区范围中的所有内容
  4312. * @method deleteContents
  4313. * @remind 执行完该操作后, 当前Range对象变成了闭合状态
  4314. * @return { UE.dom.Range } 当前操作的Range对象
  4315. * @example
  4316. * ```html
  4317. * <body>
  4318. * <!-- 中括号表示选区 -->
  4319. * <b>x<i>x[x</i>xx]x</b>
  4320. *
  4321. * <script>
  4322. * //range是已选中的选区
  4323. * range.deleteContents();
  4324. *
  4325. * //竖线表示闭合后的选区位置
  4326. * //output: <b>x<i>x</i>|x</b>
  4327. * console.log( document.body.innerHTML );
  4328. *
  4329. * //此时, range的各项属性为
  4330. * //output: B
  4331. * console.log( range.startContainer.tagName );
  4332. * //output: 2
  4333. * console.log( range.startOffset );
  4334. * //output: B
  4335. * console.log( range.endContainer.tagName );
  4336. * //output: 2
  4337. * console.log( range.endOffset );
  4338. * //output: true
  4339. * console.log( range.collapsed );
  4340. *
  4341. * </script>
  4342. * </body>
  4343. * ```
  4344. */
  4345. deleteContents:function () {
  4346. var txt;
  4347. if (!this.collapsed) {
  4348. execContentsAction(this, 1);
  4349. }
  4350. if (browser.webkit) {
  4351. txt = this.startContainer;
  4352. if (txt.nodeType == 3 && !txt.nodeValue.length) {
  4353. this.setStartBefore(txt).collapse(true);
  4354. domUtils.remove(txt);
  4355. }
  4356. }
  4357. return this;
  4358. },
  4359. /**
  4360. * 将当前选区的内容提取到一个DocumentFragment里
  4361. * @method extractContents
  4362. * @remind 执行该操作后, 选区将变成闭合状态
  4363. * @warning 执行该操作后, 原来选区所选中的内容将从dom树上剥离出来
  4364. * @return { DocumentFragment } 返回包含所提取内容的DocumentFragment对象
  4365. * @example
  4366. * ```html
  4367. * <body>
  4368. * <!-- 中括号表示选区 -->
  4369. * <b>x<i>x[x</i>xx]x</b>
  4370. *
  4371. * <script>
  4372. * //range是已选中的选区
  4373. * var fragment = range.extractContents(),
  4374. * node = document.createElement( "div" );
  4375. *
  4376. * node.appendChild( fragment );
  4377. *
  4378. * //竖线表示闭合后的选区位置
  4379. *
  4380. * //output: <b>x<i>x</i>|x</b>
  4381. * console.log( document.body.innerHTML );
  4382. * //output: <i>x</i>xx
  4383. * console.log( node.innerHTML );
  4384. *
  4385. * //此时, range的各项属性为
  4386. * //output: B
  4387. * console.log( range.startContainer.tagName );
  4388. * //output: 2
  4389. * console.log( range.startOffset );
  4390. * //output: B
  4391. * console.log( range.endContainer.tagName );
  4392. * //output: 2
  4393. * console.log( range.endOffset );
  4394. * //output: true
  4395. * console.log( range.collapsed );
  4396. *
  4397. * </script>
  4398. * </body>
  4399. */
  4400. extractContents:function () {
  4401. return this.collapsed ? null : execContentsAction(this, 2);
  4402. },
  4403. /**
  4404. * 设置Range的开始容器节点和偏移量
  4405. * @method setStart
  4406. * @remind 如果给定的节点是元素节点,那么offset指的是其子元素中索引为offset的元素,
  4407. * 如果是文本节点,那么offset指的是其文本内容的第offset个字符
  4408. * @remind 如果提供的容器节点是一个不能包含子元素的节点, 则该选区的开始容器将被设置
  4409. * 为该节点的父节点, 此时, 其距离开始容器的偏移量也变成了该节点在其父节点
  4410. * 中的索引
  4411. * @param { Node } node 将被设为当前选区开始边界容器的节点对象
  4412. * @param { int } offset 选区的开始位置偏移量
  4413. * @return { UE.dom.Range } 当前range对象
  4414. * @example
  4415. * ```html
  4416. * <!-- 选区 -->
  4417. * <b>xxx<i>x<span>xx</span>xx<em>xx</em>xxx</i>[xxx]</b>
  4418. *
  4419. * <script>
  4420. *
  4421. * //执行操作
  4422. * range.setStart( document.getElementsByTagName("i")[0], 1 );
  4423. *
  4424. * //此时, 选区变成了
  4425. * //<b>xxx<i>x[<span>xx</span>xx<em>xx</em>xxx</i>xxx]</b>
  4426. *
  4427. * </script>
  4428. * ```
  4429. * @example
  4430. * ```html
  4431. * <!-- 选区 -->
  4432. * <b>xxx<img>[xx]x</b>
  4433. *
  4434. * <script>
  4435. *
  4436. * //执行操作
  4437. * range.setStart( document.getElementsByTagName("img")[0], 3 );
  4438. *
  4439. * //此时, 选区变成了
  4440. * //<b>xxx[<img>xx]x</b>
  4441. *
  4442. * </script>
  4443. * ```
  4444. */
  4445. setStart:function (node, offset) {
  4446. return setEndPoint(true, node, offset, this);
  4447. },
  4448. /**
  4449. * 设置Range的结束容器和偏移量
  4450. * @method setEnd
  4451. * @param { Node } node 作为当前选区结束边界容器的节点对象
  4452. * @param { int } offset 结束边界的偏移量
  4453. * @see UE.dom.Range:setStart(Node,int)
  4454. * @return { UE.dom.Range } 当前range对象
  4455. */
  4456. setEnd:function (node, offset) {
  4457. return setEndPoint(false, node, offset, this);
  4458. },
  4459. /**
  4460. * 将Range开始位置设置到node节点之后
  4461. * @method setStartAfter
  4462. * @remind 该操作将会把给定节点的父节点作为range的开始容器, 且偏移量是该节点在其父节点中的位置索引+1
  4463. * @param { Node } node 选区的开始边界将紧接着该节点之后
  4464. * @return { UE.dom.Range } 当前range对象
  4465. * @example
  4466. * ```html
  4467. * <!-- 选区示例 -->
  4468. * <b>xx<i>xxx</i><span>xx[x</span>xxx]</b>
  4469. *
  4470. * <script>
  4471. *
  4472. * //执行操作
  4473. * range.setStartAfter( document.getElementsByTagName("i")[0] );
  4474. *
  4475. * //结果选区
  4476. * //<b>xx<i>xxx</i>[<span>xxx</span>xxx]</b>
  4477. *
  4478. * </script>
  4479. * ```
  4480. */
  4481. setStartAfter:function (node) {
  4482. return this.setStart(node.parentNode, domUtils.getNodeIndex(node) + 1);
  4483. },
  4484. /**
  4485. * 将Range开始位置设置到node节点之前
  4486. * @method setStartBefore
  4487. * @remind 该操作将会把给定节点的父节点作为range的开始容器, 且偏移量是该节点在其父节点中的位置索引
  4488. * @param { Node } node 新的选区开始位置在该节点之前
  4489. * @see UE.dom.Range:setStartAfter(Node)
  4490. * @return { UE.dom.Range } 当前range对象
  4491. */
  4492. setStartBefore:function (node) {
  4493. return this.setStart(node.parentNode, domUtils.getNodeIndex(node));
  4494. },
  4495. /**
  4496. * 将Range结束位置设置到node节点之后
  4497. * @method setEndAfter
  4498. * @remind 该操作将会把给定节点的父节点作为range的结束容器, 且偏移量是该节点在其父节点中的位置索引+1
  4499. * @param { Node } node 目标节点
  4500. * @see UE.dom.Range:setStartAfter(Node)
  4501. * @return { UE.dom.Range } 当前range对象
  4502. * @example
  4503. * ```html
  4504. * <!-- 选区示例 -->
  4505. * <b>[xx<i>xxx</i><span>xx]x</span>xxx</b>
  4506. *
  4507. * <script>
  4508. *
  4509. * //执行操作
  4510. * range.setStartAfter( document.getElementsByTagName("span")[0] );
  4511. *
  4512. * //结果选区
  4513. * //<b>[xx<i>xxx</i><span>xxx</span>]xxx</b>
  4514. *
  4515. * </script>
  4516. * ```
  4517. */
  4518. setEndAfter:function (node) {
  4519. return this.setEnd(node.parentNode, domUtils.getNodeIndex(node) + 1);
  4520. },
  4521. /**
  4522. * 将Range结束位置设置到node节点之前
  4523. * @method setEndBefore
  4524. * @remind 该操作将会把给定节点的父节点作为range的结束容器, 且偏移量是该节点在其父节点中的位置索引
  4525. * @param { Node } node 目标节点
  4526. * @see UE.dom.Range:setEndAfter(Node)
  4527. * @return { UE.dom.Range } 当前range对象
  4528. */
  4529. setEndBefore:function (node) {
  4530. return this.setEnd(node.parentNode, domUtils.getNodeIndex(node));
  4531. },
  4532. /**
  4533. * 设置Range的开始位置到node节点内的第一个子节点之前
  4534. * @method setStartAtFirst
  4535. * @remind 选区的开始容器将变成给定的节点, 且偏移量为0
  4536. * @remind 如果给定的节点是元素节点, 则该节点必须是允许包含子节点的元素。
  4537. * @param { Node } node 目标节点
  4538. * @see UE.dom.Range:setStartBefore(Node)
  4539. * @return { UE.dom.Range } 当前range对象
  4540. * @example
  4541. * ```html
  4542. * <!-- 选区示例 -->
  4543. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  4544. *
  4545. * <script>
  4546. *
  4547. * //执行操作
  4548. * range.setStartAtFirst( document.getElementsByTagName("i")[0] );
  4549. *
  4550. * //结果选区
  4551. * //<b>xx<i>[xxx</i><span>xx]x</span>xxx</b>
  4552. *
  4553. * </script>
  4554. * ```
  4555. */
  4556. setStartAtFirst:function (node) {
  4557. return this.setStart(node, 0);
  4558. },
  4559. /**
  4560. * 设置Range的开始位置到node节点内的最后一个节点之后
  4561. * @method setStartAtLast
  4562. * @remind 选区的开始容器将变成给定的节点, 且偏移量为该节点的子节点数
  4563. * @remind 如果给定的节点是元素节点, 则该节点必须是允许包含子节点的元素。
  4564. * @param { Node } node 目标节点
  4565. * @see UE.dom.Range:setStartAtFirst(Node)
  4566. * @return { UE.dom.Range } 当前range对象
  4567. */
  4568. setStartAtLast:function (node) {
  4569. return this.setStart(node, node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length);
  4570. },
  4571. /**
  4572. * 设置Range的结束位置到node节点内的第一个节点之前
  4573. * @method setEndAtFirst
  4574. * @param { Node } node 目标节点
  4575. * @remind 选区的结束容器将变成给定的节点, 且偏移量为0
  4576. * @remind node必须是一个元素节点, 且必须是允许包含子节点的元素。
  4577. * @see UE.dom.Range:setStartAtFirst(Node)
  4578. * @return { UE.dom.Range } 当前range对象
  4579. */
  4580. setEndAtFirst:function (node) {
  4581. return this.setEnd(node, 0);
  4582. },
  4583. /**
  4584. * 设置Range的结束位置到node节点内的最后一个节点之后
  4585. * @method setEndAtLast
  4586. * @param { Node } node 目标节点
  4587. * @remind 选区的结束容器将变成给定的节点, 且偏移量为该节点的子节点数量
  4588. * @remind node必须是一个元素节点, 且必须是允许包含子节点的元素。
  4589. * @see UE.dom.Range:setStartAtFirst(Node)
  4590. * @return { UE.dom.Range } 当前range对象
  4591. */
  4592. setEndAtLast:function (node) {
  4593. return this.setEnd(node, node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length);
  4594. },
  4595. /**
  4596. * 选中给定节点
  4597. * @method selectNode
  4598. * @remind 此时, 选区的开始容器和结束容器都是该节点的父节点, 其startOffset是该节点在父节点中的位置索引,
  4599. * 而endOffset为startOffset+1
  4600. * @param { Node } node 需要选中的节点
  4601. * @return { UE.dom.Range } 当前range对象,此时的range仅包含当前给定的节点对象
  4602. * @example
  4603. * ```html
  4604. * <!-- 选区示例 -->
  4605. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  4606. *
  4607. * <script>
  4608. *
  4609. * //执行操作
  4610. * range.selectNode( document.getElementsByTagName("i")[0] );
  4611. *
  4612. * //结果选区
  4613. * //<b>xx[<i>xxx</i>]<span>xxx</span>xxx</b>
  4614. *
  4615. * </script>
  4616. * ```
  4617. */
  4618. selectNode:function (node) {
  4619. return this.setStartBefore(node).setEndAfter(node);
  4620. },
  4621. /**
  4622. * 选中给定节点内部的所有节点
  4623. * @method selectNodeContents
  4624. * @remind 此时, 选区的开始容器和结束容器都是该节点, 其startOffset为0,
  4625. * 而endOffset是该节点的子节点数。
  4626. * @param { Node } node 目标节点, 当前range将包含该节点内的所有节点
  4627. * @return { UE.dom.Range } 当前range对象, 此时range仅包含给定节点的所有子节点
  4628. * @example
  4629. * ```html
  4630. * <!-- 选区示例 -->
  4631. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  4632. *
  4633. * <script>
  4634. *
  4635. * //执行操作
  4636. * range.selectNode( document.getElementsByTagName("b")[0] );
  4637. *
  4638. * //结果选区
  4639. * //<b>[xx<i>xxx</i><span>xxx</span>xxx]</b>
  4640. *
  4641. * </script>
  4642. * ```
  4643. */
  4644. selectNodeContents:function (node) {
  4645. return this.setStart(node, 0).setEndAtLast(node);
  4646. },
  4647. /**
  4648. * clone当前Range对象
  4649. * @method cloneRange
  4650. * @remind 返回的range是一个全新的range对象, 其内部所有属性与当前被clone的range相同。
  4651. * @return { UE.dom.Range } 当前range对象的一个副本
  4652. */
  4653. cloneRange:function () {
  4654. var me = this;
  4655. return new Range(me.document).setStart(me.startContainer, me.startOffset).setEnd(me.endContainer, me.endOffset);
  4656. },
  4657. /**
  4658. * 向当前选区的结束处闭合选区
  4659. * @method collapse
  4660. * @return { UE.dom.Range } 当前range对象
  4661. * @example
  4662. * ```html
  4663. * <!-- 选区示例 -->
  4664. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  4665. *
  4666. * <script>
  4667. *
  4668. * //执行操作
  4669. * range.collapse();
  4670. *
  4671. * //结果选区
  4672. * //“|”表示选区已闭合
  4673. * //<b>xx<i>xxx</i><span>xx|x</span>xxx</b>
  4674. *
  4675. * </script>
  4676. * ```
  4677. */
  4678. /**
  4679. * 闭合当前选区,根据给定的toStart参数项决定是向当前选区开始处闭合还是向结束处闭合,
  4680. * 如果toStart的值为true,则向开始位置闭合, 反之,向结束位置闭合。
  4681. * @method collapse
  4682. * @param { Boolean } toStart 是否向选区开始处闭合
  4683. * @return { UE.dom.Range } 当前range对象,此时range对象处于闭合状态
  4684. * @see UE.dom.Range:collapse()
  4685. * @example
  4686. * ```html
  4687. * <!-- 选区示例 -->
  4688. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  4689. *
  4690. * <script>
  4691. *
  4692. * //执行操作
  4693. * range.collapse( true );
  4694. *
  4695. * //结果选区
  4696. * //“|”表示选区已闭合
  4697. * //<b>xx<i>xxx</i><span>|xxx</span>xxx</b>
  4698. *
  4699. * </script>
  4700. * ```
  4701. */
  4702. collapse:function (toStart) {
  4703. var me = this;
  4704. if (toStart) {
  4705. me.endContainer = me.startContainer;
  4706. me.endOffset = me.startOffset;
  4707. } else {
  4708. me.startContainer = me.endContainer;
  4709. me.startOffset = me.endOffset;
  4710. }
  4711. me.collapsed = true;
  4712. return me;
  4713. },
  4714. /**
  4715. * 调整range的开始位置和结束位置,使其"收缩"到最小的位置
  4716. * @method shrinkBoundary
  4717. * @return { UE.dom.Range } 当前range对象
  4718. * @example
  4719. * ```html
  4720. * <span>xx<b>xx[</b>xxxxx]</span> => <span>xx<b>xx</b>[xxxxx]</span>
  4721. * ```
  4722. *
  4723. * @example
  4724. * ```html
  4725. * <!-- 选区示例 -->
  4726. * <b>x[xx</b><i>]xxx</i>
  4727. *
  4728. * <script>
  4729. *
  4730. * //执行收缩
  4731. * range.shrinkBoundary();
  4732. *
  4733. * //结果选区
  4734. * //<b>x[xx]</b><i>xxx</i>
  4735. * </script>
  4736. * ```
  4737. *
  4738. * @example
  4739. * ```html
  4740. * [<b><i>xxxx</i>xxxxxxx</b>] => <b><i>[xxxx</i>xxxxxxx]</b>
  4741. * ```
  4742. */
  4743. /**
  4744. * 调整range的开始位置和结束位置,使其"收缩"到最小的位置,
  4745. * 如果ignoreEnd的值为true,则忽略对结束位置的调整
  4746. * @method shrinkBoundary
  4747. * @param { Boolean } ignoreEnd 是否忽略对结束位置的调整
  4748. * @return { UE.dom.Range } 当前range对象
  4749. * @see UE.dom.domUtils.Range:shrinkBoundary()
  4750. */
  4751. shrinkBoundary:function (ignoreEnd) {
  4752. var me = this, child,
  4753. collapsed = me.collapsed;
  4754. function check(node){
  4755. return node.nodeType == 1 && !domUtils.isBookmarkNode(node) && !dtd.$empty[node.tagName] && !dtd.$nonChild[node.tagName]
  4756. }
  4757. while (me.startContainer.nodeType == 1 //是element
  4758. && (child = me.startContainer.childNodes[me.startOffset]) //子节点也是element
  4759. && check(child)) {
  4760. me.setStart(child, 0);
  4761. }
  4762. if (collapsed) {
  4763. return me.collapse(true);
  4764. }
  4765. if (!ignoreEnd) {
  4766. while (me.endContainer.nodeType == 1//是element
  4767. && me.endOffset > 0 //如果是空元素就退出 endOffset=0那么endOffst-1为负值,childNodes[endOffset]报错
  4768. && (child = me.endContainer.childNodes[me.endOffset - 1]) //子节点也是element
  4769. && check(child)) {
  4770. me.setEnd(child, child.childNodes.length);
  4771. }
  4772. }
  4773. return me;
  4774. },
  4775. /**
  4776. * 获取离当前选区内包含的所有节点最近的公共祖先节点,
  4777. * @method getCommonAncestor
  4778. * @remind 返回的公共祖先节点一定不是range自身的容器节点, 但有可能是一个文本节点
  4779. * @return { Node } 当前range对象内所有节点的公共祖先节点
  4780. * @example
  4781. * ```html
  4782. * //选区示例
  4783. * <span>xxx<b>x[x<em>xx]x</em>xxx</b>xx</span>
  4784. * <script>
  4785. *
  4786. * var node = range.getCommonAncestor();
  4787. *
  4788. * //公共祖先节点是: b节点
  4789. * //输出: B
  4790. * console.log(node.tagName);
  4791. *
  4792. * </script>
  4793. * ```
  4794. */
  4795. /**
  4796. * 获取当前选区所包含的所有节点的公共祖先节点, 可以根据给定的参数 includeSelf 决定获取到
  4797. * 的公共祖先节点是否可以是当前选区的startContainer或endContainer节点, 如果 includeSelf
  4798. * 的取值为true, 则返回的节点可以是自身的容器节点, 否则, 则不能是容器节点
  4799. * @method getCommonAncestor
  4800. * @param { Boolean } includeSelf 是否允许获取到的公共祖先节点是当前range对象的容器节点
  4801. * @return { Node } 当前range对象内所有节点的公共祖先节点
  4802. * @see UE.dom.Range:getCommonAncestor()
  4803. * @example
  4804. * ```html
  4805. * <body>
  4806. *
  4807. * <!-- 选区示例 -->
  4808. * <b>xxx<i>xxxx<span>xx[x</span>xx]x</i>xxxxxxx</b>
  4809. *
  4810. * <script>
  4811. *
  4812. * var node = range.getCommonAncestor( false );
  4813. *
  4814. * //这里的公共祖先节点是B而不是I, 是因为参数限制了获取到的节点不能是容器节点
  4815. * //output: B
  4816. * console.log( node.tagName );
  4817. *
  4818. * </script>
  4819. *
  4820. * </body>
  4821. * ```
  4822. */
  4823. /**
  4824. * 获取当前选区所包含的所有节点的公共祖先节点, 可以根据给定的参数 includeSelf 决定获取到
  4825. * 的公共祖先节点是否可以是当前选区的startContainer或endContainer节点, 如果 includeSelf
  4826. * 的取值为true, 则返回的节点可以是自身的容器节点, 否则, 则不能是容器节点; 同时可以根据
  4827. * ignoreTextNode 参数的取值决定是否忽略类型为文本节点的祖先节点。
  4828. * @method getCommonAncestor
  4829. * @param { Boolean } includeSelf 是否允许获取到的公共祖先节点是当前range对象的容器节点
  4830. * @param { Boolean } ignoreTextNode 获取祖先节点的过程中是否忽略类型为文本节点的祖先节点
  4831. * @return { Node } 当前range对象内所有节点的公共祖先节点
  4832. * @see UE.dom.Range:getCommonAncestor()
  4833. * @see UE.dom.Range:getCommonAncestor(Boolean)
  4834. * @example
  4835. * ```html
  4836. * <body>
  4837. *
  4838. * <!-- 选区示例 -->
  4839. * <b>xxx<i>xxxx<span>x[x]x</span>xxx</i>xxxxxxx</b>
  4840. *
  4841. * <script>
  4842. *
  4843. * var node = range.getCommonAncestor( true, false );
  4844. *
  4845. * //output: SPAN
  4846. * console.log( node.tagName );
  4847. *
  4848. * </script>
  4849. *
  4850. * </body>
  4851. * ```
  4852. */
  4853. getCommonAncestor:function (includeSelf, ignoreTextNode) {
  4854. var me = this,
  4855. start = me.startContainer,
  4856. end = me.endContainer;
  4857. if (start === end) {
  4858. if (includeSelf && selectOneNode(this)) {
  4859. start = start.childNodes[me.startOffset];
  4860. if(start.nodeType == 1)
  4861. return start;
  4862. }
  4863. //只有在上来就相等的情况下才会出现是文本的情况
  4864. return ignoreTextNode && start.nodeType == 3 ? start.parentNode : start;
  4865. }
  4866. return domUtils.getCommonAncestor(start, end);
  4867. },
  4868. /**
  4869. * 调整当前Range的开始和结束边界容器,如果是容器节点是文本节点,就调整到包含该文本节点的父节点上
  4870. * @method trimBoundary
  4871. * @remind 该操作有可能会引起文本节点被切开
  4872. * @return { UE.dom.Range } 当前range对象
  4873. * @example
  4874. * ```html
  4875. *
  4876. * //选区示例
  4877. * <b>xxx<i>[xxxxx]</i>xxx</b>
  4878. *
  4879. * <script>
  4880. * //未调整前, 选区的开始容器和结束都是文本节点
  4881. * //执行调整
  4882. * range.trimBoundary();
  4883. *
  4884. * //调整之后, 容器节点变成了i节点
  4885. * //<b>xxx[<i>xxxxx</i>]xxx</b>
  4886. * </script>
  4887. * ```
  4888. */
  4889. /**
  4890. * 调整当前Range的开始和结束边界容器,如果是容器节点是文本节点,就调整到包含该文本节点的父节点上,
  4891. * 可以根据 ignoreEnd 参数的值决定是否调整对结束边界的调整
  4892. * @method trimBoundary
  4893. * @param { Boolean } ignoreEnd 是否忽略对结束边界的调整
  4894. * @return { UE.dom.Range } 当前range对象
  4895. * @example
  4896. * ```html
  4897. *
  4898. * //选区示例
  4899. * <b>xxx<i>[xxxxx]</i>xxx</b>
  4900. *
  4901. * <script>
  4902. * //未调整前, 选区的开始容器和结束都是文本节点
  4903. * //执行调整
  4904. * range.trimBoundary( true );
  4905. *
  4906. * //调整之后, 开始容器节点变成了i节点
  4907. * //但是, 结束容器没有发生变化
  4908. * //<b>xxx[<i>xxxxx]</i>xxx</b>
  4909. * </script>
  4910. * ```
  4911. */
  4912. trimBoundary:function (ignoreEnd) {
  4913. this.txtToElmBoundary();
  4914. var start = this.startContainer,
  4915. offset = this.startOffset,
  4916. collapsed = this.collapsed,
  4917. end = this.endContainer;
  4918. if (start.nodeType == 3) {
  4919. if (offset == 0) {
  4920. this.setStartBefore(start);
  4921. } else {
  4922. if (offset >= start.nodeValue.length) {
  4923. this.setStartAfter(start);
  4924. } else {
  4925. var textNode = domUtils.split(start, offset);
  4926. //跟新结束边界
  4927. if (start === end) {
  4928. this.setEnd(textNode, this.endOffset - offset);
  4929. } else if (start.parentNode === end) {
  4930. this.endOffset += 1;
  4931. }
  4932. this.setStartBefore(textNode);
  4933. }
  4934. }
  4935. if (collapsed) {
  4936. return this.collapse(true);
  4937. }
  4938. }
  4939. if (!ignoreEnd) {
  4940. offset = this.endOffset;
  4941. end = this.endContainer;
  4942. if (end.nodeType == 3) {
  4943. if (offset == 0) {
  4944. this.setEndBefore(end);
  4945. } else {
  4946. offset < end.nodeValue.length && domUtils.split(end, offset);
  4947. this.setEndAfter(end);
  4948. }
  4949. }
  4950. }
  4951. return this;
  4952. },
  4953. /**
  4954. * 如果选区在文本的边界上,就扩展选区到文本的父节点上, 如果当前选区是闭合的, 则什么也不做
  4955. * @method txtToElmBoundary
  4956. * @remind 该操作不会修改dom节点
  4957. * @return { UE.dom.Range } 当前range对象
  4958. */
  4959. /**
  4960. * 如果选区在文本的边界上,就扩展选区到文本的父节点上, 如果当前选区是闭合的, 则根据参数项
  4961. * ignoreCollapsed 的值决定是否执行该调整
  4962. * @method txtToElmBoundary
  4963. * @param { Boolean } ignoreCollapsed 是否忽略选区的闭合状态, 如果该参数取值为true, 则
  4964. * 不论选区是否闭合, 都会执行该操作, 反之, 则不会对闭合的选区执行该操作
  4965. * @return { UE.dom.Range } 当前range对象
  4966. */
  4967. txtToElmBoundary:function (ignoreCollapsed) {
  4968. function adjust(r, c) {
  4969. var container = r[c + 'Container'],
  4970. offset = r[c + 'Offset'];
  4971. if (container.nodeType == 3) {
  4972. if (!offset) {
  4973. r['set' + c.replace(/(\w)/, function (a) {
  4974. return a.toUpperCase();
  4975. }) + 'Before'](container);
  4976. } else if (offset >= container.nodeValue.length) {
  4977. r['set' + c.replace(/(\w)/, function (a) {
  4978. return a.toUpperCase();
  4979. }) + 'After' ](container);
  4980. }
  4981. }
  4982. }
  4983. if (ignoreCollapsed || !this.collapsed) {
  4984. adjust(this, 'start');
  4985. adjust(this, 'end');
  4986. }
  4987. return this;
  4988. },
  4989. /**
  4990. * 在当前选区的开始位置前插入节点,新插入的节点会被该range包含
  4991. * @method insertNode
  4992. * @param { Node } node 需要插入的节点
  4993. * @remind 插入的节点可以是一个DocumentFragment依次插入多个节点
  4994. * @return { UE.dom.Range } 当前range对象
  4995. */
  4996. insertNode:function (node) {
  4997. var first = node, length = 1;
  4998. if (node.nodeType == 11) {
  4999. first = node.firstChild;
  5000. length = node.childNodes.length;
  5001. }
  5002. this.trimBoundary(true);
  5003. var start = this.startContainer,
  5004. offset = this.startOffset;
  5005. var nextNode = start.childNodes[ offset ];
  5006. if (nextNode) {
  5007. start.insertBefore(node, nextNode);
  5008. } else {
  5009. start.appendChild(node);
  5010. }
  5011. if (first.parentNode === this.endContainer) {
  5012. this.endOffset = this.endOffset + length;
  5013. }
  5014. return this.setStartBefore(first);
  5015. },
  5016. /**
  5017. * 闭合选区到当前选区的开始位置, 并且定位光标到闭合后的位置
  5018. * @method setCursor
  5019. * @return { UE.dom.Range } 当前range对象
  5020. * @see UE.dom.Range:collapse()
  5021. */
  5022. /**
  5023. * 闭合选区,可以根据参数toEnd的值控制选区是向前闭合还是向后闭合, 并且定位光标到闭合后的位置。
  5024. * @method setCursor
  5025. * @param { Boolean } toEnd 是否向后闭合, 如果为true, 则闭合选区时, 将向结束容器方向闭合,
  5026. * 反之,则向开始容器方向闭合
  5027. * @return { UE.dom.Range } 当前range对象
  5028. * @see UE.dom.Range:collapse(Boolean)
  5029. */
  5030. setCursor:function (toEnd, noFillData) {
  5031. return this.collapse(!toEnd).select(noFillData);
  5032. },
  5033. /**
  5034. * 创建当前range的一个书签,记录下当前range的位置,方便当dom树改变时,还能找回原来的选区位置
  5035. * @method createBookmark
  5036. * @param { Boolean } serialize 控制返回的标记位置是对当前位置的引用还是ID,如果该值为true,则
  5037. * 返回标记位置的ID, 反之则返回标记位置节点的引用
  5038. * @return { Object } 返回一个书签记录键值对, 其包含的key有: start => 开始标记的ID或者引用,
  5039. * end => 结束标记的ID或引用, id => 当前标记的类型, 如果为true,则表示
  5040. * 返回的记录的类型为ID, 反之则为引用
  5041. */
  5042. createBookmark:function (serialize, same) {
  5043. var endNode,
  5044. startNode = this.document.createElement('span');
  5045. startNode.style.cssText = 'display:none;line-height:0px;';
  5046. startNode.appendChild(this.document.createTextNode('\u200D'));
  5047. startNode.id = '_baidu_bookmark_start_' + (same ? '' : guid++);
  5048. if (!this.collapsed) {
  5049. endNode = startNode.cloneNode(true);
  5050. endNode.id = '_baidu_bookmark_end_' + (same ? '' : guid++);
  5051. }
  5052. this.insertNode(startNode);
  5053. if (endNode) {
  5054. this.collapse().insertNode(endNode).setEndBefore(endNode);
  5055. }
  5056. this.setStartAfter(startNode);
  5057. return {
  5058. start:serialize ? startNode.id : startNode,
  5059. end:endNode ? serialize ? endNode.id : endNode : null,
  5060. id:serialize
  5061. }
  5062. },
  5063. /**
  5064. * 调整当前range的边界到书签位置,并删除该书签对象所标记的位置内的节点
  5065. * @method moveToBookmark
  5066. * @param { BookMark } bookmark createBookmark所创建的标签对象
  5067. * @return { UE.dom.Range } 当前range对象
  5068. * @see UE.dom.Range:createBookmark(Boolean)
  5069. */
  5070. moveToBookmark:function (bookmark) {
  5071. var start = bookmark.id ? this.document.getElementById(bookmark.start) : bookmark.start,
  5072. end = bookmark.end && bookmark.id ? this.document.getElementById(bookmark.end) : bookmark.end;
  5073. this.setStartBefore(start);
  5074. domUtils.remove(start);
  5075. if (end) {
  5076. this.setEndBefore(end);
  5077. domUtils.remove(end);
  5078. } else {
  5079. this.collapse(true);
  5080. }
  5081. return this;
  5082. },
  5083. /**
  5084. * 调整range的边界,使其"放大"到最近的父节点
  5085. * @method enlarge
  5086. * @remind 会引起选区的变化
  5087. * @return { UE.dom.Range } 当前range对象
  5088. */
  5089. /**
  5090. * 调整range的边界,使其"放大"到最近的父节点,根据参数 toBlock 的取值, 可以
  5091. * 要求扩大之后的父节点是block节点
  5092. * @method enlarge
  5093. * @param { Boolean } toBlock 是否要求扩大之后的父节点必须是block节点
  5094. * @return { UE.dom.Range } 当前range对象
  5095. */
  5096. enlarge:function (toBlock, stopFn) {
  5097. var isBody = domUtils.isBody,
  5098. pre, node, tmp = this.document.createTextNode('');
  5099. if (toBlock) {
  5100. node = this.startContainer;
  5101. if (node.nodeType == 1) {
  5102. if (node.childNodes[this.startOffset]) {
  5103. pre = node = node.childNodes[this.startOffset]
  5104. } else {
  5105. node.appendChild(tmp);
  5106. pre = node = tmp;
  5107. }
  5108. } else {
  5109. pre = node;
  5110. }
  5111. while (1) {
  5112. if (domUtils.isBlockElm(node)) {
  5113. node = pre;
  5114. while ((pre = node.previousSibling) && !domUtils.isBlockElm(pre)) {
  5115. node = pre;
  5116. }
  5117. this.setStartBefore(node);
  5118. break;
  5119. }
  5120. pre = node;
  5121. node = node.parentNode;
  5122. }
  5123. node = this.endContainer;
  5124. if (node.nodeType == 1) {
  5125. if (pre = node.childNodes[this.endOffset]) {
  5126. node.insertBefore(tmp, pre);
  5127. } else {
  5128. node.appendChild(tmp);
  5129. }
  5130. pre = node = tmp;
  5131. } else {
  5132. pre = node;
  5133. }
  5134. while (1) {
  5135. if (domUtils.isBlockElm(node)) {
  5136. node = pre;
  5137. while ((pre = node.nextSibling) && !domUtils.isBlockElm(pre)) {
  5138. node = pre;
  5139. }
  5140. this.setEndAfter(node);
  5141. break;
  5142. }
  5143. pre = node;
  5144. node = node.parentNode;
  5145. }
  5146. if (tmp.parentNode === this.endContainer) {
  5147. this.endOffset--;
  5148. }
  5149. domUtils.remove(tmp);
  5150. }
  5151. // 扩展边界到最大
  5152. if (!this.collapsed) {
  5153. while (this.startOffset == 0) {
  5154. if (stopFn && stopFn(this.startContainer)) {
  5155. break;
  5156. }
  5157. if (isBody(this.startContainer)) {
  5158. break;
  5159. }
  5160. this.setStartBefore(this.startContainer);
  5161. }
  5162. while (this.endOffset == (this.endContainer.nodeType == 1 ? this.endContainer.childNodes.length : this.endContainer.nodeValue.length)) {
  5163. if (stopFn && stopFn(this.endContainer)) {
  5164. break;
  5165. }
  5166. if (isBody(this.endContainer)) {
  5167. break;
  5168. }
  5169. this.setEndAfter(this.endContainer);
  5170. }
  5171. }
  5172. return this;
  5173. },
  5174. enlargeToBlockElm:function(ignoreEnd){
  5175. while(!domUtils.isBlockElm(this.startContainer)){
  5176. this.setStartBefore(this.startContainer);
  5177. }
  5178. if(!ignoreEnd){
  5179. while(!domUtils.isBlockElm(this.endContainer)){
  5180. this.setEndAfter(this.endContainer);
  5181. }
  5182. }
  5183. return this;
  5184. },
  5185. /**
  5186. * 调整Range的边界,使其"缩小"到最合适的位置
  5187. * @method adjustmentBoundary
  5188. * @return { UE.dom.Range } 当前range对象
  5189. * @see UE.dom.Range:shrinkBoundary()
  5190. */
  5191. adjustmentBoundary:function () {
  5192. if (!this.collapsed) {
  5193. while (!domUtils.isBody(this.startContainer) &&
  5194. this.startOffset == this.startContainer[this.startContainer.nodeType == 3 ? 'nodeValue' : 'childNodes'].length &&
  5195. this.startContainer[this.startContainer.nodeType == 3 ? 'nodeValue' : 'childNodes'].length
  5196. ) {
  5197. this.setStartAfter(this.startContainer);
  5198. }
  5199. while (!domUtils.isBody(this.endContainer) && !this.endOffset &&
  5200. this.endContainer[this.endContainer.nodeType == 3 ? 'nodeValue' : 'childNodes'].length
  5201. ) {
  5202. this.setEndBefore(this.endContainer);
  5203. }
  5204. }
  5205. return this;
  5206. },
  5207. /**
  5208. * 给range选区中的内容添加给定的inline标签
  5209. * @method applyInlineStyle
  5210. * @param { String } tagName 需要添加的标签名
  5211. * @example
  5212. * ```html
  5213. * <p>xxxx[xxxx]x</p> ==> range.applyInlineStyle("strong") ==> <p>xxxx[<strong>xxxx</strong>]x</p>
  5214. * ```
  5215. */
  5216. /**
  5217. * 给range选区中的内容添加给定的inline标签, 并且为标签附加上一些初始化属性。
  5218. * @method applyInlineStyle
  5219. * @param { String } tagName 需要添加的标签名
  5220. * @param { Object } attrs 跟随新添加的标签的属性
  5221. * @return { UE.dom.Range } 当前选区
  5222. * @example
  5223. * ```html
  5224. * <p>xxxx[xxxx]x</p>
  5225. *
  5226. * ==>
  5227. *
  5228. * <!-- 执行操作 -->
  5229. * range.applyInlineStyle("strong",{"style":"font-size:12px"})
  5230. *
  5231. * ==>
  5232. *
  5233. * <p>xxxx[<strong style="font-size:12px">xxxx</strong>]x</p>
  5234. * ```
  5235. */
  5236. applyInlineStyle:function (tagName, attrs, list) {
  5237. if (this.collapsed)return this;
  5238. this.trimBoundary().enlarge(false,
  5239. function (node) {
  5240. return node.nodeType == 1 && domUtils.isBlockElm(node)
  5241. }).adjustmentBoundary();
  5242. var bookmark = this.createBookmark(),
  5243. end = bookmark.end,
  5244. filterFn = function (node) {
  5245. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' : !domUtils.isWhitespace(node);
  5246. },
  5247. current = domUtils.getNextDomNode(bookmark.start, false, filterFn),
  5248. node,
  5249. pre,
  5250. range = this.cloneRange();
  5251. while (current && (domUtils.getPosition(current, end) & domUtils.POSITION_PRECEDING)) {
  5252. if (current.nodeType == 3 || dtd[tagName][current.tagName]) {
  5253. range.setStartBefore(current);
  5254. node = current;
  5255. while (node && (node.nodeType == 3 || dtd[tagName][node.tagName]) && node !== end) {
  5256. pre = node;
  5257. node = domUtils.getNextDomNode(node, node.nodeType == 1, null, function (parent) {
  5258. return dtd[tagName][parent.tagName];
  5259. });
  5260. }
  5261. var frag = range.setEndAfter(pre).extractContents(), elm;
  5262. if (list && list.length > 0) {
  5263. var level, top;
  5264. top = level = list[0].cloneNode(false);
  5265. for (var i = 1, ci; ci = list[i++];) {
  5266. level.appendChild(ci.cloneNode(false));
  5267. level = level.firstChild;
  5268. }
  5269. elm = level;
  5270. } else {
  5271. elm = range.document.createElement(tagName);
  5272. }
  5273. if (attrs) {
  5274. domUtils.setAttributes(elm, attrs);
  5275. }
  5276. elm.appendChild(frag);
  5277. range.insertNode(list ? top : elm);
  5278. //处理下滑线在a上的情况
  5279. var aNode;
  5280. if (tagName == 'span' && attrs.style && /text\-decoration/.test(attrs.style) && (aNode = domUtils.findParentByTagName(elm, 'a', true))) {
  5281. domUtils.setAttributes(aNode, attrs);
  5282. domUtils.remove(elm, true);
  5283. elm = aNode;
  5284. } else {
  5285. domUtils.mergeSibling(elm);
  5286. domUtils.clearEmptySibling(elm);
  5287. }
  5288. //去除子节点相同的
  5289. domUtils.mergeChild(elm, attrs);
  5290. current = domUtils.getNextDomNode(elm, false, filterFn);
  5291. domUtils.mergeToParent(elm);
  5292. if (node === end) {
  5293. break;
  5294. }
  5295. } else {
  5296. current = domUtils.getNextDomNode(current, true, filterFn);
  5297. }
  5298. }
  5299. return this.moveToBookmark(bookmark);
  5300. },
  5301. /**
  5302. * 移除当前选区内指定的inline标签,但保留其中的内容
  5303. * @method removeInlineStyle
  5304. * @param { String } tagName 需要移除的标签名
  5305. * @return { UE.dom.Range } 当前的range对象
  5306. * @example
  5307. * ```html
  5308. * xx[x<span>xxx<em>yyy</em>zz]z</span> => range.removeInlineStyle(["em"]) => xx[x<span>xxxyyyzz]z</span>
  5309. * ```
  5310. */
  5311. /**
  5312. * 移除当前选区内指定的一组inline标签,但保留其中的内容
  5313. * @method removeInlineStyle
  5314. * @param { Array } tagNameArr 需要移除的标签名的数组
  5315. * @return { UE.dom.Range } 当前的range对象
  5316. * @see UE.dom.Range:removeInlineStyle(String)
  5317. */
  5318. removeInlineStyle:function (tagNames) {
  5319. if (this.collapsed)return this;
  5320. tagNames = utils.isArray(tagNames) ? tagNames : [tagNames];
  5321. this.shrinkBoundary().adjustmentBoundary();
  5322. var start = this.startContainer, end = this.endContainer;
  5323. while (1) {
  5324. if (start.nodeType == 1) {
  5325. if (utils.indexOf(tagNames, start.tagName.toLowerCase()) > -1) {
  5326. break;
  5327. }
  5328. if (start.tagName.toLowerCase() == 'body') {
  5329. start = null;
  5330. break;
  5331. }
  5332. }
  5333. start = start.parentNode;
  5334. }
  5335. while (1) {
  5336. if (end.nodeType == 1) {
  5337. if (utils.indexOf(tagNames, end.tagName.toLowerCase()) > -1) {
  5338. break;
  5339. }
  5340. if (end.tagName.toLowerCase() == 'body') {
  5341. end = null;
  5342. break;
  5343. }
  5344. }
  5345. end = end.parentNode;
  5346. }
  5347. var bookmark = this.createBookmark(),
  5348. frag,
  5349. tmpRange;
  5350. if (start) {
  5351. tmpRange = this.cloneRange().setEndBefore(bookmark.start).setStartBefore(start);
  5352. frag = tmpRange.extractContents();
  5353. tmpRange.insertNode(frag);
  5354. domUtils.clearEmptySibling(start, true);
  5355. start.parentNode.insertBefore(bookmark.start, start);
  5356. }
  5357. if (end) {
  5358. tmpRange = this.cloneRange().setStartAfter(bookmark.end).setEndAfter(end);
  5359. frag = tmpRange.extractContents();
  5360. tmpRange.insertNode(frag);
  5361. domUtils.clearEmptySibling(end, false, true);
  5362. end.parentNode.insertBefore(bookmark.end, end.nextSibling);
  5363. }
  5364. var current = domUtils.getNextDomNode(bookmark.start, false, function (node) {
  5365. return node.nodeType == 1;
  5366. }), next;
  5367. while (current && current !== bookmark.end) {
  5368. next = domUtils.getNextDomNode(current, true, function (node) {
  5369. return node.nodeType == 1;
  5370. });
  5371. if (utils.indexOf(tagNames, current.tagName.toLowerCase()) > -1) {
  5372. domUtils.remove(current, true);
  5373. }
  5374. current = next;
  5375. }
  5376. return this.moveToBookmark(bookmark);
  5377. },
  5378. /**
  5379. * 获取当前选中的自闭合的节点
  5380. * @method getClosedNode
  5381. * @return { Node | NULL } 如果当前选中的是自闭合节点, 则返回该节点, 否则返回NULL
  5382. */
  5383. getClosedNode:function () {
  5384. var node;
  5385. if (!this.collapsed) {
  5386. var range = this.cloneRange().adjustmentBoundary().shrinkBoundary();
  5387. if (selectOneNode(range)) {
  5388. var child = range.startContainer.childNodes[range.startOffset];
  5389. if (child && child.nodeType == 1 && (dtd.$empty[child.tagName] || dtd.$nonChild[child.tagName])) {
  5390. node = child;
  5391. }
  5392. }
  5393. }
  5394. return node;
  5395. },
  5396. /**
  5397. * 在页面上高亮range所表示的选区
  5398. * @method select
  5399. * @return { UE.dom.Range } 返回当前Range对象
  5400. */
  5401. //这里不区分ie9以上,trace:3824
  5402. select:browser.ie ? function (noFillData, textRange) {
  5403. var nativeRange;
  5404. if (!this.collapsed)
  5405. this.shrinkBoundary();
  5406. var node = this.getClosedNode();
  5407. if (node && !textRange) {
  5408. try {
  5409. nativeRange = this.document.body.createControlRange();
  5410. nativeRange.addElement(node);
  5411. nativeRange.select();
  5412. } catch (e) {}
  5413. return this;
  5414. }
  5415. var bookmark = this.createBookmark(),
  5416. start = bookmark.start,
  5417. end;
  5418. nativeRange = this.document.body.createTextRange();
  5419. nativeRange.moveToElementText(start);
  5420. nativeRange.moveStart('character', 1);
  5421. if (!this.collapsed) {
  5422. var nativeRangeEnd = this.document.body.createTextRange();
  5423. end = bookmark.end;
  5424. nativeRangeEnd.moveToElementText(end);
  5425. nativeRange.setEndPoint('EndToEnd', nativeRangeEnd);
  5426. } else {
  5427. if (!noFillData && this.startContainer.nodeType != 3) {
  5428. //使用<span>|x<span>固定住光标
  5429. var tmpText = this.document.createTextNode(fillChar),
  5430. tmp = this.document.createElement('span');
  5431. tmp.appendChild(this.document.createTextNode(fillChar));
  5432. start.parentNode.insertBefore(tmp, start);
  5433. start.parentNode.insertBefore(tmpText, start);
  5434. //当点b,i,u时,不能清除i上边的b
  5435. removeFillData(this.document, tmpText);
  5436. fillData = tmpText;
  5437. mergeSibling(tmp, 'previousSibling');
  5438. mergeSibling(start, 'nextSibling');
  5439. nativeRange.moveStart('character', -1);
  5440. nativeRange.collapse(true);
  5441. }
  5442. }
  5443. this.moveToBookmark(bookmark);
  5444. tmp && domUtils.remove(tmp);
  5445. //IE在隐藏状态下不支持range操作,catch一下
  5446. try {
  5447. nativeRange.select();
  5448. } catch (e) {
  5449. }
  5450. return this;
  5451. } : function (notInsertFillData) {
  5452. function checkOffset(rng){
  5453. function check(node,offset,dir){
  5454. if(node.nodeType == 3 && node.nodeValue.length < offset){
  5455. rng[dir + 'Offset'] = node.nodeValue.length
  5456. }
  5457. }
  5458. check(rng.startContainer,rng.startOffset,'start');
  5459. check(rng.endContainer,rng.endOffset,'end');
  5460. }
  5461. var win = domUtils.getWindow(this.document),
  5462. sel = win.getSelection(),
  5463. txtNode;
  5464. //FF下关闭自动长高时滚动条在关闭dialog时会跳
  5465. //ff下如果不body.focus将不能定位闭合光标到编辑器内
  5466. browser.gecko ? this.document.body.focus() : win.focus();
  5467. if (sel) {
  5468. sel.removeAllRanges();
  5469. // trace:870 chrome/safari后边是br对于闭合得range不能定位 所以去掉了判断
  5470. // this.startContainer.nodeType != 3 &&! ((child = this.startContainer.childNodes[this.startOffset]) && child.nodeType == 1 && child.tagName == 'BR'
  5471. if (this.collapsed && !notInsertFillData) {
  5472. // //opear如果没有节点接着,原生的不能够定位,不能在body的第一级插入空白节点
  5473. // if (notInsertFillData && browser.opera && !domUtils.isBody(this.startContainer) && this.startContainer.nodeType == 1) {
  5474. // var tmp = this.document.createTextNode('');
  5475. // this.insertNode(tmp).setStart(tmp, 0).collapse(true);
  5476. // }
  5477. //
  5478. //处理光标落在文本节点的情况
  5479. //处理以下的情况
  5480. //<b>|xxxx</b>
  5481. //<b>xxxx</b>|xxxx
  5482. //xxxx<b>|</b>
  5483. var start = this.startContainer,child = start;
  5484. if(start.nodeType == 1){
  5485. child = start.childNodes[this.startOffset];
  5486. }
  5487. if( !(start.nodeType == 3 && this.startOffset) &&
  5488. (child ?
  5489. (!child.previousSibling || child.previousSibling.nodeType != 3)
  5490. :
  5491. (!start.lastChild || start.lastChild.nodeType != 3)
  5492. )
  5493. ){
  5494. txtNode = this.document.createTextNode(fillChar);
  5495. //跟着前边走
  5496. this.insertNode(txtNode);
  5497. removeFillData(this.document, txtNode);
  5498. mergeSibling(txtNode, 'previousSibling');
  5499. mergeSibling(txtNode, 'nextSibling');
  5500. fillData = txtNode;
  5501. this.setStart(txtNode, browser.webkit ? 1 : 0).collapse(true);
  5502. }
  5503. }
  5504. var nativeRange = this.document.createRange();
  5505. if(this.collapsed && browser.opera && this.startContainer.nodeType == 1){
  5506. var child = this.startContainer.childNodes[this.startOffset];
  5507. if(!child){
  5508. //往前靠拢
  5509. child = this.startContainer.lastChild;
  5510. if( child && domUtils.isBr(child)){
  5511. this.setStartBefore(child).collapse(true);
  5512. }
  5513. }else{
  5514. //向后靠拢
  5515. while(child && domUtils.isBlockElm(child)){
  5516. if(child.nodeType == 1 && child.childNodes[0]){
  5517. child = child.childNodes[0]
  5518. }else{
  5519. break;
  5520. }
  5521. }
  5522. child && this.setStartBefore(child).collapse(true)
  5523. }
  5524. }
  5525. //是createAddress最后一位算的不准,现在这里进行微调
  5526. checkOffset(this);
  5527. nativeRange.setStart(this.startContainer, this.startOffset);
  5528. nativeRange.setEnd(this.endContainer, this.endOffset);
  5529. sel.addRange(nativeRange);
  5530. }
  5531. return this;
  5532. },
  5533. /**
  5534. * 滚动到当前range开始的位置
  5535. * @method scrollToView
  5536. * @param { Window } win 当前range对象所属的window对象
  5537. * @return { UE.dom.Range } 当前Range对象
  5538. */
  5539. /**
  5540. * 滚动到距离当前range开始位置 offset 的位置处
  5541. * @method scrollToView
  5542. * @param { Window } win 当前range对象所属的window对象
  5543. * @param { Number } offset 距离range开始位置处的偏移量, 如果为正数, 则向下偏移, 反之, 则向上偏移
  5544. * @return { UE.dom.Range } 当前Range对象
  5545. */
  5546. scrollToView:function (win, offset) {
  5547. win = win ? window : domUtils.getWindow(this.document);
  5548. var me = this,
  5549. span = me.document.createElement('span');
  5550. //trace:717
  5551. span.innerHTML = '&nbsp;';
  5552. me.cloneRange().insertNode(span);
  5553. domUtils.scrollToView(span, win, offset);
  5554. domUtils.remove(span);
  5555. return me;
  5556. },
  5557. /**
  5558. * 判断当前选区内容是否占位符
  5559. * @private
  5560. * @method inFillChar
  5561. * @return { Boolean } 如果是占位符返回true,否则返回false
  5562. */
  5563. inFillChar : function(){
  5564. var start = this.startContainer;
  5565. if(this.collapsed && start.nodeType == 3
  5566. && start.nodeValue.replace(new RegExp('^' + domUtils.fillChar),'').length + 1 == start.nodeValue.length
  5567. ){
  5568. return true;
  5569. }
  5570. return false;
  5571. },
  5572. /**
  5573. * 保存
  5574. * @method createAddress
  5575. * @private
  5576. * @return { Boolean } 返回开始和结束的位置
  5577. * @example
  5578. * ```html
  5579. * <body>
  5580. * <p>
  5581. * aaaa
  5582. * <em>
  5583. * <!-- 选区开始 -->
  5584. * bbbb
  5585. * <!-- 选区结束 -->
  5586. * </em>
  5587. * </p>
  5588. *
  5589. * <script>
  5590. * //output: {startAddress:[0,1,0,0],endAddress:[0,1,0,4]}
  5591. * console.log( range.createAddress() );
  5592. * </script>
  5593. * </body>
  5594. * ```
  5595. */
  5596. createAddress : function(ignoreEnd,ignoreTxt){
  5597. var addr = {},me = this;
  5598. function getAddress(isStart){
  5599. var node = isStart ? me.startContainer : me.endContainer;
  5600. var parents = domUtils.findParents(node,true,function(node){return !domUtils.isBody(node)}),
  5601. addrs = [];
  5602. for(var i = 0,ci;ci = parents[i++];){
  5603. addrs.push(domUtils.getNodeIndex(ci,ignoreTxt));
  5604. }
  5605. var firstIndex = 0;
  5606. if(ignoreTxt){
  5607. if(node.nodeType == 3){
  5608. var tmpNode = node.previousSibling;
  5609. while(tmpNode && tmpNode.nodeType == 3){
  5610. firstIndex += tmpNode.nodeValue.replace(fillCharReg,'').length;
  5611. tmpNode = tmpNode.previousSibling;
  5612. }
  5613. firstIndex += (isStart ? me.startOffset : me.endOffset)// - (fillCharReg.test(node.nodeValue) ? 1 : 0 )
  5614. }else{
  5615. node = node.childNodes[ isStart ? me.startOffset : me.endOffset];
  5616. if(node){
  5617. firstIndex = domUtils.getNodeIndex(node,ignoreTxt);
  5618. }else{
  5619. node = isStart ? me.startContainer : me.endContainer;
  5620. var first = node.firstChild;
  5621. while(first){
  5622. if(domUtils.isFillChar(first)){
  5623. first = first.nextSibling;
  5624. continue;
  5625. }
  5626. firstIndex++;
  5627. if(first.nodeType == 3){
  5628. while( first && first.nodeType == 3){
  5629. first = first.nextSibling;
  5630. }
  5631. }else{
  5632. first = first.nextSibling;
  5633. }
  5634. }
  5635. }
  5636. }
  5637. }else{
  5638. firstIndex = isStart ? domUtils.isFillChar(node) ? 0 : me.startOffset : me.endOffset
  5639. }
  5640. if(firstIndex < 0){
  5641. firstIndex = 0;
  5642. }
  5643. addrs.push(firstIndex);
  5644. return addrs;
  5645. }
  5646. addr.startAddress = getAddress(true);
  5647. if(!ignoreEnd){
  5648. addr.endAddress = me.collapsed ? [].concat(addr.startAddress) : getAddress();
  5649. }
  5650. return addr;
  5651. },
  5652. /**
  5653. * 保存
  5654. * @method createAddress
  5655. * @private
  5656. * @return { Boolean } 返回开始和结束的位置
  5657. * @example
  5658. * ```html
  5659. * <body>
  5660. * <p>
  5661. * aaaa
  5662. * <em>
  5663. * <!-- 选区开始 -->
  5664. * bbbb
  5665. * <!-- 选区结束 -->
  5666. * </em>
  5667. * </p>
  5668. *
  5669. * <script>
  5670. * var range = editor.selection.getRange();
  5671. * range.moveToAddress({startAddress:[0,1,0,0],endAddress:[0,1,0,4]});
  5672. * range.select();
  5673. * //output: 'bbbb'
  5674. * console.log(editor.selection.getText());
  5675. * </script>
  5676. * </body>
  5677. * ```
  5678. */
  5679. moveToAddress : function(addr,ignoreEnd){
  5680. var me = this;
  5681. function getNode(address,isStart){
  5682. var tmpNode = me.document.body,
  5683. parentNode,offset;
  5684. for(var i= 0,ci,l=address.length;i<l;i++){
  5685. ci = address[i];
  5686. parentNode = tmpNode;
  5687. tmpNode = tmpNode.childNodes[ci];
  5688. if(!tmpNode){
  5689. offset = ci;
  5690. break;
  5691. }
  5692. }
  5693. if(isStart){
  5694. if(tmpNode){
  5695. me.setStartBefore(tmpNode)
  5696. }else{
  5697. me.setStart(parentNode,offset)
  5698. }
  5699. }else{
  5700. if(tmpNode){
  5701. me.setEndBefore(tmpNode)
  5702. }else{
  5703. me.setEnd(parentNode,offset)
  5704. }
  5705. }
  5706. }
  5707. getNode(addr.startAddress,true);
  5708. !ignoreEnd && addr.endAddress && getNode(addr.endAddress);
  5709. return me;
  5710. },
  5711. /**
  5712. * 判断给定的Range对象是否和当前Range对象表示的是同一个选区
  5713. * @method equals
  5714. * @param { UE.dom.Range } 需要判断的Range对象
  5715. * @return { Boolean } 如果给定的Range对象与当前Range对象表示的是同一个选区, 则返回true, 否则返回false
  5716. */
  5717. equals : function(rng){
  5718. for(var p in this){
  5719. if(this.hasOwnProperty(p)){
  5720. if(this[p] !== rng[p])
  5721. return false
  5722. }
  5723. }
  5724. return true;
  5725. },
  5726. /**
  5727. * 遍历range内的节点。每当遍历一个节点时, 都会执行参数项 doFn 指定的函数, 该函数的接受当前遍历的节点
  5728. * 作为其参数。
  5729. * @method traversal
  5730. * @param { Function } doFn 对每个遍历的节点要执行的方法, 该方法接受当前遍历的节点作为其参数
  5731. * @return { UE.dom.Range } 当前range对象
  5732. * @example
  5733. * ```html
  5734. *
  5735. * <body>
  5736. *
  5737. * <!-- 选区开始 -->
  5738. * <span></span>
  5739. * <a></a>
  5740. * <!-- 选区结束 -->
  5741. * </body>
  5742. *
  5743. * <script>
  5744. *
  5745. * //output: <span></span><a></a>
  5746. * console.log( range.cloneContents() );
  5747. *
  5748. * range.traversal( function ( node ) {
  5749. *
  5750. * if ( node.nodeType === 1 ) {
  5751. * node.className = "test";
  5752. * }
  5753. *
  5754. * } );
  5755. *
  5756. * //output: <span class="test"></span><a class="test"></a>
  5757. * console.log( range.cloneContents() );
  5758. *
  5759. * </script>
  5760. * ```
  5761. */
  5762. /**
  5763. * 遍历range内的节点。
  5764. * 每当遍历一个节点时, 都会执行参数项 doFn 指定的函数, 该函数的接受当前遍历的节点
  5765. * 作为其参数。
  5766. * 可以通过参数项 filterFn 来指定一个过滤器, 只有符合该过滤器过滤规则的节点才会触
  5767. * 发doFn函数的执行
  5768. * @method traversal
  5769. * @param { Function } doFn 对每个遍历的节点要执行的方法, 该方法接受当前遍历的节点作为其参数
  5770. * @param { Function } filterFn 过滤器, 该函数接受当前遍历的节点作为参数, 如果该节点满足过滤
  5771. * 规则, 请返回true, 该节点会触发doFn, 否则, 请返回false, 则该节点不
  5772. * 会触发doFn。
  5773. * @return { UE.dom.Range } 当前range对象
  5774. * @see UE.dom.Range:traversal(Function)
  5775. * @example
  5776. * ```html
  5777. *
  5778. * <body>
  5779. *
  5780. * <!-- 选区开始 -->
  5781. * <span></span>
  5782. * <a></a>
  5783. * <!-- 选区结束 -->
  5784. * </body>
  5785. *
  5786. * <script>
  5787. *
  5788. * //output: <span></span><a></a>
  5789. * console.log( range.cloneContents() );
  5790. *
  5791. * range.traversal( function ( node ) {
  5792. *
  5793. * node.className = "test";
  5794. *
  5795. * }, function ( node ) {
  5796. * return node.nodeType === 1;
  5797. * } );
  5798. *
  5799. * //output: <span class="test"></span><a class="test"></a>
  5800. * console.log( range.cloneContents() );
  5801. *
  5802. * </script>
  5803. * ```
  5804. */
  5805. traversal:function(doFn,filterFn){
  5806. if (this.collapsed)
  5807. return this;
  5808. var bookmark = this.createBookmark(),
  5809. end = bookmark.end,
  5810. current = domUtils.getNextDomNode(bookmark.start, false, filterFn);
  5811. while (current && current !== end && (domUtils.getPosition(current, end) & domUtils.POSITION_PRECEDING)) {
  5812. var tmpNode = domUtils.getNextDomNode(current,false,filterFn);
  5813. doFn(current);
  5814. current = tmpNode;
  5815. }
  5816. return this.moveToBookmark(bookmark);
  5817. }
  5818. };
  5819. })();
  5820. // core/Selection.js
  5821. /**
  5822. * 选集
  5823. * @file
  5824. * @module UE.dom
  5825. * @class Selection
  5826. * @since 1.2.6.1
  5827. */
  5828. /**
  5829. * 选区集合
  5830. * @unfile
  5831. * @module UE.dom
  5832. * @class Selection
  5833. */
  5834. (function () {
  5835. function getBoundaryInformation( range, start ) {
  5836. var getIndex = domUtils.getNodeIndex;
  5837. range = range.duplicate();
  5838. range.collapse( start );
  5839. var parent = range.parentElement();
  5840. //如果节点里没有子节点,直接退出
  5841. if ( !parent.hasChildNodes() ) {
  5842. return {container:parent, offset:0};
  5843. }
  5844. var siblings = parent.children,
  5845. child,
  5846. testRange = range.duplicate(),
  5847. startIndex = 0, endIndex = siblings.length - 1, index = -1,
  5848. distance;
  5849. while ( startIndex <= endIndex ) {
  5850. index = Math.floor( (startIndex + endIndex) / 2 );
  5851. child = siblings[index];
  5852. testRange.moveToElementText( child );
  5853. var position = testRange.compareEndPoints( 'StartToStart', range );
  5854. if ( position > 0 ) {
  5855. endIndex = index - 1;
  5856. } else if ( position < 0 ) {
  5857. startIndex = index + 1;
  5858. } else {
  5859. //trace:1043
  5860. return {container:parent, offset:getIndex( child )};
  5861. }
  5862. }
  5863. if ( index == -1 ) {
  5864. testRange.moveToElementText( parent );
  5865. testRange.setEndPoint( 'StartToStart', range );
  5866. distance = testRange.text.replace( /(\r\n|\r)/g, '\n' ).length;
  5867. siblings = parent.childNodes;
  5868. if ( !distance ) {
  5869. child = siblings[siblings.length - 1];
  5870. return {container:child, offset:child.nodeValue.length};
  5871. }
  5872. var i = siblings.length;
  5873. while ( distance > 0 ){
  5874. distance -= siblings[ --i ].nodeValue.length;
  5875. }
  5876. return {container:siblings[i], offset:-distance};
  5877. }
  5878. testRange.collapse( position > 0 );
  5879. testRange.setEndPoint( position > 0 ? 'StartToStart' : 'EndToStart', range );
  5880. distance = testRange.text.replace( /(\r\n|\r)/g, '\n' ).length;
  5881. if ( !distance ) {
  5882. return dtd.$empty[child.tagName] || dtd.$nonChild[child.tagName] ?
  5883. {container:parent, offset:getIndex( child ) + (position > 0 ? 0 : 1)} :
  5884. {container:child, offset:position > 0 ? 0 : child.childNodes.length}
  5885. }
  5886. while ( distance > 0 ) {
  5887. try {
  5888. var pre = child;
  5889. child = child[position > 0 ? 'previousSibling' : 'nextSibling'];
  5890. distance -= child.nodeValue.length;
  5891. } catch ( e ) {
  5892. return {container:parent, offset:getIndex( pre )};
  5893. }
  5894. }
  5895. return {container:child, offset:position > 0 ? -distance : child.nodeValue.length + distance}
  5896. }
  5897. /**
  5898. * 将ieRange转换为Range对象
  5899. * @param {Range} ieRange ieRange对象
  5900. * @param {Range} range Range对象
  5901. * @return {Range} range 返回转换后的Range对象
  5902. */
  5903. function transformIERangeToRange( ieRange, range ) {
  5904. if ( ieRange.item ) {
  5905. range.selectNode( ieRange.item( 0 ) );
  5906. } else {
  5907. var bi = getBoundaryInformation( ieRange, true );
  5908. range.setStart( bi.container, bi.offset );
  5909. if ( ieRange.compareEndPoints( 'StartToEnd', ieRange ) != 0 ) {
  5910. bi = getBoundaryInformation( ieRange, false );
  5911. range.setEnd( bi.container, bi.offset );
  5912. }
  5913. }
  5914. return range;
  5915. }
  5916. /**
  5917. * 获得ieRange
  5918. * @param {Selection} sel Selection对象
  5919. * @return {ieRange} 得到ieRange
  5920. */
  5921. function _getIERange( sel ) {
  5922. var ieRange;
  5923. //ie下有可能报错
  5924. try {
  5925. ieRange = sel.getNative().createRange();
  5926. } catch ( e ) {
  5927. return null;
  5928. }
  5929. var el = ieRange.item ? ieRange.item( 0 ) : ieRange.parentElement();
  5930. if ( ( el.ownerDocument || el ) === sel.document ) {
  5931. return ieRange;
  5932. }
  5933. return null;
  5934. }
  5935. var Selection = dom.Selection = function ( doc ) {
  5936. var me = this, iframe;
  5937. me.document = doc;
  5938. if ( browser.ie9below ) {
  5939. iframe = domUtils.getWindow( doc ).frameElement;
  5940. domUtils.on( iframe, 'beforedeactivate', function () {
  5941. me._bakIERange = me.getIERange();
  5942. } );
  5943. domUtils.on( iframe, 'activate', function () {
  5944. try {
  5945. if ( !_getIERange( me ) && me._bakIERange ) {
  5946. me._bakIERange.select();
  5947. }
  5948. } catch ( ex ) {
  5949. }
  5950. me._bakIERange = null;
  5951. } );
  5952. }
  5953. iframe = doc = null;
  5954. };
  5955. Selection.prototype = {
  5956. rangeInBody : function(rng,txtRange){
  5957. var node = browser.ie9below || txtRange ? rng.item ? rng.item() : rng.parentElement() : rng.startContainer;
  5958. return node === this.document.body || domUtils.inDoc(node,this.document);
  5959. },
  5960. /**
  5961. * 获取原生seleciton对象
  5962. * @method getNative
  5963. * @return { Object } 获得selection对象
  5964. * @example
  5965. * ```javascript
  5966. * editor.selection.getNative();
  5967. * ```
  5968. */
  5969. getNative:function () {
  5970. var doc = this.document;
  5971. try {
  5972. return !doc ? null : browser.ie9below ? doc.selection : domUtils.getWindow( doc ).getSelection();
  5973. } catch ( e ) {
  5974. return null;
  5975. }
  5976. },
  5977. /**
  5978. * 获得ieRange
  5979. * @method getIERange
  5980. * @return { Object } 返回ie原生的Range
  5981. * @example
  5982. * ```javascript
  5983. * editor.selection.getIERange();
  5984. * ```
  5985. */
  5986. getIERange:function () {
  5987. var ieRange = _getIERange( this );
  5988. if ( !ieRange ) {
  5989. if ( this._bakIERange ) {
  5990. return this._bakIERange;
  5991. }
  5992. }
  5993. return ieRange;
  5994. },
  5995. /**
  5996. * 缓存当前选区的range和选区的开始节点
  5997. * @method cache
  5998. */
  5999. cache:function () {
  6000. this.clear();
  6001. this._cachedRange = this.getRange();
  6002. this._cachedStartElement = this.getStart();
  6003. this._cachedStartElementPath = this.getStartElementPath();
  6004. },
  6005. /**
  6006. * 获取选区开始位置的父节点到body
  6007. * @method getStartElementPath
  6008. * @return { Array } 返回父节点集合
  6009. * @example
  6010. * ```javascript
  6011. * editor.selection.getStartElementPath();
  6012. * ```
  6013. */
  6014. getStartElementPath:function () {
  6015. if ( this._cachedStartElementPath ) {
  6016. return this._cachedStartElementPath;
  6017. }
  6018. var start = this.getStart();
  6019. if ( start ) {
  6020. return domUtils.findParents( start, true, null, true )
  6021. }
  6022. return [];
  6023. },
  6024. /**
  6025. * 清空缓存
  6026. * @method clear
  6027. */
  6028. clear:function () {
  6029. this._cachedStartElementPath = this._cachedRange = this._cachedStartElement = null;
  6030. },
  6031. /**
  6032. * 编辑器是否得到了选区
  6033. * @method isFocus
  6034. */
  6035. isFocus:function () {
  6036. try {
  6037. if(browser.ie9below){
  6038. var nativeRange = _getIERange(this);
  6039. return !!(nativeRange && this.rangeInBody(nativeRange));
  6040. }else{
  6041. return !!this.getNative().rangeCount;
  6042. }
  6043. } catch ( e ) {
  6044. return false;
  6045. }
  6046. },
  6047. /**
  6048. * 获取选区对应的Range
  6049. * @method getRange
  6050. * @return { Object } 得到Range对象
  6051. * @example
  6052. * ```javascript
  6053. * editor.selection.getRange();
  6054. * ```
  6055. */
  6056. getRange:function () {
  6057. var me = this;
  6058. function optimze( range ) {
  6059. var child = me.document.body.firstChild,
  6060. collapsed = range.collapsed;
  6061. while ( child && child.firstChild ) {
  6062. range.setStart( child, 0 );
  6063. child = child.firstChild;
  6064. }
  6065. if ( !range.startContainer ) {
  6066. range.setStart( me.document.body, 0 )
  6067. }
  6068. if ( collapsed ) {
  6069. range.collapse( true );
  6070. }
  6071. }
  6072. if ( me._cachedRange != null ) {
  6073. return this._cachedRange;
  6074. }
  6075. var range = new baidu.editor.dom.Range( me.document );
  6076. if ( browser.ie9below ) {
  6077. var nativeRange = me.getIERange();
  6078. if ( nativeRange ) {
  6079. //备份的_bakIERange可能已经实效了,dom树发生了变化比如从源码模式切回来,所以try一下,实效就放到body开始位置
  6080. try{
  6081. transformIERangeToRange( nativeRange, range );
  6082. }catch(e){
  6083. optimze( range );
  6084. }
  6085. } else {
  6086. optimze( range );
  6087. }
  6088. } else {
  6089. var sel = me.getNative();
  6090. if ( sel && sel.rangeCount ) {
  6091. var firstRange = sel.getRangeAt( 0 );
  6092. var lastRange = sel.getRangeAt( sel.rangeCount - 1 );
  6093. range.setStart( firstRange.startContainer, firstRange.startOffset ).setEnd( lastRange.endContainer, lastRange.endOffset );
  6094. if ( range.collapsed && domUtils.isBody( range.startContainer ) && !range.startOffset ) {
  6095. optimze( range );
  6096. }
  6097. } else {
  6098. //trace:1734 有可能已经不在dom树上了,标识的节点
  6099. if ( this._bakRange && domUtils.inDoc( this._bakRange.startContainer, this.document ) ){
  6100. return this._bakRange;
  6101. }
  6102. optimze( range );
  6103. }
  6104. }
  6105. return this._bakRange = range;
  6106. },
  6107. /**
  6108. * 获取开始元素,用于状态反射
  6109. * @method getStart
  6110. * @return { Element } 获得开始元素
  6111. * @example
  6112. * ```javascript
  6113. * editor.selection.getStart();
  6114. * ```
  6115. */
  6116. getStart:function () {
  6117. if ( this._cachedStartElement ) {
  6118. return this._cachedStartElement;
  6119. }
  6120. var range = browser.ie9below ? this.getIERange() : this.getRange(),
  6121. tmpRange,
  6122. start, tmp, parent;
  6123. if ( browser.ie9below ) {
  6124. if ( !range ) {
  6125. //todo 给第一个值可能会有问题
  6126. return this.document.body.firstChild;
  6127. }
  6128. //control元素
  6129. if ( range.item ){
  6130. return range.item( 0 );
  6131. }
  6132. tmpRange = range.duplicate();
  6133. //修正ie下<b>x</b>[xx] 闭合后 <b>x|</b>xx
  6134. tmpRange.text.length > 0 && tmpRange.moveStart( 'character', 1 );
  6135. tmpRange.collapse( 1 );
  6136. start = tmpRange.parentElement();
  6137. parent = tmp = range.parentElement();
  6138. while ( tmp = tmp.parentNode ) {
  6139. if ( tmp == start ) {
  6140. start = parent;
  6141. break;
  6142. }
  6143. }
  6144. } else {
  6145. range.shrinkBoundary();
  6146. start = range.startContainer;
  6147. if ( start.nodeType == 1 && start.hasChildNodes() ){
  6148. start = start.childNodes[Math.min( start.childNodes.length - 1, range.startOffset )];
  6149. }
  6150. if ( start.nodeType == 3 ){
  6151. return start.parentNode;
  6152. }
  6153. }
  6154. return start;
  6155. },
  6156. /**
  6157. * 得到选区中的文本
  6158. * @method getText
  6159. * @return { String } 选区中包含的文本
  6160. * @example
  6161. * ```javascript
  6162. * editor.selection.getText();
  6163. * ```
  6164. */
  6165. getText:function () {
  6166. var nativeSel, nativeRange;
  6167. if ( this.isFocus() && (nativeSel = this.getNative()) ) {
  6168. nativeRange = browser.ie9below ? nativeSel.createRange() : nativeSel.getRangeAt( 0 );
  6169. return browser.ie9below ? nativeRange.text : nativeRange.toString();
  6170. }
  6171. return '';
  6172. },
  6173. /**
  6174. * 清除选区
  6175. * @method clearRange
  6176. * @example
  6177. * ```javascript
  6178. * editor.selection.clearRange();
  6179. * ```
  6180. */
  6181. clearRange : function(){
  6182. this.getNative()[browser.ie9below ? 'empty' : 'removeAllRanges']();
  6183. }
  6184. };
  6185. })();
  6186. // core/Editor.js
  6187. /**
  6188. * 编辑器主类,包含编辑器提供的大部分公用接口
  6189. * @file
  6190. * @module UE
  6191. * @class Editor
  6192. * @since 1.2.6.1
  6193. */
  6194. /**
  6195. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  6196. * @unfile
  6197. * @module UE
  6198. */
  6199. /**
  6200. * UEditor的核心类,为用户提供与编辑器交互的接口。
  6201. * @unfile
  6202. * @module UE
  6203. * @class Editor
  6204. */
  6205. (function () {
  6206. var uid = 0, _selectionChangeTimer;
  6207. /**
  6208. * 获取编辑器的html内容,赋值到编辑器所在表单的textarea文本域里面
  6209. * @private
  6210. * @method setValue
  6211. * @param { UE.Editor } editor 编辑器事例
  6212. */
  6213. function setValue(form, editor) {
  6214. var textarea;
  6215. if (editor.textarea) {
  6216. if (utils.isString(editor.textarea)) {
  6217. for (var i = 0, ti, tis = domUtils.getElementsByTagName(form, 'textarea'); ti = tis[i++];) {
  6218. if (ti.id == 'ueditor_textarea_' + editor.options.textarea) {
  6219. textarea = ti;
  6220. break;
  6221. }
  6222. }
  6223. } else {
  6224. textarea = editor.textarea;
  6225. }
  6226. }
  6227. if (!textarea) {
  6228. form.appendChild(textarea = domUtils.createElement(document, 'textarea', {
  6229. 'name': editor.options.textarea,
  6230. 'id': 'ueditor_textarea_' + editor.options.textarea,
  6231. 'style': "display:none"
  6232. }));
  6233. //不要产生多个textarea
  6234. editor.textarea = textarea;
  6235. }
  6236. !textarea.getAttribute('name') && textarea.setAttribute('name', editor.options.textarea );
  6237. textarea.value = editor.hasContents() ?
  6238. (editor.options.allHtmlEnabled ? editor.getAllHtml() : editor.getContent(null, null, true)) :
  6239. ''
  6240. }
  6241. function loadPlugins(me){
  6242. //初始化插件
  6243. for (var pi in UE.plugins) {
  6244. UE.plugins[pi].call(me);
  6245. }
  6246. }
  6247. function checkCurLang(I18N){
  6248. for(var lang in I18N){
  6249. return lang
  6250. }
  6251. }
  6252. function langReadied(me){
  6253. me.langIsReady = true;
  6254. me.fireEvent("langReady");
  6255. }
  6256. /**
  6257. * 编辑器准备就绪后会触发该事件
  6258. * @module UE
  6259. * @class Editor
  6260. * @event ready
  6261. * @remind render方法执行完成之后,会触发该事件
  6262. * @remind
  6263. * @example
  6264. * ```javascript
  6265. * editor.addListener( 'ready', function( editor ) {
  6266. * editor.execCommand( 'focus' ); //编辑器家在完成后,让编辑器拿到焦点
  6267. * } );
  6268. * ```
  6269. */
  6270. /**
  6271. * 执行destroy方法,会触发该事件
  6272. * @module UE
  6273. * @class Editor
  6274. * @event destroy
  6275. * @see UE.Editor:destroy()
  6276. */
  6277. /**
  6278. * 执行reset方法,会触发该事件
  6279. * @module UE
  6280. * @class Editor
  6281. * @event reset
  6282. * @see UE.Editor:reset()
  6283. */
  6284. /**
  6285. * 执行focus方法,会触发该事件
  6286. * @module UE
  6287. * @class Editor
  6288. * @event focus
  6289. * @see UE.Editor:focus(Boolean)
  6290. */
  6291. /**
  6292. * 语言加载完成会触发该事件
  6293. * @module UE
  6294. * @class Editor
  6295. * @event langReady
  6296. */
  6297. /**
  6298. * 运行命令之后会触发该命令
  6299. * @module UE
  6300. * @class Editor
  6301. * @event beforeExecCommand
  6302. */
  6303. /**
  6304. * 运行命令之后会触发该命令
  6305. * @module UE
  6306. * @class Editor
  6307. * @event afterExecCommand
  6308. */
  6309. /**
  6310. * 运行命令之前会触发该命令
  6311. * @module UE
  6312. * @class Editor
  6313. * @event firstBeforeExecCommand
  6314. */
  6315. /**
  6316. * 在getContent方法执行之前会触发该事件
  6317. * @module UE
  6318. * @class Editor
  6319. * @event beforeGetContent
  6320. * @see UE.Editor:getContent()
  6321. */
  6322. /**
  6323. * 在getContent方法执行之后会触发该事件
  6324. * @module UE
  6325. * @class Editor
  6326. * @event afterGetContent
  6327. * @see UE.Editor:getContent()
  6328. */
  6329. /**
  6330. * 在getAllHtml方法执行时会触发该事件
  6331. * @module UE
  6332. * @class Editor
  6333. * @event getAllHtml
  6334. * @see UE.Editor:getAllHtml()
  6335. */
  6336. /**
  6337. * 在setContent方法执行之前会触发该事件
  6338. * @module UE
  6339. * @class Editor
  6340. * @event beforeSetContent
  6341. * @see UE.Editor:setContent(String)
  6342. */
  6343. /**
  6344. * 在setContent方法执行之后会触发该事件
  6345. * @module UE
  6346. * @class Editor
  6347. * @event afterSetContent
  6348. * @see UE.Editor:setContent(String)
  6349. */
  6350. /**
  6351. * 每当编辑器内部选区发生改变时,将触发该事件
  6352. * @event selectionchange
  6353. * @warning 该事件的触发非常频繁,不建议在该事件的处理过程中做重量级的处理
  6354. * @example
  6355. * ```javascript
  6356. * editor.addListener( 'selectionchange', function( editor ) {
  6357. * console.log('选区发生改变');
  6358. * }
  6359. */
  6360. /**
  6361. * 在所有selectionchange的监听函数执行之前,会触发该事件
  6362. * @module UE
  6363. * @class Editor
  6364. * @event beforeSelectionChange
  6365. * @see UE.Editor:selectionchange
  6366. */
  6367. /**
  6368. * 在所有selectionchange的监听函数执行完之后,会触发该事件
  6369. * @module UE
  6370. * @class Editor
  6371. * @event afterSelectionChange
  6372. * @see UE.Editor:selectionchange
  6373. */
  6374. /**
  6375. * 编辑器内容发生改变时会触发该事件
  6376. * @module UE
  6377. * @class Editor
  6378. * @event contentChange
  6379. */
  6380. /**
  6381. * 以默认参数构建一个编辑器实例
  6382. * @constructor
  6383. * @remind 通过 改构造方法实例化的编辑器,不带ui层.需要render到一个容器,编辑器实例才能正常渲染到页面
  6384. * @example
  6385. * ```javascript
  6386. * var editor = new UE.Editor();
  6387. * editor.execCommand('blod');
  6388. * ```
  6389. * @see UE.Config
  6390. */
  6391. /**
  6392. * 以给定的参数集合创建一个编辑器实例,对于未指定的参数,将应用默认参数。
  6393. * @constructor
  6394. * @remind 通过 改构造方法实例化的编辑器,不带ui层.需要render到一个容器,编辑器实例才能正常渲染到页面
  6395. * @param { Object } setting 创建编辑器的参数
  6396. * @example
  6397. * ```javascript
  6398. * var editor = new UE.Editor();
  6399. * editor.execCommand('blod');
  6400. * ```
  6401. * @see UE.Config
  6402. */
  6403. var Editor = UE.Editor = function (options) {
  6404. var me = this;
  6405. me.uid = uid++;
  6406. EventBase.call(me);
  6407. me.commands = {};
  6408. me.options = utils.extend(utils.clone(options || {}), UEDITOR_CONFIG, true);
  6409. me.shortcutkeys = {};
  6410. me.inputRules = [];
  6411. me.outputRules = [];
  6412. //设置默认的常用属性
  6413. me.setOpt(Editor.defaultOptions(me));
  6414. /* 尝试异步加载后台配置 */
  6415. me.loadServerConfig();
  6416. if(!utils.isEmptyObject(UE.I18N)){
  6417. //修改默认的语言类型
  6418. me.options.lang = checkCurLang(UE.I18N);
  6419. UE.plugin.load(me);
  6420. langReadied(me);
  6421. }else{
  6422. utils.loadFile(document, {
  6423. src: me.options.langPath + me.options.lang + "/" + me.options.lang + ".js",
  6424. tag: "script",
  6425. type: "text/javascript",
  6426. defer: "defer"
  6427. }, function () {
  6428. UE.plugin.load(me);
  6429. langReadied(me);
  6430. });
  6431. }
  6432. UE.instants['ueditorInstant' + me.uid] = me;
  6433. };
  6434. Editor.prototype = {
  6435. registerCommand : function(name,obj){
  6436. this.commands[name] = obj;
  6437. },
  6438. /**
  6439. * 编辑器对外提供的监听ready事件的接口, 通过调用该方法,达到的效果与监听ready事件是一致的
  6440. * @method ready
  6441. * @param { Function } fn 编辑器ready之后所执行的回调, 如果在注册事件之前编辑器已经ready,将会
  6442. * 立即触发该回调。
  6443. * @remind 需要等待编辑器加载完成后才能执行的代码,可以使用该方法传入
  6444. * @example
  6445. * ```javascript
  6446. * editor.ready( function( editor ) {
  6447. * editor.setContent('初始化完毕');
  6448. * } );
  6449. * ```
  6450. * @see UE.Editor.event:ready
  6451. */
  6452. ready: function (fn) {
  6453. var me = this;
  6454. if (fn) {
  6455. me.isReady ? fn.apply(me) : me.addListener('ready', fn);
  6456. }
  6457. },
  6458. /**
  6459. * 该方法是提供给插件里面使用,设置配置项默认值
  6460. * @method setOpt
  6461. * @warning 三处设置配置项的优先级: 实例化时传入参数 > setOpt()设置 > config文件里设置
  6462. * @warning 该方法仅供编辑器插件内部和编辑器初始化时调用,其他地方不能调用。
  6463. * @param { String } key 编辑器的可接受的选项名称
  6464. * @param { * } val 该选项可接受的值
  6465. * @example
  6466. * ```javascript
  6467. * editor.setOpt( 'initContent', '欢迎使用编辑器' );
  6468. * ```
  6469. */
  6470. /**
  6471. * 该方法是提供给插件里面使用,以{key:value}集合的方式设置插件内用到的配置项默认值
  6472. * @method setOpt
  6473. * @warning 三处设置配置项的优先级: 实例化时传入参数 > setOpt()设置 > config文件里设置
  6474. * @warning 该方法仅供编辑器插件内部和编辑器初始化时调用,其他地方不能调用。
  6475. * @param { Object } options 将要设置的选项的键值对对象
  6476. * @example
  6477. * ```javascript
  6478. * editor.setOpt( {
  6479. * 'initContent': '欢迎使用编辑器'
  6480. * } );
  6481. * ```
  6482. */
  6483. setOpt: function (key, val) {
  6484. var obj = {};
  6485. if (utils.isString(key)) {
  6486. obj[key] = val
  6487. } else {
  6488. obj = key;
  6489. }
  6490. utils.extend(this.options, obj, true);
  6491. },
  6492. getOpt:function(key){
  6493. return this.options[key]
  6494. },
  6495. /**
  6496. * 销毁编辑器实例,使用textarea代替
  6497. * @method destroy
  6498. * @example
  6499. * ```javascript
  6500. * editor.destroy();
  6501. * ```
  6502. */
  6503. destroy: function () {
  6504. var me = this;
  6505. me.fireEvent('destroy');
  6506. var container = me.container.parentNode;
  6507. var textarea = me.textarea;
  6508. if (!textarea) {
  6509. textarea = document.createElement('textarea');
  6510. container.parentNode.insertBefore(textarea, container);
  6511. } else {
  6512. textarea.style.display = ''
  6513. }
  6514. textarea.style.width = me.iframe.offsetWidth + 'px';
  6515. textarea.style.height = me.iframe.offsetHeight + 'px';
  6516. textarea.value = me.getContent();
  6517. textarea.id = me.key;
  6518. container.innerHTML = '';
  6519. domUtils.remove(container);
  6520. var key = me.key;
  6521. //trace:2004
  6522. for (var p in me) {
  6523. if (me.hasOwnProperty(p)) {
  6524. delete this[p];
  6525. }
  6526. }
  6527. UE.delEditor(key);
  6528. },
  6529. /**
  6530. * 渲染编辑器的DOM到指定容器
  6531. * @method render
  6532. * @param { String } containerId 指定一个容器ID
  6533. * @remind 执行该方法,会触发ready事件
  6534. * @warning 必须且只能调用一次
  6535. */
  6536. /**
  6537. * 渲染编辑器的DOM到指定容器
  6538. * @method render
  6539. * @param { Element } containerDom 直接指定容器对象
  6540. * @remind 执行该方法,会触发ready事件
  6541. * @warning 必须且只能调用一次
  6542. */
  6543. render: function (container) {
  6544. var me = this,
  6545. options = me.options,
  6546. getStyleValue=function(attr){
  6547. return parseInt(domUtils.getComputedStyle(container,attr));
  6548. };
  6549. if (utils.isString(container)) {
  6550. container = document.getElementById(container);
  6551. }
  6552. if (container) {
  6553. if(options.initialFrameWidth){
  6554. options.minFrameWidth = options.initialFrameWidth
  6555. }else{
  6556. options.minFrameWidth = options.initialFrameWidth = container.offsetWidth;
  6557. }
  6558. if(options.initialFrameHeight){
  6559. options.minFrameHeight = options.initialFrameHeight
  6560. }else{
  6561. options.initialFrameHeight = options.minFrameHeight = container.offsetHeight;
  6562. }
  6563. container.style.width = /%$/.test(options.initialFrameWidth) ? '100%' : options.initialFrameWidth-
  6564. getStyleValue("padding-left")- getStyleValue("padding-right") +'px';
  6565. container.style.height = /%$/.test(options.initialFrameHeight) ? '100%' : options.initialFrameHeight -
  6566. getStyleValue("padding-top")- getStyleValue("padding-bottom") +'px';
  6567. container.style.zIndex = options.zIndex;
  6568. var html = ( ie && browser.version < 9 ? '' : '<!DOCTYPE html>') +
  6569. '<html xmlns=\'http://www.w3.org/1999/xhtml\' class=\'view\' ><head>' +
  6570. '<style type=\'text/css\'>' +
  6571. //设置四周的留边
  6572. '.view{padding:0;word-wrap:break-word;cursor:text;height:90%;}\n' +
  6573. //设置默认字体和字号
  6574. //font-family不能呢随便改,在safari下fillchar会有解析问题
  6575. 'body{margin:8px;font-family:sans-serif;font-size:16px;}' +
  6576. //设置段落间距
  6577. 'p{margin:5px 0;}</style>' +
  6578. ( options.iframeCssUrl ? '<link rel=\'stylesheet\' type=\'text/css\' href=\'' + utils.unhtml(options.iframeCssUrl) + '\'/>' : '' ) +
  6579. (options.initialStyle ? '<style>' + options.initialStyle + '</style>' : '') +
  6580. '</head><body class=\'view\' ></body>' +
  6581. '<script type=\'text/javascript\' ' + (ie ? 'defer=\'defer\'' : '' ) +' id=\'_initialScript\'>' +
  6582. 'setTimeout(function(){editor = window.parent.UE.instants[\'ueditorInstant' + me.uid + '\'];editor._setup(document);},0);' +
  6583. 'var _tmpScript = document.getElementById(\'_initialScript\');_tmpScript.parentNode.removeChild(_tmpScript);</script></html>';
  6584. container.appendChild(domUtils.createElement(document, 'iframe', {
  6585. id: 'ueditor_' + me.uid,
  6586. width: "100%",
  6587. height: "100%",
  6588. frameborder: "0",
  6589. //先注释掉了,加的原因忘记了,但开启会直接导致全屏模式下内容多时不会出现滚动条
  6590. // scrolling :'no',
  6591. src: 'javascript:void(function(){document.open();' + (options.customDomain && document.domain != location.hostname ? 'document.domain="' + document.domain + '";' : '') +
  6592. 'document.write("' + html + '");document.close();}())'
  6593. }));
  6594. container.style.overflow = 'hidden';
  6595. //解决如果是给定的百分比,会导致高度算不对的问题
  6596. setTimeout(function(){
  6597. if( /%$/.test(options.initialFrameWidth)){
  6598. options.minFrameWidth = options.initialFrameWidth = container.offsetWidth;
  6599. //如果这里给定宽度,会导致ie在拖动窗口大小时,编辑区域不随着变化
  6600. // container.style.width = options.initialFrameWidth + 'px';
  6601. }
  6602. if(/%$/.test(options.initialFrameHeight)){
  6603. options.minFrameHeight = options.initialFrameHeight = container.offsetHeight;
  6604. container.style.height = options.initialFrameHeight + 'px';
  6605. }
  6606. })
  6607. }
  6608. },
  6609. /**
  6610. * 编辑器初始化
  6611. * @method _setup
  6612. * @private
  6613. * @param { Element } doc 编辑器Iframe中的文档对象
  6614. */
  6615. _setup: function (doc) {
  6616. var me = this,
  6617. options = me.options;
  6618. if (ie) {
  6619. doc.body.disabled = true;
  6620. doc.body.contentEditable = true;
  6621. doc.body.disabled = false;
  6622. } else {
  6623. doc.body.contentEditable = true;
  6624. }
  6625. doc.body.spellcheck = false;
  6626. me.document = doc;
  6627. me.window = doc.defaultView || doc.parentWindow;
  6628. me.iframe = me.window.frameElement;
  6629. me.body = doc.body;
  6630. me.selection = new dom.Selection(doc);
  6631. //gecko初始化就能得到range,无法判断isFocus了
  6632. var geckoSel;
  6633. if (browser.gecko && (geckoSel = this.selection.getNative())) {
  6634. geckoSel.removeAllRanges();
  6635. }
  6636. this._initEvents();
  6637. //为form提交提供一个隐藏的textarea
  6638. for (var form = this.iframe.parentNode; !domUtils.isBody(form); form = form.parentNode) {
  6639. if (form.tagName == 'FORM') {
  6640. me.form = form;
  6641. if(me.options.autoSyncData){
  6642. domUtils.on(me.window,'blur',function(){
  6643. setValue(form,me);
  6644. });
  6645. }else{
  6646. domUtils.on(form, 'submit', function () {
  6647. setValue(this, me);
  6648. });
  6649. }
  6650. break;
  6651. }
  6652. }
  6653. if (options.initialContent) {
  6654. if (options.autoClearinitialContent) {
  6655. var oldExecCommand = me.execCommand;
  6656. me.execCommand = function () {
  6657. me.fireEvent('firstBeforeExecCommand');
  6658. return oldExecCommand.apply(me, arguments);
  6659. };
  6660. this._setDefaultContent(options.initialContent);
  6661. } else
  6662. this.setContent(options.initialContent, false, true);
  6663. }
  6664. //编辑器不能为空内容
  6665. if (domUtils.isEmptyNode(me.body)) {
  6666. me.body.innerHTML = '<p>' + (browser.ie ? '' : '<br/>') + '</p>';
  6667. }
  6668. //如果要求focus, 就把光标定位到内容开始
  6669. if (options.focus) {
  6670. setTimeout(function () {
  6671. me.focus(me.options.focusInEnd);
  6672. //如果自动清除开着,就不需要做selectionchange;
  6673. !me.options.autoClearinitialContent && me._selectionChange();
  6674. }, 0);
  6675. }
  6676. if (!me.container) {
  6677. me.container = this.iframe.parentNode;
  6678. }
  6679. if (options.fullscreen && me.ui) {
  6680. me.ui.setFullScreen(true);
  6681. }
  6682. try {
  6683. me.document.execCommand('2D-position', false, false);
  6684. } catch (e) {
  6685. }
  6686. try {
  6687. me.document.execCommand('enableInlineTableEditing', false, false);
  6688. } catch (e) {
  6689. }
  6690. try {
  6691. me.document.execCommand('enableObjectResizing', false, false);
  6692. } catch (e) {
  6693. }
  6694. //挂接快捷键
  6695. me._bindshortcutKeys();
  6696. me.isReady = 1;
  6697. me.fireEvent('ready');
  6698. options.onready && options.onready.call(me);
  6699. if (!browser.ie9below) {
  6700. domUtils.on(me.window, ['blur', 'focus'], function (e) {
  6701. //chrome下会出现alt+tab切换时,导致选区位置不对
  6702. if (e.type == 'blur') {
  6703. me._bakRange = me.selection.getRange();
  6704. try {
  6705. me._bakNativeRange = me.selection.getNative().getRangeAt(0);
  6706. me.selection.getNative().removeAllRanges();
  6707. } catch (e) {
  6708. me._bakNativeRange = null;
  6709. }
  6710. } else {
  6711. try {
  6712. me._bakRange && me._bakRange.select();
  6713. } catch (e) {
  6714. }
  6715. }
  6716. });
  6717. }
  6718. //trace:1518 ff3.6body不够寛,会导致点击空白处无法获得焦点
  6719. if (browser.gecko && browser.version <= 10902) {
  6720. //修复ff3.6初始化进来,不能点击获得焦点
  6721. me.body.contentEditable = false;
  6722. setTimeout(function () {
  6723. me.body.contentEditable = true;
  6724. }, 100);
  6725. setInterval(function () {
  6726. me.body.style.height = me.iframe.offsetHeight - 20 + 'px'
  6727. }, 100)
  6728. }
  6729. !options.isShow && me.setHide();
  6730. options.readonly && me.setDisabled();
  6731. },
  6732. /**
  6733. * 同步数据到编辑器所在的form
  6734. * 从编辑器的容器节点向上查找form元素,若找到,就同步编辑内容到找到的form里,为提交数据做准备,主要用于是手动提交的情况
  6735. * 后台取得数据的键值,使用你容器上的name属性,如果没有就使用参数里的textarea项
  6736. * @method sync
  6737. * @example
  6738. * ```javascript
  6739. * editor.sync();
  6740. * form.sumbit(); //form变量已经指向了form元素
  6741. * ```
  6742. */
  6743. /**
  6744. * 根据传入的formId,在页面上查找要同步数据的表单,若找到,就同步编辑内容到找到的form里,为提交数据做准备
  6745. * 后台取得数据的键值,该键值默认使用给定的编辑器容器的name属性,如果没有name属性则使用参数项里给定的“textarea”项
  6746. * @method sync
  6747. * @param { String } formID 指定一个要同步数据的form的id,编辑器的数据会同步到你指定form下
  6748. */
  6749. sync: function (formId) {
  6750. var me = this,
  6751. form = formId ? document.getElementById(formId) :
  6752. domUtils.findParent(me.iframe.parentNode, function (node) {
  6753. return node.tagName == 'FORM'
  6754. }, true);
  6755. form && setValue(form, me);
  6756. },
  6757. /**
  6758. * 设置编辑器高度
  6759. * @method setHeight
  6760. * @remind 当配置项autoHeightEnabled为真时,该方法无效
  6761. * @param { Number } number 设置的高度值,纯数值,不带单位
  6762. * @example
  6763. * ```javascript
  6764. * editor.setHeight(number);
  6765. * ```
  6766. */
  6767. setHeight: function (height,notSetHeight) {
  6768. if (height !== parseInt(this.iframe.parentNode.style.height)) {
  6769. this.iframe.parentNode.style.height = height + 'px';
  6770. }
  6771. !notSetHeight && (this.options.minFrameHeight = this.options.initialFrameHeight = height);
  6772. this.body.style.height = height + 'px';
  6773. !notSetHeight && this.trigger('setHeight')
  6774. },
  6775. /**
  6776. * 为编辑器的编辑命令提供快捷键
  6777. * 这个接口是为插件扩展提供的接口,主要是为新添加的插件,如果需要添加快捷键,所提供的接口
  6778. * @method addshortcutkey
  6779. * @param { Object } keyset 命令名和快捷键键值对对象,多个按钮的快捷键用“+”分隔
  6780. * @example
  6781. * ```javascript
  6782. * editor.addshortcutkey({
  6783. * "Bold" : "ctrl+66",//^B
  6784. * "Italic" : "ctrl+73", //^I
  6785. * });
  6786. * ```
  6787. */
  6788. /**
  6789. * 这个接口是为插件扩展提供的接口,主要是为新添加的插件,如果需要添加快捷键,所提供的接口
  6790. * @method addshortcutkey
  6791. * @param { String } cmd 触发快捷键时,响应的命令
  6792. * @param { String } keys 快捷键的字符串,多个按钮用“+”分隔
  6793. * @example
  6794. * ```javascript
  6795. * editor.addshortcutkey("Underline", "ctrl+85"); //^U
  6796. * ```
  6797. */
  6798. addshortcutkey: function (cmd, keys) {
  6799. var obj = {};
  6800. if (keys) {
  6801. obj[cmd] = keys
  6802. } else {
  6803. obj = cmd;
  6804. }
  6805. utils.extend(this.shortcutkeys, obj)
  6806. },
  6807. /**
  6808. * 对编辑器设置keydown事件监听,绑定快捷键和命令,当快捷键组合触发成功,会响应对应的命令
  6809. * @method _bindshortcutKeys
  6810. * @private
  6811. */
  6812. _bindshortcutKeys: function () {
  6813. var me = this, shortcutkeys = this.shortcutkeys;
  6814. me.addListener('keydown', function (type, e) {
  6815. var keyCode = e.keyCode || e.which;
  6816. for (var i in shortcutkeys) {
  6817. var tmp = shortcutkeys[i].split(',');
  6818. for (var t = 0, ti; ti = tmp[t++];) {
  6819. ti = ti.split(':');
  6820. var key = ti[0], param = ti[1];
  6821. if (/^(ctrl)(\+shift)?\+(\d+)$/.test(key.toLowerCase()) || /^(\d+)$/.test(key)) {
  6822. if (( (RegExp.$1 == 'ctrl' ? (e.ctrlKey || e.metaKey) : 0)
  6823. && (RegExp.$2 != "" ? e[RegExp.$2.slice(1) + "Key"] : 1)
  6824. && keyCode == RegExp.$3
  6825. ) ||
  6826. keyCode == RegExp.$1
  6827. ) {
  6828. if (me.queryCommandState(i,param) != -1)
  6829. me.execCommand(i, param);
  6830. domUtils.preventDefault(e);
  6831. }
  6832. }
  6833. }
  6834. }
  6835. });
  6836. },
  6837. /**
  6838. * 获取编辑器的内容
  6839. * @method getContent
  6840. * @warning 该方法获取到的是经过编辑器内置的过滤规则进行过滤后得到的内容
  6841. * @return { String } 编辑器的内容字符串, 如果编辑器的内容为空,或者是空的标签内容(如:”&lt;p&gt;&lt;br/&gt;&lt;/p&gt;“), 则返回空字符串
  6842. * @example
  6843. * ```javascript
  6844. * //编辑器html内容:<p>1<strong>2<em>34</em>5</strong>6</p>
  6845. * var content = editor.getContent(); //返回值:<p>1<strong>2<em>34</em>5</strong>6</p>
  6846. * ```
  6847. */
  6848. /**
  6849. * 获取编辑器的内容。 可以通过参数定义编辑器内置的判空规则
  6850. * @method getContent
  6851. * @param { Function } fn 自定的判空规则, 要求该方法返回一个boolean类型的值,
  6852. * 代表当前编辑器的内容是否空,
  6853. * 如果返回true, 则该方法将直接返回空字符串;如果返回false,则编辑器将返回
  6854. * 经过内置过滤规则处理后的内容。
  6855. * @remind 该方法在处理包含有初始化内容的时候能起到很好的作用。
  6856. * @warning 该方法获取到的是经过编辑器内置的过滤规则进行过滤后得到的内容
  6857. * @return { String } 编辑器的内容字符串
  6858. * @example
  6859. * ```javascript
  6860. * // editor 是一个编辑器的实例
  6861. * var content = editor.getContent( function ( editor ) {
  6862. * return editor.body.innerHTML === '欢迎使用UEditor'; //返回空字符串
  6863. * } );
  6864. * ```
  6865. */
  6866. getContent: function (cmd, fn,notSetCursor,ignoreBlank,formatter) {
  6867. var me = this;
  6868. if (cmd && utils.isFunction(cmd)) {
  6869. fn = cmd;
  6870. cmd = '';
  6871. }
  6872. if (fn ? !fn() : !this.hasContents()) {
  6873. return '';
  6874. }
  6875. me.fireEvent('beforegetcontent');
  6876. var root = UE.htmlparser(me.body.innerHTML,ignoreBlank);
  6877. me.filterOutputRule(root);
  6878. me.fireEvent('aftergetcontent', cmd,root);
  6879. return root.toHtml(formatter);
  6880. },
  6881. /**
  6882. * 取得完整的html代码,可以直接显示成完整的html文档
  6883. * @method getAllHtml
  6884. * @return { String } 编辑器的内容html文档字符串
  6885. * @eaxmple
  6886. * ```javascript
  6887. * editor.getAllHtml(); //返回格式大致是: <html><head>...</head><body>...</body></html>
  6888. * ```
  6889. */
  6890. getAllHtml: function () {
  6891. var me = this,
  6892. headHtml = [],
  6893. html = '';
  6894. me.fireEvent('getAllHtml', headHtml);
  6895. if (browser.ie && browser.version > 8) {
  6896. var headHtmlForIE9 = '';
  6897. utils.each(me.document.styleSheets, function (si) {
  6898. headHtmlForIE9 += ( si.href ? '<link rel="stylesheet" type="text/css" href="' + si.href + '" />' : '<style>' + si.cssText + '</style>');
  6899. });
  6900. utils.each(me.document.getElementsByTagName('script'), function (si) {
  6901. headHtmlForIE9 += si.outerHTML;
  6902. });
  6903. }
  6904. return '<html><head>' + (me.options.charset ? '<meta http-equiv="Content-Type" content="text/html; charset=' + me.options.charset + '"/>' : '')
  6905. + (headHtmlForIE9 || me.document.getElementsByTagName('head')[0].innerHTML) + headHtml.join('\n') + '</head>'
  6906. + '<body ' + (ie && browser.version < 9 ? 'class="view"' : '') + '>' + me.getContent(null, null, true) + '</body></html>';
  6907. },
  6908. /**
  6909. * 得到编辑器的纯文本内容,但会保留段落格式
  6910. * @method getPlainTxt
  6911. * @return { String } 编辑器带段落格式的纯文本内容字符串
  6912. * @example
  6913. * ```javascript
  6914. * //编辑器html内容:<p><strong>1</strong></p><p><strong>2</strong></p>
  6915. * console.log(editor.getPlainTxt()); //输出:"1\n2\n
  6916. * ```
  6917. */
  6918. getPlainTxt: function () {
  6919. var reg = new RegExp(domUtils.fillChar, 'g'),
  6920. html = this.body.innerHTML.replace(/[\n\r]/g, '');//ie要先去了\n在处理
  6921. html = html.replace(/<(p|div)[^>]*>(<br\/?>|&nbsp;)<\/\1>/gi, '\n')
  6922. .replace(/<br\/?>/gi, '\n')
  6923. .replace(/<[^>/]+>/g, '')
  6924. .replace(/(\n)?<\/([^>]+)>/g, function (a, b, c) {
  6925. return dtd.$block[c] ? '\n' : b ? b : '';
  6926. });
  6927. //取出来的空格会有c2a0会变成乱码,处理这种情况\u00a0
  6928. return html.replace(reg, '').replace(/\u00a0/g, ' ').replace(/&nbsp;/g, ' ');
  6929. },
  6930. /**
  6931. * 获取编辑器中的纯文本内容,没有段落格式
  6932. * @method getContentTxt
  6933. * @return { String } 编辑器不带段落格式的纯文本内容字符串
  6934. * @example
  6935. * ```javascript
  6936. * //编辑器html内容:<p><strong>1</strong></p><p><strong>2</strong></p>
  6937. * console.log(editor.getPlainTxt()); //输出:"12
  6938. * ```
  6939. */
  6940. getContentTxt: function () {
  6941. var reg = new RegExp(domUtils.fillChar, 'g');
  6942. //取出来的空格会有c2a0会变成乱码,处理这种情况\u00a0
  6943. return this.body[browser.ie ? 'innerText' : 'textContent'].replace(reg, '').replace(/\u00a0/g, ' ');
  6944. },
  6945. /**
  6946. * 设置编辑器的内容,可修改编辑器当前的html内容
  6947. * @method setContent
  6948. * @warning 通过该方法插入的内容,是经过编辑器内置的过滤规则进行过滤后得到的内容
  6949. * @warning 该方法会触发selectionchange事件
  6950. * @param { String } html 要插入的html内容
  6951. * @example
  6952. * ```javascript
  6953. * editor.getContent('<p>test</p>');
  6954. * ```
  6955. */
  6956. /**
  6957. * 设置编辑器的内容,可修改编辑器当前的html内容
  6958. * @method setContent
  6959. * @warning 通过该方法插入的内容,是经过编辑器内置的过滤规则进行过滤后得到的内容
  6960. * @warning 该方法会触发selectionchange事件
  6961. * @param { String } html 要插入的html内容
  6962. * @param { Boolean } isAppendTo 若传入true,不清空原来的内容,在最后插入内容,否则,清空内容再插入
  6963. * @example
  6964. * ```javascript
  6965. * //假设设置前的编辑器内容是 <p>old text</p>
  6966. * editor.setContent('<p>new text</p>', true); //插入的结果是<p>old text</p><p>new text</p>
  6967. * ```
  6968. */
  6969. setContent: function (html, isAppendTo, notFireSelectionchange) {
  6970. var me = this;
  6971. me.fireEvent('beforesetcontent', html);
  6972. var root = UE.htmlparser(html);
  6973. me.filterInputRule(root);
  6974. html = root.toHtml();
  6975. me.body.innerHTML = (isAppendTo ? me.body.innerHTML : '') + html;
  6976. function isCdataDiv(node){
  6977. return node.tagName == 'DIV' && node.getAttribute('cdata_tag');
  6978. }
  6979. //给文本或者inline节点套p标签
  6980. if (me.options.enterTag == 'p') {
  6981. var child = this.body.firstChild, tmpNode;
  6982. if (!child || child.nodeType == 1 &&
  6983. (dtd.$cdata[child.tagName] || isCdataDiv(child) ||
  6984. domUtils.isCustomeNode(child)
  6985. )
  6986. && child === this.body.lastChild) {
  6987. this.body.innerHTML = '<p>' + (browser.ie ? '&nbsp;' : '<br/>') + '</p>' + this.body.innerHTML;
  6988. } else {
  6989. var p = me.document.createElement('p');
  6990. while (child) {
  6991. while (child && (child.nodeType == 3 || child.nodeType == 1 && dtd.p[child.tagName] && !dtd.$cdata[child.tagName])) {
  6992. tmpNode = child.nextSibling;
  6993. p.appendChild(child);
  6994. child = tmpNode;
  6995. }
  6996. if (p.firstChild) {
  6997. if (!child) {
  6998. me.body.appendChild(p);
  6999. break;
  7000. } else {
  7001. child.parentNode.insertBefore(p, child);
  7002. p = me.document.createElement('p');
  7003. }
  7004. }
  7005. child = child.nextSibling;
  7006. }
  7007. }
  7008. }
  7009. me.fireEvent('aftersetcontent');
  7010. me.fireEvent('contentchange');
  7011. !notFireSelectionchange && me._selectionChange();
  7012. //清除保存的选区
  7013. me._bakRange = me._bakIERange = me._bakNativeRange = null;
  7014. //trace:1742 setContent后gecko能得到焦点问题
  7015. var geckoSel;
  7016. if (browser.gecko && (geckoSel = this.selection.getNative())) {
  7017. geckoSel.removeAllRanges();
  7018. }
  7019. if(me.options.autoSyncData){
  7020. me.form && setValue(me.form,me);
  7021. }
  7022. },
  7023. /**
  7024. * 让编辑器获得焦点,默认focus到编辑器头部
  7025. * @method focus
  7026. * @example
  7027. * ```javascript
  7028. * editor.focus()
  7029. * ```
  7030. */
  7031. /**
  7032. * 让编辑器获得焦点,toEnd确定focus位置
  7033. * @method focus
  7034. * @param { Boolean } toEnd 默认focus到编辑器头部,toEnd为true时focus到内容尾部
  7035. * @example
  7036. * ```javascript
  7037. * editor.focus(true)
  7038. * ```
  7039. */
  7040. focus: function (toEnd) {
  7041. try {
  7042. var me = this,
  7043. rng = me.selection.getRange();
  7044. if (toEnd) {
  7045. var node = me.body.lastChild;
  7046. if(node && node.nodeType == 1 && !dtd.$empty[node.tagName]){
  7047. if(domUtils.isEmptyBlock(node)){
  7048. rng.setStartAtFirst(node)
  7049. }else{
  7050. rng.setStartAtLast(node)
  7051. }
  7052. rng.collapse(true);
  7053. }
  7054. rng.setCursor(true);
  7055. } else {
  7056. if(!rng.collapsed && domUtils.isBody(rng.startContainer) && rng.startOffset == 0){
  7057. var node = me.body.firstChild;
  7058. if(node && node.nodeType == 1 && !dtd.$empty[node.tagName]){
  7059. rng.setStartAtFirst(node).collapse(true);
  7060. }
  7061. }
  7062. rng.select(true);
  7063. }
  7064. this.fireEvent('focus selectionchange');
  7065. } catch (e) {
  7066. }
  7067. },
  7068. isFocus:function(){
  7069. return this.selection.isFocus();
  7070. },
  7071. blur:function(){
  7072. var sel = this.selection.getNative();
  7073. if(sel.empty && browser.ie){
  7074. var nativeRng = document.body.createTextRange();
  7075. nativeRng.moveToElementText(document.body);
  7076. nativeRng.collapse(true);
  7077. nativeRng.select();
  7078. sel.empty()
  7079. }else{
  7080. sel.removeAllRanges()
  7081. }
  7082. //this.fireEvent('blur selectionchange');
  7083. },
  7084. /**
  7085. * 初始化UE事件及部分事件代理
  7086. * @method _initEvents
  7087. * @private
  7088. */
  7089. _initEvents: function () {
  7090. var me = this,
  7091. doc = me.document,
  7092. win = me.window;
  7093. me._proxyDomEvent = utils.bind(me._proxyDomEvent, me);
  7094. domUtils.on(doc, ['click', 'contextmenu', 'mousedown', 'keydown', 'keyup', 'keypress', 'mouseup', 'mouseover', 'mouseout', 'selectstart'], me._proxyDomEvent);
  7095. domUtils.on(win, ['focus', 'blur'], me._proxyDomEvent);
  7096. domUtils.on(me.body,'drop',function(e){
  7097. //阻止ff下默认的弹出新页面打开图片
  7098. if(browser.gecko && e.stopPropagation) { e.stopPropagation(); }
  7099. me.fireEvent('contentchange')
  7100. });
  7101. domUtils.on(doc, ['mouseup', 'keydown'], function (evt) {
  7102. //特殊键不触发selectionchange
  7103. if (evt.type == 'keydown' && (evt.ctrlKey || evt.metaKey || evt.shiftKey || evt.altKey)) {
  7104. return;
  7105. }
  7106. if (evt.button == 2)return;
  7107. me._selectionChange(250, evt);
  7108. });
  7109. },
  7110. /**
  7111. * 触发事件代理
  7112. * @method _proxyDomEvent
  7113. * @private
  7114. * @return { * } fireEvent的返回值
  7115. * @see UE.EventBase:fireEvent(String)
  7116. */
  7117. _proxyDomEvent: function (evt) {
  7118. if(this.fireEvent('before' + evt.type.replace(/^on/, '').toLowerCase()) === false){
  7119. return false;
  7120. }
  7121. if(this.fireEvent(evt.type.replace(/^on/, ''), evt) === false){
  7122. return false;
  7123. }
  7124. return this.fireEvent('after' + evt.type.replace(/^on/, '').toLowerCase())
  7125. },
  7126. /**
  7127. * 变化选区
  7128. * @method _selectionChange
  7129. * @private
  7130. */
  7131. _selectionChange: function (delay, evt) {
  7132. var me = this;
  7133. //有光标才做selectionchange 为了解决未focus时点击source不能触发更改工具栏状态的问题(source命令notNeedUndo=1)
  7134. // if ( !me.selection.isFocus() ){
  7135. // return;
  7136. // }
  7137. var hackForMouseUp = false;
  7138. var mouseX, mouseY;
  7139. if (browser.ie && browser.version < 9 && evt && evt.type == 'mouseup') {
  7140. var range = this.selection.getRange();
  7141. if (!range.collapsed) {
  7142. hackForMouseUp = true;
  7143. mouseX = evt.clientX;
  7144. mouseY = evt.clientY;
  7145. }
  7146. }
  7147. clearTimeout(_selectionChangeTimer);
  7148. _selectionChangeTimer = setTimeout(function () {
  7149. if (!me.selection || !me.selection.getNative()) {
  7150. return;
  7151. }
  7152. //修复一个IE下的bug: 鼠标点击一段已选择的文本中间时,可能在mouseup后的一段时间内取到的range是在selection的type为None下的错误值.
  7153. //IE下如果用户是拖拽一段已选择文本,则不会触发mouseup事件,所以这里的特殊处理不会对其有影响
  7154. var ieRange;
  7155. if (hackForMouseUp && me.selection.getNative().type == 'None') {
  7156. ieRange = me.document.body.createTextRange();
  7157. try {
  7158. ieRange.moveToPoint(mouseX, mouseY);
  7159. } catch (ex) {
  7160. ieRange = null;
  7161. }
  7162. }
  7163. var bakGetIERange;
  7164. if (ieRange) {
  7165. bakGetIERange = me.selection.getIERange;
  7166. me.selection.getIERange = function () {
  7167. return ieRange;
  7168. };
  7169. }
  7170. me.selection.cache();
  7171. if (bakGetIERange) {
  7172. me.selection.getIERange = bakGetIERange;
  7173. }
  7174. if (me.selection._cachedRange && me.selection._cachedStartElement) {
  7175. me.fireEvent('beforeselectionchange');
  7176. // 第二个参数causeByUi为true代表由用户交互造成的selectionchange.
  7177. me.fireEvent('selectionchange', !!evt);
  7178. me.fireEvent('afterselectionchange');
  7179. me.selection.clear();
  7180. }
  7181. }, delay || 50);
  7182. },
  7183. /**
  7184. * 执行编辑命令
  7185. * @method _callCmdFn
  7186. * @private
  7187. * @param { String } fnName 函数名称
  7188. * @param { * } args 传给命令函数的参数
  7189. * @return { * } 返回命令函数运行的返回值
  7190. */
  7191. _callCmdFn: function (fnName, args) {
  7192. var cmdName = args[0].toLowerCase(),
  7193. cmd, cmdFn;
  7194. cmd = this.commands[cmdName] || UE.commands[cmdName];
  7195. cmdFn = cmd && cmd[fnName];
  7196. //没有querycommandstate或者没有command的都默认返回0
  7197. if ((!cmd || !cmdFn) && fnName == 'queryCommandState') {
  7198. return 0;
  7199. } else if (cmdFn) {
  7200. return cmdFn.apply(this, args);
  7201. }
  7202. },
  7203. /**
  7204. * 执行编辑命令cmdName,完成富文本编辑效果
  7205. * @method execCommand
  7206. * @param { String } cmdName 需要执行的命令
  7207. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  7208. * @return { * } 返回命令函数运行的返回值
  7209. * @example
  7210. * ```javascript
  7211. * editor.execCommand(cmdName);
  7212. * ```
  7213. */
  7214. execCommand: function (cmdName) {
  7215. cmdName = cmdName.toLowerCase();
  7216. var me = this,
  7217. result,
  7218. cmd = me.commands[cmdName] || UE.commands[cmdName];
  7219. if (!cmd || !cmd.execCommand) {
  7220. return null;
  7221. }
  7222. if (!cmd.notNeedUndo && !me.__hasEnterExecCommand) {
  7223. me.__hasEnterExecCommand = true;
  7224. if (me.queryCommandState.apply(me,arguments) != -1) {
  7225. me.fireEvent('saveScene');
  7226. me.fireEvent.apply(me, ['beforeexeccommand', cmdName].concat(arguments));
  7227. result = this._callCmdFn('execCommand', arguments);
  7228. //保存场景时,做了内容对比,再看是否进行contentchange触发,这里多触发了一次,去掉
  7229. // (!cmd.ignoreContentChange && !me._ignoreContentChange) && me.fireEvent('contentchange');
  7230. me.fireEvent.apply(me, ['afterexeccommand', cmdName].concat(arguments));
  7231. me.fireEvent('saveScene');
  7232. }
  7233. me.__hasEnterExecCommand = false;
  7234. } else {
  7235. result = this._callCmdFn('execCommand', arguments);
  7236. (!me.__hasEnterExecCommand && !cmd.ignoreContentChange && !me._ignoreContentChange) && me.fireEvent('contentchange')
  7237. }
  7238. (!me.__hasEnterExecCommand && !cmd.ignoreContentChange && !me._ignoreContentChange) && me._selectionChange();
  7239. return result;
  7240. },
  7241. /**
  7242. * 根据传入的command命令,查选编辑器当前的选区,返回命令的状态
  7243. * @method queryCommandState
  7244. * @param { String } cmdName 需要查询的命令名称
  7245. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  7246. * @return { Number } number 返回放前命令的状态,返回值三种情况:(-1|0|1)
  7247. * @example
  7248. * ```javascript
  7249. * editor.queryCommandState(cmdName) => (-1|0|1)
  7250. * ```
  7251. * @see COMMAND.LIST
  7252. */
  7253. queryCommandState: function (cmdName) {
  7254. return this._callCmdFn('queryCommandState', arguments);
  7255. },
  7256. /**
  7257. * 根据传入的command命令,查选编辑器当前的选区,根据命令返回相关的值
  7258. * @method queryCommandValue
  7259. * @param { String } cmdName 需要查询的命令名称
  7260. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  7261. * @remind 只有部分插件有此方法
  7262. * @return { * } 返回每个命令特定的当前状态值
  7263. * @grammar editor.queryCommandValue(cmdName) => {*}
  7264. * @see COMMAND.LIST
  7265. */
  7266. queryCommandValue: function (cmdName) {
  7267. return this._callCmdFn('queryCommandValue', arguments);
  7268. },
  7269. /**
  7270. * 检查编辑区域中是否有内容
  7271. * @method hasContents
  7272. * @remind 默认有文本内容,或者有以下节点都不认为是空
  7273. * table,ul,ol,dl,iframe,area,base,col,hr,img,embed,input,link,meta,param
  7274. * @return { Boolean } 检查有内容返回true,否则返回false
  7275. * @example
  7276. * ```javascript
  7277. * editor.hasContents()
  7278. * ```
  7279. */
  7280. /**
  7281. * 检查编辑区域中是否有内容,若包含参数tags中的节点类型,直接返回true
  7282. * @method hasContents
  7283. * @param { Array } tags 传入数组判断时用到的节点类型
  7284. * @return { Boolean } 若文档中包含tags数组里对应的tag,返回true,否则返回false
  7285. * @example
  7286. * ```javascript
  7287. * editor.hasContents(['span']);
  7288. * ```
  7289. */
  7290. hasContents: function (tags) {
  7291. if (tags) {
  7292. for (var i = 0, ci; ci = tags[i++];) {
  7293. if (this.document.getElementsByTagName(ci).length > 0) {
  7294. return true;
  7295. }
  7296. }
  7297. }
  7298. if (!domUtils.isEmptyBlock(this.body)) {
  7299. return true
  7300. }
  7301. //随时添加,定义的特殊标签如果存在,不能认为是空
  7302. tags = ['div'];
  7303. for (i = 0; ci = tags[i++];) {
  7304. var nodes = domUtils.getElementsByTagName(this.document, ci);
  7305. for (var n = 0, cn; cn = nodes[n++];) {
  7306. if (domUtils.isCustomeNode(cn)) {
  7307. return true;
  7308. }
  7309. }
  7310. }
  7311. return false;
  7312. },
  7313. /**
  7314. * 重置编辑器,可用来做多个tab使用同一个编辑器实例
  7315. * @method reset
  7316. * @remind 此方法会清空编辑器内容,清空回退列表,会触发reset事件
  7317. * @example
  7318. * ```javascript
  7319. * editor.reset()
  7320. * ```
  7321. */
  7322. reset: function () {
  7323. this.fireEvent('reset');
  7324. },
  7325. /**
  7326. * 设置当前编辑区域可以编辑
  7327. * @method setEnabled
  7328. * @example
  7329. * ```javascript
  7330. * editor.setEnabled()
  7331. * ```
  7332. */
  7333. setEnabled: function () {
  7334. var me = this, range;
  7335. if (me.body.contentEditable == 'false') {
  7336. me.body.contentEditable = true;
  7337. range = me.selection.getRange();
  7338. //有可能内容丢失了
  7339. try {
  7340. range.moveToBookmark(me.lastBk);
  7341. delete me.lastBk
  7342. } catch (e) {
  7343. range.setStartAtFirst(me.body).collapse(true)
  7344. }
  7345. range.select(true);
  7346. if (me.bkqueryCommandState) {
  7347. me.queryCommandState = me.bkqueryCommandState;
  7348. delete me.bkqueryCommandState;
  7349. }
  7350. if (me.bkqueryCommandValue) {
  7351. me.queryCommandValue = me.bkqueryCommandValue;
  7352. delete me.bkqueryCommandValue;
  7353. }
  7354. me.fireEvent('selectionchange');
  7355. }
  7356. },
  7357. enable: function () {
  7358. return this.setEnabled();
  7359. },
  7360. /** 设置当前编辑区域不可编辑
  7361. * @method setDisabled
  7362. */
  7363. /** 设置当前编辑区域不可编辑,except中的命令除外
  7364. * @method setDisabled
  7365. * @param { String } except 例外命令的字符串
  7366. * @remind 即使设置了disable,此处配置的例外命令仍然可以执行
  7367. * @example
  7368. * ```javascript
  7369. * editor.setDisabled('bold'); //禁用工具栏中除加粗之外的所有功能
  7370. * ```
  7371. */
  7372. /** 设置当前编辑区域不可编辑,except中的命令除外
  7373. * @method setDisabled
  7374. * @param { Array } except 例外命令的字符串数组,数组中的命令仍然可以执行
  7375. * @remind 即使设置了disable,此处配置的例外命令仍然可以执行
  7376. * @example
  7377. * ```javascript
  7378. * editor.setDisabled(['bold','insertimage']); //禁用工具栏中除加粗和插入图片之外的所有功能
  7379. * ```
  7380. */
  7381. setDisabled: function (except) {
  7382. var me = this;
  7383. except = except ? utils.isArray(except) ? except : [except] : [];
  7384. if (me.body.contentEditable == 'true') {
  7385. if (!me.lastBk) {
  7386. me.lastBk = me.selection.getRange().createBookmark(true);
  7387. }
  7388. me.body.contentEditable = false;
  7389. me.bkqueryCommandState = me.queryCommandState;
  7390. me.bkqueryCommandValue = me.queryCommandValue;
  7391. me.queryCommandState = function (type) {
  7392. if (utils.indexOf(except, type) != -1) {
  7393. return me.bkqueryCommandState.apply(me, arguments);
  7394. }
  7395. return -1;
  7396. };
  7397. me.queryCommandValue = function (type) {
  7398. if (utils.indexOf(except, type) != -1) {
  7399. return me.bkqueryCommandValue.apply(me, arguments);
  7400. }
  7401. return null;
  7402. };
  7403. me.fireEvent('selectionchange');
  7404. }
  7405. },
  7406. disable: function (except) {
  7407. return this.setDisabled(except);
  7408. },
  7409. /**
  7410. * 设置默认内容
  7411. * @method _setDefaultContent
  7412. * @private
  7413. * @param { String } cont 要存入的内容
  7414. */
  7415. _setDefaultContent: function () {
  7416. function clear() {
  7417. var me = this;
  7418. if (me.document.getElementById('initContent')) {
  7419. me.body.innerHTML = '<p>' + (ie ? '' : '<br/>') + '</p>';
  7420. me.removeListener('firstBeforeExecCommand focus', clear);
  7421. setTimeout(function () {
  7422. me.focus();
  7423. me._selectionChange();
  7424. }, 0)
  7425. }
  7426. }
  7427. return function (cont) {
  7428. var me = this;
  7429. me.body.innerHTML = '<p id="initContent">' + cont + '</p>';
  7430. me.addListener('firstBeforeExecCommand focus', clear);
  7431. }
  7432. }(),
  7433. /**
  7434. * 显示编辑器
  7435. * @method setShow
  7436. * @example
  7437. * ```javascript
  7438. * editor.setShow()
  7439. * ```
  7440. */
  7441. setShow: function () {
  7442. var me = this, range = me.selection.getRange();
  7443. if (me.container.style.display == 'none') {
  7444. //有可能内容丢失了
  7445. try {
  7446. range.moveToBookmark(me.lastBk);
  7447. delete me.lastBk
  7448. } catch (e) {
  7449. range.setStartAtFirst(me.body).collapse(true)
  7450. }
  7451. //ie下focus实效,所以做了个延迟
  7452. setTimeout(function () {
  7453. range.select(true);
  7454. }, 100);
  7455. me.container.style.display = '';
  7456. }
  7457. },
  7458. show: function () {
  7459. return this.setShow();
  7460. },
  7461. /**
  7462. * 隐藏编辑器
  7463. * @method setHide
  7464. * @example
  7465. * ```javascript
  7466. * editor.setHide()
  7467. * ```
  7468. */
  7469. setHide: function () {
  7470. var me = this;
  7471. if (!me.lastBk) {
  7472. me.lastBk = me.selection.getRange().createBookmark(true);
  7473. }
  7474. me.container.style.display = 'none'
  7475. },
  7476. hide: function () {
  7477. return this.setHide();
  7478. },
  7479. /**
  7480. * 根据指定的路径,获取对应的语言资源
  7481. * @method getLang
  7482. * @param { String } path 路径根据的是lang目录下的语言文件的路径结构
  7483. * @return { Object | String } 根据路径返回语言资源的Json格式对象或者语言字符串
  7484. * @example
  7485. * ```javascript
  7486. * editor.getLang('contextMenu.delete'); //如果当前是中文,那返回是的是'删除'
  7487. * ```
  7488. */
  7489. getLang: function (path) {
  7490. var lang = UE.I18N[this.options.lang];
  7491. if (!lang) {
  7492. throw Error("not import language file");
  7493. }
  7494. path = (path || "").split(".");
  7495. for (var i = 0, ci; ci = path[i++];) {
  7496. lang = lang[ci];
  7497. if (!lang)break;
  7498. }
  7499. return lang;
  7500. },
  7501. /**
  7502. * 计算编辑器html内容字符串的长度
  7503. * @method getContentLength
  7504. * @return { Number } 返回计算的长度
  7505. * @example
  7506. * ```javascript
  7507. * //编辑器html内容<p><strong>132</strong></p>
  7508. * editor.getContentLength() //返回27
  7509. * ```
  7510. */
  7511. /**
  7512. * 计算编辑器当前纯文本内容的长度
  7513. * @method getContentLength
  7514. * @param { Boolean } ingoneHtml 传入true时,只按照纯文本来计算
  7515. * @return { Number } 返回计算的长度,内容中有hr/img/iframe标签,长度加1
  7516. * @example
  7517. * ```javascript
  7518. * //编辑器html内容<p><strong>132</strong></p>
  7519. * editor.getContentLength() //返回3
  7520. * ```
  7521. */
  7522. getContentLength: function (ingoneHtml, tagNames) {
  7523. var count = this.getContent(false,false,true).length;
  7524. if (ingoneHtml) {
  7525. tagNames = (tagNames || []).concat([ 'hr', 'img', 'iframe']);
  7526. count = this.getContentTxt().replace(/[\t\r\n]+/g, '').length;
  7527. for (var i = 0, ci; ci = tagNames[i++];) {
  7528. count += this.document.getElementsByTagName(ci).length;
  7529. }
  7530. }
  7531. return count;
  7532. },
  7533. /**
  7534. * 注册输入过滤规则
  7535. * @method addInputRule
  7536. * @param { Function } rule 要添加的过滤规则
  7537. * @example
  7538. * ```javascript
  7539. * editor.addInputRule(function(root){
  7540. * $.each(root.getNodesByTagName('div'),function(i,node){
  7541. * node.tagName="p";
  7542. * });
  7543. * });
  7544. * ```
  7545. */
  7546. addInputRule: function (rule) {
  7547. this.inputRules.push(rule);
  7548. },
  7549. /**
  7550. * 执行注册的过滤规则
  7551. * @method filterInputRule
  7552. * @param { UE.uNode } root 要过滤的uNode节点
  7553. * @remind 执行editor.setContent方法和执行'inserthtml'命令后,会运行该过滤函数
  7554. * @example
  7555. * ```javascript
  7556. * editor.filterInputRule(editor.body);
  7557. * ```
  7558. * @see UE.Editor:addInputRule
  7559. */
  7560. filterInputRule: function (root) {
  7561. for (var i = 0, ci; ci = this.inputRules[i++];) {
  7562. ci.call(this, root)
  7563. }
  7564. },
  7565. /**
  7566. * 注册输出过滤规则
  7567. * @method addOutputRule
  7568. * @param { Function } rule 要添加的过滤规则
  7569. * @example
  7570. * ```javascript
  7571. * editor.addOutputRule(function(root){
  7572. * $.each(root.getNodesByTagName('p'),function(i,node){
  7573. * node.tagName="div";
  7574. * });
  7575. * });
  7576. * ```
  7577. */
  7578. addOutputRule: function (rule) {
  7579. this.outputRules.push(rule)
  7580. },
  7581. /**
  7582. * 根据输出过滤规则,过滤编辑器内容
  7583. * @method filterOutputRule
  7584. * @remind 执行editor.getContent方法的时候,会先运行该过滤函数
  7585. * @param { UE.uNode } root 要过滤的uNode节点
  7586. * @example
  7587. * ```javascript
  7588. * editor.filterOutputRule(editor.body);
  7589. * ```
  7590. * @see UE.Editor:addOutputRule
  7591. */
  7592. filterOutputRule: function (root) {
  7593. for (var i = 0, ci; ci = this.outputRules[i++];) {
  7594. ci.call(this, root)
  7595. }
  7596. },
  7597. /**
  7598. * 根据action名称获取请求的路径
  7599. * @method getActionUrl
  7600. * @remind 假如没有设置serverUrl,会根据imageUrl设置默认的controller路径
  7601. * @param { String } action action名称
  7602. * @example
  7603. * ```javascript
  7604. * editor.getActionUrl('config'); //返回 "/ueditor/php/controller.php?action=config"
  7605. * editor.getActionUrl('image'); //返回 "/ueditor/php/controller.php?action=uplaodimage"
  7606. * editor.getActionUrl('scrawl'); //返回 "/ueditor/php/controller.php?action=uplaodscrawl"
  7607. * editor.getActionUrl('imageManager'); //返回 "/ueditor/php/controller.php?action=listimage"
  7608. * ```
  7609. */
  7610. getActionUrl: function(action){
  7611. var actionName = this.getOpt(action) || action,
  7612. imageUrl = this.getOpt('imageUrl'),
  7613. serverUrl = this.getOpt('serverUrl');
  7614. if(!serverUrl && imageUrl) {
  7615. serverUrl = imageUrl.replace(/^(.*[\/]).+([\.].+)$/, '$1controller$2');
  7616. }
  7617. if(serverUrl) {
  7618. serverUrl = serverUrl + (serverUrl.indexOf('?') == -1 ? '?':'&') + 'action=' + (actionName || '');
  7619. return utils.formatUrl(serverUrl);
  7620. } else {
  7621. return '';
  7622. }
  7623. }
  7624. };
  7625. utils.inherits(Editor, EventBase);
  7626. })();
  7627. // core/Editor.defaultoptions.js
  7628. //维护编辑器一下默认的不在插件中的配置项
  7629. UE.Editor.defaultOptions = function(editor){
  7630. var _url = editor.options.UEDITOR_HOME_URL;
  7631. return {
  7632. isShow: true,
  7633. initialContent: '',
  7634. initialStyle:'',
  7635. autoClearinitialContent: false,
  7636. iframeCssUrl: _url + 'themes/iframe.css',
  7637. textarea: 'editorValue',
  7638. focus: false,
  7639. focusInEnd: true,
  7640. autoClearEmptyNode: true,
  7641. fullscreen: false,
  7642. readonly: false,
  7643. zIndex: 999,
  7644. imagePopup: true,
  7645. enterTag: 'p',
  7646. customDomain: false,
  7647. lang: 'zh-cn',
  7648. langPath: _url + 'lang/',
  7649. theme: 'default',
  7650. themePath: _url + 'themes/',
  7651. allHtmlEnabled: false,
  7652. scaleEnabled: false,
  7653. tableNativeEditInFF: false,
  7654. autoSyncData : true,
  7655. fileNameFormat: '{time}{rand:6}'
  7656. }
  7657. };
  7658. // core/loadconfig.js
  7659. (function(){
  7660. UE.Editor.prototype.loadServerConfig = function(){
  7661. var me = this;
  7662. setTimeout(function(){
  7663. try{
  7664. me.options.imageUrl && me.setOpt('serverUrl', me.options.imageUrl.replace(/^(.*[\/]).+([\.].+)$/, '$1controller$2'));
  7665. var configUrl = me.getActionUrl('config'),
  7666. isJsonp = utils.isCrossDomainUrl(configUrl);
  7667. /* 发出ajax请求 */
  7668. me._serverConfigLoaded = false;
  7669. configUrl && UE.ajax.request(configUrl,{
  7670. 'method': 'GET',
  7671. 'dataType': isJsonp ? 'jsonp':'',
  7672. 'onsuccess':function(r){
  7673. try {
  7674. var config = isJsonp ? r:eval("("+r.responseText+")");
  7675. utils.extend(me.options, config);
  7676. me.fireEvent('serverConfigLoaded');
  7677. me._serverConfigLoaded = true;
  7678. } catch (e) {
  7679. showErrorMsg(me.getLang('loadconfigFormatError'));
  7680. }
  7681. },
  7682. 'onerror':function(){
  7683. showErrorMsg(me.getLang('loadconfigHttpError'));
  7684. }
  7685. });
  7686. } catch(e){
  7687. showErrorMsg(me.getLang('loadconfigError'));
  7688. }
  7689. });
  7690. function showErrorMsg(msg) {
  7691. console && console.error(msg);
  7692. //me.fireEvent('showMessage', {
  7693. // 'title': msg,
  7694. // 'type': 'error'
  7695. //});
  7696. }
  7697. };
  7698. UE.Editor.prototype.isServerConfigLoaded = function(){
  7699. var me = this;
  7700. return me._serverConfigLoaded || false;
  7701. };
  7702. UE.Editor.prototype.afterConfigReady = function(handler){
  7703. if (!handler || !utils.isFunction(handler)) return;
  7704. var me = this;
  7705. var readyHandler = function(){
  7706. handler.apply(me, arguments);
  7707. me.removeListener('serverConfigLoaded', readyHandler);
  7708. };
  7709. if (me.isServerConfigLoaded()) {
  7710. handler.call(me, 'serverConfigLoaded');
  7711. } else {
  7712. me.addListener('serverConfigLoaded', readyHandler);
  7713. }
  7714. };
  7715. })();
  7716. // core/ajax.js
  7717. /**
  7718. * @file
  7719. * @module UE.ajax
  7720. * @since 1.2.6.1
  7721. */
  7722. /**
  7723. * 提供对ajax请求的支持
  7724. * @module UE.ajax
  7725. */
  7726. UE.ajax = function() {
  7727. //创建一个ajaxRequest对象
  7728. var fnStr = 'XMLHttpRequest()';
  7729. try {
  7730. new ActiveXObject("Msxml2.XMLHTTP");
  7731. fnStr = 'ActiveXObject(\'Msxml2.XMLHTTP\')';
  7732. } catch (e) {
  7733. try {
  7734. new ActiveXObject("Microsoft.XMLHTTP");
  7735. fnStr = 'ActiveXObject(\'Microsoft.XMLHTTP\')'
  7736. } catch (e) {
  7737. }
  7738. }
  7739. var creatAjaxRequest = new Function('return new ' + fnStr);
  7740. /**
  7741. * 将json参数转化成适合ajax提交的参数列表
  7742. * @param json
  7743. */
  7744. function json2str(json) {
  7745. var strArr = [];
  7746. for (var i in json) {
  7747. //忽略默认的几个参数
  7748. if(i=="method" || i=="timeout" || i=="async" || i=="dataType" || i=="callback") continue;
  7749. //忽略控制
  7750. if(json[i] == undefined || json[i] == null) continue;
  7751. //传递过来的对象和函数不在提交之列
  7752. if (!((typeof json[i]).toLowerCase() == "function" || (typeof json[i]).toLowerCase() == "object")) {
  7753. strArr.push( encodeURIComponent(i) + "="+encodeURIComponent(json[i]) );
  7754. } else if (utils.isArray(json[i])) {
  7755. //支持传数组内容
  7756. for(var j = 0; j < json[i].length; j++) {
  7757. strArr.push( encodeURIComponent(i) + "[]="+encodeURIComponent(json[i][j]) );
  7758. }
  7759. }
  7760. }
  7761. return strArr.join("&");
  7762. }
  7763. function doAjax(url, ajaxOptions) {
  7764. var xhr = creatAjaxRequest(),
  7765. //是否超时
  7766. timeIsOut = false,
  7767. //默认参数
  7768. defaultAjaxOptions = {
  7769. method:"POST",
  7770. timeout:5000,
  7771. async:true,
  7772. data:{},//需要传递对象的话只能覆盖
  7773. onsuccess:function() {
  7774. },
  7775. onerror:function() {
  7776. }
  7777. };
  7778. if (typeof url === "object") {
  7779. ajaxOptions = url;
  7780. url = ajaxOptions.url;
  7781. }
  7782. if (!xhr || !url) return;
  7783. var ajaxOpts = ajaxOptions ? utils.extend(defaultAjaxOptions,ajaxOptions) : defaultAjaxOptions;
  7784. var submitStr = json2str(ajaxOpts); // { name:"Jim",city:"Beijing" } --> "name=Jim&city=Beijing"
  7785. //如果用户直接通过data参数传递json对象过来,则也要将此json对象转化为字符串
  7786. if (!utils.isEmptyObject(ajaxOpts.data)){
  7787. submitStr += (submitStr? "&":"") + json2str(ajaxOpts.data);
  7788. }
  7789. //超时检测
  7790. var timerID = setTimeout(function() {
  7791. if (xhr.readyState != 4) {
  7792. timeIsOut = true;
  7793. xhr.abort();
  7794. clearTimeout(timerID);
  7795. }
  7796. }, ajaxOpts.timeout);
  7797. var method = ajaxOpts.method.toUpperCase();
  7798. var str = url + (url.indexOf("?")==-1?"?":"&") + (method=="POST"?"":submitStr+ "&noCache=" + +new Date);
  7799. xhr.open(method, str, ajaxOpts.async);
  7800. xhr.onreadystatechange = function() {
  7801. if (xhr.readyState == 4) {
  7802. if (!timeIsOut && xhr.status == 200) {
  7803. ajaxOpts.onsuccess(xhr);
  7804. } else {
  7805. ajaxOpts.onerror(xhr);
  7806. }
  7807. }
  7808. };
  7809. if (method == "POST") {
  7810. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  7811. xhr.send(submitStr);
  7812. } else {
  7813. xhr.send(null);
  7814. }
  7815. }
  7816. function doJsonp(url, opts) {
  7817. var successhandler = opts.onsuccess || function(){},
  7818. scr = document.createElement('SCRIPT'),
  7819. options = opts || {},
  7820. charset = options['charset'],
  7821. callbackField = options['jsonp'] || 'callback',
  7822. callbackFnName,
  7823. timeOut = options['timeOut'] || 0,
  7824. timer,
  7825. reg = new RegExp('(\\?|&)' + callbackField + '=([^&]*)'),
  7826. matches;
  7827. if (utils.isFunction(successhandler)) {
  7828. callbackFnName = 'bd__editor__' + Math.floor(Math.random() * 2147483648).toString(36);
  7829. window[callbackFnName] = getCallBack(0);
  7830. } else if(utils.isString(successhandler)){
  7831. callbackFnName = successhandler;
  7832. } else {
  7833. if (matches = reg.exec(url)) {
  7834. callbackFnName = matches[2];
  7835. }
  7836. }
  7837. url = url.replace(reg, '\x241' + callbackField + '=' + callbackFnName);
  7838. if (url.search(reg) < 0) {
  7839. url += (url.indexOf('?') < 0 ? '?' : '&') + callbackField + '=' + callbackFnName;
  7840. }
  7841. var queryStr = json2str(opts); // { name:"Jim",city:"Beijing" } --> "name=Jim&city=Beijing"
  7842. //如果用户直接通过data参数传递json对象过来,则也要将此json对象转化为字符串
  7843. if (!utils.isEmptyObject(opts.data)){
  7844. queryStr += (queryStr? "&":"") + json2str(opts.data);
  7845. }
  7846. if (queryStr) {
  7847. url = url.replace(/\?/, '?' + queryStr + '&');
  7848. }
  7849. scr.onerror = getCallBack(1);
  7850. if( timeOut ){
  7851. timer = setTimeout(getCallBack(1), timeOut);
  7852. }
  7853. createScriptTag(scr, url, charset);
  7854. function createScriptTag(scr, url, charset) {
  7855. scr.setAttribute('type', 'text/javascript');
  7856. scr.setAttribute('defer', 'defer');
  7857. charset && scr.setAttribute('charset', charset);
  7858. scr.setAttribute('src', url);
  7859. document.getElementsByTagName('head')[0].appendChild(scr);
  7860. }
  7861. function getCallBack(onTimeOut){
  7862. return function(){
  7863. try {
  7864. if(onTimeOut){
  7865. options.onerror && options.onerror();
  7866. }else{
  7867. try{
  7868. clearTimeout(timer);
  7869. successhandler.apply(window, arguments);
  7870. } catch (e){}
  7871. }
  7872. } catch (exception) {
  7873. options.onerror && options.onerror.call(window, exception);
  7874. } finally {
  7875. options.oncomplete && options.oncomplete.apply(window, arguments);
  7876. scr.parentNode && scr.parentNode.removeChild(scr);
  7877. window[callbackFnName] = null;
  7878. try {
  7879. delete window[callbackFnName];
  7880. }catch(e){}
  7881. }
  7882. }
  7883. }
  7884. }
  7885. return {
  7886. /**
  7887. * 根据给定的参数项,向指定的url发起一个ajax请求。 ajax请求完成后,会根据请求结果调用相应回调: 如果请求
  7888. * 成功, 则调用onsuccess回调, 失败则调用 onerror 回调
  7889. * @method request
  7890. * @param { URLString } url ajax请求的url地址
  7891. * @param { Object } ajaxOptions ajax请求选项的键值对,支持的选项如下:
  7892. * @example
  7893. * ```javascript
  7894. * //向sayhello.php发起一个异步的Ajax GET请求, 请求超时时间为10s, 请求完成后执行相应的回调。
  7895. * UE.ajax.requeset( 'sayhello.php', {
  7896. *
  7897. * //请求方法。可选值: 'GET', 'POST',默认值是'POST'
  7898. * method: 'GET',
  7899. *
  7900. * //超时时间。 默认为5000, 单位是ms
  7901. * timeout: 10000,
  7902. *
  7903. * //是否是异步请求。 true为异步请求, false为同步请求
  7904. * async: true,
  7905. *
  7906. * //请求携带的数据。如果请求为GET请求, data会经过stringify后附加到请求url之后。
  7907. * data: {
  7908. * name: 'ueditor'
  7909. * },
  7910. *
  7911. * //请求成功后的回调, 该回调接受当前的XMLHttpRequest对象作为参数。
  7912. * onsuccess: function ( xhr ) {
  7913. * console.log( xhr.responseText );
  7914. * },
  7915. *
  7916. * //请求失败或者超时后的回调。
  7917. * onerror: function ( xhr ) {
  7918. * alert( 'Ajax请求失败' );
  7919. * }
  7920. *
  7921. * } );
  7922. * ```
  7923. */
  7924. /**
  7925. * 根据给定的参数项发起一个ajax请求, 参数项里必须包含一个url地址。 ajax请求完成后,会根据请求结果调用相应回调: 如果请求
  7926. * 成功, 则调用onsuccess回调, 失败则调用 onerror 回调。
  7927. * @method request
  7928. * @warning 如果在参数项里未提供一个key为“url”的地址值,则该请求将直接退出。
  7929. * @param { Object } ajaxOptions ajax请求选项的键值对,支持的选项如下:
  7930. * @example
  7931. * ```javascript
  7932. *
  7933. * //向sayhello.php发起一个异步的Ajax POST请求, 请求超时时间为5s, 请求完成后不执行任何回调。
  7934. * UE.ajax.requeset( 'sayhello.php', {
  7935. *
  7936. * //请求的地址, 该项是必须的。
  7937. * url: 'sayhello.php'
  7938. *
  7939. * } );
  7940. * ```
  7941. */
  7942. request:function(url, opts) {
  7943. if (opts && opts.dataType == 'jsonp') {
  7944. doJsonp(url, opts);
  7945. } else {
  7946. doAjax(url, opts);
  7947. }
  7948. },
  7949. getJSONP:function(url, data, fn) {
  7950. var opts = {
  7951. 'data': data,
  7952. 'oncomplete': fn
  7953. };
  7954. doJsonp(url, opts);
  7955. }
  7956. };
  7957. }();
  7958. // core/filterword.js
  7959. /**
  7960. * UE过滤word的静态方法
  7961. * @file
  7962. */
  7963. /**
  7964. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  7965. * @module UE
  7966. */
  7967. /**
  7968. * 根据传入html字符串过滤word
  7969. * @module UE
  7970. * @since 1.2.6.1
  7971. * @method filterWord
  7972. * @param { String } html html字符串
  7973. * @return { String } 已过滤后的结果字符串
  7974. * @example
  7975. * ```javascript
  7976. * UE.filterWord(html);
  7977. * ```
  7978. */
  7979. var filterWord = UE.filterWord = function () {
  7980. //是否是word过来的内容
  7981. function isWordDocument( str ) {
  7982. return /(class="?Mso|style="[^"]*\bmso\-|w:WordDocument|<(v|o):|lang=)/ig.test( str );
  7983. }
  7984. //去掉小数
  7985. function transUnit( v ) {
  7986. v = v.replace( /[\d.]+\w+/g, function ( m ) {
  7987. return utils.transUnitToPx(m);
  7988. } );
  7989. return v;
  7990. }
  7991. function filterPasteWord( str ) {
  7992. return str.replace(/[\t\r\n]+/g,' ')
  7993. .replace( /<!--[\s\S]*?-->/ig, "" )
  7994. //转换图片
  7995. .replace(/<v:shape [^>]*>[\s\S]*?.<\/v:shape>/gi,function(str){
  7996. //opera能自己解析出image所这里直接返回空
  7997. if(browser.opera){
  7998. return '';
  7999. }
  8000. try{
  8001. //有可能是bitmap占为图,无用,直接过滤掉,主要体现在粘贴excel表格中
  8002. if(/Bitmap/i.test(str)){
  8003. return '';
  8004. }
  8005. var width = str.match(/width:([ \d.]*p[tx])/i)[1],
  8006. height = str.match(/height:([ \d.]*p[tx])/i)[1],
  8007. src = str.match(/src=\s*"([^"]*)"/i)[1];
  8008. return '<img width="'+ transUnit(width) +'" height="'+transUnit(height) +'" src="' + src + '" />';
  8009. } catch(e){
  8010. return '';
  8011. }
  8012. })
  8013. //针对wps添加的多余标签处理
  8014. .replace(/<\/?div[^>]*>/g,'')
  8015. //去掉多余的属性
  8016. .replace( /v:\w+=(["']?)[^'"]+\1/g, '' )
  8017. .replace( /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|xml|meta|link|style|\w+:\w+)(?=[\s\/>]))[^>]*>/gi, "" )
  8018. .replace( /<p [^>]*class="?MsoHeading"?[^>]*>(.*?)<\/p>/gi, "<p><strong>$1</strong></p>" )
  8019. //去掉多余的属性
  8020. .replace( /\s+(class|lang|align)\s*=\s*(['"]?)([\w-]+)\2/ig, function(str,name,marks,val){
  8021. //保留list的标示
  8022. return name == 'class' && val == 'MsoListParagraph' ? str : ''
  8023. })
  8024. //清除多余的font/span不能匹配&nbsp;有可能是空格
  8025. .replace( /<(font|span)[^>]*>(\s*)<\/\1>/gi, function(a,b,c){
  8026. return c.replace(/[\t\r\n ]+/g,' ')
  8027. })
  8028. //处理style的问题
  8029. .replace( /(<[a-z][^>]*)\sstyle=(["'])([^\2]*?)\2/gi, function( str, tag, tmp, style ) {
  8030. var n = [],
  8031. s = style.replace( /^\s+|\s+$/, '' )
  8032. .replace(/&#39;/g,'\'')
  8033. .replace( /&quot;/gi, "'" )
  8034. .replace(/[\d.]+(cm|pt)/g,function(str){
  8035. return utils.transUnitToPx(str)
  8036. })
  8037. .split( /;\s*/g );
  8038. for ( var i = 0,v; v = s[i];i++ ) {
  8039. var name, value,
  8040. parts = v.split( ":" );
  8041. if ( parts.length == 2 ) {
  8042. name = parts[0].toLowerCase();
  8043. value = parts[1].toLowerCase();
  8044. if(/^(background)\w*/.test(name) && value.replace(/(initial|\s)/g,'').length == 0
  8045. ||
  8046. /^(margin)\w*/.test(name) && /^0\w+$/.test(value)
  8047. ){
  8048. continue;
  8049. }
  8050. switch ( name ) {
  8051. case "mso-padding-alt":
  8052. case "mso-padding-top-alt":
  8053. case "mso-padding-right-alt":
  8054. case "mso-padding-bottom-alt":
  8055. case "mso-padding-left-alt":
  8056. case "mso-margin-alt":
  8057. case "mso-margin-top-alt":
  8058. case "mso-margin-right-alt":
  8059. case "mso-margin-bottom-alt":
  8060. case "mso-margin-left-alt":
  8061. //ie下会出现挤到一起的情况
  8062. //case "mso-table-layout-alt":
  8063. case "mso-height":
  8064. case "mso-width":
  8065. case "mso-vertical-align-alt":
  8066. //trace:1819 ff下会解析出padding在table上
  8067. if(!/<table/.test(tag))
  8068. n[i] = name.replace( /^mso-|-alt$/g, "" ) + ":" + transUnit( value );
  8069. continue;
  8070. case "horiz-align":
  8071. n[i] = "text-align:" + value;
  8072. continue;
  8073. case "vert-align":
  8074. n[i] = "vertical-align:" + value;
  8075. continue;
  8076. case "font-color":
  8077. case "mso-foreground":
  8078. n[i] = "color:" + value;
  8079. continue;
  8080. case "mso-background":
  8081. case "mso-highlight":
  8082. n[i] = "background:" + value;
  8083. continue;
  8084. case "mso-default-height":
  8085. n[i] = "min-height:" + transUnit( value );
  8086. continue;
  8087. case "mso-default-width":
  8088. n[i] = "min-width:" + transUnit( value );
  8089. continue;
  8090. case "mso-padding-between-alt":
  8091. n[i] = "border-collapse:separate;border-spacing:" + transUnit( value );
  8092. continue;
  8093. case "text-line-through":
  8094. if ( (value == "single") || (value == "double") ) {
  8095. n[i] = "text-decoration:line-through";
  8096. }
  8097. continue;
  8098. case "mso-zero-height":
  8099. if ( value == "yes" ) {
  8100. n[i] = "display:none";
  8101. }
  8102. continue;
  8103. // case 'background':
  8104. // break;
  8105. case 'margin':
  8106. if ( !/[1-9]/.test( value ) ) {
  8107. continue;
  8108. }
  8109. }
  8110. if ( /^(mso|column|font-emph|lang|layout|line-break|list-image|nav|panose|punct|row|ruby|sep|size|src|tab-|table-border|text-(?:decor|trans)|top-bar|version|vnd|word-break)/.test( name )
  8111. ||
  8112. /text\-indent|padding|margin/.test(name) && /\-[\d.]+/.test(value)
  8113. ) {
  8114. continue;
  8115. }
  8116. n[i] = name + ":" + parts[1];
  8117. }
  8118. }
  8119. return tag + (n.length ? ' style="' + n.join( ';').replace(/;{2,}/g,';') + '"' : '');
  8120. })
  8121. }
  8122. return function ( html ) {
  8123. return (isWordDocument( html ) ? filterPasteWord( html ) : html);
  8124. };
  8125. }();
  8126. // core/node.js
  8127. /**
  8128. * 编辑器模拟的节点类
  8129. * @file
  8130. * @module UE
  8131. * @class uNode
  8132. * @since 1.2.6.1
  8133. */
  8134. /**
  8135. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  8136. * @unfile
  8137. * @module UE
  8138. */
  8139. (function () {
  8140. /**
  8141. * 编辑器模拟的节点类
  8142. * @unfile
  8143. * @module UE
  8144. * @class uNode
  8145. */
  8146. /**
  8147. * 通过一个键值对,创建一个uNode对象
  8148. * @constructor
  8149. * @param { Object } attr 传入要创建的uNode的初始属性
  8150. * @example
  8151. * ```javascript
  8152. * var node = new uNode({
  8153. * type:'element',
  8154. * tagName:'span',
  8155. * attrs:{style:'font-size:14px;'}
  8156. * }
  8157. * ```
  8158. */
  8159. var uNode = UE.uNode = function (obj) {
  8160. this.type = obj.type;
  8161. this.data = obj.data;
  8162. this.tagName = obj.tagName;
  8163. this.parentNode = obj.parentNode;
  8164. this.attrs = obj.attrs || {};
  8165. this.children = obj.children;
  8166. };
  8167. var notTransAttrs = {
  8168. 'href':1,
  8169. 'src':1,
  8170. '_src':1,
  8171. '_href':1,
  8172. 'cdata_data':1
  8173. };
  8174. var notTransTagName = {
  8175. style:1,
  8176. script:1
  8177. };
  8178. var indentChar = ' ',
  8179. breakChar = '\n';
  8180. function insertLine(arr, current, begin) {
  8181. arr.push(breakChar);
  8182. return current + (begin ? 1 : -1);
  8183. }
  8184. function insertIndent(arr, current) {
  8185. //插入缩进
  8186. for (var i = 0; i < current; i++) {
  8187. arr.push(indentChar);
  8188. }
  8189. }
  8190. //创建uNode的静态方法
  8191. //支持标签和html
  8192. uNode.createElement = function (html) {
  8193. if (/[<>]/.test(html)) {
  8194. return UE.htmlparser(html).children[0]
  8195. } else {
  8196. return new uNode({
  8197. type:'element',
  8198. children:[],
  8199. tagName:html
  8200. })
  8201. }
  8202. };
  8203. uNode.createText = function (data,noTrans) {
  8204. return new UE.uNode({
  8205. type:'text',
  8206. 'data':noTrans ? data : utils.unhtml(data || '')
  8207. })
  8208. };
  8209. function nodeToHtml(node, arr, formatter, current) {
  8210. switch (node.type) {
  8211. case 'root':
  8212. for (var i = 0, ci; ci = node.children[i++];) {
  8213. //插入新行
  8214. if (formatter && ci.type == 'element' && !dtd.$inlineWithA[ci.tagName] && i > 1) {
  8215. insertLine(arr, current, true);
  8216. insertIndent(arr, current)
  8217. }
  8218. nodeToHtml(ci, arr, formatter, current)
  8219. }
  8220. break;
  8221. case 'text':
  8222. isText(node, arr);
  8223. break;
  8224. case 'element':
  8225. isElement(node, arr, formatter, current);
  8226. break;
  8227. case 'comment':
  8228. isComment(node, arr, formatter);
  8229. }
  8230. return arr;
  8231. }
  8232. function isText(node, arr) {
  8233. if(node.parentNode.tagName == 'pre'){
  8234. //源码模式下输入html标签,不能做转换处理,直接输出
  8235. arr.push(node.data)
  8236. }else{
  8237. arr.push(notTransTagName[node.parentNode.tagName] ? utils.html(node.data) : node.data.replace(/[ ]{2}/g,' &nbsp;'))
  8238. }
  8239. }
  8240. function isElement(node, arr, formatter, current) {
  8241. var attrhtml = '';
  8242. if (node.attrs) {
  8243. attrhtml = [];
  8244. var attrs = node.attrs;
  8245. for (var a in attrs) {
  8246. //这里就针对
  8247. //<p>'<img src='http://nsclick.baidu.com/u.gif?&asdf=\"sdf&asdfasdfs;asdf'></p>
  8248. //这里边的\"做转换,要不用innerHTML直接被截断了,属性src
  8249. //有可能做的不够
  8250. attrhtml.push(a + (attrs[a] !== undefined ? '="' + (notTransAttrs[a] ? utils.html(attrs[a]).replace(/["]/g, function (a) {
  8251. return '&quot;'
  8252. }) : utils.unhtml(attrs[a])) + '"' : ''))
  8253. }
  8254. attrhtml = attrhtml.join(' ');
  8255. }
  8256. arr.push('<' + node.tagName +
  8257. (attrhtml ? ' ' + attrhtml : '') +
  8258. (dtd.$empty[node.tagName] ? '\/' : '' ) + '>'
  8259. );
  8260. //插入新行
  8261. if (formatter && !dtd.$inlineWithA[node.tagName] && node.tagName != 'pre') {
  8262. if(node.children && node.children.length){
  8263. current = insertLine(arr, current, true);
  8264. insertIndent(arr, current)
  8265. }
  8266. }
  8267. if (node.children && node.children.length) {
  8268. for (var i = 0, ci; ci = node.children[i++];) {
  8269. if (formatter && ci.type == 'element' && !dtd.$inlineWithA[ci.tagName] && i > 1) {
  8270. insertLine(arr, current);
  8271. insertIndent(arr, current)
  8272. }
  8273. nodeToHtml(ci, arr, formatter, current)
  8274. }
  8275. }
  8276. if (!dtd.$empty[node.tagName]) {
  8277. if (formatter && !dtd.$inlineWithA[node.tagName] && node.tagName != 'pre') {
  8278. if(node.children && node.children.length){
  8279. current = insertLine(arr, current);
  8280. insertIndent(arr, current)
  8281. }
  8282. }
  8283. arr.push('<\/' + node.tagName + '>');
  8284. }
  8285. }
  8286. function isComment(node, arr) {
  8287. arr.push('<!--' + node.data + '-->');
  8288. }
  8289. function getNodeById(root, id) {
  8290. var node;
  8291. if (root.type == 'element' && root.getAttr('id') == id) {
  8292. return root;
  8293. }
  8294. if (root.children && root.children.length) {
  8295. for (var i = 0, ci; ci = root.children[i++];) {
  8296. if (node = getNodeById(ci, id)) {
  8297. return node;
  8298. }
  8299. }
  8300. }
  8301. }
  8302. function getNodesByTagName(node, tagName, arr) {
  8303. if (node.type == 'element' && node.tagName == tagName) {
  8304. arr.push(node);
  8305. }
  8306. if (node.children && node.children.length) {
  8307. for (var i = 0, ci; ci = node.children[i++];) {
  8308. getNodesByTagName(ci, tagName, arr)
  8309. }
  8310. }
  8311. }
  8312. function nodeTraversal(root,fn){
  8313. if(root.children && root.children.length){
  8314. for(var i= 0,ci;ci=root.children[i];){
  8315. nodeTraversal(ci,fn);
  8316. //ci被替换的情况,这里就不再走 fn了
  8317. if(ci.parentNode ){
  8318. if(ci.children && ci.children.length){
  8319. fn(ci)
  8320. }
  8321. if(ci.parentNode) i++
  8322. }
  8323. }
  8324. }else{
  8325. fn(root)
  8326. }
  8327. }
  8328. uNode.prototype = {
  8329. /**
  8330. * 当前节点对象,转换成html文本
  8331. * @method toHtml
  8332. * @return { String } 返回转换后的html字符串
  8333. * @example
  8334. * ```javascript
  8335. * node.toHtml();
  8336. * ```
  8337. */
  8338. /**
  8339. * 当前节点对象,转换成html文本
  8340. * @method toHtml
  8341. * @param { Boolean } formatter 是否格式化返回值
  8342. * @return { String } 返回转换后的html字符串
  8343. * @example
  8344. * ```javascript
  8345. * node.toHtml( true );
  8346. * ```
  8347. */
  8348. toHtml:function (formatter) {
  8349. var arr = [];
  8350. nodeToHtml(this, arr, formatter, 0);
  8351. return arr.join('')
  8352. },
  8353. /**
  8354. * 获取节点的html内容
  8355. * @method innerHTML
  8356. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  8357. * @return { String } 返回节点的html内容
  8358. * @example
  8359. * ```javascript
  8360. * var htmlstr = node.innerHTML();
  8361. * ```
  8362. */
  8363. /**
  8364. * 设置节点的html内容
  8365. * @method innerHTML
  8366. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  8367. * @param { String } htmlstr 传入要设置的html内容
  8368. * @return { UE.uNode } 返回节点本身
  8369. * @example
  8370. * ```javascript
  8371. * node.innerHTML('<span>text</span>');
  8372. * ```
  8373. */
  8374. innerHTML:function (htmlstr) {
  8375. if (this.type != 'element' || dtd.$empty[this.tagName]) {
  8376. return this;
  8377. }
  8378. if (utils.isString(htmlstr)) {
  8379. if(this.children){
  8380. for (var i = 0, ci; ci = this.children[i++];) {
  8381. ci.parentNode = null;
  8382. }
  8383. }
  8384. this.children = [];
  8385. var tmpRoot = UE.htmlparser(htmlstr);
  8386. for (var i = 0, ci; ci = tmpRoot.children[i++];) {
  8387. this.children.push(ci);
  8388. ci.parentNode = this;
  8389. }
  8390. return this;
  8391. } else {
  8392. var tmpRoot = new UE.uNode({
  8393. type:'root',
  8394. children:this.children
  8395. });
  8396. return tmpRoot.toHtml();
  8397. }
  8398. },
  8399. /**
  8400. * 获取节点的纯文本内容
  8401. * @method innerText
  8402. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  8403. * @return { String } 返回节点的存文本内容
  8404. * @example
  8405. * ```javascript
  8406. * var textStr = node.innerText();
  8407. * ```
  8408. */
  8409. /**
  8410. * 设置节点的纯文本内容
  8411. * @method innerText
  8412. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  8413. * @param { String } textStr 传入要设置的文本内容
  8414. * @return { UE.uNode } 返回节点本身
  8415. * @example
  8416. * ```javascript
  8417. * node.innerText('<span>text</span>');
  8418. * ```
  8419. */
  8420. innerText:function (textStr,noTrans) {
  8421. if (this.type != 'element' || dtd.$empty[this.tagName]) {
  8422. return this;
  8423. }
  8424. if (textStr) {
  8425. if(this.children){
  8426. for (var i = 0, ci; ci = this.children[i++];) {
  8427. ci.parentNode = null;
  8428. }
  8429. }
  8430. this.children = [];
  8431. this.appendChild(uNode.createText(textStr,noTrans));
  8432. return this;
  8433. } else {
  8434. return this.toHtml().replace(/<[^>]+>/g, '');
  8435. }
  8436. },
  8437. /**
  8438. * 获取当前对象的data属性
  8439. * @method getData
  8440. * @return { Object } 若节点的type值是elemenet,返回空字符串,否则返回节点的data属性
  8441. * @example
  8442. * ```javascript
  8443. * node.getData();
  8444. * ```
  8445. */
  8446. getData:function () {
  8447. if (this.type == 'element')
  8448. return '';
  8449. return this.data
  8450. },
  8451. /**
  8452. * 获取当前节点下的第一个子节点
  8453. * @method firstChild
  8454. * @return { UE.uNode } 返回第一个子节点
  8455. * @example
  8456. * ```javascript
  8457. * node.firstChild(); //返回第一个子节点
  8458. * ```
  8459. */
  8460. firstChild:function () {
  8461. // if (this.type != 'element' || dtd.$empty[this.tagName]) {
  8462. // return this;
  8463. // }
  8464. return this.children ? this.children[0] : null;
  8465. },
  8466. /**
  8467. * 获取当前节点下的最后一个子节点
  8468. * @method lastChild
  8469. * @return { UE.uNode } 返回最后一个子节点
  8470. * @example
  8471. * ```javascript
  8472. * node.lastChild(); //返回最后一个子节点
  8473. * ```
  8474. */
  8475. lastChild:function () {
  8476. // if (this.type != 'element' || dtd.$empty[this.tagName] ) {
  8477. // return this;
  8478. // }
  8479. return this.children ? this.children[this.children.length - 1] : null;
  8480. },
  8481. /**
  8482. * 获取和当前节点有相同父亲节点的前一个节点
  8483. * @method previousSibling
  8484. * @return { UE.uNode } 返回前一个节点
  8485. * @example
  8486. * ```javascript
  8487. * node.children[2].previousSibling(); //返回子节点node.children[1]
  8488. * ```
  8489. */
  8490. previousSibling : function(){
  8491. var parent = this.parentNode;
  8492. for (var i = 0, ci; ci = parent.children[i]; i++) {
  8493. if (ci === this) {
  8494. return i == 0 ? null : parent.children[i-1];
  8495. }
  8496. }
  8497. },
  8498. /**
  8499. * 获取和当前节点有相同父亲节点的后一个节点
  8500. * @method nextSibling
  8501. * @return { UE.uNode } 返回后一个节点,找不到返回null
  8502. * @example
  8503. * ```javascript
  8504. * node.children[2].nextSibling(); //如果有,返回子节点node.children[3]
  8505. * ```
  8506. */
  8507. nextSibling : function(){
  8508. var parent = this.parentNode;
  8509. for (var i = 0, ci; ci = parent.children[i++];) {
  8510. if (ci === this) {
  8511. return parent.children[i];
  8512. }
  8513. }
  8514. },
  8515. /**
  8516. * 用新的节点替换当前节点
  8517. * @method replaceChild
  8518. * @param { UE.uNode } target 要替换成该节点参数
  8519. * @param { UE.uNode } source 要被替换掉的节点
  8520. * @return { UE.uNode } 返回替换之后的节点对象
  8521. * @example
  8522. * ```javascript
  8523. * node.replaceChild(newNode, childNode); //用newNode替换childNode,childNode是node的子节点
  8524. * ```
  8525. */
  8526. replaceChild:function (target, source) {
  8527. if (this.children) {
  8528. if(target.parentNode){
  8529. target.parentNode.removeChild(target);
  8530. }
  8531. for (var i = 0, ci; ci = this.children[i]; i++) {
  8532. if (ci === source) {
  8533. this.children.splice(i, 1, target);
  8534. source.parentNode = null;
  8535. target.parentNode = this;
  8536. return target;
  8537. }
  8538. }
  8539. }
  8540. },
  8541. /**
  8542. * 在节点的子节点列表最后位置插入一个节点
  8543. * @method appendChild
  8544. * @param { UE.uNode } node 要插入的节点
  8545. * @return { UE.uNode } 返回刚插入的子节点
  8546. * @example
  8547. * ```javascript
  8548. * node.appendChild( newNode ); //在node内插入子节点newNode
  8549. * ```
  8550. */
  8551. appendChild:function (node) {
  8552. if (this.type == 'root' || (this.type == 'element' && !dtd.$empty[this.tagName])) {
  8553. if (!this.children) {
  8554. this.children = []
  8555. }
  8556. if(node.parentNode){
  8557. node.parentNode.removeChild(node);
  8558. }
  8559. for (var i = 0, ci; ci = this.children[i]; i++) {
  8560. if (ci === node) {
  8561. this.children.splice(i, 1);
  8562. break;
  8563. }
  8564. }
  8565. this.children.push(node);
  8566. node.parentNode = this;
  8567. return node;
  8568. }
  8569. },
  8570. /**
  8571. * 在传入节点的前面插入一个节点
  8572. * @method insertBefore
  8573. * @param { UE.uNode } target 要插入的节点
  8574. * @param { UE.uNode } source 在该参数节点前面插入
  8575. * @return { UE.uNode } 返回刚插入的子节点
  8576. * @example
  8577. * ```javascript
  8578. * node.parentNode.insertBefore(newNode, node); //在node节点后面插入newNode
  8579. * ```
  8580. */
  8581. insertBefore:function (target, source) {
  8582. if (this.children) {
  8583. if(target.parentNode){
  8584. target.parentNode.removeChild(target);
  8585. }
  8586. for (var i = 0, ci; ci = this.children[i]; i++) {
  8587. if (ci === source) {
  8588. this.children.splice(i, 0, target);
  8589. target.parentNode = this;
  8590. return target;
  8591. }
  8592. }
  8593. }
  8594. },
  8595. /**
  8596. * 在传入节点的后面插入一个节点
  8597. * @method insertAfter
  8598. * @param { UE.uNode } target 要插入的节点
  8599. * @param { UE.uNode } source 在该参数节点后面插入
  8600. * @return { UE.uNode } 返回刚插入的子节点
  8601. * @example
  8602. * ```javascript
  8603. * node.parentNode.insertAfter(newNode, node); //在node节点后面插入newNode
  8604. * ```
  8605. */
  8606. insertAfter:function (target, source) {
  8607. if (this.children) {
  8608. if(target.parentNode){
  8609. target.parentNode.removeChild(target);
  8610. }
  8611. for (var i = 0, ci; ci = this.children[i]; i++) {
  8612. if (ci === source) {
  8613. this.children.splice(i + 1, 0, target);
  8614. target.parentNode = this;
  8615. return target;
  8616. }
  8617. }
  8618. }
  8619. },
  8620. /**
  8621. * 从当前节点的子节点列表中,移除节点
  8622. * @method removeChild
  8623. * @param { UE.uNode } node 要移除的节点引用
  8624. * @param { Boolean } keepChildren 是否保留移除节点的子节点,若传入true,自动把移除节点的子节点插入到移除的位置
  8625. * @return { * } 返回刚移除的子节点
  8626. * @example
  8627. * ```javascript
  8628. * node.removeChild(childNode,true); //在node的子节点列表中移除child节点,并且吧child的子节点插入到移除的位置
  8629. * ```
  8630. */
  8631. removeChild:function (node,keepChildren) {
  8632. if (this.children) {
  8633. for (var i = 0, ci; ci = this.children[i]; i++) {
  8634. if (ci === node) {
  8635. this.children.splice(i, 1);
  8636. ci.parentNode = null;
  8637. if(keepChildren && ci.children && ci.children.length){
  8638. for(var j= 0,cj;cj=ci.children[j];j++){
  8639. this.children.splice(i+j,0,cj);
  8640. cj.parentNode = this;
  8641. }
  8642. }
  8643. return ci;
  8644. }
  8645. }
  8646. }
  8647. },
  8648. /**
  8649. * 获取当前节点所代表的元素属性,即获取attrs对象下的属性值
  8650. * @method getAttr
  8651. * @param { String } attrName 要获取的属性名称
  8652. * @return { * } 返回attrs对象下的属性值
  8653. * @example
  8654. * ```javascript
  8655. * node.getAttr('title');
  8656. * ```
  8657. */
  8658. getAttr:function (attrName) {
  8659. return this.attrs && this.attrs[attrName.toLowerCase()]
  8660. },
  8661. /**
  8662. * 设置当前节点所代表的元素属性,即设置attrs对象下的属性值
  8663. * @method setAttr
  8664. * @param { String } attrName 要设置的属性名称
  8665. * @param { * } attrVal 要设置的属性值,类型视设置的属性而定
  8666. * @return { * } 返回attrs对象下的属性值
  8667. * @example
  8668. * ```javascript
  8669. * node.setAttr('title','标题');
  8670. * ```
  8671. */
  8672. setAttr:function (attrName, attrVal) {
  8673. if (!attrName) {
  8674. delete this.attrs;
  8675. return;
  8676. }
  8677. if(!this.attrs){
  8678. this.attrs = {};
  8679. }
  8680. if (utils.isObject(attrName)) {
  8681. for (var a in attrName) {
  8682. if (!attrName[a]) {
  8683. delete this.attrs[a]
  8684. } else {
  8685. this.attrs[a.toLowerCase()] = attrName[a];
  8686. }
  8687. }
  8688. } else {
  8689. if (!attrVal) {
  8690. delete this.attrs[attrName]
  8691. } else {
  8692. this.attrs[attrName.toLowerCase()] = attrVal;
  8693. }
  8694. }
  8695. },
  8696. /**
  8697. * 获取当前节点在父节点下的位置索引
  8698. * @method getIndex
  8699. * @return { Number } 返回索引数值,如果没有父节点,返回-1
  8700. * @example
  8701. * ```javascript
  8702. * node.getIndex();
  8703. * ```
  8704. */
  8705. getIndex:function(){
  8706. var parent = this.parentNode;
  8707. for(var i= 0,ci;ci=parent.children[i];i++){
  8708. if(ci === this){
  8709. return i;
  8710. }
  8711. }
  8712. return -1;
  8713. },
  8714. /**
  8715. * 在当前节点下,根据id查找节点
  8716. * @method getNodeById
  8717. * @param { String } id 要查找的id
  8718. * @return { UE.uNode } 返回找到的节点
  8719. * @example
  8720. * ```javascript
  8721. * node.getNodeById('textId');
  8722. * ```
  8723. */
  8724. getNodeById:function (id) {
  8725. var node;
  8726. if (this.children && this.children.length) {
  8727. for (var i = 0, ci; ci = this.children[i++];) {
  8728. if (node = getNodeById(ci, id)) {
  8729. return node;
  8730. }
  8731. }
  8732. }
  8733. },
  8734. /**
  8735. * 在当前节点下,根据元素名称查找节点列表
  8736. * @method getNodesByTagName
  8737. * @param { String } tagNames 要查找的元素名称
  8738. * @return { Array } 返回找到的节点列表
  8739. * @example
  8740. * ```javascript
  8741. * node.getNodesByTagName('span');
  8742. * ```
  8743. */
  8744. getNodesByTagName:function (tagNames) {
  8745. tagNames = utils.trim(tagNames).replace(/[ ]{2,}/g, ' ').split(' ');
  8746. var arr = [], me = this;
  8747. utils.each(tagNames, function (tagName) {
  8748. if (me.children && me.children.length) {
  8749. for (var i = 0, ci; ci = me.children[i++];) {
  8750. getNodesByTagName(ci, tagName, arr)
  8751. }
  8752. }
  8753. });
  8754. return arr;
  8755. },
  8756. /**
  8757. * 根据样式名称,获取节点的样式值
  8758. * @method getStyle
  8759. * @param { String } name 要获取的样式名称
  8760. * @return { String } 返回样式值
  8761. * @example
  8762. * ```javascript
  8763. * node.getStyle('font-size');
  8764. * ```
  8765. */
  8766. getStyle:function (name) {
  8767. var cssStyle = this.getAttr('style');
  8768. if (!cssStyle) {
  8769. return ''
  8770. }
  8771. var reg = new RegExp('(^|;)\\s*' + name + ':([^;]+)','i');
  8772. var match = cssStyle.match(reg);
  8773. if (match && match[0]) {
  8774. return match[2]
  8775. }
  8776. return '';
  8777. },
  8778. /**
  8779. * 给节点设置样式
  8780. * @method setStyle
  8781. * @param { String } name 要设置的的样式名称
  8782. * @param { String } val 要设置的的样值
  8783. * @example
  8784. * ```javascript
  8785. * node.setStyle('font-size', '12px');
  8786. * ```
  8787. */
  8788. setStyle:function (name, val) {
  8789. function exec(name, val) {
  8790. var reg = new RegExp('(^|;)\\s*' + name + ':([^;]+;?)', 'gi');
  8791. cssStyle = cssStyle.replace(reg, '$1');
  8792. if (val) {
  8793. cssStyle = name + ':' + utils.unhtml(val) + ';' + cssStyle
  8794. }
  8795. }
  8796. var cssStyle = this.getAttr('style');
  8797. if (!cssStyle) {
  8798. cssStyle = '';
  8799. }
  8800. if (utils.isObject(name)) {
  8801. for (var a in name) {
  8802. exec(a, name[a])
  8803. }
  8804. } else {
  8805. exec(name, val)
  8806. }
  8807. this.setAttr('style', utils.trim(cssStyle))
  8808. },
  8809. /**
  8810. * 传入一个函数,递归遍历当前节点下的所有节点
  8811. * @method traversal
  8812. * @param { Function } fn 遍历到节点的时,传入节点作为参数,运行此函数
  8813. * @example
  8814. * ```javascript
  8815. * traversal(node, function(){
  8816. * console.log(node.type);
  8817. * });
  8818. * ```
  8819. */
  8820. traversal:function(fn){
  8821. if(this.children && this.children.length){
  8822. nodeTraversal(this,fn);
  8823. }
  8824. return this;
  8825. }
  8826. }
  8827. })();
  8828. // core/htmlparser.js
  8829. /**
  8830. * html字符串转换成uNode节点
  8831. * @file
  8832. * @module UE
  8833. * @since 1.2.6.1
  8834. */
  8835. /**
  8836. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  8837. * @unfile
  8838. * @module UE
  8839. */
  8840. /**
  8841. * html字符串转换成uNode节点的静态方法
  8842. * @method htmlparser
  8843. * @param { String } htmlstr 要转换的html代码
  8844. * @param { Boolean } ignoreBlank 若设置为true,转换的时候忽略\n\r\t等空白字符
  8845. * @return { uNode } 给定的html片段转换形成的uNode对象
  8846. * @example
  8847. * ```javascript
  8848. * var root = UE.htmlparser('<p><b>htmlparser</b></p>', true);
  8849. * ```
  8850. */
  8851. var htmlparser = UE.htmlparser = function (htmlstr,ignoreBlank) {
  8852. //todo 原来的方式 [^"'<>\/] 有\/就不能配对上 <TD vAlign=top background=../AAA.JPG> 这样的标签了
  8853. //先去掉了,加上的原因忘了,这里先记录
  8854. var re_tag = /<(?:(?:\/([^>]+)>)|(?:!--([\S|\s]*?)-->)|(?:([^\s\/<>]+)\s*((?:(?:"[^"]*")|(?:'[^']*')|[^"'<>])*)\/?>))/g,
  8855. re_attr = /([\w\-:.]+)(?:(?:\s*=\s*(?:(?:"([^"]*)")|(?:'([^']*)')|([^\s>]+)))|(?=\s|$))/g;
  8856. //ie下取得的html可能会有\n存在,要去掉,在处理replace(/[\t\r\n]*/g,'');代码高量的\n不能去除
  8857. var allowEmptyTags = {
  8858. b:1,code:1,i:1,u:1,strike:1,s:1,tt:1,strong:1,q:1,samp:1,em:1,span:1,
  8859. sub:1,img:1,sup:1,font:1,big:1,small:1,iframe:1,a:1,br:1,pre:1
  8860. };
  8861. htmlstr = htmlstr.replace(new RegExp(domUtils.fillChar, 'g'), '');
  8862. if(!ignoreBlank){
  8863. htmlstr = htmlstr.replace(new RegExp('[\\r\\t\\n'+(ignoreBlank?'':' ')+']*<\/?(\\w+)\\s*(?:[^>]*)>[\\r\\t\\n'+(ignoreBlank?'':' ')+']*','g'), function(a,b){
  8864. //br暂时单独处理
  8865. if(b && allowEmptyTags[b.toLowerCase()]){
  8866. return a.replace(/(^[\n\r]+)|([\n\r]+$)/g,'');
  8867. }
  8868. return a.replace(new RegExp('^[\\r\\n'+(ignoreBlank?'':' ')+']+'),'').replace(new RegExp('[\\r\\n'+(ignoreBlank?'':' ')+']+$'),'');
  8869. });
  8870. }
  8871. var notTransAttrs = {
  8872. 'href':1,
  8873. 'src':1
  8874. };
  8875. var uNode = UE.uNode,
  8876. needParentNode = {
  8877. 'td':'tr',
  8878. 'tr':['tbody','thead','tfoot'],
  8879. 'tbody':'table',
  8880. 'th':'tr',
  8881. 'thead':'table',
  8882. 'tfoot':'table',
  8883. 'caption':'table',
  8884. 'li':['ul', 'ol'],
  8885. 'dt':'dl',
  8886. 'dd':'dl',
  8887. 'option':'select'
  8888. },
  8889. needChild = {
  8890. 'ol':'li',
  8891. 'ul':'li'
  8892. };
  8893. function text(parent, data) {
  8894. if(needChild[parent.tagName]){
  8895. var tmpNode = uNode.createElement(needChild[parent.tagName]);
  8896. parent.appendChild(tmpNode);
  8897. tmpNode.appendChild(uNode.createText(data));
  8898. parent = tmpNode;
  8899. }else{
  8900. parent.appendChild(uNode.createText(data));
  8901. }
  8902. }
  8903. function element(parent, tagName, htmlattr) {
  8904. var needParentTag;
  8905. if (needParentTag = needParentNode[tagName]) {
  8906. var tmpParent = parent,hasParent;
  8907. while(tmpParent.type != 'root'){
  8908. if(utils.isArray(needParentTag) ? utils.indexOf(needParentTag, tmpParent.tagName) != -1 : needParentTag == tmpParent.tagName){
  8909. parent = tmpParent;
  8910. hasParent = true;
  8911. break;
  8912. }
  8913. tmpParent = tmpParent.parentNode;
  8914. }
  8915. if(!hasParent){
  8916. parent = element(parent, utils.isArray(needParentTag) ? needParentTag[0] : needParentTag)
  8917. }
  8918. }
  8919. //按dtd处理嵌套
  8920. // if(parent.type != 'root' && !dtd[parent.tagName][tagName])
  8921. // parent = parent.parentNode;
  8922. var elm = new uNode({
  8923. parentNode:parent,
  8924. type:'element',
  8925. tagName:tagName.toLowerCase(),
  8926. //是自闭合的处理一下
  8927. children:dtd.$empty[tagName] ? null : []
  8928. });
  8929. //如果属性存在,处理属性
  8930. if (htmlattr) {
  8931. var attrs = {}, match;
  8932. while (match = re_attr.exec(htmlattr)) {
  8933. attrs[match[1].toLowerCase()] = notTransAttrs[match[1].toLowerCase()] ? (match[2] || match[3] || match[4]) : utils.unhtml(match[2] || match[3] || match[4])
  8934. }
  8935. elm.attrs = attrs;
  8936. }
  8937. //trace:3970
  8938. // //如果parent下不能放elm
  8939. // if(dtd.$inline[parent.tagName] && dtd.$block[elm.tagName] && !dtd[parent.tagName][elm.tagName]){
  8940. // parent = parent.parentNode;
  8941. // elm.parentNode = parent;
  8942. // }
  8943. parent.children.push(elm);
  8944. //如果是自闭合节点返回父亲节点
  8945. return dtd.$empty[tagName] ? parent : elm
  8946. }
  8947. function comment(parent, data) {
  8948. parent.children.push(new uNode({
  8949. type:'comment',
  8950. data:data,
  8951. parentNode:parent
  8952. }));
  8953. }
  8954. var match, currentIndex = 0, nextIndex = 0;
  8955. //设置根节点
  8956. var root = new uNode({
  8957. type:'root',
  8958. children:[]
  8959. });
  8960. var currentParent = root;
  8961. while (match = re_tag.exec(htmlstr)) {
  8962. currentIndex = match.index;
  8963. try{
  8964. if (currentIndex > nextIndex) {
  8965. //text node
  8966. text(currentParent, htmlstr.slice(nextIndex, currentIndex));
  8967. }
  8968. if (match[3]) {
  8969. if(dtd.$cdata[currentParent.tagName]){
  8970. text(currentParent, match[0]);
  8971. }else{
  8972. //start tag
  8973. currentParent = element(currentParent, match[3].toLowerCase(), match[4]);
  8974. }
  8975. } else if (match[1]) {
  8976. if(currentParent.type != 'root'){
  8977. if(dtd.$cdata[currentParent.tagName] && !dtd.$cdata[match[1]]){
  8978. text(currentParent, match[0]);
  8979. }else{
  8980. var tmpParent = currentParent;
  8981. while(currentParent.type == 'element' && currentParent.tagName != match[1].toLowerCase()){
  8982. currentParent = currentParent.parentNode;
  8983. if(currentParent.type == 'root'){
  8984. currentParent = tmpParent;
  8985. throw 'break'
  8986. }
  8987. }
  8988. //end tag
  8989. currentParent = currentParent.parentNode;
  8990. }
  8991. }
  8992. } else if (match[2]) {
  8993. //comment
  8994. comment(currentParent, match[2])
  8995. }
  8996. }catch(e){}
  8997. nextIndex = re_tag.lastIndex;
  8998. }
  8999. //如果结束是文本,就有可能丢掉,所以这里手动判断一下
  9000. //例如 <li>sdfsdfsdf<li>sdfsdfsdfsdf
  9001. if (nextIndex < htmlstr.length) {
  9002. text(currentParent, htmlstr.slice(nextIndex));
  9003. }
  9004. return root;
  9005. };
  9006. // core/filternode.js
  9007. /**
  9008. * UE过滤节点的静态方法
  9009. * @file
  9010. */
  9011. /**
  9012. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  9013. * @module UE
  9014. */
  9015. /**
  9016. * 根据传入节点和过滤规则过滤相应节点
  9017. * @module UE
  9018. * @since 1.2.6.1
  9019. * @method filterNode
  9020. * @param { Object } root 指定root节点
  9021. * @param { Object } rules 过滤规则json对象
  9022. * @example
  9023. * ```javascript
  9024. * UE.filterNode(root,editor.options.filterRules);
  9025. * ```
  9026. */
  9027. var filterNode = UE.filterNode = function () {
  9028. function filterNode(node,rules){
  9029. switch (node.type) {
  9030. case 'text':
  9031. break;
  9032. case 'element':
  9033. var val;
  9034. if(val = rules[node.tagName]){
  9035. if(val === '-'){
  9036. node.parentNode.removeChild(node)
  9037. }else if(utils.isFunction(val)){
  9038. var parentNode = node.parentNode,
  9039. index = node.getIndex();
  9040. val(node);
  9041. if(node.parentNode){
  9042. if(node.children){
  9043. for(var i = 0,ci;ci=node.children[i];){
  9044. filterNode(ci,rules);
  9045. if(ci.parentNode){
  9046. i++;
  9047. }
  9048. }
  9049. }
  9050. }else{
  9051. for(var i = index,ci;ci=parentNode.children[i];){
  9052. filterNode(ci,rules);
  9053. if(ci.parentNode){
  9054. i++;
  9055. }
  9056. }
  9057. }
  9058. }else{
  9059. var attrs = val['$'];
  9060. if(attrs && node.attrs){
  9061. var tmpAttrs = {},tmpVal;
  9062. for(var a in attrs){
  9063. tmpVal = node.getAttr(a);
  9064. //todo 只先对style单独处理
  9065. if(a == 'style' && utils.isArray(attrs[a])){
  9066. var tmpCssStyle = [];
  9067. utils.each(attrs[a],function(v){
  9068. var tmp;
  9069. if(tmp = node.getStyle(v)){
  9070. tmpCssStyle.push(v + ':' + tmp);
  9071. }
  9072. });
  9073. tmpVal = tmpCssStyle.join(';')
  9074. }
  9075. if(tmpVal){
  9076. tmpAttrs[a] = tmpVal;
  9077. }
  9078. }
  9079. node.attrs = tmpAttrs;
  9080. }
  9081. if(node.children){
  9082. for(var i = 0,ci;ci=node.children[i];){
  9083. filterNode(ci,rules);
  9084. if(ci.parentNode){
  9085. i++;
  9086. }
  9087. }
  9088. }
  9089. }
  9090. }else{
  9091. //如果不在名单里扣出子节点并删除该节点,cdata除外
  9092. if(dtd.$cdata[node.tagName]){
  9093. node.parentNode.removeChild(node)
  9094. }else{
  9095. var parentNode = node.parentNode,
  9096. index = node.getIndex();
  9097. node.parentNode.removeChild(node,true);
  9098. for(var i = index,ci;ci=parentNode.children[i];){
  9099. filterNode(ci,rules);
  9100. if(ci.parentNode){
  9101. i++;
  9102. }
  9103. }
  9104. }
  9105. }
  9106. break;
  9107. case 'comment':
  9108. node.parentNode.removeChild(node)
  9109. }
  9110. }
  9111. return function(root,rules){
  9112. if(utils.isEmptyObject(rules)){
  9113. return root;
  9114. }
  9115. var val;
  9116. if(val = rules['-']){
  9117. utils.each(val.split(' '),function(k){
  9118. rules[k] = '-'
  9119. })
  9120. }
  9121. for(var i= 0,ci;ci=root.children[i];){
  9122. filterNode(ci,rules);
  9123. if(ci.parentNode){
  9124. i++;
  9125. }
  9126. }
  9127. return root;
  9128. }
  9129. }();
  9130. // core/plugin.js
  9131. /**
  9132. * Created with JetBrains PhpStorm.
  9133. * User: campaign
  9134. * Date: 10/8/13
  9135. * Time: 6:15 PM
  9136. * To change this template use File | Settings | File Templates.
  9137. */
  9138. UE.plugin = function(){
  9139. var _plugins = {};
  9140. return {
  9141. register : function(pluginName,fn,oldOptionName,afterDisabled){
  9142. if(oldOptionName && utils.isFunction(oldOptionName)){
  9143. afterDisabled = oldOptionName;
  9144. oldOptionName = null
  9145. }
  9146. _plugins[pluginName] = {
  9147. optionName : oldOptionName || pluginName,
  9148. execFn : fn,
  9149. //当插件被禁用时执行
  9150. afterDisabled : afterDisabled
  9151. }
  9152. },
  9153. load : function(editor){
  9154. utils.each(_plugins,function(plugin){
  9155. var _export = plugin.execFn.call(editor);
  9156. if(editor.options[plugin.optionName] !== false){
  9157. if(_export){
  9158. //后边需要再做扩展
  9159. utils.each(_export,function(v,k){
  9160. switch(k.toLowerCase()){
  9161. case 'shortcutkey':
  9162. editor.addshortcutkey(v);
  9163. break;
  9164. case 'bindevents':
  9165. utils.each(v,function(fn,eventName){
  9166. editor.addListener(eventName,fn);
  9167. });
  9168. break;
  9169. case 'bindmultievents':
  9170. utils.each(utils.isArray(v) ? v:[v],function(event){
  9171. var types = utils.trim(event.type).split(/\s+/);
  9172. utils.each(types,function(eventName){
  9173. editor.addListener(eventName, event.handler);
  9174. });
  9175. });
  9176. break;
  9177. case 'commands':
  9178. utils.each(v,function(execFn,execName){
  9179. editor.commands[execName] = execFn
  9180. });
  9181. break;
  9182. case 'outputrule':
  9183. editor.addOutputRule(v);
  9184. break;
  9185. case 'inputrule':
  9186. editor.addInputRule(v);
  9187. break;
  9188. case 'defaultoptions':
  9189. editor.setOpt(v)
  9190. }
  9191. })
  9192. }
  9193. }else if(plugin.afterDisabled){
  9194. plugin.afterDisabled.call(editor)
  9195. }
  9196. });
  9197. //向下兼容
  9198. utils.each(UE.plugins,function(plugin){
  9199. plugin.call(editor);
  9200. });
  9201. },
  9202. run : function(pluginName,editor){
  9203. var plugin = _plugins[pluginName];
  9204. if(plugin){
  9205. plugin.exeFn.call(editor)
  9206. }
  9207. }
  9208. }
  9209. }();
  9210. // core/keymap.js
  9211. var keymap = UE.keymap = {
  9212. 'Backspace' : 8,
  9213. 'Tab' : 9,
  9214. 'Enter' : 13,
  9215. 'Shift':16,
  9216. 'Control':17,
  9217. 'Alt':18,
  9218. 'CapsLock':20,
  9219. 'Esc':27,
  9220. 'Spacebar':32,
  9221. 'PageUp':33,
  9222. 'PageDown':34,
  9223. 'End':35,
  9224. 'Home':36,
  9225. 'Left':37,
  9226. 'Up':38,
  9227. 'Right':39,
  9228. 'Down':40,
  9229. 'Insert':45,
  9230. 'Del':46,
  9231. 'NumLock':144,
  9232. 'Cmd':91,
  9233. '=':187,
  9234. '-':189,
  9235. "b":66,
  9236. 'i':73,
  9237. //回退
  9238. 'z':90,
  9239. 'y':89,
  9240. //粘贴
  9241. 'v' : 86,
  9242. 'x' : 88,
  9243. 's' : 83,
  9244. 'n' : 78
  9245. };
  9246. // core/localstorage.js
  9247. //存储媒介封装
  9248. var LocalStorage = UE.LocalStorage = (function () {
  9249. var storage = window.localStorage || getUserData() || null,
  9250. LOCAL_FILE = 'localStorage';
  9251. return {
  9252. saveLocalData: function (key, data) {
  9253. if (storage && data) {
  9254. storage.setItem(key, data);
  9255. return true;
  9256. }
  9257. return false;
  9258. },
  9259. getLocalData: function (key) {
  9260. if (storage) {
  9261. return storage.getItem(key);
  9262. }
  9263. return null;
  9264. },
  9265. removeItem: function (key) {
  9266. storage && storage.removeItem(key);
  9267. }
  9268. };
  9269. function getUserData() {
  9270. var container = document.createElement("div");
  9271. container.style.display = "none";
  9272. if (!container.addBehavior) {
  9273. return null;
  9274. }
  9275. container.addBehavior("#default#userdata");
  9276. return {
  9277. getItem: function (key) {
  9278. var result = null;
  9279. try {
  9280. document.body.appendChild(container);
  9281. container.load(LOCAL_FILE);
  9282. result = container.getAttribute(key);
  9283. document.body.removeChild(container);
  9284. } catch (e) {
  9285. }
  9286. return result;
  9287. },
  9288. setItem: function (key, value) {
  9289. document.body.appendChild(container);
  9290. container.setAttribute(key, value);
  9291. container.save(LOCAL_FILE);
  9292. document.body.removeChild(container);
  9293. },
  9294. //// 暂时没有用到
  9295. //clear: function () {
  9296. //
  9297. // var expiresTime = new Date();
  9298. // expiresTime.setFullYear(expiresTime.getFullYear() - 1);
  9299. // document.body.appendChild(container);
  9300. // container.expires = expiresTime.toUTCString();
  9301. // container.save(LOCAL_FILE);
  9302. // document.body.removeChild(container);
  9303. //
  9304. //},
  9305. removeItem: function (key) {
  9306. document.body.appendChild(container);
  9307. container.removeAttribute(key);
  9308. container.save(LOCAL_FILE);
  9309. document.body.removeChild(container);
  9310. }
  9311. };
  9312. }
  9313. })();
  9314. (function () {
  9315. var ROOTKEY = 'ueditor_preference';
  9316. UE.Editor.prototype.setPreferences = function(key,value){
  9317. var obj = {};
  9318. if (utils.isString(key)) {
  9319. obj[ key ] = value;
  9320. } else {
  9321. obj = key;
  9322. }
  9323. var data = LocalStorage.getLocalData(ROOTKEY);
  9324. if (data && (data = utils.str2json(data))) {
  9325. utils.extend(data, obj);
  9326. } else {
  9327. data = obj;
  9328. }
  9329. data && LocalStorage.saveLocalData(ROOTKEY, utils.json2str(data));
  9330. };
  9331. UE.Editor.prototype.getPreferences = function(key){
  9332. var data = LocalStorage.getLocalData(ROOTKEY);
  9333. if (data && (data = utils.str2json(data))) {
  9334. return key ? data[key] : data
  9335. }
  9336. return null;
  9337. };
  9338. UE.Editor.prototype.removePreferences = function (key) {
  9339. var data = LocalStorage.getLocalData(ROOTKEY);
  9340. if (data && (data = utils.str2json(data))) {
  9341. data[key] = undefined;
  9342. delete data[key]
  9343. }
  9344. data && LocalStorage.saveLocalData(ROOTKEY, utils.json2str(data));
  9345. };
  9346. })();
  9347. // plugins/defaultfilter.js
  9348. ///import core
  9349. ///plugin 编辑器默认的过滤转换机制
  9350. UE.plugins['defaultfilter'] = function () {
  9351. var me = this;
  9352. me.setOpt({
  9353. 'allowDivTransToP':true,
  9354. 'disabledTableInTable':true
  9355. });
  9356. //默认的过滤处理
  9357. //进入编辑器的内容处理
  9358. me.addInputRule(function (root) {
  9359. var allowDivTransToP = this.options.allowDivTransToP;
  9360. var val;
  9361. function tdParent(node){
  9362. while(node && node.type == 'element'){
  9363. if(node.tagName == 'td'){
  9364. return true;
  9365. }
  9366. node = node.parentNode;
  9367. }
  9368. return false;
  9369. }
  9370. //进行默认的处理
  9371. root.traversal(function (node) {
  9372. if (node.type == 'element') {
  9373. if (!dtd.$cdata[node.tagName] && me.options.autoClearEmptyNode && dtd.$inline[node.tagName] && !dtd.$empty[node.tagName] && (!node.attrs || utils.isEmptyObject(node.attrs))) {
  9374. if (!node.firstChild()) node.parentNode.removeChild(node);
  9375. else if (node.tagName == 'span' && (!node.attrs || utils.isEmptyObject(node.attrs))) {
  9376. node.parentNode.removeChild(node, true)
  9377. }
  9378. return;
  9379. }
  9380. switch (node.tagName) {
  9381. case 'style':
  9382. case 'script':
  9383. node.setAttr({
  9384. cdata_tag: node.tagName,
  9385. cdata_data: (node.innerHTML() || ''),
  9386. '_ue_custom_node_':'true'
  9387. });
  9388. node.tagName = 'div';
  9389. node.innerHTML('');
  9390. break;
  9391. case 'a':
  9392. if (val = node.getAttr('href')) {
  9393. node.setAttr('_href', val)
  9394. }
  9395. break;
  9396. case 'img':
  9397. //todo base64暂时去掉,后边做远程图片上传后,干掉这个
  9398. if (val = node.getAttr('src')) {
  9399. if (/^data:/.test(val)) {
  9400. node.parentNode.removeChild(node);
  9401. break;
  9402. }
  9403. }
  9404. node.setAttr('_src', node.getAttr('src'));
  9405. break;
  9406. case 'span':
  9407. if (browser.webkit && (val = node.getStyle('white-space'))) {
  9408. if (/nowrap|normal/.test(val)) {
  9409. node.setStyle('white-space', '');
  9410. if (me.options.autoClearEmptyNode && utils.isEmptyObject(node.attrs)) {
  9411. node.parentNode.removeChild(node, true)
  9412. }
  9413. }
  9414. }
  9415. val = node.getAttr('id');
  9416. if(val && /^_baidu_bookmark_/i.test(val)){
  9417. node.parentNode.removeChild(node)
  9418. }
  9419. break;
  9420. case 'p':
  9421. if (val = node.getAttr('align')) {
  9422. node.setAttr('align');
  9423. node.setStyle('text-align', val)
  9424. }
  9425. //trace:3431
  9426. // var cssStyle = node.getAttr('style');
  9427. // if (cssStyle) {
  9428. // cssStyle = cssStyle.replace(/(margin|padding)[^;]+/g, '');
  9429. // node.setAttr('style', cssStyle)
  9430. //
  9431. // }
  9432. //p标签不允许嵌套
  9433. utils.each(node.children,function(n){
  9434. if(n.type == 'element' && n.tagName == 'p'){
  9435. var next = n.nextSibling();
  9436. node.parentNode.insertAfter(n,node);
  9437. var last = n;
  9438. while(next){
  9439. var tmp = next.nextSibling();
  9440. node.parentNode.insertAfter(next,last);
  9441. last = next;
  9442. next = tmp;
  9443. }
  9444. return false;
  9445. }
  9446. });
  9447. if (!node.firstChild()) {
  9448. node.innerHTML(browser.ie ? '&nbsp;' : '<br/>')
  9449. }
  9450. break;
  9451. case 'div':
  9452. if(node.getAttr('cdata_tag')){
  9453. break;
  9454. }
  9455. //针对代码这里不处理插入代码的div
  9456. val = node.getAttr('class');
  9457. if(val && /^line number\d+/.test(val)){
  9458. break;
  9459. }
  9460. if(!allowDivTransToP){
  9461. break;
  9462. }
  9463. var tmpNode, p = UE.uNode.createElement('p');
  9464. while (tmpNode = node.firstChild()) {
  9465. if (tmpNode.type == 'text' || !UE.dom.dtd.$block[tmpNode.tagName]) {
  9466. p.appendChild(tmpNode);
  9467. } else {
  9468. if (p.firstChild()) {
  9469. node.parentNode.insertBefore(p, node);
  9470. p = UE.uNode.createElement('p');
  9471. } else {
  9472. node.parentNode.insertBefore(tmpNode, node);
  9473. }
  9474. }
  9475. }
  9476. if (p.firstChild()) {
  9477. node.parentNode.insertBefore(p, node);
  9478. }
  9479. node.parentNode.removeChild(node);
  9480. break;
  9481. case 'dl':
  9482. node.tagName = 'ul';
  9483. break;
  9484. case 'dt':
  9485. case 'dd':
  9486. node.tagName = 'li';
  9487. break;
  9488. case 'li':
  9489. var className = node.getAttr('class');
  9490. if (!className || !/list\-/.test(className)) {
  9491. node.setAttr()
  9492. }
  9493. var tmpNodes = node.getNodesByTagName('ol ul');
  9494. UE.utils.each(tmpNodes, function (n) {
  9495. node.parentNode.insertAfter(n, node);
  9496. });
  9497. break;
  9498. case 'td':
  9499. case 'th':
  9500. case 'caption':
  9501. if(!node.children || !node.children.length){
  9502. node.appendChild(browser.ie11below ? UE.uNode.createText(' ') : UE.uNode.createElement('br'))
  9503. }
  9504. break;
  9505. case 'table':
  9506. if(me.options.disabledTableInTable && tdParent(node)){
  9507. node.parentNode.insertBefore(UE.uNode.createText(node.innerText()),node);
  9508. node.parentNode.removeChild(node)
  9509. }
  9510. }
  9511. }
  9512. // if(node.type == 'comment'){
  9513. // node.parentNode.removeChild(node);
  9514. // }
  9515. })
  9516. });
  9517. //从编辑器出去的内容处理
  9518. me.addOutputRule(function (root) {
  9519. var val;
  9520. root.traversal(function (node) {
  9521. if (node.type == 'element') {
  9522. if (me.options.autoClearEmptyNode && dtd.$inline[node.tagName] && !dtd.$empty[node.tagName] && (!node.attrs || utils.isEmptyObject(node.attrs))) {
  9523. if (!node.firstChild()) node.parentNode.removeChild(node);
  9524. else if (node.tagName == 'span' && (!node.attrs || utils.isEmptyObject(node.attrs))) {
  9525. node.parentNode.removeChild(node, true)
  9526. }
  9527. return;
  9528. }
  9529. switch (node.tagName) {
  9530. case 'div':
  9531. if (val = node.getAttr('cdata_tag')) {
  9532. node.tagName = val;
  9533. node.appendChild(UE.uNode.createText(node.getAttr('cdata_data')));
  9534. node.setAttr({cdata_tag: '', cdata_data: '','_ue_custom_node_':''});
  9535. }
  9536. break;
  9537. case 'a':
  9538. if (val = node.getAttr('_href')) {
  9539. node.setAttr({
  9540. 'href': utils.html(val),
  9541. '_href': ''
  9542. })
  9543. }
  9544. break;
  9545. break;
  9546. case 'span':
  9547. val = node.getAttr('id');
  9548. if(val && /^_baidu_bookmark_/i.test(val)){
  9549. node.parentNode.removeChild(node)
  9550. }
  9551. break;
  9552. case 'img':
  9553. if (val = node.getAttr('_src')) {
  9554. node.setAttr({
  9555. 'src': node.getAttr('_src'),
  9556. '_src': ''
  9557. })
  9558. }
  9559. }
  9560. }
  9561. })
  9562. });
  9563. };
  9564. // plugins/inserthtml.js
  9565. /**
  9566. * 插入html字符串插件
  9567. * @file
  9568. * @since 1.2.6.1
  9569. */
  9570. /**
  9571. * 插入html代码
  9572. * @command inserthtml
  9573. * @method execCommand
  9574. * @param { String } cmd 命令字符串
  9575. * @param { String } html 插入的html字符串
  9576. * @remaind 插入的标签内容是在当前的选区位置上插入,如果当前是闭合状态,那直接插入内容, 如果当前是选中状态,将先清除当前选中内容后,再做插入
  9577. * @warning 注意:该命令会对当前选区的位置,对插入的内容进行过滤转换处理。 过滤的规则遵循html语意化的原则。
  9578. * @example
  9579. * ```javascript
  9580. * //xxx[BB]xxx 当前选区为非闭合选区,选中BB这两个文本
  9581. * //执行命令,插入<b>CC</b>
  9582. * //插入后的效果 xxx<b>CC</b>xxx
  9583. * //<p>xx|xxx</p> 当前选区为闭合状态
  9584. * //插入<p>CC</p>
  9585. * //结果 <p>xx</p><p>CC</p><p>xxx</p>
  9586. * //<p>xxxx</p>|</p>xxx</p> 当前选区在两个p标签之间
  9587. * //插入 xxxx
  9588. * //结果 <p>xxxx</p><p>xxxx</p></p>xxx</p>
  9589. * ```
  9590. */
  9591. UE.commands['inserthtml'] = {
  9592. execCommand: function (command,html,notNeedFilter){
  9593. var me = this,
  9594. range,
  9595. div;
  9596. if(!html){
  9597. return;
  9598. }
  9599. if(me.fireEvent('beforeinserthtml',html) === true){
  9600. return;
  9601. }
  9602. range = me.selection.getRange();
  9603. div = range.document.createElement( 'div' );
  9604. div.style.display = 'inline';
  9605. if (!notNeedFilter) {
  9606. var root = UE.htmlparser(html);
  9607. //如果给了过滤规则就先进行过滤
  9608. if(me.options.filterRules){
  9609. UE.filterNode(root,me.options.filterRules);
  9610. }
  9611. //执行默认的处理
  9612. me.filterInputRule(root);
  9613. html = root.toHtml()
  9614. }
  9615. div.innerHTML = utils.trim( html );
  9616. if ( !range.collapsed ) {
  9617. var tmpNode = range.startContainer;
  9618. if(domUtils.isFillChar(tmpNode)){
  9619. range.setStartBefore(tmpNode)
  9620. }
  9621. tmpNode = range.endContainer;
  9622. if(domUtils.isFillChar(tmpNode)){
  9623. range.setEndAfter(tmpNode)
  9624. }
  9625. range.txtToElmBoundary();
  9626. //结束边界可能放到了br的前边,要把br包含进来
  9627. // x[xxx]<br/>
  9628. if(range.endContainer && range.endContainer.nodeType == 1){
  9629. tmpNode = range.endContainer.childNodes[range.endOffset];
  9630. if(tmpNode && domUtils.isBr(tmpNode)){
  9631. range.setEndAfter(tmpNode);
  9632. }
  9633. }
  9634. if(range.startOffset == 0){
  9635. tmpNode = range.startContainer;
  9636. if(domUtils.isBoundaryNode(tmpNode,'firstChild') ){
  9637. tmpNode = range.endContainer;
  9638. if(range.endOffset == (tmpNode.nodeType == 3 ? tmpNode.nodeValue.length : tmpNode.childNodes.length) && domUtils.isBoundaryNode(tmpNode,'lastChild')){
  9639. me.body.innerHTML = '<p>'+(browser.ie ? '' : '<br/>')+'</p>';
  9640. range.setStart(me.body.firstChild,0).collapse(true)
  9641. }
  9642. }
  9643. }
  9644. !range.collapsed && range.deleteContents();
  9645. if(range.startContainer.nodeType == 1){
  9646. var child = range.startContainer.childNodes[range.startOffset],pre;
  9647. if(child && domUtils.isBlockElm(child) && (pre = child.previousSibling) && domUtils.isBlockElm(pre)){
  9648. range.setEnd(pre,pre.childNodes.length).collapse();
  9649. while(child.firstChild){
  9650. pre.appendChild(child.firstChild);
  9651. }
  9652. domUtils.remove(child);
  9653. }
  9654. }
  9655. }
  9656. var child,parent,pre,tmp,hadBreak = 0, nextNode;
  9657. //如果当前位置选中了fillchar要干掉,要不会产生空行
  9658. if(range.inFillChar()){
  9659. child = range.startContainer;
  9660. if(domUtils.isFillChar(child)){
  9661. range.setStartBefore(child).collapse(true);
  9662. domUtils.remove(child);
  9663. }else if(domUtils.isFillChar(child,true)){
  9664. child.nodeValue = child.nodeValue.replace(fillCharReg,'');
  9665. range.startOffset--;
  9666. range.collapsed && range.collapse(true)
  9667. }
  9668. }
  9669. //列表单独处理
  9670. var li = domUtils.findParentByTagName(range.startContainer,'li',true);
  9671. if(li){
  9672. var next,last;
  9673. while(child = div.firstChild){
  9674. //针对hr单独处理一下先
  9675. while(child && (child.nodeType == 3 || !domUtils.isBlockElm(child) || child.tagName=='HR' )){
  9676. next = child.nextSibling;
  9677. range.insertNode( child).collapse();
  9678. last = child;
  9679. child = next;
  9680. }
  9681. if(child){
  9682. if(/^(ol|ul)$/i.test(child.tagName)){
  9683. while(child.firstChild){
  9684. last = child.firstChild;
  9685. domUtils.insertAfter(li,child.firstChild);
  9686. li = li.nextSibling;
  9687. }
  9688. domUtils.remove(child)
  9689. }else{
  9690. var tmpLi;
  9691. next = child.nextSibling;
  9692. tmpLi = me.document.createElement('li');
  9693. domUtils.insertAfter(li,tmpLi);
  9694. tmpLi.appendChild(child);
  9695. last = child;
  9696. child = next;
  9697. li = tmpLi;
  9698. }
  9699. }
  9700. }
  9701. li = domUtils.findParentByTagName(range.startContainer,'li',true);
  9702. if(domUtils.isEmptyBlock(li)){
  9703. domUtils.remove(li)
  9704. }
  9705. if(last){
  9706. range.setStartAfter(last).collapse(true).select(true)
  9707. }
  9708. }else{
  9709. while ( child = div.firstChild ) {
  9710. if(hadBreak){
  9711. var p = me.document.createElement('p');
  9712. while(child && (child.nodeType == 3 || !dtd.$block[child.tagName])){
  9713. nextNode = child.nextSibling;
  9714. p.appendChild(child);
  9715. child = nextNode;
  9716. }
  9717. if(p.firstChild){
  9718. child = p
  9719. }
  9720. }
  9721. range.insertNode( child );
  9722. nextNode = child.nextSibling;
  9723. if ( !hadBreak && child.nodeType == domUtils.NODE_ELEMENT && domUtils.isBlockElm( child ) ){
  9724. parent = domUtils.findParent( child,function ( node ){ return domUtils.isBlockElm( node ); } );
  9725. if ( parent && parent.tagName.toLowerCase() != 'body' && !(dtd[parent.tagName][child.nodeName] && child.parentNode === parent)){
  9726. if(!dtd[parent.tagName][child.nodeName]){
  9727. pre = parent;
  9728. }else{
  9729. tmp = child.parentNode;
  9730. while (tmp !== parent){
  9731. pre = tmp;
  9732. tmp = tmp.parentNode;
  9733. }
  9734. }
  9735. domUtils.breakParent( child, pre || tmp );
  9736. //去掉break后前一个多余的节点 <p>|<[p> ==> <p></p><div></div><p>|</p>
  9737. var pre = child.previousSibling;
  9738. domUtils.trimWhiteTextNode(pre);
  9739. if(!pre.childNodes.length){
  9740. domUtils.remove(pre);
  9741. }
  9742. //trace:2012,在非ie的情况,切开后剩下的节点有可能不能点入光标添加br占位
  9743. if(!browser.ie &&
  9744. (next = child.nextSibling) &&
  9745. domUtils.isBlockElm(next) &&
  9746. next.lastChild &&
  9747. !domUtils.isBr(next.lastChild)){
  9748. next.appendChild(me.document.createElement('br'));
  9749. }
  9750. hadBreak = 1;
  9751. }
  9752. }
  9753. var next = child.nextSibling;
  9754. if(!div.firstChild && next && domUtils.isBlockElm(next)){
  9755. range.setStart(next,0).collapse(true);
  9756. break;
  9757. }
  9758. range.setEndAfter( child ).collapse();
  9759. }
  9760. child = range.startContainer;
  9761. if(nextNode && domUtils.isBr(nextNode)){
  9762. domUtils.remove(nextNode)
  9763. }
  9764. //用chrome可能有空白展位符
  9765. if(domUtils.isBlockElm(child) && domUtils.isEmptyNode(child)){
  9766. if(nextNode = child.nextSibling){
  9767. domUtils.remove(child);
  9768. if(nextNode.nodeType == 1 && dtd.$block[nextNode.tagName]){
  9769. range.setStart(nextNode,0).collapse(true).shrinkBoundary()
  9770. }
  9771. }else{
  9772. try{
  9773. child.innerHTML = browser.ie ? domUtils.fillChar : '<br/>';
  9774. }catch(e){
  9775. range.setStartBefore(child);
  9776. domUtils.remove(child)
  9777. }
  9778. }
  9779. }
  9780. //加上true因为在删除表情等时会删两次,第一次是删的fillData
  9781. try{
  9782. range.select(true);
  9783. }catch(e){}
  9784. }
  9785. setTimeout(function(){
  9786. range = me.selection.getRange();
  9787. range.scrollToView(me.autoHeightEnabled,me.autoHeightEnabled ? domUtils.getXY(me.iframe).y:0);
  9788. me.fireEvent('afterinserthtml', html);
  9789. },200);
  9790. }
  9791. };
  9792. // plugins/autotypeset.js
  9793. /**
  9794. * 自动排版
  9795. * @file
  9796. * @since 1.2.6.1
  9797. */
  9798. /**
  9799. * 对当前编辑器的内容执行自动排版, 排版的行为根据config配置文件里的“autotypeset”选项进行控制。
  9800. * @command autotypeset
  9801. * @method execCommand
  9802. * @param { String } cmd 命令字符串
  9803. * @example
  9804. * ```javascript
  9805. * editor.execCommand( 'autotypeset' );
  9806. * ```
  9807. */
  9808. UE.plugins['autotypeset'] = function(){
  9809. this.setOpt({'autotypeset': {
  9810. mergeEmptyline: true, //合并空行
  9811. removeClass: true, //去掉冗余的class
  9812. removeEmptyline: false, //去掉空行
  9813. textAlign:"left", //段落的排版方式,可以是 left,right,center,justify 去掉这个属性表示不执行排版
  9814. imageBlockLine: 'center', //图片的浮动方式,独占一行剧中,左右浮动,默认: center,left,right,none 去掉这个属性表示不执行排版
  9815. pasteFilter: false, //根据规则过滤没事粘贴进来的内容
  9816. clearFontSize: false, //去掉所有的内嵌字号,使用编辑器默认的字号
  9817. clearFontFamily: false, //去掉所有的内嵌字体,使用编辑器默认的字体
  9818. removeEmptyNode: false, // 去掉空节点
  9819. //可以去掉的标签
  9820. removeTagNames: utils.extend({div:1},dtd.$removeEmpty),
  9821. indent: false, // 行首缩进
  9822. indentValue : '2em', //行首缩进的大小
  9823. bdc2sb: false,
  9824. tobdc: false
  9825. }});
  9826. var me = this,
  9827. opt = me.options.autotypeset,
  9828. remainClass = {
  9829. 'selectTdClass':1,
  9830. 'pagebreak':1,
  9831. 'anchorclass':1
  9832. },
  9833. remainTag = {
  9834. 'li':1
  9835. },
  9836. tags = {
  9837. div:1,
  9838. p:1,
  9839. //trace:2183 这些也认为是行
  9840. blockquote:1,center:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,
  9841. span:1
  9842. },
  9843. highlightCont;
  9844. //升级了版本,但配置项目里没有autotypeset
  9845. if(!opt){
  9846. return;
  9847. }
  9848. readLocalOpts();
  9849. function isLine(node,notEmpty){
  9850. if(!node || node.nodeType == 3)
  9851. return 0;
  9852. if(domUtils.isBr(node))
  9853. return 1;
  9854. if(node && node.parentNode && tags[node.tagName.toLowerCase()]){
  9855. if(highlightCont && highlightCont.contains(node)
  9856. ||
  9857. node.getAttribute('pagebreak')
  9858. ){
  9859. return 0;
  9860. }
  9861. return notEmpty ? !domUtils.isEmptyBlock(node) : domUtils.isEmptyBlock(node,new RegExp('[\\s'+domUtils.fillChar
  9862. +']','g'));
  9863. }
  9864. }
  9865. function removeNotAttributeSpan(node){
  9866. if(!node.style.cssText){
  9867. domUtils.removeAttributes(node,['style']);
  9868. if(node.tagName.toLowerCase() == 'span' && domUtils.hasNoAttributes(node)){
  9869. domUtils.remove(node,true);
  9870. }
  9871. }
  9872. }
  9873. function autotype(type,html){
  9874. var me = this,cont;
  9875. var str=me.getContent();
  9876. str=str.replace(/style\s*?=\s*?([‘"])[\s\S]*?\1/ig,'');
  9877. str=str.replace(/class\s*?=\s*?([‘"])[\s\S]*?\1/ig,'');
  9878. str=str.replace(/width\s*?=\s*?([‘"])[\s\S]*?\1/ig,'');
  9879. str=str.replace(/<\/?strong[^>]*>/g,'');
  9880. str=str.replace(/&nbsp;/g,' ');
  9881. // var reg = /<\s*\/?\s*[^>]*\s*>/gi;
  9882. // console.log(str);
  9883. me.setContent(str);
  9884. return ;
  9885. var me = this,cont;
  9886. if(html){
  9887. if(!opt.pasteFilter){
  9888. return;
  9889. }
  9890. cont = me.document.createElement('div');
  9891. cont.innerHTML = html.html;
  9892. }else{
  9893. cont = me.document.body;
  9894. }
  9895. var nodes = domUtils.getElementsByTagName(cont,'*');
  9896. // 行首缩进,段落方向,段间距,段内间距
  9897. for(var i=0,ci;ci=nodes[i++];){
  9898. if(me.fireEvent('excludeNodeinautotype',ci) === true){
  9899. continue;
  9900. }
  9901. //font-size
  9902. if(opt.clearFontSize && ci.style.fontSize){
  9903. domUtils.removeStyle(ci,'font-size');
  9904. removeNotAttributeSpan(ci);
  9905. }
  9906. //font-family
  9907. if(opt.clearFontFamily && ci.style.fontFamily){
  9908. domUtils.removeStyle(ci,'font-family');
  9909. removeNotAttributeSpan(ci);
  9910. }
  9911. if(isLine(ci)){
  9912. //合并空行
  9913. if(opt.mergeEmptyline ){
  9914. var next = ci.nextSibling,tmpNode,isBr = domUtils.isBr(ci);
  9915. while(isLine(next)){
  9916. tmpNode = next;
  9917. next = tmpNode.nextSibling;
  9918. if(isBr && (!next || next && !domUtils.isBr(next))){
  9919. break;
  9920. }
  9921. domUtils.remove(tmpNode);
  9922. }
  9923. }
  9924. //去掉空行,保留占位的空行
  9925. if(opt.removeEmptyline && domUtils.inDoc(ci,cont) && !remainTag[ci.parentNode.tagName.toLowerCase()] ){
  9926. if(domUtils.isBr(ci)){
  9927. next = ci.nextSibling;
  9928. if(next && !domUtils.isBr(next)){
  9929. continue;
  9930. }
  9931. }
  9932. domUtils.remove(ci);
  9933. continue;
  9934. }
  9935. }
  9936. if(isLine(ci,true) && ci.tagName != 'SPAN'){
  9937. if(opt.indent){
  9938. ci.style.textIndent = opt.indentValue;
  9939. }
  9940. if(opt.textAlign){
  9941. ci.style.textAlign = opt.textAlign;
  9942. }
  9943. // if(opt.lineHeight)
  9944. // ci.style.lineHeight = opt.lineHeight + 'cm';
  9945. }
  9946. //去掉class,保留的class不去掉
  9947. if(opt.removeClass && ci.className && !remainClass[ci.className.toLowerCase()]){
  9948. if(highlightCont && highlightCont.contains(ci)){
  9949. continue;
  9950. }
  9951. domUtils.removeAttributes(ci,['class']);
  9952. }
  9953. //表情不处理
  9954. if(opt.imageBlockLine && ci.tagName.toLowerCase() == 'img' && !ci.getAttribute('emotion')){
  9955. if(html){
  9956. var img = ci;
  9957. switch (opt.imageBlockLine){
  9958. case 'left':
  9959. case 'right':
  9960. case 'none':
  9961. var pN = img.parentNode,tmpNode,pre,next;
  9962. while(dtd.$inline[pN.tagName] || pN.tagName == 'A'){
  9963. pN = pN.parentNode;
  9964. }
  9965. tmpNode = pN;
  9966. if(tmpNode.tagName == 'P' && domUtils.getStyle(tmpNode,'text-align') == 'center'){
  9967. if(!domUtils.isBody(tmpNode) && domUtils.getChildCount(tmpNode,function(node){return !domUtils.isBr(node) && !domUtils.isWhitespace(node)}) == 1){
  9968. pre = tmpNode.previousSibling;
  9969. next = tmpNode.nextSibling;
  9970. if(pre && next && pre.nodeType == 1 && next.nodeType == 1 && pre.tagName == next.tagName && domUtils.isBlockElm(pre)){
  9971. pre.appendChild(tmpNode.firstChild);
  9972. while(next.firstChild){
  9973. pre.appendChild(next.firstChild);
  9974. }
  9975. domUtils.remove(tmpNode);
  9976. domUtils.remove(next);
  9977. }else{
  9978. domUtils.setStyle(tmpNode,'text-align','');
  9979. }
  9980. }
  9981. }
  9982. domUtils.setStyle(img,'float', opt.imageBlockLine);
  9983. break;
  9984. case 'center':
  9985. if(me.queryCommandValue('imagefloat') != 'center'){
  9986. pN = img.parentNode;
  9987. domUtils.setStyle(img,'float','none');
  9988. tmpNode = img;
  9989. while(pN && domUtils.getChildCount(pN,function(node){return !domUtils.isBr(node) && !domUtils.isWhitespace(node)}) == 1
  9990. && (dtd.$inline[pN.tagName] || pN.tagName == 'A')){
  9991. tmpNode = pN;
  9992. pN = pN.parentNode;
  9993. }
  9994. var pNode = me.document.createElement('p');
  9995. domUtils.setAttributes(pNode,{
  9996. style:'text-align:center'
  9997. });
  9998. tmpNode.parentNode.insertBefore(pNode,tmpNode);
  9999. pNode.appendChild(tmpNode);
  10000. domUtils.setStyle(tmpNode,'float','');
  10001. }
  10002. }
  10003. } else {
  10004. var range = me.selection.getRange();
  10005. range.selectNode(ci).select();
  10006. me.execCommand('imagefloat', opt.imageBlockLine);
  10007. }
  10008. }
  10009. //去掉冗余的标签
  10010. if(opt.removeEmptyNode){
  10011. if(opt.removeTagNames[ci.tagName.toLowerCase()] && domUtils.hasNoAttributes(ci) && domUtils.isEmptyBlock(ci)){
  10012. domUtils.remove(ci);
  10013. }
  10014. }
  10015. }
  10016. if(opt.tobdc){
  10017. var root = UE.htmlparser(cont.innerHTML);
  10018. root.traversal(function(node){
  10019. if(node.type == 'text'){
  10020. node.data = ToDBC(node.data)
  10021. }
  10022. });
  10023. cont.innerHTML = root.toHtml()
  10024. }
  10025. if(opt.bdc2sb){
  10026. var root = UE.htmlparser(cont.innerHTML);
  10027. root.traversal(function(node){
  10028. if(node.type == 'text'){
  10029. node.data = DBC2SB(node.data)
  10030. }
  10031. });
  10032. cont.innerHTML = root.toHtml()
  10033. }
  10034. if(html){
  10035. html.html = cont.innerHTML;
  10036. }
  10037. }
  10038. if(opt.pasteFilter){
  10039. me.addListener('beforepaste',autotype);
  10040. }
  10041. function DBC2SB(str) {
  10042. var result = '';
  10043. for (var i = 0; i < str.length; i++) {
  10044. var code = str.charCodeAt(i); //获取当前字符的unicode编码
  10045. if (code >= 65281 && code <= 65373)//在这个unicode编码范围中的是所有的英文字母已经各种字符
  10046. {
  10047. result += String.fromCharCode(str.charCodeAt(i) - 65248); //把全角字符的unicode编码转换为对应半角字符的unicode码
  10048. } else if (code == 12288)//空格
  10049. {
  10050. result += String.fromCharCode(str.charCodeAt(i) - 12288 + 32);
  10051. } else {
  10052. result += str.charAt(i);
  10053. }
  10054. }
  10055. return result;
  10056. }
  10057. function ToDBC(txtstring) {
  10058. txtstring = utils.html(txtstring);
  10059. var tmp = "";
  10060. var mark = "";/*用于判断,如果是html尖括里的标记,则不进行全角的转换*/
  10061. for (var i = 0; i < txtstring.length; i++) {
  10062. if (txtstring.charCodeAt(i) == 32) {
  10063. tmp = tmp + String.fromCharCode(12288);
  10064. }
  10065. else if (txtstring.charCodeAt(i) < 127) {
  10066. tmp = tmp + String.fromCharCode(txtstring.charCodeAt(i) + 65248);
  10067. }
  10068. else {
  10069. tmp += txtstring.charAt(i);
  10070. }
  10071. }
  10072. return tmp;
  10073. }
  10074. function readLocalOpts() {
  10075. var cookieOpt = me.getPreferences('autotypeset');
  10076. utils.extend(me.options.autotypeset, cookieOpt);
  10077. }
  10078. me.commands['autotypeset'] = {
  10079. execCommand:function () {
  10080. me.removeListener('beforepaste',autotype);
  10081. if(opt.pasteFilter){
  10082. me.addListener('beforepaste',autotype);
  10083. }
  10084. autotype.call(me)
  10085. }
  10086. };
  10087. };
  10088. // plugins/autosubmit.js
  10089. /**
  10090. * 快捷键提交
  10091. * @file
  10092. * @since 1.2.6.1
  10093. */
  10094. /**
  10095. * 提交表单
  10096. * @command autosubmit
  10097. * @method execCommand
  10098. * @param { String } cmd 命令字符串
  10099. * @example
  10100. * ```javascript
  10101. * editor.execCommand( 'autosubmit' );
  10102. * ```
  10103. */
  10104. UE.plugin.register('autosubmit',function(){
  10105. return {
  10106. shortcutkey:{
  10107. "autosubmit":"ctrl+13" //手动提交
  10108. },
  10109. commands:{
  10110. 'autosubmit':{
  10111. execCommand:function () {
  10112. var me=this,
  10113. form = domUtils.findParentByTagName(me.iframe,"form", false);
  10114. if (form){
  10115. if(me.fireEvent("beforesubmit")===false){
  10116. return;
  10117. }
  10118. me.sync();
  10119. form.submit();
  10120. }
  10121. }
  10122. }
  10123. }
  10124. }
  10125. });
  10126. // plugins/background.js
  10127. /**
  10128. * 背景插件,为UEditor提供设置背景功能
  10129. * @file
  10130. * @since 1.2.6.1
  10131. */
  10132. UE.plugin.register('background', function () {
  10133. var me = this,
  10134. cssRuleId = 'editor_background',
  10135. isSetColored,
  10136. reg = new RegExp('body[\\s]*\\{(.+)\\}', 'i');
  10137. function stringToObj(str) {
  10138. var obj = {}, styles = str.split(';');
  10139. utils.each(styles, function (v) {
  10140. var index = v.indexOf(':'),
  10141. key = utils.trim(v.substr(0, index)).toLowerCase();
  10142. key && (obj[key] = utils.trim(v.substr(index + 1) || ''));
  10143. });
  10144. return obj;
  10145. }
  10146. function setBackground(obj) {
  10147. if (obj) {
  10148. var styles = [];
  10149. for (var name in obj) {
  10150. if (obj.hasOwnProperty(name)) {
  10151. styles.push(name + ":" + obj[name] + '; ');
  10152. }
  10153. }
  10154. utils.cssRule(cssRuleId, styles.length ? ('body{' + styles.join("") + '}') : '', me.document);
  10155. } else {
  10156. utils.cssRule(cssRuleId, '', me.document)
  10157. }
  10158. }
  10159. //重写editor.hasContent方法
  10160. var orgFn = me.hasContents;
  10161. me.hasContents = function(){
  10162. if(me.queryCommandValue('background')){
  10163. return true
  10164. }
  10165. return orgFn.apply(me,arguments);
  10166. };
  10167. return {
  10168. bindEvents: {
  10169. 'getAllHtml': function (type, headHtml) {
  10170. var body = this.body,
  10171. su = domUtils.getComputedStyle(body, "background-image"),
  10172. url = "";
  10173. if (su.indexOf(me.options.imagePath) > 0) {
  10174. url = su.substring(su.indexOf(me.options.imagePath), su.length - 1).replace(/"|\(|\)/ig, "");
  10175. } else {
  10176. url = su != "none" ? su.replace(/url\("?|"?\)/ig, "") : "";
  10177. }
  10178. var html = '<style type="text/css">body{';
  10179. var bgObj = {
  10180. "background-color": domUtils.getComputedStyle(body, "background-color") || "#ffffff",
  10181. 'background-image': url ? 'url(' + url + ')' : '',
  10182. 'background-repeat': domUtils.getComputedStyle(body, "background-repeat") || "",
  10183. 'background-position': browser.ie ? (domUtils.getComputedStyle(body, "background-position-x") + " " + domUtils.getComputedStyle(body, "background-position-y")) : domUtils.getComputedStyle(body, "background-position"),
  10184. 'height': domUtils.getComputedStyle(body, "height")
  10185. };
  10186. for (var name in bgObj) {
  10187. if (bgObj.hasOwnProperty(name)) {
  10188. html += name + ":" + bgObj[name] + "; ";
  10189. }
  10190. }
  10191. html += '}</style> ';
  10192. headHtml.push(html);
  10193. },
  10194. 'aftersetcontent': function () {
  10195. if(isSetColored == false) setBackground();
  10196. }
  10197. },
  10198. inputRule: function (root) {
  10199. isSetColored = false;
  10200. utils.each(root.getNodesByTagName('p'), function (p) {
  10201. var styles = p.getAttr('data-background');
  10202. if (styles) {
  10203. isSetColored = true;
  10204. setBackground(stringToObj(styles));
  10205. p.parentNode.removeChild(p);
  10206. }
  10207. })
  10208. },
  10209. outputRule: function (root) {
  10210. var me = this,
  10211. styles = (utils.cssRule(cssRuleId, me.document) || '').replace(/[\n\r]+/g, '').match(reg);
  10212. if (styles) {
  10213. root.appendChild(UE.uNode.createElement('<p style="display:none;" data-background="' + utils.trim(styles[1].replace(/"/g, '').replace(/[\s]+/g, ' ')) + '"><br/></p>'));
  10214. }
  10215. },
  10216. commands: {
  10217. 'background': {
  10218. execCommand: function (cmd, obj) {
  10219. setBackground(obj);
  10220. },
  10221. queryCommandValue: function () {
  10222. var me = this,
  10223. styles = (utils.cssRule(cssRuleId, me.document) || '').replace(/[\n\r]+/g, '').match(reg);
  10224. return styles ? stringToObj(styles[1]) : null;
  10225. },
  10226. notNeedUndo: true
  10227. }
  10228. }
  10229. }
  10230. });
  10231. // plugins/image.js
  10232. /**
  10233. * 图片插入、排版插件
  10234. * @file
  10235. * @since 1.2.6.1
  10236. */
  10237. /**
  10238. * 图片对齐方式
  10239. * @command imagefloat
  10240. * @method execCommand
  10241. * @remind 值center为独占一行居中
  10242. * @param { String } cmd 命令字符串
  10243. * @param { String } align 对齐方式,可传left、right、none、center
  10244. * @remaind center表示图片独占一行
  10245. * @example
  10246. * ```javascript
  10247. * editor.execCommand( 'imagefloat', 'center' );
  10248. * ```
  10249. */
  10250. /**
  10251. * 如果选区所在位置是图片区域
  10252. * @command imagefloat
  10253. * @method queryCommandValue
  10254. * @param { String } cmd 命令字符串
  10255. * @return { String } 返回图片对齐方式
  10256. * @example
  10257. * ```javascript
  10258. * editor.queryCommandValue( 'imagefloat' );
  10259. * ```
  10260. */
  10261. UE.commands['imagefloat'] = {
  10262. execCommand:function (cmd, align) {
  10263. var me = this,
  10264. range = me.selection.getRange();
  10265. if (!range.collapsed) {
  10266. var img = range.getClosedNode();
  10267. if (img && img.tagName == 'IMG') {
  10268. switch (align) {
  10269. case 'left':
  10270. case 'right':
  10271. case 'none':
  10272. var pN = img.parentNode, tmpNode, pre, next;
  10273. while (dtd.$inline[pN.tagName] || pN.tagName == 'A') {
  10274. pN = pN.parentNode;
  10275. }
  10276. tmpNode = pN;
  10277. if (tmpNode.tagName == 'P' && domUtils.getStyle(tmpNode, 'text-align') == 'center') {
  10278. if (!domUtils.isBody(tmpNode) && domUtils.getChildCount(tmpNode, function (node) {
  10279. return !domUtils.isBr(node) && !domUtils.isWhitespace(node);
  10280. }) == 1) {
  10281. pre = tmpNode.previousSibling;
  10282. next = tmpNode.nextSibling;
  10283. if (pre && next && pre.nodeType == 1 && next.nodeType == 1 && pre.tagName == next.tagName && domUtils.isBlockElm(pre)) {
  10284. pre.appendChild(tmpNode.firstChild);
  10285. while (next.firstChild) {
  10286. pre.appendChild(next.firstChild);
  10287. }
  10288. domUtils.remove(tmpNode);
  10289. domUtils.remove(next);
  10290. } else {
  10291. domUtils.setStyle(tmpNode, 'text-align', '');
  10292. }
  10293. }
  10294. range.selectNode(img).select();
  10295. }
  10296. domUtils.setStyle(img, 'float', align == 'none' ? '' : align);
  10297. if(align == 'none'){
  10298. domUtils.removeAttributes(img,'align');
  10299. }
  10300. break;
  10301. case 'center':
  10302. if (me.queryCommandValue('imagefloat') != 'center') {
  10303. pN = img.parentNode;
  10304. domUtils.setStyle(img, 'float', '');
  10305. domUtils.removeAttributes(img,'align');
  10306. tmpNode = img;
  10307. while (pN && domUtils.getChildCount(pN, function (node) {
  10308. return !domUtils.isBr(node) && !domUtils.isWhitespace(node);
  10309. }) == 1
  10310. && (dtd.$inline[pN.tagName] || pN.tagName == 'A')) {
  10311. tmpNode = pN;
  10312. pN = pN.parentNode;
  10313. }
  10314. range.setStartBefore(tmpNode).setCursor(false);
  10315. pN = me.document.createElement('div');
  10316. pN.appendChild(tmpNode);
  10317. domUtils.setStyle(tmpNode, 'float', '');
  10318. me.execCommand('insertHtml', '<p id="_img_parent_tmp" style="text-align:center">' + pN.innerHTML + '</p>');
  10319. tmpNode = me.document.getElementById('_img_parent_tmp');
  10320. tmpNode.removeAttribute('id');
  10321. tmpNode = tmpNode.firstChild;
  10322. range.selectNode(tmpNode).select();
  10323. //去掉后边多余的元素
  10324. next = tmpNode.parentNode.nextSibling;
  10325. if (next && domUtils.isEmptyNode(next)) {
  10326. domUtils.remove(next);
  10327. }
  10328. }
  10329. break;
  10330. }
  10331. }
  10332. }
  10333. },
  10334. queryCommandValue:function () {
  10335. var range = this.selection.getRange(),
  10336. startNode, floatStyle;
  10337. if (range.collapsed) {
  10338. return 'none';
  10339. }
  10340. startNode = range.getClosedNode();
  10341. if (startNode && startNode.nodeType == 1 && startNode.tagName == 'IMG') {
  10342. floatStyle = domUtils.getComputedStyle(startNode, 'float') || startNode.getAttribute('align');
  10343. if (floatStyle == 'none') {
  10344. floatStyle = domUtils.getComputedStyle(startNode.parentNode, 'text-align') == 'center' ? 'center' : floatStyle;
  10345. }
  10346. return {
  10347. left:1,
  10348. right:1,
  10349. center:1
  10350. }[floatStyle] ? floatStyle : 'none';
  10351. }
  10352. return 'none';
  10353. },
  10354. queryCommandState:function () {
  10355. var range = this.selection.getRange(),
  10356. startNode;
  10357. if (range.collapsed) return -1;
  10358. startNode = range.getClosedNode();
  10359. if (startNode && startNode.nodeType == 1 && startNode.tagName == 'IMG') {
  10360. return 0;
  10361. }
  10362. return -1;
  10363. }
  10364. };
  10365. /**
  10366. * 插入图片
  10367. * @command insertimage
  10368. * @method execCommand
  10369. * @param { String } cmd 命令字符串
  10370. * @param { Object } opt 属性键值对,这些属性都将被复制到当前插入图片
  10371. * @remind 该命令第二个参数可接受一个图片配置项对象的数组,可以插入多张图片,
  10372. * 此时数组的每一个元素都是一个Object类型的图片属性集合。
  10373. * @example
  10374. * ```javascript
  10375. * editor.execCommand( 'insertimage', {
  10376. * src:'a/b/c.jpg',
  10377. * width:'100',
  10378. * height:'100'
  10379. * } );
  10380. * ```
  10381. * @example
  10382. * ```javascript
  10383. * editor.execCommand( 'insertimage', [{
  10384. * src:'a/b/c.jpg',
  10385. * width:'100',
  10386. * height:'100'
  10387. * },{
  10388. * src:'a/b/d.jpg',
  10389. * width:'100',
  10390. * height:'100'
  10391. * }] );
  10392. * ```
  10393. */
  10394. UE.commands['insertimage'] = {
  10395. execCommand:function (cmd, opt) {
  10396. opt = utils.isArray(opt) ? opt : [opt];
  10397. if (!opt.length) {
  10398. return;
  10399. }
  10400. var me = this,
  10401. range = me.selection.getRange(),
  10402. img = range.getClosedNode();
  10403. if(me.fireEvent('beforeinsertimage', opt) === true){
  10404. return;
  10405. }
  10406. if (img && /img/i.test(img.tagName) && (img.className != "edui-faked-video" || img.className.indexOf("edui-upload-video")!=-1) && !img.getAttribute("word_img")) {
  10407. var first = opt.shift();
  10408. var floatStyle = first['floatStyle'];
  10409. delete first['floatStyle'];
  10410. //// img.style.border = (first.border||0) +"px solid #000";
  10411. //// img.style.margin = (first.margin||0) +"px";
  10412. // img.style.cssText += ';margin:' + (first.margin||0) +"px;" + 'border:' + (first.border||0) +"px solid #000";
  10413. domUtils.setAttributes(img, first);
  10414. me.execCommand('imagefloat', floatStyle);
  10415. if (opt.length > 0) {
  10416. range.setStartAfter(img).setCursor(false, true);
  10417. me.execCommand('insertimage', opt);
  10418. }
  10419. } else {
  10420. var html = [], str = '', ci;
  10421. ci = opt[0];
  10422. if (opt.length == 1) {
  10423. str = '<img src="' + ci.src + '" ' + (ci._src ? ' _src="' + ci._src + '" ' : '') +
  10424. (ci.width ? 'width="' + ci.width + '" ' : '') +
  10425. (ci.height ? ' height="' + ci.height + '" ' : '') +
  10426. (ci['floatStyle'] == 'left' || ci['floatStyle'] == 'right' ? ' style="float:' + ci['floatStyle'] + ';"' : '') +
  10427. (ci.title && ci.title != "" ? ' title="' + ci.title + '"' : '') +
  10428. (ci.border && ci.border != "0" ? ' border="' + ci.border + '"' : '') +
  10429. (ci.alt && ci.alt != "" ? ' alt="' + ci.alt + '"' : '') +
  10430. (ci.hspace && ci.hspace != "0" ? ' hspace = "' + ci.hspace + '"' : '') +
  10431. (ci.vspace && ci.vspace != "0" ? ' vspace = "' + ci.vspace + '"' : '') + '/>';
  10432. if (ci['floatStyle'] == 'center') {
  10433. str = '<p style="text-align: center">' + str + '</p>';
  10434. }
  10435. html.push(str);
  10436. } else {
  10437. for (var i = 0; ci = opt[i++];) {
  10438. str = '<p ' + (ci['floatStyle'] == 'center' ? 'style="text-align: center" ' : '') + '><img src="' + ci.src + '" ' +
  10439. (ci.width ? 'width="' + ci.width + '" ' : '') + (ci._src ? ' _src="' + ci._src + '" ' : '') +
  10440. (ci.height ? ' height="' + ci.height + '" ' : '') +
  10441. ' style="' + (ci['floatStyle'] && ci['floatStyle'] != 'center' ? 'float:' + ci['floatStyle'] + ';' : '') +
  10442. (ci.border || '') + '" ' +
  10443. (ci.title ? ' title="' + ci.title + '"' : '') + ' /></p>';
  10444. html.push(str);
  10445. }
  10446. }
  10447. me.execCommand('insertHtml', html.join(''));
  10448. }
  10449. me.fireEvent('afterinsertimage', opt)
  10450. }
  10451. };
  10452. // plugins/justify.js
  10453. /**
  10454. * 段落格式
  10455. * @file
  10456. * @since 1.2.6.1
  10457. */
  10458. /**
  10459. * 段落对齐方式
  10460. * @command justify
  10461. * @method execCommand
  10462. * @param { String } cmd 命令字符串
  10463. * @param { String } align 对齐方式:left => 居左,right => 居右,center => 居中,justify => 两端对齐
  10464. * @example
  10465. * ```javascript
  10466. * editor.execCommand( 'justify', 'center' );
  10467. * ```
  10468. */
  10469. /**
  10470. * 如果选区所在位置是段落区域,返回当前段落对齐方式
  10471. * @command justify
  10472. * @method queryCommandValue
  10473. * @param { String } cmd 命令字符串
  10474. * @return { String } 返回段落对齐方式
  10475. * @example
  10476. * ```javascript
  10477. * editor.queryCommandValue( 'justify' );
  10478. * ```
  10479. */
  10480. UE.plugins['justify']=function(){
  10481. var me=this,
  10482. block = domUtils.isBlockElm,
  10483. defaultValue = {
  10484. left:1,
  10485. right:1,
  10486. center:1,
  10487. justify:1
  10488. },
  10489. doJustify = function (range, style) {
  10490. var bookmark = range.createBookmark(),
  10491. filterFn = function (node) {
  10492. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' && !domUtils.isBookmarkNode(node) : !domUtils.isWhitespace(node);
  10493. };
  10494. range.enlarge(true);
  10495. var bookmark2 = range.createBookmark(),
  10496. current = domUtils.getNextDomNode(bookmark2.start, false, filterFn),
  10497. tmpRange = range.cloneRange(),
  10498. tmpNode;
  10499. while (current && !(domUtils.getPosition(current, bookmark2.end) & domUtils.POSITION_FOLLOWING)) {
  10500. if (current.nodeType == 3 || !block(current)) {
  10501. tmpRange.setStartBefore(current);
  10502. while (current && current !== bookmark2.end && !block(current)) {
  10503. tmpNode = current;
  10504. current = domUtils.getNextDomNode(current, false, null, function (node) {
  10505. return !block(node);
  10506. });
  10507. }
  10508. tmpRange.setEndAfter(tmpNode);
  10509. var common = tmpRange.getCommonAncestor();
  10510. if (!domUtils.isBody(common) && block(common)) {
  10511. domUtils.setStyles(common, utils.isString(style) ? {'text-align':style} : style);
  10512. current = common;
  10513. } else {
  10514. var p = range.document.createElement('p');
  10515. domUtils.setStyles(p, utils.isString(style) ? {'text-align':style} : style);
  10516. var frag = tmpRange.extractContents();
  10517. p.appendChild(frag);
  10518. tmpRange.insertNode(p);
  10519. current = p;
  10520. }
  10521. current = domUtils.getNextDomNode(current, false, filterFn);
  10522. } else {
  10523. current = domUtils.getNextDomNode(current, true, filterFn);
  10524. }
  10525. }
  10526. return range.moveToBookmark(bookmark2).moveToBookmark(bookmark);
  10527. };
  10528. UE.commands['justify'] = {
  10529. execCommand:function (cmdName, align) {
  10530. var range = this.selection.getRange(),
  10531. txt;
  10532. //闭合时单独处理
  10533. if (range.collapsed) {
  10534. txt = this.document.createTextNode('p');
  10535. range.insertNode(txt);
  10536. }
  10537. doJustify(range, align);
  10538. if (txt) {
  10539. range.setStartBefore(txt).collapse(true);
  10540. domUtils.remove(txt);
  10541. }
  10542. range.select();
  10543. return true;
  10544. },
  10545. queryCommandValue:function () {
  10546. var startNode = this.selection.getStart(),
  10547. value = domUtils.getComputedStyle(startNode, 'text-align');
  10548. return defaultValue[value] ? value : 'left';
  10549. },
  10550. queryCommandState:function () {
  10551. var start = this.selection.getStart(),
  10552. cell = start && domUtils.findParentByTagName(start, ["td", "th","caption"], true);
  10553. return cell? -1:0;
  10554. }
  10555. };
  10556. };
  10557. // plugins/font.js
  10558. /**
  10559. * 字体颜色,背景色,字号,字体,下划线,删除线
  10560. * @file
  10561. * @since 1.2.6.1
  10562. */
  10563. /**
  10564. * 字体颜色
  10565. * @command forecolor
  10566. * @method execCommand
  10567. * @param { String } cmd 命令字符串
  10568. * @param { String } value 色值(必须十六进制)
  10569. * @example
  10570. * ```javascript
  10571. * editor.execCommand( 'forecolor', '#000' );
  10572. * ```
  10573. */
  10574. /**
  10575. * 返回选区字体颜色
  10576. * @command forecolor
  10577. * @method queryCommandValue
  10578. * @param { String } cmd 命令字符串
  10579. * @return { String } 返回字体颜色
  10580. * @example
  10581. * ```javascript
  10582. * editor.queryCommandValue( 'forecolor' );
  10583. * ```
  10584. */
  10585. /**
  10586. * 字体背景颜色
  10587. * @command backcolor
  10588. * @method execCommand
  10589. * @param { String } cmd 命令字符串
  10590. * @param { String } value 色值(必须十六进制)
  10591. * @example
  10592. * ```javascript
  10593. * editor.execCommand( 'backcolor', '#000' );
  10594. * ```
  10595. */
  10596. /**
  10597. * 返回选区字体颜色
  10598. * @command backcolor
  10599. * @method queryCommandValue
  10600. * @param { String } cmd 命令字符串
  10601. * @return { String } 返回字体背景颜色
  10602. * @example
  10603. * ```javascript
  10604. * editor.queryCommandValue( 'backcolor' );
  10605. * ```
  10606. */
  10607. /**
  10608. * 字体大小
  10609. * @command fontsize
  10610. * @method execCommand
  10611. * @param { String } cmd 命令字符串
  10612. * @param { String } value 字体大小
  10613. * @example
  10614. * ```javascript
  10615. * editor.execCommand( 'fontsize', '14px' );
  10616. * ```
  10617. */
  10618. /**
  10619. * 返回选区字体大小
  10620. * @command fontsize
  10621. * @method queryCommandValue
  10622. * @param { String } cmd 命令字符串
  10623. * @return { String } 返回字体大小
  10624. * @example
  10625. * ```javascript
  10626. * editor.queryCommandValue( 'fontsize' );
  10627. * ```
  10628. */
  10629. /**
  10630. * 字体样式
  10631. * @command fontfamily
  10632. * @method execCommand
  10633. * @param { String } cmd 命令字符串
  10634. * @param { String } value 字体样式
  10635. * @example
  10636. * ```javascript
  10637. * editor.execCommand( 'fontfamily', '微软雅黑' );
  10638. * ```
  10639. */
  10640. /**
  10641. * 返回选区字体样式
  10642. * @command fontfamily
  10643. * @method queryCommandValue
  10644. * @param { String } cmd 命令字符串
  10645. * @return { String } 返回字体样式
  10646. * @example
  10647. * ```javascript
  10648. * editor.queryCommandValue( 'fontfamily' );
  10649. * ```
  10650. */
  10651. /**
  10652. * 字体下划线,与删除线互斥
  10653. * @command underline
  10654. * @method execCommand
  10655. * @param { String } cmd 命令字符串
  10656. * @example
  10657. * ```javascript
  10658. * editor.execCommand( 'underline' );
  10659. * ```
  10660. */
  10661. /**
  10662. * 字体删除线,与下划线互斥
  10663. * @command strikethrough
  10664. * @method execCommand
  10665. * @param { String } cmd 命令字符串
  10666. * @example
  10667. * ```javascript
  10668. * editor.execCommand( 'strikethrough' );
  10669. * ```
  10670. */
  10671. /**
  10672. * 字体边框
  10673. * @command fontborder
  10674. * @method execCommand
  10675. * @param { String } cmd 命令字符串
  10676. * @example
  10677. * ```javascript
  10678. * editor.execCommand( 'fontborder' );
  10679. * ```
  10680. */
  10681. UE.plugins['font'] = function () {
  10682. var me = this,
  10683. fonts = {
  10684. 'forecolor': 'color',
  10685. 'backcolor': 'background-color',
  10686. 'fontsize': 'font-size',
  10687. 'fontfamily': 'font-family',
  10688. 'underline': 'text-decoration',
  10689. 'strikethrough': 'text-decoration',
  10690. 'fontborder': 'border'
  10691. },
  10692. needCmd = {'underline': 1, 'strikethrough': 1, 'fontborder': 1},
  10693. needSetChild = {
  10694. 'forecolor': 'color',
  10695. 'backcolor': 'background-color',
  10696. 'fontsize': 'font-size',
  10697. 'fontfamily': 'font-family'
  10698. };
  10699. me.setOpt({
  10700. 'fontfamily': [
  10701. { name: 'songti', val: '宋体,SimSun'},
  10702. { name: 'yahei', val: '微软雅黑,Microsoft YaHei'},
  10703. { name: 'kaiti', val: '楷体,楷体_GB2312, SimKai'},
  10704. { name: 'heiti', val: '黑体, SimHei'},
  10705. { name: 'lishu', val: '隶书, SimLi'},
  10706. { name: 'andaleMono', val: 'andale mono'},
  10707. { name: 'arial', val: 'arial, helvetica,sans-serif'},
  10708. { name: 'arialBlack', val: 'arial black,avant garde'},
  10709. { name: 'comicSansMs', val: 'comic sans ms'},
  10710. { name: 'impact', val: 'impact,chicago'},
  10711. { name: 'timesNewRoman', val: 'times new roman'}
  10712. ],
  10713. 'fontsize': [10, 11, 12, 14, 16, 18, 20, 24, 36]
  10714. });
  10715. function mergeWithParent(node){
  10716. var parent;
  10717. while(parent = node.parentNode){
  10718. if(parent.tagName == 'SPAN' && domUtils.getChildCount(parent,function(child){
  10719. return !domUtils.isBookmarkNode(child) && !domUtils.isBr(child)
  10720. }) == 1) {
  10721. parent.style.cssText += node.style.cssText;
  10722. domUtils.remove(node,true);
  10723. node = parent;
  10724. }else{
  10725. break;
  10726. }
  10727. }
  10728. }
  10729. function mergeChild(rng,cmdName,value){
  10730. if(needSetChild[cmdName]){
  10731. rng.adjustmentBoundary();
  10732. if(!rng.collapsed && rng.startContainer.nodeType == 1){
  10733. var start = rng.startContainer.childNodes[rng.startOffset];
  10734. if(start && domUtils.isTagNode(start,'span')){
  10735. var bk = rng.createBookmark();
  10736. utils.each(domUtils.getElementsByTagName(start, 'span'), function (span) {
  10737. if (!span.parentNode || domUtils.isBookmarkNode(span))return;
  10738. if(cmdName == 'backcolor' && domUtils.getComputedStyle(span,'background-color').toLowerCase() === value){
  10739. return;
  10740. }
  10741. domUtils.removeStyle(span,needSetChild[cmdName]);
  10742. if(span.style.cssText.replace(/^\s+$/,'').length == 0){
  10743. domUtils.remove(span,true)
  10744. }
  10745. });
  10746. rng.moveToBookmark(bk)
  10747. }
  10748. }
  10749. }
  10750. }
  10751. function mergesibling(rng,cmdName,value) {
  10752. var collapsed = rng.collapsed,
  10753. bk = rng.createBookmark(), common;
  10754. if (collapsed) {
  10755. common = bk.start.parentNode;
  10756. while (dtd.$inline[common.tagName]) {
  10757. common = common.parentNode;
  10758. }
  10759. } else {
  10760. common = domUtils.getCommonAncestor(bk.start, bk.end);
  10761. }
  10762. utils.each(domUtils.getElementsByTagName(common, 'span'), function (span) {
  10763. if (!span.parentNode || domUtils.isBookmarkNode(span))return;
  10764. if (/\s*border\s*:\s*none;?\s*/i.test(span.style.cssText)) {
  10765. if(/^\s*border\s*:\s*none;?\s*$/.test(span.style.cssText)){
  10766. domUtils.remove(span, true);
  10767. }else{
  10768. domUtils.removeStyle(span,'border');
  10769. }
  10770. return
  10771. }
  10772. if (/border/i.test(span.style.cssText) && span.parentNode.tagName == 'SPAN' && /border/i.test(span.parentNode.style.cssText)) {
  10773. span.style.cssText = span.style.cssText.replace(/border[^:]*:[^;]+;?/gi, '');
  10774. }
  10775. if(!(cmdName=='fontborder' && value=='none')){
  10776. var next = span.nextSibling;
  10777. while (next && next.nodeType == 1 && next.tagName == 'SPAN' ) {
  10778. if(domUtils.isBookmarkNode(next) && cmdName == 'fontborder') {
  10779. span.appendChild(next);
  10780. next = span.nextSibling;
  10781. continue;
  10782. }
  10783. if (next.style.cssText == span.style.cssText) {
  10784. domUtils.moveChild(next, span);
  10785. domUtils.remove(next);
  10786. }
  10787. if (span.nextSibling === next)
  10788. break;
  10789. next = span.nextSibling;
  10790. }
  10791. }
  10792. mergeWithParent(span);
  10793. if(browser.ie && browser.version > 8 ){
  10794. //拷贝父亲们的特别的属性,这里只做背景颜色的处理
  10795. var parent = domUtils.findParent(span,function(n){return n.tagName == 'SPAN' && /background-color/.test(n.style.cssText)});
  10796. if(parent && !/background-color/.test(span.style.cssText)){
  10797. span.style.backgroundColor = parent.style.backgroundColor;
  10798. }
  10799. }
  10800. });
  10801. rng.moveToBookmark(bk);
  10802. mergeChild(rng,cmdName,value)
  10803. }
  10804. me.addInputRule(function (root) {
  10805. utils.each(root.getNodesByTagName('u s del font strike'), function (node) {
  10806. if (node.tagName == 'font') {
  10807. var cssStyle = [];
  10808. for (var p in node.attrs) {
  10809. switch (p) {
  10810. case 'size':
  10811. cssStyle.push('font-size:' +
  10812. ({
  10813. '1':'10',
  10814. '2':'12',
  10815. '3':'16',
  10816. '4':'18',
  10817. '5':'24',
  10818. '6':'32',
  10819. '7':'48'
  10820. }[node.attrs[p]] || node.attrs[p]) + 'px');
  10821. break;
  10822. case 'color':
  10823. cssStyle.push('color:' + node.attrs[p]);
  10824. break;
  10825. case 'face':
  10826. cssStyle.push('font-family:' + node.attrs[p]);
  10827. break;
  10828. case 'style':
  10829. cssStyle.push(node.attrs[p]);
  10830. }
  10831. }
  10832. node.attrs = {
  10833. 'style': cssStyle.join(';')
  10834. };
  10835. } else {
  10836. var val = node.tagName == 'u' ? 'underline' : 'line-through';
  10837. node.attrs = {
  10838. 'style': (node.getAttr('style') || '') + 'text-decoration:' + val + ';'
  10839. }
  10840. }
  10841. node.tagName = 'span';
  10842. });
  10843. // utils.each(root.getNodesByTagName('span'), function (node) {
  10844. // var val;
  10845. // if(val = node.getAttr('class')){
  10846. // if(/fontstrikethrough/.test(val)){
  10847. // node.setStyle('text-decoration','line-through');
  10848. // if(node.attrs['class']){
  10849. // node.attrs['class'] = node.attrs['class'].replace(/fontstrikethrough/,'');
  10850. // }else{
  10851. // node.setAttr('class')
  10852. // }
  10853. // }
  10854. // if(/fontborder/.test(val)){
  10855. // node.setStyle('border','1px solid #000');
  10856. // if(node.attrs['class']){
  10857. // node.attrs['class'] = node.attrs['class'].replace(/fontborder/,'');
  10858. // }else{
  10859. // node.setAttr('class')
  10860. // }
  10861. // }
  10862. // }
  10863. // });
  10864. });
  10865. // me.addOutputRule(function(root){
  10866. // utils.each(root.getNodesByTagName('span'), function (node) {
  10867. // var val;
  10868. // if(val = node.getStyle('text-decoration')){
  10869. // if(/line-through/.test(val)){
  10870. // if(node.attrs['class']){
  10871. // node.attrs['class'] += ' fontstrikethrough';
  10872. // }else{
  10873. // node.setAttr('class','fontstrikethrough')
  10874. // }
  10875. // }
  10876. //
  10877. // node.setStyle('text-decoration')
  10878. // }
  10879. // if(val = node.getStyle('border')){
  10880. // if(/1px/.test(val) && /solid/.test(val)){
  10881. // if(node.attrs['class']){
  10882. // node.attrs['class'] += ' fontborder';
  10883. //
  10884. // }else{
  10885. // node.setAttr('class','fontborder')
  10886. // }
  10887. // }
  10888. // node.setStyle('border')
  10889. //
  10890. // }
  10891. // });
  10892. // });
  10893. for (var p in fonts) {
  10894. (function (cmd, style) {
  10895. UE.commands[cmd] = {
  10896. execCommand: function (cmdName, value) {
  10897. value = value || (this.queryCommandState(cmdName) ? 'none' : cmdName == 'underline' ? 'underline' :
  10898. cmdName == 'fontborder' ? '1px solid #000' :
  10899. 'line-through');
  10900. var me = this,
  10901. range = this.selection.getRange(),
  10902. text;
  10903. if (value == 'default') {
  10904. if (range.collapsed) {
  10905. text = me.document.createTextNode('font');
  10906. range.insertNode(text).select();
  10907. }
  10908. me.execCommand('removeFormat', 'span,a', style);
  10909. if (text) {
  10910. range.setStartBefore(text).collapse(true);
  10911. domUtils.remove(text);
  10912. }
  10913. mergesibling(range,cmdName,value);
  10914. range.select()
  10915. } else {
  10916. if (!range.collapsed) {
  10917. if (needCmd[cmd] && me.queryCommandValue(cmd)) {
  10918. me.execCommand('removeFormat', 'span,a', style);
  10919. }
  10920. range = me.selection.getRange();
  10921. range.applyInlineStyle('span', {'style': style + ':' + value});
  10922. mergesibling(range, cmdName,value);
  10923. range.select();
  10924. } else {
  10925. var span = domUtils.findParentByTagName(range.startContainer, 'span', true);
  10926. text = me.document.createTextNode('font');
  10927. if (span && !span.children.length && !span[browser.ie ? 'innerText' : 'textContent'].replace(fillCharReg, '').length) {
  10928. //for ie hack when enter
  10929. range.insertNode(text);
  10930. if (needCmd[cmd]) {
  10931. range.selectNode(text).select();
  10932. me.execCommand('removeFormat', 'span,a', style, null);
  10933. span = domUtils.findParentByTagName(text, 'span', true);
  10934. range.setStartBefore(text);
  10935. }
  10936. span && (span.style.cssText += ';' + style + ':' + value);
  10937. range.collapse(true).select();
  10938. } else {
  10939. range.insertNode(text);
  10940. range.selectNode(text).select();
  10941. span = range.document.createElement('span');
  10942. if (needCmd[cmd]) {
  10943. //a标签内的不处理跳过
  10944. if (domUtils.findParentByTagName(text, 'a', true)) {
  10945. range.setStartBefore(text).setCursor();
  10946. domUtils.remove(text);
  10947. return;
  10948. }
  10949. me.execCommand('removeFormat', 'span,a', style);
  10950. }
  10951. span.style.cssText = style + ':' + value;
  10952. text.parentNode.insertBefore(span, text);
  10953. //修复,span套span 但样式不继承的问题
  10954. if (!browser.ie || browser.ie && browser.version == 9) {
  10955. var spanParent = span.parentNode;
  10956. while (!domUtils.isBlockElm(spanParent)) {
  10957. if (spanParent.tagName == 'SPAN') {
  10958. //opera合并style不会加入";"
  10959. span.style.cssText = spanParent.style.cssText + ";" + span.style.cssText;
  10960. }
  10961. spanParent = spanParent.parentNode;
  10962. }
  10963. }
  10964. if (opera) {
  10965. setTimeout(function () {
  10966. range.setStart(span, 0).collapse(true);
  10967. mergesibling(range, cmdName,value);
  10968. range.select();
  10969. });
  10970. } else {
  10971. range.setStart(span, 0).collapse(true);
  10972. mergesibling(range,cmdName,value);
  10973. range.select();
  10974. }
  10975. //trace:981
  10976. //domUtils.mergeToParent(span)
  10977. }
  10978. domUtils.remove(text);
  10979. }
  10980. }
  10981. return true;
  10982. },
  10983. queryCommandValue: function (cmdName) {
  10984. var startNode = this.selection.getStart();
  10985. //trace:946
  10986. if (cmdName == 'underline' || cmdName == 'strikethrough') {
  10987. var tmpNode = startNode, value;
  10988. while (tmpNode && !domUtils.isBlockElm(tmpNode) && !domUtils.isBody(tmpNode)) {
  10989. if (tmpNode.nodeType == 1) {
  10990. value = domUtils.getComputedStyle(tmpNode, style);
  10991. if (value != 'none') {
  10992. return value;
  10993. }
  10994. }
  10995. tmpNode = tmpNode.parentNode;
  10996. }
  10997. return 'none';
  10998. }
  10999. if (cmdName == 'fontborder') {
  11000. var tmp = startNode, val;
  11001. while (tmp && dtd.$inline[tmp.tagName]) {
  11002. if (val = domUtils.getComputedStyle(tmp, 'border')) {
  11003. if (/1px/.test(val) && /solid/.test(val)) {
  11004. return val;
  11005. }
  11006. }
  11007. tmp = tmp.parentNode;
  11008. }
  11009. return ''
  11010. }
  11011. if( cmdName == 'FontSize' ) {
  11012. var styleVal = domUtils.getComputedStyle(startNode, style),
  11013. tmp = /^([\d\.]+)(\w+)$/.exec( styleVal );
  11014. if( tmp ) {
  11015. return Math.floor( tmp[1] ) + tmp[2];
  11016. }
  11017. return styleVal;
  11018. }
  11019. return domUtils.getComputedStyle(startNode, style);
  11020. },
  11021. queryCommandState: function (cmdName) {
  11022. if (!needCmd[cmdName])
  11023. return 0;
  11024. var val = this.queryCommandValue(cmdName);
  11025. if (cmdName == 'fontborder') {
  11026. return /1px/.test(val) && /solid/.test(val)
  11027. } else {
  11028. return cmdName == 'underline' ? /underline/.test(val) : /line\-through/.test(val);
  11029. }
  11030. }
  11031. };
  11032. })(p, fonts[p]);
  11033. }
  11034. };
  11035. // plugins/link.js
  11036. /**
  11037. * 超链接
  11038. * @file
  11039. * @since 1.2.6.1
  11040. */
  11041. /**
  11042. * 插入超链接
  11043. * @command link
  11044. * @method execCommand
  11045. * @param { String } cmd 命令字符串
  11046. * @param { Object } options 设置自定义属性,例如:url、title、target
  11047. * @example
  11048. * ```javascript
  11049. * editor.execCommand( 'link', '{
  11050. * url:'ueditor.baidu.com',
  11051. * title:'ueditor',
  11052. * target:'_blank'
  11053. * }' );
  11054. * ```
  11055. */
  11056. /**
  11057. * 返回当前选中的第一个超链接节点
  11058. * @command link
  11059. * @method queryCommandValue
  11060. * @param { String } cmd 命令字符串
  11061. * @return { Element } 超链接节点
  11062. * @example
  11063. * ```javascript
  11064. * editor.queryCommandValue( 'link' );
  11065. * ```
  11066. */
  11067. /**
  11068. * 取消超链接
  11069. * @command unlink
  11070. * @method execCommand
  11071. * @param { String } cmd 命令字符串
  11072. * @example
  11073. * ```javascript
  11074. * editor.execCommand( 'unlink');
  11075. * ```
  11076. */
  11077. UE.plugins['link'] = function(){
  11078. function optimize( range ) {
  11079. var start = range.startContainer,end = range.endContainer;
  11080. if ( start = domUtils.findParentByTagName( start, 'a', true ) ) {
  11081. range.setStartBefore( start );
  11082. }
  11083. if ( end = domUtils.findParentByTagName( end, 'a', true ) ) {
  11084. range.setEndAfter( end );
  11085. }
  11086. }
  11087. UE.commands['unlink'] = {
  11088. execCommand : function() {
  11089. var range = this.selection.getRange(),
  11090. bookmark;
  11091. if(range.collapsed && !domUtils.findParentByTagName( range.startContainer, 'a', true )){
  11092. return;
  11093. }
  11094. bookmark = range.createBookmark();
  11095. optimize( range );
  11096. range.removeInlineStyle( 'a' ).moveToBookmark( bookmark ).select();
  11097. },
  11098. queryCommandState : function(){
  11099. return !this.highlight && this.queryCommandValue('link') ? 0 : -1;
  11100. }
  11101. };
  11102. function doLink(range,opt,me){
  11103. var rngClone = range.cloneRange(),
  11104. link = me.queryCommandValue('link');
  11105. optimize( range = range.adjustmentBoundary() );
  11106. var start = range.startContainer;
  11107. if(start.nodeType == 1 && link){
  11108. start = start.childNodes[range.startOffset];
  11109. if(start && start.nodeType == 1 && start.tagName == 'A' && /^(?:https?|ftp|file)\s*:\s*\/\//.test(start[browser.ie?'innerText':'textContent'])){
  11110. start[browser.ie ? 'innerText' : 'textContent'] = utils.html(opt.textValue||opt.href);
  11111. }
  11112. }
  11113. if( !rngClone.collapsed || link){
  11114. range.removeInlineStyle( 'a' );
  11115. rngClone = range.cloneRange();
  11116. }
  11117. if ( rngClone.collapsed ) {
  11118. var a = range.document.createElement( 'a'),
  11119. text = '';
  11120. if(opt.textValue){
  11121. text = utils.html(opt.textValue);
  11122. delete opt.textValue;
  11123. }else{
  11124. text = utils.html(opt.href);
  11125. }
  11126. domUtils.setAttributes( a, opt );
  11127. start = domUtils.findParentByTagName( rngClone.startContainer, 'a', true );
  11128. if(start && domUtils.isInNodeEndBoundary(rngClone,start)){
  11129. range.setStartAfter(start).collapse(true);
  11130. }
  11131. a[browser.ie ? 'innerText' : 'textContent'] = text;
  11132. range.insertNode(a).selectNode( a );
  11133. } else {
  11134. range.applyInlineStyle( 'a', opt );
  11135. }
  11136. }
  11137. UE.commands['link'] = {
  11138. execCommand : function( cmdName, opt ) {
  11139. var range;
  11140. opt._href && (opt._href = utils.unhtml(opt._href,/[<">]/g));
  11141. opt.href && (opt.href = utils.unhtml(opt.href,/[<">]/g));
  11142. opt.textValue && (opt.textValue = utils.unhtml(opt.textValue,/[<">]/g));
  11143. doLink(range=this.selection.getRange(),opt,this);
  11144. //闭合都不加占位符,如果加了会在a后边多个占位符节点,导致a是图片背景组成的列表,出现空白问题
  11145. range.collapse().select(true);
  11146. },
  11147. queryCommandValue : function() {
  11148. var range = this.selection.getRange(),
  11149. node;
  11150. if ( range.collapsed ) {
  11151. // node = this.selection.getStart();
  11152. //在ie下getstart()取值偏上了
  11153. node = range.startContainer;
  11154. node = node.nodeType == 1 ? node : node.parentNode;
  11155. if ( node && (node = domUtils.findParentByTagName( node, 'a', true )) && ! domUtils.isInNodeEndBoundary(range,node)) {
  11156. return node;
  11157. }
  11158. } else {
  11159. //trace:1111 如果是<p><a>xx</a></p> startContainer是p就会找不到a
  11160. range.shrinkBoundary();
  11161. var start = range.startContainer.nodeType == 3 || !range.startContainer.childNodes[range.startOffset] ? range.startContainer : range.startContainer.childNodes[range.startOffset],
  11162. end = range.endContainer.nodeType == 3 || range.endOffset == 0 ? range.endContainer : range.endContainer.childNodes[range.endOffset-1],
  11163. common = range.getCommonAncestor();
  11164. node = domUtils.findParentByTagName( common, 'a', true );
  11165. if ( !node && common.nodeType == 1){
  11166. var as = common.getElementsByTagName( 'a' ),
  11167. ps,pe;
  11168. for ( var i = 0,ci; ci = as[i++]; ) {
  11169. ps = domUtils.getPosition( ci, start ),pe = domUtils.getPosition( ci,end);
  11170. if ( (ps & domUtils.POSITION_FOLLOWING || ps & domUtils.POSITION_CONTAINS)
  11171. &&
  11172. (pe & domUtils.POSITION_PRECEDING || pe & domUtils.POSITION_CONTAINS)
  11173. ) {
  11174. node = ci;
  11175. break;
  11176. }
  11177. }
  11178. }
  11179. return node;
  11180. }
  11181. },
  11182. queryCommandState : function() {
  11183. //判断如果是视频的话连接不可用
  11184. //fix 853
  11185. var img = this.selection.getRange().getClosedNode(),
  11186. flag = img && (img.className == "edui-faked-video" || img.className.indexOf("edui-upload-video")!=-1);
  11187. return flag ? -1 : 0;
  11188. }
  11189. };
  11190. };
  11191. // plugins/iframe.js
  11192. ///import core
  11193. ///import plugins\inserthtml.js
  11194. ///commands 插入框架
  11195. ///commandsName InsertFrame
  11196. ///commandsTitle 插入Iframe
  11197. ///commandsDialog dialogs\insertframe
  11198. UE.plugins['insertframe'] = function() {
  11199. var me =this;
  11200. function deleteIframe(){
  11201. me._iframe && delete me._iframe;
  11202. }
  11203. me.addListener("selectionchange",function(){
  11204. deleteIframe();
  11205. });
  11206. };
  11207. // plugins/scrawl.js
  11208. ///import core
  11209. ///commands 涂鸦
  11210. ///commandsName Scrawl
  11211. ///commandsTitle 涂鸦
  11212. ///commandsDialog dialogs\scrawl
  11213. UE.commands['scrawl'] = {
  11214. queryCommandState : function(){
  11215. return ( browser.ie && browser.version <= 8 ) ? -1 :0;
  11216. }
  11217. };
  11218. // plugins/removeformat.js
  11219. /**
  11220. * 清除格式
  11221. * @file
  11222. * @since 1.2.6.1
  11223. */
  11224. /**
  11225. * 清除文字样式
  11226. * @command removeformat
  11227. * @method execCommand
  11228. * @param { String } cmd 命令字符串
  11229. * @param {String} tags 以逗号隔开的标签。如:strong
  11230. * @param {String} style 样式如:color
  11231. * @param {String} attrs 属性如:width
  11232. * @example
  11233. * ```javascript
  11234. * editor.execCommand( 'removeformat', 'strong','color','width' );
  11235. * ```
  11236. */
  11237. UE.plugins['removeformat'] = function(){
  11238. var me = this;
  11239. me.setOpt({
  11240. 'removeFormatTags': 'b,big,code,del,dfn,em,font,i,ins,kbd,q,samp,small,span,strike,strong,sub,sup,tt,u,var',
  11241. 'removeFormatAttributes':'class,style,lang,width,height,align,hspace,valign'
  11242. });
  11243. me.commands['removeformat'] = {
  11244. execCommand : function( cmdName, tags, style, attrs,notIncludeA ) {
  11245. var tagReg = new RegExp( '^(?:' + (tags || this.options.removeFormatTags).replace( /,/g, '|' ) + ')$', 'i' ) ,
  11246. removeFormatAttributes = style ? [] : (attrs || this.options.removeFormatAttributes).split( ',' ),
  11247. range = new dom.Range( this.document ),
  11248. bookmark,node,parent,
  11249. filter = function( node ) {
  11250. return node.nodeType == 1;
  11251. };
  11252. function isRedundantSpan (node) {
  11253. if (node.nodeType == 3 || node.tagName.toLowerCase() != 'span'){
  11254. return 0;
  11255. }
  11256. if (browser.ie) {
  11257. //ie 下判断实效,所以只能简单用style来判断
  11258. //return node.style.cssText == '' ? 1 : 0;
  11259. var attrs = node.attributes;
  11260. if ( attrs.length ) {
  11261. for ( var i = 0,l = attrs.length; i<l; i++ ) {
  11262. if ( attrs[i].specified ) {
  11263. return 0;
  11264. }
  11265. }
  11266. return 1;
  11267. }
  11268. }
  11269. return !node.attributes.length;
  11270. }
  11271. function doRemove( range ) {
  11272. var bookmark1 = range.createBookmark();
  11273. if ( range.collapsed ) {
  11274. range.enlarge( true );
  11275. }
  11276. //不能把a标签切了
  11277. if(!notIncludeA){
  11278. var aNode = domUtils.findParentByTagName(range.startContainer,'a',true);
  11279. if(aNode){
  11280. range.setStartBefore(aNode);
  11281. }
  11282. aNode = domUtils.findParentByTagName(range.endContainer,'a',true);
  11283. if(aNode){
  11284. range.setEndAfter(aNode);
  11285. }
  11286. }
  11287. bookmark = range.createBookmark();
  11288. node = bookmark.start;
  11289. //切开始
  11290. while ( (parent = node.parentNode) && !domUtils.isBlockElm( parent ) ) {
  11291. domUtils.breakParent( node, parent );
  11292. domUtils.clearEmptySibling( node );
  11293. }
  11294. if ( bookmark.end ) {
  11295. //切结束
  11296. node = bookmark.end;
  11297. while ( (parent = node.parentNode) && !domUtils.isBlockElm( parent ) ) {
  11298. domUtils.breakParent( node, parent );
  11299. domUtils.clearEmptySibling( node );
  11300. }
  11301. //开始去除样式
  11302. var current = domUtils.getNextDomNode( bookmark.start, false, filter ),
  11303. next;
  11304. while ( current ) {
  11305. if ( current == bookmark.end ) {
  11306. break;
  11307. }
  11308. next = domUtils.getNextDomNode( current, true, filter );
  11309. if ( !dtd.$empty[current.tagName.toLowerCase()] && !domUtils.isBookmarkNode( current ) ) {
  11310. if ( tagReg.test( current.tagName ) ) {
  11311. if ( style ) {
  11312. domUtils.removeStyle( current, style );
  11313. if ( isRedundantSpan( current ) && style != 'text-decoration'){
  11314. domUtils.remove( current, true );
  11315. }
  11316. } else {
  11317. domUtils.remove( current, true );
  11318. }
  11319. } else {
  11320. //trace:939 不能把list上的样式去掉
  11321. if(!dtd.$tableContent[current.tagName] && !dtd.$list[current.tagName]){
  11322. domUtils.removeAttributes( current, removeFormatAttributes );
  11323. if ( isRedundantSpan( current ) ){
  11324. domUtils.remove( current, true );
  11325. }
  11326. }
  11327. }
  11328. }
  11329. current = next;
  11330. }
  11331. }
  11332. //trace:1035
  11333. //trace:1096 不能把td上的样式去掉,比如边框
  11334. var pN = bookmark.start.parentNode;
  11335. if(domUtils.isBlockElm(pN) && !dtd.$tableContent[pN.tagName] && !dtd.$list[pN.tagName]){
  11336. domUtils.removeAttributes( pN,removeFormatAttributes );
  11337. }
  11338. pN = bookmark.end.parentNode;
  11339. if(bookmark.end && domUtils.isBlockElm(pN) && !dtd.$tableContent[pN.tagName]&& !dtd.$list[pN.tagName]){
  11340. domUtils.removeAttributes( pN,removeFormatAttributes );
  11341. }
  11342. range.moveToBookmark( bookmark ).moveToBookmark(bookmark1);
  11343. //清除冗余的代码 <b><bookmark></b>
  11344. var node = range.startContainer,
  11345. tmp,
  11346. collapsed = range.collapsed;
  11347. while(node.nodeType == 1 && domUtils.isEmptyNode(node) && dtd.$removeEmpty[node.tagName]){
  11348. tmp = node.parentNode;
  11349. range.setStartBefore(node);
  11350. //trace:937
  11351. //更新结束边界
  11352. if(range.startContainer === range.endContainer){
  11353. range.endOffset--;
  11354. }
  11355. domUtils.remove(node);
  11356. node = tmp;
  11357. }
  11358. if(!collapsed){
  11359. node = range.endContainer;
  11360. while(node.nodeType == 1 && domUtils.isEmptyNode(node) && dtd.$removeEmpty[node.tagName]){
  11361. tmp = node.parentNode;
  11362. range.setEndBefore(node);
  11363. domUtils.remove(node);
  11364. node = tmp;
  11365. }
  11366. }
  11367. }
  11368. range = this.selection.getRange();
  11369. doRemove( range );
  11370. range.select();
  11371. }
  11372. };
  11373. };
  11374. // plugins/blockquote.js
  11375. /**
  11376. * 添加引用
  11377. * @file
  11378. * @since 1.2.6.1
  11379. */
  11380. /**
  11381. * 添加引用
  11382. * @command blockquote
  11383. * @method execCommand
  11384. * @param { String } cmd 命令字符串
  11385. * @example
  11386. * ```javascript
  11387. * editor.execCommand( 'blockquote' );
  11388. * ```
  11389. */
  11390. /**
  11391. * 添加引用
  11392. * @command blockquote
  11393. * @method execCommand
  11394. * @param { String } cmd 命令字符串
  11395. * @param { Object } attrs 节点属性
  11396. * @example
  11397. * ```javascript
  11398. * editor.execCommand( 'blockquote',{
  11399. * style: "color: red;"
  11400. * } );
  11401. * ```
  11402. */
  11403. UE.plugins['blockquote'] = function(){
  11404. var me = this;
  11405. function getObj(editor){
  11406. return domUtils.filterNodeList(editor.selection.getStartElementPath(),'blockquote');
  11407. }
  11408. me.commands['blockquote'] = {
  11409. execCommand : function( cmdName, attrs ) {
  11410. var range = this.selection.getRange(),
  11411. obj = getObj(this),
  11412. blockquote = dtd.blockquote,
  11413. bookmark = range.createBookmark();
  11414. if ( obj ) {
  11415. var start = range.startContainer,
  11416. startBlock = domUtils.isBlockElm(start) ? start : domUtils.findParent(start,function(node){return domUtils.isBlockElm(node)}),
  11417. end = range.endContainer,
  11418. endBlock = domUtils.isBlockElm(end) ? end : domUtils.findParent(end,function(node){return domUtils.isBlockElm(node)});
  11419. //处理一下li
  11420. startBlock = domUtils.findParentByTagName(startBlock,'li',true) || startBlock;
  11421. endBlock = domUtils.findParentByTagName(endBlock,'li',true) || endBlock;
  11422. if(startBlock.tagName == 'LI' || startBlock.tagName == 'TD' || startBlock === obj || domUtils.isBody(startBlock)){
  11423. domUtils.remove(obj,true);
  11424. }else{
  11425. domUtils.breakParent(startBlock,obj);
  11426. }
  11427. if(startBlock !== endBlock){
  11428. obj = domUtils.findParentByTagName(endBlock,'blockquote');
  11429. if(obj){
  11430. if(endBlock.tagName == 'LI' || endBlock.tagName == 'TD'|| domUtils.isBody(endBlock)){
  11431. obj.parentNode && domUtils.remove(obj,true);
  11432. }else{
  11433. domUtils.breakParent(endBlock,obj);
  11434. }
  11435. }
  11436. }
  11437. var blockquotes = domUtils.getElementsByTagName(this.document,'blockquote');
  11438. for(var i=0,bi;bi=blockquotes[i++];){
  11439. if(!bi.childNodes.length){
  11440. domUtils.remove(bi);
  11441. }else if(domUtils.getPosition(bi,startBlock)&domUtils.POSITION_FOLLOWING && domUtils.getPosition(bi,endBlock)&domUtils.POSITION_PRECEDING){
  11442. domUtils.remove(bi,true);
  11443. }
  11444. }
  11445. } else {
  11446. var tmpRange = range.cloneRange(),
  11447. node = tmpRange.startContainer.nodeType == 1 ? tmpRange.startContainer : tmpRange.startContainer.parentNode,
  11448. preNode = node,
  11449. doEnd = 1;
  11450. //调整开始
  11451. while ( 1 ) {
  11452. if ( domUtils.isBody(node) ) {
  11453. if ( preNode !== node ) {
  11454. if ( range.collapsed ) {
  11455. tmpRange.selectNode( preNode );
  11456. doEnd = 0;
  11457. } else {
  11458. tmpRange.setStartBefore( preNode );
  11459. }
  11460. }else{
  11461. tmpRange.setStart(node,0);
  11462. }
  11463. break;
  11464. }
  11465. if ( !blockquote[node.tagName] ) {
  11466. if ( range.collapsed ) {
  11467. tmpRange.selectNode( preNode );
  11468. } else{
  11469. tmpRange.setStartBefore( preNode);
  11470. }
  11471. break;
  11472. }
  11473. preNode = node;
  11474. node = node.parentNode;
  11475. }
  11476. //调整结束
  11477. if ( doEnd ) {
  11478. preNode = node = node = tmpRange.endContainer.nodeType == 1 ? tmpRange.endContainer : tmpRange.endContainer.parentNode;
  11479. while ( 1 ) {
  11480. if ( domUtils.isBody( node ) ) {
  11481. if ( preNode !== node ) {
  11482. tmpRange.setEndAfter( preNode );
  11483. } else {
  11484. tmpRange.setEnd( node, node.childNodes.length );
  11485. }
  11486. break;
  11487. }
  11488. if ( !blockquote[node.tagName] ) {
  11489. tmpRange.setEndAfter( preNode );
  11490. break;
  11491. }
  11492. preNode = node;
  11493. node = node.parentNode;
  11494. }
  11495. }
  11496. node = range.document.createElement( 'blockquote' );
  11497. domUtils.setAttributes( node, attrs );
  11498. node.appendChild( tmpRange.extractContents() );
  11499. tmpRange.insertNode( node );
  11500. //去除重复的
  11501. var childs = domUtils.getElementsByTagName(node,'blockquote');
  11502. for(var i=0,ci;ci=childs[i++];){
  11503. if(ci.parentNode){
  11504. domUtils.remove(ci,true);
  11505. }
  11506. }
  11507. }
  11508. range.moveToBookmark( bookmark ).select();
  11509. },
  11510. queryCommandState : function() {
  11511. return getObj(this) ? 1 : 0;
  11512. }
  11513. };
  11514. };
  11515. // plugins/convertcase.js
  11516. /**
  11517. * 大小写转换
  11518. * @file
  11519. * @since 1.2.6.1
  11520. */
  11521. /**
  11522. * 把选区内文本变大写,与“tolowercase”命令互斥
  11523. * @command touppercase
  11524. * @method execCommand
  11525. * @param { String } cmd 命令字符串
  11526. * @example
  11527. * ```javascript
  11528. * editor.execCommand( 'touppercase' );
  11529. * ```
  11530. */
  11531. /**
  11532. * 把选区内文本变小写,与“touppercase”命令互斥
  11533. * @command tolowercase
  11534. * @method execCommand
  11535. * @param { String } cmd 命令字符串
  11536. * @example
  11537. * ```javascript
  11538. * editor.execCommand( 'tolowercase' );
  11539. * ```
  11540. */
  11541. UE.commands['touppercase'] =
  11542. UE.commands['tolowercase'] = {
  11543. execCommand:function (cmd) {
  11544. var me = this;
  11545. var rng = me.selection.getRange();
  11546. if(rng.collapsed){
  11547. return rng;
  11548. }
  11549. var bk = rng.createBookmark(),
  11550. bkEnd = bk.end,
  11551. filterFn = function( node ) {
  11552. return !domUtils.isBr(node) && !domUtils.isWhitespace( node );
  11553. },
  11554. curNode = domUtils.getNextDomNode( bk.start, false, filterFn );
  11555. while ( curNode && (domUtils.getPosition( curNode, bkEnd ) & domUtils.POSITION_PRECEDING) ) {
  11556. if ( curNode.nodeType == 3 ) {
  11557. curNode.nodeValue = curNode.nodeValue[cmd == 'touppercase' ? 'toUpperCase' : 'toLowerCase']();
  11558. }
  11559. curNode = domUtils.getNextDomNode( curNode, true, filterFn );
  11560. if(curNode === bkEnd){
  11561. break;
  11562. }
  11563. }
  11564. rng.moveToBookmark(bk).select();
  11565. }
  11566. };
  11567. // plugins/indent.js
  11568. /**
  11569. * 首行缩进
  11570. * @file
  11571. * @since 1.2.6.1
  11572. */
  11573. /**
  11574. * 缩进
  11575. * @command indent
  11576. * @method execCommand
  11577. * @param { String } cmd 命令字符串
  11578. * @example
  11579. * ```javascript
  11580. * editor.execCommand( 'indent' );
  11581. * ```
  11582. */
  11583. UE.commands['indent'] = {
  11584. execCommand : function() {
  11585. var me = this,value = me.queryCommandState("indent") ? "0em" : (me.options.indentValue || '2em');
  11586. me.execCommand('Paragraph','p',{style:'text-indent:'+ value});
  11587. },
  11588. queryCommandState : function() {
  11589. var pN = domUtils.filterNodeList(this.selection.getStartElementPath(),'p h1 h2 h3 h4 h5 h6');
  11590. return pN && pN.style.textIndent && parseInt(pN.style.textIndent) ? 1 : 0;
  11591. }
  11592. };
  11593. // plugins/print.js
  11594. /**
  11595. * 打印
  11596. * @file
  11597. * @since 1.2.6.1
  11598. */
  11599. /**
  11600. * 打印
  11601. * @command print
  11602. * @method execCommand
  11603. * @param { String } cmd 命令字符串
  11604. * @example
  11605. * ```javascript
  11606. * editor.execCommand( 'print' );
  11607. * ```
  11608. */
  11609. UE.commands['print'] = {
  11610. execCommand : function(){
  11611. this.window.print();
  11612. },
  11613. notNeedUndo : 1
  11614. };
  11615. // plugins/preview.js
  11616. /**
  11617. * 预览
  11618. * @file
  11619. * @since 1.2.6.1
  11620. */
  11621. /**
  11622. * 预览
  11623. * @command preview
  11624. * @method execCommand
  11625. * @param { String } cmd 命令字符串
  11626. * @example
  11627. * ```javascript
  11628. * editor.execCommand( 'preview' );
  11629. * ```
  11630. */
  11631. UE.commands['preview'] = {
  11632. execCommand : function(){
  11633. var w = window.open('', '_blank', ''),
  11634. d = w.document;
  11635. d.open();
  11636. d.write('<!DOCTYPE html><html><head><meta charset="utf-8"/><script src="'+this.options.UEDITOR_HOME_URL+'ueditor.parse.js"></script><script>' +
  11637. "setTimeout(function(){uParse('div',{rootPath: '"+ this.options.UEDITOR_HOME_URL +"'})},300)" +
  11638. '</script></head><body><div>'+this.getContent(null,null,true)+'</div></body></html>');
  11639. d.close();
  11640. },
  11641. notNeedUndo : 1
  11642. };
  11643. // plugins/selectall.js
  11644. /**
  11645. * 全选
  11646. * @file
  11647. * @since 1.2.6.1
  11648. */
  11649. /**
  11650. * 选中所有内容
  11651. * @command selectall
  11652. * @method execCommand
  11653. * @param { String } cmd 命令字符串
  11654. * @example
  11655. * ```javascript
  11656. * editor.execCommand( 'selectall' );
  11657. * ```
  11658. */
  11659. UE.plugins['selectall'] = function(){
  11660. var me = this;
  11661. me.commands['selectall'] = {
  11662. execCommand : function(){
  11663. //去掉了原生的selectAll,因为会出现报错和当内容为空时,不能出现闭合状态的光标
  11664. var me = this,body = me.body,
  11665. range = me.selection.getRange();
  11666. range.selectNodeContents(body);
  11667. if(domUtils.isEmptyBlock(body)){
  11668. //opera不能自动合并到元素的里边,要手动处理一下
  11669. if(browser.opera && body.firstChild && body.firstChild.nodeType == 1){
  11670. range.setStartAtFirst(body.firstChild);
  11671. }
  11672. range.collapse(true);
  11673. }
  11674. range.select(true);
  11675. },
  11676. notNeedUndo : 1
  11677. };
  11678. //快捷键
  11679. me.addshortcutkey({
  11680. "selectAll" : "ctrl+65"
  11681. });
  11682. };
  11683. // plugins/paragraph.js
  11684. /**
  11685. * 段落样式
  11686. * @file
  11687. * @since 1.2.6.1
  11688. */
  11689. /**
  11690. * 段落格式
  11691. * @command paragraph
  11692. * @method execCommand
  11693. * @param { String } cmd 命令字符串
  11694. * @param {String} style 标签值为:'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
  11695. * @param {Object} attrs 标签的属性
  11696. * @example
  11697. * ```javascript
  11698. * editor.execCommand( 'Paragraph','h1','{
  11699. * class:'test'
  11700. * }' );
  11701. * ```
  11702. */
  11703. /**
  11704. * 返回选区内节点标签名
  11705. * @command paragraph
  11706. * @method queryCommandValue
  11707. * @param { String } cmd 命令字符串
  11708. * @return { String } 节点标签名
  11709. * @example
  11710. * ```javascript
  11711. * editor.queryCommandValue( 'Paragraph' );
  11712. * ```
  11713. */
  11714. UE.plugins['paragraph'] = function() {
  11715. var me = this,
  11716. block = domUtils.isBlockElm,
  11717. notExchange = ['TD','LI','PRE'],
  11718. doParagraph = function(range,style,attrs,sourceCmdName){
  11719. var bookmark = range.createBookmark(),
  11720. filterFn = function( node ) {
  11721. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' && !domUtils.isBookmarkNode(node) : !domUtils.isWhitespace( node );
  11722. },
  11723. para;
  11724. range.enlarge( true );
  11725. var bookmark2 = range.createBookmark(),
  11726. current = domUtils.getNextDomNode( bookmark2.start, false, filterFn ),
  11727. tmpRange = range.cloneRange(),
  11728. tmpNode;
  11729. while ( current && !(domUtils.getPosition( current, bookmark2.end ) & domUtils.POSITION_FOLLOWING) ) {
  11730. if ( current.nodeType == 3 || !block( current ) ) {
  11731. tmpRange.setStartBefore( current );
  11732. while ( current && current !== bookmark2.end && !block( current ) ) {
  11733. tmpNode = current;
  11734. current = domUtils.getNextDomNode( current, false, null, function( node ) {
  11735. return !block( node );
  11736. } );
  11737. }
  11738. tmpRange.setEndAfter( tmpNode );
  11739. para = range.document.createElement( style );
  11740. if(attrs){
  11741. domUtils.setAttributes(para,attrs);
  11742. if(sourceCmdName && sourceCmdName == 'customstyle' && attrs.style){
  11743. para.style.cssText = attrs.style;
  11744. }
  11745. }
  11746. para.appendChild( tmpRange.extractContents() );
  11747. //需要内容占位
  11748. if(domUtils.isEmptyNode(para)){
  11749. domUtils.fillChar(range.document,para);
  11750. }
  11751. tmpRange.insertNode( para );
  11752. var parent = para.parentNode;
  11753. //如果para上一级是一个block元素且不是body,td就删除它
  11754. if ( block( parent ) && !domUtils.isBody( para.parentNode ) && utils.indexOf(notExchange,parent.tagName)==-1) {
  11755. //存储dir,style
  11756. if(!(sourceCmdName && sourceCmdName == 'customstyle')){
  11757. parent.getAttribute('dir') && para.setAttribute('dir',parent.getAttribute('dir'));
  11758. //trace:1070
  11759. parent.style.cssText && (para.style.cssText = parent.style.cssText + ';' + para.style.cssText);
  11760. //trace:1030
  11761. parent.style.textAlign && !para.style.textAlign && (para.style.textAlign = parent.style.textAlign);
  11762. parent.style.textIndent && !para.style.textIndent && (para.style.textIndent = parent.style.textIndent);
  11763. parent.style.padding && !para.style.padding && (para.style.padding = parent.style.padding);
  11764. }
  11765. //trace:1706 选择的就是h1-6要删除
  11766. if(attrs && /h\d/i.test(parent.tagName) && !/h\d/i.test(para.tagName) ){
  11767. domUtils.setAttributes(parent,attrs);
  11768. if(sourceCmdName && sourceCmdName == 'customstyle' && attrs.style){
  11769. parent.style.cssText = attrs.style;
  11770. }
  11771. domUtils.remove(para,true);
  11772. para = parent;
  11773. }else{
  11774. domUtils.remove( para.parentNode, true );
  11775. }
  11776. }
  11777. if( utils.indexOf(notExchange,parent.tagName)!=-1){
  11778. current = parent;
  11779. }else{
  11780. current = para;
  11781. }
  11782. current = domUtils.getNextDomNode( current, false, filterFn );
  11783. } else {
  11784. current = domUtils.getNextDomNode( current, true, filterFn );
  11785. }
  11786. }
  11787. return range.moveToBookmark( bookmark2 ).moveToBookmark( bookmark );
  11788. };
  11789. me.setOpt('paragraph',{'p':'', 'h1':'', 'h2':'', 'h3':'', 'h4':'', 'h5':'', 'h6':''});
  11790. me.commands['paragraph'] = {
  11791. execCommand : function( cmdName, style,attrs,sourceCmdName ) {
  11792. var range = this.selection.getRange();
  11793. //闭合时单独处理
  11794. if(range.collapsed){
  11795. var txt = this.document.createTextNode('p');
  11796. range.insertNode(txt);
  11797. //去掉冗余的fillchar
  11798. if(browser.ie){
  11799. var node = txt.previousSibling;
  11800. if(node && domUtils.isWhitespace(node)){
  11801. domUtils.remove(node);
  11802. }
  11803. node = txt.nextSibling;
  11804. if(node && domUtils.isWhitespace(node)){
  11805. domUtils.remove(node);
  11806. }
  11807. }
  11808. }
  11809. range = doParagraph(range,style,attrs,sourceCmdName);
  11810. if(txt){
  11811. range.setStartBefore(txt).collapse(true);
  11812. pN = txt.parentNode;
  11813. domUtils.remove(txt);
  11814. if(domUtils.isBlockElm(pN)&&domUtils.isEmptyNode(pN)){
  11815. domUtils.fillNode(this.document,pN);
  11816. }
  11817. }
  11818. if(browser.gecko && range.collapsed && range.startContainer.nodeType == 1){
  11819. var child = range.startContainer.childNodes[range.startOffset];
  11820. if(child && child.nodeType == 1 && child.tagName.toLowerCase() == style){
  11821. range.setStart(child,0).collapse(true);
  11822. }
  11823. }
  11824. //trace:1097 原来有true,原因忘了,但去了就不能清除多余的占位符了
  11825. range.select();
  11826. return true;
  11827. },
  11828. queryCommandValue : function() {
  11829. var node = domUtils.filterNodeList(this.selection.getStartElementPath(),'p h1 h2 h3 h4 h5 h6');
  11830. return node ? node.tagName.toLowerCase() : '';
  11831. }
  11832. };
  11833. };
  11834. // plugins/directionality.js
  11835. /**
  11836. * 设置文字输入的方向的插件
  11837. * @file
  11838. * @since 1.2.6.1
  11839. */
  11840. (function() {
  11841. var block = domUtils.isBlockElm ,
  11842. getObj = function(editor){
  11843. // var startNode = editor.selection.getStart(),
  11844. // parents;
  11845. // if ( startNode ) {
  11846. // //查找所有的是block的父亲节点
  11847. // parents = domUtils.findParents( startNode, true, block, true );
  11848. // for ( var i = 0,ci; ci = parents[i++]; ) {
  11849. // if ( ci.getAttribute( 'dir' ) ) {
  11850. // return ci;
  11851. // }
  11852. // }
  11853. // }
  11854. return domUtils.filterNodeList(editor.selection.getStartElementPath(),function(n){return n && n.nodeType == 1 && n.getAttribute('dir')});
  11855. },
  11856. doDirectionality = function(range,editor,forward){
  11857. var bookmark,
  11858. filterFn = function( node ) {
  11859. return node.nodeType == 1 ? !domUtils.isBookmarkNode(node) : !domUtils.isWhitespace(node);
  11860. },
  11861. obj = getObj( editor );
  11862. if ( obj && range.collapsed ) {
  11863. obj.setAttribute( 'dir', forward );
  11864. return range;
  11865. }
  11866. bookmark = range.createBookmark();
  11867. range.enlarge( true );
  11868. var bookmark2 = range.createBookmark(),
  11869. current = domUtils.getNextDomNode( bookmark2.start, false, filterFn ),
  11870. tmpRange = range.cloneRange(),
  11871. tmpNode;
  11872. while ( current && !(domUtils.getPosition( current, bookmark2.end ) & domUtils.POSITION_FOLLOWING) ) {
  11873. if ( current.nodeType == 3 || !block( current ) ) {
  11874. tmpRange.setStartBefore( current );
  11875. while ( current && current !== bookmark2.end && !block( current ) ) {
  11876. tmpNode = current;
  11877. current = domUtils.getNextDomNode( current, false, null, function( node ) {
  11878. return !block( node );
  11879. } );
  11880. }
  11881. tmpRange.setEndAfter( tmpNode );
  11882. var common = tmpRange.getCommonAncestor();
  11883. if ( !domUtils.isBody( common ) && block( common ) ) {
  11884. //遍历到了block节点
  11885. common.setAttribute( 'dir', forward );
  11886. current = common;
  11887. } else {
  11888. //没有遍历到,添加一个block节点
  11889. var p = range.document.createElement( 'p' );
  11890. p.setAttribute( 'dir', forward );
  11891. var frag = tmpRange.extractContents();
  11892. p.appendChild( frag );
  11893. tmpRange.insertNode( p );
  11894. current = p;
  11895. }
  11896. current = domUtils.getNextDomNode( current, false, filterFn );
  11897. } else {
  11898. current = domUtils.getNextDomNode( current, true, filterFn );
  11899. }
  11900. }
  11901. return range.moveToBookmark( bookmark2 ).moveToBookmark( bookmark );
  11902. };
  11903. /**
  11904. * 文字输入方向
  11905. * @command directionality
  11906. * @method execCommand
  11907. * @param { String } cmdName 命令字符串
  11908. * @param { String } forward 传入'ltr'表示从左向右输入,传入'rtl'表示从右向左输入
  11909. * @example
  11910. * ```javascript
  11911. * editor.execCommand( 'directionality', 'ltr');
  11912. * ```
  11913. */
  11914. /**
  11915. * 查询当前选区的文字输入方向
  11916. * @command directionality
  11917. * @method queryCommandValue
  11918. * @param { String } cmdName 命令字符串
  11919. * @return { String } 返回'ltr'表示从左向右输入,返回'rtl'表示从右向左输入
  11920. * @example
  11921. * ```javascript
  11922. * editor.queryCommandValue( 'directionality');
  11923. * ```
  11924. */
  11925. UE.commands['directionality'] = {
  11926. execCommand : function( cmdName,forward ) {
  11927. var range = this.selection.getRange();
  11928. //闭合时单独处理
  11929. if(range.collapsed){
  11930. var txt = this.document.createTextNode('d');
  11931. range.insertNode(txt);
  11932. }
  11933. doDirectionality(range,this,forward);
  11934. if(txt){
  11935. range.setStartBefore(txt).collapse(true);
  11936. domUtils.remove(txt);
  11937. }
  11938. range.select();
  11939. return true;
  11940. },
  11941. queryCommandValue : function() {
  11942. var node = getObj(this);
  11943. return node ? node.getAttribute('dir') : 'ltr';
  11944. }
  11945. };
  11946. })();
  11947. // plugins/horizontal.js
  11948. /**
  11949. * 插入分割线插件
  11950. * @file
  11951. * @since 1.2.6.1
  11952. */
  11953. /**
  11954. * 插入分割线
  11955. * @command horizontal
  11956. * @method execCommand
  11957. * @param { String } cmdName 命令字符串
  11958. * @example
  11959. * ```javascript
  11960. * editor.execCommand( 'horizontal' );
  11961. * ```
  11962. */
  11963. UE.plugins['horizontal'] = function(){
  11964. var me = this;
  11965. me.commands['horizontal'] = {
  11966. execCommand : function( cmdName ) {
  11967. var me = this;
  11968. if(me.queryCommandState(cmdName)!==-1){
  11969. me.execCommand('insertHtml','<hr>');
  11970. var range = me.selection.getRange(),
  11971. start = range.startContainer;
  11972. if(start.nodeType == 1 && !start.childNodes[range.startOffset] ){
  11973. var tmp;
  11974. if(tmp = start.childNodes[range.startOffset - 1]){
  11975. if(tmp.nodeType == 1 && tmp.tagName == 'HR'){
  11976. if(me.options.enterTag == 'p'){
  11977. tmp = me.document.createElement('p');
  11978. range.insertNode(tmp);
  11979. range.setStart(tmp,0).setCursor();
  11980. }else{
  11981. tmp = me.document.createElement('br');
  11982. range.insertNode(tmp);
  11983. range.setStartBefore(tmp).setCursor();
  11984. }
  11985. }
  11986. }
  11987. }
  11988. return true;
  11989. }
  11990. },
  11991. //边界在table里不能加分隔线
  11992. queryCommandState : function() {
  11993. return domUtils.filterNodeList(this.selection.getStartElementPath(),'table') ? -1 : 0;
  11994. }
  11995. };
  11996. // me.addListener('delkeyup',function(){
  11997. // var rng = this.selection.getRange();
  11998. // if(browser.ie && browser.version > 8){
  11999. // rng.txtToElmBoundary(true);
  12000. // if(domUtils.isStartInblock(rng)){
  12001. // var tmpNode = rng.startContainer;
  12002. // var pre = tmpNode.previousSibling;
  12003. // if(pre && domUtils.isTagNode(pre,'hr')){
  12004. // domUtils.remove(pre);
  12005. // rng.select();
  12006. // return;
  12007. // }
  12008. // }
  12009. // }
  12010. // if(domUtils.isBody(rng.startContainer)){
  12011. // var hr = rng.startContainer.childNodes[rng.startOffset -1];
  12012. // if(hr && hr.nodeName == 'HR'){
  12013. // var next = hr.nextSibling;
  12014. // if(next){
  12015. // rng.setStart(next,0)
  12016. // }else if(hr.previousSibling){
  12017. // rng.setStartAtLast(hr.previousSibling)
  12018. // }else{
  12019. // var p = this.document.createElement('p');
  12020. // hr.parentNode.insertBefore(p,hr);
  12021. // domUtils.fillNode(this.document,p);
  12022. // rng.setStart(p,0);
  12023. // }
  12024. // domUtils.remove(hr);
  12025. // rng.setCursor(false,true);
  12026. // }
  12027. // }
  12028. // })
  12029. me.addListener('delkeydown',function(name,evt){
  12030. var rng = this.selection.getRange();
  12031. rng.txtToElmBoundary(true);
  12032. if(domUtils.isStartInblock(rng)){
  12033. var tmpNode = rng.startContainer;
  12034. var pre = tmpNode.previousSibling;
  12035. if(pre && domUtils.isTagNode(pre,'hr')){
  12036. domUtils.remove(pre);
  12037. rng.select();
  12038. domUtils.preventDefault(evt);
  12039. return true;
  12040. }
  12041. }
  12042. })
  12043. };
  12044. // plugins/time.js
  12045. /**
  12046. * 插入时间和日期
  12047. * @file
  12048. * @since 1.2.6.1
  12049. */
  12050. /**
  12051. * 插入时间,默认格式:12:59:59
  12052. * @command time
  12053. * @method execCommand
  12054. * @param { String } cmd 命令字符串
  12055. * @example
  12056. * ```javascript
  12057. * editor.execCommand( 'time');
  12058. * ```
  12059. */
  12060. /**
  12061. * 插入日期,默认格式:2013-08-30
  12062. * @command date
  12063. * @method execCommand
  12064. * @param { String } cmd 命令字符串
  12065. * @example
  12066. * ```javascript
  12067. * editor.execCommand( 'date');
  12068. * ```
  12069. */
  12070. UE.commands['time'] = UE.commands["date"] = {
  12071. execCommand : function(cmd, format){
  12072. var date = new Date;
  12073. function formatTime(date, format) {
  12074. var hh = ('0' + date.getHours()).slice(-2),
  12075. ii = ('0' + date.getMinutes()).slice(-2),
  12076. ss = ('0' + date.getSeconds()).slice(-2);
  12077. format = format || 'hh:ii:ss';
  12078. return format.replace(/hh/ig, hh).replace(/ii/ig, ii).replace(/ss/ig, ss);
  12079. }
  12080. function formatDate(date, format) {
  12081. var yyyy = ('000' + date.getFullYear()).slice(-4),
  12082. yy = yyyy.slice(-2),
  12083. mm = ('0' + (date.getMonth()+1)).slice(-2),
  12084. dd = ('0' + date.getDate()).slice(-2);
  12085. format = format || 'yyyy-mm-dd';
  12086. return format.replace(/yyyy/ig, yyyy).replace(/yy/ig, yy).replace(/mm/ig, mm).replace(/dd/ig, dd);
  12087. }
  12088. this.execCommand('insertHtml',cmd == "time" ? formatTime(date, format):formatDate(date, format) );
  12089. }
  12090. };
  12091. // plugins/rowspacing.js
  12092. /**
  12093. * 段前段后间距插件
  12094. * @file
  12095. * @since 1.2.6.1
  12096. */
  12097. /**
  12098. * 设置段间距
  12099. * @command rowspacing
  12100. * @method execCommand
  12101. * @param { String } cmd 命令字符串
  12102. * @param { String } value 段间距的值,以px为单位
  12103. * @param { String } dir 间距位置,top或bottom,分别表示段前和段后
  12104. * @example
  12105. * ```javascript
  12106. * editor.execCommand( 'rowspacing', '10', 'top' );
  12107. * ```
  12108. */
  12109. UE.plugins['rowspacing'] = function(){
  12110. var me = this;
  12111. me.setOpt({
  12112. 'rowspacingtop':['5', '10', '15', '20', '25'],
  12113. 'rowspacingbottom':['5', '10', '15', '20', '25']
  12114. });
  12115. me.commands['rowspacing'] = {
  12116. execCommand : function( cmdName,value,dir ) {
  12117. this.execCommand('paragraph','p',{style:'margin-'+dir+':'+value + 'px'});
  12118. return true;
  12119. },
  12120. queryCommandValue : function(cmdName,dir) {
  12121. var pN = domUtils.filterNodeList(this.selection.getStartElementPath(),function(node){return domUtils.isBlockElm(node) }),
  12122. value;
  12123. //trace:1026
  12124. if(pN){
  12125. value = domUtils.getComputedStyle(pN,'margin-'+dir).replace(/[^\d]/g,'');
  12126. return !value ? 0 : value;
  12127. }
  12128. return 0;
  12129. }
  12130. };
  12131. };
  12132. // plugins/lineheight.js
  12133. /**
  12134. * 设置行内间距
  12135. * @file
  12136. * @since 1.2.6.1
  12137. */
  12138. UE.plugins['lineheight'] = function(){
  12139. var me = this;
  12140. me.setOpt({'lineheight':['1', '1.5','1.75','2', '3', '4', '5']});
  12141. /**
  12142. * 行距
  12143. * @command lineheight
  12144. * @method execCommand
  12145. * @param { String } cmdName 命令字符串
  12146. * @param { String } value 传入的行高值, 该值是当前字体的倍数, 例如: 1.5, 1.75
  12147. * @example
  12148. * ```javascript
  12149. * editor.execCommand( 'lineheight', 1.5);
  12150. * ```
  12151. */
  12152. /**
  12153. * 查询当前选区内容的行高大小
  12154. * @command lineheight
  12155. * @method queryCommandValue
  12156. * @param { String } cmd 命令字符串
  12157. * @return { String } 返回当前行高大小
  12158. * @example
  12159. * ```javascript
  12160. * editor.queryCommandValue( 'lineheight' );
  12161. * ```
  12162. */
  12163. me.commands['lineheight'] = {
  12164. execCommand : function( cmdName,value ) {
  12165. this.execCommand('paragraph','p',{style:'line-height:'+ (value == "1" ? "normal" : value + 'em') });
  12166. return true;
  12167. },
  12168. queryCommandValue : function() {
  12169. var pN = domUtils.filterNodeList(this.selection.getStartElementPath(),function(node){return domUtils.isBlockElm(node)});
  12170. if(pN){
  12171. var value = domUtils.getComputedStyle(pN,'line-height');
  12172. return value == 'normal' ? 1 : value.replace(/[^\d.]*/ig,"");
  12173. }
  12174. }
  12175. };
  12176. };
  12177. // plugins/insertcode.js
  12178. /**
  12179. * 插入代码插件
  12180. * @file
  12181. * @since 1.2.6.1
  12182. */
  12183. UE.plugins['insertcode'] = function() {
  12184. var me = this;
  12185. me.ready(function(){
  12186. utils.cssRule('pre','pre{margin:.5em 0;padding:.4em .6em;border-radius:8px;background:#f8f8f8;}',
  12187. me.document)
  12188. });
  12189. me.setOpt('insertcode',{
  12190. 'as3':'ActionScript3',
  12191. 'bash':'Bash/Shell',
  12192. 'cpp':'C/C++',
  12193. 'css':'Css',
  12194. 'cf':'CodeFunction',
  12195. 'c#':'C#',
  12196. 'delphi':'Delphi',
  12197. 'diff':'Diff',
  12198. 'erlang':'Erlang',
  12199. 'groovy':'Groovy',
  12200. 'html':'Html',
  12201. 'java':'Java',
  12202. 'jfx':'JavaFx',
  12203. 'js':'Javascript',
  12204. 'pl':'Perl',
  12205. 'php':'Php',
  12206. 'plain':'Plain Text',
  12207. 'ps':'PowerShell',
  12208. 'python':'Python',
  12209. 'ruby':'Ruby',
  12210. 'scala':'Scala',
  12211. 'sql':'Sql',
  12212. 'vb':'Vb',
  12213. 'xml':'Xml'
  12214. });
  12215. /**
  12216. * 插入代码
  12217. * @command insertcode
  12218. * @method execCommand
  12219. * @param { String } cmd 命令字符串
  12220. * @param { String } lang 插入代码的语言
  12221. * @example
  12222. * ```javascript
  12223. * editor.execCommand( 'insertcode', 'javascript' );
  12224. * ```
  12225. */
  12226. /**
  12227. * 如果选区所在位置是插入插入代码区域,返回代码的语言
  12228. * @command insertcode
  12229. * @method queryCommandValue
  12230. * @param { String } cmd 命令字符串
  12231. * @return { String } 返回代码的语言
  12232. * @example
  12233. * ```javascript
  12234. * editor.queryCommandValue( 'insertcode' );
  12235. * ```
  12236. */
  12237. me.commands['insertcode'] = {
  12238. execCommand : function(cmd,lang){
  12239. var me = this,
  12240. rng = me.selection.getRange(),
  12241. pre = domUtils.findParentByTagName(rng.startContainer,'pre',true);
  12242. if(pre){
  12243. pre.className = 'brush:'+lang+';toolbar:false;';
  12244. }else{
  12245. var code = '';
  12246. if(rng.collapsed){
  12247. code = browser.ie && browser.ie11below ? (browser.version <= 8 ? '&nbsp;':''):'<br/>';
  12248. }else{
  12249. var frag = rng.extractContents();
  12250. var div = me.document.createElement('div');
  12251. div.appendChild(frag);
  12252. utils.each(UE.filterNode(UE.htmlparser(div.innerHTML.replace(/[\r\t]/g,'')),me.options.filterTxtRules).children,function(node){
  12253. if(browser.ie && browser.ie11below && browser.version > 8){
  12254. if(node.type =='element'){
  12255. if(node.tagName == 'br'){
  12256. code += '\n'
  12257. }else if(!dtd.$empty[node.tagName]){
  12258. utils.each(node.children,function(cn){
  12259. if(cn.type =='element'){
  12260. if(cn.tagName == 'br'){
  12261. code += '\n'
  12262. }else if(!dtd.$empty[node.tagName]){
  12263. code += cn.innerText();
  12264. }
  12265. }else{
  12266. code += cn.data
  12267. }
  12268. })
  12269. if(!/\n$/.test(code)){
  12270. code += '\n';
  12271. }
  12272. }
  12273. }else{
  12274. code += node.data + '\n'
  12275. }
  12276. if(!node.nextSibling() && /\n$/.test(code)){
  12277. code = code.replace(/\n$/,'');
  12278. }
  12279. }else{
  12280. if(browser.ie && browser.ie11below){
  12281. if(node.type =='element'){
  12282. if(node.tagName == 'br'){
  12283. code += '<br>'
  12284. }else if(!dtd.$empty[node.tagName]){
  12285. utils.each(node.children,function(cn){
  12286. if(cn.type =='element'){
  12287. if(cn.tagName == 'br'){
  12288. code += '<br>'
  12289. }else if(!dtd.$empty[node.tagName]){
  12290. code += cn.innerText();
  12291. }
  12292. }else{
  12293. code += cn.data
  12294. }
  12295. });
  12296. if(!/br>$/.test(code)){
  12297. code += '<br>';
  12298. }
  12299. }
  12300. }else{
  12301. code += node.data + '<br>'
  12302. }
  12303. if(!node.nextSibling() && /<br>$/.test(code)){
  12304. code = code.replace(/<br>$/,'');
  12305. }
  12306. }else{
  12307. code += (node.type == 'element' ? (dtd.$empty[node.tagName] ? '' : node.innerText()) : node.data);
  12308. if(!/br\/?\s*>$/.test(code)){
  12309. if(!node.nextSibling())
  12310. return;
  12311. code += '<br>'
  12312. }
  12313. }
  12314. }
  12315. });
  12316. }
  12317. me.execCommand('inserthtml','<pre id="coder"class="brush:'+lang+';toolbar:false">'+code+'</pre>',true);
  12318. pre = me.document.getElementById('coder');
  12319. domUtils.removeAttributes(pre,'id');
  12320. var tmpNode = pre.previousSibling;
  12321. if(tmpNode && (tmpNode.nodeType == 3 && tmpNode.nodeValue.length == 1 && browser.ie && browser.version == 6 || domUtils.isEmptyBlock(tmpNode))){
  12322. domUtils.remove(tmpNode)
  12323. }
  12324. var rng = me.selection.getRange();
  12325. if(domUtils.isEmptyBlock(pre)){
  12326. rng.setStart(pre,0).setCursor(false,true)
  12327. }else{
  12328. rng.selectNodeContents(pre).select()
  12329. }
  12330. }
  12331. },
  12332. queryCommandValue : function(){
  12333. var path = this.selection.getStartElementPath();
  12334. var lang = '';
  12335. utils.each(path,function(node){
  12336. if(node.nodeName =='PRE'){
  12337. var match = node.className.match(/brush:([^;]+)/);
  12338. lang = match && match[1] ? match[1] : '';
  12339. return false;
  12340. }
  12341. });
  12342. return lang;
  12343. }
  12344. };
  12345. me.addInputRule(function(root){
  12346. utils.each(root.getNodesByTagName('pre'),function(pre){
  12347. var brs = pre.getNodesByTagName('br');
  12348. if(brs.length){
  12349. browser.ie && browser.ie11below && browser.version > 8 && utils.each(brs,function(br){
  12350. var txt = UE.uNode.createText('\n');
  12351. br.parentNode.insertBefore(txt,br);
  12352. br.parentNode.removeChild(br);
  12353. });
  12354. return;
  12355. }
  12356. if(browser.ie && browser.ie11below && browser.version > 8)
  12357. return;
  12358. var code = pre.innerText().split(/\n/);
  12359. pre.innerHTML('');
  12360. utils.each(code,function(c){
  12361. if(c.length){
  12362. pre.appendChild(UE.uNode.createText(c));
  12363. }
  12364. pre.appendChild(UE.uNode.createElement('br'))
  12365. })
  12366. })
  12367. });
  12368. me.addOutputRule(function(root){
  12369. utils.each(root.getNodesByTagName('pre'),function(pre){
  12370. var code = '';
  12371. utils.each(pre.children,function(n){
  12372. if(n.type == 'text'){
  12373. //在ie下文本内容有可能末尾带有\n要去掉
  12374. //trace:3396
  12375. code += n.data.replace(/[ ]/g,'&nbsp;').replace(/\n$/,'');
  12376. }else{
  12377. if(n.tagName == 'br'){
  12378. code += '\n'
  12379. }else{
  12380. code += (!dtd.$empty[n.tagName] ? '' : n.innerText());
  12381. }
  12382. }
  12383. });
  12384. pre.innerText(code.replace(/(&nbsp;|\n)+$/,''))
  12385. })
  12386. });
  12387. //不需要判断highlight的command列表
  12388. me.notNeedCodeQuery ={
  12389. help:1,
  12390. undo:1,
  12391. redo:1,
  12392. source:1,
  12393. print:1,
  12394. searchreplace:1,
  12395. fullscreen:1,
  12396. preview:1,
  12397. insertparagraph:1,
  12398. elementpath:1,
  12399. insertcode:1,
  12400. inserthtml:1,
  12401. selectall:1
  12402. };
  12403. //将queyCommamndState重置
  12404. var orgQuery = me.queryCommandState;
  12405. me.queryCommandState = function(cmd){
  12406. var me = this;
  12407. if(!me.notNeedCodeQuery[cmd.toLowerCase()] && me.selection && me.queryCommandValue('insertcode')){
  12408. return -1;
  12409. }
  12410. return UE.Editor.prototype.queryCommandState.apply(this,arguments)
  12411. };
  12412. me.addListener('beforeenterkeydown',function(){
  12413. var rng = me.selection.getRange();
  12414. var pre = domUtils.findParentByTagName(rng.startContainer,'pre',true);
  12415. if(pre){
  12416. me.fireEvent('saveScene');
  12417. if(!rng.collapsed){
  12418. rng.deleteContents();
  12419. }
  12420. if(!browser.ie || browser.ie9above){
  12421. var tmpNode = me.document.createElement('br'),pre;
  12422. rng.insertNode(tmpNode).setStartAfter(tmpNode).collapse(true);
  12423. var next = tmpNode.nextSibling;
  12424. if(!next && (!browser.ie || browser.version > 10)){
  12425. rng.insertNode(tmpNode.cloneNode(false));
  12426. }else{
  12427. rng.setStartAfter(tmpNode);
  12428. }
  12429. pre = tmpNode.previousSibling;
  12430. var tmp;
  12431. while(pre ){
  12432. tmp = pre;
  12433. pre = pre.previousSibling;
  12434. if(!pre || pre.nodeName == 'BR'){
  12435. pre = tmp;
  12436. break;
  12437. }
  12438. }
  12439. if(pre){
  12440. var str = '';
  12441. while(pre && pre.nodeName != 'BR' && new RegExp('^[\\s'+domUtils.fillChar+']*$').test(pre.nodeValue)){
  12442. str += pre.nodeValue;
  12443. pre = pre.nextSibling;
  12444. }
  12445. if(pre.nodeName != 'BR'){
  12446. var match = pre.nodeValue.match(new RegExp('^([\\s'+domUtils.fillChar+']+)'));
  12447. if(match && match[1]){
  12448. str += match[1]
  12449. }
  12450. }
  12451. if(str){
  12452. str = me.document.createTextNode(str);
  12453. rng.insertNode(str).setStartAfter(str);
  12454. }
  12455. }
  12456. rng.collapse(true).select(true);
  12457. }else{
  12458. if(browser.version > 8){
  12459. var txt = me.document.createTextNode('\n');
  12460. var start = rng.startContainer;
  12461. if(rng.startOffset == 0){
  12462. var preNode = start.previousSibling;
  12463. if(preNode){
  12464. rng.insertNode(txt);
  12465. var fillchar = me.document.createTextNode(' ');
  12466. rng.setStartAfter(txt).insertNode(fillchar).setStart(fillchar,0).collapse(true).select(true)
  12467. }
  12468. }else{
  12469. rng.insertNode(txt).setStartAfter(txt);
  12470. var fillchar = me.document.createTextNode(' ');
  12471. start = rng.startContainer.childNodes[rng.startOffset];
  12472. if(start && !/^\n/.test(start.nodeValue)){
  12473. rng.setStartBefore(txt)
  12474. }
  12475. rng.insertNode(fillchar).setStart(fillchar,0).collapse(true).select(true)
  12476. }
  12477. }else{
  12478. var tmpNode = me.document.createElement('br');
  12479. rng.insertNode(tmpNode);
  12480. rng.insertNode(me.document.createTextNode(domUtils.fillChar));
  12481. rng.setStartAfter(tmpNode);
  12482. pre = tmpNode.previousSibling;
  12483. var tmp;
  12484. while(pre ){
  12485. tmp = pre;
  12486. pre = pre.previousSibling;
  12487. if(!pre || pre.nodeName == 'BR'){
  12488. pre = tmp;
  12489. break;
  12490. }
  12491. }
  12492. if(pre){
  12493. var str = '';
  12494. while(pre && pre.nodeName != 'BR' && new RegExp('^[ '+domUtils.fillChar+']*$').test(pre.nodeValue)){
  12495. str += pre.nodeValue;
  12496. pre = pre.nextSibling;
  12497. }
  12498. if(pre.nodeName != 'BR'){
  12499. var match = pre.nodeValue.match(new RegExp('^([ '+domUtils.fillChar+']+)'));
  12500. if(match && match[1]){
  12501. str += match[1]
  12502. }
  12503. }
  12504. str = me.document.createTextNode(str);
  12505. rng.insertNode(str).setStartAfter(str);
  12506. }
  12507. rng.collapse(true).select();
  12508. }
  12509. }
  12510. me.fireEvent('saveScene');
  12511. return true;
  12512. }
  12513. });
  12514. me.addListener('tabkeydown',function(cmd,evt){
  12515. var rng = me.selection.getRange();
  12516. var pre = domUtils.findParentByTagName(rng.startContainer,'pre',true);
  12517. if(pre){
  12518. me.fireEvent('saveScene');
  12519. if(evt.shiftKey){
  12520. }else{
  12521. if(!rng.collapsed){
  12522. var bk = rng.createBookmark();
  12523. var start = bk.start.previousSibling;
  12524. while(start){
  12525. if(pre.firstChild === start && !domUtils.isBr(start)){
  12526. pre.insertBefore(me.document.createTextNode(' '),start);
  12527. break;
  12528. }
  12529. if(domUtils.isBr(start)){
  12530. pre.insertBefore(me.document.createTextNode(' '),start.nextSibling);
  12531. break;
  12532. }
  12533. start = start.previousSibling;
  12534. }
  12535. var end = bk.end;
  12536. start = bk.start.nextSibling;
  12537. if(pre.firstChild === bk.start){
  12538. pre.insertBefore(me.document.createTextNode(' '),start.nextSibling)
  12539. }
  12540. while(start && start !== end){
  12541. if(domUtils.isBr(start) && start.nextSibling){
  12542. if(start.nextSibling === end){
  12543. break;
  12544. }
  12545. pre.insertBefore(me.document.createTextNode(' '),start.nextSibling)
  12546. }
  12547. start = start.nextSibling;
  12548. }
  12549. rng.moveToBookmark(bk).select();
  12550. }else{
  12551. var tmpNode = me.document.createTextNode(' ');
  12552. rng.insertNode(tmpNode).setStartAfter(tmpNode).collapse(true).select(true);
  12553. }
  12554. }
  12555. me.fireEvent('saveScene');
  12556. return true;
  12557. }
  12558. });
  12559. me.addListener('beforeinserthtml',function(evtName,html){
  12560. var me = this,
  12561. rng = me.selection.getRange(),
  12562. pre = domUtils.findParentByTagName(rng.startContainer,'pre',true);
  12563. if(pre){
  12564. if(!rng.collapsed){
  12565. rng.deleteContents()
  12566. }
  12567. var htmlstr = '';
  12568. if(browser.ie && browser.version > 8){
  12569. utils.each(UE.filterNode(UE.htmlparser(html),me.options.filterTxtRules).children,function(node){
  12570. if(node.type =='element'){
  12571. if(node.tagName == 'br'){
  12572. htmlstr += '\n'
  12573. }else if(!dtd.$empty[node.tagName]){
  12574. utils.each(node.children,function(cn){
  12575. if(cn.type =='element'){
  12576. if(cn.tagName == 'br'){
  12577. htmlstr += '\n'
  12578. }else if(!dtd.$empty[node.tagName]){
  12579. htmlstr += cn.innerText();
  12580. }
  12581. }else{
  12582. htmlstr += cn.data
  12583. }
  12584. })
  12585. if(!/\n$/.test(htmlstr)){
  12586. htmlstr += '\n';
  12587. }
  12588. }
  12589. }else{
  12590. htmlstr += node.data + '\n'
  12591. }
  12592. if(!node.nextSibling() && /\n$/.test(htmlstr)){
  12593. htmlstr = htmlstr.replace(/\n$/,'');
  12594. }
  12595. });
  12596. var tmpNode = me.document.createTextNode(utils.html(htmlstr.replace(/&nbsp;/g,' ')));
  12597. rng.insertNode(tmpNode).selectNode(tmpNode).select();
  12598. }else{
  12599. var frag = me.document.createDocumentFragment();
  12600. utils.each(UE.filterNode(UE.htmlparser(html),me.options.filterTxtRules).children,function(node){
  12601. if(node.type =='element'){
  12602. if(node.tagName == 'br'){
  12603. frag.appendChild(me.document.createElement('br'))
  12604. }else if(!dtd.$empty[node.tagName]){
  12605. utils.each(node.children,function(cn){
  12606. if(cn.type =='element'){
  12607. if(cn.tagName == 'br'){
  12608. frag.appendChild(me.document.createElement('br'))
  12609. }else if(!dtd.$empty[node.tagName]){
  12610. frag.appendChild(me.document.createTextNode(utils.html(cn.innerText().replace(/&nbsp;/g,' '))));
  12611. }
  12612. }else{
  12613. frag.appendChild(me.document.createTextNode(utils.html( cn.data.replace(/&nbsp;/g,' '))));
  12614. }
  12615. })
  12616. if(frag.lastChild.nodeName != 'BR'){
  12617. frag.appendChild(me.document.createElement('br'))
  12618. }
  12619. }
  12620. }else{
  12621. frag.appendChild(me.document.createTextNode(utils.html( node.data.replace(/&nbsp;/g,' '))));
  12622. }
  12623. if(!node.nextSibling() && frag.lastChild.nodeName == 'BR'){
  12624. frag.removeChild(frag.lastChild)
  12625. }
  12626. });
  12627. rng.insertNode(frag).select();
  12628. }
  12629. return true;
  12630. }
  12631. });
  12632. //方向键的处理
  12633. me.addListener('keydown',function(cmd,evt){
  12634. var me = this,keyCode = evt.keyCode || evt.which;
  12635. if(keyCode == 40){
  12636. var rng = me.selection.getRange(),pre,start = rng.startContainer;
  12637. if(rng.collapsed && (pre = domUtils.findParentByTagName(rng.startContainer,'pre',true)) && !pre.nextSibling){
  12638. var last = pre.lastChild
  12639. while(last && last.nodeName == 'BR'){
  12640. last = last.previousSibling;
  12641. }
  12642. if(last === start || rng.startContainer === pre && rng.startOffset == pre.childNodes.length){
  12643. me.execCommand('insertparagraph');
  12644. domUtils.preventDefault(evt)
  12645. }
  12646. }
  12647. }
  12648. });
  12649. //trace:3395
  12650. me.addListener('delkeydown',function(type,evt){
  12651. var rng = this.selection.getRange();
  12652. rng.txtToElmBoundary(true);
  12653. var start = rng.startContainer;
  12654. if(domUtils.isTagNode(start,'pre') && rng.collapsed && domUtils.isStartInblock(rng)){
  12655. var p = me.document.createElement('p');
  12656. domUtils.fillNode(me.document,p);
  12657. start.parentNode.insertBefore(p,start);
  12658. domUtils.remove(start);
  12659. rng.setStart(p,0).setCursor(false,true);
  12660. domUtils.preventDefault(evt);
  12661. return true;
  12662. }
  12663. })
  12664. };
  12665. // plugins/cleardoc.js
  12666. /**
  12667. * 清空文档插件
  12668. * @file
  12669. * @since 1.2.6.1
  12670. */
  12671. /**
  12672. * 清空文档
  12673. * @command cleardoc
  12674. * @method execCommand
  12675. * @param { String } cmd 命令字符串
  12676. * @example
  12677. * ```javascript
  12678. * //editor 是编辑器实例
  12679. * editor.execCommand('cleardoc');
  12680. * ```
  12681. */
  12682. UE.commands['cleardoc'] = {
  12683. execCommand : function( cmdName) {
  12684. var me = this,
  12685. enterTag = me.options.enterTag,
  12686. range = me.selection.getRange();
  12687. if(enterTag == "br"){
  12688. me.body.innerHTML = "<br/>";
  12689. range.setStart(me.body,0).setCursor();
  12690. }else{
  12691. me.body.innerHTML = "<p>"+(ie ? "" : "<br/>")+"</p>";
  12692. range.setStart(me.body.firstChild,0).setCursor(false,true);
  12693. }
  12694. setTimeout(function(){
  12695. me.fireEvent("clearDoc");
  12696. },0);
  12697. }
  12698. };
  12699. // plugins/anchor.js
  12700. /**
  12701. * 锚点插件,为UEditor提供插入锚点支持
  12702. * @file
  12703. * @since 1.2.6.1
  12704. */
  12705. UE.plugin.register('anchor', function (){
  12706. return {
  12707. bindEvents:{
  12708. 'ready':function(){
  12709. utils.cssRule('anchor',
  12710. '.anchorclass{background: url(\''
  12711. + this.options.themePath
  12712. + this.options.theme +'/images/anchor.gif\') no-repeat scroll left center transparent;cursor: auto;display: inline-block;height: 16px;width: 15px;}',
  12713. this.document);
  12714. }
  12715. },
  12716. outputRule: function(root){
  12717. utils.each(root.getNodesByTagName('img'),function(a){
  12718. var val;
  12719. if(val = a.getAttr('anchorname')){
  12720. a.tagName = 'a';
  12721. a.setAttr({
  12722. anchorname : '',
  12723. name : val,
  12724. 'class' : ''
  12725. })
  12726. }
  12727. })
  12728. },
  12729. inputRule:function(root){
  12730. utils.each(root.getNodesByTagName('a'),function(a){
  12731. var val;
  12732. if((val = a.getAttr('name')) && !a.getAttr('href')){
  12733. a.tagName = 'img';
  12734. a.setAttr({
  12735. anchorname :a.getAttr('name'),
  12736. 'class' : 'anchorclass'
  12737. });
  12738. a.setAttr('name')
  12739. }
  12740. })
  12741. },
  12742. commands:{
  12743. /**
  12744. * 插入锚点
  12745. * @command anchor
  12746. * @method execCommand
  12747. * @param { String } cmd 命令字符串
  12748. * @param { String } name 锚点名称字符串
  12749. * @example
  12750. * ```javascript
  12751. * //editor 是编辑器实例
  12752. * editor.execCommand('anchor', 'anchor1');
  12753. * ```
  12754. */
  12755. 'anchor':{
  12756. execCommand:function (cmd, name) {
  12757. var range = this.selection.getRange(),img = range.getClosedNode();
  12758. if (img && img.getAttribute('anchorname')) {
  12759. if (name) {
  12760. img.setAttribute('anchorname', name);
  12761. } else {
  12762. range.setStartBefore(img).setCursor();
  12763. domUtils.remove(img);
  12764. }
  12765. } else {
  12766. if (name) {
  12767. //只在选区的开始插入
  12768. var anchor = this.document.createElement('img');
  12769. range.collapse(true);
  12770. domUtils.setAttributes(anchor,{
  12771. 'anchorname':name,
  12772. 'class':'anchorclass'
  12773. });
  12774. range.insertNode(anchor).setStartAfter(anchor).setCursor(false,true);
  12775. }
  12776. }
  12777. }
  12778. }
  12779. }
  12780. }
  12781. });
  12782. // plugins/wordcount.js
  12783. ///import core
  12784. ///commands 字数统计
  12785. ///commandsName WordCount,wordCount
  12786. ///commandsTitle 字数统计
  12787. /*
  12788. * Created by JetBrains WebStorm.
  12789. * User: taoqili
  12790. * Date: 11-9-7
  12791. * Time: 下午8:18
  12792. * To change this template use File | Settings | File Templates.
  12793. */
  12794. UE.plugins['wordcount'] = function(){
  12795. var me = this;
  12796. me.setOpt('wordCount',true);
  12797. me.addListener('contentchange',function(){
  12798. me.fireEvent('wordcount');
  12799. });
  12800. var timer;
  12801. me.addListener('ready',function(){
  12802. var me = this;
  12803. domUtils.on(me.body,"keyup",function(evt){
  12804. var code = evt.keyCode||evt.which,
  12805. //忽略的按键,ctr,alt,shift,方向键
  12806. ignores = {"16":1,"18":1,"20":1,"37":1,"38":1,"39":1,"40":1};
  12807. if(code in ignores) return;
  12808. clearTimeout(timer);
  12809. timer = setTimeout(function(){
  12810. me.fireEvent('wordcount');
  12811. },200)
  12812. })
  12813. });
  12814. };
  12815. // plugins/pagebreak.js
  12816. /**
  12817. * 分页功能插件
  12818. * @file
  12819. * @since 1.2.6.1
  12820. */
  12821. UE.plugins['pagebreak'] = function () {
  12822. var me = this,
  12823. notBreakTags = ['td'];
  12824. me.setOpt('pageBreakTag','_ueditor_page_break_tag_');
  12825. function fillNode(node){
  12826. if(domUtils.isEmptyBlock(node)){
  12827. var firstChild = node.firstChild,tmpNode;
  12828. while(firstChild && firstChild.nodeType == 1 && domUtils.isEmptyBlock(firstChild)){
  12829. tmpNode = firstChild;
  12830. firstChild = firstChild.firstChild;
  12831. }
  12832. !tmpNode && (tmpNode = node);
  12833. domUtils.fillNode(me.document,tmpNode);
  12834. }
  12835. }
  12836. //分页符样式添加
  12837. me.ready(function(){
  12838. utils.cssRule('pagebreak','.pagebreak{display:block;clear:both !important;cursor:default !important;width: 100% !important;margin:0;}',me.document);
  12839. });
  12840. function isHr(node){
  12841. return node && node.nodeType == 1 && node.tagName == 'HR' && node.className == 'pagebreak';
  12842. }
  12843. me.addInputRule(function(root){
  12844. root.traversal(function(node){
  12845. if(node.type == 'text' && node.data == me.options.pageBreakTag){
  12846. var hr = UE.uNode.createElement('<hr class="pagebreak" noshade="noshade" size="5" style="-webkit-user-select: none;">');
  12847. node.parentNode.insertBefore(hr,node);
  12848. node.parentNode.removeChild(node)
  12849. }
  12850. })
  12851. });
  12852. me.addOutputRule(function(node){
  12853. utils.each(node.getNodesByTagName('hr'),function(n){
  12854. if(n.getAttr('class') == 'pagebreak'){
  12855. var txt = UE.uNode.createText(me.options.pageBreakTag);
  12856. n.parentNode.insertBefore(txt,n);
  12857. n.parentNode.removeChild(n);
  12858. }
  12859. })
  12860. });
  12861. /**
  12862. * 插入分页符
  12863. * @command pagebreak
  12864. * @method execCommand
  12865. * @param { String } cmd 命令字符串
  12866. * @remind 在表格中插入分页符会把表格切分成两部分
  12867. * @remind 获取编辑器内的数据时, 编辑器会把分页符转换成“_ueditor_page_break_tag_”字符串,
  12868. * 以便于提交数据到服务器端后处理分页。
  12869. * @example
  12870. * ```javascript
  12871. * editor.execCommand( 'pagebreak'); //插入一个hr标签,带有样式类名pagebreak
  12872. * ```
  12873. */
  12874. me.commands['pagebreak'] = {
  12875. execCommand:function () {
  12876. var range = me.selection.getRange(),hr = me.document.createElement('hr');
  12877. domUtils.setAttributes(hr,{
  12878. 'class' : 'pagebreak',
  12879. noshade:"noshade",
  12880. size:"5"
  12881. });
  12882. domUtils.unSelectable(hr);
  12883. //table单独处理
  12884. var node = domUtils.findParentByTagName(range.startContainer, notBreakTags, true),
  12885. parents = [], pN;
  12886. if (node) {
  12887. switch (node.tagName) {
  12888. case 'TD':
  12889. pN = node.parentNode;
  12890. if (!pN.previousSibling) {
  12891. var table = domUtils.findParentByTagName(pN, 'table');
  12892. // var tableWrapDiv = table.parentNode;
  12893. // if(tableWrapDiv && tableWrapDiv.nodeType == 1
  12894. // && tableWrapDiv.tagName == 'DIV'
  12895. // && tableWrapDiv.getAttribute('dropdrag')
  12896. // ){
  12897. // domUtils.remove(tableWrapDiv,true);
  12898. // }
  12899. table.parentNode.insertBefore(hr, table);
  12900. parents = domUtils.findParents(hr, true);
  12901. } else {
  12902. pN.parentNode.insertBefore(hr, pN);
  12903. parents = domUtils.findParents(hr);
  12904. }
  12905. pN = parents[1];
  12906. if (hr !== pN) {
  12907. domUtils.breakParent(hr, pN);
  12908. }
  12909. //table要重写绑定一下拖拽
  12910. me.fireEvent('afteradjusttable',me.document);
  12911. }
  12912. } else {
  12913. if (!range.collapsed) {
  12914. range.deleteContents();
  12915. var start = range.startContainer;
  12916. while ( !domUtils.isBody(start) && domUtils.isBlockElm(start) && domUtils.isEmptyNode(start)) {
  12917. range.setStartBefore(start).collapse(true);
  12918. domUtils.remove(start);
  12919. start = range.startContainer;
  12920. }
  12921. }
  12922. range.insertNode(hr);
  12923. var pN = hr.parentNode, nextNode;
  12924. while (!domUtils.isBody(pN)) {
  12925. domUtils.breakParent(hr, pN);
  12926. nextNode = hr.nextSibling;
  12927. if (nextNode && domUtils.isEmptyBlock(nextNode)) {
  12928. domUtils.remove(nextNode);
  12929. }
  12930. pN = hr.parentNode;
  12931. }
  12932. nextNode = hr.nextSibling;
  12933. var pre = hr.previousSibling;
  12934. if(isHr(pre)){
  12935. domUtils.remove(pre);
  12936. }else{
  12937. pre && fillNode(pre);
  12938. }
  12939. if(!nextNode){
  12940. var p = me.document.createElement('p');
  12941. hr.parentNode.appendChild(p);
  12942. domUtils.fillNode(me.document,p);
  12943. range.setStart(p,0).collapse(true);
  12944. }else{
  12945. if(isHr(nextNode)){
  12946. domUtils.remove(nextNode);
  12947. }else{
  12948. fillNode(nextNode);
  12949. }
  12950. range.setEndAfter(hr).collapse(false);
  12951. }
  12952. range.select(true);
  12953. }
  12954. }
  12955. };
  12956. };
  12957. // plugins/wordimage.js
  12958. ///import core
  12959. ///commands 本地图片引导上传
  12960. ///commandsName WordImage
  12961. ///commandsTitle 本地图片引导上传
  12962. ///commandsDialog dialogs\wordimage
  12963. UE.plugin.register('wordimage',function(){
  12964. var me = this,
  12965. images = [];
  12966. return {
  12967. commands : {
  12968. 'wordimage':{
  12969. execCommand:function () {
  12970. var images = domUtils.getElementsByTagName(me.body, "img");
  12971. var urlList = [];
  12972. for (var i = 0, ci; ci = images[i++];) {
  12973. var url = ci.getAttribute("word_img");
  12974. url && urlList.push(url);
  12975. }
  12976. return urlList;
  12977. },
  12978. queryCommandState:function () {
  12979. images = domUtils.getElementsByTagName(me.body, "img");
  12980. for (var i = 0, ci; ci = images[i++];) {
  12981. if (ci.getAttribute("word_img")) {
  12982. return 1;
  12983. }
  12984. }
  12985. return -1;
  12986. },
  12987. notNeedUndo:true
  12988. }
  12989. },
  12990. inputRule : function (root) {
  12991. utils.each(root.getNodesByTagName('img'), function (img) {
  12992. var attrs = img.attrs,
  12993. flag = parseInt(attrs.width) < 128 || parseInt(attrs.height) < 43,
  12994. opt = me.options,
  12995. src = opt.UEDITOR_HOME_URL + 'themes/default/images/spacer.gif';
  12996. if (attrs['src'] && /^(?:(file:\/+))/.test(attrs['src'])) {
  12997. img.setAttr({
  12998. width:attrs.width,
  12999. height:attrs.height,
  13000. alt:attrs.alt,
  13001. word_img: attrs.src,
  13002. src:src,
  13003. 'style':'background:url(' + ( flag ? opt.themePath + opt.theme + '/images/word.gif' : opt.langPath + opt.lang + '/images/localimage.png') + ') no-repeat center center;border:1px solid #ddd'
  13004. })
  13005. }
  13006. })
  13007. }
  13008. }
  13009. });
  13010. // plugins/dragdrop.js
  13011. UE.plugins['dragdrop'] = function (){
  13012. var me = this;
  13013. me.ready(function(){
  13014. domUtils.on(this.body,'dragend',function(){
  13015. var rng = me.selection.getRange();
  13016. var node = rng.getClosedNode()||me.selection.getStart();
  13017. if(node && node.tagName == 'IMG'){
  13018. var pre = node.previousSibling,next;
  13019. while(next = node.nextSibling){
  13020. if(next.nodeType == 1 && next.tagName == 'SPAN' && !next.firstChild){
  13021. domUtils.remove(next)
  13022. }else{
  13023. break;
  13024. }
  13025. }
  13026. if((pre && pre.nodeType == 1 && !domUtils.isEmptyBlock(pre) || !pre) && (!next || next && !domUtils.isEmptyBlock(next))){
  13027. if(pre && pre.tagName == 'P' && !domUtils.isEmptyBlock(pre)){
  13028. pre.appendChild(node);
  13029. domUtils.moveChild(next,pre);
  13030. domUtils.remove(next);
  13031. }else if(next && next.tagName == 'P' && !domUtils.isEmptyBlock(next)){
  13032. next.insertBefore(node,next.firstChild);
  13033. }
  13034. if(pre && pre.tagName == 'P' && domUtils.isEmptyBlock(pre)){
  13035. domUtils.remove(pre)
  13036. }
  13037. if(next && next.tagName == 'P' && domUtils.isEmptyBlock(next)){
  13038. domUtils.remove(next)
  13039. }
  13040. rng.selectNode(node).select();
  13041. me.fireEvent('saveScene');
  13042. }
  13043. }
  13044. })
  13045. });
  13046. me.addListener('keyup', function(type, evt) {
  13047. var keyCode = evt.keyCode || evt.which;
  13048. if (keyCode == 13) {
  13049. var rng = me.selection.getRange(),node;
  13050. if(node = domUtils.findParentByTagName(rng.startContainer,'p',true)){
  13051. if(domUtils.getComputedStyle(node,'text-align') == 'center'){
  13052. domUtils.removeStyle(node,'text-align')
  13053. }
  13054. }
  13055. }
  13056. })
  13057. };
  13058. // plugins/undo.js
  13059. /**
  13060. * undo redo
  13061. * @file
  13062. * @since 1.2.6.1
  13063. */
  13064. /**
  13065. * 撤销上一次执行的命令
  13066. * @command undo
  13067. * @method execCommand
  13068. * @param { String } cmd 命令字符串
  13069. * @example
  13070. * ```javascript
  13071. * editor.execCommand( 'undo' );
  13072. * ```
  13073. */
  13074. /**
  13075. * 重做上一次执行的命令
  13076. * @command redo
  13077. * @method execCommand
  13078. * @param { String } cmd 命令字符串
  13079. * @example
  13080. * ```javascript
  13081. * editor.execCommand( 'redo' );
  13082. * ```
  13083. */
  13084. UE.plugins['undo'] = function () {
  13085. var saveSceneTimer;
  13086. var me = this,
  13087. maxUndoCount = me.options.maxUndoCount || 20,
  13088. maxInputCount = me.options.maxInputCount || 20,
  13089. fillchar = new RegExp(domUtils.fillChar + '|<\/hr>', 'gi');// ie会产生多余的</hr>
  13090. var noNeedFillCharTags = {
  13091. ol:1,ul:1,table:1,tbody:1,tr:1,body:1
  13092. };
  13093. var orgState = me.options.autoClearEmptyNode;
  13094. function compareAddr(indexA, indexB) {
  13095. if (indexA.length != indexB.length)
  13096. return 0;
  13097. for (var i = 0, l = indexA.length; i < l; i++) {
  13098. if (indexA[i] != indexB[i])
  13099. return 0
  13100. }
  13101. return 1;
  13102. }
  13103. function compareRangeAddress(rngAddrA, rngAddrB) {
  13104. if (rngAddrA.collapsed != rngAddrB.collapsed) {
  13105. return 0;
  13106. }
  13107. if (!compareAddr(rngAddrA.startAddress, rngAddrB.startAddress) || !compareAddr(rngAddrA.endAddress, rngAddrB.endAddress)) {
  13108. return 0;
  13109. }
  13110. return 1;
  13111. }
  13112. function UndoManager() {
  13113. this.list = [];
  13114. this.index = 0;
  13115. this.hasUndo = false;
  13116. this.hasRedo = false;
  13117. this.undo = function () {
  13118. if (this.hasUndo) {
  13119. if (!this.list[this.index - 1] && this.list.length == 1) {
  13120. this.reset();
  13121. return;
  13122. }
  13123. while (this.list[this.index].content == this.list[this.index - 1].content) {
  13124. this.index--;
  13125. if (this.index == 0) {
  13126. return this.restore(0);
  13127. }
  13128. }
  13129. this.restore(--this.index);
  13130. }
  13131. };
  13132. this.redo = function () {
  13133. if (this.hasRedo) {
  13134. while (this.list[this.index].content == this.list[this.index + 1].content) {
  13135. this.index++;
  13136. if (this.index == this.list.length - 1) {
  13137. return this.restore(this.index);
  13138. }
  13139. }
  13140. this.restore(++this.index);
  13141. }
  13142. };
  13143. this.restore = function () {
  13144. var me = this.editor;
  13145. var scene = this.list[this.index];
  13146. var root = UE.htmlparser(scene.content.replace(fillchar, ''));
  13147. me.options.autoClearEmptyNode = false;
  13148. me.filterInputRule(root);
  13149. me.options.autoClearEmptyNode = orgState;
  13150. //trace:873
  13151. //去掉展位符
  13152. me.document.body.innerHTML = root.toHtml();
  13153. me.fireEvent('afterscencerestore');
  13154. //处理undo后空格不展位的问题
  13155. if (browser.ie) {
  13156. utils.each(domUtils.getElementsByTagName(me.document,'td th caption p'),function(node){
  13157. if(domUtils.isEmptyNode(node)){
  13158. domUtils.fillNode(me.document, node);
  13159. }
  13160. })
  13161. }
  13162. try{
  13163. var rng = new dom.Range(me.document).moveToAddress(scene.address);
  13164. rng.select(noNeedFillCharTags[rng.startContainer.nodeName.toLowerCase()]);
  13165. }catch(e){}
  13166. this.update();
  13167. this.clearKey();
  13168. //不能把自己reset了
  13169. me.fireEvent('reset', true);
  13170. };
  13171. this.getScene = function () {
  13172. var me = this.editor;
  13173. var rng = me.selection.getRange(),
  13174. rngAddress = rng.createAddress(false,true);
  13175. me.fireEvent('beforegetscene');
  13176. var root = UE.htmlparser(me.body.innerHTML);
  13177. me.options.autoClearEmptyNode = false;
  13178. me.filterOutputRule(root);
  13179. me.options.autoClearEmptyNode = orgState;
  13180. var cont = root.toHtml();
  13181. //trace:3461
  13182. //这个会引起回退时导致空格丢失的情况
  13183. // browser.ie && (cont = cont.replace(/>&nbsp;</g, '><').replace(/\s*</g, '<').replace(/>\s*/g, '>'));
  13184. me.fireEvent('aftergetscene');
  13185. return {
  13186. address:rngAddress,
  13187. content:cont
  13188. }
  13189. };
  13190. this.save = function (notCompareRange,notSetCursor) {
  13191. clearTimeout(saveSceneTimer);
  13192. var currentScene = this.getScene(notSetCursor),
  13193. lastScene = this.list[this.index];
  13194. if(lastScene && lastScene.content != currentScene.content){
  13195. me.trigger('contentchange')
  13196. }
  13197. //内容相同位置相同不存
  13198. if (lastScene && lastScene.content == currentScene.content &&
  13199. ( notCompareRange ? 1 : compareRangeAddress(lastScene.address, currentScene.address) )
  13200. ) {
  13201. return;
  13202. }
  13203. this.list = this.list.slice(0, this.index + 1);
  13204. this.list.push(currentScene);
  13205. //如果大于最大数量了,就把最前的剔除
  13206. if (this.list.length > maxUndoCount) {
  13207. this.list.shift();
  13208. }
  13209. this.index = this.list.length - 1;
  13210. this.clearKey();
  13211. //跟新undo/redo状态
  13212. this.update();
  13213. };
  13214. this.update = function () {
  13215. this.hasRedo = !!this.list[this.index + 1];
  13216. this.hasUndo = !!this.list[this.index - 1];
  13217. };
  13218. this.reset = function () {
  13219. this.list = [];
  13220. this.index = 0;
  13221. this.hasUndo = false;
  13222. this.hasRedo = false;
  13223. this.clearKey();
  13224. };
  13225. this.clearKey = function () {
  13226. keycont = 0;
  13227. lastKeyCode = null;
  13228. };
  13229. }
  13230. me.undoManger = new UndoManager();
  13231. me.undoManger.editor = me;
  13232. function saveScene() {
  13233. this.undoManger.save();
  13234. }
  13235. me.addListener('saveScene', function () {
  13236. var args = Array.prototype.splice.call(arguments,1);
  13237. this.undoManger.save.apply(this.undoManger,args);
  13238. });
  13239. // me.addListener('beforeexeccommand', saveScene);
  13240. // me.addListener('afterexeccommand', saveScene);
  13241. me.addListener('reset', function (type, exclude) {
  13242. if (!exclude) {
  13243. this.undoManger.reset();
  13244. }
  13245. });
  13246. me.commands['redo'] = me.commands['undo'] = {
  13247. execCommand:function (cmdName) {
  13248. this.undoManger[cmdName]();
  13249. },
  13250. queryCommandState:function (cmdName) {
  13251. return this.undoManger['has' + (cmdName.toLowerCase() == 'undo' ? 'Undo' : 'Redo')] ? 0 : -1;
  13252. },
  13253. notNeedUndo:1
  13254. };
  13255. var keys = {
  13256. // /*Backspace*/ 8:1, /*Delete*/ 46:1,
  13257. /*Shift*/ 16:1, /*Ctrl*/ 17:1, /*Alt*/ 18:1,
  13258. 37:1, 38:1, 39:1, 40:1
  13259. },
  13260. keycont = 0,
  13261. lastKeyCode;
  13262. //输入法状态下不计算字符数
  13263. var inputType = false;
  13264. me.addListener('ready', function () {
  13265. domUtils.on(this.body, 'compositionstart', function () {
  13266. inputType = true;
  13267. });
  13268. domUtils.on(this.body, 'compositionend', function () {
  13269. inputType = false;
  13270. })
  13271. });
  13272. //快捷键
  13273. me.addshortcutkey({
  13274. "Undo":"ctrl+90", //undo
  13275. "Redo":"ctrl+89" //redo
  13276. });
  13277. var isCollapsed = true;
  13278. me.addListener('keydown', function (type, evt) {
  13279. var me = this;
  13280. var keyCode = evt.keyCode || evt.which;
  13281. if (!keys[keyCode] && !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey) {
  13282. if (inputType)
  13283. return;
  13284. if(!me.selection.getRange().collapsed){
  13285. me.undoManger.save(false,true);
  13286. isCollapsed = false;
  13287. return;
  13288. }
  13289. if (me.undoManger.list.length == 0) {
  13290. me.undoManger.save(true);
  13291. }
  13292. clearTimeout(saveSceneTimer);
  13293. function save(cont){
  13294. cont.undoManger.save(false,true);
  13295. cont.fireEvent('selectionchange');
  13296. }
  13297. saveSceneTimer = setTimeout(function(){
  13298. if(inputType){
  13299. var interalTimer = setInterval(function(){
  13300. if(!inputType){
  13301. save(me);
  13302. clearInterval(interalTimer)
  13303. }
  13304. },300)
  13305. return;
  13306. }
  13307. save(me);
  13308. },200);
  13309. lastKeyCode = keyCode;
  13310. keycont++;
  13311. if (keycont >= maxInputCount ) {
  13312. save(me)
  13313. }
  13314. }
  13315. });
  13316. me.addListener('keyup', function (type, evt) {
  13317. var keyCode = evt.keyCode || evt.which;
  13318. if (!keys[keyCode] && !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey) {
  13319. if (inputType)
  13320. return;
  13321. if(!isCollapsed){
  13322. this.undoManger.save(false,true);
  13323. isCollapsed = true;
  13324. }
  13325. }
  13326. });
  13327. //扩展实例,添加关闭和开启命令undo
  13328. me.stopCmdUndo = function(){
  13329. me.__hasEnterExecCommand = true;
  13330. };
  13331. me.startCmdUndo = function(){
  13332. me.__hasEnterExecCommand = false;
  13333. }
  13334. };
  13335. // plugins/copy.js
  13336. UE.plugin.register('copy', function () {
  13337. var me = this;
  13338. function initZeroClipboard() {
  13339. ZeroClipboard.config({
  13340. debug: false,
  13341. swfPath: me.options.UEDITOR_HOME_URL + 'third-party/zeroclipboard/ZeroClipboard.swf'
  13342. });
  13343. var client = me.zeroclipboard = new ZeroClipboard();
  13344. // 复制内容
  13345. client.on('copy', function (e) {
  13346. var client = e.client,
  13347. rng = me.selection.getRange(),
  13348. div = document.createElement('div');
  13349. div.appendChild(rng.cloneContents());
  13350. client.setText(div.innerText || div.textContent);
  13351. client.setHtml(div.innerHTML);
  13352. rng.select();
  13353. });
  13354. // hover事件传递到target
  13355. client.on('mouseover mouseout', function (e) {
  13356. var target = e.target;
  13357. if (e.type == 'mouseover') {
  13358. domUtils.addClass(target, 'edui-state-hover');
  13359. } else if (e.type == 'mouseout') {
  13360. domUtils.removeClasses(target, 'edui-state-hover');
  13361. }
  13362. });
  13363. // flash加载不成功
  13364. client.on('wrongflash noflash', function () {
  13365. ZeroClipboard.destroy();
  13366. });
  13367. }
  13368. return {
  13369. bindEvents: {
  13370. 'ready': function () {
  13371. if (!browser.ie) {
  13372. if (window.ZeroClipboard) {
  13373. initZeroClipboard();
  13374. } else {
  13375. utils.loadFile(document, {
  13376. src: me.options.UEDITOR_HOME_URL + "third-party/zeroclipboard/ZeroClipboard.js",
  13377. tag: "script",
  13378. type: "text/javascript",
  13379. defer: "defer"
  13380. }, function () {
  13381. initZeroClipboard();
  13382. });
  13383. }
  13384. }
  13385. }
  13386. },
  13387. commands: {
  13388. 'copy': {
  13389. execCommand: function (cmd) {
  13390. if (!me.document.execCommand('copy')) {
  13391. alert(me.getLang('copymsg'));
  13392. }
  13393. }
  13394. }
  13395. }
  13396. }
  13397. });
  13398. // plugins/paste.js
  13399. ///import core
  13400. ///import plugins/inserthtml.js
  13401. ///import plugins/undo.js
  13402. ///import plugins/serialize.js
  13403. ///commands 粘贴
  13404. ///commandsName PastePlain
  13405. ///commandsTitle 纯文本粘贴模式
  13406. /**
  13407. * @description 粘贴
  13408. * @author zhanyi
  13409. */
  13410. UE.plugins['paste'] = function () {
  13411. function getClipboardData(callback) {
  13412. var doc = this.document;
  13413. if (doc.getElementById('baidu_pastebin')) {
  13414. return;
  13415. }
  13416. var range = this.selection.getRange(),
  13417. bk = range.createBookmark(),
  13418. //创建剪贴的容器div
  13419. pastebin = doc.createElement('div');
  13420. pastebin.id = 'baidu_pastebin';
  13421. // Safari 要求div必须有内容,才能粘贴内容进来
  13422. browser.webkit && pastebin.appendChild(doc.createTextNode(domUtils.fillChar + domUtils.fillChar));
  13423. doc.body.appendChild(pastebin);
  13424. //trace:717 隐藏的span不能得到top
  13425. //bk.start.innerHTML = '&nbsp;';
  13426. bk.start.style.display = '';
  13427. pastebin.style.cssText = "position:absolute;width:1px;height:1px;overflow:hidden;left:-1000px;white-space:nowrap;top:" +
  13428. //要在现在光标平行的位置加入,否则会出现跳动的问题
  13429. domUtils.getXY(bk.start).y + 'px';
  13430. range.selectNodeContents(pastebin).select(true);
  13431. setTimeout(function () {
  13432. if (browser.webkit) {
  13433. for (var i = 0, pastebins = doc.querySelectorAll('#baidu_pastebin'), pi; pi = pastebins[i++];) {
  13434. if (domUtils.isEmptyNode(pi)) {
  13435. domUtils.remove(pi);
  13436. } else {
  13437. pastebin = pi;
  13438. break;
  13439. }
  13440. }
  13441. }
  13442. try {
  13443. pastebin.parentNode.removeChild(pastebin);
  13444. } catch (e) {
  13445. }
  13446. range.moveToBookmark(bk).select(true);
  13447. callback(pastebin);
  13448. }, 0);
  13449. }
  13450. var me = this;
  13451. me.setOpt({
  13452. retainOnlyLabelPasted : false
  13453. });
  13454. var txtContent, htmlContent, address;
  13455. function getPureHtml(html){
  13456. return html.replace(/<(\/?)([\w\-]+)([^>]*)>/gi, function (a, b, tagName, attrs) {
  13457. tagName = tagName.toLowerCase();
  13458. if ({img: 1}[tagName]) {
  13459. return a;
  13460. }
  13461. attrs = attrs.replace(/([\w\-]*?)\s*=\s*(("([^"]*)")|('([^']*)')|([^\s>]+))/gi, function (str, atr, val) {
  13462. if ({
  13463. 'src': 1,
  13464. 'href': 1,
  13465. 'name': 1
  13466. }[atr.toLowerCase()]) {
  13467. return atr + '=' + val + ' '
  13468. }
  13469. return ''
  13470. });
  13471. if ({
  13472. 'span': 1,
  13473. 'div': 1
  13474. }[tagName]) {
  13475. return ''
  13476. } else {
  13477. return '<' + b + tagName + ' ' + utils.trim(attrs) + '>'
  13478. }
  13479. });
  13480. }
  13481. function filter(div) {
  13482. var html;
  13483. if (div.firstChild) {
  13484. //去掉cut中添加的边界值
  13485. var nodes = domUtils.getElementsByTagName(div, 'span');
  13486. for (var i = 0, ni; ni = nodes[i++];) {
  13487. if (ni.id == '_baidu_cut_start' || ni.id == '_baidu_cut_end') {
  13488. domUtils.remove(ni);
  13489. }
  13490. }
  13491. if (browser.webkit) {
  13492. var brs = div.querySelectorAll('div br');
  13493. for (var i = 0, bi; bi = brs[i++];) {
  13494. var pN = bi.parentNode;
  13495. if (pN.tagName == 'DIV' && pN.childNodes.length == 1) {
  13496. pN.innerHTML = '<p><br/></p>';
  13497. domUtils.remove(pN);
  13498. }
  13499. }
  13500. var divs = div.querySelectorAll('#baidu_pastebin');
  13501. for (var i = 0, di; di = divs[i++];) {
  13502. var tmpP = me.document.createElement('p');
  13503. di.parentNode.insertBefore(tmpP, di);
  13504. while (di.firstChild) {
  13505. tmpP.appendChild(di.firstChild);
  13506. }
  13507. domUtils.remove(di);
  13508. }
  13509. var metas = div.querySelectorAll('meta');
  13510. for (var i = 0, ci; ci = metas[i++];) {
  13511. domUtils.remove(ci);
  13512. }
  13513. var brs = div.querySelectorAll('br');
  13514. for (i = 0; ci = brs[i++];) {
  13515. if (/^apple-/i.test(ci.className)) {
  13516. domUtils.remove(ci);
  13517. }
  13518. }
  13519. }
  13520. if (browser.gecko) {
  13521. var dirtyNodes = div.querySelectorAll('[_moz_dirty]');
  13522. for (i = 0; ci = dirtyNodes[i++];) {
  13523. ci.removeAttribute('_moz_dirty');
  13524. }
  13525. }
  13526. if (!browser.ie) {
  13527. var spans = div.querySelectorAll('span.Apple-style-span');
  13528. for (var i = 0, ci; ci = spans[i++];) {
  13529. domUtils.remove(ci, true);
  13530. }
  13531. }
  13532. //ie下使用innerHTML会产生多余的\r\n字符,也会产生&nbsp;这里过滤掉
  13533. html = div.innerHTML;//.replace(/>(?:(\s|&nbsp;)*?)</g,'><');
  13534. //过滤word粘贴过来的冗余属性
  13535. html = UE.filterWord(html);
  13536. //取消了忽略空白的第二个参数,粘贴过来的有些是有空白的,会被套上相关的标签
  13537. var root = UE.htmlparser(html);
  13538. //如果给了过滤规则就先进行过滤
  13539. if (me.options.filterRules) {
  13540. UE.filterNode(root, me.options.filterRules);
  13541. }
  13542. //执行默认的处理
  13543. me.filterInputRule(root);
  13544. //针对chrome的处理
  13545. if (browser.webkit) {
  13546. var br = root.lastChild();
  13547. if (br && br.type == 'element' && br.tagName == 'br') {
  13548. root.removeChild(br)
  13549. }
  13550. utils.each(me.body.querySelectorAll('div'), function (node) {
  13551. if (domUtils.isEmptyBlock(node)) {
  13552. domUtils.remove(node,true)
  13553. }
  13554. })
  13555. }
  13556. html = {'html': root.toHtml()};
  13557. me.fireEvent('beforepaste', html, root);
  13558. //抢了默认的粘贴,那后边的内容就不执行了,比如表格粘贴
  13559. if(!html.html){
  13560. return;
  13561. }
  13562. root = UE.htmlparser(html.html,true);
  13563. //如果开启了纯文本模式
  13564. if (me.queryCommandState('pasteplain') === 1) {
  13565. me.execCommand('insertHtml', UE.filterNode(root, me.options.filterTxtRules).toHtml(), true);
  13566. } else {
  13567. //文本模式
  13568. UE.filterNode(root, me.options.filterTxtRules);
  13569. txtContent = root.toHtml();
  13570. //完全模式
  13571. htmlContent = html.html;
  13572. address = me.selection.getRange().createAddress(true);
  13573. me.execCommand('insertHtml', me.getOpt('retainOnlyLabelPasted') === true ? getPureHtml(htmlContent) : htmlContent, true);
  13574. }
  13575. me.fireEvent("afterpaste", html);
  13576. }
  13577. }
  13578. me.addListener('pasteTransfer', function (cmd, plainType) {
  13579. if (address && txtContent && htmlContent && txtContent != htmlContent) {
  13580. var range = me.selection.getRange();
  13581. range.moveToAddress(address, true);
  13582. if (!range.collapsed) {
  13583. while (!domUtils.isBody(range.startContainer)
  13584. ) {
  13585. var start = range.startContainer;
  13586. if(start.nodeType == 1){
  13587. start = start.childNodes[range.startOffset];
  13588. if(!start){
  13589. range.setStartBefore(range.startContainer);
  13590. continue;
  13591. }
  13592. var pre = start.previousSibling;
  13593. if(pre && pre.nodeType == 3 && new RegExp('^[\n\r\t '+domUtils.fillChar+']*$').test(pre.nodeValue)){
  13594. range.setStartBefore(pre)
  13595. }
  13596. }
  13597. if(range.startOffset == 0){
  13598. range.setStartBefore(range.startContainer);
  13599. }else{
  13600. break;
  13601. }
  13602. }
  13603. while (!domUtils.isBody(range.endContainer)
  13604. ) {
  13605. var end = range.endContainer;
  13606. if(end.nodeType == 1){
  13607. end = end.childNodes[range.endOffset];
  13608. if(!end){
  13609. range.setEndAfter(range.endContainer);
  13610. continue;
  13611. }
  13612. var next = end.nextSibling;
  13613. if(next && next.nodeType == 3 && new RegExp('^[\n\r\t'+domUtils.fillChar+']*$').test(next.nodeValue)){
  13614. range.setEndAfter(next)
  13615. }
  13616. }
  13617. if(range.endOffset == range.endContainer[range.endContainer.nodeType == 3 ? 'nodeValue' : 'childNodes'].length){
  13618. range.setEndAfter(range.endContainer);
  13619. }else{
  13620. break;
  13621. }
  13622. }
  13623. }
  13624. range.deleteContents();
  13625. range.select(true);
  13626. me.__hasEnterExecCommand = true;
  13627. var html = htmlContent;
  13628. if (plainType === 2 ) {
  13629. html = getPureHtml(html);
  13630. } else if (plainType) {
  13631. html = txtContent;
  13632. }
  13633. me.execCommand('inserthtml', html, true);
  13634. me.__hasEnterExecCommand = false;
  13635. var rng = me.selection.getRange();
  13636. while (!domUtils.isBody(rng.startContainer) && !rng.startOffset &&
  13637. rng.startContainer[rng.startContainer.nodeType == 3 ? 'nodeValue' : 'childNodes'].length
  13638. ) {
  13639. rng.setStartBefore(rng.startContainer);
  13640. }
  13641. var tmpAddress = rng.createAddress(true);
  13642. address.endAddress = tmpAddress.startAddress;
  13643. }
  13644. });
  13645. me.addListener('ready', function () {
  13646. domUtils.on(me.body, 'cut', function () {
  13647. var range = me.selection.getRange();
  13648. if (!range.collapsed && me.undoManger) {
  13649. me.undoManger.save();
  13650. }
  13651. });
  13652. //ie下beforepaste在点击右键时也会触发,所以用监控键盘才处理
  13653. domUtils.on(me.body, browser.ie || browser.opera ? 'keydown' : 'paste', function (e) {
  13654. if ((browser.ie || browser.opera) && ((!e.ctrlKey && !e.metaKey) || e.keyCode != '86')) {
  13655. return;
  13656. }
  13657. getClipboardData.call(me, function (div) {
  13658. filter(div);
  13659. });
  13660. });
  13661. });
  13662. me.commands['paste'] = {
  13663. execCommand: function (cmd) {
  13664. if (browser.ie) {
  13665. getClipboardData.call(me, function (div) {
  13666. filter(div);
  13667. });
  13668. me.document.execCommand('paste');
  13669. } else {
  13670. alert(me.getLang('pastemsg'));
  13671. }
  13672. }
  13673. }
  13674. };
  13675. // plugins/puretxtpaste.js
  13676. /**
  13677. * 纯文本粘贴插件
  13678. * @file
  13679. * @since 1.2.6.1
  13680. */
  13681. UE.plugins['pasteplain'] = function(){
  13682. var me = this;
  13683. me.setOpt({
  13684. 'pasteplain':false,
  13685. 'filterTxtRules' : function(){
  13686. function transP(node){
  13687. node.tagName = 'p';
  13688. node.setStyle();
  13689. }
  13690. function removeNode(node){
  13691. node.parentNode.removeChild(node,true)
  13692. }
  13693. return {
  13694. //直接删除及其字节点内容
  13695. '-' : 'script style object iframe embed input select',
  13696. 'p': {$:{}},
  13697. 'br':{$:{}},
  13698. div: function (node) {
  13699. var tmpNode, p = UE.uNode.createElement('p');
  13700. while (tmpNode = node.firstChild()) {
  13701. if (tmpNode.type == 'text' || !UE.dom.dtd.$block[tmpNode.tagName]) {
  13702. p.appendChild(tmpNode);
  13703. } else {
  13704. if (p.firstChild()) {
  13705. node.parentNode.insertBefore(p, node);
  13706. p = UE.uNode.createElement('p');
  13707. } else {
  13708. node.parentNode.insertBefore(tmpNode, node);
  13709. }
  13710. }
  13711. }
  13712. if (p.firstChild()) {
  13713. node.parentNode.insertBefore(p, node);
  13714. }
  13715. node.parentNode.removeChild(node);
  13716. },
  13717. ol: removeNode,
  13718. ul: removeNode,
  13719. dl:removeNode,
  13720. dt:removeNode,
  13721. dd:removeNode,
  13722. 'li':removeNode,
  13723. 'caption':transP,
  13724. 'th':transP,
  13725. 'tr':transP,
  13726. 'h1':transP,'h2':transP,'h3':transP,'h4':transP,'h5':transP,'h6':transP,
  13727. 'td':function(node){
  13728. //没有内容的td直接删掉
  13729. var txt = !!node.innerText();
  13730. if(txt){
  13731. node.parentNode.insertAfter(UE.uNode.createText(' &nbsp; &nbsp;'),node);
  13732. }
  13733. node.parentNode.removeChild(node,node.innerText())
  13734. }
  13735. }
  13736. }()
  13737. });
  13738. //暂时这里支持一下老版本的属性
  13739. var pasteplain = me.options.pasteplain;
  13740. /**
  13741. * 启用或取消纯文本粘贴模式
  13742. * @command pasteplain
  13743. * @method execCommand
  13744. * @param { String } cmd 命令字符串
  13745. * @example
  13746. * ```javascript
  13747. * editor.queryCommandState( 'pasteplain' );
  13748. * ```
  13749. */
  13750. /**
  13751. * 查询当前是否处于纯文本粘贴模式
  13752. * @command pasteplain
  13753. * @method queryCommandState
  13754. * @param { String } cmd 命令字符串
  13755. * @return { int } 如果处于纯文本模式,返回1,否则,返回0
  13756. * @example
  13757. * ```javascript
  13758. * editor.queryCommandState( 'pasteplain' );
  13759. * ```
  13760. */
  13761. me.commands['pasteplain'] = {
  13762. queryCommandState: function (){
  13763. return pasteplain ? 1 : 0;
  13764. },
  13765. execCommand: function (){
  13766. pasteplain = !pasteplain|0;
  13767. },
  13768. notNeedUndo : 1
  13769. };
  13770. };
  13771. // plugins/list.js
  13772. /**
  13773. * 有序列表,无序列表插件
  13774. * @file
  13775. * @since 1.2.6.1
  13776. */
  13777. UE.plugins['list'] = function () {
  13778. var me = this,
  13779. notExchange = {
  13780. 'TD':1,
  13781. 'PRE':1,
  13782. 'BLOCKQUOTE':1
  13783. };
  13784. var customStyle = {
  13785. 'cn' : 'cn-1-',
  13786. 'cn1' : 'cn-2-',
  13787. 'cn2' : 'cn-3-',
  13788. 'num': 'num-1-',
  13789. 'num1' : 'num-2-',
  13790. 'num2' : 'num-3-',
  13791. 'dash' : 'dash',
  13792. 'dot':'dot'
  13793. };
  13794. me.setOpt( {
  13795. 'autoTransWordToList':false,
  13796. 'insertorderedlist':{
  13797. 'num':'',
  13798. 'num1':'',
  13799. 'num2':'',
  13800. 'cn':'',
  13801. 'cn1':'',
  13802. 'cn2':'',
  13803. 'decimal':'',
  13804. 'lower-alpha':'',
  13805. 'lower-roman':'',
  13806. 'upper-alpha':'',
  13807. 'upper-roman':''
  13808. },
  13809. 'insertunorderedlist':{
  13810. 'circle':'',
  13811. 'disc':'',
  13812. 'square':'',
  13813. 'dash' : '',
  13814. 'dot':''
  13815. },
  13816. listDefaultPaddingLeft : '30',
  13817. listiconpath : 'http://bs.baidu.com/listicon/',
  13818. maxListLevel : -1,//-1不限制
  13819. disablePInList:false
  13820. } );
  13821. function listToArray(list){
  13822. var arr = [];
  13823. for(var p in list){
  13824. arr.push(p)
  13825. }
  13826. return arr;
  13827. }
  13828. var listStyle = {
  13829. 'OL':listToArray(me.options.insertorderedlist),
  13830. 'UL':listToArray(me.options.insertunorderedlist)
  13831. };
  13832. var liiconpath = me.options.listiconpath;
  13833. //根据用户配置,调整customStyle
  13834. for(var s in customStyle){
  13835. if(!me.options.insertorderedlist.hasOwnProperty(s) && !me.options.insertunorderedlist.hasOwnProperty(s)){
  13836. delete customStyle[s];
  13837. }
  13838. }
  13839. me.ready(function () {
  13840. var customCss = [];
  13841. for(var p in customStyle){
  13842. if(p == 'dash' || p == 'dot'){
  13843. customCss.push('li.list-' + customStyle[p] + '{background-image:url(' + liiconpath +customStyle[p]+'.gif)}');
  13844. customCss.push('ul.custom_'+p+'{list-style:none;}ul.custom_'+p+' li{background-position:0 3px;background-repeat:no-repeat}');
  13845. }else{
  13846. for(var i= 0;i<99;i++){
  13847. customCss.push('li.list-' + customStyle[p] + i + '{background-image:url(' + liiconpath + 'list-'+customStyle[p] + i + '.gif)}')
  13848. }
  13849. customCss.push('ol.custom_'+p+'{list-style:none;}ol.custom_'+p+' li{background-position:0 3px;background-repeat:no-repeat}');
  13850. }
  13851. switch(p){
  13852. case 'cn':
  13853. customCss.push('li.list-'+p+'-paddingleft-1{padding-left:25px}');
  13854. customCss.push('li.list-'+p+'-paddingleft-2{padding-left:40px}');
  13855. customCss.push('li.list-'+p+'-paddingleft-3{padding-left:55px}');
  13856. break;
  13857. case 'cn1':
  13858. customCss.push('li.list-'+p+'-paddingleft-1{padding-left:30px}');
  13859. customCss.push('li.list-'+p+'-paddingleft-2{padding-left:40px}');
  13860. customCss.push('li.list-'+p+'-paddingleft-3{padding-left:55px}');
  13861. break;
  13862. case 'cn2':
  13863. customCss.push('li.list-'+p+'-paddingleft-1{padding-left:40px}');
  13864. customCss.push('li.list-'+p+'-paddingleft-2{padding-left:55px}');
  13865. customCss.push('li.list-'+p+'-paddingleft-3{padding-left:68px}');
  13866. break;
  13867. case 'num':
  13868. case 'num1':
  13869. customCss.push('li.list-'+p+'-paddingleft-1{padding-left:25px}');
  13870. break;
  13871. case 'num2':
  13872. customCss.push('li.list-'+p+'-paddingleft-1{padding-left:35px}');
  13873. customCss.push('li.list-'+p+'-paddingleft-2{padding-left:40px}');
  13874. break;
  13875. case 'dash':
  13876. customCss.push('li.list-'+p+'-paddingleft{padding-left:35px}');
  13877. break;
  13878. case 'dot':
  13879. customCss.push('li.list-'+p+'-paddingleft{padding-left:20px}');
  13880. }
  13881. }
  13882. customCss.push('.list-paddingleft-1{padding-left:0}');
  13883. customCss.push('.list-paddingleft-2{padding-left:'+me.options.listDefaultPaddingLeft+'px}');
  13884. customCss.push('.list-paddingleft-3{padding-left:'+me.options.listDefaultPaddingLeft*2+'px}');
  13885. //如果不给宽度会在自定应样式里出现滚动条
  13886. utils.cssRule('list', 'ol,ul{margin:0;pading:0;'+(browser.ie ? '' : 'width:95%')+'}li{clear:both;}'+customCss.join('\n'), me.document);
  13887. });
  13888. //单独处理剪切的问题
  13889. me.ready(function(){
  13890. domUtils.on(me.body,'cut',function(){
  13891. setTimeout(function(){
  13892. var rng = me.selection.getRange(),li;
  13893. //trace:3416
  13894. if(!rng.collapsed){
  13895. if(li = domUtils.findParentByTagName(rng.startContainer,'li',true)){
  13896. if(!li.nextSibling && domUtils.isEmptyBlock(li)){
  13897. var pn = li.parentNode,node;
  13898. if(node = pn.previousSibling){
  13899. domUtils.remove(pn);
  13900. rng.setStartAtLast(node).collapse(true);
  13901. rng.select(true);
  13902. }else if(node = pn.nextSibling){
  13903. domUtils.remove(pn);
  13904. rng.setStartAtFirst(node).collapse(true);
  13905. rng.select(true);
  13906. }else{
  13907. var tmpNode = me.document.createElement('p');
  13908. domUtils.fillNode(me.document,tmpNode);
  13909. pn.parentNode.insertBefore(tmpNode,pn);
  13910. domUtils.remove(pn);
  13911. rng.setStart(tmpNode,0).collapse(true);
  13912. rng.select(true);
  13913. }
  13914. }
  13915. }
  13916. }
  13917. })
  13918. })
  13919. });
  13920. function getStyle(node){
  13921. var cls = node.className;
  13922. if(domUtils.hasClass(node,/custom_/)){
  13923. return cls.match(/custom_(\w+)/)[1]
  13924. }
  13925. return domUtils.getStyle(node, 'list-style-type')
  13926. }
  13927. me.addListener('beforepaste',function(type,html){
  13928. var me = this,
  13929. rng = me.selection.getRange(),li;
  13930. var root = UE.htmlparser(html.html,true);
  13931. if(li = domUtils.findParentByTagName(rng.startContainer,'li',true)){
  13932. var list = li.parentNode,tagName = list.tagName == 'OL' ? 'ul':'ol';
  13933. utils.each(root.getNodesByTagName(tagName),function(n){
  13934. n.tagName = list.tagName;
  13935. n.setAttr();
  13936. if(n.parentNode === root){
  13937. type = getStyle(list) || (list.tagName == 'OL' ? 'decimal' : 'disc')
  13938. }else{
  13939. var className = n.parentNode.getAttr('class');
  13940. if(className && /custom_/.test(className)){
  13941. type = className.match(/custom_(\w+)/)[1]
  13942. }else{
  13943. type = n.parentNode.getStyle('list-style-type');
  13944. }
  13945. if(!type){
  13946. type = list.tagName == 'OL' ? 'decimal' : 'disc';
  13947. }
  13948. }
  13949. var index = utils.indexOf(listStyle[list.tagName], type);
  13950. if(n.parentNode !== root)
  13951. index = index + 1 == listStyle[list.tagName].length ? 0 : index + 1;
  13952. var currentStyle = listStyle[list.tagName][index];
  13953. if(customStyle[currentStyle]){
  13954. n.setAttr('class', 'custom_' + currentStyle)
  13955. }else{
  13956. n.setStyle('list-style-type',currentStyle)
  13957. }
  13958. })
  13959. }
  13960. html.html = root.toHtml();
  13961. });
  13962. //导出时,去掉p标签
  13963. me.getOpt('disablePInList') === true && me.addOutputRule(function(root){
  13964. utils.each(root.getNodesByTagName('li'),function(li){
  13965. var newChildrens = [],index=0;
  13966. utils.each(li.children,function(n){
  13967. if(n.tagName == 'p'){
  13968. var tmpNode;
  13969. while(tmpNode = n.children.pop()) {
  13970. newChildrens.splice(index,0,tmpNode);
  13971. tmpNode.parentNode = li;
  13972. lastNode = tmpNode;
  13973. }
  13974. tmpNode = newChildrens[newChildrens.length-1];
  13975. if(!tmpNode || tmpNode.type != 'element' || tmpNode.tagName != 'br'){
  13976. var br = UE.uNode.createElement('br');
  13977. br.parentNode = li;
  13978. newChildrens.push(br);
  13979. }
  13980. index = newChildrens.length;
  13981. }
  13982. });
  13983. if(newChildrens.length){
  13984. li.children = newChildrens;
  13985. }
  13986. });
  13987. });
  13988. //进入编辑器的li要套p标签
  13989. me.addInputRule(function(root){
  13990. utils.each(root.getNodesByTagName('li'),function(li){
  13991. var tmpP = UE.uNode.createElement('p');
  13992. for(var i= 0,ci;ci=li.children[i];){
  13993. if(ci.type == 'text' || dtd.p[ci.tagName]){
  13994. tmpP.appendChild(ci);
  13995. }else{
  13996. if(tmpP.firstChild()){
  13997. li.insertBefore(tmpP,ci);
  13998. tmpP = UE.uNode.createElement('p');
  13999. i = i + 2;
  14000. }else{
  14001. i++;
  14002. }
  14003. }
  14004. }
  14005. if(tmpP.firstChild() && !tmpP.parentNode || !li.firstChild()){
  14006. li.appendChild(tmpP);
  14007. }
  14008. //trace:3357
  14009. //p不能为空
  14010. if (!tmpP.firstChild()) {
  14011. tmpP.innerHTML(browser.ie ? '&nbsp;' : '<br/>')
  14012. }
  14013. //去掉末尾的空白
  14014. var p = li.firstChild();
  14015. var lastChild = p.lastChild();
  14016. if(lastChild && lastChild.type == 'text' && /^\s*$/.test(lastChild.data)){
  14017. p.removeChild(lastChild)
  14018. }
  14019. });
  14020. if(me.options.autoTransWordToList){
  14021. var orderlisttype = {
  14022. 'num1':/^\d+\)/,
  14023. 'decimal':/^\d+\./,
  14024. 'lower-alpha':/^[a-z]+\)/,
  14025. 'upper-alpha':/^[A-Z]+\./,
  14026. 'cn':/^[\u4E00\u4E8C\u4E09\u56DB\u516d\u4e94\u4e03\u516b\u4e5d]+[\u3001]/,
  14027. 'cn2':/^\([\u4E00\u4E8C\u4E09\u56DB\u516d\u4e94\u4e03\u516b\u4e5d]+\)/
  14028. },
  14029. unorderlisttype = {
  14030. 'square':'n'
  14031. };
  14032. function checkListType(content,container){
  14033. var span = container.firstChild();
  14034. if(span && span.type == 'element' && span.tagName == 'span' && /Wingdings|Symbol/.test(span.getStyle('font-family'))){
  14035. for(var p in unorderlisttype){
  14036. if(unorderlisttype[p] == span.data){
  14037. return p
  14038. }
  14039. }
  14040. return 'disc'
  14041. }
  14042. for(var p in orderlisttype){
  14043. if(orderlisttype[p].test(content)){
  14044. return p;
  14045. }
  14046. }
  14047. }
  14048. utils.each(root.getNodesByTagName('p'),function(node){
  14049. if(node.getAttr('class') != 'MsoListParagraph'){
  14050. return
  14051. }
  14052. //word粘贴过来的会带有margin要去掉,但这样也可能会误命中一些央视
  14053. node.setStyle('margin','');
  14054. node.setStyle('margin-left','');
  14055. node.setAttr('class','');
  14056. function appendLi(list,p,type){
  14057. if(list.tagName == 'ol'){
  14058. if(browser.ie){
  14059. var first = p.firstChild();
  14060. if(first.type =='element' && first.tagName == 'span' && orderlisttype[type].test(first.innerText())){
  14061. p.removeChild(first);
  14062. }
  14063. }else{
  14064. p.innerHTML(p.innerHTML().replace(orderlisttype[type],''));
  14065. }
  14066. }else{
  14067. p.removeChild(p.firstChild())
  14068. }
  14069. var li = UE.uNode.createElement('li');
  14070. li.appendChild(p);
  14071. list.appendChild(li);
  14072. }
  14073. var tmp = node,type,cacheNode = node;
  14074. if(node.parentNode.tagName != 'li' && (type = checkListType(node.innerText(),node))){
  14075. var list = UE.uNode.createElement(me.options.insertorderedlist.hasOwnProperty(type) ? 'ol' : 'ul');
  14076. if(customStyle[type]){
  14077. list.setAttr('class','custom_'+type)
  14078. }else{
  14079. list.setStyle('list-style-type',type)
  14080. }
  14081. while(node && node.parentNode.tagName != 'li' && checkListType(node.innerText(),node)){
  14082. tmp = node.nextSibling();
  14083. if(!tmp){
  14084. node.parentNode.insertBefore(list,node)
  14085. }
  14086. appendLi(list,node,type);
  14087. node = tmp;
  14088. }
  14089. if(!list.parentNode && node && node.parentNode){
  14090. node.parentNode.insertBefore(list,node)
  14091. }
  14092. }
  14093. var span = cacheNode.firstChild();
  14094. if(span && span.type == 'element' && span.tagName == 'span' && /^\s*(&nbsp;)+\s*$/.test(span.innerText())){
  14095. span.parentNode.removeChild(span)
  14096. }
  14097. })
  14098. }
  14099. });
  14100. //调整索引标签
  14101. me.addListener('contentchange',function(){
  14102. adjustListStyle(me.document)
  14103. });
  14104. function adjustListStyle(doc,ignore){
  14105. utils.each(domUtils.getElementsByTagName(doc,'ol ul'),function(node){
  14106. if(!domUtils.inDoc(node,doc))
  14107. return;
  14108. var parent = node.parentNode;
  14109. if(parent.tagName == node.tagName){
  14110. var nodeStyleType = getStyle(node) || (node.tagName == 'OL' ? 'decimal' : 'disc'),
  14111. parentStyleType = getStyle(parent) || (parent.tagName == 'OL' ? 'decimal' : 'disc');
  14112. if(nodeStyleType == parentStyleType){
  14113. var styleIndex = utils.indexOf(listStyle[node.tagName], nodeStyleType);
  14114. styleIndex = styleIndex + 1 == listStyle[node.tagName].length ? 0 : styleIndex + 1;
  14115. setListStyle(node,listStyle[node.tagName][styleIndex])
  14116. }
  14117. }
  14118. var index = 0,type = 2;
  14119. if( domUtils.hasClass(node,/custom_/)){
  14120. if(!(/[ou]l/i.test(parent.tagName) && domUtils.hasClass(parent,/custom_/))){
  14121. type = 1;
  14122. }
  14123. }else{
  14124. if(/[ou]l/i.test(parent.tagName) && domUtils.hasClass(parent,/custom_/)){
  14125. type = 3;
  14126. }
  14127. }
  14128. var style = domUtils.getStyle(node, 'list-style-type');
  14129. style && (node.style.cssText = 'list-style-type:' + style);
  14130. node.className = utils.trim(node.className.replace(/list-paddingleft-\w+/,'')) + ' list-paddingleft-' + type;
  14131. utils.each(domUtils.getElementsByTagName(node,'li'),function(li){
  14132. li.style.cssText && (li.style.cssText = '');
  14133. if(!li.firstChild){
  14134. domUtils.remove(li);
  14135. return;
  14136. }
  14137. if(li.parentNode !== node){
  14138. return;
  14139. }
  14140. index++;
  14141. if(domUtils.hasClass(node,/custom_/) ){
  14142. var paddingLeft = 1,currentStyle = getStyle(node);
  14143. if(node.tagName == 'OL'){
  14144. if(currentStyle){
  14145. switch(currentStyle){
  14146. case 'cn' :
  14147. case 'cn1':
  14148. case 'cn2':
  14149. if(index > 10 && (index % 10 == 0 || index > 10 && index < 20)){
  14150. paddingLeft = 2
  14151. }else if(index > 20){
  14152. paddingLeft = 3
  14153. }
  14154. break;
  14155. case 'num2' :
  14156. if(index > 9){
  14157. paddingLeft = 2
  14158. }
  14159. }
  14160. }
  14161. li.className = 'list-'+customStyle[currentStyle]+ index + ' ' + 'list-'+currentStyle+'-paddingleft-' + paddingLeft;
  14162. }else{
  14163. li.className = 'list-'+customStyle[currentStyle] + ' ' + 'list-'+currentStyle+'-paddingleft';
  14164. }
  14165. }else{
  14166. li.className = li.className.replace(/list-[\w\-]+/gi,'');
  14167. }
  14168. var className = li.getAttribute('class');
  14169. if(className !== null && !className.replace(/\s/g,'')){
  14170. domUtils.removeAttributes(li,'class')
  14171. }
  14172. });
  14173. !ignore && adjustList(node,node.tagName.toLowerCase(),getStyle(node)||domUtils.getStyle(node, 'list-style-type'),true);
  14174. })
  14175. }
  14176. function adjustList(list, tag, style,ignoreEmpty) {
  14177. var nextList = list.nextSibling;
  14178. if (nextList && nextList.nodeType == 1 && nextList.tagName.toLowerCase() == tag && (getStyle(nextList) || domUtils.getStyle(nextList, 'list-style-type') || (tag == 'ol' ? 'decimal' : 'disc')) == style) {
  14179. domUtils.moveChild(nextList, list);
  14180. if (nextList.childNodes.length == 0) {
  14181. domUtils.remove(nextList);
  14182. }
  14183. }
  14184. if(nextList && domUtils.isFillChar(nextList)){
  14185. domUtils.remove(nextList);
  14186. }
  14187. var preList = list.previousSibling;
  14188. if (preList && preList.nodeType == 1 && preList.tagName.toLowerCase() == tag && (getStyle(preList) || domUtils.getStyle(preList, 'list-style-type') || (tag == 'ol' ? 'decimal' : 'disc')) == style) {
  14189. domUtils.moveChild(list, preList);
  14190. }
  14191. if(preList && domUtils.isFillChar(preList)){
  14192. domUtils.remove(preList);
  14193. }
  14194. !ignoreEmpty && domUtils.isEmptyBlock(list) && domUtils.remove(list);
  14195. if(getStyle(list)){
  14196. adjustListStyle(list.ownerDocument,true)
  14197. }
  14198. }
  14199. function setListStyle(list,style){
  14200. if(customStyle[style]){
  14201. list.className = 'custom_' + style;
  14202. }
  14203. try{
  14204. domUtils.setStyle(list, 'list-style-type', style);
  14205. }catch(e){}
  14206. }
  14207. function clearEmptySibling(node) {
  14208. var tmpNode = node.previousSibling;
  14209. if (tmpNode && domUtils.isEmptyBlock(tmpNode)) {
  14210. domUtils.remove(tmpNode);
  14211. }
  14212. tmpNode = node.nextSibling;
  14213. if (tmpNode && domUtils.isEmptyBlock(tmpNode)) {
  14214. domUtils.remove(tmpNode);
  14215. }
  14216. }
  14217. me.addListener('keydown', function (type, evt) {
  14218. function preventAndSave() {
  14219. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  14220. me.fireEvent('contentchange');
  14221. me.undoManger && me.undoManger.save();
  14222. }
  14223. function findList(node,filterFn){
  14224. while(node && !domUtils.isBody(node)){
  14225. if(filterFn(node)){
  14226. return null
  14227. }
  14228. if(node.nodeType == 1 && /[ou]l/i.test(node.tagName)){
  14229. return node;
  14230. }
  14231. node = node.parentNode;
  14232. }
  14233. return null;
  14234. }
  14235. var keyCode = evt.keyCode || evt.which;
  14236. if (keyCode == 13 && !evt.shiftKey) {//回车
  14237. var rng = me.selection.getRange(),
  14238. parent = domUtils.findParent(rng.startContainer,function(node){return domUtils.isBlockElm(node)},true),
  14239. li = domUtils.findParentByTagName(rng.startContainer,'li',true);
  14240. if(parent && parent.tagName != 'PRE' && !li){
  14241. var html = parent.innerHTML.replace(new RegExp(domUtils.fillChar, 'g'),'');
  14242. if(/^\s*1\s*\.[^\d]/.test(html)){
  14243. parent.innerHTML = html.replace(/^\s*1\s*\./,'');
  14244. rng.setStartAtLast(parent).collapse(true).select();
  14245. me.__hasEnterExecCommand = true;
  14246. me.execCommand('insertorderedlist');
  14247. me.__hasEnterExecCommand = false;
  14248. }
  14249. }
  14250. var range = me.selection.getRange(),
  14251. start = findList(range.startContainer,function (node) {
  14252. return node.tagName == 'TABLE';
  14253. }),
  14254. end = range.collapsed ? start : findList(range.endContainer,function (node) {
  14255. return node.tagName == 'TABLE';
  14256. });
  14257. if (start && end && start === end) {
  14258. if (!range.collapsed) {
  14259. start = domUtils.findParentByTagName(range.startContainer, 'li', true);
  14260. end = domUtils.findParentByTagName(range.endContainer, 'li', true);
  14261. if (start && end && start === end) {
  14262. range.deleteContents();
  14263. li = domUtils.findParentByTagName(range.startContainer, 'li', true);
  14264. if (li && domUtils.isEmptyBlock(li)) {
  14265. pre = li.previousSibling;
  14266. next = li.nextSibling;
  14267. p = me.document.createElement('p');
  14268. domUtils.fillNode(me.document, p);
  14269. parentList = li.parentNode;
  14270. if (pre && next) {
  14271. range.setStart(next, 0).collapse(true).select(true);
  14272. domUtils.remove(li);
  14273. } else {
  14274. if (!pre && !next || !pre) {
  14275. parentList.parentNode.insertBefore(p, parentList);
  14276. } else {
  14277. li.parentNode.parentNode.insertBefore(p, parentList.nextSibling);
  14278. }
  14279. domUtils.remove(li);
  14280. if (!parentList.firstChild) {
  14281. domUtils.remove(parentList);
  14282. }
  14283. range.setStart(p, 0).setCursor();
  14284. }
  14285. preventAndSave();
  14286. return;
  14287. }
  14288. } else {
  14289. var tmpRange = range.cloneRange(),
  14290. bk = tmpRange.collapse(false).createBookmark();
  14291. range.deleteContents();
  14292. tmpRange.moveToBookmark(bk);
  14293. var li = domUtils.findParentByTagName(tmpRange.startContainer, 'li', true);
  14294. clearEmptySibling(li);
  14295. tmpRange.select();
  14296. preventAndSave();
  14297. return;
  14298. }
  14299. }
  14300. li = domUtils.findParentByTagName(range.startContainer, 'li', true);
  14301. if (li) {
  14302. if (domUtils.isEmptyBlock(li)) {
  14303. bk = range.createBookmark();
  14304. var parentList = li.parentNode;
  14305. if (li !== parentList.lastChild) {
  14306. domUtils.breakParent(li, parentList);
  14307. clearEmptySibling(li);
  14308. } else {
  14309. parentList.parentNode.insertBefore(li, parentList.nextSibling);
  14310. if (domUtils.isEmptyNode(parentList)) {
  14311. domUtils.remove(parentList);
  14312. }
  14313. }
  14314. //嵌套不处理
  14315. if (!dtd.$list[li.parentNode.tagName]) {
  14316. if (!domUtils.isBlockElm(li.firstChild)) {
  14317. p = me.document.createElement('p');
  14318. li.parentNode.insertBefore(p, li);
  14319. while (li.firstChild) {
  14320. p.appendChild(li.firstChild);
  14321. }
  14322. domUtils.remove(li);
  14323. } else {
  14324. domUtils.remove(li, true);
  14325. }
  14326. }
  14327. range.moveToBookmark(bk).select();
  14328. } else {
  14329. var first = li.firstChild;
  14330. if (!first || !domUtils.isBlockElm(first)) {
  14331. var p = me.document.createElement('p');
  14332. !li.firstChild && domUtils.fillNode(me.document, p);
  14333. while (li.firstChild) {
  14334. p.appendChild(li.firstChild);
  14335. }
  14336. li.appendChild(p);
  14337. first = p;
  14338. }
  14339. var span = me.document.createElement('span');
  14340. range.insertNode(span);
  14341. domUtils.breakParent(span, li);
  14342. var nextLi = span.nextSibling;
  14343. first = nextLi.firstChild;
  14344. if (!first) {
  14345. p = me.document.createElement('p');
  14346. domUtils.fillNode(me.document, p);
  14347. nextLi.appendChild(p);
  14348. first = p;
  14349. }
  14350. if (domUtils.isEmptyNode(first)) {
  14351. first.innerHTML = '';
  14352. domUtils.fillNode(me.document, first);
  14353. }
  14354. range.setStart(first, 0).collapse(true).shrinkBoundary().select();
  14355. domUtils.remove(span);
  14356. var pre = nextLi.previousSibling;
  14357. if (pre && domUtils.isEmptyBlock(pre)) {
  14358. pre.innerHTML = '<p></p>';
  14359. domUtils.fillNode(me.document, pre.firstChild);
  14360. }
  14361. }
  14362. // }
  14363. preventAndSave();
  14364. }
  14365. }
  14366. }
  14367. if (keyCode == 8) {
  14368. //修中ie中li下的问题
  14369. range = me.selection.getRange();
  14370. if (range.collapsed && domUtils.isStartInblock(range)) {
  14371. tmpRange = range.cloneRange().trimBoundary();
  14372. li = domUtils.findParentByTagName(range.startContainer, 'li', true);
  14373. //要在li的最左边,才能处理
  14374. if (li && domUtils.isStartInblock(tmpRange)) {
  14375. start = domUtils.findParentByTagName(range.startContainer, 'p', true);
  14376. if (start && start !== li.firstChild) {
  14377. var parentList = domUtils.findParentByTagName(start,['ol','ul']);
  14378. domUtils.breakParent(start,parentList);
  14379. clearEmptySibling(start);
  14380. me.fireEvent('contentchange');
  14381. range.setStart(start,0).setCursor(false,true);
  14382. me.fireEvent('saveScene');
  14383. domUtils.preventDefault(evt);
  14384. return;
  14385. }
  14386. if (li && (pre = li.previousSibling)) {
  14387. if (keyCode == 46 && li.childNodes.length) {
  14388. return;
  14389. }
  14390. //有可能上边的兄弟节点是个2级菜单,要追加到2级菜单的最后的li
  14391. if (dtd.$list[pre.tagName]) {
  14392. pre = pre.lastChild;
  14393. }
  14394. me.undoManger && me.undoManger.save();
  14395. first = li.firstChild;
  14396. if (domUtils.isBlockElm(first)) {
  14397. if (domUtils.isEmptyNode(first)) {
  14398. // range.setEnd(pre, pre.childNodes.length).shrinkBoundary().collapse().select(true);
  14399. pre.appendChild(first);
  14400. range.setStart(first, 0).setCursor(false, true);
  14401. //first不是唯一的节点
  14402. while (li.firstChild) {
  14403. pre.appendChild(li.firstChild);
  14404. }
  14405. } else {
  14406. span = me.document.createElement('span');
  14407. range.insertNode(span);
  14408. //判断pre是否是空的节点,如果是<p><br/></p>类型的空节点,干掉p标签防止它占位
  14409. if (domUtils.isEmptyBlock(pre)) {
  14410. pre.innerHTML = '';
  14411. }
  14412. domUtils.moveChild(li, pre);
  14413. range.setStartBefore(span).collapse(true).select(true);
  14414. domUtils.remove(span);
  14415. }
  14416. } else {
  14417. if (domUtils.isEmptyNode(li)) {
  14418. var p = me.document.createElement('p');
  14419. pre.appendChild(p);
  14420. range.setStart(p, 0).setCursor();
  14421. // range.setEnd(pre, pre.childNodes.length).shrinkBoundary().collapse().select(true);
  14422. } else {
  14423. range.setEnd(pre, pre.childNodes.length).collapse().select(true);
  14424. while (li.firstChild) {
  14425. pre.appendChild(li.firstChild);
  14426. }
  14427. }
  14428. }
  14429. domUtils.remove(li);
  14430. me.fireEvent('contentchange');
  14431. me.fireEvent('saveScene');
  14432. domUtils.preventDefault(evt);
  14433. return;
  14434. }
  14435. //trace:980
  14436. if (li && !li.previousSibling) {
  14437. var parentList = li.parentNode;
  14438. var bk = range.createBookmark();
  14439. if(domUtils.isTagNode(parentList.parentNode,'ol ul')){
  14440. parentList.parentNode.insertBefore(li,parentList);
  14441. if(domUtils.isEmptyNode(parentList)){
  14442. domUtils.remove(parentList)
  14443. }
  14444. }else{
  14445. while(li.firstChild){
  14446. parentList.parentNode.insertBefore(li.firstChild,parentList);
  14447. }
  14448. domUtils.remove(li);
  14449. if(domUtils.isEmptyNode(parentList)){
  14450. domUtils.remove(parentList)
  14451. }
  14452. }
  14453. range.moveToBookmark(bk).setCursor(false,true);
  14454. me.fireEvent('contentchange');
  14455. me.fireEvent('saveScene');
  14456. domUtils.preventDefault(evt);
  14457. return;
  14458. }
  14459. }
  14460. }
  14461. }
  14462. });
  14463. me.addListener('keyup',function(type, evt){
  14464. var keyCode = evt.keyCode || evt.which;
  14465. if (keyCode == 8) {
  14466. var rng = me.selection.getRange(),list;
  14467. if(list = domUtils.findParentByTagName(rng.startContainer,['ol', 'ul'],true)){
  14468. adjustList(list,list.tagName.toLowerCase(),getStyle(list)||domUtils.getComputedStyle(list,'list-style-type'),true)
  14469. }
  14470. }
  14471. });
  14472. //处理tab键
  14473. me.addListener('tabkeydown',function(){
  14474. var range = me.selection.getRange();
  14475. //控制级数
  14476. function checkLevel(li){
  14477. if(me.options.maxListLevel != -1){
  14478. var level = li.parentNode,levelNum = 0;
  14479. while(/[ou]l/i.test(level.tagName)){
  14480. levelNum++;
  14481. level = level.parentNode;
  14482. }
  14483. if(levelNum >= me.options.maxListLevel){
  14484. return true;
  14485. }
  14486. }
  14487. }
  14488. //只以开始为准
  14489. //todo 后续改进
  14490. var li = domUtils.findParentByTagName(range.startContainer, 'li', true);
  14491. if(li){
  14492. var bk;
  14493. if(range.collapsed){
  14494. if(checkLevel(li))
  14495. return true;
  14496. var parentLi = li.parentNode,
  14497. list = me.document.createElement(parentLi.tagName),
  14498. index = utils.indexOf(listStyle[list.tagName], getStyle(parentLi)||domUtils.getComputedStyle(parentLi, 'list-style-type'));
  14499. index = index + 1 == listStyle[list.tagName].length ? 0 : index + 1;
  14500. var currentStyle = listStyle[list.tagName][index];
  14501. setListStyle(list,currentStyle);
  14502. if(domUtils.isStartInblock(range)){
  14503. me.fireEvent('saveScene');
  14504. bk = range.createBookmark();
  14505. parentLi.insertBefore(list, li);
  14506. list.appendChild(li);
  14507. adjustList(list,list.tagName.toLowerCase(),currentStyle);
  14508. me.fireEvent('contentchange');
  14509. range.moveToBookmark(bk).select(true);
  14510. return true;
  14511. }
  14512. }else{
  14513. me.fireEvent('saveScene');
  14514. bk = range.createBookmark();
  14515. for(var i= 0,closeList,parents = domUtils.findParents(li),ci;ci=parents[i++];){
  14516. if(domUtils.isTagNode(ci,'ol ul')){
  14517. closeList = ci;
  14518. break;
  14519. }
  14520. }
  14521. var current = li;
  14522. if(bk.end){
  14523. while(current && !(domUtils.getPosition(current, bk.end) & domUtils.POSITION_FOLLOWING)){
  14524. if(checkLevel(current)){
  14525. current = domUtils.getNextDomNode(current,false,null,function(node){return node !== closeList});
  14526. continue;
  14527. }
  14528. var parentLi = current.parentNode,
  14529. list = me.document.createElement(parentLi.tagName),
  14530. index = utils.indexOf(listStyle[list.tagName], getStyle(parentLi)||domUtils.getComputedStyle(parentLi, 'list-style-type'));
  14531. var currentIndex = index + 1 == listStyle[list.tagName].length ? 0 : index + 1;
  14532. var currentStyle = listStyle[list.tagName][currentIndex];
  14533. setListStyle(list,currentStyle);
  14534. parentLi.insertBefore(list, current);
  14535. while(current && !(domUtils.getPosition(current, bk.end) & domUtils.POSITION_FOLLOWING)){
  14536. li = current.nextSibling;
  14537. list.appendChild(current);
  14538. if(!li || domUtils.isTagNode(li,'ol ul')){
  14539. if(li){
  14540. while(li = li.firstChild){
  14541. if(li.tagName == 'LI'){
  14542. break;
  14543. }
  14544. }
  14545. }else{
  14546. li = domUtils.getNextDomNode(current,false,null,function(node){return node !== closeList});
  14547. }
  14548. break;
  14549. }
  14550. current = li;
  14551. }
  14552. adjustList(list,list.tagName.toLowerCase(),currentStyle);
  14553. current = li;
  14554. }
  14555. }
  14556. me.fireEvent('contentchange');
  14557. range.moveToBookmark(bk).select();
  14558. return true;
  14559. }
  14560. }
  14561. });
  14562. function getLi(start){
  14563. while(start && !domUtils.isBody(start)){
  14564. if(start.nodeName == 'TABLE'){
  14565. return null;
  14566. }
  14567. if(start.nodeName == 'LI'){
  14568. return start
  14569. }
  14570. start = start.parentNode;
  14571. }
  14572. }
  14573. /**
  14574. * 有序列表,与“insertunorderedlist”命令互斥
  14575. * @command insertorderedlist
  14576. * @method execCommand
  14577. * @param { String } command 命令字符串
  14578. * @param { String } style 插入的有序列表类型,值为:decimal,lower-alpha,lower-roman,upper-alpha,upper-roman,cn,cn1,cn2,num,num1,num2
  14579. * @example
  14580. * ```javascript
  14581. * editor.execCommand( 'insertorderedlist','decimal');
  14582. * ```
  14583. */
  14584. /**
  14585. * 查询当前选区内容是否有序列表
  14586. * @command insertorderedlist
  14587. * @method queryCommandState
  14588. * @param { String } cmd 命令字符串
  14589. * @return { int } 如果当前选区是有序列表返回1,否则返回0
  14590. * @example
  14591. * ```javascript
  14592. * editor.queryCommandState( 'insertorderedlist' );
  14593. * ```
  14594. */
  14595. /**
  14596. * 查询当前选区内容是否有序列表
  14597. * @command insertorderedlist
  14598. * @method queryCommandValue
  14599. * @param { String } cmd 命令字符串
  14600. * @return { String } 返回当前有序列表的类型,值为null或decimal,lower-alpha,lower-roman,upper-alpha,upper-roman,cn,cn1,cn2,num,num1,num2
  14601. * @example
  14602. * ```javascript
  14603. * editor.queryCommandValue( 'insertorderedlist' );
  14604. * ```
  14605. */
  14606. /**
  14607. * 无序列表,与“insertorderedlist”命令互斥
  14608. * @command insertunorderedlist
  14609. * @method execCommand
  14610. * @param { String } command 命令字符串
  14611. * @param { String } style 插入的无序列表类型,值为:circle,disc,square,dash,dot
  14612. * @example
  14613. * ```javascript
  14614. * editor.execCommand( 'insertunorderedlist','circle');
  14615. * ```
  14616. */
  14617. /**
  14618. * 查询当前是否有word文档粘贴进来的图片
  14619. * @command insertunorderedlist
  14620. * @method insertunorderedlist
  14621. * @param { String } command 命令字符串
  14622. * @return { int } 如果当前选区是无序列表返回1,否则返回0
  14623. * @example
  14624. * ```javascript
  14625. * editor.queryCommandState( 'insertunorderedlist' );
  14626. * ```
  14627. */
  14628. /**
  14629. * 查询当前选区内容是否有序列表
  14630. * @command insertunorderedlist
  14631. * @method queryCommandValue
  14632. * @param { String } command 命令字符串
  14633. * @return { String } 返回当前无序列表的类型,值为null或circle,disc,square,dash,dot
  14634. * @example
  14635. * ```javascript
  14636. * editor.queryCommandValue( 'insertunorderedlist' );
  14637. * ```
  14638. */
  14639. me.commands['insertorderedlist'] =
  14640. me.commands['insertunorderedlist'] = {
  14641. execCommand:function (command, style) {
  14642. if (!style) {
  14643. style = command.toLowerCase() == 'insertorderedlist' ? 'decimal' : 'disc';
  14644. }
  14645. var me = this,
  14646. range = this.selection.getRange(),
  14647. filterFn = function (node) {
  14648. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' : !domUtils.isWhitespace(node);
  14649. },
  14650. tag = command.toLowerCase() == 'insertorderedlist' ? 'ol' : 'ul',
  14651. frag = me.document.createDocumentFragment();
  14652. //去掉是因为会出现选到末尾,导致adjustmentBoundary缩到ol/ul的位置
  14653. //range.shrinkBoundary();//.adjustmentBoundary();
  14654. range.adjustmentBoundary().shrinkBoundary();
  14655. var bko = range.createBookmark(true),
  14656. start = getLi(me.document.getElementById(bko.start)),
  14657. modifyStart = 0,
  14658. end = getLi(me.document.getElementById(bko.end)),
  14659. modifyEnd = 0,
  14660. startParent, endParent,
  14661. list, tmp;
  14662. if (start || end) {
  14663. start && (startParent = start.parentNode);
  14664. if (!bko.end) {
  14665. end = start;
  14666. }
  14667. end && (endParent = end.parentNode);
  14668. if (startParent === endParent) {
  14669. while (start !== end) {
  14670. tmp = start;
  14671. start = start.nextSibling;
  14672. if (!domUtils.isBlockElm(tmp.firstChild)) {
  14673. var p = me.document.createElement('p');
  14674. while (tmp.firstChild) {
  14675. p.appendChild(tmp.firstChild);
  14676. }
  14677. tmp.appendChild(p);
  14678. }
  14679. frag.appendChild(tmp);
  14680. }
  14681. tmp = me.document.createElement('span');
  14682. startParent.insertBefore(tmp, end);
  14683. if (!domUtils.isBlockElm(end.firstChild)) {
  14684. p = me.document.createElement('p');
  14685. while (end.firstChild) {
  14686. p.appendChild(end.firstChild);
  14687. }
  14688. end.appendChild(p);
  14689. }
  14690. frag.appendChild(end);
  14691. domUtils.breakParent(tmp, startParent);
  14692. if (domUtils.isEmptyNode(tmp.previousSibling)) {
  14693. domUtils.remove(tmp.previousSibling);
  14694. }
  14695. if (domUtils.isEmptyNode(tmp.nextSibling)) {
  14696. domUtils.remove(tmp.nextSibling)
  14697. }
  14698. var nodeStyle = getStyle(startParent) || domUtils.getComputedStyle(startParent, 'list-style-type') || (command.toLowerCase() == 'insertorderedlist' ? 'decimal' : 'disc');
  14699. if (startParent.tagName.toLowerCase() == tag && nodeStyle == style) {
  14700. for (var i = 0, ci, tmpFrag = me.document.createDocumentFragment(); ci = frag.firstChild;) {
  14701. if(domUtils.isTagNode(ci,'ol ul')){
  14702. // 删除时,子列表不处理
  14703. // utils.each(domUtils.getElementsByTagName(ci,'li'),function(li){
  14704. // while(li.firstChild){
  14705. // tmpFrag.appendChild(li.firstChild);
  14706. // }
  14707. //
  14708. // });
  14709. tmpFrag.appendChild(ci);
  14710. }else{
  14711. while (ci.firstChild) {
  14712. tmpFrag.appendChild(ci.firstChild);
  14713. domUtils.remove(ci);
  14714. }
  14715. }
  14716. }
  14717. tmp.parentNode.insertBefore(tmpFrag, tmp);
  14718. } else {
  14719. list = me.document.createElement(tag);
  14720. setListStyle(list,style);
  14721. list.appendChild(frag);
  14722. tmp.parentNode.insertBefore(list, tmp);
  14723. }
  14724. domUtils.remove(tmp);
  14725. list && adjustList(list, tag, style);
  14726. range.moveToBookmark(bko).select();
  14727. return;
  14728. }
  14729. //开始
  14730. if (start) {
  14731. while (start) {
  14732. tmp = start.nextSibling;
  14733. if (domUtils.isTagNode(start, 'ol ul')) {
  14734. frag.appendChild(start);
  14735. } else {
  14736. var tmpfrag = me.document.createDocumentFragment(),
  14737. hasBlock = 0;
  14738. while (start.firstChild) {
  14739. if (domUtils.isBlockElm(start.firstChild)) {
  14740. hasBlock = 1;
  14741. }
  14742. tmpfrag.appendChild(start.firstChild);
  14743. }
  14744. if (!hasBlock) {
  14745. var tmpP = me.document.createElement('p');
  14746. tmpP.appendChild(tmpfrag);
  14747. frag.appendChild(tmpP);
  14748. } else {
  14749. frag.appendChild(tmpfrag);
  14750. }
  14751. domUtils.remove(start);
  14752. }
  14753. start = tmp;
  14754. }
  14755. startParent.parentNode.insertBefore(frag, startParent.nextSibling);
  14756. if (domUtils.isEmptyNode(startParent)) {
  14757. range.setStartBefore(startParent);
  14758. domUtils.remove(startParent);
  14759. } else {
  14760. range.setStartAfter(startParent);
  14761. }
  14762. modifyStart = 1;
  14763. }
  14764. if (end && domUtils.inDoc(endParent, me.document)) {
  14765. //结束
  14766. start = endParent.firstChild;
  14767. while (start && start !== end) {
  14768. tmp = start.nextSibling;
  14769. if (domUtils.isTagNode(start, 'ol ul')) {
  14770. frag.appendChild(start);
  14771. } else {
  14772. tmpfrag = me.document.createDocumentFragment();
  14773. hasBlock = 0;
  14774. while (start.firstChild) {
  14775. if (domUtils.isBlockElm(start.firstChild)) {
  14776. hasBlock = 1;
  14777. }
  14778. tmpfrag.appendChild(start.firstChild);
  14779. }
  14780. if (!hasBlock) {
  14781. tmpP = me.document.createElement('p');
  14782. tmpP.appendChild(tmpfrag);
  14783. frag.appendChild(tmpP);
  14784. } else {
  14785. frag.appendChild(tmpfrag);
  14786. }
  14787. domUtils.remove(start);
  14788. }
  14789. start = tmp;
  14790. }
  14791. var tmpDiv = domUtils.createElement(me.document, 'div', {
  14792. 'tmpDiv':1
  14793. });
  14794. domUtils.moveChild(end, tmpDiv);
  14795. frag.appendChild(tmpDiv);
  14796. domUtils.remove(end);
  14797. endParent.parentNode.insertBefore(frag, endParent);
  14798. range.setEndBefore(endParent);
  14799. if (domUtils.isEmptyNode(endParent)) {
  14800. domUtils.remove(endParent);
  14801. }
  14802. modifyEnd = 1;
  14803. }
  14804. }
  14805. if (!modifyStart) {
  14806. range.setStartBefore(me.document.getElementById(bko.start));
  14807. }
  14808. if (bko.end && !modifyEnd) {
  14809. range.setEndAfter(me.document.getElementById(bko.end));
  14810. }
  14811. range.enlarge(true, function (node) {
  14812. return notExchange[node.tagName];
  14813. });
  14814. frag = me.document.createDocumentFragment();
  14815. var bk = range.createBookmark(),
  14816. current = domUtils.getNextDomNode(bk.start, false, filterFn),
  14817. tmpRange = range.cloneRange(),
  14818. tmpNode,
  14819. block = domUtils.isBlockElm;
  14820. while (current && current !== bk.end && (domUtils.getPosition(current, bk.end) & domUtils.POSITION_PRECEDING)) {
  14821. if (current.nodeType == 3 || dtd.li[current.tagName]) {
  14822. if (current.nodeType == 1 && dtd.$list[current.tagName]) {
  14823. while (current.firstChild) {
  14824. frag.appendChild(current.firstChild);
  14825. }
  14826. tmpNode = domUtils.getNextDomNode(current, false, filterFn);
  14827. domUtils.remove(current);
  14828. current = tmpNode;
  14829. continue;
  14830. }
  14831. tmpNode = current;
  14832. tmpRange.setStartBefore(current);
  14833. while (current && current !== bk.end && (!block(current) || domUtils.isBookmarkNode(current) )) {
  14834. tmpNode = current;
  14835. current = domUtils.getNextDomNode(current, false, null, function (node) {
  14836. return !notExchange[node.tagName];
  14837. });
  14838. }
  14839. if (current && block(current)) {
  14840. tmp = domUtils.getNextDomNode(tmpNode, false, filterFn);
  14841. if (tmp && domUtils.isBookmarkNode(tmp)) {
  14842. current = domUtils.getNextDomNode(tmp, false, filterFn);
  14843. tmpNode = tmp;
  14844. }
  14845. }
  14846. tmpRange.setEndAfter(tmpNode);
  14847. current = domUtils.getNextDomNode(tmpNode, false, filterFn);
  14848. var li = range.document.createElement('li');
  14849. li.appendChild(tmpRange.extractContents());
  14850. if(domUtils.isEmptyNode(li)){
  14851. var tmpNode = range.document.createElement('p');
  14852. while(li.firstChild){
  14853. tmpNode.appendChild(li.firstChild)
  14854. }
  14855. li.appendChild(tmpNode);
  14856. }
  14857. frag.appendChild(li);
  14858. } else {
  14859. current = domUtils.getNextDomNode(current, true, filterFn);
  14860. }
  14861. }
  14862. range.moveToBookmark(bk).collapse(true);
  14863. list = me.document.createElement(tag);
  14864. setListStyle(list,style);
  14865. list.appendChild(frag);
  14866. range.insertNode(list);
  14867. //当前list上下看能否合并
  14868. adjustList(list, tag, style);
  14869. //去掉冗余的tmpDiv
  14870. for (var i = 0, ci, tmpDivs = domUtils.getElementsByTagName(list, 'div'); ci = tmpDivs[i++];) {
  14871. if (ci.getAttribute('tmpDiv')) {
  14872. domUtils.remove(ci, true)
  14873. }
  14874. }
  14875. range.moveToBookmark(bko).select();
  14876. },
  14877. queryCommandState:function (command) {
  14878. var tag = command.toLowerCase() == 'insertorderedlist' ? 'ol' : 'ul';
  14879. var path = this.selection.getStartElementPath();
  14880. for(var i= 0,ci;ci = path[i++];){
  14881. if(ci.nodeName == 'TABLE'){
  14882. return 0
  14883. }
  14884. if(tag == ci.nodeName.toLowerCase()){
  14885. return 1
  14886. };
  14887. }
  14888. return 0;
  14889. },
  14890. queryCommandValue:function (command) {
  14891. var tag = command.toLowerCase() == 'insertorderedlist' ? 'ol' : 'ul';
  14892. var path = this.selection.getStartElementPath(),
  14893. node;
  14894. for(var i= 0,ci;ci = path[i++];){
  14895. if(ci.nodeName == 'TABLE'){
  14896. node = null;
  14897. break;
  14898. }
  14899. if(tag == ci.nodeName.toLowerCase()){
  14900. node = ci;
  14901. break;
  14902. };
  14903. }
  14904. return node ? getStyle(node) || domUtils.getComputedStyle(node, 'list-style-type') : null;
  14905. }
  14906. };
  14907. };
  14908. // plugins/source.js
  14909. /**
  14910. * 源码编辑插件
  14911. * @file
  14912. * @since 1.2.6.1
  14913. */
  14914. (function (){
  14915. var sourceEditors = {
  14916. textarea: function (editor, holder){
  14917. var textarea = holder.ownerDocument.createElement('textarea');
  14918. textarea.style.cssText = 'position:absolute;resize:none;width:100%;height:100%;border:0;padding:0;margin:0;overflow-y:auto;';
  14919. // todo: IE下只有onresize属性可用... 很纠结
  14920. if (browser.ie && browser.version < 8) {
  14921. textarea.style.width = holder.offsetWidth + 'px';
  14922. textarea.style.height = holder.offsetHeight + 'px';
  14923. holder.onresize = function (){
  14924. textarea.style.width = holder.offsetWidth + 'px';
  14925. textarea.style.height = holder.offsetHeight + 'px';
  14926. };
  14927. }
  14928. holder.appendChild(textarea);
  14929. return {
  14930. setContent: function (content){
  14931. textarea.value = content;
  14932. },
  14933. getContent: function (){
  14934. return textarea.value;
  14935. },
  14936. select: function (){
  14937. var range;
  14938. if (browser.ie) {
  14939. range = textarea.createTextRange();
  14940. range.collapse(true);
  14941. range.select();
  14942. } else {
  14943. //todo: chrome下无法设置焦点
  14944. textarea.setSelectionRange(0, 0);
  14945. textarea.focus();
  14946. }
  14947. },
  14948. dispose: function (){
  14949. holder.removeChild(textarea);
  14950. // todo
  14951. holder.onresize = null;
  14952. textarea = null;
  14953. holder = null;
  14954. }
  14955. };
  14956. },
  14957. codemirror: function (editor, holder){
  14958. var codeEditor = window.CodeMirror(holder, {
  14959. mode: "text/html",
  14960. tabMode: "indent",
  14961. lineNumbers: true,
  14962. lineWrapping:true
  14963. });
  14964. var dom = codeEditor.getWrapperElement();
  14965. dom.style.cssText = 'position:absolute;left:0;top:0;width:100%;height:100%;font-family:consolas,"Courier new",monospace;font-size:13px;';
  14966. codeEditor.getScrollerElement().style.cssText = 'position:absolute;left:0;top:0;width:100%;height:100%;';
  14967. codeEditor.refresh();
  14968. return {
  14969. getCodeMirror:function(){
  14970. return codeEditor;
  14971. },
  14972. setContent: function (content){
  14973. codeEditor.setValue(content);
  14974. },
  14975. getContent: function (){
  14976. return codeEditor.getValue();
  14977. },
  14978. select: function (){
  14979. codeEditor.focus();
  14980. },
  14981. dispose: function (){
  14982. holder.removeChild(dom);
  14983. dom = null;
  14984. codeEditor = null;
  14985. }
  14986. };
  14987. }
  14988. };
  14989. UE.plugins['source'] = function (){
  14990. var me = this;
  14991. var opt = this.options;
  14992. var sourceMode = false;
  14993. var sourceEditor;
  14994. var orgSetContent;
  14995. opt.sourceEditor = browser.ie ? 'textarea' : (opt.sourceEditor || 'codemirror');
  14996. me.setOpt({
  14997. sourceEditorFirst:false
  14998. });
  14999. function createSourceEditor(holder){
  15000. return sourceEditors[opt.sourceEditor == 'codemirror' && window.CodeMirror ? 'codemirror' : 'textarea'](me, holder);
  15001. }
  15002. var bakCssText;
  15003. //解决在源码模式下getContent不能得到最新的内容问题
  15004. var oldGetContent,
  15005. bakAddress;
  15006. /**
  15007. * 切换源码模式和编辑模式
  15008. * @command source
  15009. * @method execCommand
  15010. * @param { String } cmd 命令字符串
  15011. * @example
  15012. * ```javascript
  15013. * editor.execCommand( 'source');
  15014. * ```
  15015. */
  15016. /**
  15017. * 查询当前编辑区域的状态是源码模式还是可视化模式
  15018. * @command source
  15019. * @method queryCommandState
  15020. * @param { String } cmd 命令字符串
  15021. * @return { int } 如果当前是源码编辑模式,返回1,否则返回0
  15022. * @example
  15023. * ```javascript
  15024. * editor.queryCommandState( 'source' );
  15025. * ```
  15026. */
  15027. me.commands['source'] = {
  15028. execCommand: function (){
  15029. sourceMode = !sourceMode;
  15030. if (sourceMode) {
  15031. bakAddress = me.selection.getRange().createAddress(false,true);
  15032. me.undoManger && me.undoManger.save(true);
  15033. if(browser.gecko){
  15034. me.body.contentEditable = false;
  15035. }
  15036. bakCssText = me.iframe.style.cssText;
  15037. me.iframe.style.cssText += 'position:absolute;left:-32768px;top:-32768px;';
  15038. me.fireEvent('beforegetcontent');
  15039. var root = UE.htmlparser(me.body.innerHTML);
  15040. me.filterOutputRule(root);
  15041. root.traversal(function (node) {
  15042. if (node.type == 'element') {
  15043. switch (node.tagName) {
  15044. case 'td':
  15045. case 'th':
  15046. case 'caption':
  15047. if(node.children && node.children.length == 1){
  15048. if(node.firstChild().tagName == 'br' ){
  15049. node.removeChild(node.firstChild())
  15050. }
  15051. };
  15052. break;
  15053. case 'pre':
  15054. node.innerText(node.innerText().replace(/&nbsp;/g,' '))
  15055. }
  15056. }
  15057. });
  15058. me.fireEvent('aftergetcontent');
  15059. var content = root.toHtml(true);
  15060. sourceEditor = createSourceEditor(me.iframe.parentNode);
  15061. sourceEditor.setContent(content);
  15062. orgSetContent = me.setContent;
  15063. me.setContent = function(html){
  15064. //这里暂时不触发事件,防止报错
  15065. var root = UE.htmlparser(html);
  15066. me.filterInputRule(root);
  15067. html = root.toHtml();
  15068. sourceEditor.setContent(html);
  15069. };
  15070. setTimeout(function (){
  15071. sourceEditor.select();
  15072. me.addListener('fullscreenchanged', function(){
  15073. try{
  15074. sourceEditor.getCodeMirror().refresh()
  15075. }catch(e){}
  15076. });
  15077. });
  15078. //重置getContent,源码模式下取值也能是最新的数据
  15079. oldGetContent = me.getContent;
  15080. me.getContent = function (){
  15081. return sourceEditor.getContent() || '<p>' + (browser.ie ? '' : '<br/>')+'</p>';
  15082. };
  15083. } else {
  15084. me.iframe.style.cssText = bakCssText;
  15085. var cont = sourceEditor.getContent() || '<p>' + (browser.ie ? '' : '<br/>')+'</p>';
  15086. //处理掉block节点前后的空格,有可能会误命中,暂时不考虑
  15087. cont = cont.replace(new RegExp('[\\r\\t\\n ]*<\/?(\\w+)\\s*(?:[^>]*)>','g'), function(a,b){
  15088. if(b && !dtd.$inlineWithA[b.toLowerCase()]){
  15089. return a.replace(/(^[\n\r\t ]*)|([\n\r\t ]*$)/g,'');
  15090. }
  15091. return a.replace(/(^[\n\r\t]*)|([\n\r\t]*$)/g,'')
  15092. });
  15093. me.setContent = orgSetContent;
  15094. me.setContent(cont);
  15095. sourceEditor.dispose();
  15096. sourceEditor = null;
  15097. //还原getContent方法
  15098. me.getContent = oldGetContent;
  15099. var first = me.body.firstChild;
  15100. //trace:1106 都删除空了,下边会报错,所以补充一个p占位
  15101. if(!first){
  15102. me.body.innerHTML = '<p>'+(browser.ie?'':'<br/>')+'</p>';
  15103. first = me.body.firstChild;
  15104. }
  15105. //要在ifm为显示时ff才能取到selection,否则报错
  15106. //这里不能比较位置了
  15107. me.undoManger && me.undoManger.save(true);
  15108. if(browser.gecko){
  15109. var input = document.createElement('input');
  15110. input.style.cssText = 'position:absolute;left:0;top:-32768px';
  15111. document.body.appendChild(input);
  15112. me.body.contentEditable = false;
  15113. setTimeout(function(){
  15114. domUtils.setViewportOffset(input, { left: -32768, top: 0 });
  15115. input.focus();
  15116. setTimeout(function(){
  15117. me.body.contentEditable = true;
  15118. me.selection.getRange().moveToAddress(bakAddress).select(true);
  15119. domUtils.remove(input);
  15120. });
  15121. });
  15122. }else{
  15123. //ie下有可能报错,比如在代码顶头的情况
  15124. try{
  15125. me.selection.getRange().moveToAddress(bakAddress).select(true);
  15126. }catch(e){}
  15127. }
  15128. }
  15129. this.fireEvent('sourcemodechanged', sourceMode);
  15130. },
  15131. queryCommandState: function (){
  15132. return sourceMode|0;
  15133. },
  15134. notNeedUndo : 1
  15135. };
  15136. var oldQueryCommandState = me.queryCommandState;
  15137. me.queryCommandState = function (cmdName){
  15138. cmdName = cmdName.toLowerCase();
  15139. if (sourceMode) {
  15140. //源码模式下可以开启的命令
  15141. return cmdName in {
  15142. 'source' : 1,
  15143. 'fullscreen' : 1
  15144. } ? 1 : -1
  15145. }
  15146. return oldQueryCommandState.apply(this, arguments);
  15147. };
  15148. if(opt.sourceEditor == "codemirror"){
  15149. me.addListener("ready",function(){
  15150. utils.loadFile(document,{
  15151. src : opt.codeMirrorJsUrl || opt.UEDITOR_HOME_URL + "third-party/codemirror/codemirror.js",
  15152. tag : "script",
  15153. type : "text/javascript",
  15154. defer : "defer"
  15155. },function(){
  15156. if(opt.sourceEditorFirst){
  15157. setTimeout(function(){
  15158. me.execCommand("source");
  15159. },0);
  15160. }
  15161. });
  15162. utils.loadFile(document,{
  15163. tag : "link",
  15164. rel : "stylesheet",
  15165. type : "text/css",
  15166. href : opt.codeMirrorCssUrl || opt.UEDITOR_HOME_URL + "third-party/codemirror/codemirror.css"
  15167. });
  15168. });
  15169. }
  15170. };
  15171. })();
  15172. // plugins/enterkey.js
  15173. ///import core
  15174. ///import plugins/undo.js
  15175. ///commands 设置回车标签p或br
  15176. ///commandsName EnterKey
  15177. ///commandsTitle 设置回车标签p或br
  15178. /**
  15179. * @description 处理回车
  15180. * @author zhanyi
  15181. */
  15182. UE.plugins['enterkey'] = function() {
  15183. var hTag,
  15184. me = this,
  15185. tag = me.options.enterTag;
  15186. me.addListener('keyup', function(type, evt) {
  15187. var keyCode = evt.keyCode || evt.which;
  15188. if (keyCode == 13) {
  15189. var range = me.selection.getRange(),
  15190. start = range.startContainer,
  15191. doSave;
  15192. //修正在h1-h6里边回车后不能嵌套p的问题
  15193. if (!browser.ie) {
  15194. if (/h\d/i.test(hTag)) {
  15195. if (browser.gecko) {
  15196. var h = domUtils.findParentByTagName(start, [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6','blockquote','caption','table'], true);
  15197. if (!h) {
  15198. me.document.execCommand('formatBlock', false, '<p>');
  15199. doSave = 1;
  15200. }
  15201. } else {
  15202. //chrome remove div
  15203. if (start.nodeType == 1) {
  15204. var tmp = me.document.createTextNode(''),div;
  15205. range.insertNode(tmp);
  15206. div = domUtils.findParentByTagName(tmp, 'div', true);
  15207. if (div) {
  15208. var p = me.document.createElement('p');
  15209. while (div.firstChild) {
  15210. p.appendChild(div.firstChild);
  15211. }
  15212. div.parentNode.insertBefore(p, div);
  15213. domUtils.remove(div);
  15214. range.setStartBefore(tmp).setCursor();
  15215. doSave = 1;
  15216. }
  15217. domUtils.remove(tmp);
  15218. }
  15219. }
  15220. if (me.undoManger && doSave) {
  15221. me.undoManger.save();
  15222. }
  15223. }
  15224. //没有站位符,会出现多行的问题
  15225. browser.opera && range.select();
  15226. }else{
  15227. me.fireEvent('saveScene',true,true)
  15228. }
  15229. }
  15230. });
  15231. me.addListener('keydown', function(type, evt) {
  15232. var keyCode = evt.keyCode || evt.which;
  15233. if (keyCode == 13) {//回车
  15234. if(me.fireEvent('beforeenterkeydown')){
  15235. domUtils.preventDefault(evt);
  15236. return;
  15237. }
  15238. me.fireEvent('saveScene',true,true);
  15239. hTag = '';
  15240. var range = me.selection.getRange();
  15241. if (!range.collapsed) {
  15242. //跨td不能删
  15243. var start = range.startContainer,
  15244. end = range.endContainer,
  15245. startTd = domUtils.findParentByTagName(start, 'td', true),
  15246. endTd = domUtils.findParentByTagName(end, 'td', true);
  15247. if (startTd && endTd && startTd !== endTd || !startTd && endTd || startTd && !endTd) {
  15248. evt.preventDefault ? evt.preventDefault() : ( evt.returnValue = false);
  15249. return;
  15250. }
  15251. }
  15252. if (tag == 'p') {
  15253. if (!browser.ie) {
  15254. start = domUtils.findParentByTagName(range.startContainer, ['ol','ul','p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6','blockquote','caption'], true);
  15255. //opera下执行formatblock会在table的场景下有问题,回车在opera原生支持很好,所以暂时在opera去掉调用这个原生的command
  15256. //trace:2431
  15257. if (!start && !browser.opera) {
  15258. me.document.execCommand('formatBlock', false, '<p>');
  15259. if (browser.gecko) {
  15260. range = me.selection.getRange();
  15261. start = domUtils.findParentByTagName(range.startContainer, 'p', true);
  15262. start && domUtils.removeDirtyAttr(start);
  15263. }
  15264. } else {
  15265. hTag = start.tagName;
  15266. start.tagName.toLowerCase() == 'p' && browser.gecko && domUtils.removeDirtyAttr(start);
  15267. }
  15268. }
  15269. } else {
  15270. evt.preventDefault ? evt.preventDefault() : ( evt.returnValue = false);
  15271. if (!range.collapsed) {
  15272. range.deleteContents();
  15273. start = range.startContainer;
  15274. if (start.nodeType == 1 && (start = start.childNodes[range.startOffset])) {
  15275. while (start.nodeType == 1) {
  15276. if (dtd.$empty[start.tagName]) {
  15277. range.setStartBefore(start).setCursor();
  15278. if (me.undoManger) {
  15279. me.undoManger.save();
  15280. }
  15281. return false;
  15282. }
  15283. if (!start.firstChild) {
  15284. var br = range.document.createElement('br');
  15285. start.appendChild(br);
  15286. range.setStart(start, 0).setCursor();
  15287. if (me.undoManger) {
  15288. me.undoManger.save();
  15289. }
  15290. return false;
  15291. }
  15292. start = start.firstChild;
  15293. }
  15294. if (start === range.startContainer.childNodes[range.startOffset]) {
  15295. br = range.document.createElement('br');
  15296. range.insertNode(br).setCursor();
  15297. } else {
  15298. range.setStart(start, 0).setCursor();
  15299. }
  15300. } else {
  15301. br = range.document.createElement('br');
  15302. range.insertNode(br).setStartAfter(br).setCursor();
  15303. }
  15304. } else {
  15305. br = range.document.createElement('br');
  15306. range.insertNode(br);
  15307. var parent = br.parentNode;
  15308. if (parent.lastChild === br) {
  15309. br.parentNode.insertBefore(br.cloneNode(true), br);
  15310. range.setStartBefore(br);
  15311. } else {
  15312. range.setStartAfter(br);
  15313. }
  15314. range.setCursor();
  15315. }
  15316. }
  15317. }
  15318. });
  15319. };
  15320. // plugins/keystrokes.js
  15321. /* 处理特殊键的兼容性问题 */
  15322. UE.plugins['keystrokes'] = function() {
  15323. var me = this;
  15324. var collapsed = true;
  15325. me.addListener('keydown', function(type, evt) {
  15326. var keyCode = evt.keyCode || evt.which,
  15327. rng = me.selection.getRange();
  15328. //处理全选的情况
  15329. if(!rng.collapsed && !(evt.ctrlKey || evt.shiftKey || evt.altKey || evt.metaKey) && (keyCode >= 65 && keyCode <=90
  15330. || keyCode >= 48 && keyCode <= 57 ||
  15331. keyCode >= 96 && keyCode <= 111 || {
  15332. 13:1,
  15333. 8:1,
  15334. 46:1
  15335. }[keyCode])
  15336. ){
  15337. var tmpNode = rng.startContainer;
  15338. if(domUtils.isFillChar(tmpNode)){
  15339. rng.setStartBefore(tmpNode)
  15340. }
  15341. tmpNode = rng.endContainer;
  15342. if(domUtils.isFillChar(tmpNode)){
  15343. rng.setEndAfter(tmpNode)
  15344. }
  15345. rng.txtToElmBoundary();
  15346. //结束边界可能放到了br的前边,要把br包含进来
  15347. // x[xxx]<br/>
  15348. if(rng.endContainer && rng.endContainer.nodeType == 1){
  15349. tmpNode = rng.endContainer.childNodes[rng.endOffset];
  15350. if(tmpNode && domUtils.isBr(tmpNode)){
  15351. rng.setEndAfter(tmpNode);
  15352. }
  15353. }
  15354. if(rng.startOffset == 0){
  15355. tmpNode = rng.startContainer;
  15356. if(domUtils.isBoundaryNode(tmpNode,'firstChild') ){
  15357. tmpNode = rng.endContainer;
  15358. if(rng.endOffset == (tmpNode.nodeType == 3 ? tmpNode.nodeValue.length : tmpNode.childNodes.length) && domUtils.isBoundaryNode(tmpNode,'lastChild')){
  15359. me.fireEvent('saveScene');
  15360. me.body.innerHTML = '<p>'+(browser.ie ? '' : '<br/>')+'</p>';
  15361. rng.setStart(me.body.firstChild,0).setCursor(false,true);
  15362. me._selectionChange();
  15363. return;
  15364. }
  15365. }
  15366. }
  15367. }
  15368. //处理backspace
  15369. if (keyCode == keymap.Backspace) {
  15370. rng = me.selection.getRange();
  15371. collapsed = rng.collapsed;
  15372. if(me.fireEvent('delkeydown',evt)){
  15373. return;
  15374. }
  15375. var start,end;
  15376. //避免按两次删除才能生效的问题
  15377. if(rng.collapsed && rng.inFillChar()){
  15378. start = rng.startContainer;
  15379. if(domUtils.isFillChar(start)){
  15380. rng.setStartBefore(start).shrinkBoundary(true).collapse(true);
  15381. domUtils.remove(start)
  15382. }else{
  15383. start.nodeValue = start.nodeValue.replace(new RegExp('^' + domUtils.fillChar ),'');
  15384. rng.startOffset--;
  15385. rng.collapse(true).select(true)
  15386. }
  15387. }
  15388. //解决选中control元素不能删除的问题
  15389. if (start = rng.getClosedNode()) {
  15390. me.fireEvent('saveScene');
  15391. rng.setStartBefore(start);
  15392. domUtils.remove(start);
  15393. rng.setCursor();
  15394. me.fireEvent('saveScene');
  15395. domUtils.preventDefault(evt);
  15396. return;
  15397. }
  15398. //阻止在table上的删除
  15399. if (!browser.ie) {
  15400. start = domUtils.findParentByTagName(rng.startContainer, 'table', true);
  15401. end = domUtils.findParentByTagName(rng.endContainer, 'table', true);
  15402. if (start && !end || !start && end || start !== end) {
  15403. evt.preventDefault();
  15404. return;
  15405. }
  15406. }
  15407. }
  15408. //处理tab键的逻辑
  15409. if (keyCode == keymap.Tab) {
  15410. //不处理以下标签
  15411. var excludeTagNameForTabKey = {
  15412. 'ol' : 1,
  15413. 'ul' : 1,
  15414. 'table':1
  15415. };
  15416. //处理组件里的tab按下事件
  15417. if(me.fireEvent('tabkeydown',evt)){
  15418. domUtils.preventDefault(evt);
  15419. return;
  15420. }
  15421. var range = me.selection.getRange();
  15422. me.fireEvent('saveScene');
  15423. for (var i = 0,txt = '',tabSize = me.options.tabSize|| 4,tabNode = me.options.tabNode || '&nbsp;'; i < tabSize; i++) {
  15424. txt += tabNode;
  15425. }
  15426. var span = me.document.createElement('span');
  15427. span.innerHTML = txt + domUtils.fillChar;
  15428. if (range.collapsed) {
  15429. range.insertNode(span.cloneNode(true).firstChild).setCursor(true);
  15430. } else {
  15431. var filterFn = function(node) {
  15432. return domUtils.isBlockElm(node) && !excludeTagNameForTabKey[node.tagName.toLowerCase()]
  15433. };
  15434. //普通的情况
  15435. start = domUtils.findParent(range.startContainer, filterFn,true);
  15436. end = domUtils.findParent(range.endContainer, filterFn,true);
  15437. if (start && end && start === end) {
  15438. range.deleteContents();
  15439. range.insertNode(span.cloneNode(true).firstChild).setCursor(true);
  15440. } else {
  15441. var bookmark = range.createBookmark();
  15442. range.enlarge(true);
  15443. var bookmark2 = range.createBookmark(),
  15444. current = domUtils.getNextDomNode(bookmark2.start, false, filterFn);
  15445. while (current && !(domUtils.getPosition(current, bookmark2.end) & domUtils.POSITION_FOLLOWING)) {
  15446. current.insertBefore(span.cloneNode(true).firstChild, current.firstChild);
  15447. current = domUtils.getNextDomNode(current, false, filterFn);
  15448. }
  15449. range.moveToBookmark(bookmark2).moveToBookmark(bookmark).select();
  15450. }
  15451. }
  15452. domUtils.preventDefault(evt)
  15453. }
  15454. //trace:1634
  15455. //ff的del键在容器空的时候,也会删除
  15456. if(browser.gecko && keyCode == 46){
  15457. range = me.selection.getRange();
  15458. if(range.collapsed){
  15459. start = range.startContainer;
  15460. if(domUtils.isEmptyBlock(start)){
  15461. var parent = start.parentNode;
  15462. while(domUtils.getChildCount(parent) == 1 && !domUtils.isBody(parent)){
  15463. start = parent;
  15464. parent = parent.parentNode;
  15465. }
  15466. if(start === parent.lastChild)
  15467. evt.preventDefault();
  15468. return;
  15469. }
  15470. }
  15471. }
  15472. });
  15473. me.addListener('keyup', function(type, evt) {
  15474. var keyCode = evt.keyCode || evt.which,
  15475. rng,me = this;
  15476. if(keyCode == keymap.Backspace){
  15477. if(me.fireEvent('delkeyup')){
  15478. return;
  15479. }
  15480. rng = me.selection.getRange();
  15481. if(rng.collapsed){
  15482. var tmpNode,
  15483. autoClearTagName = ['h1','h2','h3','h4','h5','h6'];
  15484. if(tmpNode = domUtils.findParentByTagName(rng.startContainer,autoClearTagName,true)){
  15485. if(domUtils.isEmptyBlock(tmpNode)){
  15486. var pre = tmpNode.previousSibling;
  15487. if(pre && pre.nodeName != 'TABLE'){
  15488. domUtils.remove(tmpNode);
  15489. rng.setStartAtLast(pre).setCursor(false,true);
  15490. return;
  15491. }else{
  15492. var next = tmpNode.nextSibling;
  15493. if(next && next.nodeName != 'TABLE'){
  15494. domUtils.remove(tmpNode);
  15495. rng.setStartAtFirst(next).setCursor(false,true);
  15496. return;
  15497. }
  15498. }
  15499. }
  15500. }
  15501. //处理当删除到body时,要重新给p标签展位
  15502. if(domUtils.isBody(rng.startContainer)){
  15503. var tmpNode = domUtils.createElement(me.document,'p',{
  15504. 'innerHTML' : browser.ie ? domUtils.fillChar : '<br/>'
  15505. });
  15506. rng.insertNode(tmpNode).setStart(tmpNode,0).setCursor(false,true);
  15507. }
  15508. }
  15509. //chrome下如果删除了inline标签,浏览器会有记忆,在输入文字还是会套上刚才删除的标签,所以这里再选一次就不会了
  15510. if( !collapsed && (rng.startContainer.nodeType == 3 || rng.startContainer.nodeType == 1 && domUtils.isEmptyBlock(rng.startContainer))){
  15511. if(browser.ie){
  15512. var span = rng.document.createElement('span');
  15513. rng.insertNode(span).setStartBefore(span).collapse(true);
  15514. rng.select();
  15515. domUtils.remove(span)
  15516. }else{
  15517. rng.select()
  15518. }
  15519. }
  15520. }
  15521. })
  15522. };
  15523. // plugins/fiximgclick.js
  15524. ///import core
  15525. ///commands 修复chrome下图片不能点击的问题,出现八个角可改变大小
  15526. ///commandsName FixImgClick
  15527. ///commandsTitle 修复chrome下图片不能点击的问题,出现八个角可改变大小
  15528. //修复chrome下图片不能点击的问题,出现八个角可改变大小
  15529. UE.plugins['fiximgclick'] = (function () {
  15530. var elementUpdated = false;
  15531. function Scale() {
  15532. this.editor = null;
  15533. this.resizer = null;
  15534. this.cover = null;
  15535. this.doc = document;
  15536. this.prePos = {x: 0, y: 0};
  15537. this.startPos = {x: 0, y: 0};
  15538. }
  15539. (function () {
  15540. var rect = [
  15541. //[left, top, width, height]
  15542. [0, 0, -1, -1],
  15543. [0, 0, 0, -1],
  15544. [0, 0, 1, -1],
  15545. [0, 0, -1, 0],
  15546. [0, 0, 1, 0],
  15547. [0, 0, -1, 1],
  15548. [0, 0, 0, 1],
  15549. [0, 0, 1, 1]
  15550. ];
  15551. Scale.prototype = {
  15552. init: function (editor) {
  15553. var me = this;
  15554. me.editor = editor;
  15555. me.startPos = this.prePos = {x: 0, y: 0};
  15556. me.dragId = -1;
  15557. var hands = [],
  15558. cover = me.cover = document.createElement('div'),
  15559. resizer = me.resizer = document.createElement('div');
  15560. cover.id = me.editor.ui.id + '_imagescale_cover';
  15561. cover.style.cssText = 'position:absolute;display:none;z-index:' + (me.editor.options.zIndex) + ';filter:alpha(opacity=0); opacity:0;background:#CCC;';
  15562. domUtils.on(cover, 'mousedown click', function () {
  15563. me.hide();
  15564. });
  15565. for (i = 0; i < 8; i++) {
  15566. hands.push('<span class="edui-editor-imagescale-hand' + i + '"></span>');
  15567. }
  15568. resizer.id = me.editor.ui.id + '_imagescale';
  15569. resizer.className = 'edui-editor-imagescale';
  15570. resizer.innerHTML = hands.join('');
  15571. resizer.style.cssText += ';display:none;border:1px solid #3b77ff;z-index:' + (me.editor.options.zIndex) + ';';
  15572. me.editor.ui.getDom().appendChild(cover);
  15573. me.editor.ui.getDom().appendChild(resizer);
  15574. me.initStyle();
  15575. me.initEvents();
  15576. },
  15577. initStyle: function () {
  15578. utils.cssRule('imagescale', '.edui-editor-imagescale{display:none;position:absolute;border:1px solid #38B2CE;cursor:hand;-webkit-box-sizing: content-box;-moz-box-sizing: content-box;box-sizing: content-box;}' +
  15579. '.edui-editor-imagescale span{position:absolute;width:6px;height:6px;overflow:hidden;font-size:0px;display:block;background-color:#3C9DD0;}'
  15580. + '.edui-editor-imagescale .edui-editor-imagescale-hand0{cursor:nw-resize;top:0;margin-top:-4px;left:0;margin-left:-4px;}'
  15581. + '.edui-editor-imagescale .edui-editor-imagescale-hand1{cursor:n-resize;top:0;margin-top:-4px;left:50%;margin-left:-4px;}'
  15582. + '.edui-editor-imagescale .edui-editor-imagescale-hand2{cursor:ne-resize;top:0;margin-top:-4px;left:100%;margin-left:-3px;}'
  15583. + '.edui-editor-imagescale .edui-editor-imagescale-hand3{cursor:w-resize;top:50%;margin-top:-4px;left:0;margin-left:-4px;}'
  15584. + '.edui-editor-imagescale .edui-editor-imagescale-hand4{cursor:e-resize;top:50%;margin-top:-4px;left:100%;margin-left:-3px;}'
  15585. + '.edui-editor-imagescale .edui-editor-imagescale-hand5{cursor:sw-resize;top:100%;margin-top:-3px;left:0;margin-left:-4px;}'
  15586. + '.edui-editor-imagescale .edui-editor-imagescale-hand6{cursor:s-resize;top:100%;margin-top:-3px;left:50%;margin-left:-4px;}'
  15587. + '.edui-editor-imagescale .edui-editor-imagescale-hand7{cursor:se-resize;top:100%;margin-top:-3px;left:100%;margin-left:-3px;}');
  15588. },
  15589. initEvents: function () {
  15590. var me = this;
  15591. me.startPos.x = me.startPos.y = 0;
  15592. me.isDraging = false;
  15593. },
  15594. _eventHandler: function (e) {
  15595. var me = this;
  15596. switch (e.type) {
  15597. case 'mousedown':
  15598. var hand = e.target || e.srcElement, hand;
  15599. if (hand.className.indexOf('edui-editor-imagescale-hand') != -1 && me.dragId == -1) {
  15600. me.dragId = hand.className.slice(-1);
  15601. me.startPos.x = me.prePos.x = e.clientX;
  15602. me.startPos.y = me.prePos.y = e.clientY;
  15603. domUtils.on(me.doc,'mousemove', me.proxy(me._eventHandler, me));
  15604. }
  15605. break;
  15606. case 'mousemove':
  15607. if (me.dragId != -1) {
  15608. me.updateContainerStyle(me.dragId, {x: e.clientX - me.prePos.x, y: e.clientY - me.prePos.y});
  15609. me.prePos.x = e.clientX;
  15610. me.prePos.y = e.clientY;
  15611. elementUpdated = true;
  15612. me.updateTargetElement();
  15613. }
  15614. break;
  15615. case 'mouseup':
  15616. if (me.dragId != -1) {
  15617. me.updateContainerStyle(me.dragId, {x: e.clientX - me.prePos.x, y: e.clientY - me.prePos.y});
  15618. me.updateTargetElement();
  15619. if (me.target.parentNode) me.attachTo(me.target);
  15620. me.dragId = -1;
  15621. }
  15622. domUtils.un(me.doc,'mousemove', me.proxy(me._eventHandler, me));
  15623. //修复只是点击挪动点,但没有改变大小,不应该触发contentchange
  15624. if(elementUpdated){
  15625. elementUpdated = false;
  15626. me.editor.fireEvent('contentchange');
  15627. }
  15628. break;
  15629. default:
  15630. break;
  15631. }
  15632. },
  15633. updateTargetElement: function () {
  15634. var me = this;
  15635. domUtils.setStyles(me.target, {
  15636. 'width': me.resizer.style.width,
  15637. 'height': me.resizer.style.height
  15638. });
  15639. me.target.width = parseInt(me.resizer.style.width);
  15640. me.target.height = parseInt(me.resizer.style.height);
  15641. me.attachTo(me.target);
  15642. },
  15643. updateContainerStyle: function (dir, offset) {
  15644. var me = this,
  15645. dom = me.resizer, tmp;
  15646. if (rect[dir][0] != 0) {
  15647. tmp = parseInt(dom.style.left) + offset.x;
  15648. dom.style.left = me._validScaledProp('left', tmp) + 'px';
  15649. }
  15650. if (rect[dir][1] != 0) {
  15651. tmp = parseInt(dom.style.top) + offset.y;
  15652. dom.style.top = me._validScaledProp('top', tmp) + 'px';
  15653. }
  15654. if (rect[dir][2] != 0) {
  15655. tmp = dom.clientWidth + rect[dir][2] * offset.x;
  15656. dom.style.width = me._validScaledProp('width', tmp) + 'px';
  15657. }
  15658. if (rect[dir][3] != 0) {
  15659. tmp = dom.clientHeight + rect[dir][3] * offset.y;
  15660. dom.style.height = me._validScaledProp('height', tmp) + 'px';
  15661. }
  15662. },
  15663. _validScaledProp: function (prop, value) {
  15664. var ele = this.resizer,
  15665. wrap = document;
  15666. value = isNaN(value) ? 0 : value;
  15667. switch (prop) {
  15668. case 'left':
  15669. return value < 0 ? 0 : (value + ele.clientWidth) > wrap.clientWidth ? wrap.clientWidth - ele.clientWidth : value;
  15670. case 'top':
  15671. return value < 0 ? 0 : (value + ele.clientHeight) > wrap.clientHeight ? wrap.clientHeight - ele.clientHeight : value;
  15672. case 'width':
  15673. return value <= 0 ? 1 : (value + ele.offsetLeft) > wrap.clientWidth ? wrap.clientWidth - ele.offsetLeft : value;
  15674. case 'height':
  15675. return value <= 0 ? 1 : (value + ele.offsetTop) > wrap.clientHeight ? wrap.clientHeight - ele.offsetTop : value;
  15676. }
  15677. },
  15678. hideCover: function () {
  15679. this.cover.style.display = 'none';
  15680. },
  15681. showCover: function () {
  15682. var me = this,
  15683. editorPos = domUtils.getXY(me.editor.ui.getDom()),
  15684. iframePos = domUtils.getXY(me.editor.iframe);
  15685. domUtils.setStyles(me.cover, {
  15686. 'width': me.editor.iframe.offsetWidth + 'px',
  15687. 'height': me.editor.iframe.offsetHeight + 'px',
  15688. 'top': iframePos.y - editorPos.y + 'px',
  15689. 'left': iframePos.x - editorPos.x + 'px',
  15690. 'position': 'absolute',
  15691. 'display': ''
  15692. })
  15693. },
  15694. show: function (targetObj) {
  15695. var me = this;
  15696. me.resizer.style.display = 'block';
  15697. if(targetObj) me.attachTo(targetObj);
  15698. domUtils.on(this.resizer, 'mousedown', me.proxy(me._eventHandler, me));
  15699. domUtils.on(me.doc, 'mouseup', me.proxy(me._eventHandler, me));
  15700. me.showCover();
  15701. me.editor.fireEvent('afterscaleshow', me);
  15702. me.editor.fireEvent('saveScene');
  15703. },
  15704. hide: function () {
  15705. var me = this;
  15706. me.hideCover();
  15707. me.resizer.style.display = 'none';
  15708. domUtils.un(me.resizer, 'mousedown', me.proxy(me._eventHandler, me));
  15709. domUtils.un(me.doc, 'mouseup', me.proxy(me._eventHandler, me));
  15710. me.editor.fireEvent('afterscalehide', me);
  15711. },
  15712. proxy: function( fn, context ) {
  15713. return function(e) {
  15714. return fn.apply( context || this, arguments);
  15715. };
  15716. },
  15717. attachTo: function (targetObj) {
  15718. var me = this,
  15719. target = me.target = targetObj,
  15720. resizer = this.resizer,
  15721. imgPos = domUtils.getXY(target),
  15722. iframePos = domUtils.getXY(me.editor.iframe),
  15723. editorPos = domUtils.getXY(resizer.parentNode);
  15724. domUtils.setStyles(resizer, {
  15725. 'width': target.width + 'px',
  15726. 'height': target.height + 'px',
  15727. 'left': iframePos.x + imgPos.x - me.editor.document.body.scrollLeft - editorPos.x - parseInt(resizer.style.borderLeftWidth) + 'px',
  15728. 'top': iframePos.y + imgPos.y - me.editor.document.body.scrollTop - editorPos.y - parseInt(resizer.style.borderTopWidth) + 'px'
  15729. });
  15730. }
  15731. }
  15732. })();
  15733. return function () {
  15734. var me = this,
  15735. imageScale;
  15736. me.setOpt('imageScaleEnabled', true);
  15737. if ( !browser.ie && me.options.imageScaleEnabled) {
  15738. me.addListener('click', function (type, e) {
  15739. var range = me.selection.getRange(),
  15740. img = range.getClosedNode();
  15741. if (img && img.tagName == 'IMG' && me.body.contentEditable!="false") {
  15742. if (img.className.indexOf("edui-faked-music") != -1 ||
  15743. img.getAttribute("anchorname") ||
  15744. domUtils.hasClass(img, 'loadingclass') ||
  15745. domUtils.hasClass(img, 'loaderrorclass')) { return }
  15746. if (!imageScale) {
  15747. imageScale = new Scale();
  15748. imageScale.init(me);
  15749. me.ui.getDom().appendChild(imageScale.resizer);
  15750. var _keyDownHandler = function (e) {
  15751. imageScale.hide();
  15752. if(imageScale.target) me.selection.getRange().selectNode(imageScale.target).select();
  15753. }, _mouseDownHandler = function (e) {
  15754. var ele = e.target || e.srcElement;
  15755. if (ele && (ele.className===undefined || ele.className.indexOf('edui-editor-imagescale') == -1)) {
  15756. _keyDownHandler(e);
  15757. }
  15758. }, timer;
  15759. me.addListener('afterscaleshow', function (e) {
  15760. me.addListener('beforekeydown', _keyDownHandler);
  15761. me.addListener('beforemousedown', _mouseDownHandler);
  15762. domUtils.on(document, 'keydown', _keyDownHandler);
  15763. domUtils.on(document,'mousedown', _mouseDownHandler);
  15764. me.selection.getNative().removeAllRanges();
  15765. });
  15766. me.addListener('afterscalehide', function (e) {
  15767. me.removeListener('beforekeydown', _keyDownHandler);
  15768. me.removeListener('beforemousedown', _mouseDownHandler);
  15769. domUtils.un(document, 'keydown', _keyDownHandler);
  15770. domUtils.un(document,'mousedown', _mouseDownHandler);
  15771. var target = imageScale.target;
  15772. if (target.parentNode) {
  15773. me.selection.getRange().selectNode(target).select();
  15774. }
  15775. });
  15776. //TODO 有iframe的情况,mousedown不能往下传。。
  15777. domUtils.on(imageScale.resizer, 'mousedown', function (e) {
  15778. me.selection.getNative().removeAllRanges();
  15779. var ele = e.target || e.srcElement;
  15780. if (ele && ele.className.indexOf('edui-editor-imagescale-hand') == -1) {
  15781. timer = setTimeout(function () {
  15782. imageScale.hide();
  15783. if(imageScale.target) me.selection.getRange().selectNode(ele).select();
  15784. }, 200);
  15785. }
  15786. });
  15787. domUtils.on(imageScale.resizer, 'mouseup', function (e) {
  15788. var ele = e.target || e.srcElement;
  15789. if (ele && ele.className.indexOf('edui-editor-imagescale-hand') == -1) {
  15790. clearTimeout(timer);
  15791. }
  15792. });
  15793. }
  15794. imageScale.show(img);
  15795. } else {
  15796. if (imageScale && imageScale.resizer.style.display != 'none') imageScale.hide();
  15797. }
  15798. });
  15799. }
  15800. if (browser.webkit) {
  15801. me.addListener('click', function (type, e) {
  15802. if (e.target.tagName == 'IMG' && me.body.contentEditable!="false") {
  15803. var range = new dom.Range(me.document);
  15804. range.selectNode(e.target).select();
  15805. }
  15806. });
  15807. }
  15808. }
  15809. })();
  15810. // plugins/autolink.js
  15811. ///import core
  15812. ///commands 为非ie浏览器自动添加a标签
  15813. ///commandsName AutoLink
  15814. ///commandsTitle 自动增加链接
  15815. /**
  15816. * @description 为非ie浏览器自动添加a标签
  15817. * @author zhanyi
  15818. */
  15819. UE.plugin.register('autolink',function(){
  15820. var cont = 0;
  15821. return !browser.ie ? {
  15822. bindEvents:{
  15823. 'reset' : function(){
  15824. cont = 0;
  15825. },
  15826. 'keydown':function(type, evt) {
  15827. var me = this;
  15828. var keyCode = evt.keyCode || evt.which;
  15829. if (keyCode == 32 || keyCode == 13) {
  15830. var sel = me.selection.getNative(),
  15831. range = sel.getRangeAt(0).cloneRange(),
  15832. offset,
  15833. charCode;
  15834. var start = range.startContainer;
  15835. while (start.nodeType == 1 && range.startOffset > 0) {
  15836. start = range.startContainer.childNodes[range.startOffset - 1];
  15837. if (!start){
  15838. break;
  15839. }
  15840. range.setStart(start, start.nodeType == 1 ? start.childNodes.length : start.nodeValue.length);
  15841. range.collapse(true);
  15842. start = range.startContainer;
  15843. }
  15844. do{
  15845. if (range.startOffset == 0) {
  15846. start = range.startContainer.previousSibling;
  15847. while (start && start.nodeType == 1) {
  15848. start = start.lastChild;
  15849. }
  15850. if (!start || domUtils.isFillChar(start)){
  15851. break;
  15852. }
  15853. offset = start.nodeValue.length;
  15854. } else {
  15855. start = range.startContainer;
  15856. offset = range.startOffset;
  15857. }
  15858. range.setStart(start, offset - 1);
  15859. charCode = range.toString().charCodeAt(0);
  15860. } while (charCode != 160 && charCode != 32);
  15861. if (range.toString().replace(new RegExp(domUtils.fillChar, 'g'), '').match(/(?:https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.)/i)) {
  15862. while(range.toString().length){
  15863. if(/^(?:https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.)/i.test(range.toString())){
  15864. break;
  15865. }
  15866. try{
  15867. range.setStart(range.startContainer,range.startOffset+1);
  15868. }catch(e){
  15869. //trace:2121
  15870. var start = range.startContainer;
  15871. while(!(next = start.nextSibling)){
  15872. if(domUtils.isBody(start)){
  15873. return;
  15874. }
  15875. start = start.parentNode;
  15876. }
  15877. range.setStart(next,0);
  15878. }
  15879. }
  15880. //range的开始边界已经在a标签里的不再处理
  15881. if(domUtils.findParentByTagName(range.startContainer,'a',true)){
  15882. return;
  15883. }
  15884. var a = me.document.createElement('a'),text = me.document.createTextNode(' '),href;
  15885. me.undoManger && me.undoManger.save();
  15886. a.appendChild(range.extractContents());
  15887. a.href = a.innerHTML = a.innerHTML.replace(/<[^>]+>/g,'');
  15888. href = a.getAttribute("href").replace(new RegExp(domUtils.fillChar,'g'),'');
  15889. href = /^(?:https?:\/\/)/ig.test(href) ? href : "http://"+ href;
  15890. a.setAttribute('_src',utils.html(href));
  15891. a.href = utils.html(href);
  15892. range.insertNode(a);
  15893. a.parentNode.insertBefore(text, a.nextSibling);
  15894. range.setStart(text, 0);
  15895. range.collapse(true);
  15896. sel.removeAllRanges();
  15897. sel.addRange(range);
  15898. me.undoManger && me.undoManger.save();
  15899. }
  15900. }
  15901. }
  15902. }
  15903. }:{}
  15904. },function(){
  15905. var keyCodes = {
  15906. 37:1, 38:1, 39:1, 40:1,
  15907. 13:1,32:1
  15908. };
  15909. function checkIsCludeLink(node){
  15910. if(node.nodeType == 3){
  15911. return null
  15912. }
  15913. if(node.nodeName == 'A'){
  15914. return node;
  15915. }
  15916. var lastChild = node.lastChild;
  15917. while(lastChild){
  15918. if(lastChild.nodeName == 'A'){
  15919. return lastChild;
  15920. }
  15921. if(lastChild.nodeType == 3){
  15922. if(domUtils.isWhitespace(lastChild)){
  15923. lastChild = lastChild.previousSibling;
  15924. continue;
  15925. }
  15926. return null
  15927. }
  15928. lastChild = lastChild.lastChild;
  15929. }
  15930. }
  15931. browser.ie && this.addListener('keyup',function(cmd,evt){
  15932. var me = this,keyCode = evt.keyCode;
  15933. if(keyCodes[keyCode]){
  15934. var rng = me.selection.getRange();
  15935. var start = rng.startContainer;
  15936. if(keyCode == 13){
  15937. while(start && !domUtils.isBody(start) && !domUtils.isBlockElm(start)){
  15938. start = start.parentNode;
  15939. }
  15940. if(start && !domUtils.isBody(start) && start.nodeName == 'P'){
  15941. var pre = start.previousSibling;
  15942. if(pre && pre.nodeType == 1){
  15943. var pre = checkIsCludeLink(pre);
  15944. if(pre && !pre.getAttribute('_href')){
  15945. domUtils.remove(pre,true);
  15946. }
  15947. }
  15948. }
  15949. }else if(keyCode == 32 ){
  15950. if(start.nodeType == 3 && /^\s$/.test(start.nodeValue)){
  15951. start = start.previousSibling;
  15952. if(start && start.nodeName == 'A' && !start.getAttribute('_href')){
  15953. domUtils.remove(start,true);
  15954. }
  15955. }
  15956. }else {
  15957. start = domUtils.findParentByTagName(start,'a',true);
  15958. if(start && !start.getAttribute('_href')){
  15959. var bk = rng.createBookmark();
  15960. domUtils.remove(start,true);
  15961. rng.moveToBookmark(bk).select(true)
  15962. }
  15963. }
  15964. }
  15965. });
  15966. }
  15967. );
  15968. // plugins/autoheight.js
  15969. ///import core
  15970. ///commands 当输入内容超过编辑器高度时,编辑器自动增高
  15971. ///commandsName AutoHeight,autoHeightEnabled
  15972. ///commandsTitle 自动增高
  15973. /**
  15974. * @description 自动伸展
  15975. * @author zhanyi
  15976. */
  15977. UE.plugins['autoheight'] = function () {
  15978. var me = this;
  15979. //提供开关,就算加载也可以关闭
  15980. me.autoHeightEnabled = me.options.autoHeightEnabled !== false;
  15981. if (!me.autoHeightEnabled) {
  15982. return;
  15983. }
  15984. var bakOverflow,
  15985. lastHeight = 0,
  15986. options = me.options,
  15987. currentHeight,
  15988. timer;
  15989. function adjustHeight() {
  15990. var me = this;
  15991. clearTimeout(timer);
  15992. if(isFullscreen)return;
  15993. if (!me.queryCommandState || me.queryCommandState && me.queryCommandState('source') != 1) {
  15994. timer = setTimeout(function(){
  15995. var node = me.body.lastChild;
  15996. while(node && node.nodeType != 1){
  15997. node = node.previousSibling;
  15998. }
  15999. if(node && node.nodeType == 1){
  16000. node.style.clear = 'both';
  16001. currentHeight = Math.max(domUtils.getXY(node).y + node.offsetHeight + 25 ,Math.max(options.minFrameHeight, options.initialFrameHeight)) ;
  16002. if (currentHeight != lastHeight) {
  16003. if (currentHeight !== parseInt(me.iframe.parentNode.style.height)) {
  16004. me.iframe.parentNode.style.height = currentHeight + 'px';
  16005. }
  16006. me.body.style.height = currentHeight + 'px';
  16007. lastHeight = currentHeight;
  16008. }
  16009. domUtils.removeStyle(node,'clear');
  16010. }
  16011. },50)
  16012. }
  16013. }
  16014. var isFullscreen;
  16015. me.addListener('fullscreenchanged',function(cmd,f){
  16016. isFullscreen = f
  16017. });
  16018. me.addListener('destroy', function () {
  16019. me.removeListener('contentchange afterinserthtml keyup mouseup',adjustHeight)
  16020. });
  16021. me.enableAutoHeight = function () {
  16022. var me = this;
  16023. if (!me.autoHeightEnabled) {
  16024. return;
  16025. }
  16026. var doc = me.document;
  16027. me.autoHeightEnabled = true;
  16028. bakOverflow = doc.body.style.overflowY;
  16029. doc.body.style.overflowY = 'hidden';
  16030. me.addListener('contentchange afterinserthtml keyup mouseup',adjustHeight);
  16031. //ff不给事件算得不对
  16032. setTimeout(function () {
  16033. adjustHeight.call(me);
  16034. }, browser.gecko ? 100 : 0);
  16035. me.fireEvent('autoheightchanged', me.autoHeightEnabled);
  16036. };
  16037. me.disableAutoHeight = function () {
  16038. me.body.style.overflowY = bakOverflow || '';
  16039. me.removeListener('contentchange', adjustHeight);
  16040. me.removeListener('keyup', adjustHeight);
  16041. me.removeListener('mouseup', adjustHeight);
  16042. me.autoHeightEnabled = false;
  16043. me.fireEvent('autoheightchanged', me.autoHeightEnabled);
  16044. };
  16045. me.on('setHeight',function(){
  16046. me.disableAutoHeight()
  16047. });
  16048. me.addListener('ready', function () {
  16049. me.enableAutoHeight();
  16050. //trace:1764
  16051. var timer;
  16052. domUtils.on(browser.ie ? me.body : me.document, browser.webkit ? 'dragover' : 'drop', function () {
  16053. clearTimeout(timer);
  16054. timer = setTimeout(function () {
  16055. //trace:3681
  16056. adjustHeight.call(me);
  16057. }, 100);
  16058. });
  16059. //修复内容过多时,回到顶部,顶部内容被工具栏遮挡问题
  16060. var lastScrollY;
  16061. window.onscroll = function(){
  16062. if(lastScrollY === null){
  16063. lastScrollY = this.scrollY
  16064. }else if(this.scrollY == 0 && lastScrollY != 0){
  16065. me.window.scrollTo(0,0);
  16066. lastScrollY = null;
  16067. }
  16068. }
  16069. });
  16070. };
  16071. // plugins/autofloat.js
  16072. ///import core
  16073. ///commands 悬浮工具栏
  16074. ///commandsName AutoFloat,autoFloatEnabled
  16075. ///commandsTitle 悬浮工具栏
  16076. /**
  16077. * modified by chengchao01
  16078. * 注意: 引入此功能后,在IE6下会将body的背景图片覆盖掉!
  16079. */
  16080. UE.plugins['autofloat'] = function() {
  16081. var me = this,
  16082. lang = me.getLang();
  16083. me.setOpt({
  16084. topOffset:0
  16085. });
  16086. var optsAutoFloatEnabled = me.options.autoFloatEnabled !== false,
  16087. topOffset = me.options.topOffset;
  16088. //如果不固定toolbar的位置,则直接退出
  16089. if(!optsAutoFloatEnabled){
  16090. return;
  16091. }
  16092. var uiUtils = UE.ui.uiUtils,
  16093. LteIE6 = browser.ie && browser.version <= 6,
  16094. quirks = browser.quirks;
  16095. function checkHasUI(){
  16096. if(!UE.ui){
  16097. alert(lang.autofloatMsg);
  16098. return 0;
  16099. }
  16100. return 1;
  16101. }
  16102. function fixIE6FixedPos(){
  16103. var docStyle = document.body.style;
  16104. docStyle.backgroundImage = 'url("about:blank")';
  16105. docStyle.backgroundAttachment = 'fixed';
  16106. }
  16107. var bakCssText,
  16108. placeHolder = document.createElement('div'),
  16109. toolbarBox,orgTop,
  16110. getPosition,
  16111. flag =true; //ie7模式下需要偏移
  16112. function setFloating(){
  16113. var toobarBoxPos = domUtils.getXY(toolbarBox),
  16114. origalFloat = domUtils.getComputedStyle(toolbarBox,'position'),
  16115. origalLeft = domUtils.getComputedStyle(toolbarBox,'left');
  16116. toolbarBox.style.width = toolbarBox.offsetWidth + 'px';
  16117. toolbarBox.style.zIndex = me.options.zIndex * 1 + 1;
  16118. toolbarBox.parentNode.insertBefore(placeHolder, toolbarBox);
  16119. if (LteIE6 || (quirks && browser.ie)) {
  16120. if(toolbarBox.style.position != 'absolute'){
  16121. toolbarBox.style.position = 'absolute';
  16122. }
  16123. toolbarBox.style.top = (document.body.scrollTop||document.documentElement.scrollTop) - orgTop + topOffset + 'px';
  16124. } else {
  16125. if (browser.ie7Compat && flag) {
  16126. flag = false;
  16127. toolbarBox.style.left = domUtils.getXY(toolbarBox).x - document.documentElement.getBoundingClientRect().left+2 + 'px';
  16128. }
  16129. if(toolbarBox.style.position != 'fixed'){
  16130. toolbarBox.style.position = 'fixed';
  16131. toolbarBox.style.top = topOffset +"px";
  16132. ((origalFloat == 'absolute' || origalFloat == 'relative') && parseFloat(origalLeft)) && (toolbarBox.style.left = toobarBoxPos.x + 'px');
  16133. }
  16134. }
  16135. }
  16136. function unsetFloating(){
  16137. flag = true;
  16138. if(placeHolder.parentNode){
  16139. placeHolder.parentNode.removeChild(placeHolder);
  16140. }
  16141. toolbarBox.style.cssText = bakCssText;
  16142. }
  16143. function updateFloating(){
  16144. var rect3 = getPosition(me.container);
  16145. var offset=me.options.toolbarTopOffset||0;
  16146. if (rect3.top < 0 && rect3.bottom - toolbarBox.offsetHeight > offset) {
  16147. setFloating();
  16148. }else{
  16149. unsetFloating();
  16150. }
  16151. }
  16152. var defer_updateFloating = utils.defer(function(){
  16153. updateFloating();
  16154. },browser.ie ? 200 : 100,true);
  16155. me.addListener('destroy',function(){
  16156. domUtils.un(window, ['scroll','resize'], updateFloating);
  16157. me.removeListener('keydown', defer_updateFloating);
  16158. });
  16159. me.addListener('ready', function(){
  16160. if(checkHasUI(me)){
  16161. //加载了ui组件,但在new时,没有加载ui,导致编辑器实例上没有ui类,所以这里做判断
  16162. if(!me.ui){
  16163. return;
  16164. }
  16165. getPosition = uiUtils.getClientRect;
  16166. toolbarBox = me.ui.getDom('toolbarbox');
  16167. orgTop = getPosition(toolbarBox).top;
  16168. bakCssText = toolbarBox.style.cssText;
  16169. placeHolder.style.height = toolbarBox.offsetHeight + 'px';
  16170. if(LteIE6){
  16171. fixIE6FixedPos();
  16172. }
  16173. domUtils.on(window, ['scroll','resize'], updateFloating);
  16174. me.addListener('keydown', defer_updateFloating);
  16175. me.addListener('beforefullscreenchange', function (t, enabled){
  16176. if (enabled) {
  16177. unsetFloating();
  16178. }
  16179. });
  16180. me.addListener('fullscreenchanged', function (t, enabled){
  16181. if (!enabled) {
  16182. updateFloating();
  16183. }
  16184. });
  16185. me.addListener('sourcemodechanged', function (t, enabled){
  16186. setTimeout(function (){
  16187. updateFloating();
  16188. },0);
  16189. });
  16190. me.addListener("clearDoc",function(){
  16191. setTimeout(function(){
  16192. updateFloating();
  16193. },0);
  16194. })
  16195. }
  16196. });
  16197. };
  16198. // plugins/video.js
  16199. /**
  16200. * video插件, 为UEditor提供视频插入支持
  16201. * @file
  16202. * @since 1.2.6.1
  16203. */
  16204. UE.plugins['video'] = function (){
  16205. var me =this;
  16206. /**
  16207. * 创建插入视频字符窜
  16208. * @param url 视频地址
  16209. * @param width 视频宽度
  16210. * @param height 视频高度
  16211. * @param align 视频对齐
  16212. * @param toEmbed 是否以flash代替显示
  16213. * @param addParagraph 是否需要添加P 标签
  16214. */
  16215. function creatInsertStr(url,width,height,id,align,classname,type){
  16216. var str;
  16217. switch (type){
  16218. case 'image':
  16219. str = '<img ' + (id ? 'id="' + id+'"' : '') + ' width="'+ width +'" height="' + height + '" _url="'+url+'" class="' + classname.replace(/\bvideo-js\b/, '') + '"' +
  16220. ' src="' + me.options.UEDITOR_HOME_URL+'themes/default/images/spacer.gif" style="background:url('+me.options.UEDITOR_HOME_URL+'themes/default/images/videologo.gif) no-repeat center center; border:1px solid gray;'+(align ? 'float:' + align + ';': '')+'" />'
  16221. break;
  16222. case 'embed':
  16223. str = '<embed type="application/x-shockwave-flash" class="' + classname + '" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
  16224. ' src="' + utils.html(url) + '" width="' + width + '" height="' + height + '"' + (align ? ' style="float:' + align + '"': '') +
  16225. ' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >';
  16226. break;
  16227. case 'video':
  16228. var ext = url.substr(url.lastIndexOf('.') + 1);
  16229. if(ext == 'ogv') ext = 'ogg';
  16230. str = '<video' + (id ? ' id="' + id + '"' : '') + ' class="' + classname + ' video-js" ' + (align ? ' style="float:' + align + '"': '') +
  16231. ' controls preload="none" width="' + width + '" height="' + height + '" src="' + url + '" data-setup="{}">' +
  16232. '<source src="' + url + '" type="video/' + ext + '" /></video>';
  16233. break;
  16234. }
  16235. return str;
  16236. }
  16237. function switchImgAndVideo(root,img2video){
  16238. utils.each(root.getNodesByTagName(img2video ? 'img' : 'embed video'),function(node){
  16239. var className = node.getAttr('class');
  16240. if(className && className.indexOf('edui-faked-video') != -1){
  16241. var html = creatInsertStr( img2video ? node.getAttr('_url') : node.getAttr('src'),node.getAttr('width'),node.getAttr('height'),null,node.getStyle('float') || '',className,img2video ? 'embed':'image');
  16242. node.parentNode.replaceChild(UE.uNode.createElement(html),node);
  16243. }
  16244. if(className && className.indexOf('edui-upload-video') != -1){
  16245. var html = creatInsertStr( img2video ? node.getAttr('_url') : node.getAttr('src'),node.getAttr('width'),node.getAttr('height'),null,node.getStyle('float') || '',className,img2video ? 'video':'image');
  16246. node.parentNode.replaceChild(UE.uNode.createElement(html),node);
  16247. }
  16248. })
  16249. }
  16250. me.addOutputRule(function(root){
  16251. switchImgAndVideo(root,true)
  16252. });
  16253. me.addInputRule(function(root){
  16254. switchImgAndVideo(root)
  16255. });
  16256. /**
  16257. * 插入视频
  16258. * @command insertvideo
  16259. * @method execCommand
  16260. * @param { String } cmd 命令字符串
  16261. * @param { Object } videoAttr 键值对对象, 描述一个视频的所有属性
  16262. * @example
  16263. * ```javascript
  16264. *
  16265. * var videoAttr = {
  16266. * //视频地址
  16267. * url: 'http://www.youku.com/xxx',
  16268. * //视频宽高值, 单位px
  16269. * width: 200,
  16270. * height: 100
  16271. * };
  16272. *
  16273. * //editor 是编辑器实例
  16274. * //向编辑器插入单个视频
  16275. * editor.execCommand( 'insertvideo', videoAttr );
  16276. * ```
  16277. */
  16278. /**
  16279. * 插入视频
  16280. * @command insertvideo
  16281. * @method execCommand
  16282. * @param { String } cmd 命令字符串
  16283. * @param { Array } videoArr 需要插入的视频的数组, 其中的每一个元素都是一个键值对对象, 描述了一个视频的所有属性
  16284. * @example
  16285. * ```javascript
  16286. *
  16287. * var videoAttr1 = {
  16288. * //视频地址
  16289. * url: 'http://www.youku.com/xxx',
  16290. * //视频宽高值, 单位px
  16291. * width: 200,
  16292. * height: 100
  16293. * },
  16294. * videoAttr2 = {
  16295. * //视频地址
  16296. * url: 'http://www.youku.com/xxx',
  16297. * //视频宽高值, 单位px
  16298. * width: 200,
  16299. * height: 100
  16300. * }
  16301. *
  16302. * //editor 是编辑器实例
  16303. * //该方法将会向编辑器内插入两个视频
  16304. * editor.execCommand( 'insertvideo', [ videoAttr1, videoAttr2 ] );
  16305. * ```
  16306. */
  16307. /**
  16308. * 查询当前光标所在处是否是一个视频
  16309. * @command insertvideo
  16310. * @method queryCommandState
  16311. * @param { String } cmd 需要查询的命令字符串
  16312. * @return { int } 如果当前光标所在处的元素是一个视频对象, 则返回1,否则返回0
  16313. * @example
  16314. * ```javascript
  16315. *
  16316. * //editor 是编辑器实例
  16317. * editor.queryCommandState( 'insertvideo' );
  16318. * ```
  16319. */
  16320. me.commands["insertvideo"] = {
  16321. execCommand: function (cmd, videoObjs, type){
  16322. videoObjs = utils.isArray(videoObjs)?videoObjs:[videoObjs];
  16323. var html = [],id = 'tmpVedio', cl;
  16324. for(var i=0,vi,len = videoObjs.length;i<len;i++){
  16325. vi = videoObjs[i];
  16326. cl = (type == 'upload' ? 'edui-upload-video video-js vjs-default-skin':'edui-faked-video');
  16327. html.push(creatInsertStr( vi.url, vi.width || 420, vi.height || 280, id + i, null, cl, 'image'));
  16328. }
  16329. me.execCommand("inserthtml",html.join(""),true);
  16330. var rng = this.selection.getRange();
  16331. for(var i= 0,len=videoObjs.length;i<len;i++){
  16332. var img = this.document.getElementById('tmpVedio'+i);
  16333. domUtils.removeAttributes(img,'id');
  16334. rng.selectNode(img).select();
  16335. me.execCommand('imagefloat',videoObjs[i].align)
  16336. }
  16337. },
  16338. queryCommandState : function(){
  16339. var img = me.selection.getRange().getClosedNode(),
  16340. flag = img && (img.className == "edui-faked-video" || img.className.indexOf("edui-upload-video")!=-1);
  16341. return flag ? 1 : 0;
  16342. }
  16343. };
  16344. };
  16345. // plugins/table.core.js
  16346. /**
  16347. * Created with JetBrains WebStorm.
  16348. * User: taoqili
  16349. * Date: 13-1-18
  16350. * Time: 上午11:09
  16351. * To change this template use File | Settings | File Templates.
  16352. */
  16353. /**
  16354. * UE表格操作类
  16355. * @param table
  16356. * @constructor
  16357. */
  16358. (function () {
  16359. var UETable = UE.UETable = function (table) {
  16360. this.table = table;
  16361. this.indexTable = [];
  16362. this.selectedTds = [];
  16363. this.cellsRange = {};
  16364. this.update(table);
  16365. };
  16366. //===以下为静态工具方法===
  16367. UETable.removeSelectedClass = function (cells) {
  16368. utils.each(cells, function (cell) {
  16369. domUtils.removeClasses(cell, "selectTdClass");
  16370. })
  16371. };
  16372. UETable.addSelectedClass = function (cells) {
  16373. utils.each(cells, function (cell) {
  16374. domUtils.addClass(cell, "selectTdClass");
  16375. })
  16376. };
  16377. UETable.isEmptyBlock = function (node) {
  16378. var reg = new RegExp(domUtils.fillChar, 'g');
  16379. if (node[browser.ie ? 'innerText' : 'textContent'].replace(/^\s*$/, '').replace(reg, '').length > 0) {
  16380. return 0;
  16381. }
  16382. for (var i in dtd.$isNotEmpty) if (dtd.$isNotEmpty.hasOwnProperty(i)) {
  16383. if (node.getElementsByTagName(i).length) {
  16384. return 0;
  16385. }
  16386. }
  16387. return 1;
  16388. };
  16389. UETable.getWidth = function (cell) {
  16390. if (!cell)return 0;
  16391. return parseInt(domUtils.getComputedStyle(cell, "width"), 10);
  16392. };
  16393. /**
  16394. * 获取单元格或者单元格组的“对齐”状态。 如果当前的检测对象是一个单元格组, 只有在满足所有单元格的 水平和竖直 对齐属性都相同的
  16395. * 条件时才会返回其状态值,否则将返回null; 如果当前只检测了一个单元格, 则直接返回当前单元格的对齐状态;
  16396. * @param table cell or table cells , 支持单个单元格dom对象 或者 单元格dom对象数组
  16397. * @return { align: 'left' || 'right' || 'center', valign: 'top' || 'middle' || 'bottom' } 或者 null
  16398. */
  16399. UETable.getTableCellAlignState = function ( cells ) {
  16400. !utils.isArray( cells ) && ( cells = [cells] );
  16401. var result = {},
  16402. status = ['align', 'valign'],
  16403. tempStatus = null,
  16404. isSame = true;//状态是否相同
  16405. utils.each( cells, function( cellNode ){
  16406. utils.each( status, function( currentState ){
  16407. tempStatus = cellNode.getAttribute( currentState );
  16408. if( !result[ currentState ] && tempStatus ) {
  16409. result[ currentState ] = tempStatus;
  16410. } else if( !result[ currentState ] || ( tempStatus !== result[ currentState ] ) ) {
  16411. isSame = false;
  16412. return false;
  16413. }
  16414. } );
  16415. return isSame;
  16416. });
  16417. return isSame ? result : null;
  16418. };
  16419. /**
  16420. * 根据当前选区获取相关的table信息
  16421. * @return {Object}
  16422. */
  16423. UETable.getTableItemsByRange = function (editor) {
  16424. var start = editor.selection.getStart();
  16425. //ff下会选中bookmark
  16426. if( start && start.id && start.id.indexOf('_baidu_bookmark_start_') === 0 && start.nextSibling) {
  16427. start = start.nextSibling;
  16428. }
  16429. //在table或者td边缘有可能存在选中tr的情况
  16430. var cell = start && domUtils.findParentByTagName(start, ["td", "th"], true),
  16431. tr = cell && cell.parentNode,
  16432. caption = start && domUtils.findParentByTagName(start, 'caption', true),
  16433. table = caption ? caption.parentNode : tr && tr.parentNode.parentNode;
  16434. return {
  16435. cell:cell,
  16436. tr:tr,
  16437. table:table,
  16438. caption:caption
  16439. }
  16440. };
  16441. UETable.getUETableBySelected = function (editor) {
  16442. var table = UETable.getTableItemsByRange(editor).table;
  16443. if (table && table.ueTable && table.ueTable.selectedTds.length) {
  16444. return table.ueTable;
  16445. }
  16446. return null;
  16447. };
  16448. UETable.getDefaultValue = function (editor, table) {
  16449. var borderMap = {
  16450. thin:'0px',
  16451. medium:'1px',
  16452. thick:'2px'
  16453. },
  16454. tableBorder, tdPadding, tdBorder, tmpValue;
  16455. if (!table) {
  16456. table = editor.document.createElement('table');
  16457. table.insertRow(0).insertCell(0).innerHTML = 'xxx';
  16458. editor.body.appendChild(table);
  16459. var td = table.getElementsByTagName('td')[0];
  16460. tmpValue = domUtils.getComputedStyle(table, 'border-left-width');
  16461. tableBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16462. tmpValue = domUtils.getComputedStyle(td, 'padding-left');
  16463. tdPadding = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16464. tmpValue = domUtils.getComputedStyle(td, 'border-left-width');
  16465. tdBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16466. domUtils.remove(table);
  16467. return {
  16468. tableBorder:tableBorder,
  16469. tdPadding:tdPadding,
  16470. tdBorder:tdBorder
  16471. };
  16472. } else {
  16473. td = table.getElementsByTagName('td')[0];
  16474. tmpValue = domUtils.getComputedStyle(table, 'border-left-width');
  16475. tableBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16476. tmpValue = domUtils.getComputedStyle(td, 'padding-left');
  16477. tdPadding = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16478. tmpValue = domUtils.getComputedStyle(td, 'border-left-width');
  16479. tdBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16480. return {
  16481. tableBorder:tableBorder,
  16482. tdPadding:tdPadding,
  16483. tdBorder:tdBorder
  16484. };
  16485. }
  16486. };
  16487. /**
  16488. * 根据当前点击的td或者table获取索引对象
  16489. * @param tdOrTable
  16490. */
  16491. UETable.getUETable = function (tdOrTable) {
  16492. var tag = tdOrTable.tagName.toLowerCase();
  16493. tdOrTable = (tag == "td" || tag == "th" || tag == 'caption') ? domUtils.findParentByTagName(tdOrTable, "table", true) : tdOrTable;
  16494. if (!tdOrTable.ueTable) {
  16495. tdOrTable.ueTable = new UETable(tdOrTable);
  16496. }
  16497. return tdOrTable.ueTable;
  16498. };
  16499. UETable.cloneCell = function(cell,ignoreMerge,keepPro){
  16500. if (!cell || utils.isString(cell)) {
  16501. return this.table.ownerDocument.createElement(cell || 'td');
  16502. }
  16503. var flag = domUtils.hasClass(cell, "selectTdClass");
  16504. flag && domUtils.removeClasses(cell, "selectTdClass");
  16505. var tmpCell = cell.cloneNode(true);
  16506. if (ignoreMerge) {
  16507. tmpCell.rowSpan = tmpCell.colSpan = 1;
  16508. }
  16509. //去掉宽高
  16510. !keepPro && domUtils.removeAttributes(tmpCell,'width height');
  16511. !keepPro && domUtils.removeAttributes(tmpCell,'style');
  16512. tmpCell.style.borderLeftStyle = "";
  16513. tmpCell.style.borderTopStyle = "";
  16514. tmpCell.style.borderLeftColor = cell.style.borderRightColor;
  16515. tmpCell.style.borderLeftWidth = cell.style.borderRightWidth;
  16516. tmpCell.style.borderTopColor = cell.style.borderBottomColor;
  16517. tmpCell.style.borderTopWidth = cell.style.borderBottomWidth;
  16518. flag && domUtils.addClass(cell, "selectTdClass");
  16519. return tmpCell;
  16520. }
  16521. UETable.prototype = {
  16522. getMaxRows:function () {
  16523. var rows = this.table.rows, maxLen = 1;
  16524. for (var i = 0, row; row = rows[i]; i++) {
  16525. var currentMax = 1;
  16526. for (var j = 0, cj; cj = row.cells[j++];) {
  16527. currentMax = Math.max(cj.rowSpan || 1, currentMax);
  16528. }
  16529. maxLen = Math.max(currentMax + i, maxLen);
  16530. }
  16531. return maxLen;
  16532. },
  16533. /**
  16534. * 获取当前表格的最大列数
  16535. */
  16536. getMaxCols:function () {
  16537. var rows = this.table.rows, maxLen = 0, cellRows = {};
  16538. for (var i = 0, row; row = rows[i]; i++) {
  16539. var cellsNum = 0;
  16540. for (var j = 0, cj; cj = row.cells[j++];) {
  16541. cellsNum += (cj.colSpan || 1);
  16542. if (cj.rowSpan && cj.rowSpan > 1) {
  16543. for (var k = 1; k < cj.rowSpan; k++) {
  16544. if (!cellRows['row_' + (i + k)]) {
  16545. cellRows['row_' + (i + k)] = (cj.colSpan || 1);
  16546. } else {
  16547. cellRows['row_' + (i + k)]++
  16548. }
  16549. }
  16550. }
  16551. }
  16552. cellsNum += cellRows['row_' + i] || 0;
  16553. maxLen = Math.max(cellsNum, maxLen);
  16554. }
  16555. return maxLen;
  16556. },
  16557. getCellColIndex:function (cell) {
  16558. },
  16559. /**
  16560. * 获取当前cell旁边的单元格,
  16561. * @param cell
  16562. * @param right
  16563. */
  16564. getHSideCell:function (cell, right) {
  16565. try {
  16566. var cellInfo = this.getCellInfo(cell),
  16567. previewRowIndex, previewColIndex;
  16568. var len = this.selectedTds.length,
  16569. range = this.cellsRange;
  16570. //首行或者首列没有前置单元格
  16571. if ((!right && (!len ? !cellInfo.colIndex : !range.beginColIndex)) || (right && (!len ? (cellInfo.colIndex == (this.colsNum - 1)) : (range.endColIndex == this.colsNum - 1)))) return null;
  16572. previewRowIndex = !len ? cellInfo.rowIndex : range.beginRowIndex;
  16573. previewColIndex = !right ? ( !len ? (cellInfo.colIndex < 1 ? 0 : (cellInfo.colIndex - 1)) : range.beginColIndex - 1)
  16574. : ( !len ? cellInfo.colIndex + 1 : range.endColIndex + 1);
  16575. return this.getCell(this.indexTable[previewRowIndex][previewColIndex].rowIndex, this.indexTable[previewRowIndex][previewColIndex].cellIndex);
  16576. } catch (e) {
  16577. showError(e);
  16578. }
  16579. },
  16580. getTabNextCell:function (cell, preRowIndex) {
  16581. var cellInfo = this.getCellInfo(cell),
  16582. rowIndex = preRowIndex || cellInfo.rowIndex,
  16583. colIndex = cellInfo.colIndex + 1 + (cellInfo.colSpan - 1),
  16584. nextCell;
  16585. try {
  16586. nextCell = this.getCell(this.indexTable[rowIndex][colIndex].rowIndex, this.indexTable[rowIndex][colIndex].cellIndex);
  16587. } catch (e) {
  16588. try {
  16589. rowIndex = rowIndex * 1 + 1;
  16590. colIndex = 0;
  16591. nextCell = this.getCell(this.indexTable[rowIndex][colIndex].rowIndex, this.indexTable[rowIndex][colIndex].cellIndex);
  16592. } catch (e) {
  16593. }
  16594. }
  16595. return nextCell;
  16596. },
  16597. /**
  16598. * 获取视觉上的后置单元格
  16599. * @param cell
  16600. * @param bottom
  16601. */
  16602. getVSideCell:function (cell, bottom, ignoreRange) {
  16603. try {
  16604. var cellInfo = this.getCellInfo(cell),
  16605. nextRowIndex, nextColIndex;
  16606. var len = this.selectedTds.length && !ignoreRange,
  16607. range = this.cellsRange;
  16608. //末行或者末列没有后置单元格
  16609. if ((!bottom && (cellInfo.rowIndex == 0)) || (bottom && (!len ? (cellInfo.rowIndex + cellInfo.rowSpan > this.rowsNum - 1) : (range.endRowIndex == this.rowsNum - 1)))) return null;
  16610. nextRowIndex = !bottom ? ( !len ? cellInfo.rowIndex - 1 : range.beginRowIndex - 1)
  16611. : ( !len ? (cellInfo.rowIndex + cellInfo.rowSpan) : range.endRowIndex + 1);
  16612. nextColIndex = !len ? cellInfo.colIndex : range.beginColIndex;
  16613. return this.getCell(this.indexTable[nextRowIndex][nextColIndex].rowIndex, this.indexTable[nextRowIndex][nextColIndex].cellIndex);
  16614. } catch (e) {
  16615. showError(e);
  16616. }
  16617. },
  16618. /**
  16619. * 获取相同结束位置的单元格,xOrY指代了是获取x轴相同还是y轴相同
  16620. */
  16621. getSameEndPosCells:function (cell, xOrY) {
  16622. try {
  16623. var flag = (xOrY.toLowerCase() === "x"),
  16624. end = domUtils.getXY(cell)[flag ? 'x' : 'y'] + cell["offset" + (flag ? 'Width' : 'Height')],
  16625. rows = this.table.rows,
  16626. cells = null, returns = [];
  16627. for (var i = 0; i < this.rowsNum; i++) {
  16628. cells = rows[i].cells;
  16629. for (var j = 0, tmpCell; tmpCell = cells[j++];) {
  16630. var tmpEnd = domUtils.getXY(tmpCell)[flag ? 'x' : 'y'] + tmpCell["offset" + (flag ? 'Width' : 'Height')];
  16631. //对应行的td已经被上面行rowSpan了
  16632. if (tmpEnd > end && flag) break;
  16633. if (cell == tmpCell || end == tmpEnd) {
  16634. //只获取单一的单元格
  16635. //todo 仅获取单一单元格在特定情况下会造成returns为空,从而影响后续的拖拽实现,修正这个。需考虑性能
  16636. if (tmpCell[flag ? "colSpan" : "rowSpan"] == 1) {
  16637. returns.push(tmpCell);
  16638. }
  16639. if (flag) break;
  16640. }
  16641. }
  16642. }
  16643. return returns;
  16644. } catch (e) {
  16645. showError(e);
  16646. }
  16647. },
  16648. setCellContent:function (cell, content) {
  16649. cell.innerHTML = content || (browser.ie ? domUtils.fillChar : "<br />");
  16650. },
  16651. cloneCell:UETable.cloneCell,
  16652. /**
  16653. * 获取跟当前单元格的右边竖线为左边的所有未合并单元格
  16654. */
  16655. getSameStartPosXCells:function (cell) {
  16656. try {
  16657. var start = domUtils.getXY(cell).x + cell.offsetWidth,
  16658. rows = this.table.rows, cells , returns = [];
  16659. for (var i = 0; i < this.rowsNum; i++) {
  16660. cells = rows[i].cells;
  16661. for (var j = 0, tmpCell; tmpCell = cells[j++];) {
  16662. var tmpStart = domUtils.getXY(tmpCell).x;
  16663. if (tmpStart > start) break;
  16664. if (tmpStart == start && tmpCell.colSpan == 1) {
  16665. returns.push(tmpCell);
  16666. break;
  16667. }
  16668. }
  16669. }
  16670. return returns;
  16671. } catch (e) {
  16672. showError(e);
  16673. }
  16674. },
  16675. /**
  16676. * 更新table对应的索引表
  16677. */
  16678. update:function (table) {
  16679. this.table = table || this.table;
  16680. this.selectedTds = [];
  16681. this.cellsRange = {};
  16682. this.indexTable = [];
  16683. var rows = this.table.rows,
  16684. rowsNum = this.getMaxRows(),
  16685. dNum = rowsNum - rows.length,
  16686. colsNum = this.getMaxCols();
  16687. while (dNum--) {
  16688. this.table.insertRow(rows.length);
  16689. }
  16690. this.rowsNum = rowsNum;
  16691. this.colsNum = colsNum;
  16692. for (var i = 0, len = rows.length; i < len; i++) {
  16693. this.indexTable[i] = new Array(colsNum);
  16694. }
  16695. //填充索引表
  16696. for (var rowIndex = 0, row; row = rows[rowIndex]; rowIndex++) {
  16697. for (var cellIndex = 0, cell, cells = row.cells; cell = cells[cellIndex]; cellIndex++) {
  16698. //修正整行被rowSpan时导致的行数计算错误
  16699. if (cell.rowSpan > rowsNum) {
  16700. cell.rowSpan = rowsNum;
  16701. }
  16702. var colIndex = cellIndex,
  16703. rowSpan = cell.rowSpan || 1,
  16704. colSpan = cell.colSpan || 1;
  16705. //当已经被上一行rowSpan或者被前一列colSpan了,则跳到下一个单元格进行
  16706. while (this.indexTable[rowIndex][colIndex]) colIndex++;
  16707. for (var j = 0; j < rowSpan; j++) {
  16708. for (var k = 0; k < colSpan; k++) {
  16709. this.indexTable[rowIndex + j][colIndex + k] = {
  16710. rowIndex:rowIndex,
  16711. cellIndex:cellIndex,
  16712. colIndex:colIndex,
  16713. rowSpan:rowSpan,
  16714. colSpan:colSpan
  16715. }
  16716. }
  16717. }
  16718. }
  16719. }
  16720. //修复残缺td
  16721. for (j = 0; j < rowsNum; j++) {
  16722. for (k = 0; k < colsNum; k++) {
  16723. if (this.indexTable[j][k] === undefined) {
  16724. row = rows[j];
  16725. cell = row.cells[row.cells.length - 1];
  16726. cell = cell ? cell.cloneNode(true) : this.table.ownerDocument.createElement("td");
  16727. this.setCellContent(cell);
  16728. if (cell.colSpan !== 1)cell.colSpan = 1;
  16729. if (cell.rowSpan !== 1)cell.rowSpan = 1;
  16730. row.appendChild(cell);
  16731. this.indexTable[j][k] = {
  16732. rowIndex:j,
  16733. cellIndex:cell.cellIndex,
  16734. colIndex:k,
  16735. rowSpan:1,
  16736. colSpan:1
  16737. }
  16738. }
  16739. }
  16740. }
  16741. //当框选后删除行或者列后撤销,需要重建选区。
  16742. var tds = domUtils.getElementsByTagName(this.table, "td"),
  16743. selectTds = [];
  16744. utils.each(tds, function (td) {
  16745. if (domUtils.hasClass(td, "selectTdClass")) {
  16746. selectTds.push(td);
  16747. }
  16748. });
  16749. if (selectTds.length) {
  16750. var start = selectTds[0],
  16751. end = selectTds[selectTds.length - 1],
  16752. startInfo = this.getCellInfo(start),
  16753. endInfo = this.getCellInfo(end);
  16754. this.selectedTds = selectTds;
  16755. this.cellsRange = {
  16756. beginRowIndex:startInfo.rowIndex,
  16757. beginColIndex:startInfo.colIndex,
  16758. endRowIndex:endInfo.rowIndex + endInfo.rowSpan - 1,
  16759. endColIndex:endInfo.colIndex + endInfo.colSpan - 1
  16760. };
  16761. }
  16762. //给第一行设置firstRow的样式名称,在排序图标的样式上使用到
  16763. if(!domUtils.hasClass(this.table.rows[0], "firstRow")) {
  16764. domUtils.addClass(this.table.rows[0], "firstRow");
  16765. for(var i = 1; i< this.table.rows.length; i++) {
  16766. domUtils.removeClasses(this.table.rows[i], "firstRow");
  16767. }
  16768. }
  16769. },
  16770. /**
  16771. * 获取单元格的索引信息
  16772. */
  16773. getCellInfo:function (cell) {
  16774. if (!cell) return;
  16775. var cellIndex = cell.cellIndex,
  16776. rowIndex = cell.parentNode.rowIndex,
  16777. rowInfo = this.indexTable[rowIndex],
  16778. numCols = this.colsNum;
  16779. for (var colIndex = cellIndex; colIndex < numCols; colIndex++) {
  16780. var cellInfo = rowInfo[colIndex];
  16781. if (cellInfo.rowIndex === rowIndex && cellInfo.cellIndex === cellIndex) {
  16782. return cellInfo;
  16783. }
  16784. }
  16785. },
  16786. /**
  16787. * 根据行列号获取单元格
  16788. */
  16789. getCell:function (rowIndex, cellIndex) {
  16790. return rowIndex < this.rowsNum && this.table.rows[rowIndex].cells[cellIndex] || null;
  16791. },
  16792. /**
  16793. * 删除单元格
  16794. */
  16795. deleteCell:function (cell, rowIndex) {
  16796. rowIndex = typeof rowIndex == 'number' ? rowIndex : cell.parentNode.rowIndex;
  16797. var row = this.table.rows[rowIndex];
  16798. row.deleteCell(cell.cellIndex);
  16799. },
  16800. /**
  16801. * 根据始末两个单元格获取被框选的所有单元格范围
  16802. */
  16803. getCellsRange:function (cellA, cellB) {
  16804. function checkRange(beginRowIndex, beginColIndex, endRowIndex, endColIndex) {
  16805. var tmpBeginRowIndex = beginRowIndex,
  16806. tmpBeginColIndex = beginColIndex,
  16807. tmpEndRowIndex = endRowIndex,
  16808. tmpEndColIndex = endColIndex,
  16809. cellInfo, colIndex, rowIndex;
  16810. // 通过indexTable检查是否存在超出TableRange上边界的情况
  16811. if (beginRowIndex > 0) {
  16812. for (colIndex = beginColIndex; colIndex < endColIndex; colIndex++) {
  16813. cellInfo = me.indexTable[beginRowIndex][colIndex];
  16814. rowIndex = cellInfo.rowIndex;
  16815. if (rowIndex < beginRowIndex) {
  16816. tmpBeginRowIndex = Math.min(rowIndex, tmpBeginRowIndex);
  16817. }
  16818. }
  16819. }
  16820. // 通过indexTable检查是否存在超出TableRange右边界的情况
  16821. if (endColIndex < me.colsNum) {
  16822. for (rowIndex = beginRowIndex; rowIndex < endRowIndex; rowIndex++) {
  16823. cellInfo = me.indexTable[rowIndex][endColIndex];
  16824. colIndex = cellInfo.colIndex + cellInfo.colSpan - 1;
  16825. if (colIndex > endColIndex) {
  16826. tmpEndColIndex = Math.max(colIndex, tmpEndColIndex);
  16827. }
  16828. }
  16829. }
  16830. // 检查是否有超出TableRange下边界的情况
  16831. if (endRowIndex < me.rowsNum) {
  16832. for (colIndex = beginColIndex; colIndex < endColIndex; colIndex++) {
  16833. cellInfo = me.indexTable[endRowIndex][colIndex];
  16834. rowIndex = cellInfo.rowIndex + cellInfo.rowSpan - 1;
  16835. if (rowIndex > endRowIndex) {
  16836. tmpEndRowIndex = Math.max(rowIndex, tmpEndRowIndex);
  16837. }
  16838. }
  16839. }
  16840. // 检查是否有超出TableRange左边界的情况
  16841. if (beginColIndex > 0) {
  16842. for (rowIndex = beginRowIndex; rowIndex < endRowIndex; rowIndex++) {
  16843. cellInfo = me.indexTable[rowIndex][beginColIndex];
  16844. colIndex = cellInfo.colIndex;
  16845. if (colIndex < beginColIndex) {
  16846. tmpBeginColIndex = Math.min(cellInfo.colIndex, tmpBeginColIndex);
  16847. }
  16848. }
  16849. }
  16850. //递归调用直至所有完成所有框选单元格的扩展
  16851. if (tmpBeginRowIndex != beginRowIndex || tmpBeginColIndex != beginColIndex || tmpEndRowIndex != endRowIndex || tmpEndColIndex != endColIndex) {
  16852. return checkRange(tmpBeginRowIndex, tmpBeginColIndex, tmpEndRowIndex, tmpEndColIndex);
  16853. } else {
  16854. // 不需要扩展TableRange的情况
  16855. return {
  16856. beginRowIndex:beginRowIndex,
  16857. beginColIndex:beginColIndex,
  16858. endRowIndex:endRowIndex,
  16859. endColIndex:endColIndex
  16860. };
  16861. }
  16862. }
  16863. try {
  16864. var me = this,
  16865. cellAInfo = me.getCellInfo(cellA);
  16866. if (cellA === cellB) {
  16867. return {
  16868. beginRowIndex:cellAInfo.rowIndex,
  16869. beginColIndex:cellAInfo.colIndex,
  16870. endRowIndex:cellAInfo.rowIndex + cellAInfo.rowSpan - 1,
  16871. endColIndex:cellAInfo.colIndex + cellAInfo.colSpan - 1
  16872. };
  16873. }
  16874. var cellBInfo = me.getCellInfo(cellB);
  16875. // 计算TableRange的四个边
  16876. var beginRowIndex = Math.min(cellAInfo.rowIndex, cellBInfo.rowIndex),
  16877. beginColIndex = Math.min(cellAInfo.colIndex, cellBInfo.colIndex),
  16878. endRowIndex = Math.max(cellAInfo.rowIndex + cellAInfo.rowSpan - 1, cellBInfo.rowIndex + cellBInfo.rowSpan - 1),
  16879. endColIndex = Math.max(cellAInfo.colIndex + cellAInfo.colSpan - 1, cellBInfo.colIndex + cellBInfo.colSpan - 1);
  16880. return checkRange(beginRowIndex, beginColIndex, endRowIndex, endColIndex);
  16881. } catch (e) {
  16882. //throw e;
  16883. }
  16884. },
  16885. /**
  16886. * 依据cellsRange获取对应的单元格集合
  16887. */
  16888. getCells:function (range) {
  16889. //每次获取cells之前必须先清除上次的选择,否则会对后续获取操作造成影响
  16890. this.clearSelected();
  16891. var beginRowIndex = range.beginRowIndex,
  16892. beginColIndex = range.beginColIndex,
  16893. endRowIndex = range.endRowIndex,
  16894. endColIndex = range.endColIndex,
  16895. cellInfo, rowIndex, colIndex, tdHash = {}, returnTds = [];
  16896. for (var i = beginRowIndex; i <= endRowIndex; i++) {
  16897. for (var j = beginColIndex; j <= endColIndex; j++) {
  16898. cellInfo = this.indexTable[i][j];
  16899. rowIndex = cellInfo.rowIndex;
  16900. colIndex = cellInfo.colIndex;
  16901. // 如果Cells里已经包含了此Cell则跳过
  16902. var key = rowIndex + '|' + colIndex;
  16903. if (tdHash[key]) continue;
  16904. tdHash[key] = 1;
  16905. if (rowIndex < i || colIndex < j || rowIndex + cellInfo.rowSpan - 1 > endRowIndex || colIndex + cellInfo.colSpan - 1 > endColIndex) {
  16906. return null;
  16907. }
  16908. returnTds.push(this.getCell(rowIndex, cellInfo.cellIndex));
  16909. }
  16910. }
  16911. return returnTds;
  16912. },
  16913. /**
  16914. * 清理已经选中的单元格
  16915. */
  16916. clearSelected:function () {
  16917. UETable.removeSelectedClass(this.selectedTds);
  16918. this.selectedTds = [];
  16919. this.cellsRange = {};
  16920. },
  16921. /**
  16922. * 根据range设置已经选中的单元格
  16923. */
  16924. setSelected:function (range) {
  16925. var cells = this.getCells(range);
  16926. UETable.addSelectedClass(cells);
  16927. this.selectedTds = cells;
  16928. this.cellsRange = range;
  16929. },
  16930. isFullRow:function () {
  16931. var range = this.cellsRange;
  16932. return (range.endColIndex - range.beginColIndex + 1) == this.colsNum;
  16933. },
  16934. isFullCol:function () {
  16935. var range = this.cellsRange,
  16936. table = this.table,
  16937. ths = table.getElementsByTagName("th"),
  16938. rows = range.endRowIndex - range.beginRowIndex + 1;
  16939. return !ths.length ? rows == this.rowsNum : rows == this.rowsNum || (rows == this.rowsNum - 1);
  16940. },
  16941. /**
  16942. * 获取视觉上的前置单元格,默认是左边,top传入时
  16943. * @param cell
  16944. * @param top
  16945. */
  16946. getNextCell:function (cell, bottom, ignoreRange) {
  16947. try {
  16948. var cellInfo = this.getCellInfo(cell),
  16949. nextRowIndex, nextColIndex;
  16950. var len = this.selectedTds.length && !ignoreRange,
  16951. range = this.cellsRange;
  16952. //末行或者末列没有后置单元格
  16953. if ((!bottom && (cellInfo.rowIndex == 0)) || (bottom && (!len ? (cellInfo.rowIndex + cellInfo.rowSpan > this.rowsNum - 1) : (range.endRowIndex == this.rowsNum - 1)))) return null;
  16954. nextRowIndex = !bottom ? ( !len ? cellInfo.rowIndex - 1 : range.beginRowIndex - 1)
  16955. : ( !len ? (cellInfo.rowIndex + cellInfo.rowSpan) : range.endRowIndex + 1);
  16956. nextColIndex = !len ? cellInfo.colIndex : range.beginColIndex;
  16957. return this.getCell(this.indexTable[nextRowIndex][nextColIndex].rowIndex, this.indexTable[nextRowIndex][nextColIndex].cellIndex);
  16958. } catch (e) {
  16959. showError(e);
  16960. }
  16961. },
  16962. getPreviewCell:function (cell, top) {
  16963. try {
  16964. var cellInfo = this.getCellInfo(cell),
  16965. previewRowIndex, previewColIndex;
  16966. var len = this.selectedTds.length,
  16967. range = this.cellsRange;
  16968. //首行或者首列没有前置单元格
  16969. if ((!top && (!len ? !cellInfo.colIndex : !range.beginColIndex)) || (top && (!len ? (cellInfo.rowIndex > (this.colsNum - 1)) : (range.endColIndex == this.colsNum - 1)))) return null;
  16970. previewRowIndex = !top ? ( !len ? cellInfo.rowIndex : range.beginRowIndex )
  16971. : ( !len ? (cellInfo.rowIndex < 1 ? 0 : (cellInfo.rowIndex - 1)) : range.beginRowIndex);
  16972. previewColIndex = !top ? ( !len ? (cellInfo.colIndex < 1 ? 0 : (cellInfo.colIndex - 1)) : range.beginColIndex - 1)
  16973. : ( !len ? cellInfo.colIndex : range.endColIndex + 1);
  16974. return this.getCell(this.indexTable[previewRowIndex][previewColIndex].rowIndex, this.indexTable[previewRowIndex][previewColIndex].cellIndex);
  16975. } catch (e) {
  16976. showError(e);
  16977. }
  16978. },
  16979. /**
  16980. * 移动单元格中的内容
  16981. */
  16982. moveContent:function (cellTo, cellFrom) {
  16983. if (UETable.isEmptyBlock(cellFrom)) return;
  16984. if (UETable.isEmptyBlock(cellTo)) {
  16985. cellTo.innerHTML = cellFrom.innerHTML;
  16986. return;
  16987. }
  16988. var child = cellTo.lastChild;
  16989. if (child.nodeType == 3 || !dtd.$block[child.tagName]) {
  16990. cellTo.appendChild(cellTo.ownerDocument.createElement('br'))
  16991. }
  16992. while (child = cellFrom.firstChild) {
  16993. cellTo.appendChild(child);
  16994. }
  16995. },
  16996. /**
  16997. * 向右合并单元格
  16998. */
  16999. mergeRight:function (cell) {
  17000. var cellInfo = this.getCellInfo(cell),
  17001. rightColIndex = cellInfo.colIndex + cellInfo.colSpan,
  17002. rightCellInfo = this.indexTable[cellInfo.rowIndex][rightColIndex],
  17003. rightCell = this.getCell(rightCellInfo.rowIndex, rightCellInfo.cellIndex);
  17004. //合并
  17005. cell.colSpan = cellInfo.colSpan + rightCellInfo.colSpan;
  17006. //被合并的单元格不应存在宽度属性
  17007. cell.removeAttribute("width");
  17008. //移动内容
  17009. this.moveContent(cell, rightCell);
  17010. //删掉被合并的Cell
  17011. this.deleteCell(rightCell, rightCellInfo.rowIndex);
  17012. this.update();
  17013. },
  17014. /**
  17015. * 向下合并单元格
  17016. */
  17017. mergeDown:function (cell) {
  17018. var cellInfo = this.getCellInfo(cell),
  17019. downRowIndex = cellInfo.rowIndex + cellInfo.rowSpan,
  17020. downCellInfo = this.indexTable[downRowIndex][cellInfo.colIndex],
  17021. downCell = this.getCell(downCellInfo.rowIndex, downCellInfo.cellIndex);
  17022. cell.rowSpan = cellInfo.rowSpan + downCellInfo.rowSpan;
  17023. cell.removeAttribute("height");
  17024. this.moveContent(cell, downCell);
  17025. this.deleteCell(downCell, downCellInfo.rowIndex);
  17026. this.update();
  17027. },
  17028. /**
  17029. * 合并整个range中的内容
  17030. */
  17031. mergeRange:function () {
  17032. //由于合并操作可以在任意时刻进行,所以无法通过鼠标位置等信息实时生成range,只能通过缓存实例中的cellsRange对象来访问
  17033. var range = this.cellsRange,
  17034. leftTopCell = this.getCell(range.beginRowIndex, this.indexTable[range.beginRowIndex][range.beginColIndex].cellIndex);
  17035. if (leftTopCell.tagName == "TH" && range.endRowIndex !== range.beginRowIndex) {
  17036. var index = this.indexTable,
  17037. info = this.getCellInfo(leftTopCell);
  17038. leftTopCell = this.getCell(1, index[1][info.colIndex].cellIndex);
  17039. range = this.getCellsRange(leftTopCell, this.getCell(index[this.rowsNum - 1][info.colIndex].rowIndex, index[this.rowsNum - 1][info.colIndex].cellIndex));
  17040. }
  17041. // 删除剩余的Cells
  17042. var cells = this.getCells(range);
  17043. for(var i= 0,ci;ci=cells[i++];){
  17044. if (ci !== leftTopCell) {
  17045. this.moveContent(leftTopCell, ci);
  17046. this.deleteCell(ci);
  17047. }
  17048. }
  17049. // 修改左上角Cell的rowSpan和colSpan,并调整宽度属性设置
  17050. leftTopCell.rowSpan = range.endRowIndex - range.beginRowIndex + 1;
  17051. leftTopCell.rowSpan > 1 && leftTopCell.removeAttribute("height");
  17052. leftTopCell.colSpan = range.endColIndex - range.beginColIndex + 1;
  17053. leftTopCell.colSpan > 1 && leftTopCell.removeAttribute("width");
  17054. if (leftTopCell.rowSpan == this.rowsNum && leftTopCell.colSpan != 1) {
  17055. leftTopCell.colSpan = 1;
  17056. }
  17057. if (leftTopCell.colSpan == this.colsNum && leftTopCell.rowSpan != 1) {
  17058. var rowIndex = leftTopCell.parentNode.rowIndex;
  17059. //解决IE下的表格操作问题
  17060. if( this.table.deleteRow ) {
  17061. for (var i = rowIndex+ 1, curIndex=rowIndex+ 1, len=leftTopCell.rowSpan; i < len; i++) {
  17062. this.table.deleteRow(curIndex);
  17063. }
  17064. } else {
  17065. for (var i = 0, len=leftTopCell.rowSpan - 1; i < len; i++) {
  17066. var row = this.table.rows[rowIndex + 1];
  17067. row.parentNode.removeChild(row);
  17068. }
  17069. }
  17070. leftTopCell.rowSpan = 1;
  17071. }
  17072. this.update();
  17073. },
  17074. /**
  17075. * 插入一行单元格
  17076. */
  17077. insertRow:function (rowIndex, sourceCell) {
  17078. var numCols = this.colsNum,
  17079. table = this.table,
  17080. row = table.insertRow(rowIndex), cell,
  17081. isInsertTitle = typeof sourceCell == 'string' && sourceCell.toUpperCase() == 'TH';
  17082. function replaceTdToTh(colIndex, cell, tableRow) {
  17083. if (colIndex == 0) {
  17084. var tr = tableRow.nextSibling || tableRow.previousSibling,
  17085. th = tr.cells[colIndex];
  17086. if (th.tagName == 'TH') {
  17087. th = cell.ownerDocument.createElement("th");
  17088. th.appendChild(cell.firstChild);
  17089. tableRow.insertBefore(th, cell);
  17090. domUtils.remove(cell)
  17091. }
  17092. }else{
  17093. if (cell.tagName == 'TH') {
  17094. var td = cell.ownerDocument.createElement("td");
  17095. td.appendChild(cell.firstChild);
  17096. tableRow.insertBefore(td, cell);
  17097. domUtils.remove(cell)
  17098. }
  17099. }
  17100. }
  17101. //首行直接插入,无需考虑部分单元格被rowspan的情况
  17102. if (rowIndex == 0 || rowIndex == this.rowsNum) {
  17103. for (var colIndex = 0; colIndex < numCols; colIndex++) {
  17104. cell = this.cloneCell(sourceCell, true);
  17105. this.setCellContent(cell);
  17106. cell.getAttribute('vAlign') && cell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17107. row.appendChild(cell);
  17108. if(!isInsertTitle) replaceTdToTh(colIndex, cell, row);
  17109. }
  17110. } else {
  17111. var infoRow = this.indexTable[rowIndex],
  17112. cellIndex = 0;
  17113. for (colIndex = 0; colIndex < numCols; colIndex++) {
  17114. var cellInfo = infoRow[colIndex];
  17115. //如果存在某个单元格的rowspan穿过待插入行的位置,则修改该单元格的rowspan即可,无需插入单元格
  17116. if (cellInfo.rowIndex < rowIndex) {
  17117. cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
  17118. cell.rowSpan = cellInfo.rowSpan + 1;
  17119. } else {
  17120. cell = this.cloneCell(sourceCell, true);
  17121. this.setCellContent(cell);
  17122. row.appendChild(cell);
  17123. }
  17124. if(!isInsertTitle) replaceTdToTh(colIndex, cell, row);
  17125. }
  17126. }
  17127. //框选时插入不触发contentchange,需要手动更新索引。
  17128. this.update();
  17129. return row;
  17130. },
  17131. /**
  17132. * 删除一行单元格
  17133. * @param rowIndex
  17134. */
  17135. deleteRow:function (rowIndex) {
  17136. var row = this.table.rows[rowIndex],
  17137. infoRow = this.indexTable[rowIndex],
  17138. colsNum = this.colsNum,
  17139. count = 0; //处理计数
  17140. for (var colIndex = 0; colIndex < colsNum;) {
  17141. var cellInfo = infoRow[colIndex],
  17142. cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
  17143. if (cell.rowSpan > 1) {
  17144. if (cellInfo.rowIndex == rowIndex) {
  17145. var clone = cell.cloneNode(true);
  17146. clone.rowSpan = cell.rowSpan - 1;
  17147. clone.innerHTML = "";
  17148. cell.rowSpan = 1;
  17149. var nextRowIndex = rowIndex + 1,
  17150. nextRow = this.table.rows[nextRowIndex],
  17151. insertCellIndex,
  17152. preMerged = this.getPreviewMergedCellsNum(nextRowIndex, colIndex) - count;
  17153. if (preMerged < colIndex) {
  17154. insertCellIndex = colIndex - preMerged - 1;
  17155. //nextRow.insertCell(insertCellIndex);
  17156. domUtils.insertAfter(nextRow.cells[insertCellIndex], clone);
  17157. } else {
  17158. if (nextRow.cells.length) nextRow.insertBefore(clone, nextRow.cells[0])
  17159. }
  17160. count += 1;
  17161. //cell.parentNode.removeChild(cell);
  17162. }
  17163. }
  17164. colIndex += cell.colSpan || 1;
  17165. }
  17166. var deleteTds = [], cacheMap = {};
  17167. for (colIndex = 0; colIndex < colsNum; colIndex++) {
  17168. var tmpRowIndex = infoRow[colIndex].rowIndex,
  17169. tmpCellIndex = infoRow[colIndex].cellIndex,
  17170. key = tmpRowIndex + "_" + tmpCellIndex;
  17171. if (cacheMap[key])continue;
  17172. cacheMap[key] = 1;
  17173. cell = this.getCell(tmpRowIndex, tmpCellIndex);
  17174. deleteTds.push(cell);
  17175. }
  17176. var mergeTds = [];
  17177. utils.each(deleteTds, function (td) {
  17178. if (td.rowSpan == 1) {
  17179. td.parentNode.removeChild(td);
  17180. } else {
  17181. mergeTds.push(td);
  17182. }
  17183. });
  17184. utils.each(mergeTds, function (td) {
  17185. td.rowSpan--;
  17186. });
  17187. row.parentNode.removeChild(row);
  17188. //浏览器方法本身存在bug,采用自定义方法删除
  17189. //this.table.deleteRow(rowIndex);
  17190. this.update();
  17191. },
  17192. insertCol:function (colIndex, sourceCell, defaultValue) {
  17193. var rowsNum = this.rowsNum,
  17194. rowIndex = 0,
  17195. tableRow, cell,
  17196. backWidth = parseInt((this.table.offsetWidth - (this.colsNum + 1) * 20 - (this.colsNum + 1)) / (this.colsNum + 1), 10),
  17197. isInsertTitleCol = typeof sourceCell == 'string' && sourceCell.toUpperCase() == 'TH';
  17198. function replaceTdToTh(rowIndex, cell, tableRow) {
  17199. if (rowIndex == 0) {
  17200. var th = cell.nextSibling || cell.previousSibling;
  17201. if (th.tagName == 'TH') {
  17202. th = cell.ownerDocument.createElement("th");
  17203. th.appendChild(cell.firstChild);
  17204. tableRow.insertBefore(th, cell);
  17205. domUtils.remove(cell)
  17206. }
  17207. }else{
  17208. if (cell.tagName == 'TH') {
  17209. var td = cell.ownerDocument.createElement("td");
  17210. td.appendChild(cell.firstChild);
  17211. tableRow.insertBefore(td, cell);
  17212. domUtils.remove(cell)
  17213. }
  17214. }
  17215. }
  17216. var preCell;
  17217. if (colIndex == 0 || colIndex == this.colsNum) {
  17218. for (; rowIndex < rowsNum; rowIndex++) {
  17219. tableRow = this.table.rows[rowIndex];
  17220. preCell = tableRow.cells[colIndex == 0 ? colIndex : tableRow.cells.length];
  17221. cell = this.cloneCell(sourceCell, true); //tableRow.insertCell(colIndex == 0 ? colIndex : tableRow.cells.length);
  17222. this.setCellContent(cell);
  17223. cell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17224. preCell && cell.setAttribute('width', preCell.getAttribute('width'));
  17225. if (!colIndex) {
  17226. tableRow.insertBefore(cell, tableRow.cells[0]);
  17227. } else {
  17228. domUtils.insertAfter(tableRow.cells[tableRow.cells.length - 1], cell);
  17229. }
  17230. if(!isInsertTitleCol) replaceTdToTh(rowIndex, cell, tableRow)
  17231. }
  17232. } else {
  17233. for (; rowIndex < rowsNum; rowIndex++) {
  17234. var cellInfo = this.indexTable[rowIndex][colIndex];
  17235. if (cellInfo.colIndex < colIndex) {
  17236. cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
  17237. cell.colSpan = cellInfo.colSpan + 1;
  17238. } else {
  17239. tableRow = this.table.rows[rowIndex];
  17240. preCell = tableRow.cells[cellInfo.cellIndex];
  17241. cell = this.cloneCell(sourceCell, true);//tableRow.insertCell(cellInfo.cellIndex);
  17242. this.setCellContent(cell);
  17243. cell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17244. preCell && cell.setAttribute('width', preCell.getAttribute('width'));
  17245. //防止IE下报错
  17246. preCell ? tableRow.insertBefore(cell, preCell) : tableRow.appendChild(cell);
  17247. }
  17248. if(!isInsertTitleCol) replaceTdToTh(rowIndex, cell, tableRow);
  17249. }
  17250. }
  17251. //框选时插入不触发contentchange,需要手动更新索引
  17252. this.update();
  17253. this.updateWidth(backWidth, defaultValue || {tdPadding:10, tdBorder:1});
  17254. },
  17255. updateWidth:function (width, defaultValue) {
  17256. var table = this.table,
  17257. tmpWidth = UETable.getWidth(table) - defaultValue.tdPadding * 2 - defaultValue.tdBorder + width;
  17258. if (tmpWidth < table.ownerDocument.body.offsetWidth) {
  17259. table.setAttribute("width", tmpWidth);
  17260. return;
  17261. }
  17262. var tds = domUtils.getElementsByTagName(this.table, "td th");
  17263. utils.each(tds, function (td) {
  17264. td.setAttribute("width", width);
  17265. })
  17266. },
  17267. deleteCol:function (colIndex) {
  17268. var indexTable = this.indexTable,
  17269. tableRows = this.table.rows,
  17270. backTableWidth = this.table.getAttribute("width"),
  17271. backTdWidth = 0,
  17272. rowsNum = this.rowsNum,
  17273. cacheMap = {};
  17274. for (var rowIndex = 0; rowIndex < rowsNum;) {
  17275. var infoRow = indexTable[rowIndex],
  17276. cellInfo = infoRow[colIndex],
  17277. key = cellInfo.rowIndex + '_' + cellInfo.colIndex;
  17278. // 跳过已经处理过的Cell
  17279. if (cacheMap[key])continue;
  17280. cacheMap[key] = 1;
  17281. var cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
  17282. if (!backTdWidth) backTdWidth = cell && parseInt(cell.offsetWidth / cell.colSpan, 10).toFixed(0);
  17283. // 如果Cell的colSpan大于1, 就修改colSpan, 否则就删掉这个Cell
  17284. if (cell.colSpan > 1) {
  17285. cell.colSpan--;
  17286. } else {
  17287. tableRows[rowIndex].deleteCell(cellInfo.cellIndex);
  17288. }
  17289. rowIndex += cellInfo.rowSpan || 1;
  17290. }
  17291. this.table.setAttribute("width", backTableWidth - backTdWidth);
  17292. this.update();
  17293. },
  17294. splitToCells:function (cell) {
  17295. var me = this,
  17296. cells = this.splitToRows(cell);
  17297. utils.each(cells, function (cell) {
  17298. me.splitToCols(cell);
  17299. })
  17300. },
  17301. splitToRows:function (cell) {
  17302. var cellInfo = this.getCellInfo(cell),
  17303. rowIndex = cellInfo.rowIndex,
  17304. colIndex = cellInfo.colIndex,
  17305. results = [];
  17306. // 修改Cell的rowSpan
  17307. cell.rowSpan = 1;
  17308. results.push(cell);
  17309. // 补齐单元格
  17310. for (var i = rowIndex, endRow = rowIndex + cellInfo.rowSpan; i < endRow; i++) {
  17311. if (i == rowIndex)continue;
  17312. var tableRow = this.table.rows[i],
  17313. tmpCell = tableRow.insertCell(colIndex - this.getPreviewMergedCellsNum(i, colIndex));
  17314. tmpCell.colSpan = cellInfo.colSpan;
  17315. this.setCellContent(tmpCell);
  17316. tmpCell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17317. tmpCell.setAttribute('align', cell.getAttribute('align'));
  17318. if (cell.style.cssText) {
  17319. tmpCell.style.cssText = cell.style.cssText;
  17320. }
  17321. results.push(tmpCell);
  17322. }
  17323. this.update();
  17324. return results;
  17325. },
  17326. getPreviewMergedCellsNum:function (rowIndex, colIndex) {
  17327. var indexRow = this.indexTable[rowIndex],
  17328. num = 0;
  17329. for (var i = 0; i < colIndex;) {
  17330. var colSpan = indexRow[i].colSpan,
  17331. tmpRowIndex = indexRow[i].rowIndex;
  17332. num += (colSpan - (tmpRowIndex == rowIndex ? 1 : 0));
  17333. i += colSpan;
  17334. }
  17335. return num;
  17336. },
  17337. splitToCols:function (cell) {
  17338. var backWidth = (cell.offsetWidth / cell.colSpan - 22).toFixed(0),
  17339. cellInfo = this.getCellInfo(cell),
  17340. rowIndex = cellInfo.rowIndex,
  17341. colIndex = cellInfo.colIndex,
  17342. results = [];
  17343. // 修改Cell的rowSpan
  17344. cell.colSpan = 1;
  17345. cell.setAttribute("width", backWidth);
  17346. results.push(cell);
  17347. // 补齐单元格
  17348. for (var j = colIndex, endCol = colIndex + cellInfo.colSpan; j < endCol; j++) {
  17349. if (j == colIndex)continue;
  17350. var tableRow = this.table.rows[rowIndex],
  17351. tmpCell = tableRow.insertCell(this.indexTable[rowIndex][j].cellIndex + 1);
  17352. tmpCell.rowSpan = cellInfo.rowSpan;
  17353. this.setCellContent(tmpCell);
  17354. tmpCell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17355. tmpCell.setAttribute('align', cell.getAttribute('align'));
  17356. tmpCell.setAttribute('width', backWidth);
  17357. if (cell.style.cssText) {
  17358. tmpCell.style.cssText = cell.style.cssText;
  17359. }
  17360. //处理th的情况
  17361. if (cell.tagName == 'TH') {
  17362. var th = cell.ownerDocument.createElement('th');
  17363. th.appendChild(tmpCell.firstChild);
  17364. th.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17365. th.rowSpan = tmpCell.rowSpan;
  17366. tableRow.insertBefore(th, tmpCell);
  17367. domUtils.remove(tmpCell);
  17368. }
  17369. results.push(tmpCell);
  17370. }
  17371. this.update();
  17372. return results;
  17373. },
  17374. isLastCell:function (cell, rowsNum, colsNum) {
  17375. rowsNum = rowsNum || this.rowsNum;
  17376. colsNum = colsNum || this.colsNum;
  17377. var cellInfo = this.getCellInfo(cell);
  17378. return ((cellInfo.rowIndex + cellInfo.rowSpan) == rowsNum) &&
  17379. ((cellInfo.colIndex + cellInfo.colSpan) == colsNum);
  17380. },
  17381. getLastCell:function (cells) {
  17382. cells = cells || this.table.getElementsByTagName("td");
  17383. var firstInfo = this.getCellInfo(cells[0]);
  17384. var me = this, last = cells[0],
  17385. tr = last.parentNode,
  17386. cellsNum = 0, cols = 0, rows;
  17387. utils.each(cells, function (cell) {
  17388. if (cell.parentNode == tr)cols += cell.colSpan || 1;
  17389. cellsNum += cell.rowSpan * cell.colSpan || 1;
  17390. });
  17391. rows = cellsNum / cols;
  17392. utils.each(cells, function (cell) {
  17393. if (me.isLastCell(cell, rows, cols)) {
  17394. last = cell;
  17395. return false;
  17396. }
  17397. });
  17398. return last;
  17399. },
  17400. selectRow:function (rowIndex) {
  17401. var indexRow = this.indexTable[rowIndex],
  17402. start = this.getCell(indexRow[0].rowIndex, indexRow[0].cellIndex),
  17403. end = this.getCell(indexRow[this.colsNum - 1].rowIndex, indexRow[this.colsNum - 1].cellIndex),
  17404. range = this.getCellsRange(start, end);
  17405. this.setSelected(range);
  17406. },
  17407. selectTable:function () {
  17408. var tds = this.table.getElementsByTagName("td"),
  17409. range = this.getCellsRange(tds[0], tds[tds.length - 1]);
  17410. this.setSelected(range);
  17411. },
  17412. setBackground:function (cells, value) {
  17413. if (typeof value === "string") {
  17414. utils.each(cells, function (cell) {
  17415. cell.style.backgroundColor = value;
  17416. })
  17417. } else if (typeof value === "object") {
  17418. value = utils.extend({
  17419. repeat:true,
  17420. colorList:["#ddd", "#fff"]
  17421. }, value);
  17422. var rowIndex = this.getCellInfo(cells[0]).rowIndex,
  17423. count = 0,
  17424. colors = value.colorList,
  17425. getColor = function (list, index, repeat) {
  17426. return list[index] ? list[index] : repeat ? list[index % list.length] : "";
  17427. };
  17428. for (var i = 0, cell; cell = cells[i++];) {
  17429. var cellInfo = this.getCellInfo(cell);
  17430. cell.style.backgroundColor = getColor(colors, ((rowIndex + count) == cellInfo.rowIndex) ? count : ++count, value.repeat);
  17431. }
  17432. }
  17433. },
  17434. removeBackground:function (cells) {
  17435. utils.each(cells, function (cell) {
  17436. cell.style.backgroundColor = "";
  17437. })
  17438. }
  17439. };
  17440. function showError(e) {
  17441. }
  17442. })();
  17443. // plugins/table.cmds.js
  17444. /**
  17445. * Created with JetBrains PhpStorm.
  17446. * User: taoqili
  17447. * Date: 13-2-20
  17448. * Time: 下午6:25
  17449. * To change this template use File | Settings | File Templates.
  17450. */
  17451. ;
  17452. (function () {
  17453. var UT = UE.UETable,
  17454. getTableItemsByRange = function (editor) {
  17455. return UT.getTableItemsByRange(editor);
  17456. },
  17457. getUETableBySelected = function (editor) {
  17458. return UT.getUETableBySelected(editor)
  17459. },
  17460. getDefaultValue = function (editor, table) {
  17461. return UT.getDefaultValue(editor, table);
  17462. },
  17463. getUETable = function (tdOrTable) {
  17464. return UT.getUETable(tdOrTable);
  17465. };
  17466. UE.commands['inserttable'] = {
  17467. queryCommandState: function () {
  17468. return getTableItemsByRange(this).table ? -1 : 0;
  17469. },
  17470. execCommand: function (cmd, opt) {
  17471. function createTable(opt, tdWidth) {
  17472. var html = [],
  17473. rowsNum = opt.numRows,
  17474. colsNum = opt.numCols;
  17475. for (var r = 0; r < rowsNum; r++) {
  17476. html.push('<tr' + (r == 0 ? ' class="firstRow"':'') + '>');
  17477. for (var c = 0; c < colsNum; c++) {
  17478. html.push('<td width="' + tdWidth + '" vAlign="' + opt.tdvalign + '" >' + (browser.ie && browser.version < 11 ? domUtils.fillChar : '<br/>') + '</td>')
  17479. }
  17480. html.push('</tr>')
  17481. }
  17482. //禁止指定table-width
  17483. return '<table><tbody>' + html.join('') + '</tbody></table>'
  17484. }
  17485. if (!opt) {
  17486. opt = utils.extend({}, {
  17487. numCols: this.options.defaultCols,
  17488. numRows: this.options.defaultRows,
  17489. tdvalign: this.options.tdvalign
  17490. })
  17491. }
  17492. var me = this;
  17493. var range = this.selection.getRange(),
  17494. start = range.startContainer,
  17495. firstParentBlock = domUtils.findParent(start, function (node) {
  17496. return domUtils.isBlockElm(node);
  17497. }, true) || me.body;
  17498. var defaultValue = getDefaultValue(me),
  17499. tableWidth = firstParentBlock.offsetWidth,
  17500. tdWidth = Math.floor(tableWidth / opt.numCols - defaultValue.tdPadding * 2 - defaultValue.tdBorder);
  17501. //todo其他属性
  17502. !opt.tdvalign && (opt.tdvalign = me.options.tdvalign);
  17503. me.execCommand("inserthtml", createTable(opt, tdWidth));
  17504. }
  17505. };
  17506. UE.commands['insertparagraphbeforetable'] = {
  17507. queryCommandState: function () {
  17508. return getTableItemsByRange(this).cell ? 0 : -1;
  17509. },
  17510. execCommand: function () {
  17511. var table = getTableItemsByRange(this).table;
  17512. if (table) {
  17513. var p = this.document.createElement("p");
  17514. p.innerHTML = browser.ie ? '&nbsp;' : '<br />';
  17515. table.parentNode.insertBefore(p, table);
  17516. this.selection.getRange().setStart(p, 0).setCursor();
  17517. }
  17518. }
  17519. };
  17520. UE.commands['deletetable'] = {
  17521. queryCommandState: function () {
  17522. var rng = this.selection.getRange();
  17523. return domUtils.findParentByTagName(rng.startContainer, 'table', true) ? 0 : -1;
  17524. },
  17525. execCommand: function (cmd, table) {
  17526. var rng = this.selection.getRange();
  17527. table = table || domUtils.findParentByTagName(rng.startContainer, 'table', true);
  17528. if (table) {
  17529. var next = table.nextSibling;
  17530. if (!next) {
  17531. next = domUtils.createElement(this.document, 'p', {
  17532. 'innerHTML': browser.ie ? domUtils.fillChar : '<br/>'
  17533. });
  17534. table.parentNode.insertBefore(next, table);
  17535. }
  17536. domUtils.remove(table);
  17537. rng = this.selection.getRange();
  17538. if (next.nodeType == 3) {
  17539. rng.setStartBefore(next)
  17540. } else {
  17541. rng.setStart(next, 0)
  17542. }
  17543. rng.setCursor(false, true)
  17544. this.fireEvent("tablehasdeleted")
  17545. }
  17546. }
  17547. };
  17548. UE.commands['cellalign'] = {
  17549. queryCommandState: function () {
  17550. return getSelectedArr(this).length ? 0 : -1
  17551. },
  17552. execCommand: function (cmd, align) {
  17553. var selectedTds = getSelectedArr(this);
  17554. if (selectedTds.length) {
  17555. for (var i = 0, ci; ci = selectedTds[i++];) {
  17556. ci.setAttribute('align', align);
  17557. }
  17558. }
  17559. }
  17560. };
  17561. UE.commands['cellvalign'] = {
  17562. queryCommandState: function () {
  17563. return getSelectedArr(this).length ? 0 : -1;
  17564. },
  17565. execCommand: function (cmd, valign) {
  17566. var selectedTds = getSelectedArr(this);
  17567. if (selectedTds.length) {
  17568. for (var i = 0, ci; ci = selectedTds[i++];) {
  17569. ci.setAttribute('vAlign', valign);
  17570. }
  17571. }
  17572. }
  17573. };
  17574. UE.commands['insertcaption'] = {
  17575. queryCommandState: function () {
  17576. var table = getTableItemsByRange(this).table;
  17577. if (table) {
  17578. return table.getElementsByTagName('caption').length == 0 ? 1 : -1;
  17579. }
  17580. return -1;
  17581. },
  17582. execCommand: function () {
  17583. var table = getTableItemsByRange(this).table;
  17584. if (table) {
  17585. var caption = this.document.createElement('caption');
  17586. caption.innerHTML = browser.ie ? domUtils.fillChar : '<br/>';
  17587. table.insertBefore(caption, table.firstChild);
  17588. var range = this.selection.getRange();
  17589. range.setStart(caption, 0).setCursor();
  17590. }
  17591. }
  17592. };
  17593. UE.commands['deletecaption'] = {
  17594. queryCommandState: function () {
  17595. var rng = this.selection.getRange(),
  17596. table = domUtils.findParentByTagName(rng.startContainer, 'table');
  17597. if (table) {
  17598. return table.getElementsByTagName('caption').length == 0 ? -1 : 1;
  17599. }
  17600. return -1;
  17601. },
  17602. execCommand: function () {
  17603. var rng = this.selection.getRange(),
  17604. table = domUtils.findParentByTagName(rng.startContainer, 'table');
  17605. if (table) {
  17606. domUtils.remove(table.getElementsByTagName('caption')[0]);
  17607. var range = this.selection.getRange();
  17608. range.setStart(table.rows[0].cells[0], 0).setCursor();
  17609. }
  17610. }
  17611. };
  17612. UE.commands['inserttitle'] = {
  17613. queryCommandState: function () {
  17614. var table = getTableItemsByRange(this).table;
  17615. if (table) {
  17616. var firstRow = table.rows[0];
  17617. return firstRow.cells[firstRow.cells.length-1].tagName.toLowerCase() != 'th' ? 0 : -1
  17618. }
  17619. return -1;
  17620. },
  17621. execCommand: function () {
  17622. var table = getTableItemsByRange(this).table;
  17623. if (table) {
  17624. getUETable(table).insertRow(0, 'th');
  17625. }
  17626. var th = table.getElementsByTagName('th')[0];
  17627. this.selection.getRange().setStart(th, 0).setCursor(false, true);
  17628. }
  17629. };
  17630. UE.commands['deletetitle'] = {
  17631. queryCommandState: function () {
  17632. var table = getTableItemsByRange(this).table;
  17633. if (table) {
  17634. var firstRow = table.rows[0];
  17635. return firstRow.cells[firstRow.cells.length-1].tagName.toLowerCase() == 'th' ? 0 : -1
  17636. }
  17637. return -1;
  17638. },
  17639. execCommand: function () {
  17640. var table = getTableItemsByRange(this).table;
  17641. if (table) {
  17642. domUtils.remove(table.rows[0])
  17643. }
  17644. var td = table.getElementsByTagName('td')[0];
  17645. this.selection.getRange().setStart(td, 0).setCursor(false, true);
  17646. }
  17647. };
  17648. UE.commands['inserttitlecol'] = {
  17649. queryCommandState: function () {
  17650. var table = getTableItemsByRange(this).table;
  17651. if (table) {
  17652. var lastRow = table.rows[table.rows.length-1];
  17653. return lastRow.getElementsByTagName('th').length ? -1 : 0;
  17654. }
  17655. return -1;
  17656. },
  17657. execCommand: function (cmd) {
  17658. var table = getTableItemsByRange(this).table;
  17659. if (table) {
  17660. getUETable(table).insertCol(0, 'th');
  17661. }
  17662. resetTdWidth(table, this);
  17663. var th = table.getElementsByTagName('th')[0];
  17664. this.selection.getRange().setStart(th, 0).setCursor(false, true);
  17665. }
  17666. };
  17667. UE.commands['deletetitlecol'] = {
  17668. queryCommandState: function () {
  17669. var table = getTableItemsByRange(this).table;
  17670. if (table) {
  17671. var lastRow = table.rows[table.rows.length-1];
  17672. return lastRow.getElementsByTagName('th').length ? 0 : -1;
  17673. }
  17674. return -1;
  17675. },
  17676. execCommand: function () {
  17677. var table = getTableItemsByRange(this).table;
  17678. if (table) {
  17679. for(var i = 0; i< table.rows.length; i++ ){
  17680. domUtils.remove(table.rows[i].children[0])
  17681. }
  17682. }
  17683. resetTdWidth(table, this);
  17684. var td = table.getElementsByTagName('td')[0];
  17685. this.selection.getRange().setStart(td, 0).setCursor(false, true);
  17686. }
  17687. };
  17688. UE.commands["mergeright"] = {
  17689. queryCommandState: function (cmd) {
  17690. var tableItems = getTableItemsByRange(this),
  17691. table = tableItems.table,
  17692. cell = tableItems.cell;
  17693. if (!table || !cell) return -1;
  17694. var ut = getUETable(table);
  17695. if (ut.selectedTds.length) return -1;
  17696. var cellInfo = ut.getCellInfo(cell),
  17697. rightColIndex = cellInfo.colIndex + cellInfo.colSpan;
  17698. if (rightColIndex >= ut.colsNum) return -1; // 如果处于最右边则不能向右合并
  17699. var rightCellInfo = ut.indexTable[cellInfo.rowIndex][rightColIndex],
  17700. rightCell = table.rows[rightCellInfo.rowIndex].cells[rightCellInfo.cellIndex];
  17701. if (!rightCell || cell.tagName != rightCell.tagName) return -1; // TH和TD不能相互合并
  17702. // 当且仅当两个Cell的开始列号和结束列号一致时能进行合并
  17703. return (rightCellInfo.rowIndex == cellInfo.rowIndex && rightCellInfo.rowSpan == cellInfo.rowSpan) ? 0 : -1;
  17704. },
  17705. execCommand: function (cmd) {
  17706. var rng = this.selection.getRange(),
  17707. bk = rng.createBookmark(true);
  17708. var cell = getTableItemsByRange(this).cell,
  17709. ut = getUETable(cell);
  17710. ut.mergeRight(cell);
  17711. rng.moveToBookmark(bk).select();
  17712. }
  17713. };
  17714. UE.commands["mergedown"] = {
  17715. queryCommandState: function (cmd) {
  17716. var tableItems = getTableItemsByRange(this),
  17717. table = tableItems.table,
  17718. cell = tableItems.cell;
  17719. if (!table || !cell) return -1;
  17720. var ut = getUETable(table);
  17721. if (ut.selectedTds.length)return -1;
  17722. var cellInfo = ut.getCellInfo(cell),
  17723. downRowIndex = cellInfo.rowIndex + cellInfo.rowSpan;
  17724. if (downRowIndex >= ut.rowsNum) return -1; // 如果处于最下边则不能向下合并
  17725. var downCellInfo = ut.indexTable[downRowIndex][cellInfo.colIndex],
  17726. downCell = table.rows[downCellInfo.rowIndex].cells[downCellInfo.cellIndex];
  17727. if (!downCell || cell.tagName != downCell.tagName) return -1; // TH和TD不能相互合并
  17728. // 当且仅当两个Cell的开始列号和结束列号一致时能进行合并
  17729. return (downCellInfo.colIndex == cellInfo.colIndex && downCellInfo.colSpan == cellInfo.colSpan) ? 0 : -1;
  17730. },
  17731. execCommand: function () {
  17732. var rng = this.selection.getRange(),
  17733. bk = rng.createBookmark(true);
  17734. var cell = getTableItemsByRange(this).cell,
  17735. ut = getUETable(cell);
  17736. ut.mergeDown(cell);
  17737. rng.moveToBookmark(bk).select();
  17738. }
  17739. };
  17740. UE.commands["mergecells"] = {
  17741. queryCommandState: function () {
  17742. return getUETableBySelected(this) ? 0 : -1;
  17743. },
  17744. execCommand: function () {
  17745. var ut = getUETableBySelected(this);
  17746. if (ut && ut.selectedTds.length) {
  17747. var cell = ut.selectedTds[0];
  17748. ut.mergeRange();
  17749. var rng = this.selection.getRange();
  17750. if (domUtils.isEmptyBlock(cell)) {
  17751. rng.setStart(cell, 0).collapse(true)
  17752. } else {
  17753. rng.selectNodeContents(cell)
  17754. }
  17755. rng.select();
  17756. }
  17757. }
  17758. };
  17759. UE.commands["insertrow"] = {
  17760. queryCommandState: function () {
  17761. var tableItems = getTableItemsByRange(this),
  17762. cell = tableItems.cell;
  17763. return cell && (cell.tagName == "TD" || (cell.tagName == 'TH' && tableItems.tr !== tableItems.table.rows[0])) &&
  17764. getUETable(tableItems.table).rowsNum < this.options.maxRowNum ? 0 : -1;
  17765. },
  17766. execCommand: function () {
  17767. var rng = this.selection.getRange(),
  17768. bk = rng.createBookmark(true);
  17769. var tableItems = getTableItemsByRange(this),
  17770. cell = tableItems.cell,
  17771. table = tableItems.table,
  17772. ut = getUETable(table),
  17773. cellInfo = ut.getCellInfo(cell);
  17774. //ut.insertRow(!ut.selectedTds.length ? cellInfo.rowIndex:ut.cellsRange.beginRowIndex,'');
  17775. if (!ut.selectedTds.length) {
  17776. ut.insertRow(cellInfo.rowIndex, cell);
  17777. } else {
  17778. var range = ut.cellsRange;
  17779. for (var i = 0, len = range.endRowIndex - range.beginRowIndex + 1; i < len; i++) {
  17780. ut.insertRow(range.beginRowIndex, cell);
  17781. }
  17782. }
  17783. rng.moveToBookmark(bk).select();
  17784. if (table.getAttribute("interlaced") === "enabled")this.fireEvent("interlacetable", table);
  17785. }
  17786. };
  17787. //后插入行
  17788. UE.commands["insertrownext"] = {
  17789. queryCommandState: function () {
  17790. var tableItems = getTableItemsByRange(this),
  17791. cell = tableItems.cell;
  17792. return cell && (cell.tagName == "TD") && getUETable(tableItems.table).rowsNum < this.options.maxRowNum ? 0 : -1;
  17793. },
  17794. execCommand: function () {
  17795. var rng = this.selection.getRange(),
  17796. bk = rng.createBookmark(true);
  17797. var tableItems = getTableItemsByRange(this),
  17798. cell = tableItems.cell,
  17799. table = tableItems.table,
  17800. ut = getUETable(table),
  17801. cellInfo = ut.getCellInfo(cell);
  17802. //ut.insertRow(!ut.selectedTds.length? cellInfo.rowIndex + cellInfo.rowSpan : ut.cellsRange.endRowIndex + 1,'');
  17803. if (!ut.selectedTds.length) {
  17804. ut.insertRow(cellInfo.rowIndex + cellInfo.rowSpan, cell);
  17805. } else {
  17806. var range = ut.cellsRange;
  17807. for (var i = 0, len = range.endRowIndex - range.beginRowIndex + 1; i < len; i++) {
  17808. ut.insertRow(range.endRowIndex + 1, cell);
  17809. }
  17810. }
  17811. rng.moveToBookmark(bk).select();
  17812. if (table.getAttribute("interlaced") === "enabled")this.fireEvent("interlacetable", table);
  17813. }
  17814. };
  17815. UE.commands["deleterow"] = {
  17816. queryCommandState: function () {
  17817. var tableItems = getTableItemsByRange(this);
  17818. return tableItems.cell ? 0 : -1;
  17819. },
  17820. execCommand: function () {
  17821. var cell = getTableItemsByRange(this).cell,
  17822. ut = getUETable(cell),
  17823. cellsRange = ut.cellsRange,
  17824. cellInfo = ut.getCellInfo(cell),
  17825. preCell = ut.getVSideCell(cell),
  17826. nextCell = ut.getVSideCell(cell, true),
  17827. rng = this.selection.getRange();
  17828. if (utils.isEmptyObject(cellsRange)) {
  17829. ut.deleteRow(cellInfo.rowIndex);
  17830. } else {
  17831. for (var i = cellsRange.beginRowIndex; i < cellsRange.endRowIndex + 1; i++) {
  17832. ut.deleteRow(cellsRange.beginRowIndex);
  17833. }
  17834. }
  17835. var table = ut.table;
  17836. if (!table.getElementsByTagName('td').length) {
  17837. var nextSibling = table.nextSibling;
  17838. domUtils.remove(table);
  17839. if (nextSibling) {
  17840. rng.setStart(nextSibling, 0).setCursor(false, true);
  17841. }
  17842. } else {
  17843. if (cellInfo.rowSpan == 1 || cellInfo.rowSpan == cellsRange.endRowIndex - cellsRange.beginRowIndex + 1) {
  17844. if (nextCell || preCell) rng.selectNodeContents(nextCell || preCell).setCursor(false, true);
  17845. } else {
  17846. var newCell = ut.getCell(cellInfo.rowIndex, ut.indexTable[cellInfo.rowIndex][cellInfo.colIndex].cellIndex);
  17847. if (newCell) rng.selectNodeContents(newCell).setCursor(false, true);
  17848. }
  17849. }
  17850. if (table.getAttribute("interlaced") === "enabled")this.fireEvent("interlacetable", table);
  17851. }
  17852. };
  17853. UE.commands["insertcol"] = {
  17854. queryCommandState: function (cmd) {
  17855. var tableItems = getTableItemsByRange(this),
  17856. cell = tableItems.cell;
  17857. return cell && (cell.tagName == "TD" || (cell.tagName == 'TH' && cell !== tableItems.tr.cells[0])) &&
  17858. getUETable(tableItems.table).colsNum < this.options.maxColNum ? 0 : -1;
  17859. },
  17860. execCommand: function (cmd) {
  17861. var rng = this.selection.getRange(),
  17862. bk = rng.createBookmark(true);
  17863. if (this.queryCommandState(cmd) == -1)return;
  17864. var cell = getTableItemsByRange(this).cell,
  17865. ut = getUETable(cell),
  17866. cellInfo = ut.getCellInfo(cell);
  17867. //ut.insertCol(!ut.selectedTds.length ? cellInfo.colIndex:ut.cellsRange.beginColIndex);
  17868. if (!ut.selectedTds.length) {
  17869. ut.insertCol(cellInfo.colIndex, cell);
  17870. } else {
  17871. var range = ut.cellsRange;
  17872. for (var i = 0, len = range.endColIndex - range.beginColIndex + 1; i < len; i++) {
  17873. ut.insertCol(range.beginColIndex, cell);
  17874. }
  17875. }
  17876. rng.moveToBookmark(bk).select(true);
  17877. }
  17878. };
  17879. UE.commands["insertcolnext"] = {
  17880. queryCommandState: function () {
  17881. var tableItems = getTableItemsByRange(this),
  17882. cell = tableItems.cell;
  17883. return cell && getUETable(tableItems.table).colsNum < this.options.maxColNum ? 0 : -1;
  17884. },
  17885. execCommand: function () {
  17886. var rng = this.selection.getRange(),
  17887. bk = rng.createBookmark(true);
  17888. var cell = getTableItemsByRange(this).cell,
  17889. ut = getUETable(cell),
  17890. cellInfo = ut.getCellInfo(cell);
  17891. //ut.insertCol(!ut.selectedTds.length ? cellInfo.colIndex + cellInfo.colSpan:ut.cellsRange.endColIndex +1);
  17892. if (!ut.selectedTds.length) {
  17893. ut.insertCol(cellInfo.colIndex + cellInfo.colSpan, cell);
  17894. } else {
  17895. var range = ut.cellsRange;
  17896. for (var i = 0, len = range.endColIndex - range.beginColIndex + 1; i < len; i++) {
  17897. ut.insertCol(range.endColIndex + 1, cell);
  17898. }
  17899. }
  17900. rng.moveToBookmark(bk).select();
  17901. }
  17902. };
  17903. UE.commands["deletecol"] = {
  17904. queryCommandState: function () {
  17905. var tableItems = getTableItemsByRange(this);
  17906. return tableItems.cell ? 0 : -1;
  17907. },
  17908. execCommand: function () {
  17909. var cell = getTableItemsByRange(this).cell,
  17910. ut = getUETable(cell),
  17911. range = ut.cellsRange,
  17912. cellInfo = ut.getCellInfo(cell),
  17913. preCell = ut.getHSideCell(cell),
  17914. nextCell = ut.getHSideCell(cell, true);
  17915. if (utils.isEmptyObject(range)) {
  17916. ut.deleteCol(cellInfo.colIndex);
  17917. } else {
  17918. for (var i = range.beginColIndex; i < range.endColIndex + 1; i++) {
  17919. ut.deleteCol(range.beginColIndex);
  17920. }
  17921. }
  17922. var table = ut.table,
  17923. rng = this.selection.getRange();
  17924. if (!table.getElementsByTagName('td').length) {
  17925. var nextSibling = table.nextSibling;
  17926. domUtils.remove(table);
  17927. if (nextSibling) {
  17928. rng.setStart(nextSibling, 0).setCursor(false, true);
  17929. }
  17930. } else {
  17931. if (domUtils.inDoc(cell, this.document)) {
  17932. rng.setStart(cell, 0).setCursor(false, true);
  17933. } else {
  17934. if (nextCell && domUtils.inDoc(nextCell, this.document)) {
  17935. rng.selectNodeContents(nextCell).setCursor(false, true);
  17936. } else {
  17937. if (preCell && domUtils.inDoc(preCell, this.document)) {
  17938. rng.selectNodeContents(preCell).setCursor(true, true);
  17939. }
  17940. }
  17941. }
  17942. }
  17943. }
  17944. };
  17945. UE.commands["splittocells"] = {
  17946. queryCommandState: function () {
  17947. var tableItems = getTableItemsByRange(this),
  17948. cell = tableItems.cell;
  17949. if (!cell) return -1;
  17950. var ut = getUETable(tableItems.table);
  17951. if (ut.selectedTds.length > 0) return -1;
  17952. return cell && (cell.colSpan > 1 || cell.rowSpan > 1) ? 0 : -1;
  17953. },
  17954. execCommand: function () {
  17955. var rng = this.selection.getRange(),
  17956. bk = rng.createBookmark(true);
  17957. var cell = getTableItemsByRange(this).cell,
  17958. ut = getUETable(cell);
  17959. ut.splitToCells(cell);
  17960. rng.moveToBookmark(bk).select();
  17961. }
  17962. };
  17963. UE.commands["splittorows"] = {
  17964. queryCommandState: function () {
  17965. var tableItems = getTableItemsByRange(this),
  17966. cell = tableItems.cell;
  17967. if (!cell) return -1;
  17968. var ut = getUETable(tableItems.table);
  17969. if (ut.selectedTds.length > 0) return -1;
  17970. return cell && cell.rowSpan > 1 ? 0 : -1;
  17971. },
  17972. execCommand: function () {
  17973. var rng = this.selection.getRange(),
  17974. bk = rng.createBookmark(true);
  17975. var cell = getTableItemsByRange(this).cell,
  17976. ut = getUETable(cell);
  17977. ut.splitToRows(cell);
  17978. rng.moveToBookmark(bk).select();
  17979. }
  17980. };
  17981. UE.commands["splittocols"] = {
  17982. queryCommandState: function () {
  17983. var tableItems = getTableItemsByRange(this),
  17984. cell = tableItems.cell;
  17985. if (!cell) return -1;
  17986. var ut = getUETable(tableItems.table);
  17987. if (ut.selectedTds.length > 0) return -1;
  17988. return cell && cell.colSpan > 1 ? 0 : -1;
  17989. },
  17990. execCommand: function () {
  17991. var rng = this.selection.getRange(),
  17992. bk = rng.createBookmark(true);
  17993. var cell = getTableItemsByRange(this).cell,
  17994. ut = getUETable(cell);
  17995. ut.splitToCols(cell);
  17996. rng.moveToBookmark(bk).select();
  17997. }
  17998. };
  17999. UE.commands["adaptbytext"] =
  18000. UE.commands["adaptbywindow"] = {
  18001. queryCommandState: function () {
  18002. return getTableItemsByRange(this).table ? 0 : -1
  18003. },
  18004. execCommand: function (cmd) {
  18005. var tableItems = getTableItemsByRange(this),
  18006. table = tableItems.table;
  18007. if (table) {
  18008. if (cmd == 'adaptbywindow') {
  18009. resetTdWidth(table, this);
  18010. } else {
  18011. var cells = domUtils.getElementsByTagName(table, "td th");
  18012. utils.each(cells, function (cell) {
  18013. cell.removeAttribute("width");
  18014. });
  18015. table.removeAttribute("width");
  18016. }
  18017. }
  18018. }
  18019. };
  18020. //平均分配各列
  18021. UE.commands['averagedistributecol'] = {
  18022. queryCommandState: function () {
  18023. var ut = getUETableBySelected(this);
  18024. if (!ut) return -1;
  18025. return ut.isFullRow() || ut.isFullCol() ? 0 : -1;
  18026. },
  18027. execCommand: function (cmd) {
  18028. var me = this,
  18029. ut = getUETableBySelected(me);
  18030. function getAverageWidth() {
  18031. var tb = ut.table,
  18032. averageWidth, sumWidth = 0, colsNum = 0,
  18033. tbAttr = getDefaultValue(me, tb);
  18034. if (ut.isFullRow()) {
  18035. sumWidth = tb.offsetWidth;
  18036. colsNum = ut.colsNum;
  18037. } else {
  18038. var begin = ut.cellsRange.beginColIndex,
  18039. end = ut.cellsRange.endColIndex,
  18040. node;
  18041. for (var i = begin; i <= end;) {
  18042. node = ut.selectedTds[i];
  18043. sumWidth += node.offsetWidth;
  18044. i += node.colSpan;
  18045. colsNum += 1;
  18046. }
  18047. }
  18048. averageWidth = Math.ceil(sumWidth / colsNum) - tbAttr.tdBorder * 2 - tbAttr.tdPadding * 2;
  18049. return averageWidth;
  18050. }
  18051. function setAverageWidth(averageWidth) {
  18052. utils.each(domUtils.getElementsByTagName(ut.table, "th"), function (node) {
  18053. node.setAttribute("width", "");
  18054. });
  18055. var cells = ut.isFullRow() ? domUtils.getElementsByTagName(ut.table, "td") : ut.selectedTds;
  18056. utils.each(cells, function (node) {
  18057. if (node.colSpan == 1) {
  18058. node.setAttribute("width", averageWidth);
  18059. }
  18060. });
  18061. }
  18062. if (ut && ut.selectedTds.length) {
  18063. setAverageWidth(getAverageWidth());
  18064. }
  18065. }
  18066. };
  18067. //平均分配各行
  18068. UE.commands['averagedistributerow'] = {
  18069. queryCommandState: function () {
  18070. var ut = getUETableBySelected(this);
  18071. if (!ut) return -1;
  18072. if (ut.selectedTds && /th/ig.test(ut.selectedTds[0].tagName)) return -1;
  18073. return ut.isFullRow() || ut.isFullCol() ? 0 : -1;
  18074. },
  18075. execCommand: function (cmd) {
  18076. var me = this,
  18077. ut = getUETableBySelected(me);
  18078. function getAverageHeight() {
  18079. var averageHeight, rowNum, sumHeight = 0,
  18080. tb = ut.table,
  18081. tbAttr = getDefaultValue(me, tb),
  18082. tdpadding = parseInt(domUtils.getComputedStyle(tb.getElementsByTagName('td')[0], "padding-top"));
  18083. if (ut.isFullCol()) {
  18084. var captionArr = domUtils.getElementsByTagName(tb, "caption"),
  18085. thArr = domUtils.getElementsByTagName(tb, "th"),
  18086. captionHeight, thHeight;
  18087. if (captionArr.length > 0) {
  18088. captionHeight = captionArr[0].offsetHeight;
  18089. }
  18090. if (thArr.length > 0) {
  18091. thHeight = thArr[0].offsetHeight;
  18092. }
  18093. sumHeight = tb.offsetHeight - (captionHeight || 0) - (thHeight || 0);
  18094. rowNum = thArr.length == 0 ? ut.rowsNum : (ut.rowsNum - 1);
  18095. } else {
  18096. var begin = ut.cellsRange.beginRowIndex,
  18097. end = ut.cellsRange.endRowIndex,
  18098. count = 0,
  18099. trs = domUtils.getElementsByTagName(tb, "tr");
  18100. for (var i = begin; i <= end; i++) {
  18101. sumHeight += trs[i].offsetHeight;
  18102. count += 1;
  18103. }
  18104. rowNum = count;
  18105. }
  18106. //ie8下是混杂模式
  18107. if (browser.ie && browser.version < 9) {
  18108. averageHeight = Math.ceil(sumHeight / rowNum);
  18109. } else {
  18110. averageHeight = Math.ceil(sumHeight / rowNum) - tbAttr.tdBorder * 2 - tdpadding * 2;
  18111. }
  18112. return averageHeight;
  18113. }
  18114. function setAverageHeight(averageHeight) {
  18115. var cells = ut.isFullCol() ? domUtils.getElementsByTagName(ut.table, "td") : ut.selectedTds;
  18116. utils.each(cells, function (node) {
  18117. if (node.rowSpan == 1) {
  18118. node.setAttribute("height", averageHeight);
  18119. }
  18120. });
  18121. }
  18122. if (ut && ut.selectedTds.length) {
  18123. setAverageHeight(getAverageHeight());
  18124. }
  18125. }
  18126. };
  18127. //单元格对齐方式
  18128. UE.commands['cellalignment'] = {
  18129. queryCommandState: function () {
  18130. return getTableItemsByRange(this).table ? 0 : -1
  18131. },
  18132. execCommand: function (cmd, data) {
  18133. var me = this,
  18134. ut = getUETableBySelected(me);
  18135. if (!ut) {
  18136. var start = me.selection.getStart(),
  18137. cell = start && domUtils.findParentByTagName(start, ["td", "th", "caption"], true);
  18138. if (!/caption/ig.test(cell.tagName)) {
  18139. domUtils.setAttributes(cell, data);
  18140. } else {
  18141. cell.style.textAlign = data.align;
  18142. cell.style.verticalAlign = data.vAlign;
  18143. }
  18144. me.selection.getRange().setCursor(true);
  18145. } else {
  18146. utils.each(ut.selectedTds, function (cell) {
  18147. domUtils.setAttributes(cell, data);
  18148. });
  18149. }
  18150. },
  18151. /**
  18152. * 查询当前点击的单元格的对齐状态, 如果当前已经选择了多个单元格, 则会返回所有单元格经过统一协调过后的状态
  18153. * @see UE.UETable.getTableCellAlignState
  18154. */
  18155. queryCommandValue: function (cmd) {
  18156. var activeMenuCell = getTableItemsByRange( this).cell;
  18157. if( !activeMenuCell ) {
  18158. activeMenuCell = getSelectedArr(this)[0];
  18159. }
  18160. if (!activeMenuCell) {
  18161. return null;
  18162. } else {
  18163. //获取同时选中的其他单元格
  18164. var cells = UE.UETable.getUETable(activeMenuCell).selectedTds;
  18165. !cells.length && ( cells = activeMenuCell );
  18166. return UE.UETable.getTableCellAlignState(cells);
  18167. }
  18168. }
  18169. };
  18170. //表格对齐方式
  18171. UE.commands['tablealignment'] = {
  18172. queryCommandState: function () {
  18173. if (browser.ie && browser.version < 8) {
  18174. return -1;
  18175. }
  18176. return getTableItemsByRange(this).table ? 0 : -1
  18177. },
  18178. execCommand: function (cmd, value) {
  18179. var me = this,
  18180. start = me.selection.getStart(),
  18181. table = start && domUtils.findParentByTagName(start, ["table"], true);
  18182. if (table) {
  18183. table.setAttribute("align",value);
  18184. }
  18185. }
  18186. };
  18187. //表格属性
  18188. UE.commands['edittable'] = {
  18189. queryCommandState: function () {
  18190. return getTableItemsByRange(this).table ? 0 : -1
  18191. },
  18192. execCommand: function (cmd, color) {
  18193. var rng = this.selection.getRange(),
  18194. table = domUtils.findParentByTagName(rng.startContainer, 'table');
  18195. if (table) {
  18196. var arr = domUtils.getElementsByTagName(table, "td").concat(
  18197. domUtils.getElementsByTagName(table, "th"),
  18198. domUtils.getElementsByTagName(table, "caption")
  18199. );
  18200. utils.each(arr, function (node) {
  18201. node.style.borderColor = color;
  18202. });
  18203. }
  18204. }
  18205. };
  18206. //单元格属性
  18207. UE.commands['edittd'] = {
  18208. queryCommandState: function () {
  18209. return getTableItemsByRange(this).table ? 0 : -1
  18210. },
  18211. execCommand: function (cmd, bkColor) {
  18212. var me = this,
  18213. ut = getUETableBySelected(me);
  18214. if (!ut) {
  18215. var start = me.selection.getStart(),
  18216. cell = start && domUtils.findParentByTagName(start, ["td", "th", "caption"], true);
  18217. if (cell) {
  18218. cell.style.backgroundColor = bkColor;
  18219. }
  18220. } else {
  18221. utils.each(ut.selectedTds, function (cell) {
  18222. cell.style.backgroundColor = bkColor;
  18223. });
  18224. }
  18225. }
  18226. };
  18227. UE.commands["settablebackground"] = {
  18228. queryCommandState: function () {
  18229. return getSelectedArr(this).length > 1 ? 0 : -1;
  18230. },
  18231. execCommand: function (cmd, value) {
  18232. var cells, ut;
  18233. cells = getSelectedArr(this);
  18234. ut = getUETable(cells[0]);
  18235. ut.setBackground(cells, value);
  18236. }
  18237. };
  18238. UE.commands["cleartablebackground"] = {
  18239. queryCommandState: function () {
  18240. var cells = getSelectedArr(this);
  18241. if (!cells.length)return -1;
  18242. for (var i = 0, cell; cell = cells[i++];) {
  18243. if (cell.style.backgroundColor !== "") return 0;
  18244. }
  18245. return -1;
  18246. },
  18247. execCommand: function () {
  18248. var cells = getSelectedArr(this),
  18249. ut = getUETable(cells[0]);
  18250. ut.removeBackground(cells);
  18251. }
  18252. };
  18253. UE.commands["interlacetable"] = UE.commands["uninterlacetable"] = {
  18254. queryCommandState: function (cmd) {
  18255. var table = getTableItemsByRange(this).table;
  18256. if (!table) return -1;
  18257. var interlaced = table.getAttribute("interlaced");
  18258. if (cmd == "interlacetable") {
  18259. //TODO 待定
  18260. //是否需要待定,如果设置,则命令只能单次执行成功,但反射具备toggle效果;否则可以覆盖前次命令,但反射将不存在toggle效果
  18261. return (interlaced === "enabled") ? -1 : 0;
  18262. } else {
  18263. return (!interlaced || interlaced === "disabled") ? -1 : 0;
  18264. }
  18265. },
  18266. execCommand: function (cmd, classList) {
  18267. var table = getTableItemsByRange(this).table;
  18268. if (cmd == "interlacetable") {
  18269. table.setAttribute("interlaced", "enabled");
  18270. this.fireEvent("interlacetable", table, classList);
  18271. } else {
  18272. table.setAttribute("interlaced", "disabled");
  18273. this.fireEvent("uninterlacetable", table);
  18274. }
  18275. }
  18276. };
  18277. UE.commands["setbordervisible"] = {
  18278. queryCommandState: function (cmd) {
  18279. var table = getTableItemsByRange(this).table;
  18280. if (!table) return -1;
  18281. return 0;
  18282. },
  18283. execCommand: function () {
  18284. var table = getTableItemsByRange(this).table;
  18285. utils.each(domUtils.getElementsByTagName(table,'td'),function(td){
  18286. td.style.borderWidth = '1px';
  18287. td.style.borderStyle = 'solid';
  18288. })
  18289. }
  18290. };
  18291. function resetTdWidth(table, editor) {
  18292. var tds = domUtils.getElementsByTagName(table,'td th');
  18293. utils.each(tds, function (td) {
  18294. td.removeAttribute("width");
  18295. });
  18296. table.setAttribute('width', getTableWidth(editor, true, getDefaultValue(editor, table)));
  18297. var tdsWidths = [];
  18298. setTimeout(function () {
  18299. utils.each(tds, function (td) {
  18300. (td.colSpan == 1) && tdsWidths.push(td.offsetWidth)
  18301. })
  18302. utils.each(tds, function (td,i) {
  18303. (td.colSpan == 1) && td.setAttribute("width", tdsWidths[i] + "");
  18304. })
  18305. }, 0);
  18306. }
  18307. function getTableWidth(editor, needIEHack, defaultValue) {
  18308. var body = editor.body;
  18309. return body.offsetWidth - (needIEHack ? parseInt(domUtils.getComputedStyle(body, 'margin-left'), 10) * 2 : 0) - defaultValue.tableBorder * 2 - (editor.options.offsetWidth || 0);
  18310. }
  18311. function getSelectedArr(editor) {
  18312. var cell = getTableItemsByRange(editor).cell;
  18313. if (cell) {
  18314. var ut = getUETable(cell);
  18315. return ut.selectedTds.length ? ut.selectedTds : [cell];
  18316. } else {
  18317. return [];
  18318. }
  18319. }
  18320. })();
  18321. // plugins/table.action.js
  18322. /**
  18323. * Created with JetBrains PhpStorm.
  18324. * User: taoqili
  18325. * Date: 12-10-12
  18326. * Time: 上午10:05
  18327. * To change this template use File | Settings | File Templates.
  18328. */
  18329. UE.plugins['table'] = function () {
  18330. var me = this,
  18331. tabTimer = null,
  18332. //拖动计时器
  18333. tableDragTimer = null,
  18334. //双击计时器
  18335. tableResizeTimer = null,
  18336. //单元格最小宽度
  18337. cellMinWidth = 5,
  18338. isInResizeBuffer = false,
  18339. //单元格边框大小
  18340. cellBorderWidth = 5,
  18341. //鼠标偏移距离
  18342. offsetOfTableCell = 10,
  18343. //记录在有限时间内的点击状态, 共有3个取值, 0, 1, 2。 0代表未初始化, 1代表单击了1次,2代表2次
  18344. singleClickState = 0,
  18345. userActionStatus = null,
  18346. //双击允许的时间范围
  18347. dblclickTime = 360,
  18348. UT = UE.UETable,
  18349. getUETable = function (tdOrTable) {
  18350. return UT.getUETable(tdOrTable);
  18351. },
  18352. getUETableBySelected = function (editor) {
  18353. return UT.getUETableBySelected(editor);
  18354. },
  18355. getDefaultValue = function (editor, table) {
  18356. return UT.getDefaultValue(editor, table);
  18357. },
  18358. removeSelectedClass = function (cells) {
  18359. return UT.removeSelectedClass(cells);
  18360. };
  18361. function showError(e) {
  18362. // throw e;
  18363. }
  18364. me.ready(function(){
  18365. var me = this;
  18366. var orgGetText = me.selection.getText;
  18367. me.selection.getText = function(){
  18368. var table = getUETableBySelected(me);
  18369. if(table){
  18370. var str = '';
  18371. utils.each(table.selectedTds,function(td){
  18372. str += td[browser.ie?'innerText':'textContent'];
  18373. })
  18374. return str;
  18375. }else{
  18376. return orgGetText.call(me.selection)
  18377. }
  18378. }
  18379. })
  18380. //处理拖动及框选相关方法
  18381. var startTd = null, //鼠标按下时的锚点td
  18382. currentTd = null, //当前鼠标经过时的td
  18383. onDrag = "", //指示当前拖动状态,其值可为"","h","v" ,分别表示未拖动状态,横向拖动状态,纵向拖动状态,用于鼠标移动过程中的判断
  18384. onBorder = false, //检测鼠标按下时是否处在单元格边缘位置
  18385. dragButton = null,
  18386. dragOver = false,
  18387. dragLine = null, //模拟的拖动线
  18388. dragTd = null; //发生拖动的目标td
  18389. var mousedown = false,
  18390. //todo 判断混乱模式
  18391. needIEHack = true;
  18392. me.setOpt({
  18393. 'maxColNum':20,
  18394. 'maxRowNum':100,
  18395. 'defaultCols':5,
  18396. 'defaultRows':5,
  18397. 'tdvalign':'top',
  18398. 'cursorpath':me.options.UEDITOR_HOME_URL + "themes/default/images/cursor_",
  18399. 'tableDragable':false,
  18400. 'classList':["ue-table-interlace-color-single","ue-table-interlace-color-double"]
  18401. });
  18402. me.getUETable = getUETable;
  18403. var commands = {
  18404. 'deletetable':1,
  18405. 'inserttable':1,
  18406. 'cellvalign':1,
  18407. 'insertcaption':1,
  18408. 'deletecaption':1,
  18409. 'inserttitle':1,
  18410. 'deletetitle':1,
  18411. "mergeright":1,
  18412. "mergedown":1,
  18413. "mergecells":1,
  18414. "insertrow":1,
  18415. "insertrownext":1,
  18416. "deleterow":1,
  18417. "insertcol":1,
  18418. "insertcolnext":1,
  18419. "deletecol":1,
  18420. "splittocells":1,
  18421. "splittorows":1,
  18422. "splittocols":1,
  18423. "adaptbytext":1,
  18424. "adaptbywindow":1,
  18425. "adaptbycustomer":1,
  18426. "insertparagraph":1,
  18427. "insertparagraphbeforetable":1,
  18428. "averagedistributecol":1,
  18429. "averagedistributerow":1
  18430. };
  18431. me.ready(function () {
  18432. utils.cssRule('table',
  18433. //选中的td上的样式
  18434. '.selectTdClass{background-color:#edf5fa !important}' +
  18435. 'table.noBorderTable td,table.noBorderTable th,table.noBorderTable caption{border:1px dashed #ddd !important}' +
  18436. //插入的表格的默认样式
  18437. 'table{margin-bottom:10px;border-collapse:collapse;display:table;}' +
  18438. 'td,th{padding: 5px 10px;border: 1px solid #DDD;}' +
  18439. 'caption{border:1px dashed #DDD;border-bottom:0;padding:3px;text-align:center;}' +
  18440. 'th{border-top:1px solid #BBB;background-color:#F7F7F7;}' +
  18441. 'table tr.firstRow th{border-top-width:2px;}' +
  18442. '.ue-table-interlace-color-single{ background-color: #fcfcfc; } .ue-table-interlace-color-double{ background-color: #f7faff; }' +
  18443. 'td p{margin:0;padding:0;}', me.document);
  18444. var tableCopyList, isFullCol, isFullRow;
  18445. //注册del/backspace事件
  18446. me.addListener('keydown', function (cmd, evt) {
  18447. var me = this;
  18448. var keyCode = evt.keyCode || evt.which;
  18449. if (keyCode == 8) {
  18450. var ut = getUETableBySelected(me);
  18451. if (ut && ut.selectedTds.length) {
  18452. if (ut.isFullCol()) {
  18453. me.execCommand('deletecol')
  18454. } else if (ut.isFullRow()) {
  18455. me.execCommand('deleterow')
  18456. } else {
  18457. me.fireEvent('delcells');
  18458. }
  18459. domUtils.preventDefault(evt);
  18460. }
  18461. var caption = domUtils.findParentByTagName(me.selection.getStart(), 'caption', true),
  18462. range = me.selection.getRange();
  18463. if (range.collapsed && caption && isEmptyBlock(caption)) {
  18464. me.fireEvent('saveScene');
  18465. var table = caption.parentNode;
  18466. domUtils.remove(caption);
  18467. if (table) {
  18468. range.setStart(table.rows[0].cells[0], 0).setCursor(false, true);
  18469. }
  18470. me.fireEvent('saveScene');
  18471. }
  18472. }
  18473. if (keyCode == 46) {
  18474. ut = getUETableBySelected(me);
  18475. if (ut) {
  18476. me.fireEvent('saveScene');
  18477. for (var i = 0, ci; ci = ut.selectedTds[i++];) {
  18478. domUtils.fillNode(me.document, ci)
  18479. }
  18480. me.fireEvent('saveScene');
  18481. domUtils.preventDefault(evt);
  18482. }
  18483. }
  18484. if (keyCode == 13) {
  18485. var rng = me.selection.getRange(),
  18486. caption = domUtils.findParentByTagName(rng.startContainer, 'caption', true);
  18487. if (caption) {
  18488. var table = domUtils.findParentByTagName(caption, 'table');
  18489. if (!rng.collapsed) {
  18490. rng.deleteContents();
  18491. me.fireEvent('saveScene');
  18492. } else {
  18493. if (caption) {
  18494. rng.setStart(table.rows[0].cells[0], 0).setCursor(false, true);
  18495. }
  18496. }
  18497. domUtils.preventDefault(evt);
  18498. return;
  18499. }
  18500. if (rng.collapsed) {
  18501. var table = domUtils.findParentByTagName(rng.startContainer, 'table');
  18502. if (table) {
  18503. var cell = table.rows[0].cells[0],
  18504. start = domUtils.findParentByTagName(me.selection.getStart(), ['td', 'th'], true),
  18505. preNode = table.previousSibling;
  18506. if (cell === start && (!preNode || preNode.nodeType == 1 && preNode.tagName == 'TABLE' ) && domUtils.isStartInblock(rng)) {
  18507. var first = domUtils.findParent(me.selection.getStart(), function(n){return domUtils.isBlockElm(n)}, true);
  18508. if(first && ( /t(h|d)/i.test(first.tagName) || first === start.firstChild )){
  18509. me.execCommand('insertparagraphbeforetable');
  18510. domUtils.preventDefault(evt);
  18511. }
  18512. }
  18513. }
  18514. }
  18515. }
  18516. if ((evt.ctrlKey || evt.metaKey) && evt.keyCode == '67') {
  18517. tableCopyList = null;
  18518. var ut = getUETableBySelected(me);
  18519. if (ut) {
  18520. var tds = ut.selectedTds;
  18521. isFullCol = ut.isFullCol();
  18522. isFullRow = ut.isFullRow();
  18523. tableCopyList = [
  18524. [ut.cloneCell(tds[0],null,true)]
  18525. ];
  18526. for (var i = 1, ci; ci = tds[i]; i++) {
  18527. if (ci.parentNode !== tds[i - 1].parentNode) {
  18528. tableCopyList.push([ut.cloneCell(ci,null,true)]);
  18529. } else {
  18530. tableCopyList[tableCopyList.length - 1].push(ut.cloneCell(ci,null,true));
  18531. }
  18532. }
  18533. }
  18534. }
  18535. });
  18536. me.addListener("tablehasdeleted",function(){
  18537. toggleDraggableState(this, false, "", null);
  18538. if (dragButton)domUtils.remove(dragButton);
  18539. });
  18540. me.addListener('beforepaste', function (cmd, html) {
  18541. var me = this;
  18542. var rng = me.selection.getRange();
  18543. if (domUtils.findParentByTagName(rng.startContainer, 'caption', true)) {
  18544. var div = me.document.createElement("div");
  18545. div.innerHTML = html.html;
  18546. //trace:3729
  18547. html.html = div[browser.ie9below ? 'innerText' : 'textContent'];
  18548. return;
  18549. }
  18550. var table = getUETableBySelected(me);
  18551. if (tableCopyList) {
  18552. me.fireEvent('saveScene');
  18553. var rng = me.selection.getRange();
  18554. var td = domUtils.findParentByTagName(rng.startContainer, ['td', 'th'], true), tmpNode, preNode;
  18555. if (td) {
  18556. var ut = getUETable(td);
  18557. if (isFullRow) {
  18558. var rowIndex = ut.getCellInfo(td).rowIndex;
  18559. if (td.tagName == 'TH') {
  18560. rowIndex++;
  18561. }
  18562. for (var i = 0, ci; ci = tableCopyList[i++];) {
  18563. var tr = ut.insertRow(rowIndex++, "td");
  18564. for (var j = 0, cj; cj = ci[j]; j++) {
  18565. var cell = tr.cells[j];
  18566. if (!cell) {
  18567. cell = tr.insertCell(j)
  18568. }
  18569. cell.innerHTML = cj.innerHTML;
  18570. cj.getAttribute('width') && cell.setAttribute('width', cj.getAttribute('width'));
  18571. cj.getAttribute('vAlign') && cell.setAttribute('vAlign', cj.getAttribute('vAlign'));
  18572. cj.getAttribute('align') && cell.setAttribute('align', cj.getAttribute('align'));
  18573. cj.style.cssText && (cell.style.cssText = cj.style.cssText)
  18574. }
  18575. for (var j = 0, cj; cj = tr.cells[j]; j++) {
  18576. if (!ci[j])
  18577. break;
  18578. cj.innerHTML = ci[j].innerHTML;
  18579. ci[j].getAttribute('width') && cj.setAttribute('width', ci[j].getAttribute('width'));
  18580. ci[j].getAttribute('vAlign') && cj.setAttribute('vAlign', ci[j].getAttribute('vAlign'));
  18581. ci[j].getAttribute('align') && cj.setAttribute('align', ci[j].getAttribute('align'));
  18582. ci[j].style.cssText && (cj.style.cssText = ci[j].style.cssText)
  18583. }
  18584. }
  18585. } else {
  18586. if (isFullCol) {
  18587. cellInfo = ut.getCellInfo(td);
  18588. var maxColNum = 0;
  18589. for (var j = 0, ci = tableCopyList[0], cj; cj = ci[j++];) {
  18590. maxColNum += cj.colSpan || 1;
  18591. }
  18592. me.__hasEnterExecCommand = true;
  18593. for (i = 0; i < maxColNum; i++) {
  18594. me.execCommand('insertcol');
  18595. }
  18596. me.__hasEnterExecCommand = false;
  18597. td = ut.table.rows[0].cells[cellInfo.cellIndex];
  18598. if (td.tagName == 'TH') {
  18599. td = ut.table.rows[1].cells[cellInfo.cellIndex];
  18600. }
  18601. }
  18602. for (var i = 0, ci; ci = tableCopyList[i++];) {
  18603. tmpNode = td;
  18604. for (var j = 0, cj; cj = ci[j++];) {
  18605. if (td) {
  18606. td.innerHTML = cj.innerHTML;
  18607. //todo 定制处理
  18608. cj.getAttribute('width') && td.setAttribute('width', cj.getAttribute('width'));
  18609. cj.getAttribute('vAlign') && td.setAttribute('vAlign', cj.getAttribute('vAlign'));
  18610. cj.getAttribute('align') && td.setAttribute('align', cj.getAttribute('align'));
  18611. cj.style.cssText && (td.style.cssText = cj.style.cssText);
  18612. preNode = td;
  18613. td = td.nextSibling;
  18614. } else {
  18615. var cloneTd = cj.cloneNode(true);
  18616. domUtils.removeAttributes(cloneTd, ['class', 'rowSpan', 'colSpan']);
  18617. preNode.parentNode.appendChild(cloneTd)
  18618. }
  18619. }
  18620. td = ut.getNextCell(tmpNode, true, true);
  18621. if (!tableCopyList[i])
  18622. break;
  18623. if (!td) {
  18624. var cellInfo = ut.getCellInfo(tmpNode);
  18625. ut.table.insertRow(ut.table.rows.length);
  18626. ut.update();
  18627. td = ut.getVSideCell(tmpNode, true);
  18628. }
  18629. }
  18630. }
  18631. ut.update();
  18632. } else {
  18633. table = me.document.createElement('table');
  18634. for (var i = 0, ci; ci = tableCopyList[i++];) {
  18635. var tr = table.insertRow(table.rows.length);
  18636. for (var j = 0, cj; cj = ci[j++];) {
  18637. cloneTd = UT.cloneCell(cj,null,true);
  18638. domUtils.removeAttributes(cloneTd, ['class']);
  18639. tr.appendChild(cloneTd)
  18640. }
  18641. if (j == 2 && cloneTd.rowSpan > 1) {
  18642. cloneTd.rowSpan = 1;
  18643. }
  18644. }
  18645. var defaultValue = getDefaultValue(me),
  18646. width = me.body.offsetWidth -
  18647. (needIEHack ? parseInt(domUtils.getComputedStyle(me.body, 'margin-left'), 10) * 2 : 0) - defaultValue.tableBorder * 2 - (me.options.offsetWidth || 0);
  18648. me.execCommand('insertHTML', '<table ' +
  18649. ( isFullCol && isFullRow ? 'width="' + width + '"' : '') +
  18650. '>' + table.innerHTML.replace(/>\s*</g, '><').replace(/\bth\b/gi, "td") + '</table>')
  18651. }
  18652. me.fireEvent('contentchange');
  18653. me.fireEvent('saveScene');
  18654. html.html = '';
  18655. return true;
  18656. } else {
  18657. var div = me.document.createElement("div"), tables;
  18658. div.innerHTML = html.html;
  18659. tables = div.getElementsByTagName("table");
  18660. if (domUtils.findParentByTagName(me.selection.getStart(), 'table')) {
  18661. utils.each(tables, function (t) {
  18662. domUtils.remove(t)
  18663. });
  18664. if (domUtils.findParentByTagName(me.selection.getStart(), 'caption', true)) {
  18665. div.innerHTML = div[browser.ie ? 'innerText' : 'textContent'];
  18666. }
  18667. } else {
  18668. utils.each(tables, function (table) {
  18669. removeStyleSize(table, true);
  18670. domUtils.removeAttributes(table, ['style', 'border']);
  18671. utils.each(domUtils.getElementsByTagName(table, "td"), function (td) {
  18672. if (isEmptyBlock(td)) {
  18673. domUtils.fillNode(me.document, td);
  18674. }
  18675. removeStyleSize(td, true);
  18676. // domUtils.removeAttributes(td, ['style'])
  18677. });
  18678. });
  18679. }
  18680. html.html = div.innerHTML;
  18681. }
  18682. });
  18683. me.addListener('afterpaste', function () {
  18684. utils.each(domUtils.getElementsByTagName(me.body, "table"), function (table) {
  18685. if (table.offsetWidth > me.body.offsetWidth) {
  18686. var defaultValue = getDefaultValue(me, table);
  18687. table.style.width = me.body.offsetWidth - (needIEHack ? parseInt(domUtils.getComputedStyle(me.body, 'margin-left'), 10) * 2 : 0) - defaultValue.tableBorder * 2 - (me.options.offsetWidth || 0) + 'px'
  18688. }
  18689. })
  18690. });
  18691. me.addListener('blur', function () {
  18692. tableCopyList = null;
  18693. });
  18694. var timer;
  18695. me.addListener('keydown', function () {
  18696. clearTimeout(timer);
  18697. timer = setTimeout(function () {
  18698. var rng = me.selection.getRange(),
  18699. cell = domUtils.findParentByTagName(rng.startContainer, ['th', 'td'], true);
  18700. if (cell) {
  18701. var table = cell.parentNode.parentNode.parentNode;
  18702. if (table.offsetWidth > table.getAttribute("width")) {
  18703. cell.style.wordBreak = "break-all";
  18704. }
  18705. }
  18706. }, 100);
  18707. });
  18708. me.addListener("selectionchange", function () {
  18709. toggleDraggableState(me, false, "", null);
  18710. });
  18711. //内容变化时触发索引更新
  18712. //todo 可否考虑标记检测,如果不涉及表格的变化就不进行索引重建和更新
  18713. me.addListener("contentchange", function () {
  18714. var me = this;
  18715. //尽可能排除一些不需要更新的状况
  18716. hideDragLine(me);
  18717. if (getUETableBySelected(me))return;
  18718. var rng = me.selection.getRange();
  18719. var start = rng.startContainer;
  18720. start = domUtils.findParentByTagName(start, ['td', 'th'], true);
  18721. utils.each(domUtils.getElementsByTagName(me.document, 'table'), function (table) {
  18722. if (me.fireEvent("excludetable", table) === true) return;
  18723. table.ueTable = new UT(table);
  18724. //trace:3742
  18725. // utils.each(domUtils.getElementsByTagName(me.document, 'td'), function (td) {
  18726. //
  18727. // if (domUtils.isEmptyBlock(td) && td !== start) {
  18728. // domUtils.fillNode(me.document, td);
  18729. // if (browser.ie && browser.version == 6) {
  18730. // td.innerHTML = '&nbsp;'
  18731. // }
  18732. // }
  18733. // });
  18734. // utils.each(domUtils.getElementsByTagName(me.document, 'th'), function (th) {
  18735. // if (domUtils.isEmptyBlock(th) && th !== start) {
  18736. // domUtils.fillNode(me.document, th);
  18737. // if (browser.ie && browser.version == 6) {
  18738. // th.innerHTML = '&nbsp;'
  18739. // }
  18740. // }
  18741. // });
  18742. table.onmouseover = function () {
  18743. me.fireEvent('tablemouseover', table);
  18744. };
  18745. table.onmousemove = function () {
  18746. me.fireEvent('tablemousemove', table);
  18747. me.options.tableDragable && toggleDragButton(true, this, me);
  18748. utils.defer(function(){
  18749. me.fireEvent('contentchange',50)
  18750. },true)
  18751. };
  18752. table.onmouseout = function () {
  18753. me.fireEvent('tablemouseout', table);
  18754. toggleDraggableState(me, false, "", null);
  18755. hideDragLine(me);
  18756. };
  18757. table.onclick = function (evt) {
  18758. evt = me.window.event || evt;
  18759. var target = getParentTdOrTh(evt.target || evt.srcElement);
  18760. if (!target)return;
  18761. var ut = getUETable(target),
  18762. table = ut.table,
  18763. cellInfo = ut.getCellInfo(target),
  18764. cellsRange,
  18765. rng = me.selection.getRange();
  18766. // if ("topLeft" == inPosition(table, mouseCoords(evt))) {
  18767. // cellsRange = ut.getCellsRange(ut.table.rows[0].cells[0], ut.getLastCell());
  18768. // ut.setSelected(cellsRange);
  18769. // return;
  18770. // }
  18771. // if ("bottomRight" == inPosition(table, mouseCoords(evt))) {
  18772. //
  18773. // return;
  18774. // }
  18775. if (inTableSide(table, target, evt, true)) {
  18776. var endTdCol = ut.getCell(ut.indexTable[ut.rowsNum - 1][cellInfo.colIndex].rowIndex, ut.indexTable[ut.rowsNum - 1][cellInfo.colIndex].cellIndex);
  18777. if (evt.shiftKey && ut.selectedTds.length) {
  18778. if (ut.selectedTds[0] !== endTdCol) {
  18779. cellsRange = ut.getCellsRange(ut.selectedTds[0], endTdCol);
  18780. ut.setSelected(cellsRange);
  18781. } else {
  18782. rng && rng.selectNodeContents(endTdCol).select();
  18783. }
  18784. } else {
  18785. if (target !== endTdCol) {
  18786. cellsRange = ut.getCellsRange(target, endTdCol);
  18787. ut.setSelected(cellsRange);
  18788. } else {
  18789. rng && rng.selectNodeContents(endTdCol).select();
  18790. }
  18791. }
  18792. return;
  18793. }
  18794. if (inTableSide(table, target, evt)) {
  18795. var endTdRow = ut.getCell(ut.indexTable[cellInfo.rowIndex][ut.colsNum - 1].rowIndex, ut.indexTable[cellInfo.rowIndex][ut.colsNum - 1].cellIndex);
  18796. if (evt.shiftKey && ut.selectedTds.length) {
  18797. if (ut.selectedTds[0] !== endTdRow) {
  18798. cellsRange = ut.getCellsRange(ut.selectedTds[0], endTdRow);
  18799. ut.setSelected(cellsRange);
  18800. } else {
  18801. rng && rng.selectNodeContents(endTdRow).select();
  18802. }
  18803. } else {
  18804. if (target !== endTdRow) {
  18805. cellsRange = ut.getCellsRange(target, endTdRow);
  18806. ut.setSelected(cellsRange);
  18807. } else {
  18808. rng && rng.selectNodeContents(endTdRow).select();
  18809. }
  18810. }
  18811. }
  18812. };
  18813. });
  18814. switchBorderColor(me, true);
  18815. });
  18816. domUtils.on(me.document, "mousemove", mouseMoveEvent);
  18817. domUtils.on(me.document, "mouseout", function (evt) {
  18818. var target = evt.target || evt.srcElement;
  18819. if (target.tagName == "TABLE") {
  18820. toggleDraggableState(me, false, "", null);
  18821. }
  18822. });
  18823. /**
  18824. * 表格隔行变色
  18825. */
  18826. me.addListener("interlacetable",function(type,table,classList){
  18827. if(!table) return;
  18828. var me = this,
  18829. rows = table.rows,
  18830. len = rows.length,
  18831. getClass = function(list,index,repeat){
  18832. return list[index] ? list[index] : repeat ? list[index % list.length]: "";
  18833. };
  18834. for(var i = 0;i<len;i++){
  18835. rows[i].className = getClass( classList|| me.options.classList,i,true);
  18836. }
  18837. });
  18838. me.addListener("uninterlacetable",function(type,table){
  18839. if(!table) return;
  18840. var me = this,
  18841. rows = table.rows,
  18842. classList = me.options.classList,
  18843. len = rows.length;
  18844. for(var i = 0;i<len;i++){
  18845. domUtils.removeClasses( rows[i], classList );
  18846. }
  18847. });
  18848. me.addListener("mousedown", mouseDownEvent);
  18849. me.addListener("mouseup", mouseUpEvent);
  18850. //拖动的时候触发mouseup
  18851. domUtils.on( me.body, 'dragstart', function( evt ){
  18852. mouseUpEvent.call( me, 'dragstart', evt );
  18853. });
  18854. me.addOutputRule(function(root){
  18855. utils.each(root.getNodesByTagName('div'),function(n){
  18856. if (n.getAttr('id') == 'ue_tableDragLine') {
  18857. n.parentNode.removeChild(n);
  18858. }
  18859. });
  18860. });
  18861. var currentRowIndex = 0;
  18862. me.addListener("mousedown", function () {
  18863. currentRowIndex = 0;
  18864. });
  18865. me.addListener('tabkeydown', function () {
  18866. var range = this.selection.getRange(),
  18867. common = range.getCommonAncestor(true, true),
  18868. table = domUtils.findParentByTagName(common, 'table');
  18869. if (table) {
  18870. if (domUtils.findParentByTagName(common, 'caption', true)) {
  18871. var cell = domUtils.getElementsByTagName(table, 'th td');
  18872. if (cell && cell.length) {
  18873. range.setStart(cell[0], 0).setCursor(false, true)
  18874. }
  18875. } else {
  18876. var cell = domUtils.findParentByTagName(common, ['td', 'th'], true),
  18877. ua = getUETable(cell);
  18878. currentRowIndex = cell.rowSpan > 1 ? currentRowIndex : ua.getCellInfo(cell).rowIndex;
  18879. var nextCell = ua.getTabNextCell(cell, currentRowIndex);
  18880. if (nextCell) {
  18881. if (isEmptyBlock(nextCell)) {
  18882. range.setStart(nextCell, 0).setCursor(false, true)
  18883. } else {
  18884. range.selectNodeContents(nextCell).select()
  18885. }
  18886. } else {
  18887. me.fireEvent('saveScene');
  18888. me.__hasEnterExecCommand = true;
  18889. this.execCommand('insertrownext');
  18890. me.__hasEnterExecCommand = false;
  18891. range = this.selection.getRange();
  18892. range.setStart(table.rows[table.rows.length - 1].cells[0], 0).setCursor();
  18893. me.fireEvent('saveScene');
  18894. }
  18895. }
  18896. return true;
  18897. }
  18898. });
  18899. browser.ie && me.addListener('selectionchange', function () {
  18900. toggleDraggableState(this, false, "", null);
  18901. });
  18902. me.addListener("keydown", function (type, evt) {
  18903. var me = this;
  18904. //处理在表格的最后一个输入tab产生新的表格
  18905. var keyCode = evt.keyCode || evt.which;
  18906. if (keyCode == 8 || keyCode == 46) {
  18907. return;
  18908. }
  18909. var notCtrlKey = !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey;
  18910. notCtrlKey && removeSelectedClass(domUtils.getElementsByTagName(me.body, "td"));
  18911. var ut = getUETableBySelected(me);
  18912. if (!ut) return;
  18913. notCtrlKey && ut.clearSelected();
  18914. });
  18915. me.addListener("beforegetcontent", function () {
  18916. switchBorderColor(this, false);
  18917. browser.ie && utils.each(this.document.getElementsByTagName('caption'), function (ci) {
  18918. if (domUtils.isEmptyNode(ci)) {
  18919. ci.innerHTML = '&nbsp;'
  18920. }
  18921. });
  18922. });
  18923. me.addListener("aftergetcontent", function () {
  18924. switchBorderColor(this, true);
  18925. });
  18926. me.addListener("getAllHtml", function () {
  18927. removeSelectedClass(me.document.getElementsByTagName("td"));
  18928. });
  18929. //修正全屏状态下插入的表格宽度在非全屏状态下撑开编辑器的情况
  18930. me.addListener("fullscreenchanged", function (type, fullscreen) {
  18931. if (!fullscreen) {
  18932. var ratio = this.body.offsetWidth / document.body.offsetWidth,
  18933. tables = domUtils.getElementsByTagName(this.body, "table");
  18934. utils.each(tables, function (table) {
  18935. if (table.offsetWidth < me.body.offsetWidth) return false;
  18936. var tds = domUtils.getElementsByTagName(table, "td"),
  18937. backWidths = [];
  18938. utils.each(tds, function (td) {
  18939. backWidths.push(td.offsetWidth);
  18940. });
  18941. for (var i = 0, td; td = tds[i]; i++) {
  18942. td.setAttribute("width", Math.floor(backWidths[i] * ratio));
  18943. }
  18944. table.setAttribute("width", Math.floor(getTableWidth(me, needIEHack, getDefaultValue(me))))
  18945. });
  18946. }
  18947. });
  18948. //重写execCommand命令,用于处理框选时的处理
  18949. var oldExecCommand = me.execCommand;
  18950. me.execCommand = function (cmd, datatat) {
  18951. var me = this,
  18952. args = arguments;
  18953. cmd = cmd.toLowerCase();
  18954. var ut = getUETableBySelected(me), tds,
  18955. range = new dom.Range(me.document),
  18956. cmdFun = me.commands[cmd] || UE.commands[cmd],
  18957. result;
  18958. if (!cmdFun) return;
  18959. if (ut && !commands[cmd] && !cmdFun.notNeedUndo && !me.__hasEnterExecCommand) {
  18960. me.__hasEnterExecCommand = true;
  18961. me.fireEvent("beforeexeccommand", cmd);
  18962. tds = ut.selectedTds;
  18963. var lastState = -2, lastValue = -2, value, state;
  18964. for (var i = 0, td; td = tds[i]; i++) {
  18965. if (isEmptyBlock(td)) {
  18966. range.setStart(td, 0).setCursor(false, true)
  18967. } else {
  18968. range.selectNode(td).select(true);
  18969. }
  18970. state = me.queryCommandState(cmd);
  18971. value = me.queryCommandValue(cmd);
  18972. if (state != -1) {
  18973. if (lastState !== state || lastValue !== value) {
  18974. me._ignoreContentChange = true;
  18975. result = oldExecCommand.apply(me, arguments);
  18976. me._ignoreContentChange = false;
  18977. }
  18978. lastState = me.queryCommandState(cmd);
  18979. lastValue = me.queryCommandValue(cmd);
  18980. if (domUtils.isEmptyBlock(td)) {
  18981. domUtils.fillNode(me.document, td)
  18982. }
  18983. }
  18984. }
  18985. range.setStart(tds[0], 0).shrinkBoundary(true).setCursor(false, true);
  18986. me.fireEvent('contentchange');
  18987. me.fireEvent("afterexeccommand", cmd);
  18988. me.__hasEnterExecCommand = false;
  18989. me._selectionChange();
  18990. } else {
  18991. result = oldExecCommand.apply(me, arguments);
  18992. }
  18993. return result;
  18994. };
  18995. });
  18996. /**
  18997. * 删除obj的宽高style,改成属性宽高
  18998. * @param obj
  18999. * @param replaceToProperty
  19000. */
  19001. function removeStyleSize(obj, replaceToProperty) {
  19002. removeStyle(obj, "width", true);
  19003. removeStyle(obj, "height", true);
  19004. }
  19005. function removeStyle(obj, styleName, replaceToProperty) {
  19006. if (obj.style[styleName]) {
  19007. replaceToProperty && obj.setAttribute(styleName, parseInt(obj.style[styleName], 10));
  19008. obj.style[styleName] = "";
  19009. }
  19010. }
  19011. function getParentTdOrTh(ele) {
  19012. if (ele.tagName == "TD" || ele.tagName == "TH") return ele;
  19013. var td;
  19014. if (td = domUtils.findParentByTagName(ele, "td", true) || domUtils.findParentByTagName(ele, "th", true)) return td;
  19015. return null;
  19016. }
  19017. function isEmptyBlock(node) {
  19018. var reg = new RegExp(domUtils.fillChar, 'g');
  19019. if (node[browser.ie ? 'innerText' : 'textContent'].replace(/^\s*$/, '').replace(reg, '').length > 0) {
  19020. return 0;
  19021. }
  19022. for (var n in dtd.$isNotEmpty) {
  19023. if (node.getElementsByTagName(n).length) {
  19024. return 0;
  19025. }
  19026. }
  19027. return 1;
  19028. }
  19029. function mouseCoords(evt) {
  19030. if (evt.pageX || evt.pageY) {
  19031. return { x:evt.pageX, y:evt.pageY };
  19032. }
  19033. return {
  19034. x:evt.clientX + me.document.body.scrollLeft - me.document.body.clientLeft,
  19035. y:evt.clientY + me.document.body.scrollTop - me.document.body.clientTop
  19036. };
  19037. }
  19038. function mouseMoveEvent(evt) {
  19039. if( isEditorDisabled() ) {
  19040. return;
  19041. }
  19042. try {
  19043. //普通状态下鼠标移动
  19044. var target = getParentTdOrTh(evt.target || evt.srcElement),
  19045. pos;
  19046. //区分用户的行为是拖动还是双击
  19047. if( isInResizeBuffer ) {
  19048. me.body.style.webkitUserSelect = 'none';
  19049. if( Math.abs( userActionStatus.x - evt.clientX ) > offsetOfTableCell || Math.abs( userActionStatus.y - evt.clientY ) > offsetOfTableCell ) {
  19050. clearTableDragTimer();
  19051. isInResizeBuffer = false;
  19052. singleClickState = 0;
  19053. //drag action
  19054. tableBorderDrag(evt);
  19055. }
  19056. }
  19057. //修改单元格大小时的鼠标移动
  19058. if (onDrag && dragTd) {
  19059. singleClickState = 0;
  19060. me.body.style.webkitUserSelect = 'none';
  19061. me.selection.getNative()[browser.ie9below ? 'empty' : 'removeAllRanges']();
  19062. pos = mouseCoords(evt);
  19063. toggleDraggableState(me, true, onDrag, pos, target);
  19064. if (onDrag == "h") {
  19065. dragLine.style.left = getPermissionX(dragTd, evt) + "px";
  19066. } else if (onDrag == "v") {
  19067. dragLine.style.top = getPermissionY(dragTd, evt) + "px";
  19068. }
  19069. return;
  19070. }
  19071. //当鼠标处于table上时,修改移动过程中的光标状态
  19072. if (target) {
  19073. //针对使用table作为容器的组件不触发拖拽效果
  19074. if (me.fireEvent('excludetable', target) === true)
  19075. return;
  19076. pos = mouseCoords(evt);
  19077. var state = getRelation(target, pos),
  19078. table = domUtils.findParentByTagName(target, "table", true);
  19079. if (inTableSide(table, target, evt, true)) {
  19080. if (me.fireEvent("excludetable", table) === true) return;
  19081. me.body.style.cursor = "url(" + me.options.cursorpath + "h.png),pointer";
  19082. } else if (inTableSide(table, target, evt)) {
  19083. if (me.fireEvent("excludetable", table) === true) return;
  19084. me.body.style.cursor = "url(" + me.options.cursorpath + "v.png),pointer";
  19085. } else {
  19086. me.body.style.cursor = "text";
  19087. var curCell = target;
  19088. if (/\d/.test(state)) {
  19089. state = state.replace(/\d/, '');
  19090. target = getUETable(target).getPreviewCell(target, state == "v");
  19091. }
  19092. //位于第一行的顶部或者第一列的左边时不可拖动
  19093. toggleDraggableState(me, target ? !!state : false, target ? state : '', pos, target);
  19094. }
  19095. } else {
  19096. toggleDragButton(false, table, me);
  19097. }
  19098. } catch (e) {
  19099. showError(e);
  19100. }
  19101. }
  19102. var dragButtonTimer;
  19103. function toggleDragButton(show, table, editor) {
  19104. if (!show) {
  19105. if (dragOver)return;
  19106. dragButtonTimer = setTimeout(function () {
  19107. !dragOver && dragButton && dragButton.parentNode && dragButton.parentNode.removeChild(dragButton);
  19108. }, 2000);
  19109. } else {
  19110. createDragButton(table, editor);
  19111. }
  19112. }
  19113. function createDragButton(table, editor) {
  19114. var pos = domUtils.getXY(table),
  19115. doc = table.ownerDocument;
  19116. if (dragButton && dragButton.parentNode)return dragButton;
  19117. dragButton = doc.createElement("div");
  19118. dragButton.contentEditable = false;
  19119. dragButton.innerHTML = "";
  19120. dragButton.style.cssText = "width:15px;height:15px;background-image:url(" + editor.options.UEDITOR_HOME_URL + "dialogs/table/dragicon.png);position: absolute;cursor:move;top:" + (pos.y - 15) + "px;left:" + (pos.x) + "px;";
  19121. domUtils.unSelectable(dragButton);
  19122. dragButton.onmouseover = function (evt) {
  19123. dragOver = true;
  19124. };
  19125. dragButton.onmouseout = function (evt) {
  19126. dragOver = false;
  19127. };
  19128. domUtils.on(dragButton, 'click', function (type, evt) {
  19129. doClick(evt, this);
  19130. });
  19131. domUtils.on(dragButton, 'dblclick', function (type, evt) {
  19132. doDblClick(evt);
  19133. });
  19134. domUtils.on(dragButton, 'dragstart', function (type, evt) {
  19135. domUtils.preventDefault(evt);
  19136. });
  19137. var timer;
  19138. function doClick(evt, button) {
  19139. // 部分浏览器下需要清理
  19140. clearTimeout(timer);
  19141. timer = setTimeout(function () {
  19142. editor.fireEvent("tableClicked", table, button);
  19143. }, 300);
  19144. }
  19145. function doDblClick(evt) {
  19146. clearTimeout(timer);
  19147. var ut = getUETable(table),
  19148. start = table.rows[0].cells[0],
  19149. end = ut.getLastCell(),
  19150. range = ut.getCellsRange(start, end);
  19151. editor.selection.getRange().setStart(start, 0).setCursor(false, true);
  19152. ut.setSelected(range);
  19153. }
  19154. doc.body.appendChild(dragButton);
  19155. }
  19156. // function inPosition(table, pos) {
  19157. // var tablePos = domUtils.getXY(table),
  19158. // width = table.offsetWidth,
  19159. // height = table.offsetHeight;
  19160. // if (pos.x - tablePos.x < 5 && pos.y - tablePos.y < 5) {
  19161. // return "topLeft";
  19162. // } else if (tablePos.x + width - pos.x < 5 && tablePos.y + height - pos.y < 5) {
  19163. // return "bottomRight";
  19164. // }
  19165. // }
  19166. function inTableSide(table, cell, evt, top) {
  19167. var pos = mouseCoords(evt),
  19168. state = getRelation(cell, pos);
  19169. if (top) {
  19170. var caption = table.getElementsByTagName("caption")[0],
  19171. capHeight = caption ? caption.offsetHeight : 0;
  19172. return (state == "v1") && ((pos.y - domUtils.getXY(table).y - capHeight) < 8);
  19173. } else {
  19174. return (state == "h1") && ((pos.x - domUtils.getXY(table).x) < 8);
  19175. }
  19176. }
  19177. /**
  19178. * 获取拖动时允许的X轴坐标
  19179. * @param dragTd
  19180. * @param evt
  19181. */
  19182. function getPermissionX(dragTd, evt) {
  19183. var ut = getUETable(dragTd);
  19184. if (ut) {
  19185. var preTd = ut.getSameEndPosCells(dragTd, "x")[0],
  19186. nextTd = ut.getSameStartPosXCells(dragTd)[0],
  19187. mouseX = mouseCoords(evt).x,
  19188. left = (preTd ? domUtils.getXY(preTd).x : domUtils.getXY(ut.table).x) + 20 ,
  19189. right = nextTd ? domUtils.getXY(nextTd).x + nextTd.offsetWidth - 20 : (me.body.offsetWidth + 5 || parseInt(domUtils.getComputedStyle(me.body, "width"), 10));
  19190. left += cellMinWidth;
  19191. right -= cellMinWidth;
  19192. return mouseX < left ? left : mouseX > right ? right : mouseX;
  19193. }
  19194. }
  19195. /**
  19196. * 获取拖动时允许的Y轴坐标
  19197. */
  19198. function getPermissionY(dragTd, evt) {
  19199. try {
  19200. var top = domUtils.getXY(dragTd).y,
  19201. mousePosY = mouseCoords(evt).y;
  19202. return mousePosY < top ? top : mousePosY;
  19203. } catch (e) {
  19204. showError(e);
  19205. }
  19206. }
  19207. /**
  19208. * 移动状态切换
  19209. */
  19210. function toggleDraggableState(editor, draggable, dir, mousePos, cell) {
  19211. try {
  19212. editor.body.style.cursor = dir == "h" ? "col-resize" : dir == "v" ? "row-resize" : "text";
  19213. if (browser.ie) {
  19214. if (dir && !mousedown && !getUETableBySelected(editor)) {
  19215. getDragLine(editor, editor.document);
  19216. showDragLineAt(dir, cell);
  19217. } else {
  19218. hideDragLine(editor)
  19219. }
  19220. }
  19221. onBorder = draggable;
  19222. } catch (e) {
  19223. showError(e);
  19224. }
  19225. }
  19226. /**
  19227. * 获取与UETable相关的resize line
  19228. * @param uetable UETable对象
  19229. */
  19230. function getResizeLineByUETable() {
  19231. var lineId = '_UETableResizeLine',
  19232. line = this.document.getElementById( lineId );
  19233. if( !line ) {
  19234. line = this.document.createElement("div");
  19235. line.id = lineId;
  19236. line.contnetEditable = false;
  19237. line.setAttribute("unselectable", "on");
  19238. var styles = {
  19239. width: 2*cellBorderWidth + 1 + 'px',
  19240. position: 'absolute',
  19241. 'z-index': 100000,
  19242. cursor: 'col-resize',
  19243. background: 'red',
  19244. display: 'none'
  19245. };
  19246. //切换状态
  19247. line.onmouseout = function(){
  19248. this.style.display = 'none';
  19249. };
  19250. utils.extend( line.style, styles );
  19251. this.document.body.appendChild( line );
  19252. }
  19253. return line;
  19254. }
  19255. /**
  19256. * 更新resize-line
  19257. */
  19258. function updateResizeLine( cell, uetable ) {
  19259. var line = getResizeLineByUETable.call( this ),
  19260. table = uetable.table,
  19261. styles = {
  19262. top: domUtils.getXY( table ).y + 'px',
  19263. left: domUtils.getXY( cell).x + cell.offsetWidth - cellBorderWidth + 'px',
  19264. display: 'block',
  19265. height: table.offsetHeight + 'px'
  19266. };
  19267. utils.extend( line.style, styles );
  19268. }
  19269. /**
  19270. * 显示resize-line
  19271. */
  19272. function showResizeLine( cell ) {
  19273. var uetable = getUETable( cell );
  19274. updateResizeLine.call( this, cell, uetable );
  19275. }
  19276. /**
  19277. * 获取鼠标与当前单元格的相对位置
  19278. * @param ele
  19279. * @param mousePos
  19280. */
  19281. function getRelation(ele, mousePos) {
  19282. var elePos = domUtils.getXY(ele);
  19283. if( !elePos ) {
  19284. return '';
  19285. }
  19286. if (elePos.x + ele.offsetWidth - mousePos.x < cellBorderWidth) {
  19287. return "h";
  19288. }
  19289. if (mousePos.x - elePos.x < cellBorderWidth) {
  19290. return 'h1'
  19291. }
  19292. if (elePos.y + ele.offsetHeight - mousePos.y < cellBorderWidth) {
  19293. return "v";
  19294. }
  19295. if (mousePos.y - elePos.y < cellBorderWidth) {
  19296. return 'v1'
  19297. }
  19298. return '';
  19299. }
  19300. function mouseDownEvent(type, evt) {
  19301. if( isEditorDisabled() ) {
  19302. return ;
  19303. }
  19304. userActionStatus = {
  19305. x: evt.clientX,
  19306. y: evt.clientY
  19307. };
  19308. //右键菜单单独处理
  19309. if (evt.button == 2) {
  19310. var ut = getUETableBySelected(me),
  19311. flag = false;
  19312. if (ut) {
  19313. var td = getTargetTd(me, evt);
  19314. utils.each(ut.selectedTds, function (ti) {
  19315. if (ti === td) {
  19316. flag = true;
  19317. }
  19318. });
  19319. if (!flag) {
  19320. removeSelectedClass(domUtils.getElementsByTagName(me.body, "th td"));
  19321. ut.clearSelected()
  19322. } else {
  19323. td = ut.selectedTds[0];
  19324. setTimeout(function () {
  19325. me.selection.getRange().setStart(td, 0).setCursor(false, true);
  19326. }, 0);
  19327. }
  19328. }
  19329. } else {
  19330. tableClickHander( evt );
  19331. }
  19332. }
  19333. //清除表格的计时器
  19334. function clearTableTimer() {
  19335. tabTimer && clearTimeout( tabTimer );
  19336. tabTimer = null;
  19337. }
  19338. //双击收缩
  19339. function tableDbclickHandler(evt) {
  19340. singleClickState = 0;
  19341. evt = evt || me.window.event;
  19342. var target = getParentTdOrTh(evt.target || evt.srcElement);
  19343. if (target) {
  19344. var h;
  19345. if (h = getRelation(target, mouseCoords(evt))) {
  19346. hideDragLine( me );
  19347. if (h == 'h1') {
  19348. h = 'h';
  19349. if (inTableSide(domUtils.findParentByTagName(target, "table"), target, evt)) {
  19350. me.execCommand('adaptbywindow');
  19351. } else {
  19352. target = getUETable(target).getPreviewCell(target);
  19353. if (target) {
  19354. var rng = me.selection.getRange();
  19355. rng.selectNodeContents(target).setCursor(true, true)
  19356. }
  19357. }
  19358. }
  19359. if (h == 'h') {
  19360. var ut = getUETable(target),
  19361. table = ut.table,
  19362. cells = getCellsByMoveBorder( target, table, true );
  19363. cells = extractArray( cells, 'left' );
  19364. ut.width = ut.offsetWidth;
  19365. var oldWidth = [],
  19366. newWidth = [];
  19367. utils.each( cells, function( cell ){
  19368. oldWidth.push( cell.offsetWidth );
  19369. } );
  19370. utils.each( cells, function( cell ){
  19371. cell.removeAttribute("width");
  19372. } );
  19373. window.setTimeout( function(){
  19374. //是否允许改变
  19375. var changeable = true;
  19376. utils.each( cells, function( cell, index ){
  19377. var width = cell.offsetWidth;
  19378. if( width > oldWidth[index] ) {
  19379. changeable = false;
  19380. return false;
  19381. }
  19382. newWidth.push( width );
  19383. } );
  19384. var change = changeable ? newWidth : oldWidth;
  19385. utils.each( cells, function( cell, index ){
  19386. cell.width = change[index] - getTabcellSpace();
  19387. } );
  19388. }, 0 );
  19389. // minWidth -= cellMinWidth;
  19390. //
  19391. // table.removeAttribute("width");
  19392. // utils.each(cells, function (cell) {
  19393. // cell.style.width = "";
  19394. // cell.width -= minWidth;
  19395. // });
  19396. }
  19397. }
  19398. }
  19399. }
  19400. function tableClickHander( evt ) {
  19401. removeSelectedClass(domUtils.getElementsByTagName(me.body, "td th"));
  19402. //trace:3113
  19403. //选中单元格,点击table外部,不会清掉table上挂的ueTable,会引起getUETableBySelected方法返回值
  19404. utils.each(me.document.getElementsByTagName('table'), function (t) {
  19405. t.ueTable = null;
  19406. });
  19407. startTd = getTargetTd(me, evt);
  19408. if( !startTd ) return;
  19409. var table = domUtils.findParentByTagName(startTd, "table", true);
  19410. ut = getUETable(table);
  19411. ut && ut.clearSelected();
  19412. //判断当前鼠标状态
  19413. if (!onBorder) {
  19414. me.document.body.style.webkitUserSelect = '';
  19415. mousedown = true;
  19416. me.addListener('mouseover', mouseOverEvent);
  19417. } else {
  19418. //边框上的动作处理
  19419. borderActionHandler( evt );
  19420. }
  19421. }
  19422. //处理表格边框上的动作, 这里做延时处理,避免两种动作互相影响
  19423. function borderActionHandler( evt ) {
  19424. if ( browser.ie ) {
  19425. evt = reconstruct(evt );
  19426. }
  19427. clearTableDragTimer();
  19428. //是否正在等待resize的缓冲中
  19429. isInResizeBuffer = true;
  19430. tableDragTimer = setTimeout(function(){
  19431. tableBorderDrag( evt );
  19432. }, dblclickTime);
  19433. }
  19434. function extractArray( originArr, key ) {
  19435. var result = [],
  19436. tmp = null;
  19437. for( var i = 0, len = originArr.length; i<len; i++ ) {
  19438. tmp = originArr[ i ][ key ];
  19439. if( tmp ) {
  19440. result.push( tmp );
  19441. }
  19442. }
  19443. return result;
  19444. }
  19445. function clearTableDragTimer() {
  19446. tableDragTimer && clearTimeout(tableDragTimer);
  19447. tableDragTimer = null;
  19448. }
  19449. function reconstruct( obj ) {
  19450. var attrs = ['pageX', 'pageY', 'clientX', 'clientY', 'srcElement', 'target'],
  19451. newObj = {};
  19452. if( obj ) {
  19453. for( var i = 0, key, val; key = attrs[i]; i++ ) {
  19454. val=obj[ key ];
  19455. val && (newObj[ key ] = val);
  19456. }
  19457. }
  19458. return newObj;
  19459. }
  19460. //边框拖动
  19461. function tableBorderDrag( evt ) {
  19462. isInResizeBuffer = false;
  19463. startTd = evt.target || evt.srcElement;
  19464. if( !startTd ) return;
  19465. var state = getRelation(startTd, mouseCoords(evt));
  19466. if (/\d/.test(state)) {
  19467. state = state.replace(/\d/, '');
  19468. startTd = getUETable(startTd).getPreviewCell(startTd, state == 'v');
  19469. }
  19470. hideDragLine(me);
  19471. getDragLine(me, me.document);
  19472. me.fireEvent('saveScene');
  19473. showDragLineAt(state, startTd);
  19474. mousedown = true;
  19475. //拖动开始
  19476. onDrag = state;
  19477. dragTd = startTd;
  19478. }
  19479. function mouseUpEvent(type, evt) {
  19480. if( isEditorDisabled() ) {
  19481. return ;
  19482. }
  19483. clearTableDragTimer();
  19484. isInResizeBuffer = false;
  19485. if( onBorder ) {
  19486. singleClickState = ++singleClickState % 3;
  19487. userActionStatus = {
  19488. x: evt.clientX,
  19489. y: evt.clientY
  19490. };
  19491. tableResizeTimer = setTimeout(function(){
  19492. singleClickState > 0 && singleClickState--;
  19493. }, dblclickTime );
  19494. if( singleClickState === 2 ) {
  19495. singleClickState = 0;
  19496. tableDbclickHandler(evt);
  19497. return;
  19498. }
  19499. }
  19500. if (evt.button == 2)return;
  19501. var me = this;
  19502. //清除表格上原生跨选问题
  19503. var range = me.selection.getRange(),
  19504. start = domUtils.findParentByTagName(range.startContainer, 'table', true),
  19505. end = domUtils.findParentByTagName(range.endContainer, 'table', true);
  19506. if (start || end) {
  19507. if (start === end) {
  19508. start = domUtils.findParentByTagName(range.startContainer, ['td', 'th', 'caption'], true);
  19509. end = domUtils.findParentByTagName(range.endContainer, ['td', 'th', 'caption'], true);
  19510. if (start !== end) {
  19511. me.selection.clearRange()
  19512. }
  19513. } else {
  19514. me.selection.clearRange()
  19515. }
  19516. }
  19517. mousedown = false;
  19518. me.document.body.style.webkitUserSelect = '';
  19519. //拖拽状态下的mouseUP
  19520. if ( onDrag && dragTd ) {
  19521. me.selection.getNative()[browser.ie9below ? 'empty' : 'removeAllRanges']();
  19522. singleClickState = 0;
  19523. dragLine = me.document.getElementById('ue_tableDragLine');
  19524. // trace 3973
  19525. if (dragLine) {
  19526. var dragTdPos = domUtils.getXY(dragTd),
  19527. dragLinePos = domUtils.getXY(dragLine);
  19528. switch (onDrag) {
  19529. case "h":
  19530. changeColWidth(dragTd, dragLinePos.x - dragTdPos.x);
  19531. break;
  19532. case "v":
  19533. changeRowHeight(dragTd, dragLinePos.y - dragTdPos.y - dragTd.offsetHeight);
  19534. break;
  19535. default:
  19536. }
  19537. onDrag = "";
  19538. dragTd = null;
  19539. hideDragLine(me);
  19540. me.fireEvent('saveScene');
  19541. return;
  19542. }
  19543. }
  19544. //正常状态下的mouseup
  19545. if (!startTd) {
  19546. var target = domUtils.findParentByTagName(evt.target || evt.srcElement, "td", true);
  19547. if (!target) target = domUtils.findParentByTagName(evt.target || evt.srcElement, "th", true);
  19548. if (target && (target.tagName == "TD" || target.tagName == "TH")) {
  19549. if (me.fireEvent("excludetable", target) === true) return;
  19550. range = new dom.Range(me.document);
  19551. range.setStart(target, 0).setCursor(false, true);
  19552. }
  19553. } else {
  19554. var ut = getUETable(startTd),
  19555. cell = ut ? ut.selectedTds[0] : null;
  19556. if (cell) {
  19557. range = new dom.Range(me.document);
  19558. if (domUtils.isEmptyBlock(cell)) {
  19559. range.setStart(cell, 0).setCursor(false, true);
  19560. } else {
  19561. range.selectNodeContents(cell).shrinkBoundary().setCursor(false, true);
  19562. }
  19563. } else {
  19564. range = me.selection.getRange().shrinkBoundary();
  19565. if (!range.collapsed) {
  19566. var start = domUtils.findParentByTagName(range.startContainer, ['td', 'th'], true),
  19567. end = domUtils.findParentByTagName(range.endContainer, ['td', 'th'], true);
  19568. //在table里边的不能清除
  19569. if (start && !end || !start && end || start && end && start !== end) {
  19570. range.setCursor(false, true);
  19571. }
  19572. }
  19573. }
  19574. startTd = null;
  19575. me.removeListener('mouseover', mouseOverEvent);
  19576. }
  19577. me._selectionChange(250, evt);
  19578. }
  19579. function mouseOverEvent(type, evt) {
  19580. if( isEditorDisabled() ) {
  19581. return;
  19582. }
  19583. var me = this,
  19584. tar = evt.target || evt.srcElement;
  19585. currentTd = domUtils.findParentByTagName(tar, "td", true) || domUtils.findParentByTagName(tar, "th", true);
  19586. //需要判断两个TD是否位于同一个表格内
  19587. if (startTd && currentTd &&
  19588. ((startTd.tagName == "TD" && currentTd.tagName == "TD") || (startTd.tagName == "TH" && currentTd.tagName == "TH")) &&
  19589. domUtils.findParentByTagName(startTd, 'table') == domUtils.findParentByTagName(currentTd, 'table')) {
  19590. var ut = getUETable(currentTd);
  19591. if (startTd != currentTd) {
  19592. me.document.body.style.webkitUserSelect = 'none';
  19593. me.selection.getNative()[browser.ie9below ? 'empty' : 'removeAllRanges']();
  19594. var range = ut.getCellsRange(startTd, currentTd);
  19595. ut.setSelected(range);
  19596. } else {
  19597. me.document.body.style.webkitUserSelect = '';
  19598. ut.clearSelected();
  19599. }
  19600. }
  19601. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  19602. }
  19603. function setCellHeight(cell, height, backHeight) {
  19604. var lineHight = parseInt(domUtils.getComputedStyle(cell, "line-height"), 10),
  19605. tmpHeight = backHeight + height;
  19606. height = tmpHeight < lineHight ? lineHight : tmpHeight;
  19607. if (cell.style.height) cell.style.height = "";
  19608. cell.rowSpan == 1 ? cell.setAttribute("height", height) : (cell.removeAttribute && cell.removeAttribute("height"));
  19609. }
  19610. function getWidth(cell) {
  19611. if (!cell)return 0;
  19612. return parseInt(domUtils.getComputedStyle(cell, "width"), 10);
  19613. }
  19614. function changeColWidth(cell, changeValue) {
  19615. var ut = getUETable(cell);
  19616. if (ut) {
  19617. //根据当前移动的边框获取相关的单元格
  19618. var table = ut.table,
  19619. cells = getCellsByMoveBorder( cell, table );
  19620. table.style.width = "";
  19621. table.removeAttribute("width");
  19622. //修正改变量
  19623. changeValue = correctChangeValue( changeValue, cell, cells );
  19624. if (cell.nextSibling) {
  19625. var i=0;
  19626. utils.each( cells, function( cellGroup ){
  19627. cellGroup.left.width = (+cellGroup.left.width)+changeValue;
  19628. cellGroup.right && ( cellGroup.right.width = (+cellGroup.right.width)-changeValue );
  19629. } );
  19630. } else {
  19631. utils.each( cells, function( cellGroup ){
  19632. cellGroup.left.width -= -changeValue;
  19633. } );
  19634. }
  19635. }
  19636. }
  19637. function isEditorDisabled() {
  19638. return me.body.contentEditable === "false";
  19639. }
  19640. function changeRowHeight(td, changeValue) {
  19641. if (Math.abs(changeValue) < 10) return;
  19642. var ut = getUETable(td);
  19643. if (ut) {
  19644. var cells = ut.getSameEndPosCells(td, "y"),
  19645. //备份需要连带变化的td的原始高度,否则后期无法获取正确的值
  19646. backHeight = cells[0] ? cells[0].offsetHeight : 0;
  19647. for (var i = 0, cell; cell = cells[i++];) {
  19648. setCellHeight(cell, changeValue, backHeight);
  19649. }
  19650. }
  19651. }
  19652. /**
  19653. * 获取调整单元格大小的相关单元格
  19654. * @isContainMergeCell 返回的结果中是否包含发生合并后的单元格
  19655. */
  19656. function getCellsByMoveBorder( cell, table, isContainMergeCell ) {
  19657. if( !table ) {
  19658. table = domUtils.findParentByTagName( cell, 'table' );
  19659. }
  19660. if( !table ) {
  19661. return null;
  19662. }
  19663. //获取到该单元格所在行的序列号
  19664. var index = domUtils.getNodeIndex( cell ),
  19665. temp = cell,
  19666. rows = table.rows,
  19667. colIndex = 0;
  19668. while( temp ) {
  19669. //获取到当前单元格在未发生单元格合并时的序列
  19670. if( temp.nodeType === 1 ) {
  19671. colIndex += (temp.colSpan || 1);
  19672. }
  19673. temp = temp.previousSibling;
  19674. }
  19675. temp = null;
  19676. //记录想关的单元格
  19677. var borderCells = [];
  19678. utils.each(rows, function( tabRow ){
  19679. var cells = tabRow.cells,
  19680. currIndex = 0;
  19681. utils.each( cells, function( tabCell ){
  19682. currIndex += (tabCell.colSpan || 1);
  19683. if( currIndex === colIndex ) {
  19684. borderCells.push({
  19685. left: tabCell,
  19686. right: tabCell.nextSibling || null
  19687. });
  19688. return false;
  19689. } else if( currIndex > colIndex ) {
  19690. if( isContainMergeCell ) {
  19691. borderCells.push({
  19692. left: tabCell
  19693. });
  19694. }
  19695. return false;
  19696. }
  19697. } );
  19698. });
  19699. return borderCells;
  19700. }
  19701. /**
  19702. * 通过给定的单元格集合获取最小的单元格width
  19703. */
  19704. function getMinWidthByTableCells( cells ) {
  19705. var minWidth = Number.MAX_VALUE;
  19706. for( var i = 0, curCell; curCell = cells[ i ] ; i++ ) {
  19707. minWidth = Math.min( minWidth, curCell.width || getTableCellWidth( curCell ) );
  19708. }
  19709. return minWidth;
  19710. }
  19711. function correctChangeValue( changeValue, relatedCell, cells ) {
  19712. //为单元格的paading预留空间
  19713. changeValue -= getTabcellSpace();
  19714. if( changeValue < 0 ) {
  19715. return 0;
  19716. }
  19717. changeValue -= getTableCellWidth( relatedCell );
  19718. //确定方向
  19719. var direction = changeValue < 0 ? 'left':'right';
  19720. changeValue = Math.abs(changeValue);
  19721. //只关心非最后一个单元格就可以
  19722. utils.each( cells, function( cellGroup ){
  19723. var curCell = cellGroup[direction];
  19724. //为单元格保留最小空间
  19725. if( curCell ) {
  19726. changeValue = Math.min( changeValue, getTableCellWidth( curCell )-cellMinWidth );
  19727. }
  19728. } );
  19729. //修正越界
  19730. changeValue = changeValue < 0 ? 0 : changeValue;
  19731. return direction === 'left' ? -changeValue : changeValue;
  19732. }
  19733. function getTableCellWidth( cell ) {
  19734. var width = 0,
  19735. //偏移纠正量
  19736. offset = 0,
  19737. width = cell.offsetWidth - getTabcellSpace();
  19738. //最后一个节点纠正一下
  19739. if( !cell.nextSibling ) {
  19740. width -= getTableCellOffset( cell );
  19741. }
  19742. width = width < 0 ? 0 : width;
  19743. try {
  19744. cell.width = width;
  19745. } catch(e) {
  19746. }
  19747. return width;
  19748. }
  19749. /**
  19750. * 获取单元格所在表格的最末单元格的偏移量
  19751. */
  19752. function getTableCellOffset( cell ) {
  19753. tab = domUtils.findParentByTagName( cell, "table", false);
  19754. if( tab.offsetVal === undefined ) {
  19755. var prev = cell.previousSibling;
  19756. if( prev ) {
  19757. //最后一个单元格和前一个单元格的width diff结果 如果恰好为一个border width, 则条件成立
  19758. tab.offsetVal = cell.offsetWidth - prev.offsetWidth === UT.borderWidth ? UT.borderWidth : 0;
  19759. } else {
  19760. tab.offsetVal = 0;
  19761. }
  19762. }
  19763. return tab.offsetVal;
  19764. }
  19765. function getTabcellSpace() {
  19766. if( UT.tabcellSpace === undefined ) {
  19767. var cell = null,
  19768. tab = me.document.createElement("table"),
  19769. tbody = me.document.createElement("tbody"),
  19770. trow = me.document.createElement("tr"),
  19771. tabcell = me.document.createElement("td"),
  19772. mirror = null;
  19773. tabcell.style.cssText = 'border: 0;';
  19774. tabcell.width = 1;
  19775. trow.appendChild( tabcell );
  19776. trow.appendChild( mirror = tabcell.cloneNode( false ) );
  19777. tbody.appendChild( trow );
  19778. tab.appendChild( tbody );
  19779. tab.style.cssText = "visibility: hidden;";
  19780. me.body.appendChild( tab );
  19781. UT.paddingSpace = tabcell.offsetWidth - 1;
  19782. var tmpTabWidth = tab.offsetWidth;
  19783. tabcell.style.cssText = '';
  19784. mirror.style.cssText = '';
  19785. UT.borderWidth = ( tab.offsetWidth - tmpTabWidth ) / 3;
  19786. UT.tabcellSpace = UT.paddingSpace + UT.borderWidth;
  19787. me.body.removeChild( tab );
  19788. }
  19789. getTabcellSpace = function(){ return UT.tabcellSpace; };
  19790. return UT.tabcellSpace;
  19791. }
  19792. function getDragLine(editor, doc) {
  19793. if (mousedown)return;
  19794. dragLine = editor.document.createElement("div");
  19795. domUtils.setAttributes(dragLine, {
  19796. id:"ue_tableDragLine",
  19797. unselectable:'on',
  19798. contenteditable:false,
  19799. 'onresizestart':'return false',
  19800. 'ondragstart':'return false',
  19801. 'onselectstart':'return false',
  19802. style:"background-color:blue;position:absolute;padding:0;margin:0;background-image:none;border:0px none;opacity:0;filter:alpha(opacity=0)"
  19803. });
  19804. editor.body.appendChild(dragLine);
  19805. }
  19806. function hideDragLine(editor) {
  19807. if (mousedown)return;
  19808. var line;
  19809. while (line = editor.document.getElementById('ue_tableDragLine')) {
  19810. domUtils.remove(line)
  19811. }
  19812. }
  19813. /**
  19814. * 依据state(v|h)在cell位置显示横线
  19815. * @param state
  19816. * @param cell
  19817. */
  19818. function showDragLineAt(state, cell) {
  19819. if (!cell) return;
  19820. var table = domUtils.findParentByTagName(cell, "table"),
  19821. caption = table.getElementsByTagName('caption'),
  19822. width = table.offsetWidth,
  19823. height = table.offsetHeight - (caption.length > 0 ? caption[0].offsetHeight : 0),
  19824. tablePos = domUtils.getXY(table),
  19825. cellPos = domUtils.getXY(cell), css;
  19826. switch (state) {
  19827. case "h":
  19828. css = 'height:' + height + 'px;top:' + (tablePos.y + (caption.length > 0 ? caption[0].offsetHeight : 0)) + 'px;left:' + (cellPos.x + cell.offsetWidth);
  19829. dragLine.style.cssText = css + 'px;position: absolute;display:block;background-color:blue;width:1px;border:0; color:blue;opacity:.3;filter:alpha(opacity=30)';
  19830. break;
  19831. case "v":
  19832. css = 'width:' + width + 'px;left:' + tablePos.x + 'px;top:' + (cellPos.y + cell.offsetHeight );
  19833. //必须加上border:0和color:blue,否则低版ie不支持背景色显示
  19834. dragLine.style.cssText = css + 'px;overflow:hidden;position: absolute;display:block;background-color:blue;height:1px;border:0;color:blue;opacity:.2;filter:alpha(opacity=20)';
  19835. break;
  19836. default:
  19837. }
  19838. }
  19839. /**
  19840. * 当表格边框颜色为白色时设置为虚线,true为添加虚线
  19841. * @param editor
  19842. * @param flag
  19843. */
  19844. function switchBorderColor(editor, flag) {
  19845. var tableArr = domUtils.getElementsByTagName(editor.body, "table"), color;
  19846. for (var i = 0, node; node = tableArr[i++];) {
  19847. var td = domUtils.getElementsByTagName(node, "td");
  19848. if (td[0]) {
  19849. if (flag) {
  19850. color = (td[0].style.borderColor).replace(/\s/g, "");
  19851. if (/(#ffffff)|(rgb\(255,255,255\))/ig.test(color))
  19852. domUtils.addClass(node, "noBorderTable")
  19853. } else {
  19854. domUtils.removeClasses(node, "noBorderTable")
  19855. }
  19856. }
  19857. }
  19858. }
  19859. function getTableWidth(editor, needIEHack, defaultValue) {
  19860. var body = editor.body;
  19861. return body.offsetWidth - (needIEHack ? parseInt(domUtils.getComputedStyle(body, 'margin-left'), 10) * 2 : 0) - defaultValue.tableBorder * 2 - (editor.options.offsetWidth || 0);
  19862. }
  19863. /**
  19864. * 获取当前拖动的单元格
  19865. */
  19866. function getTargetTd(editor, evt) {
  19867. var target = domUtils.findParentByTagName(evt.target || evt.srcElement, ["td", "th"], true),
  19868. dir = null;
  19869. if( !target ) {
  19870. return null;
  19871. }
  19872. dir = getRelation( target, mouseCoords( evt ) );
  19873. //如果有前一个节点, 需要做一个修正, 否则可能会得到一个错误的td
  19874. if( !target ) {
  19875. return null;
  19876. }
  19877. if( dir === 'h1' && target.previousSibling ) {
  19878. var position = domUtils.getXY( target),
  19879. cellWidth = target.offsetWidth;
  19880. if( Math.abs( position.x + cellWidth - evt.clientX ) > cellWidth / 3 ) {
  19881. target = target.previousSibling;
  19882. }
  19883. } else if( dir === 'v1' && target.parentNode.previousSibling ) {
  19884. var position = domUtils.getXY( target),
  19885. cellHeight = target.offsetHeight;
  19886. if( Math.abs( position.y + cellHeight - evt.clientY ) > cellHeight / 3 ) {
  19887. target = target.parentNode.previousSibling.firstChild;
  19888. }
  19889. }
  19890. //排除了非td内部以及用于代码高亮部分的td
  19891. return target && !(editor.fireEvent("excludetable", target) === true) ? target : null;
  19892. }
  19893. };
  19894. // plugins/table.sort.js
  19895. /**
  19896. * Created with JetBrains PhpStorm.
  19897. * User: Jinqn
  19898. * Date: 13-10-12
  19899. * Time: 上午10:20
  19900. * To change this template use File | Settings | File Templates.
  19901. */
  19902. UE.UETable.prototype.sortTable = function (sortByCellIndex, compareFn) {
  19903. var table = this.table,
  19904. rows = table.rows,
  19905. trArray = [],
  19906. flag = rows[0].cells[0].tagName === "TH",
  19907. lastRowIndex = 0;
  19908. if(this.selectedTds.length){
  19909. var range = this.cellsRange,
  19910. len = range.endRowIndex + 1;
  19911. for (var i = range.beginRowIndex; i < len; i++) {
  19912. trArray[i] = rows[i];
  19913. }
  19914. trArray.splice(0,range.beginRowIndex);
  19915. lastRowIndex = (range.endRowIndex +1) === this.rowsNum ? 0 : range.endRowIndex +1;
  19916. }else{
  19917. for (var i = 0,len = rows.length; i < len; i++) {
  19918. trArray[i] = rows[i];
  19919. }
  19920. }
  19921. var Fn = {
  19922. 'reversecurrent': function(td1,td2){
  19923. return 1;
  19924. },
  19925. 'orderbyasc': function(td1,td2){
  19926. var value1 = td1.innerText||td1.textContent,
  19927. value2 = td2.innerText||td2.textContent;
  19928. return value1.localeCompare(value2);
  19929. },
  19930. 'reversebyasc': function(td1,td2){
  19931. var value1 = td1.innerHTML,
  19932. value2 = td2.innerHTML;
  19933. return value2.localeCompare(value1);
  19934. },
  19935. 'orderbynum': function(td1,td2){
  19936. var value1 = td1[browser.ie ? 'innerText':'textContent'].match(/\d+/),
  19937. value2 = td2[browser.ie ? 'innerText':'textContent'].match(/\d+/);
  19938. if(value1) value1 = +value1[0];
  19939. if(value2) value2 = +value2[0];
  19940. return (value1||0) - (value2||0);
  19941. },
  19942. 'reversebynum': function(td1,td2){
  19943. var value1 = td1[browser.ie ? 'innerText':'textContent'].match(/\d+/),
  19944. value2 = td2[browser.ie ? 'innerText':'textContent'].match(/\d+/);
  19945. if(value1) value1 = +value1[0];
  19946. if(value2) value2 = +value2[0];
  19947. return (value2||0) - (value1||0);
  19948. }
  19949. };
  19950. //对表格设置排序的标记data-sort-type
  19951. table.setAttribute('data-sort-type', compareFn && typeof compareFn === "string" && Fn[compareFn] ? compareFn:'');
  19952. //th不参与排序
  19953. flag && trArray.splice(0, 1);
  19954. trArray = utils.sort(trArray,function (tr1, tr2) {
  19955. var result;
  19956. if (compareFn && typeof compareFn === "function") {
  19957. result = compareFn.call(this, tr1.cells[sortByCellIndex], tr2.cells[sortByCellIndex]);
  19958. } else if (compareFn && typeof compareFn === "number") {
  19959. result = 1;
  19960. } else if (compareFn && typeof compareFn === "string" && Fn[compareFn]) {
  19961. result = Fn[compareFn].call(this, tr1.cells[sortByCellIndex], tr2.cells[sortByCellIndex]);
  19962. } else {
  19963. result = Fn['orderbyasc'].call(this, tr1.cells[sortByCellIndex], tr2.cells[sortByCellIndex]);
  19964. }
  19965. return result;
  19966. });
  19967. var fragment = table.ownerDocument.createDocumentFragment();
  19968. for (var j = 0, len = trArray.length; j < len; j++) {
  19969. fragment.appendChild(trArray[j]);
  19970. }
  19971. var tbody = table.getElementsByTagName("tbody")[0];
  19972. if(!lastRowIndex){
  19973. tbody.appendChild(fragment);
  19974. }else{
  19975. tbody.insertBefore(fragment,rows[lastRowIndex- range.endRowIndex + range.beginRowIndex - 1])
  19976. }
  19977. };
  19978. UE.plugins['tablesort'] = function () {
  19979. var me = this,
  19980. UT = UE.UETable,
  19981. getUETable = function (tdOrTable) {
  19982. return UT.getUETable(tdOrTable);
  19983. },
  19984. getTableItemsByRange = function (editor) {
  19985. return UT.getTableItemsByRange(editor);
  19986. };
  19987. me.ready(function () {
  19988. //添加表格可排序的样式
  19989. utils.cssRule('tablesort',
  19990. 'table.sortEnabled tr.firstRow th,table.sortEnabled tr.firstRow td{padding-right:20px;background-repeat: no-repeat;background-position: center right;' +
  19991. ' background-image:url(' + me.options.themePath + me.options.theme + '/images/sortable.png);}',
  19992. me.document);
  19993. //做单元格合并操作时,清除可排序标识
  19994. me.addListener("afterexeccommand", function (type, cmd) {
  19995. if( cmd == 'mergeright' || cmd == 'mergedown' || cmd == 'mergecells') {
  19996. this.execCommand('disablesort');
  19997. }
  19998. });
  19999. });
  20000. //表格排序
  20001. UE.commands['sorttable'] = {
  20002. queryCommandState: function () {
  20003. var me = this,
  20004. tableItems = getTableItemsByRange(me);
  20005. if (!tableItems.cell) return -1;
  20006. var table = tableItems.table,
  20007. cells = table.getElementsByTagName("td");
  20008. for (var i = 0, cell; cell = cells[i++];) {
  20009. if (cell.rowSpan != 1 || cell.colSpan != 1) return -1;
  20010. }
  20011. return 0;
  20012. },
  20013. execCommand: function (cmd, fn) {
  20014. var me = this,
  20015. range = me.selection.getRange(),
  20016. bk = range.createBookmark(true),
  20017. tableItems = getTableItemsByRange(me),
  20018. cell = tableItems.cell,
  20019. ut = getUETable(tableItems.table),
  20020. cellInfo = ut.getCellInfo(cell);
  20021. ut.sortTable(cellInfo.cellIndex, fn);
  20022. range.moveToBookmark(bk);
  20023. try{
  20024. range.select();
  20025. }catch(e){}
  20026. }
  20027. };
  20028. //设置表格可排序,清除表格可排序
  20029. UE.commands["enablesort"] = UE.commands["disablesort"] = {
  20030. queryCommandState: function (cmd) {
  20031. var table = getTableItemsByRange(this).table;
  20032. if(table && cmd=='enablesort') {
  20033. var cells = domUtils.getElementsByTagName(table, 'th td');
  20034. for(var i = 0; i<cells.length; i++) {
  20035. if(cells[i].getAttribute('colspan')>1 || cells[i].getAttribute('rowspan')>1) return -1;
  20036. }
  20037. }
  20038. return !table ? -1: cmd=='enablesort' ^ table.getAttribute('data-sort')!='sortEnabled' ? -1:0;
  20039. },
  20040. execCommand: function (cmd) {
  20041. var table = getTableItemsByRange(this).table;
  20042. table.setAttribute("data-sort", cmd == "enablesort" ? "sortEnabled" : "sortDisabled");
  20043. cmd == "enablesort" ? domUtils.addClass(table,"sortEnabled"):domUtils.removeClasses(table,"sortEnabled");
  20044. }
  20045. };
  20046. };
  20047. // plugins/contextmenu.js
  20048. ///import core
  20049. ///commands 右键菜单
  20050. ///commandsName ContextMenu
  20051. ///commandsTitle 右键菜单
  20052. /**
  20053. * 右键菜单
  20054. * @function
  20055. * @name baidu.editor.plugins.contextmenu
  20056. * @author zhanyi
  20057. */
  20058. UE.plugins['contextmenu'] = function () {
  20059. var me = this;
  20060. me.setOpt('enableContextMenu',true);
  20061. if(me.getOpt('enableContextMenu') === false){
  20062. return;
  20063. }
  20064. var lang = me.getLang( "contextMenu" ),
  20065. menu,
  20066. items = me.options.contextMenu || [
  20067. {label:lang['selectall'], cmdName:'selectall'},
  20068. {
  20069. label:lang.cleardoc,
  20070. cmdName:'cleardoc',
  20071. exec:function () {
  20072. if ( confirm( lang.confirmclear ) ) {
  20073. this.execCommand( 'cleardoc' );
  20074. }
  20075. }
  20076. },
  20077. '-',
  20078. {
  20079. label:lang.unlink,
  20080. cmdName:'unlink'
  20081. },
  20082. '-',
  20083. {
  20084. group:lang.paragraph,
  20085. icon:'justifyjustify',
  20086. subMenu:[
  20087. {
  20088. label:lang.justifyleft,
  20089. cmdName:'justify',
  20090. value:'left'
  20091. },
  20092. {
  20093. label:lang.justifyright,
  20094. cmdName:'justify',
  20095. value:'right'
  20096. },
  20097. {
  20098. label:lang.justifycenter,
  20099. cmdName:'justify',
  20100. value:'center'
  20101. },
  20102. {
  20103. label:lang.justifyjustify,
  20104. cmdName:'justify',
  20105. value:'justify'
  20106. }
  20107. ]
  20108. },
  20109. '-',
  20110. {
  20111. group:lang.table,
  20112. icon:'table',
  20113. subMenu:[
  20114. {
  20115. label:lang.inserttable,
  20116. cmdName:'inserttable'
  20117. },
  20118. {
  20119. label:lang.deletetable,
  20120. cmdName:'deletetable'
  20121. },
  20122. '-',
  20123. {
  20124. label:lang.deleterow,
  20125. cmdName:'deleterow'
  20126. },
  20127. {
  20128. label:lang.deletecol,
  20129. cmdName:'deletecol'
  20130. },
  20131. {
  20132. label:lang.insertcol,
  20133. cmdName:'insertcol'
  20134. },
  20135. {
  20136. label:lang.insertcolnext,
  20137. cmdName:'insertcolnext'
  20138. },
  20139. {
  20140. label:lang.insertrow,
  20141. cmdName:'insertrow'
  20142. },
  20143. {
  20144. label:lang.insertrownext,
  20145. cmdName:'insertrownext'
  20146. },
  20147. '-',
  20148. {
  20149. label:lang.insertcaption,
  20150. cmdName:'insertcaption'
  20151. },
  20152. {
  20153. label:lang.deletecaption,
  20154. cmdName:'deletecaption'
  20155. },
  20156. {
  20157. label:lang.inserttitle,
  20158. cmdName:'inserttitle'
  20159. },
  20160. {
  20161. label:lang.deletetitle,
  20162. cmdName:'deletetitle'
  20163. },
  20164. {
  20165. label:lang.inserttitlecol,
  20166. cmdName:'inserttitlecol'
  20167. },
  20168. {
  20169. label:lang.deletetitlecol,
  20170. cmdName:'deletetitlecol'
  20171. },
  20172. '-',
  20173. {
  20174. label:lang.mergecells,
  20175. cmdName:'mergecells'
  20176. },
  20177. {
  20178. label:lang.mergeright,
  20179. cmdName:'mergeright'
  20180. },
  20181. {
  20182. label:lang.mergedown,
  20183. cmdName:'mergedown'
  20184. },
  20185. '-',
  20186. {
  20187. label:lang.splittorows,
  20188. cmdName:'splittorows'
  20189. },
  20190. {
  20191. label:lang.splittocols,
  20192. cmdName:'splittocols'
  20193. },
  20194. {
  20195. label:lang.splittocells,
  20196. cmdName:'splittocells'
  20197. },
  20198. '-',
  20199. {
  20200. label:lang.averageDiseRow,
  20201. cmdName:'averagedistributerow'
  20202. },
  20203. {
  20204. label:lang.averageDisCol,
  20205. cmdName:'averagedistributecol'
  20206. },
  20207. '-',
  20208. {
  20209. label:lang.edittd,
  20210. cmdName:'edittd',
  20211. exec:function () {
  20212. if ( UE.ui['edittd'] ) {
  20213. new UE.ui['edittd']( this );
  20214. }
  20215. this.getDialog('edittd').open();
  20216. }
  20217. },
  20218. {
  20219. label:lang.edittable,
  20220. cmdName:'edittable',
  20221. exec:function () {
  20222. if ( UE.ui['edittable'] ) {
  20223. new UE.ui['edittable']( this );
  20224. }
  20225. this.getDialog('edittable').open();
  20226. }
  20227. },
  20228. {
  20229. label:lang.setbordervisible,
  20230. cmdName:'setbordervisible'
  20231. }
  20232. ]
  20233. },
  20234. {
  20235. group:lang.tablesort,
  20236. icon:'tablesort',
  20237. subMenu:[
  20238. {
  20239. label:lang.enablesort,
  20240. cmdName:'enablesort'
  20241. },
  20242. {
  20243. label:lang.disablesort,
  20244. cmdName:'disablesort'
  20245. },
  20246. '-',
  20247. {
  20248. label:lang.reversecurrent,
  20249. cmdName:'sorttable',
  20250. value:'reversecurrent'
  20251. },
  20252. {
  20253. label:lang.orderbyasc,
  20254. cmdName:'sorttable',
  20255. value:'orderbyasc'
  20256. },
  20257. {
  20258. label:lang.reversebyasc,
  20259. cmdName:'sorttable',
  20260. value:'reversebyasc'
  20261. },
  20262. {
  20263. label:lang.orderbynum,
  20264. cmdName:'sorttable',
  20265. value:'orderbynum'
  20266. },
  20267. {
  20268. label:lang.reversebynum,
  20269. cmdName:'sorttable',
  20270. value:'reversebynum'
  20271. }
  20272. ]
  20273. },
  20274. {
  20275. group:lang.borderbk,
  20276. icon:'borderBack',
  20277. subMenu:[
  20278. {
  20279. label:lang.setcolor,
  20280. cmdName:"interlacetable",
  20281. exec:function(){
  20282. this.execCommand("interlacetable");
  20283. }
  20284. },
  20285. {
  20286. label:lang.unsetcolor,
  20287. cmdName:"uninterlacetable",
  20288. exec:function(){
  20289. this.execCommand("uninterlacetable");
  20290. }
  20291. },
  20292. {
  20293. label:lang.setbackground,
  20294. cmdName:"settablebackground",
  20295. exec:function(){
  20296. this.execCommand("settablebackground",{repeat:true,colorList:["#bbb","#ccc"]});
  20297. }
  20298. },
  20299. {
  20300. label:lang.unsetbackground,
  20301. cmdName:"cleartablebackground",
  20302. exec:function(){
  20303. this.execCommand("cleartablebackground");
  20304. }
  20305. },
  20306. {
  20307. label:lang.redandblue,
  20308. cmdName:"settablebackground",
  20309. exec:function(){
  20310. this.execCommand("settablebackground",{repeat:true,colorList:["red","blue"]});
  20311. }
  20312. },
  20313. {
  20314. label:lang.threecolorgradient,
  20315. cmdName:"settablebackground",
  20316. exec:function(){
  20317. this.execCommand("settablebackground",{repeat:true,colorList:["#aaa","#bbb","#ccc"]});
  20318. }
  20319. }
  20320. ]
  20321. },
  20322. {
  20323. group:lang.aligntd,
  20324. icon:'aligntd',
  20325. subMenu:[
  20326. {
  20327. cmdName:'cellalignment',
  20328. value:{align:'left',vAlign:'top'}
  20329. },
  20330. {
  20331. cmdName:'cellalignment',
  20332. value:{align:'center',vAlign:'top'}
  20333. },
  20334. {
  20335. cmdName:'cellalignment',
  20336. value:{align:'right',vAlign:'top'}
  20337. },
  20338. {
  20339. cmdName:'cellalignment',
  20340. value:{align:'left',vAlign:'middle'}
  20341. },
  20342. {
  20343. cmdName:'cellalignment',
  20344. value:{align:'center',vAlign:'middle'}
  20345. },
  20346. {
  20347. cmdName:'cellalignment',
  20348. value:{align:'right',vAlign:'middle'}
  20349. },
  20350. {
  20351. cmdName:'cellalignment',
  20352. value:{align:'left',vAlign:'bottom'}
  20353. },
  20354. {
  20355. cmdName:'cellalignment',
  20356. value:{align:'center',vAlign:'bottom'}
  20357. },
  20358. {
  20359. cmdName:'cellalignment',
  20360. value:{align:'right',vAlign:'bottom'}
  20361. }
  20362. ]
  20363. },
  20364. {
  20365. group:lang.aligntable,
  20366. icon:'aligntable',
  20367. subMenu:[
  20368. {
  20369. cmdName:'tablealignment',
  20370. className: 'left',
  20371. label:lang.tableleft,
  20372. value:"left"
  20373. },
  20374. {
  20375. cmdName:'tablealignment',
  20376. className: 'center',
  20377. label:lang.tablecenter,
  20378. value:"center"
  20379. },
  20380. {
  20381. cmdName:'tablealignment',
  20382. className: 'right',
  20383. label:lang.tableright,
  20384. value:"right"
  20385. }
  20386. ]
  20387. },
  20388. '-',
  20389. {
  20390. label:lang.insertparagraphbefore,
  20391. cmdName:'insertparagraph',
  20392. value:true
  20393. },
  20394. {
  20395. label:lang.insertparagraphafter,
  20396. cmdName:'insertparagraph'
  20397. },
  20398. {
  20399. label:lang['copy'],
  20400. cmdName:'copy'
  20401. },
  20402. {
  20403. label:lang['paste'],
  20404. cmdName:'paste'
  20405. }
  20406. ];
  20407. if ( !items.length ) {
  20408. return;
  20409. }
  20410. var uiUtils = UE.ui.uiUtils;
  20411. me.addListener( 'contextmenu', function ( type, evt ) {
  20412. var offset = uiUtils.getViewportOffsetByEvent( evt );
  20413. me.fireEvent( 'beforeselectionchange' );
  20414. if ( menu ) {
  20415. menu.destroy();
  20416. }
  20417. for ( var i = 0, ti, contextItems = []; ti = items[i]; i++ ) {
  20418. var last;
  20419. (function ( item ) {
  20420. if ( item == '-' ) {
  20421. if ( (last = contextItems[contextItems.length - 1 ] ) && last !== '-' ) {
  20422. contextItems.push( '-' );
  20423. }
  20424. } else if ( item.hasOwnProperty( "group" ) ) {
  20425. for ( var j = 0, cj, subMenu = []; cj = item.subMenu[j]; j++ ) {
  20426. (function ( subItem ) {
  20427. if ( subItem == '-' ) {
  20428. if ( (last = subMenu[subMenu.length - 1 ] ) && last !== '-' ) {
  20429. subMenu.push( '-' );
  20430. }else{
  20431. subMenu.splice(subMenu.length-1);
  20432. }
  20433. } else {
  20434. if ( (me.commands[subItem.cmdName] || UE.commands[subItem.cmdName] || subItem.query) &&
  20435. (subItem.query ? subItem.query() : me.queryCommandState( subItem.cmdName )) > -1 ) {
  20436. subMenu.push( {
  20437. 'label':subItem.label || me.getLang( "contextMenu." + subItem.cmdName + (subItem.value || '') )||"",
  20438. 'className':'edui-for-' +subItem.cmdName + ( subItem.className ? ( ' edui-for-' + subItem.cmdName + '-' + subItem.className ) : '' ),
  20439. onclick:subItem.exec ? function () {
  20440. subItem.exec.call( me );
  20441. } : function () {
  20442. me.execCommand( subItem.cmdName, subItem.value );
  20443. }
  20444. } );
  20445. }
  20446. }
  20447. })( cj );
  20448. }
  20449. if ( subMenu.length ) {
  20450. function getLabel(){
  20451. switch (item.icon){
  20452. case "table":
  20453. return me.getLang( "contextMenu.table" );
  20454. case "justifyjustify":
  20455. return me.getLang( "contextMenu.paragraph" );
  20456. case "aligntd":
  20457. return me.getLang("contextMenu.aligntd");
  20458. case "aligntable":
  20459. return me.getLang("contextMenu.aligntable");
  20460. case "tablesort":
  20461. return lang.tablesort;
  20462. case "borderBack":
  20463. return lang.borderbk;
  20464. default :
  20465. return '';
  20466. }
  20467. }
  20468. contextItems.push( {
  20469. //todo 修正成自动获取方式
  20470. 'label':getLabel(),
  20471. className:'edui-for-' + item.icon,
  20472. 'subMenu':{
  20473. items:subMenu,
  20474. editor:me
  20475. }
  20476. } );
  20477. }
  20478. } else {
  20479. //有可能commmand没有加载右键不能出来,或者没有command也想能展示出来添加query方法
  20480. if ( (me.commands[item.cmdName] || UE.commands[item.cmdName] || item.query) &&
  20481. (item.query ? item.query.call(me) : me.queryCommandState( item.cmdName )) > -1 ) {
  20482. contextItems.push( {
  20483. 'label':item.label || me.getLang( "contextMenu." + item.cmdName ),
  20484. className:'edui-for-' + (item.icon ? item.icon : item.cmdName + (item.value || '')),
  20485. onclick:item.exec ? function () {
  20486. item.exec.call( me );
  20487. } : function () {
  20488. me.execCommand( item.cmdName, item.value );
  20489. }
  20490. } );
  20491. }
  20492. }
  20493. })( ti );
  20494. }
  20495. if ( contextItems[contextItems.length - 1] == '-' ) {
  20496. contextItems.pop();
  20497. }
  20498. menu = new UE.ui.Menu( {
  20499. items:contextItems,
  20500. className:"edui-contextmenu",
  20501. editor:me
  20502. } );
  20503. menu.render();
  20504. menu.showAt( offset );
  20505. me.fireEvent("aftershowcontextmenu",menu);
  20506. domUtils.preventDefault( evt );
  20507. if ( browser.ie ) {
  20508. var ieRange;
  20509. try {
  20510. ieRange = me.selection.getNative().createRange();
  20511. } catch ( e ) {
  20512. return;
  20513. }
  20514. if ( ieRange.item ) {
  20515. var range = new dom.Range( me.document );
  20516. range.selectNode( ieRange.item( 0 ) ).select( true, true );
  20517. }
  20518. }
  20519. });
  20520. // 添加复制的flash按钮
  20521. me.addListener('aftershowcontextmenu', function(type, menu) {
  20522. if (me.zeroclipboard) {
  20523. var items = menu.items;
  20524. for (var key in items) {
  20525. if (items[key].className == 'edui-for-copy') {
  20526. me.zeroclipboard.clip(items[key].getDom());
  20527. }
  20528. }
  20529. }
  20530. });
  20531. };
  20532. // plugins/shortcutmenu.js
  20533. ///import core
  20534. ///commands 弹出菜单
  20535. // commandsName popupmenu
  20536. ///commandsTitle 弹出菜单
  20537. /**
  20538. * 弹出菜单
  20539. * @function
  20540. * @name baidu.editor.plugins.popupmenu
  20541. * @author xuheng
  20542. */
  20543. UE.plugins['shortcutmenu'] = function () {
  20544. var me = this,
  20545. menu,
  20546. items = me.options.shortcutMenu || [];
  20547. if (!items.length) {
  20548. return;
  20549. }
  20550. me.addListener ('contextmenu mouseup' , function (type , e) {
  20551. var me = this,
  20552. customEvt = {
  20553. type : type ,
  20554. target : e.target || e.srcElement ,
  20555. screenX : e.screenX ,
  20556. screenY : e.screenY ,
  20557. clientX : e.clientX ,
  20558. clientY : e.clientY
  20559. };
  20560. setTimeout (function () {
  20561. var rng = me.selection.getRange ();
  20562. if (rng.collapsed === false || type == "contextmenu") {
  20563. if (!menu) {
  20564. menu = new baidu.editor.ui.ShortCutMenu ({
  20565. editor : me ,
  20566. items : items ,
  20567. theme : me.options.theme ,
  20568. className : 'edui-shortcutmenu'
  20569. });
  20570. menu.render ();
  20571. me.fireEvent ("afterrendershortcutmenu" , menu);
  20572. }
  20573. menu.show (customEvt , !!UE.plugins['contextmenu']);
  20574. }
  20575. });
  20576. if (type == 'contextmenu') {
  20577. domUtils.preventDefault (e);
  20578. if (browser.ie9below) {
  20579. var ieRange;
  20580. try {
  20581. ieRange = me.selection.getNative().createRange();
  20582. } catch (e) {
  20583. return;
  20584. }
  20585. if (ieRange.item) {
  20586. var range = new dom.Range (me.document);
  20587. range.selectNode (ieRange.item (0)).select (true , true);
  20588. }
  20589. }
  20590. }
  20591. });
  20592. me.addListener ('keydown' , function (type) {
  20593. if (type == "keydown") {
  20594. menu && !menu.isHidden && menu.hide ();
  20595. }
  20596. });
  20597. };
  20598. // plugins/basestyle.js
  20599. /**
  20600. * B、I、sub、super命令支持
  20601. * @file
  20602. * @since 1.2.6.1
  20603. */
  20604. UE.plugins['basestyle'] = function(){
  20605. /**
  20606. * 字体加粗
  20607. * @command bold
  20608. * @param { String } cmd 命令字符串
  20609. * @remind 对已加粗的文本内容执行该命令, 将取消加粗
  20610. * @method execCommand
  20611. * @example
  20612. * ```javascript
  20613. * //editor是编辑器实例
  20614. * //对当前选中的文本内容执行加粗操作
  20615. * //第一次执行, 文本内容加粗
  20616. * editor.execCommand( 'bold' );
  20617. *
  20618. * //第二次执行, 文本内容取消加粗
  20619. * editor.execCommand( 'bold' );
  20620. * ```
  20621. */
  20622. /**
  20623. * 字体倾斜
  20624. * @command italic
  20625. * @method execCommand
  20626. * @param { String } cmd 命令字符串
  20627. * @remind 对已倾斜的文本内容执行该命令, 将取消倾斜
  20628. * @example
  20629. * ```javascript
  20630. * //editor是编辑器实例
  20631. * //对当前选中的文本内容执行斜体操作
  20632. * //第一次操作, 文本内容将变成斜体
  20633. * editor.execCommand( 'italic' );
  20634. *
  20635. * //再次对同一文本内容执行, 则文本内容将恢复正常
  20636. * editor.execCommand( 'italic' );
  20637. * ```
  20638. */
  20639. /**
  20640. * 下标文本,与“superscript”命令互斥
  20641. * @command subscript
  20642. * @method execCommand
  20643. * @remind 把选中的文本内容切换成下标文本, 如果当前选中的文本已经是下标, 则该操作会把文本内容还原成正常文本
  20644. * @param { String } cmd 命令字符串
  20645. * @example
  20646. * ```javascript
  20647. * //editor是编辑器实例
  20648. * //对当前选中的文本内容执行下标操作
  20649. * //第一次操作, 文本内容将变成下标文本
  20650. * editor.execCommand( 'subscript' );
  20651. *
  20652. * //再次对同一文本内容执行, 则文本内容将恢复正常
  20653. * editor.execCommand( 'subscript' );
  20654. * ```
  20655. */
  20656. /**
  20657. * 上标文本,与“subscript”命令互斥
  20658. * @command superscript
  20659. * @method execCommand
  20660. * @remind 把选中的文本内容切换成上标文本, 如果当前选中的文本已经是上标, 则该操作会把文本内容还原成正常文本
  20661. * @param { String } cmd 命令字符串
  20662. * @example
  20663. * ```javascript
  20664. * //editor是编辑器实例
  20665. * //对当前选中的文本内容执行上标操作
  20666. * //第一次操作, 文本内容将变成上标文本
  20667. * editor.execCommand( 'superscript' );
  20668. *
  20669. * //再次对同一文本内容执行, 则文本内容将恢复正常
  20670. * editor.execCommand( 'superscript' );
  20671. * ```
  20672. */
  20673. var basestyles = {
  20674. 'bold':['strong','b'],
  20675. 'italic':['em','i'],
  20676. 'subscript':['sub'],
  20677. 'superscript':['sup']
  20678. },
  20679. getObj = function(editor,tagNames){
  20680. return domUtils.filterNodeList(editor.selection.getStartElementPath(),tagNames);
  20681. },
  20682. me = this;
  20683. //添加快捷键
  20684. me.addshortcutkey({
  20685. "Bold" : "ctrl+66",//^B
  20686. "Italic" : "ctrl+73", //^I
  20687. "Underline" : "ctrl+85"//^U
  20688. });
  20689. me.addInputRule(function(root){
  20690. utils.each(root.getNodesByTagName('b i'),function(node){
  20691. switch (node.tagName){
  20692. case 'b':
  20693. node.tagName = 'strong';
  20694. break;
  20695. case 'i':
  20696. node.tagName = 'em';
  20697. }
  20698. });
  20699. });
  20700. for ( var style in basestyles ) {
  20701. (function( cmd, tagNames ) {
  20702. me.commands[cmd] = {
  20703. execCommand : function( cmdName ) {
  20704. var range = me.selection.getRange(),obj = getObj(this,tagNames);
  20705. if ( range.collapsed ) {
  20706. if ( obj ) {
  20707. var tmpText = me.document.createTextNode('');
  20708. range.insertNode( tmpText ).removeInlineStyle( tagNames );
  20709. range.setStartBefore(tmpText);
  20710. domUtils.remove(tmpText);
  20711. } else {
  20712. var tmpNode = range.document.createElement( tagNames[0] );
  20713. if(cmdName == 'superscript' || cmdName == 'subscript'){
  20714. tmpText = me.document.createTextNode('');
  20715. range.insertNode(tmpText)
  20716. .removeInlineStyle(['sub','sup'])
  20717. .setStartBefore(tmpText)
  20718. .collapse(true);
  20719. }
  20720. range.insertNode( tmpNode ).setStart( tmpNode, 0 );
  20721. }
  20722. range.collapse( true );
  20723. } else {
  20724. if(cmdName == 'superscript' || cmdName == 'subscript'){
  20725. if(!obj || obj.tagName.toLowerCase() != cmdName){
  20726. range.removeInlineStyle(['sub','sup']);
  20727. }
  20728. }
  20729. obj ? range.removeInlineStyle( tagNames ) : range.applyInlineStyle( tagNames[0] );
  20730. }
  20731. range.select();
  20732. },
  20733. queryCommandState : function() {
  20734. return getObj(this,tagNames) ? 1 : 0;
  20735. }
  20736. };
  20737. })( style, basestyles[style] );
  20738. }
  20739. };
  20740. // plugins/elementpath.js
  20741. /**
  20742. * 选取路径命令
  20743. * @file
  20744. */
  20745. UE.plugins['elementpath'] = function(){
  20746. var currentLevel,
  20747. tagNames,
  20748. me = this;
  20749. me.setOpt('elementPathEnabled',true);
  20750. if(!me.options.elementPathEnabled){
  20751. return;
  20752. }
  20753. me.commands['elementpath'] = {
  20754. execCommand : function( cmdName, level ) {
  20755. var start = tagNames[level],
  20756. range = me.selection.getRange();
  20757. currentLevel = level*1;
  20758. range.selectNode(start).select();
  20759. },
  20760. queryCommandValue : function() {
  20761. //产生一个副本,不能修改原来的startElementPath;
  20762. var parents = [].concat(this.selection.getStartElementPath()).reverse(),
  20763. names = [];
  20764. tagNames = parents;
  20765. for(var i=0,ci;ci=parents[i];i++){
  20766. if(ci.nodeType == 3) {
  20767. continue;
  20768. }
  20769. var name = ci.tagName.toLowerCase();
  20770. if(name == 'img' && ci.getAttribute('anchorname')){
  20771. name = 'anchor';
  20772. }
  20773. names[i] = name;
  20774. if(currentLevel == i){
  20775. currentLevel = -1;
  20776. break;
  20777. }
  20778. }
  20779. return names;
  20780. }
  20781. };
  20782. };
  20783. // plugins/formatmatch.js
  20784. /**
  20785. * 格式刷,只格式inline的
  20786. * @file
  20787. * @since 1.2.6.1
  20788. */
  20789. /**
  20790. * 格式刷
  20791. * @command formatmatch
  20792. * @method execCommand
  20793. * @remind 该操作不能复制段落格式
  20794. * @param { String } cmd 命令字符串
  20795. * @example
  20796. * ```javascript
  20797. * //editor是编辑器实例
  20798. * //获取格式刷
  20799. * editor.execCommand( 'formatmatch' );
  20800. * ```
  20801. */
  20802. UE.plugins['formatmatch'] = function(){
  20803. var me = this,
  20804. list = [],img,
  20805. flag = 0;
  20806. me.addListener('reset',function(){
  20807. list = [];
  20808. flag = 0;
  20809. });
  20810. function addList(type,evt){
  20811. if(browser.webkit){
  20812. var target = evt.target.tagName == 'IMG' ? evt.target : null;
  20813. }
  20814. function addFormat(range){
  20815. if(text){
  20816. range.selectNode(text);
  20817. }
  20818. return range.applyInlineStyle(list[list.length-1].tagName,null,list);
  20819. }
  20820. me.undoManger && me.undoManger.save();
  20821. var range = me.selection.getRange(),
  20822. imgT = target || range.getClosedNode();
  20823. if(img && imgT && imgT.tagName == 'IMG'){
  20824. //trace:964
  20825. imgT.style.cssText += ';float:' + (img.style.cssFloat || img.style.styleFloat ||'none') + ';display:' + (img.style.display||'inline');
  20826. img = null;
  20827. }else{
  20828. if(!img){
  20829. var collapsed = range.collapsed;
  20830. if(collapsed){
  20831. var text = me.document.createTextNode('match');
  20832. range.insertNode(text).select();
  20833. }
  20834. me.__hasEnterExecCommand = true;
  20835. //不能把block上的属性干掉
  20836. //trace:1553
  20837. var removeFormatAttributes = me.options.removeFormatAttributes;
  20838. me.options.removeFormatAttributes = '';
  20839. me.execCommand('removeformat');
  20840. me.options.removeFormatAttributes = removeFormatAttributes;
  20841. me.__hasEnterExecCommand = false;
  20842. //trace:969
  20843. range = me.selection.getRange();
  20844. if(list.length){
  20845. addFormat(range);
  20846. }
  20847. if(text){
  20848. range.setStartBefore(text).collapse(true);
  20849. }
  20850. range.select();
  20851. text && domUtils.remove(text);
  20852. }
  20853. }
  20854. me.undoManger && me.undoManger.save();
  20855. me.removeListener('mouseup',addList);
  20856. flag = 0;
  20857. }
  20858. me.commands['formatmatch'] = {
  20859. execCommand : function( cmdName ) {
  20860. if(flag){
  20861. flag = 0;
  20862. list = [];
  20863. me.removeListener('mouseup',addList);
  20864. return;
  20865. }
  20866. var range = me.selection.getRange();
  20867. img = range.getClosedNode();
  20868. if(!img || img.tagName != 'IMG'){
  20869. range.collapse(true).shrinkBoundary();
  20870. var start = range.startContainer;
  20871. list = domUtils.findParents(start,true,function(node){
  20872. return !domUtils.isBlockElm(node) && node.nodeType == 1;
  20873. });
  20874. //a不能加入格式刷, 并且克隆节点
  20875. for(var i=0,ci;ci=list[i];i++){
  20876. if(ci.tagName == 'A'){
  20877. list.splice(i,1);
  20878. break;
  20879. }
  20880. }
  20881. }
  20882. me.addListener('mouseup',addList);
  20883. flag = 1;
  20884. },
  20885. queryCommandState : function() {
  20886. return flag;
  20887. },
  20888. notNeedUndo : 1
  20889. };
  20890. };
  20891. // plugins/searchreplace.js
  20892. ///import core
  20893. ///commands 查找替换
  20894. ///commandsName SearchReplace
  20895. ///commandsTitle 查询替换
  20896. ///commandsDialog dialogs\searchreplace
  20897. /**
  20898. * @description 查找替换
  20899. * @author zhanyi
  20900. */
  20901. UE.plugin.register('searchreplace',function(){
  20902. var me = this;
  20903. var _blockElm = {'table':1,'tbody':1,'tr':1,'ol':1,'ul':1};
  20904. function findTextInString(textContent,opt,currentIndex){
  20905. var str = opt.searchStr;
  20906. if(opt.dir == -1){
  20907. textContent = textContent.split('').reverse().join('');
  20908. str = str.split('').reverse().join('');
  20909. currentIndex = textContent.length - currentIndex;
  20910. }
  20911. var reg = new RegExp(str,'g' + (opt.casesensitive ? '' : 'i')),match;
  20912. while(match = reg.exec(textContent)){
  20913. if(match.index >= currentIndex){
  20914. return opt.dir == -1 ? textContent.length - match.index - opt.searchStr.length : match.index;
  20915. }
  20916. }
  20917. return -1
  20918. }
  20919. function findTextBlockElm(node,currentIndex,opt){
  20920. var textContent,index,methodName = opt.all || opt.dir == 1 ? 'getNextDomNode' : 'getPreDomNode';
  20921. if(domUtils.isBody(node)){
  20922. node = node.firstChild;
  20923. }
  20924. var first = 1;
  20925. while(node){
  20926. textContent = node.nodeType == 3 ? node.nodeValue : node[browser.ie ? 'innerText' : 'textContent'];
  20927. index = findTextInString(textContent,opt,currentIndex );
  20928. first = 0;
  20929. if(index!=-1){
  20930. return {
  20931. 'node':node,
  20932. 'index':index
  20933. }
  20934. }
  20935. node = domUtils[methodName](node);
  20936. while(node && _blockElm[node.nodeName.toLowerCase()]){
  20937. node = domUtils[methodName](node,true);
  20938. }
  20939. if(node){
  20940. currentIndex = opt.dir == -1 ? (node.nodeType == 3 ? node.nodeValue : node[browser.ie ? 'innerText' : 'textContent']).length : 0;
  20941. }
  20942. }
  20943. }
  20944. function findNTextInBlockElm(node,index,str){
  20945. var currentIndex = 0,
  20946. currentNode = node.firstChild,
  20947. currentNodeLength = 0,
  20948. result;
  20949. while(currentNode){
  20950. if(currentNode.nodeType == 3){
  20951. currentNodeLength = currentNode.nodeValue.replace(/(^[\t\r\n]+)|([\t\r\n]+$)/,'').length;
  20952. currentIndex += currentNodeLength;
  20953. if(currentIndex >= index){
  20954. return {
  20955. 'node':currentNode,
  20956. 'index': currentNodeLength - (currentIndex - index)
  20957. }
  20958. }
  20959. }else if(!dtd.$empty[currentNode.tagName]){
  20960. currentNodeLength = currentNode[browser.ie ? 'innerText' : 'textContent'].replace(/(^[\t\r\n]+)|([\t\r\n]+$)/,'').length
  20961. currentIndex += currentNodeLength;
  20962. if(currentIndex >= index){
  20963. result = findNTextInBlockElm(currentNode,currentNodeLength - (currentIndex - index),str);
  20964. if(result){
  20965. return result;
  20966. }
  20967. }
  20968. }
  20969. currentNode = domUtils.getNextDomNode(currentNode);
  20970. }
  20971. }
  20972. function searchReplace(me,opt){
  20973. var rng = me.selection.getRange(),
  20974. startBlockNode,
  20975. searchStr = opt.searchStr,
  20976. span = me.document.createElement('span');
  20977. span.innerHTML = '$$ueditor_searchreplace_key$$';
  20978. rng.shrinkBoundary(true);
  20979. //判断是不是第一次选中
  20980. if(!rng.collapsed){
  20981. rng.select();
  20982. var rngText = me.selection.getText();
  20983. if(new RegExp('^' + opt.searchStr + '$',(opt.casesensitive ? '' : 'i')).test(rngText)){
  20984. if(opt.replaceStr != undefined){
  20985. replaceText(rng,opt.replaceStr);
  20986. rng.select();
  20987. return true;
  20988. }else{
  20989. rng.collapse(opt.dir == -1)
  20990. }
  20991. }
  20992. }
  20993. rng.insertNode(span);
  20994. rng.enlargeToBlockElm(true);
  20995. startBlockNode = rng.startContainer;
  20996. var currentIndex = startBlockNode[browser.ie ? 'innerText' : 'textContent'].indexOf('$$ueditor_searchreplace_key$$');
  20997. rng.setStartBefore(span);
  20998. domUtils.remove(span);
  20999. var result = findTextBlockElm(startBlockNode,currentIndex,opt);
  21000. if(result){
  21001. var rngStart = findNTextInBlockElm(result.node,result.index,searchStr);
  21002. var rngEnd = findNTextInBlockElm(result.node,result.index + searchStr.length,searchStr);
  21003. rng.setStart(rngStart.node,rngStart.index).setEnd(rngEnd.node,rngEnd.index);
  21004. if(opt.replaceStr !== undefined){
  21005. replaceText(rng,opt.replaceStr)
  21006. }
  21007. rng.select();
  21008. return true;
  21009. }else{
  21010. rng.setCursor()
  21011. }
  21012. }
  21013. function replaceText(rng,str){
  21014. str = me.document.createTextNode(str);
  21015. rng.deleteContents().insertNode(str);
  21016. }
  21017. return {
  21018. commands:{
  21019. 'searchreplace':{
  21020. execCommand:function(cmdName,opt){
  21021. utils.extend(opt,{
  21022. all : false,
  21023. casesensitive : false,
  21024. dir : 1
  21025. },true);
  21026. var num = 0;
  21027. if(opt.all){
  21028. var rng = me.selection.getRange(),
  21029. first = me.body.firstChild;
  21030. if(first && first.nodeType == 1){
  21031. rng.setStart(first,0);
  21032. rng.shrinkBoundary(true);
  21033. }else if(first.nodeType == 3){
  21034. rng.setStartBefore(first)
  21035. }
  21036. rng.collapse(true).select(true);
  21037. if(opt.replaceStr !== undefined){
  21038. me.fireEvent('saveScene');
  21039. }
  21040. while(searchReplace(this,opt)){
  21041. num++;
  21042. }
  21043. if(num){
  21044. me.fireEvent('saveScene');
  21045. }
  21046. }else{
  21047. if(opt.replaceStr !== undefined){
  21048. me.fireEvent('saveScene');
  21049. }
  21050. if(searchReplace(this,opt)){
  21051. num++
  21052. }
  21053. if(num){
  21054. me.fireEvent('saveScene');
  21055. }
  21056. }
  21057. return num;
  21058. },
  21059. notNeedUndo:1
  21060. }
  21061. }
  21062. }
  21063. });
  21064. // plugins/customstyle.js
  21065. /**
  21066. * 自定义样式
  21067. * @file
  21068. * @since 1.2.6.1
  21069. */
  21070. /**
  21071. * 根据config配置文件里“customstyle”选项的值对匹配的标签执行样式替换。
  21072. * @command customstyle
  21073. * @method execCommand
  21074. * @param { String } cmd 命令字符串
  21075. * @example
  21076. * ```javascript
  21077. * editor.execCommand( 'customstyle' );
  21078. * ```
  21079. */
  21080. UE.plugins['customstyle'] = function() {
  21081. var me = this;
  21082. me.setOpt({ 'customstyle':[
  21083. {tag:'h1',name:'tc', style:'font-size:32px;font-weight:bold;border-bottom:#ccc 2px solid;padding:0 4px 0 0;text-align:center;margin:0 0 20px 0;'},
  21084. {tag:'h1',name:'tl', style:'font-size:32px;font-weight:bold;border-bottom:#ccc 2px solid;padding:0 4px 0 0;text-align:left;margin:0 0 10px 0;'},
  21085. {tag:'span',name:'im', style:'font-size:16px;font-style:italic;font-weight:bold;line-height:18px;'},
  21086. {tag:'span',name:'hi', style:'font-size:16px;font-style:italic;font-weight:bold;color:rgb(51, 153, 204);line-height:18px;'}
  21087. ]});
  21088. me.commands['customstyle'] = {
  21089. execCommand : function(cmdName, obj) {
  21090. var me = this,
  21091. tagName = obj.tag,
  21092. node = domUtils.findParent(me.selection.getStart(), function(node) {
  21093. return node.getAttribute('label');
  21094. }, true),
  21095. range,bk,tmpObj = {};
  21096. for (var p in obj) {
  21097. if(obj[p]!==undefined)
  21098. tmpObj[p] = obj[p];
  21099. }
  21100. delete tmpObj.tag;
  21101. if (node && node.getAttribute('label') == obj.label) {
  21102. range = this.selection.getRange();
  21103. bk = range.createBookmark();
  21104. if (range.collapsed) {
  21105. //trace:1732 删掉自定义标签,要有p来回填站位
  21106. if(dtd.$block[node.tagName]){
  21107. var fillNode = me.document.createElement('p');
  21108. domUtils.moveChild(node, fillNode);
  21109. node.parentNode.insertBefore(fillNode, node);
  21110. domUtils.remove(node);
  21111. }else{
  21112. domUtils.remove(node,true);
  21113. }
  21114. } else {
  21115. var common = domUtils.getCommonAncestor(bk.start, bk.end),
  21116. nodes = domUtils.getElementsByTagName(common, tagName);
  21117. if(new RegExp(tagName,'i').test(common.tagName)){
  21118. nodes.push(common);
  21119. }
  21120. for (var i = 0,ni; ni = nodes[i++];) {
  21121. if (ni.getAttribute('label') == obj.label) {
  21122. var ps = domUtils.getPosition(ni, bk.start),pe = domUtils.getPosition(ni, bk.end);
  21123. if ((ps & domUtils.POSITION_FOLLOWING || ps & domUtils.POSITION_CONTAINS)
  21124. &&
  21125. (pe & domUtils.POSITION_PRECEDING || pe & domUtils.POSITION_CONTAINS)
  21126. )
  21127. if (dtd.$block[tagName]) {
  21128. var fillNode = me.document.createElement('p');
  21129. domUtils.moveChild(ni, fillNode);
  21130. ni.parentNode.insertBefore(fillNode, ni);
  21131. }
  21132. domUtils.remove(ni, true);
  21133. }
  21134. }
  21135. node = domUtils.findParent(common, function(node) {
  21136. return node.getAttribute('label') == obj.label;
  21137. }, true);
  21138. if (node) {
  21139. domUtils.remove(node, true);
  21140. }
  21141. }
  21142. range.moveToBookmark(bk).select();
  21143. } else {
  21144. if (dtd.$block[tagName]) {
  21145. this.execCommand('paragraph', tagName, tmpObj,'customstyle');
  21146. range = me.selection.getRange();
  21147. if (!range.collapsed) {
  21148. range.collapse();
  21149. node = domUtils.findParent(me.selection.getStart(), function(node) {
  21150. return node.getAttribute('label') == obj.label;
  21151. }, true);
  21152. var pNode = me.document.createElement('p');
  21153. domUtils.insertAfter(node, pNode);
  21154. domUtils.fillNode(me.document, pNode);
  21155. range.setStart(pNode, 0).setCursor();
  21156. }
  21157. } else {
  21158. range = me.selection.getRange();
  21159. if (range.collapsed) {
  21160. node = me.document.createElement(tagName);
  21161. domUtils.setAttributes(node, tmpObj);
  21162. range.insertNode(node).setStart(node, 0).setCursor();
  21163. return;
  21164. }
  21165. bk = range.createBookmark();
  21166. range.applyInlineStyle(tagName, tmpObj).moveToBookmark(bk).select();
  21167. }
  21168. }
  21169. },
  21170. queryCommandValue : function() {
  21171. var parent = domUtils.filterNodeList(
  21172. this.selection.getStartElementPath(),
  21173. function(node){return node.getAttribute('label')}
  21174. );
  21175. return parent ? parent.getAttribute('label') : '';
  21176. }
  21177. };
  21178. //当去掉customstyle是,如果是块元素,用p代替
  21179. me.addListener('keyup', function(type, evt) {
  21180. var keyCode = evt.keyCode || evt.which;
  21181. if (keyCode == 32 || keyCode == 13) {
  21182. var range = me.selection.getRange();
  21183. if (range.collapsed) {
  21184. var node = domUtils.findParent(me.selection.getStart(), function(node) {
  21185. return node.getAttribute('label');
  21186. }, true);
  21187. if (node && dtd.$block[node.tagName] && domUtils.isEmptyNode(node)) {
  21188. var p = me.document.createElement('p');
  21189. domUtils.insertAfter(node, p);
  21190. domUtils.fillNode(me.document, p);
  21191. domUtils.remove(node);
  21192. range.setStart(p, 0).setCursor();
  21193. }
  21194. }
  21195. }
  21196. });
  21197. };
  21198. // plugins/catchremoteimage.js
  21199. ///import core
  21200. ///commands 远程图片抓取
  21201. ///commandsName catchRemoteImage,catchremoteimageenable
  21202. ///commandsTitle 远程图片抓取
  21203. /**
  21204. * 远程图片抓取,当开启本插件时所有不符合本地域名的图片都将被抓取成为本地服务器上的图片
  21205. */
  21206. UE.plugins['catchremoteimage'] = function () {
  21207. var me = this,
  21208. ajax = UE.ajax;
  21209. /* 设置默认值 */
  21210. if (me.options.catchRemoteImageEnable === false) return;
  21211. me.setOpt({
  21212. catchRemoteImageEnable: false
  21213. });
  21214. me.addListener("afterpaste", function () {
  21215. me.fireEvent("catchRemoteImage");
  21216. });
  21217. me.addListener("catchRemoteImage", function () {
  21218. var catcherLocalDomain = me.getOpt('catcherLocalDomain'),
  21219. catcherActionUrl = me.getActionUrl(me.getOpt('catcherActionName')),
  21220. catcherUrlPrefix = me.getOpt('catcherUrlPrefix'),
  21221. catcherFieldName = me.getOpt('catcherFieldName');
  21222. var remoteImages = [],
  21223. imgs = domUtils.getElementsByTagName(me.document, "img"),
  21224. test = function (src, urls) {
  21225. if (src.indexOf(location.host) != -1 || /(^\.)|(^\/)/.test(src)) {
  21226. return true;
  21227. }
  21228. if (urls) {
  21229. for (var j = 0, url; url = urls[j++];) {
  21230. if (src.indexOf(url) !== -1) {
  21231. return true;
  21232. }
  21233. }
  21234. }
  21235. return false;
  21236. };
  21237. for (var i = 0, ci; ci = imgs[i++];) {
  21238. if (ci.getAttribute("word_img")) {
  21239. continue;
  21240. }
  21241. var src = ci.getAttribute("_src") || ci.src || "";
  21242. if (/^(https?|ftp):/i.test(src) && !test(src, catcherLocalDomain)) {
  21243. remoteImages.push(src);
  21244. }
  21245. }
  21246. if (remoteImages.length) {
  21247. catchremoteimage(remoteImages, {
  21248. //成功抓取
  21249. success: function (r) {
  21250. try {
  21251. var info = r.state !== undefined ? r:eval("(" + r.responseText + ")");
  21252. } catch (e) {
  21253. return;
  21254. }
  21255. /* 获取源路径和新路径 */
  21256. var i, j, ci, cj, oldSrc, newSrc, list = info.list;
  21257. for (i = 0; ci = imgs[i++];) {
  21258. oldSrc = ci.getAttribute("_src") || ci.src || "";
  21259. for (j = 0; cj = list[j++];) {
  21260. if (oldSrc == cj.source && cj.state == "SUCCESS") { //抓取失败时不做替换处理
  21261. newSrc = catcherUrlPrefix + cj.url;
  21262. domUtils.setAttributes(ci, {
  21263. "src": newSrc,
  21264. "_src": newSrc
  21265. });
  21266. break;
  21267. }
  21268. }
  21269. }
  21270. me.fireEvent('catchremotesuccess')
  21271. },
  21272. //回调失败,本次请求超时
  21273. error: function () {
  21274. me.fireEvent("catchremoteerror");
  21275. }
  21276. });
  21277. }
  21278. function catchremoteimage(imgs, callbacks) {
  21279. var params = utils.serializeParam(me.queryCommandValue('serverparam')) || '',
  21280. url = utils.formatUrl(catcherActionUrl + (catcherActionUrl.indexOf('?') == -1 ? '?':'&') + params),
  21281. isJsonp = utils.isCrossDomainUrl(url),
  21282. opt = {
  21283. 'method': 'POST',
  21284. 'dataType': isJsonp ? 'jsonp':'',
  21285. 'timeout': 60000, //单位:毫秒,回调请求超时设置。目标用户如果网速不是很快的话此处建议设置一个较大的数值
  21286. 'onsuccess': callbacks["success"],
  21287. 'onerror': callbacks["error"]
  21288. };
  21289. opt[catcherFieldName] = imgs;
  21290. ajax.request(url, opt);
  21291. }
  21292. });
  21293. };
  21294. // plugins/snapscreen.js
  21295. /**
  21296. * 截屏插件,为UEditor提供插入支持
  21297. * @file
  21298. * @since 1.4.2
  21299. */
  21300. UE.plugin.register('snapscreen', function (){
  21301. var me = this;
  21302. var snapplugin;
  21303. function getLocation(url){
  21304. var search,
  21305. a = document.createElement('a'),
  21306. params = utils.serializeParam(me.queryCommandValue('serverparam')) || '';
  21307. a.href = url;
  21308. if (browser.ie) {
  21309. a.href = a.href;
  21310. }
  21311. search = a.search;
  21312. if (params) {
  21313. search = search + (search.indexOf('?') == -1 ? '?':'&')+ params;
  21314. search = search.replace(/[&]+/ig, '&');
  21315. }
  21316. return {
  21317. 'port': a.port,
  21318. 'hostname': a.hostname,
  21319. 'path': a.pathname + search || + a.hash
  21320. }
  21321. }
  21322. return {
  21323. commands:{
  21324. /**
  21325. * 字体背景颜色
  21326. * @command snapscreen
  21327. * @method execCommand
  21328. * @param { String } cmd 命令字符串
  21329. * @example
  21330. * ```javascript
  21331. * editor.execCommand('snapscreen');
  21332. * ```
  21333. */
  21334. 'snapscreen':{
  21335. execCommand:function (cmd) {
  21336. var url, local, res;
  21337. var lang = me.getLang("snapScreen_plugin");
  21338. if(!snapplugin){
  21339. var container = me.container;
  21340. var doc = me.container.ownerDocument || me.container.document;
  21341. snapplugin = doc.createElement("object");
  21342. try{snapplugin.type = "application/x-pluginbaidusnap";}catch(e){
  21343. return;
  21344. }
  21345. snapplugin.style.cssText = "position:absolute;left:-9999px;width:0;height:0;";
  21346. snapplugin.setAttribute("width","0");
  21347. snapplugin.setAttribute("height","0");
  21348. container.appendChild(snapplugin);
  21349. }
  21350. function onSuccess(rs){
  21351. try{
  21352. rs = eval("("+ rs +")");
  21353. if(rs.state == 'SUCCESS'){
  21354. var opt = me.options;
  21355. me.execCommand('insertimage', {
  21356. src: opt.snapscreenUrlPrefix + rs.url,
  21357. _src: opt.snapscreenUrlPrefix + rs.url,
  21358. alt: rs.title || '',
  21359. floatStyle: opt.snapscreenImgAlign
  21360. });
  21361. } else {
  21362. alert(rs.state);
  21363. }
  21364. }catch(e){
  21365. alert(lang.callBackErrorMsg);
  21366. }
  21367. }
  21368. url = me.getActionUrl(me.getOpt('snapscreenActionName'));
  21369. local = getLocation(url);
  21370. setTimeout(function () {
  21371. try{
  21372. res =snapplugin.saveSnapshot(local.hostname, local.path, local.port);
  21373. }catch(e){
  21374. me.ui._dialogs['snapscreenDialog'].open();
  21375. return;
  21376. }
  21377. onSuccess(res);
  21378. }, 50);
  21379. },
  21380. queryCommandState: function(){
  21381. return (navigator.userAgent.indexOf("Windows",0) != -1) ? 0:-1;
  21382. }
  21383. }
  21384. }
  21385. }
  21386. });
  21387. // plugins/insertparagraph.js
  21388. /**
  21389. * 插入段落
  21390. * @file
  21391. * @since 1.2.6.1
  21392. */
  21393. /**
  21394. * 插入段落
  21395. * @command insertparagraph
  21396. * @method execCommand
  21397. * @param { String } cmd 命令字符串
  21398. * @example
  21399. * ```javascript
  21400. * //editor是编辑器实例
  21401. * editor.execCommand( 'insertparagraph' );
  21402. * ```
  21403. */
  21404. UE.commands['insertparagraph'] = {
  21405. execCommand : function( cmdName,front) {
  21406. var me = this,
  21407. range = me.selection.getRange(),
  21408. start = range.startContainer,tmpNode;
  21409. while(start ){
  21410. if(domUtils.isBody(start)){
  21411. break;
  21412. }
  21413. tmpNode = start;
  21414. start = start.parentNode;
  21415. }
  21416. if(tmpNode){
  21417. var p = me.document.createElement('p');
  21418. if(front){
  21419. tmpNode.parentNode.insertBefore(p,tmpNode)
  21420. }else{
  21421. tmpNode.parentNode.insertBefore(p,tmpNode.nextSibling)
  21422. }
  21423. domUtils.fillNode(me.document,p);
  21424. range.setStart(p,0).setCursor(false,true);
  21425. }
  21426. }
  21427. };
  21428. // plugins/webapp.js
  21429. /**
  21430. * 百度应用
  21431. * @file
  21432. * @since 1.2.6.1
  21433. */
  21434. /**
  21435. * 插入百度应用
  21436. * @command webapp
  21437. * @method execCommand
  21438. * @remind 需要百度APPKey
  21439. * @remind 百度应用主页: <a href="http://app.baidu.com/" target="_blank">http://app.baidu.com/</a>
  21440. * @param { Object } appOptions 应用所需的参数项, 支持的key有: title=>应用标题, width=>应用容器宽度,
  21441. * height=>应用容器高度,logo=>应用logo,url=>应用地址
  21442. * @example
  21443. * ```javascript
  21444. * //editor是编辑器实例
  21445. * //在编辑器里插入一个“植物大战僵尸”的APP
  21446. * editor.execCommand( 'webapp' , {
  21447. * title: '植物大战僵尸',
  21448. * width: 560,
  21449. * height: 465,
  21450. * logo: '应用展示的图片',
  21451. * url: '百度应用的地址'
  21452. * } );
  21453. * ```
  21454. */
  21455. //UE.plugins['webapp'] = function () {
  21456. // var me = this;
  21457. // function createInsertStr( obj, toIframe, addParagraph ) {
  21458. // return !toIframe ?
  21459. // (addParagraph ? '<p>' : '') + '<img title="'+obj.title+'" width="' + obj.width + '" height="' + obj.height + '"' +
  21460. // ' src="' + me.options.UEDITOR_HOME_URL + 'themes/default/images/spacer.gif" style="background:url(' + obj.logo+') no-repeat center center; border:1px solid gray;" class="edui-faked-webapp" _url="' + obj.url + '" />' +
  21461. // (addParagraph ? '</p>' : '')
  21462. // :
  21463. // '<iframe class="edui-faked-webapp" title="'+obj.title+'" width="' + obj.width + '" height="' + obj.height + '" scrolling="no" frameborder="0" src="' + obj.url + '" logo_url = '+obj.logo+'></iframe>';
  21464. // }
  21465. //
  21466. // function switchImgAndIframe( img2frame ) {
  21467. // var tmpdiv,
  21468. // nodes = domUtils.getElementsByTagName( me.document, !img2frame ? "iframe" : "img" );
  21469. // for ( var i = 0, node; node = nodes[i++]; ) {
  21470. // if ( node.className != "edui-faked-webapp" ){
  21471. // continue;
  21472. // }
  21473. // tmpdiv = me.document.createElement( "div" );
  21474. // tmpdiv.innerHTML = createInsertStr( img2frame ? {url:node.getAttribute( "_url" ), width:node.width, height:node.height,title:node.title,logo:node.style.backgroundImage.replace("url(","").replace(")","")} : {url:node.getAttribute( "src", 2 ),title:node.title, width:node.width, height:node.height,logo:node.getAttribute("logo_url")}, img2frame ? true : false,false );
  21475. // node.parentNode.replaceChild( tmpdiv.firstChild, node );
  21476. // }
  21477. // }
  21478. //
  21479. // me.addListener( "beforegetcontent", function () {
  21480. // switchImgAndIframe( true );
  21481. // } );
  21482. // me.addListener( 'aftersetcontent', function () {
  21483. // switchImgAndIframe( false );
  21484. // } );
  21485. // me.addListener( 'aftergetcontent', function ( cmdName ) {
  21486. // if ( cmdName == 'aftergetcontent' && me.queryCommandState( 'source' ) ){
  21487. // return;
  21488. // }
  21489. // switchImgAndIframe( false );
  21490. // } );
  21491. //
  21492. // me.commands['webapp'] = {
  21493. // execCommand:function ( cmd, obj ) {
  21494. // me.execCommand( "inserthtml", createInsertStr( obj, false,true ) );
  21495. // }
  21496. // };
  21497. //};
  21498. UE.plugin.register('webapp', function (){
  21499. var me = this;
  21500. function createInsertStr(obj,toEmbed){
  21501. return !toEmbed ?
  21502. '<img title="'+obj.title+'" width="' + obj.width + '" height="' + obj.height + '"' +
  21503. ' src="' + me.options.UEDITOR_HOME_URL + 'themes/default/images/spacer.gif" _logo_url="'+obj.logo+'" style="background:url(' + obj.logo
  21504. +') no-repeat center center; border:1px solid gray;" class="edui-faked-webapp" _url="' + obj.url + '" ' +
  21505. (obj.align && !obj.cssfloat? 'align="' + obj.align + '"' : '') +
  21506. (obj.cssfloat ? 'style="float:' + obj.cssfloat + '"' : '') +
  21507. '/>'
  21508. :
  21509. '<iframe class="edui-faked-webapp" title="'+obj.title+'" ' +
  21510. (obj.align && !obj.cssfloat? 'align="' + obj.align + '"' : '') +
  21511. (obj.cssfloat ? 'style="float:' + obj.cssfloat + '"' : '') +
  21512. 'width="' + obj.width + '" height="' + obj.height + '" scrolling="no" frameborder="0" src="' + obj.url + '" logo_url = "'+obj.logo+'"></iframe>'
  21513. }
  21514. return {
  21515. outputRule: function(root){
  21516. utils.each(root.getNodesByTagName('img'),function(node){
  21517. var html;
  21518. if(node.getAttr('class') == 'edui-faked-webapp'){
  21519. html = createInsertStr({
  21520. title:node.getAttr('title'),
  21521. 'width':node.getAttr('width'),
  21522. 'height':node.getAttr('height'),
  21523. 'align':node.getAttr('align'),
  21524. 'cssfloat':node.getStyle('float'),
  21525. 'url':node.getAttr("_url"),
  21526. 'logo':node.getAttr('_logo_url')
  21527. },true);
  21528. var embed = UE.uNode.createElement(html);
  21529. node.parentNode.replaceChild(embed,node);
  21530. }
  21531. })
  21532. },
  21533. inputRule:function(root){
  21534. utils.each(root.getNodesByTagName('iframe'),function(node){
  21535. if(node.getAttr('class') == 'edui-faked-webapp'){
  21536. var img = UE.uNode.createElement(createInsertStr({
  21537. title:node.getAttr('title'),
  21538. 'width':node.getAttr('width'),
  21539. 'height':node.getAttr('height'),
  21540. 'align':node.getAttr('align'),
  21541. 'cssfloat':node.getStyle('float'),
  21542. 'url':node.getAttr("src"),
  21543. 'logo':node.getAttr('logo_url')
  21544. }));
  21545. node.parentNode.replaceChild(img,node);
  21546. }
  21547. })
  21548. },
  21549. commands:{
  21550. /**
  21551. * 插入百度应用
  21552. * @command webapp
  21553. * @method execCommand
  21554. * @remind 需要百度APPKey
  21555. * @remind 百度应用主页: <a href="http://app.baidu.com/" target="_blank">http://app.baidu.com/</a>
  21556. * @param { Object } appOptions 应用所需的参数项, 支持的key有: title=>应用标题, width=>应用容器宽度,
  21557. * height=>应用容器高度,logo=>应用logo,url=>应用地址
  21558. * @example
  21559. * ```javascript
  21560. * //editor是编辑器实例
  21561. * //在编辑器里插入一个“植物大战僵尸”的APP
  21562. * editor.execCommand( 'webapp' , {
  21563. * title: '植物大战僵尸',
  21564. * width: 560,
  21565. * height: 465,
  21566. * logo: '应用展示的图片',
  21567. * url: '百度应用的地址'
  21568. * } );
  21569. * ```
  21570. */
  21571. 'webapp':{
  21572. execCommand:function (cmd, obj) {
  21573. var me = this,
  21574. str = createInsertStr(utils.extend(obj,{
  21575. align:'none'
  21576. }), false);
  21577. me.execCommand("inserthtml",str);
  21578. },
  21579. queryCommandState:function () {
  21580. var me = this,
  21581. img = me.selection.getRange().getClosedNode(),
  21582. flag = img && (img.className == "edui-faked-webapp");
  21583. return flag ? 1 : 0;
  21584. }
  21585. }
  21586. }
  21587. }
  21588. });
  21589. // plugins/template.js
  21590. ///import core
  21591. ///import plugins\inserthtml.js
  21592. ///import plugins\cleardoc.js
  21593. ///commands 模板
  21594. ///commandsName template
  21595. ///commandsTitle 模板
  21596. ///commandsDialog dialogs\template
  21597. UE.plugins['template'] = function () {
  21598. UE.commands['template'] = {
  21599. execCommand:function (cmd, obj) {
  21600. obj.html && this.execCommand("inserthtml", obj.html);
  21601. }
  21602. };
  21603. this.addListener("click", function (type, evt) {
  21604. var el = evt.target || evt.srcElement,
  21605. range = this.selection.getRange();
  21606. var tnode = domUtils.findParent(el, function (node) {
  21607. if (node.className && domUtils.hasClass(node, "ue_t")) {
  21608. return node;
  21609. }
  21610. }, true);
  21611. tnode && range.selectNode(tnode).shrinkBoundary().select();
  21612. });
  21613. this.addListener("keydown", function (type, evt) {
  21614. var range = this.selection.getRange();
  21615. if (!range.collapsed) {
  21616. if (!evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey) {
  21617. var tnode = domUtils.findParent(range.startContainer, function (node) {
  21618. if (node.className && domUtils.hasClass(node, "ue_t")) {
  21619. return node;
  21620. }
  21621. }, true);
  21622. if (tnode) {
  21623. domUtils.removeClasses(tnode, ["ue_t"]);
  21624. }
  21625. }
  21626. }
  21627. });
  21628. };
  21629. // plugins/music.js
  21630. /**
  21631. * 插入音乐命令
  21632. * @file
  21633. */
  21634. UE.plugin.register('music', function (){
  21635. var me = this;
  21636. function creatInsertStr(url,width,height,align,cssfloat,toEmbed){
  21637. return !toEmbed ?
  21638. '<img ' +
  21639. (align && !cssfloat? 'align="' + align + '"' : '') +
  21640. (cssfloat ? 'style="float:' + cssfloat + '"' : '') +
  21641. ' width="'+ width +'" height="' + height + '" _url="'+url+'" class="edui-faked-music"' +
  21642. ' src="'+me.options.langPath+me.options.lang+'/images/music.png" />'
  21643. :
  21644. '<embed type="application/x-shockwave-flash" class="edui-faked-music" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
  21645. ' src="' + url + '" width="' + width + '" height="' + height + '" '+ (align && !cssfloat? 'align="' + align + '"' : '') +
  21646. (cssfloat ? 'style="float:' + cssfloat + '"' : '') +
  21647. ' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >';
  21648. }
  21649. return {
  21650. outputRule: function(root){
  21651. utils.each(root.getNodesByTagName('img'),function(node){
  21652. var html;
  21653. if(node.getAttr('class') == 'edui-faked-music'){
  21654. var cssfloat = node.getStyle('float');
  21655. var align = node.getAttr('align');
  21656. html = creatInsertStr(node.getAttr("_url"), node.getAttr('width'), node.getAttr('height'), align, cssfloat, true);
  21657. var embed = UE.uNode.createElement(html);
  21658. node.parentNode.replaceChild(embed,node);
  21659. }
  21660. })
  21661. },
  21662. inputRule:function(root){
  21663. utils.each(root.getNodesByTagName('embed'),function(node){
  21664. if(node.getAttr('class') == 'edui-faked-music'){
  21665. var cssfloat = node.getStyle('float');
  21666. var align = node.getAttr('align');
  21667. html = creatInsertStr(node.getAttr("src"), node.getAttr('width'), node.getAttr('height'), align, cssfloat,false);
  21668. var img = UE.uNode.createElement(html);
  21669. node.parentNode.replaceChild(img,node);
  21670. }
  21671. })
  21672. },
  21673. commands:{
  21674. /**
  21675. * 插入音乐
  21676. * @command music
  21677. * @method execCommand
  21678. * @param { Object } musicOptions 插入音乐的参数项, 支持的key有: url=>音乐地址;
  21679. * width=>音乐容器宽度;height=>音乐容器高度;align=>音乐文件的对齐方式, 可选值有: left, center, right, none
  21680. * @example
  21681. * ```javascript
  21682. * //editor是编辑器实例
  21683. * //在编辑器里插入一个“植物大战僵尸”的APP
  21684. * editor.execCommand( 'music' , {
  21685. * width: 400,
  21686. * height: 95,
  21687. * align: "center",
  21688. * url: "音乐地址"
  21689. * } );
  21690. * ```
  21691. */
  21692. 'music':{
  21693. execCommand:function (cmd, musicObj) {
  21694. var me = this,
  21695. str = creatInsertStr(musicObj.url, musicObj.width || 400, musicObj.height || 95, "none", false);
  21696. me.execCommand("inserthtml",str);
  21697. },
  21698. queryCommandState:function () {
  21699. var me = this,
  21700. img = me.selection.getRange().getClosedNode(),
  21701. flag = img && (img.className == "edui-faked-music");
  21702. return flag ? 1 : 0;
  21703. }
  21704. }
  21705. }
  21706. }
  21707. });
  21708. // plugins/autoupload.js
  21709. /**
  21710. * @description
  21711. * 1.拖放文件到编辑区域,自动上传并插入到选区
  21712. * 2.插入粘贴板的图片,自动上传并插入到选区
  21713. * @author Jinqn
  21714. * @date 2013-10-14
  21715. */
  21716. UE.plugin.register('autoupload', function (){
  21717. function sendAndInsertFile(file, editor) {
  21718. var me = editor;
  21719. //模拟数据
  21720. var fieldName, urlPrefix, maxSize, allowFiles, actionUrl,
  21721. loadingHtml, errorHandler, successHandler,
  21722. filetype = /image\/\w+/i.test(file.type) ? 'image':'file',
  21723. loadingId = 'loading_' + (+new Date()).toString(36);
  21724. fieldName = me.getOpt(filetype + 'FieldName');
  21725. urlPrefix = me.getOpt(filetype + 'UrlPrefix');
  21726. maxSize = me.getOpt(filetype + 'MaxSize');
  21727. allowFiles = me.getOpt(filetype + 'AllowFiles');
  21728. actionUrl = me.getActionUrl(me.getOpt(filetype + 'ActionName'));
  21729. errorHandler = function(title) {
  21730. var loader = me.document.getElementById(loadingId);
  21731. loader && domUtils.remove(loader);
  21732. me.fireEvent('showmessage', {
  21733. 'id': loadingId,
  21734. 'content': title,
  21735. 'type': 'error',
  21736. 'timeout': 4000
  21737. });
  21738. };
  21739. if (filetype == 'image') {
  21740. loadingHtml = '<img class="loadingclass" id="' + loadingId + '" src="' +
  21741. me.options.themePath + me.options.theme +
  21742. '/images/spacer.gif" title="' + (me.getLang('autoupload.loading') || '') + '" >';
  21743. successHandler = function(data) {
  21744. var link = urlPrefix + data.url,
  21745. loader = me.document.getElementById(loadingId);
  21746. if (loader) {
  21747. loader.setAttribute('src', link);
  21748. loader.setAttribute('_src', link);
  21749. loader.setAttribute('title', data.title || '');
  21750. loader.setAttribute('alt', data.original || '');
  21751. loader.removeAttribute('id');
  21752. domUtils.removeClasses(loader, 'loadingclass');
  21753. }
  21754. };
  21755. } else {
  21756. loadingHtml = '<p>' +
  21757. '<img class="loadingclass" id="' + loadingId + '" src="' +
  21758. me.options.themePath + me.options.theme +
  21759. '/images/spacer.gif" title="' + (me.getLang('autoupload.loading') || '') + '" >' +
  21760. '</p>';
  21761. successHandler = function(data) {
  21762. var link = urlPrefix + data.url,
  21763. loader = me.document.getElementById(loadingId);
  21764. var rng = me.selection.getRange(),
  21765. bk = rng.createBookmark();
  21766. rng.selectNode(loader).select();
  21767. me.execCommand('insertfile', {'url': link});
  21768. rng.moveToBookmark(bk).select();
  21769. };
  21770. }
  21771. /* 插入loading的占位符 */
  21772. me.execCommand('inserthtml', loadingHtml);
  21773. /* 判断后端配置是否没有加载成功 */
  21774. if (!me.getOpt(filetype + 'ActionName')) {
  21775. errorHandler(me.getLang('autoupload.errorLoadConfig'));
  21776. return;
  21777. }
  21778. /* 判断文件大小是否超出限制 */
  21779. if(file.size > maxSize) {
  21780. errorHandler(me.getLang('autoupload.exceedSizeError'));
  21781. return;
  21782. }
  21783. /* 判断文件格式是否超出允许 */
  21784. var fileext = file.name ? file.name.substr(file.name.lastIndexOf('.')):'';
  21785. if ((fileext && filetype != 'image') || (allowFiles && (allowFiles.join('') + '.').indexOf(fileext.toLowerCase() + '.') == -1)) {
  21786. errorHandler(me.getLang('autoupload.exceedTypeError'));
  21787. return;
  21788. }
  21789. /* 创建Ajax并提交 */
  21790. var xhr = new XMLHttpRequest(),
  21791. fd = new FormData(),
  21792. params = utils.serializeParam(me.queryCommandValue('serverparam')) || '',
  21793. url = utils.formatUrl(actionUrl + (actionUrl.indexOf('?') == -1 ? '?':'&') + params);
  21794. fd.append(fieldName, file, file.name || ('blob.' + file.type.substr('image/'.length)));
  21795. fd.append('type', 'ajax');
  21796. xhr.open("post", url, true);
  21797. xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
  21798. xhr.addEventListener('load', function (e) {
  21799. try{
  21800. var json = (new Function("return " + utils.trim(e.target.response)))();
  21801. if (json.state == 'SUCCESS' && json.url) {
  21802. successHandler(json);
  21803. } else {
  21804. errorHandler(json.state);
  21805. }
  21806. }catch(er){
  21807. errorHandler(me.getLang('autoupload.loadError'));
  21808. }
  21809. });
  21810. xhr.send(fd);
  21811. }
  21812. function getPasteImage(e){
  21813. return e.clipboardData && e.clipboardData.items && e.clipboardData.items.length == 1 && /^image\//.test(e.clipboardData.items[0].type) ? e.clipboardData.items:null;
  21814. }
  21815. function getDropImage(e){
  21816. return e.dataTransfer && e.dataTransfer.files ? e.dataTransfer.files:null;
  21817. }
  21818. return {
  21819. outputRule: function(root){
  21820. utils.each(root.getNodesByTagName('img'),function(n){
  21821. if (/\b(loaderrorclass)|(bloaderrorclass)\b/.test(n.getAttr('class'))) {
  21822. n.parentNode.removeChild(n);
  21823. }
  21824. });
  21825. utils.each(root.getNodesByTagName('p'),function(n){
  21826. if (/\bloadpara\b/.test(n.getAttr('class'))) {
  21827. n.parentNode.removeChild(n);
  21828. }
  21829. });
  21830. },
  21831. bindEvents:{
  21832. //插入粘贴板的图片,拖放插入图片
  21833. 'ready':function(e){
  21834. var me = this;
  21835. if(window.FormData && window.FileReader) {
  21836. domUtils.on(me.body, 'paste drop', function(e){
  21837. var hasImg = false,
  21838. items;
  21839. //获取粘贴板文件列表或者拖放文件列表
  21840. items = e.type == 'paste' ? getPasteImage(e):getDropImage(e);
  21841. if(items){
  21842. var len = items.length,
  21843. file;
  21844. while (len--){
  21845. file = items[len];
  21846. if(file.getAsFile) file = file.getAsFile();
  21847. if(file && file.size > 0) {
  21848. sendAndInsertFile(file, me);
  21849. hasImg = true;
  21850. }
  21851. }
  21852. hasImg && e.preventDefault();
  21853. }
  21854. });
  21855. //取消拖放图片时出现的文字光标位置提示
  21856. domUtils.on(me.body, 'dragover', function (e) {
  21857. if(e.dataTransfer.types[0] == 'Files') {
  21858. e.preventDefault();
  21859. }
  21860. });
  21861. //设置loading的样式
  21862. utils.cssRule('loading',
  21863. '.loadingclass{display:inline-block;cursor:default;background: url(\''
  21864. + this.options.themePath
  21865. + this.options.theme +'/images/loading.gif\') no-repeat center center transparent;border:1px solid #cccccc;margin-left:1px;height: 22px;width: 22px;}\n' +
  21866. '.loaderrorclass{display:inline-block;cursor:default;background: url(\''
  21867. + this.options.themePath
  21868. + this.options.theme +'/images/loaderror.png\') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;' +
  21869. '}',
  21870. this.document);
  21871. }
  21872. }
  21873. }
  21874. }
  21875. });
  21876. // plugins/autosave.js
  21877. UE.plugin.register('autosave', function (){
  21878. var me = this,
  21879. //无限循环保护
  21880. lastSaveTime = new Date(),
  21881. //最小保存间隔时间
  21882. MIN_TIME = 20,
  21883. //auto save key
  21884. saveKey = null;
  21885. function save ( editor ) {
  21886. var saveData;
  21887. if ( new Date() - lastSaveTime < MIN_TIME ) {
  21888. return;
  21889. }
  21890. if ( !editor.hasContents() ) {
  21891. //这里不能调用命令来删除, 会造成事件死循环
  21892. saveKey && me.removePreferences( saveKey );
  21893. return;
  21894. }
  21895. lastSaveTime = new Date();
  21896. editor._saveFlag = null;
  21897. saveData = me.body.innerHTML;
  21898. if ( editor.fireEvent( "beforeautosave", {
  21899. content: saveData
  21900. } ) === false ) {
  21901. return;
  21902. }
  21903. me.setPreferences( saveKey, saveData );
  21904. editor.fireEvent( "afterautosave", {
  21905. content: saveData
  21906. } );
  21907. }
  21908. return {
  21909. defaultOptions: {
  21910. //默认间隔时间
  21911. saveInterval: 500
  21912. },
  21913. bindEvents:{
  21914. 'ready':function(){
  21915. var _suffix = "-drafts-data",
  21916. key = null;
  21917. if ( me.key ) {
  21918. key = me.key + _suffix;
  21919. } else {
  21920. key = ( me.container.parentNode.id || 'ue-common' ) + _suffix;
  21921. }
  21922. //页面地址+编辑器ID 保持唯一
  21923. saveKey = ( location.protocol + location.host + location.pathname ).replace( /[.:\/]/g, '_' ) + key;
  21924. },
  21925. 'contentchange': function () {
  21926. if ( !saveKey ) {
  21927. return;
  21928. }
  21929. if ( me._saveFlag ) {
  21930. window.clearTimeout( me._saveFlag );
  21931. }
  21932. if ( me.options.saveInterval > 0 ) {
  21933. me._saveFlag = window.setTimeout( function () {
  21934. save( me );
  21935. }, me.options.saveInterval );
  21936. } else {
  21937. save(me);
  21938. }
  21939. }
  21940. },
  21941. commands:{
  21942. 'clearlocaldata':{
  21943. execCommand:function (cmd, name) {
  21944. if ( saveKey && me.getPreferences( saveKey ) ) {
  21945. me.removePreferences( saveKey )
  21946. }
  21947. },
  21948. notNeedUndo: true,
  21949. ignoreContentChange:true
  21950. },
  21951. 'getlocaldata':{
  21952. execCommand:function (cmd, name) {
  21953. return saveKey ? me.getPreferences( saveKey ) || '' : '';
  21954. },
  21955. notNeedUndo: true,
  21956. ignoreContentChange:true
  21957. },
  21958. 'drafts':{
  21959. execCommand:function (cmd, name) {
  21960. if ( saveKey ) {
  21961. me.body.innerHTML = me.getPreferences( saveKey ) || '<p>'+domUtils.fillHtml+'</p>';
  21962. me.focus(true);
  21963. }
  21964. },
  21965. queryCommandState: function () {
  21966. return saveKey ? ( me.getPreferences( saveKey ) === null ? -1 : 0 ) : -1;
  21967. },
  21968. notNeedUndo: true,
  21969. ignoreContentChange:true
  21970. }
  21971. }
  21972. }
  21973. });
  21974. // plugins/charts.js
  21975. UE.plugin.register('charts', function (){
  21976. var me = this;
  21977. return {
  21978. bindEvents: {
  21979. 'chartserror': function () {
  21980. }
  21981. },
  21982. commands:{
  21983. 'charts': {
  21984. execCommand: function ( cmd, data ) {
  21985. var tableNode = domUtils.findParentByTagName(this.selection.getRange().startContainer, 'table', true),
  21986. flagText = [],
  21987. config = {};
  21988. if ( !tableNode ) {
  21989. return false;
  21990. }
  21991. if ( !validData( tableNode ) ) {
  21992. me.fireEvent( "chartserror" );
  21993. return false;
  21994. }
  21995. config.title = data.title || '';
  21996. config.subTitle = data.subTitle || '';
  21997. config.xTitle = data.xTitle || '';
  21998. config.yTitle = data.yTitle || '';
  21999. config.suffix = data.suffix || '';
  22000. config.tip = data.tip || '';
  22001. //数据对齐方式
  22002. config.dataFormat = data.tableDataFormat || '';
  22003. //图表类型
  22004. config.chartType = data.chartType || 0;
  22005. for ( var key in config ) {
  22006. if ( !config.hasOwnProperty( key ) ) {
  22007. continue;
  22008. }
  22009. flagText.push( key+":"+config[ key ] );
  22010. }
  22011. tableNode.setAttribute( "data-chart", flagText.join( ";" ) );
  22012. domUtils.addClass( tableNode, "edui-charts-table" );
  22013. },
  22014. queryCommandState: function ( cmd, name ) {
  22015. var tableNode = domUtils.findParentByTagName(this.selection.getRange().startContainer, 'table', true);
  22016. return tableNode && validData( tableNode ) ? 0 : -1;
  22017. }
  22018. }
  22019. },
  22020. inputRule:function(root){
  22021. utils.each(root.getNodesByTagName('table'),function( tableNode ){
  22022. if ( tableNode.getAttr("data-chart") !== undefined ) {
  22023. tableNode.setAttr("style");
  22024. }
  22025. })
  22026. },
  22027. outputRule:function(root){
  22028. utils.each(root.getNodesByTagName('table'),function( tableNode ){
  22029. if ( tableNode.getAttr("data-chart") !== undefined ) {
  22030. tableNode.setAttr("style", "display: none;");
  22031. }
  22032. })
  22033. }
  22034. }
  22035. function validData ( table ) {
  22036. var firstRows = null,
  22037. cellCount = 0;
  22038. //行数不够
  22039. if ( table.rows.length < 2 ) {
  22040. return false;
  22041. }
  22042. //列数不够
  22043. if ( table.rows[0].cells.length < 2 ) {
  22044. return false;
  22045. }
  22046. //第一行所有cell必须是th
  22047. firstRows = table.rows[ 0 ].cells;
  22048. cellCount = firstRows.length;
  22049. for ( var i = 0, cell; cell = firstRows[ i ]; i++ ) {
  22050. if ( cell.tagName.toLowerCase() !== 'th' ) {
  22051. return false;
  22052. }
  22053. }
  22054. for ( var i = 1, row; row = table.rows[ i ]; i++ ) {
  22055. //每行单元格数不匹配, 返回false
  22056. if ( row.cells.length != cellCount ) {
  22057. return false;
  22058. }
  22059. //第一列不是th也返回false
  22060. if ( row.cells[0].tagName.toLowerCase() !== 'th' ) {
  22061. return false;
  22062. }
  22063. for ( var j = 1, cell; cell = row.cells[ j ]; j++ ) {
  22064. var value = utils.trim( ( cell.innerText || cell.textContent || '' ) );
  22065. value = value.replace( new RegExp( UE.dom.domUtils.fillChar, 'g' ), '' ).replace( /^\s+|\s+$/g, '' );
  22066. //必须是数字
  22067. if ( !/^\d*\.?\d+$/.test( value ) ) {
  22068. return false;
  22069. }
  22070. }
  22071. }
  22072. return true;
  22073. }
  22074. });
  22075. // plugins/section.js
  22076. /**
  22077. * 目录大纲支持插件
  22078. * @file
  22079. * @since 1.3.0
  22080. */
  22081. UE.plugin.register('section', function (){
  22082. /* 目录节点对象 */
  22083. function Section(option){
  22084. this.tag = '';
  22085. this.level = -1,
  22086. this.dom = null;
  22087. this.nextSection = null;
  22088. this.previousSection = null;
  22089. this.parentSection = null;
  22090. this.startAddress = [];
  22091. this.endAddress = [];
  22092. this.children = [];
  22093. }
  22094. function getSection(option) {
  22095. var section = new Section();
  22096. return utils.extend(section, option);
  22097. }
  22098. function getNodeFromAddress(startAddress, root) {
  22099. var current = root;
  22100. for(var i = 0;i < startAddress.length; i++) {
  22101. if(!current.childNodes) return null;
  22102. current = current.childNodes[startAddress[i]];
  22103. }
  22104. return current;
  22105. }
  22106. var me = this;
  22107. return {
  22108. bindMultiEvents:{
  22109. type: 'aftersetcontent afterscencerestore',
  22110. handler: function(){
  22111. me.fireEvent('updateSections');
  22112. }
  22113. },
  22114. bindEvents:{
  22115. /* 初始化、拖拽、粘贴、执行setcontent之后 */
  22116. 'ready': function (){
  22117. me.fireEvent('updateSections');
  22118. domUtils.on(me.body, 'drop paste', function(){
  22119. me.fireEvent('updateSections');
  22120. });
  22121. },
  22122. /* 执行paragraph命令之后 */
  22123. 'afterexeccommand': function (type, cmd) {
  22124. if(cmd == 'paragraph') {
  22125. me.fireEvent('updateSections');
  22126. }
  22127. },
  22128. /* 部分键盘操作,触发updateSections事件 */
  22129. 'keyup': function (type, e) {
  22130. var me = this,
  22131. range = me.selection.getRange();
  22132. if(range.collapsed != true) {
  22133. me.fireEvent('updateSections');
  22134. } else {
  22135. var keyCode = e.keyCode || e.which;
  22136. if(keyCode == 13 || keyCode == 8 || keyCode == 46) {
  22137. me.fireEvent('updateSections');
  22138. }
  22139. }
  22140. }
  22141. },
  22142. commands:{
  22143. 'getsections': {
  22144. execCommand: function (cmd, levels) {
  22145. var levelFn = levels || ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
  22146. for (var i = 0; i < levelFn.length; i++) {
  22147. if (typeof levelFn[i] == 'string') {
  22148. levelFn[i] = function(fn){
  22149. return function(node){
  22150. return node.tagName == fn.toUpperCase()
  22151. };
  22152. }(levelFn[i]);
  22153. } else if (typeof levelFn[i] != 'function') {
  22154. levelFn[i] = function (node) {
  22155. return null;
  22156. }
  22157. }
  22158. }
  22159. function getSectionLevel(node) {
  22160. for (var i = 0; i < levelFn.length; i++) {
  22161. if (levelFn[i](node)) return i;
  22162. }
  22163. return -1;
  22164. }
  22165. var me = this,
  22166. Directory = getSection({'level':-1, 'title':'root'}),
  22167. previous = Directory;
  22168. function traversal(node, Directory) {
  22169. var level,
  22170. tmpSection = null,
  22171. parent,
  22172. child,
  22173. children = node.childNodes;
  22174. for (var i = 0, len = children.length; i < len; i++) {
  22175. child = children[i];
  22176. level = getSectionLevel(child);
  22177. if (level >= 0) {
  22178. var address = me.selection.getRange().selectNode(child).createAddress(true).startAddress,
  22179. current = getSection({
  22180. 'tag': child.tagName,
  22181. 'title': child.innerText || child.textContent || '',
  22182. 'level': level,
  22183. 'dom': child,
  22184. 'startAddress': utils.clone(address, []),
  22185. 'endAddress': utils.clone(address, []),
  22186. 'children': []
  22187. });
  22188. previous.nextSection = current;
  22189. current.previousSection = previous;
  22190. parent = previous;
  22191. while(level <= parent.level){
  22192. parent = parent.parentSection;
  22193. }
  22194. current.parentSection = parent;
  22195. parent.children.push(current);
  22196. tmpSection = previous = current;
  22197. } else {
  22198. child.nodeType === 1 && traversal(child, Directory);
  22199. tmpSection && tmpSection.endAddress[tmpSection.endAddress.length - 1] ++;
  22200. }
  22201. }
  22202. }
  22203. traversal(me.body, Directory);
  22204. return Directory;
  22205. },
  22206. notNeedUndo: true
  22207. },
  22208. 'movesection': {
  22209. execCommand: function (cmd, sourceSection, targetSection, isAfter) {
  22210. var me = this,
  22211. targetAddress,
  22212. target;
  22213. if(!sourceSection || !targetSection || targetSection.level == -1) return;
  22214. targetAddress = isAfter ? targetSection.endAddress:targetSection.startAddress;
  22215. target = getNodeFromAddress(targetAddress, me.body);
  22216. /* 判断目标地址是否被源章节包含 */
  22217. if(!targetAddress || !target || isContainsAddress(sourceSection.startAddress, sourceSection.endAddress, targetAddress)) return;
  22218. var startNode = getNodeFromAddress(sourceSection.startAddress, me.body),
  22219. endNode = getNodeFromAddress(sourceSection.endAddress, me.body),
  22220. current,
  22221. nextNode;
  22222. if(isAfter) {
  22223. current = endNode;
  22224. while ( current && !(domUtils.getPosition( startNode, current ) & domUtils.POSITION_FOLLOWING) ) {
  22225. nextNode = current.previousSibling;
  22226. domUtils.insertAfter(target, current);
  22227. if(current == startNode) break;
  22228. current = nextNode;
  22229. }
  22230. } else {
  22231. current = startNode;
  22232. while ( current && !(domUtils.getPosition( current, endNode ) & domUtils.POSITION_FOLLOWING) ) {
  22233. nextNode = current.nextSibling;
  22234. target.parentNode.insertBefore(current, target);
  22235. if(current == endNode) break;
  22236. current = nextNode;
  22237. }
  22238. }
  22239. me.fireEvent('updateSections');
  22240. /* 获取地址的包含关系 */
  22241. function isContainsAddress(startAddress, endAddress, addressTarget){
  22242. var isAfterStartAddress = false,
  22243. isBeforeEndAddress = false;
  22244. for(var i = 0; i< startAddress.length; i++){
  22245. if(i >= addressTarget.length) break;
  22246. if(addressTarget[i] > startAddress[i]) {
  22247. isAfterStartAddress = true;
  22248. break;
  22249. } else if(addressTarget[i] < startAddress[i]) {
  22250. break;
  22251. }
  22252. }
  22253. for(var i = 0; i< endAddress.length; i++){
  22254. if(i >= addressTarget.length) break;
  22255. if(addressTarget[i] < startAddress[i]) {
  22256. isBeforeEndAddress = true;
  22257. break;
  22258. } else if(addressTarget[i] > startAddress[i]) {
  22259. break;
  22260. }
  22261. }
  22262. return isAfterStartAddress && isBeforeEndAddress;
  22263. }
  22264. }
  22265. },
  22266. 'deletesection': {
  22267. execCommand: function (cmd, section, keepChildren) {
  22268. var me = this;
  22269. if(!section) return;
  22270. function getNodeFromAddress(startAddress) {
  22271. var current = me.body;
  22272. for(var i = 0;i < startAddress.length; i++) {
  22273. if(!current.childNodes) return null;
  22274. current = current.childNodes[startAddress[i]];
  22275. }
  22276. return current;
  22277. }
  22278. var startNode = getNodeFromAddress(section.startAddress),
  22279. endNode = getNodeFromAddress(section.endAddress),
  22280. current = startNode,
  22281. nextNode;
  22282. if(!keepChildren) {
  22283. while ( current && domUtils.inDoc(endNode, me.document) && !(domUtils.getPosition( current, endNode ) & domUtils.POSITION_FOLLOWING) ) {
  22284. nextNode = current.nextSibling;
  22285. domUtils.remove(current);
  22286. current = nextNode;
  22287. }
  22288. } else {
  22289. domUtils.remove(current);
  22290. }
  22291. me.fireEvent('updateSections');
  22292. }
  22293. },
  22294. 'selectsection': {
  22295. execCommand: function (cmd, section) {
  22296. if(!section && !section.dom) return false;
  22297. var me = this,
  22298. range = me.selection.getRange(),
  22299. address = {
  22300. 'startAddress':utils.clone(section.startAddress, []),
  22301. 'endAddress':utils.clone(section.endAddress, [])
  22302. };
  22303. address.endAddress[address.endAddress.length - 1]++;
  22304. range.moveToAddress(address).select().scrollToView();
  22305. return true;
  22306. },
  22307. notNeedUndo: true
  22308. },
  22309. 'scrolltosection': {
  22310. execCommand: function (cmd, section) {
  22311. if(!section && !section.dom) return false;
  22312. var me = this,
  22313. range = me.selection.getRange(),
  22314. address = {
  22315. 'startAddress':section.startAddress,
  22316. 'endAddress':section.endAddress
  22317. };
  22318. address.endAddress[address.endAddress.length - 1]++;
  22319. range.moveToAddress(address).scrollToView();
  22320. return true;
  22321. },
  22322. notNeedUndo: true
  22323. }
  22324. }
  22325. }
  22326. });
  22327. // plugins/simpleupload.js
  22328. /**
  22329. * @description
  22330. * 简单上传:点击按钮,直接选择文件上传
  22331. * @author Jinqn
  22332. * @date 2014-03-31
  22333. */
  22334. UE.plugin.register('simpleupload', function (){
  22335. var me = this,
  22336. isLoaded = false,
  22337. containerBtn;
  22338. function initUploadBtn(){
  22339. var w = containerBtn.offsetWidth || 20,
  22340. h = containerBtn.offsetHeight || 20,
  22341. btnIframe = document.createElement('iframe'),
  22342. btnStyle = 'display:block;width:' + w + 'px;height:' + h + 'px;overflow:hidden;border:0;margin:0;padding:0;position:absolute;top:0;left:0;filter:alpha(opacity=0);-moz-opacity:0;-khtml-opacity: 0;opacity: 0;cursor:pointer;';
  22343. domUtils.on(btnIframe, 'load', function(){
  22344. var timestrap = (+new Date()).toString(36),
  22345. wrapper,
  22346. btnIframeDoc,
  22347. btnIframeBody;
  22348. btnIframeDoc = (btnIframe.contentDocument || btnIframe.contentWindow.document);
  22349. btnIframeBody = btnIframeDoc.body;
  22350. wrapper = btnIframeDoc.createElement('div');
  22351. wrapper.innerHTML = '<form id="edui_form_' + timestrap + '" target="edui_iframe_' + timestrap + '" method="POST" enctype="multipart/form-data" action="' + me.getOpt('serverUrl') + '" ' +
  22352. 'style="' + btnStyle + '">' +
  22353. '<input id="edui_input_' + timestrap + '" type="file" accept="image/*" name="' + me.options.imageFieldName + '" ' +
  22354. 'style="' + btnStyle + '">' +
  22355. '</form>' +
  22356. '<iframe id="edui_iframe_' + timestrap + '" name="edui_iframe_' + timestrap + '" style="display:none;width:0;height:0;border:0;margin:0;padding:0;position:absolute;"></iframe>';
  22357. wrapper.className = 'edui-' + me.options.theme;
  22358. wrapper.id = me.ui.id + '_iframeupload';
  22359. btnIframeBody.style.cssText = btnStyle;
  22360. btnIframeBody.style.width = w + 'px';
  22361. btnIframeBody.style.height = h + 'px';
  22362. btnIframeBody.appendChild(wrapper);
  22363. if (btnIframeBody.parentNode) {
  22364. btnIframeBody.parentNode.style.width = w + 'px';
  22365. btnIframeBody.parentNode.style.height = w + 'px';
  22366. }
  22367. var form = btnIframeDoc.getElementById('edui_form_' + timestrap);
  22368. var input = btnIframeDoc.getElementById('edui_input_' + timestrap);
  22369. var iframe = btnIframeDoc.getElementById('edui_iframe_' + timestrap);
  22370. domUtils.on(input, 'change', function(){
  22371. if(!input.value) return;
  22372. var loadingId = 'loading_' + (+new Date()).toString(36);
  22373. var params = utils.serializeParam(me.queryCommandValue('serverparam')) || '';
  22374. var imageActionUrl = me.getActionUrl(me.getOpt('imageActionName'));
  22375. var allowFiles = me.getOpt('imageAllowFiles');
  22376. me.focus();
  22377. me.execCommand('inserthtml', '<img class="loadingclass" id="' + loadingId + '" src="' + me.options.themePath + me.options.theme +'/images/spacer.gif" title="' + (me.getLang('simpleupload.loading') || '') + '" >');
  22378. function callback(){
  22379. try{
  22380. var link, json, loader,
  22381. body = (iframe.contentDocument || iframe.contentWindow.document).body,
  22382. result = body.innerText || body.textContent || '';
  22383. json = (new Function("return " + result))();
  22384. link = me.options.imageUrlPrefix + json.url;
  22385. if(json.state == 'SUCCESS' && json.url) {
  22386. loader = me.document.getElementById(loadingId);
  22387. loader.setAttribute('src', link);
  22388. loader.setAttribute('_src', link);
  22389. loader.setAttribute('title', json.title || '');
  22390. loader.setAttribute('alt', json.original || '');
  22391. loader.removeAttribute('id');
  22392. domUtils.removeClasses(loader, 'loadingclass');
  22393. } else {
  22394. showErrorLoader && showErrorLoader(json.state);
  22395. }
  22396. }catch(er){
  22397. showErrorLoader && showErrorLoader(me.getLang('simpleupload.loadError'));
  22398. }
  22399. form.reset();
  22400. domUtils.un(iframe, 'load', callback);
  22401. }
  22402. function showErrorLoader(title){
  22403. if(loadingId) {
  22404. var loader = me.document.getElementById(loadingId);
  22405. loader && domUtils.remove(loader);
  22406. me.fireEvent('showmessage', {
  22407. 'id': loadingId,
  22408. 'content': title,
  22409. 'type': 'error',
  22410. 'timeout': 4000
  22411. });
  22412. }
  22413. }
  22414. /* 判断后端配置是否没有加载成功 */
  22415. if (!me.getOpt('imageActionName')) {
  22416. errorHandler(me.getLang('autoupload.errorLoadConfig'));
  22417. return;
  22418. }
  22419. // 判断文件格式是否错误
  22420. var filename = input.value,
  22421. fileext = filename ? filename.substr(filename.lastIndexOf('.')):'';
  22422. if (!fileext || (allowFiles && (allowFiles.join('') + '.').indexOf(fileext.toLowerCase() + '.') == -1)) {
  22423. showErrorLoader(me.getLang('simpleupload.exceedTypeError'));
  22424. return;
  22425. }
  22426. domUtils.on(iframe, 'load', callback);
  22427. form.action = utils.formatUrl(imageActionUrl + (imageActionUrl.indexOf('?') == -1 ? '?':'&') + params);
  22428. form.submit();
  22429. });
  22430. var stateTimer;
  22431. me.addListener('selectionchange', function () {
  22432. clearTimeout(stateTimer);
  22433. stateTimer = setTimeout(function() {
  22434. var state = me.queryCommandState('simpleupload');
  22435. if (state == -1) {
  22436. input.disabled = 'disabled';
  22437. } else {
  22438. input.disabled = false;
  22439. }
  22440. }, 400);
  22441. });
  22442. isLoaded = true;
  22443. });
  22444. btnIframe.style.cssText = btnStyle;
  22445. containerBtn.appendChild(btnIframe);
  22446. }
  22447. return {
  22448. bindEvents:{
  22449. 'ready': function() {
  22450. //设置loading的样式
  22451. utils.cssRule('loading',
  22452. '.loadingclass{display:inline-block;cursor:default;background: url(\''
  22453. + this.options.themePath
  22454. + this.options.theme +'/images/loading.gif\') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;}\n' +
  22455. '.loaderrorclass{display:inline-block;cursor:default;background: url(\''
  22456. + this.options.themePath
  22457. + this.options.theme +'/images/loaderror.png\') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;' +
  22458. '}',
  22459. this.document);
  22460. },
  22461. /* 初始化简单上传按钮 */
  22462. 'simpleuploadbtnready': function(type, container) {
  22463. containerBtn = container;
  22464. me.afterConfigReady(initUploadBtn);
  22465. }
  22466. },
  22467. outputRule: function(root){
  22468. utils.each(root.getNodesByTagName('img'),function(n){
  22469. if (/\b(loaderrorclass)|(bloaderrorclass)\b/.test(n.getAttr('class'))) {
  22470. n.parentNode.removeChild(n);
  22471. }
  22472. });
  22473. },
  22474. commands: {
  22475. 'simpleupload': {
  22476. queryCommandState: function () {
  22477. return isLoaded ? 0:-1;
  22478. }
  22479. }
  22480. }
  22481. }
  22482. });
  22483. // plugins/serverparam.js
  22484. /**
  22485. * 服务器提交的额外参数列表设置插件
  22486. * @file
  22487. * @since 1.2.6.1
  22488. */
  22489. UE.plugin.register('serverparam', function (){
  22490. var me = this,
  22491. serverParam = {};
  22492. return {
  22493. commands:{
  22494. /**
  22495. * 修改服务器提交的额外参数列表,清除所有项
  22496. * @command serverparam
  22497. * @method execCommand
  22498. * @param { String } cmd 命令字符串
  22499. * @example
  22500. * ```javascript
  22501. * editor.execCommand('serverparam');
  22502. * editor.queryCommandValue('serverparam'); //返回空
  22503. * ```
  22504. */
  22505. /**
  22506. * 修改服务器提交的额外参数列表,删除指定项
  22507. * @command serverparam
  22508. * @method execCommand
  22509. * @param { String } cmd 命令字符串
  22510. * @param { String } key 要清除的属性
  22511. * @example
  22512. * ```javascript
  22513. * editor.execCommand('serverparam', 'name'); //删除属性name
  22514. * ```
  22515. */
  22516. /**
  22517. * 修改服务器提交的额外参数列表,使用键值添加项
  22518. * @command serverparam
  22519. * @method execCommand
  22520. * @param { String } cmd 命令字符串
  22521. * @param { String } key 要添加的属性
  22522. * @param { String } value 要添加属性的值
  22523. * @example
  22524. * ```javascript
  22525. * editor.execCommand('serverparam', 'name', 'hello');
  22526. * editor.queryCommandValue('serverparam'); //返回对象 {'name': 'hello'}
  22527. * ```
  22528. */
  22529. /**
  22530. * 修改服务器提交的额外参数列表,传入键值对对象添加多项
  22531. * @command serverparam
  22532. * @method execCommand
  22533. * @param { String } cmd 命令字符串
  22534. * @param { Object } key 传入的键值对对象
  22535. * @example
  22536. * ```javascript
  22537. * editor.execCommand('serverparam', {'name': 'hello'});
  22538. * editor.queryCommandValue('serverparam'); //返回对象 {'name': 'hello'}
  22539. * ```
  22540. */
  22541. /**
  22542. * 修改服务器提交的额外参数列表,使用自定义函数添加多项
  22543. * @command serverparam
  22544. * @method execCommand
  22545. * @param { String } cmd 命令字符串
  22546. * @param { Function } key 自定义获取参数的函数
  22547. * @example
  22548. * ```javascript
  22549. * editor.execCommand('serverparam', function(editor){
  22550. * return {'key': 'value'};
  22551. * });
  22552. * editor.queryCommandValue('serverparam'); //返回对象 {'key': 'value'}
  22553. * ```
  22554. */
  22555. /**
  22556. * 获取服务器提交的额外参数列表
  22557. * @command serverparam
  22558. * @method queryCommandValue
  22559. * @param { String } cmd 命令字符串
  22560. * @example
  22561. * ```javascript
  22562. * editor.queryCommandValue( 'serverparam' ); //返回对象 {'key': 'value'}
  22563. * ```
  22564. */
  22565. 'serverparam':{
  22566. execCommand:function (cmd, key, value) {
  22567. if (key === undefined || key === null) { //不传参数,清空列表
  22568. serverParam = {};
  22569. } else if (utils.isString(key)) { //传入键值
  22570. if(value === undefined || value === null) {
  22571. delete serverParam[key];
  22572. } else {
  22573. serverParam[key] = value;
  22574. }
  22575. } else if (utils.isObject(key)) { //传入对象,覆盖列表项
  22576. utils.extend(serverParam, key, true);
  22577. } else if (utils.isFunction(key)){ //传入函数,添加列表项
  22578. utils.extend(serverParam, key(), true);
  22579. }
  22580. },
  22581. queryCommandValue: function(){
  22582. return serverParam || {};
  22583. }
  22584. }
  22585. }
  22586. }
  22587. });
  22588. // plugins/insertfile.js
  22589. /**
  22590. * 插入附件
  22591. */
  22592. UE.plugin.register('insertfile', function (){
  22593. var me = this;
  22594. function getFileIcon(url){
  22595. var ext = url.substr(url.lastIndexOf('.') + 1).toLowerCase(),
  22596. maps = {
  22597. "rar":"icon_rar.gif",
  22598. "zip":"icon_rar.gif",
  22599. "tar":"icon_rar.gif",
  22600. "gz":"icon_rar.gif",
  22601. "bz2":"icon_rar.gif",
  22602. "doc":"icon_doc.gif",
  22603. "docx":"icon_doc.gif",
  22604. "pdf":"icon_pdf.gif",
  22605. "mp3":"icon_mp3.gif",
  22606. "xls":"icon_xls.gif",
  22607. "chm":"icon_chm.gif",
  22608. "ppt":"icon_ppt.gif",
  22609. "pptx":"icon_ppt.gif",
  22610. "avi":"icon_mv.gif",
  22611. "rmvb":"icon_mv.gif",
  22612. "wmv":"icon_mv.gif",
  22613. "flv":"icon_mv.gif",
  22614. "swf":"icon_mv.gif",
  22615. "rm":"icon_mv.gif",
  22616. "exe":"icon_exe.gif",
  22617. "psd":"icon_psd.gif",
  22618. "txt":"icon_txt.gif",
  22619. "jpg":"icon_jpg.gif",
  22620. "png":"icon_jpg.gif",
  22621. "jpeg":"icon_jpg.gif",
  22622. "gif":"icon_jpg.gif",
  22623. "ico":"icon_jpg.gif",
  22624. "bmp":"icon_jpg.gif"
  22625. };
  22626. return maps[ext] ? maps[ext]:maps['txt'];
  22627. }
  22628. return {
  22629. commands:{
  22630. 'insertfile': {
  22631. execCommand: function (command, filelist){
  22632. filelist = utils.isArray(filelist) ? filelist : [filelist];
  22633. var i, item, icon, title,
  22634. html = '',
  22635. URL = me.getOpt('UEDITOR_HOME_URL'),
  22636. iconDir = URL + (URL.substr(URL.length - 1) == '/' ? '':'/') + 'dialogs/attachment/fileTypeImages/';
  22637. for (i = 0; i < filelist.length; i++) {
  22638. item = filelist[i];
  22639. icon = iconDir + getFileIcon(item.url);
  22640. title = item.title || item.url.substr(item.url.lastIndexOf('/') + 1);
  22641. html += '<p style="line-height: 16px;">' +
  22642. '<img style="vertical-align: middle; margin-right: 2px;" src="'+ icon + '" _src="' + icon + '" />' +
  22643. '<a style="font-size:12px; color:#0066cc;" href="' + item.url +'" title="' + title + '">' + title + '</a>' +
  22644. '</p>';
  22645. }
  22646. me.execCommand('insertHtml', html);
  22647. }
  22648. }
  22649. }
  22650. }
  22651. });
  22652. // ui/ui.js
  22653. var baidu = baidu || {};
  22654. baidu.editor = baidu.editor || {};
  22655. UE.ui = baidu.editor.ui = {};
  22656. // ui/uiutils.js
  22657. (function (){
  22658. var browser = baidu.editor.browser,
  22659. domUtils = baidu.editor.dom.domUtils;
  22660. var magic = '$EDITORUI';
  22661. var root = window[magic] = {};
  22662. var uidMagic = 'ID' + magic;
  22663. var uidCount = 0;
  22664. var uiUtils = baidu.editor.ui.uiUtils = {
  22665. uid: function (obj){
  22666. return (obj ? obj[uidMagic] || (obj[uidMagic] = ++ uidCount) : ++ uidCount);
  22667. },
  22668. hook: function ( fn, callback ) {
  22669. var dg;
  22670. if (fn && fn._callbacks) {
  22671. dg = fn;
  22672. } else {
  22673. dg = function (){
  22674. var q;
  22675. if (fn) {
  22676. q = fn.apply(this, arguments);
  22677. }
  22678. var callbacks = dg._callbacks;
  22679. var k = callbacks.length;
  22680. while (k --) {
  22681. var r = callbacks[k].apply(this, arguments);
  22682. if (q === undefined) {
  22683. q = r;
  22684. }
  22685. }
  22686. return q;
  22687. };
  22688. dg._callbacks = [];
  22689. }
  22690. dg._callbacks.push(callback);
  22691. return dg;
  22692. },
  22693. createElementByHtml: function (html){
  22694. var el = document.createElement('div');
  22695. el.innerHTML = html;
  22696. el = el.firstChild;
  22697. el.parentNode.removeChild(el);
  22698. return el;
  22699. },
  22700. getViewportElement: function (){
  22701. return (browser.ie && browser.quirks) ?
  22702. document.body : document.documentElement;
  22703. },
  22704. getClientRect: function (element){
  22705. var bcr;
  22706. //trace IE6下在控制编辑器显隐时可能会报错,catch一下
  22707. try{
  22708. bcr = element.getBoundingClientRect();
  22709. }catch(e){
  22710. bcr={left:0,top:0,height:0,width:0}
  22711. }
  22712. var rect = {
  22713. left: Math.round(bcr.left),
  22714. top: Math.round(bcr.top),
  22715. height: Math.round(bcr.bottom - bcr.top),
  22716. width: Math.round(bcr.right - bcr.left)
  22717. };
  22718. var doc;
  22719. while ((doc = element.ownerDocument) !== document &&
  22720. (element = domUtils.getWindow(doc).frameElement)) {
  22721. bcr = element.getBoundingClientRect();
  22722. rect.left += bcr.left;
  22723. rect.top += bcr.top;
  22724. }
  22725. rect.bottom = rect.top + rect.height;
  22726. rect.right = rect.left + rect.width;
  22727. return rect;
  22728. },
  22729. getViewportRect: function (){
  22730. var viewportEl = uiUtils.getViewportElement();
  22731. var width = (window.innerWidth || viewportEl.clientWidth) | 0;
  22732. var height = (window.innerHeight ||viewportEl.clientHeight) | 0;
  22733. return {
  22734. left: 0,
  22735. top: 0,
  22736. height: height,
  22737. width: width,
  22738. bottom: height,
  22739. right: width
  22740. };
  22741. },
  22742. setViewportOffset: function (element, offset){
  22743. var rect;
  22744. var fixedLayer = uiUtils.getFixedLayer();
  22745. if (element.parentNode === fixedLayer) {
  22746. element.style.left = offset.left + 'px';
  22747. element.style.top = offset.top + 'px';
  22748. } else {
  22749. domUtils.setViewportOffset(element, offset);
  22750. }
  22751. },
  22752. getEventOffset: function (evt){
  22753. var el = evt.target || evt.srcElement;
  22754. var rect = uiUtils.getClientRect(el);
  22755. var offset = uiUtils.getViewportOffsetByEvent(evt);
  22756. return {
  22757. left: offset.left - rect.left,
  22758. top: offset.top - rect.top
  22759. };
  22760. },
  22761. getViewportOffsetByEvent: function (evt){
  22762. var el = evt.target || evt.srcElement;
  22763. var frameEl = domUtils.getWindow(el).frameElement;
  22764. var offset = {
  22765. left: evt.clientX,
  22766. top: evt.clientY
  22767. };
  22768. if (frameEl && el.ownerDocument !== document) {
  22769. var rect = uiUtils.getClientRect(frameEl);
  22770. offset.left += rect.left;
  22771. offset.top += rect.top;
  22772. }
  22773. return offset;
  22774. },
  22775. setGlobal: function (id, obj){
  22776. root[id] = obj;
  22777. return magic + '["' + id + '"]';
  22778. },
  22779. unsetGlobal: function (id){
  22780. delete root[id];
  22781. },
  22782. copyAttributes: function (tgt, src){
  22783. var attributes = src.attributes;
  22784. var k = attributes.length;
  22785. while (k --) {
  22786. var attrNode = attributes[k];
  22787. if ( attrNode.nodeName != 'style' && attrNode.nodeName != 'class' && (!browser.ie || attrNode.specified) ) {
  22788. tgt.setAttribute(attrNode.nodeName, attrNode.nodeValue);
  22789. }
  22790. }
  22791. if (src.className) {
  22792. domUtils.addClass(tgt,src.className);
  22793. }
  22794. if (src.style.cssText) {
  22795. tgt.style.cssText += ';' + src.style.cssText;
  22796. }
  22797. },
  22798. removeStyle: function (el, styleName){
  22799. if (el.style.removeProperty) {
  22800. el.style.removeProperty(styleName);
  22801. } else if (el.style.removeAttribute) {
  22802. el.style.removeAttribute(styleName);
  22803. } else throw '';
  22804. },
  22805. contains: function (elA, elB){
  22806. return elA && elB && (elA === elB ? false : (
  22807. elA.contains ? elA.contains(elB) :
  22808. elA.compareDocumentPosition(elB) & 16
  22809. ));
  22810. },
  22811. startDrag: function (evt, callbacks,doc){
  22812. var doc = doc || document;
  22813. var startX = evt.clientX;
  22814. var startY = evt.clientY;
  22815. function handleMouseMove(evt){
  22816. var x = evt.clientX - startX;
  22817. var y = evt.clientY - startY;
  22818. callbacks.ondragmove(x, y,evt);
  22819. if (evt.stopPropagation) {
  22820. evt.stopPropagation();
  22821. } else {
  22822. evt.cancelBubble = true;
  22823. }
  22824. }
  22825. if (doc.addEventListener) {
  22826. function handleMouseUp(evt){
  22827. doc.removeEventListener('mousemove', handleMouseMove, true);
  22828. doc.removeEventListener('mouseup', handleMouseUp, true);
  22829. window.removeEventListener('mouseup', handleMouseUp, true);
  22830. callbacks.ondragstop();
  22831. }
  22832. doc.addEventListener('mousemove', handleMouseMove, true);
  22833. doc.addEventListener('mouseup', handleMouseUp, true);
  22834. window.addEventListener('mouseup', handleMouseUp, true);
  22835. evt.preventDefault();
  22836. } else {
  22837. var elm = evt.srcElement;
  22838. elm.setCapture();
  22839. function releaseCaptrue(){
  22840. elm.releaseCapture();
  22841. elm.detachEvent('onmousemove', handleMouseMove);
  22842. elm.detachEvent('onmouseup', releaseCaptrue);
  22843. elm.detachEvent('onlosecaptrue', releaseCaptrue);
  22844. callbacks.ondragstop();
  22845. }
  22846. elm.attachEvent('onmousemove', handleMouseMove);
  22847. elm.attachEvent('onmouseup', releaseCaptrue);
  22848. elm.attachEvent('onlosecaptrue', releaseCaptrue);
  22849. evt.returnValue = false;
  22850. }
  22851. callbacks.ondragstart();
  22852. },
  22853. getFixedLayer: function (){
  22854. var layer = document.getElementById('edui_fixedlayer');
  22855. if (layer == null) {
  22856. layer = document.createElement('div');
  22857. layer.id = 'edui_fixedlayer';
  22858. document.body.appendChild(layer);
  22859. if (browser.ie && browser.version <= 8) {
  22860. layer.style.position = 'absolute';
  22861. bindFixedLayer();
  22862. setTimeout(updateFixedOffset);
  22863. } else {
  22864. layer.style.position = 'fixed';
  22865. }
  22866. layer.style.left = '0';
  22867. layer.style.top = '0';
  22868. layer.style.width = '0';
  22869. layer.style.height = '0';
  22870. }
  22871. return layer;
  22872. },
  22873. makeUnselectable: function (element){
  22874. if (browser.opera || (browser.ie && browser.version < 9)) {
  22875. element.unselectable = 'on';
  22876. if (element.hasChildNodes()) {
  22877. for (var i=0; i<element.childNodes.length; i++) {
  22878. if (element.childNodes[i].nodeType == 1) {
  22879. uiUtils.makeUnselectable(element.childNodes[i]);
  22880. }
  22881. }
  22882. }
  22883. } else {
  22884. if (element.style.MozUserSelect !== undefined) {
  22885. element.style.MozUserSelect = 'none';
  22886. } else if (element.style.WebkitUserSelect !== undefined) {
  22887. element.style.WebkitUserSelect = 'none';
  22888. } else if (element.style.KhtmlUserSelect !== undefined) {
  22889. element.style.KhtmlUserSelect = 'none';
  22890. }
  22891. }
  22892. }
  22893. };
  22894. function updateFixedOffset(){
  22895. var layer = document.getElementById('edui_fixedlayer');
  22896. uiUtils.setViewportOffset(layer, {
  22897. left: 0,
  22898. top: 0
  22899. });
  22900. // layer.style.display = 'none';
  22901. // layer.style.display = 'block';
  22902. //#trace: 1354
  22903. // setTimeout(updateFixedOffset);
  22904. }
  22905. function bindFixedLayer(adjOffset){
  22906. domUtils.on(window, 'scroll', updateFixedOffset);
  22907. domUtils.on(window, 'resize', baidu.editor.utils.defer(updateFixedOffset, 0, true));
  22908. }
  22909. })();
  22910. // ui/uibase.js
  22911. (function () {
  22912. var utils = baidu.editor.utils,
  22913. uiUtils = baidu.editor.ui.uiUtils,
  22914. EventBase = baidu.editor.EventBase,
  22915. UIBase = baidu.editor.ui.UIBase = function () {
  22916. };
  22917. UIBase.prototype = {
  22918. className:'',
  22919. uiName:'',
  22920. initOptions:function (options) {
  22921. var me = this;
  22922. for (var k in options) {
  22923. me[k] = options[k];
  22924. }
  22925. this.id = this.id || 'edui' + uiUtils.uid();
  22926. },
  22927. initUIBase:function () {
  22928. this._globalKey = utils.unhtml(uiUtils.setGlobal(this.id, this));
  22929. },
  22930. render:function (holder) {
  22931. var html = this.renderHtml();
  22932. var el = uiUtils.createElementByHtml(html);
  22933. //by xuheng 给每个node添加class
  22934. var list = domUtils.getElementsByTagName(el, "*");
  22935. var theme = "edui-" + (this.theme || this.editor.options.theme);
  22936. var layer = document.getElementById('edui_fixedlayer');
  22937. for (var i = 0, node; node = list[i++];) {
  22938. domUtils.addClass(node, theme);
  22939. }
  22940. domUtils.addClass(el, theme);
  22941. if(layer){
  22942. layer.className="";
  22943. domUtils.addClass(layer,theme);
  22944. }
  22945. var seatEl = this.getDom();
  22946. if (seatEl != null) {
  22947. seatEl.parentNode.replaceChild(el, seatEl);
  22948. uiUtils.copyAttributes(el, seatEl);
  22949. } else {
  22950. if (typeof holder == 'string') {
  22951. holder = document.getElementById(holder);
  22952. }
  22953. holder = holder || uiUtils.getFixedLayer();
  22954. domUtils.addClass(holder, theme);
  22955. holder.appendChild(el);
  22956. }
  22957. this.postRender();
  22958. },
  22959. getDom:function (name) {
  22960. if (!name) {
  22961. return document.getElementById(this.id);
  22962. } else {
  22963. return document.getElementById(this.id + '_' + name);
  22964. }
  22965. },
  22966. postRender:function () {
  22967. this.fireEvent('postrender');
  22968. },
  22969. getHtmlTpl:function () {
  22970. return '';
  22971. },
  22972. formatHtml:function (tpl) {
  22973. var prefix = 'edui-' + this.uiName;
  22974. return (tpl
  22975. .replace(/##/g, this.id)
  22976. .replace(/%%-/g, this.uiName ? prefix + '-' : '')
  22977. .replace(/%%/g, (this.uiName ? prefix : '') + ' ' + this.className)
  22978. .replace(/\$\$/g, this._globalKey));
  22979. },
  22980. renderHtml:function () {
  22981. return this.formatHtml(this.getHtmlTpl());
  22982. },
  22983. dispose:function () {
  22984. var box = this.getDom();
  22985. if (box) baidu.editor.dom.domUtils.remove(box);
  22986. uiUtils.unsetGlobal(this.id);
  22987. }
  22988. };
  22989. utils.inherits(UIBase, EventBase);
  22990. })();
  22991. // ui/separator.js
  22992. (function (){
  22993. var utils = baidu.editor.utils,
  22994. UIBase = baidu.editor.ui.UIBase,
  22995. Separator = baidu.editor.ui.Separator = function (options){
  22996. this.initOptions(options);
  22997. this.initSeparator();
  22998. };
  22999. Separator.prototype = {
  23000. uiName: 'separator',
  23001. initSeparator: function (){
  23002. this.initUIBase();
  23003. },
  23004. getHtmlTpl: function (){
  23005. return '<div id="##" class="edui-box %%"></div>';
  23006. }
  23007. };
  23008. utils.inherits(Separator, UIBase);
  23009. })();
  23010. // ui/mask.js
  23011. ///import core
  23012. ///import uicore
  23013. (function (){
  23014. var utils = baidu.editor.utils,
  23015. domUtils = baidu.editor.dom.domUtils,
  23016. UIBase = baidu.editor.ui.UIBase,
  23017. uiUtils = baidu.editor.ui.uiUtils;
  23018. var Mask = baidu.editor.ui.Mask = function (options){
  23019. this.initOptions(options);
  23020. this.initUIBase();
  23021. };
  23022. Mask.prototype = {
  23023. getHtmlTpl: function (){
  23024. return '<div id="##" class="edui-mask %%" onclick="return $$._onClick(event, this);" onmousedown="return $$._onMouseDown(event, this);"></div>';
  23025. },
  23026. postRender: function (){
  23027. var me = this;
  23028. domUtils.on(window, 'resize', function (){
  23029. setTimeout(function (){
  23030. if (!me.isHidden()) {
  23031. me._fill();
  23032. }
  23033. });
  23034. });
  23035. },
  23036. show: function (zIndex){
  23037. this._fill();
  23038. this.getDom().style.display = '';
  23039. this.getDom().style.zIndex = zIndex;
  23040. },
  23041. hide: function (){
  23042. this.getDom().style.display = 'none';
  23043. this.getDom().style.zIndex = '';
  23044. },
  23045. isHidden: function (){
  23046. return this.getDom().style.display == 'none';
  23047. },
  23048. _onMouseDown: function (){
  23049. return false;
  23050. },
  23051. _onClick: function (e, target){
  23052. this.fireEvent('click', e, target);
  23053. },
  23054. _fill: function (){
  23055. var el = this.getDom();
  23056. var vpRect = uiUtils.getViewportRect();
  23057. el.style.width = vpRect.width + 'px';
  23058. el.style.height = vpRect.height + 'px';
  23059. }
  23060. };
  23061. utils.inherits(Mask, UIBase);
  23062. })();
  23063. // ui/popup.js
  23064. ///import core
  23065. ///import uicore
  23066. (function () {
  23067. var utils = baidu.editor.utils,
  23068. uiUtils = baidu.editor.ui.uiUtils,
  23069. domUtils = baidu.editor.dom.domUtils,
  23070. UIBase = baidu.editor.ui.UIBase,
  23071. Popup = baidu.editor.ui.Popup = function (options){
  23072. this.initOptions(options);
  23073. this.initPopup();
  23074. };
  23075. var allPopups = [];
  23076. function closeAllPopup( evt,el ){
  23077. for ( var i = 0; i < allPopups.length; i++ ) {
  23078. var pop = allPopups[i];
  23079. if (!pop.isHidden()) {
  23080. if (pop.queryAutoHide(el) !== false) {
  23081. if(evt&&/scroll/ig.test(evt.type)&&pop.className=="edui-wordpastepop") return;
  23082. pop.hide();
  23083. }
  23084. }
  23085. }
  23086. if(allPopups.length)
  23087. pop.editor.fireEvent("afterhidepop");
  23088. }
  23089. Popup.postHide = closeAllPopup;
  23090. var ANCHOR_CLASSES = ['edui-anchor-topleft','edui-anchor-topright',
  23091. 'edui-anchor-bottomleft','edui-anchor-bottomright'];
  23092. Popup.prototype = {
  23093. SHADOW_RADIUS: 5,
  23094. content: null,
  23095. _hidden: false,
  23096. autoRender: true,
  23097. canSideLeft: true,
  23098. canSideUp: true,
  23099. initPopup: function (){
  23100. this.initUIBase();
  23101. allPopups.push( this );
  23102. },
  23103. getHtmlTpl: function (){
  23104. return '<div id="##" class="edui-popup %%" onmousedown="return false;">' +
  23105. ' <div id="##_body" class="edui-popup-body">' +
  23106. ' <iframe style="position:absolute;z-index:-1;left:0;top:0;background-color: transparent;" frameborder="0" width="100%" height="100%" src="about:blank"></iframe>' +
  23107. ' <div class="edui-shadow"></div>' +
  23108. ' <div id="##_content" class="edui-popup-content">' +
  23109. this.getContentHtmlTpl() +
  23110. ' </div>' +
  23111. ' </div>' +
  23112. '</div>';
  23113. },
  23114. getContentHtmlTpl: function (){
  23115. if(this.content){
  23116. if (typeof this.content == 'string') {
  23117. return this.content;
  23118. }
  23119. return this.content.renderHtml();
  23120. }else{
  23121. return ''
  23122. }
  23123. },
  23124. _UIBase_postRender: UIBase.prototype.postRender,
  23125. postRender: function (){
  23126. if (this.content instanceof UIBase) {
  23127. this.content.postRender();
  23128. }
  23129. //捕获鼠标滚轮
  23130. if( this.captureWheel && !this.captured ) {
  23131. this.captured = true;
  23132. var winHeight = ( document.documentElement.clientHeight || document.body.clientHeight ) - 80,
  23133. _height = this.getDom().offsetHeight,
  23134. _top = uiUtils.getClientRect( this.combox.getDom() ).top,
  23135. content = this.getDom('content'),
  23136. ifr = this.getDom('body').getElementsByTagName('iframe'),
  23137. me = this;
  23138. ifr.length && ( ifr = ifr[0] );
  23139. while( _top + _height > winHeight ) {
  23140. _height -= 30;
  23141. }
  23142. content.style.height = _height + 'px';
  23143. //同步更改iframe高度
  23144. ifr && ( ifr.style.height = _height + 'px' );
  23145. //阻止在combox上的鼠标滚轮事件, 防止用户的正常操作被误解
  23146. if( window.XMLHttpRequest ) {
  23147. domUtils.on( content, ( 'onmousewheel' in document.body ) ? 'mousewheel' :'DOMMouseScroll' , function(e){
  23148. if(e.preventDefault) {
  23149. e.preventDefault();
  23150. } else {
  23151. e.returnValue = false;
  23152. }
  23153. if( e.wheelDelta ) {
  23154. content.scrollTop -= ( e.wheelDelta / 120 )*60;
  23155. } else {
  23156. content.scrollTop -= ( e.detail / -3 )*60;
  23157. }
  23158. });
  23159. } else {
  23160. //ie6
  23161. domUtils.on( this.getDom(), 'mousewheel' , function(e){
  23162. e.returnValue = false;
  23163. me.getDom('content').scrollTop -= ( e.wheelDelta / 120 )*60;
  23164. });
  23165. }
  23166. }
  23167. this.fireEvent('postRenderAfter');
  23168. this.hide(true);
  23169. this._UIBase_postRender();
  23170. },
  23171. _doAutoRender: function (){
  23172. if (!this.getDom() && this.autoRender) {
  23173. this.render();
  23174. }
  23175. },
  23176. mesureSize: function (){
  23177. var box = this.getDom('content');
  23178. return uiUtils.getClientRect(box);
  23179. },
  23180. fitSize: function (){
  23181. if( this.captureWheel && this.sized ) {
  23182. return this.__size;
  23183. }
  23184. this.sized = true;
  23185. var popBodyEl = this.getDom('body');
  23186. popBodyEl.style.width = '';
  23187. popBodyEl.style.height = '';
  23188. var size = this.mesureSize();
  23189. if( this.captureWheel ) {
  23190. popBodyEl.style.width = -(-20 -size.width) + 'px';
  23191. var height = parseInt( this.getDom('content').style.height, 10 );
  23192. !window.isNaN( height ) && ( size.height = height );
  23193. } else {
  23194. popBodyEl.style.width = size.width + 'px';
  23195. }
  23196. popBodyEl.style.height = size.height + 'px';
  23197. this.__size = size;
  23198. this.captureWheel && (this.getDom('content').style.overflow = 'auto');
  23199. return size;
  23200. },
  23201. showAnchor: function ( element, hoz ){
  23202. this.showAnchorRect( uiUtils.getClientRect( element ), hoz );
  23203. },
  23204. showAnchorRect: function ( rect, hoz, adj ){
  23205. this._doAutoRender();
  23206. var vpRect = uiUtils.getViewportRect();
  23207. this.getDom().style.visibility = 'hidden';
  23208. this._show();
  23209. var popSize = this.fitSize();
  23210. var sideLeft, sideUp, left, top;
  23211. if (hoz) {
  23212. sideLeft = this.canSideLeft && (rect.right + popSize.width > vpRect.right && rect.left > popSize.width);
  23213. sideUp = this.canSideUp && (rect.top + popSize.height > vpRect.bottom && rect.bottom > popSize.height);
  23214. left = (sideLeft ? rect.left - popSize.width : rect.right);
  23215. top = (sideUp ? rect.bottom - popSize.height : rect.top);
  23216. } else {
  23217. sideLeft = this.canSideLeft && (rect.right + popSize.width > vpRect.right && rect.left > popSize.width);
  23218. sideUp = this.canSideUp && (rect.top + popSize.height > vpRect.bottom && rect.bottom > popSize.height);
  23219. left = (sideLeft ? rect.right - popSize.width : rect.left);
  23220. top = (sideUp ? rect.top - popSize.height : rect.bottom);
  23221. }
  23222. var popEl = this.getDom();
  23223. uiUtils.setViewportOffset(popEl, {
  23224. left: left,
  23225. top: top
  23226. });
  23227. domUtils.removeClasses(popEl, ANCHOR_CLASSES);
  23228. popEl.className += ' ' + ANCHOR_CLASSES[(sideUp ? 1 : 0) * 2 + (sideLeft ? 1 : 0)];
  23229. if(this.editor){
  23230. popEl.style.zIndex = this.editor.container.style.zIndex * 1 + 10;
  23231. baidu.editor.ui.uiUtils.getFixedLayer().style.zIndex = popEl.style.zIndex - 1;
  23232. }
  23233. this.getDom().style.visibility = 'visible';
  23234. },
  23235. showAt: function (offset) {
  23236. var left = offset.left;
  23237. var top = offset.top;
  23238. var rect = {
  23239. left: left,
  23240. top: top,
  23241. right: left,
  23242. bottom: top,
  23243. height: 0,
  23244. width: 0
  23245. };
  23246. this.showAnchorRect(rect, false, true);
  23247. },
  23248. _show: function (){
  23249. if (this._hidden) {
  23250. var box = this.getDom();
  23251. box.style.display = '';
  23252. this._hidden = false;
  23253. // if (box.setActive) {
  23254. // box.setActive();
  23255. // }
  23256. this.fireEvent('show');
  23257. }
  23258. },
  23259. isHidden: function (){
  23260. return this._hidden;
  23261. },
  23262. show: function (){
  23263. this._doAutoRender();
  23264. this._show();
  23265. },
  23266. hide: function (notNofity){
  23267. if (!this._hidden && this.getDom()) {
  23268. this.getDom().style.display = 'none';
  23269. this._hidden = true;
  23270. if (!notNofity) {
  23271. this.fireEvent('hide');
  23272. }
  23273. }
  23274. },
  23275. queryAutoHide: function (el){
  23276. return !el || !uiUtils.contains(this.getDom(), el);
  23277. }
  23278. };
  23279. utils.inherits(Popup, UIBase);
  23280. domUtils.on( document, 'mousedown', function ( evt ) {
  23281. var el = evt.target || evt.srcElement;
  23282. closeAllPopup( evt,el );
  23283. } );
  23284. domUtils.on( window, 'scroll', function (evt,el) {
  23285. closeAllPopup( evt,el );
  23286. } );
  23287. })();
  23288. // ui/colorpicker.js
  23289. ///import core
  23290. ///import uicore
  23291. (function (){
  23292. var utils = baidu.editor.utils,
  23293. UIBase = baidu.editor.ui.UIBase,
  23294. ColorPicker = baidu.editor.ui.ColorPicker = function (options){
  23295. this.initOptions(options);
  23296. this.noColorText = this.noColorText || this.editor.getLang("clearColor");
  23297. this.initUIBase();
  23298. };
  23299. ColorPicker.prototype = {
  23300. getHtmlTpl: function (){
  23301. return genColorPicker(this.noColorText,this.editor);
  23302. },
  23303. _onTableClick: function (evt){
  23304. var tgt = evt.target || evt.srcElement;
  23305. var color = tgt.getAttribute('data-color');
  23306. if (color) {
  23307. this.fireEvent('pickcolor', color);
  23308. }
  23309. },
  23310. _onTableOver: function (evt){
  23311. var tgt = evt.target || evt.srcElement;
  23312. var color = tgt.getAttribute('data-color');
  23313. if (color) {
  23314. this.getDom('preview').style.backgroundColor = color;
  23315. }
  23316. },
  23317. _onTableOut: function (){
  23318. this.getDom('preview').style.backgroundColor = '';
  23319. },
  23320. _onPickNoColor: function (){
  23321. this.fireEvent('picknocolor');
  23322. }
  23323. };
  23324. utils.inherits(ColorPicker, UIBase);
  23325. var COLORS = (
  23326. 'ffffff,000000,eeece1,1f497d,4f81bd,c0504d,9bbb59,8064a2,4bacc6,f79646,' +
  23327. 'f2f2f2,7f7f7f,ddd9c3,c6d9f0,dbe5f1,f2dcdb,ebf1dd,e5e0ec,dbeef3,fdeada,' +
  23328. 'd8d8d8,595959,c4bd97,8db3e2,b8cce4,e5b9b7,d7e3bc,ccc1d9,b7dde8,fbd5b5,' +
  23329. 'bfbfbf,3f3f3f,938953,548dd4,95b3d7,d99694,c3d69b,b2a2c7,92cddc,fac08f,' +
  23330. 'a5a5a5,262626,494429,17365d,366092,953734,76923c,5f497a,31859b,e36c09,' +
  23331. '7f7f7f,0c0c0c,1d1b10,0f243e,244061,632423,4f6128,3f3151,205867,974806,' +
  23332. 'c00000,ff0000,ffc000,ffff00,92d050,00b050,00b0f0,0070c0,002060,7030a0,').split(',');
  23333. function genColorPicker(noColorText,editor){
  23334. var html = '<div id="##" class="edui-colorpicker %%">' +
  23335. '<div class="edui-colorpicker-topbar edui-clearfix">' +
  23336. '<div unselectable="on" id="##_preview" class="edui-colorpicker-preview"></div>' +
  23337. '<div unselectable="on" class="edui-colorpicker-nocolor" onclick="$$._onPickNoColor(event, this);">'+ noColorText +'</div>' +
  23338. '</div>' +
  23339. '<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">' +
  23340. '<tr style="border-bottom: 1px solid #ddd;font-size: 13px;line-height: 25px;color:#39C;padding-top: 2px"><td colspan="10">'+editor.getLang("themeColor")+'</td> </tr>'+
  23341. '<tr class="edui-colorpicker-tablefirstrow" >';
  23342. for (var i=0; i<COLORS.length; i++) {
  23343. if (i && i%10 === 0) {
  23344. html += '</tr>'+(i==60?'<tr style="border-bottom: 1px solid #ddd;font-size: 13px;line-height: 25px;color:#39C;"><td colspan="10">'+editor.getLang("standardColor")+'</td></tr>':'')+'<tr'+(i==60?' class="edui-colorpicker-tablefirstrow"':'')+'>';
  23345. }
  23346. html += i<70 ? '<td style="padding: 0 2px;"><a hidefocus title="'+COLORS[i]+'" onclick="return false;" href="javascript:" unselectable="on" class="edui-box edui-colorpicker-colorcell"' +
  23347. ' data-color="#'+ COLORS[i] +'"'+
  23348. ' style="background-color:#'+ COLORS[i] +';border:solid #ccc;'+
  23349. (i<10 || i>=60?'border-width:1px;':
  23350. i>=10&&i<20?'border-width:1px 1px 0 1px;':
  23351. 'border-width:0 1px 0 1px;')+
  23352. '"' +
  23353. '></a></td>':'';
  23354. }
  23355. html += '</tr></table></div>';
  23356. return html;
  23357. }
  23358. })();
  23359. // ui/tablepicker.js
  23360. ///import core
  23361. ///import uicore
  23362. (function (){
  23363. var utils = baidu.editor.utils,
  23364. uiUtils = baidu.editor.ui.uiUtils,
  23365. UIBase = baidu.editor.ui.UIBase;
  23366. var TablePicker = baidu.editor.ui.TablePicker = function (options){
  23367. this.initOptions(options);
  23368. this.initTablePicker();
  23369. };
  23370. TablePicker.prototype = {
  23371. defaultNumRows: 10,
  23372. defaultNumCols: 10,
  23373. maxNumRows: 20,
  23374. maxNumCols: 20,
  23375. numRows: 10,
  23376. numCols: 10,
  23377. lengthOfCellSide: 22,
  23378. initTablePicker: function (){
  23379. this.initUIBase();
  23380. },
  23381. getHtmlTpl: function (){
  23382. var me = this;
  23383. return '<div id="##" class="edui-tablepicker %%">' +
  23384. '<div class="edui-tablepicker-body">' +
  23385. '<div class="edui-infoarea">' +
  23386. '<span id="##_label" class="edui-label"></span>' +
  23387. '</div>' +
  23388. '<div class="edui-pickarea"' +
  23389. ' onmousemove="$$._onMouseMove(event, this);"' +
  23390. ' onmouseover="$$._onMouseOver(event, this);"' +
  23391. ' onmouseout="$$._onMouseOut(event, this);"' +
  23392. ' onclick="$$._onClick(event, this);"' +
  23393. '>' +
  23394. '<div id="##_overlay" class="edui-overlay"></div>' +
  23395. '</div>' +
  23396. '</div>' +
  23397. '</div>';
  23398. },
  23399. _UIBase_render: UIBase.prototype.render,
  23400. render: function (holder){
  23401. this._UIBase_render(holder);
  23402. this.getDom('label').innerHTML = '0'+this.editor.getLang("t_row")+' x 0'+this.editor.getLang("t_col");
  23403. },
  23404. _track: function (numCols, numRows){
  23405. var style = this.getDom('overlay').style;
  23406. var sideLen = this.lengthOfCellSide;
  23407. style.width = numCols * sideLen + 'px';
  23408. style.height = numRows * sideLen + 'px';
  23409. var label = this.getDom('label');
  23410. label.innerHTML = numCols +this.editor.getLang("t_col")+' x ' + numRows + this.editor.getLang("t_row");
  23411. this.numCols = numCols;
  23412. this.numRows = numRows;
  23413. },
  23414. _onMouseOver: function (evt, el){
  23415. var rel = evt.relatedTarget || evt.fromElement;
  23416. if (!uiUtils.contains(el, rel) && el !== rel) {
  23417. this.getDom('label').innerHTML = '0'+this.editor.getLang("t_col")+' x 0'+this.editor.getLang("t_row");
  23418. this.getDom('overlay').style.visibility = '';
  23419. }
  23420. },
  23421. _onMouseOut: function (evt, el){
  23422. var rel = evt.relatedTarget || evt.toElement;
  23423. if (!uiUtils.contains(el, rel) && el !== rel) {
  23424. this.getDom('label').innerHTML = '0'+this.editor.getLang("t_col")+' x 0'+this.editor.getLang("t_row");
  23425. this.getDom('overlay').style.visibility = 'hidden';
  23426. }
  23427. },
  23428. _onMouseMove: function (evt, el){
  23429. var style = this.getDom('overlay').style;
  23430. var offset = uiUtils.getEventOffset(evt);
  23431. var sideLen = this.lengthOfCellSide;
  23432. var numCols = Math.ceil(offset.left / sideLen);
  23433. var numRows = Math.ceil(offset.top / sideLen);
  23434. this._track(numCols, numRows);
  23435. },
  23436. _onClick: function (){
  23437. this.fireEvent('picktable', this.numCols, this.numRows);
  23438. }
  23439. };
  23440. utils.inherits(TablePicker, UIBase);
  23441. })();
  23442. // ui/stateful.js
  23443. (function (){
  23444. var browser = baidu.editor.browser,
  23445. domUtils = baidu.editor.dom.domUtils,
  23446. uiUtils = baidu.editor.ui.uiUtils;
  23447. var TPL_STATEFUL = 'onmousedown="$$.Stateful_onMouseDown(event, this);"' +
  23448. ' onmouseup="$$.Stateful_onMouseUp(event, this);"' +
  23449. ( browser.ie ? (
  23450. ' onmouseenter="$$.Stateful_onMouseEnter(event, this);"' +
  23451. ' onmouseleave="$$.Stateful_onMouseLeave(event, this);"' )
  23452. : (
  23453. ' onmouseover="$$.Stateful_onMouseOver(event, this);"' +
  23454. ' onmouseout="$$.Stateful_onMouseOut(event, this);"' ));
  23455. baidu.editor.ui.Stateful = {
  23456. alwalysHoverable: false,
  23457. target:null,//目标元素和this指向dom不一样
  23458. Stateful_init: function (){
  23459. this._Stateful_dGetHtmlTpl = this.getHtmlTpl;
  23460. this.getHtmlTpl = this.Stateful_getHtmlTpl;
  23461. },
  23462. Stateful_getHtmlTpl: function (){
  23463. var tpl = this._Stateful_dGetHtmlTpl();
  23464. // 使用function避免$转义
  23465. return tpl.replace(/stateful/g, function (){ return TPL_STATEFUL; });
  23466. },
  23467. Stateful_onMouseEnter: function (evt, el){
  23468. this.target=el;
  23469. if (!this.isDisabled() || this.alwalysHoverable) {
  23470. this.addState('hover');
  23471. this.fireEvent('over');
  23472. }
  23473. },
  23474. Stateful_onMouseLeave: function (evt, el){
  23475. if (!this.isDisabled() || this.alwalysHoverable) {
  23476. this.removeState('hover');
  23477. this.removeState('active');
  23478. this.fireEvent('out');
  23479. }
  23480. },
  23481. Stateful_onMouseOver: function (evt, el){
  23482. var rel = evt.relatedTarget;
  23483. if (!uiUtils.contains(el, rel) && el !== rel) {
  23484. this.Stateful_onMouseEnter(evt, el);
  23485. }
  23486. },
  23487. Stateful_onMouseOut: function (evt, el){
  23488. var rel = evt.relatedTarget;
  23489. if (!uiUtils.contains(el, rel) && el !== rel) {
  23490. this.Stateful_onMouseLeave(evt, el);
  23491. }
  23492. },
  23493. Stateful_onMouseDown: function (evt, el){
  23494. if (!this.isDisabled()) {
  23495. this.addState('active');
  23496. }
  23497. },
  23498. Stateful_onMouseUp: function (evt, el){
  23499. if (!this.isDisabled()) {
  23500. this.removeState('active');
  23501. }
  23502. },
  23503. Stateful_postRender: function (){
  23504. if (this.disabled && !this.hasState('disabled')) {
  23505. this.addState('disabled');
  23506. }
  23507. },
  23508. hasState: function (state){
  23509. return domUtils.hasClass(this.getStateDom(), 'edui-state-' + state);
  23510. },
  23511. addState: function (state){
  23512. if (!this.hasState(state)) {
  23513. this.getStateDom().className += ' edui-state-' + state;
  23514. }
  23515. },
  23516. removeState: function (state){
  23517. if (this.hasState(state)) {
  23518. domUtils.removeClasses(this.getStateDom(), ['edui-state-' + state]);
  23519. }
  23520. },
  23521. getStateDom: function (){
  23522. return this.getDom('state');
  23523. },
  23524. isChecked: function (){
  23525. return this.hasState('checked');
  23526. },
  23527. setChecked: function (checked){
  23528. if (!this.isDisabled() && checked) {
  23529. this.addState('checked');
  23530. } else {
  23531. this.removeState('checked');
  23532. }
  23533. },
  23534. isDisabled: function (){
  23535. return this.hasState('disabled');
  23536. },
  23537. setDisabled: function (disabled){
  23538. if (disabled) {
  23539. this.removeState('hover');
  23540. this.removeState('checked');
  23541. this.removeState('active');
  23542. this.addState('disabled');
  23543. } else {
  23544. this.removeState('disabled');
  23545. }
  23546. }
  23547. };
  23548. })();
  23549. // ui/button.js
  23550. ///import core
  23551. ///import uicore
  23552. ///import ui/stateful.js
  23553. (function (){
  23554. var utils = baidu.editor.utils,
  23555. UIBase = baidu.editor.ui.UIBase,
  23556. Stateful = baidu.editor.ui.Stateful,
  23557. Button = baidu.editor.ui.Button = function (options){
  23558. if(options.name){
  23559. var btnName = options.name;
  23560. var cssRules = options.cssRules;
  23561. if(!options.className){
  23562. options.className = 'edui-for-' + btnName;
  23563. }
  23564. options.cssRules = '.edui-default .edui-for-'+ btnName +' .edui-icon {'+ cssRules +'}'
  23565. }
  23566. this.initOptions(options);
  23567. this.initButton();
  23568. };
  23569. Button.prototype = {
  23570. uiName: 'button',
  23571. label: '',
  23572. title: '',
  23573. showIcon: true,
  23574. showText: true,
  23575. cssRules:'',
  23576. initButton: function (){
  23577. this.initUIBase();
  23578. this.Stateful_init();
  23579. if(this.cssRules){
  23580. utils.cssRule('edui-customize-'+this.name+'-style',this.cssRules);
  23581. }
  23582. },
  23583. getHtmlTpl: function (){
  23584. return '<div id="##" class="edui-box %%">' +
  23585. '<div id="##_state" stateful>' +
  23586. '<div class="%%-wrap"><div id="##_body" unselectable="on" ' + (this.title ? 'title="' + this.title + '"' : '') +
  23587. ' class="%%-body" onmousedown="return $$._onMouseDown(event, this);" onclick="return $$._onClick(event, this);">' +
  23588. (this.showIcon ? '<div class="edui-box edui-icon"></div>' : '') +
  23589. (this.showText ? '<div class="edui-box edui-label">' + this.label + '</div>' : '') +
  23590. '</div>' +
  23591. '</div>' +
  23592. '</div></div>';
  23593. },
  23594. postRender: function (){
  23595. this.Stateful_postRender();
  23596. this.setDisabled(this.disabled)
  23597. },
  23598. _onMouseDown: function (e){
  23599. var target = e.target || e.srcElement,
  23600. tagName = target && target.tagName && target.tagName.toLowerCase();
  23601. if (tagName == 'input' || tagName == 'object' || tagName == 'object') {
  23602. return false;
  23603. }
  23604. },
  23605. _onClick: function (){
  23606. if (!this.isDisabled()) {
  23607. this.fireEvent('click');
  23608. }
  23609. },
  23610. setTitle: function(text){
  23611. var label = this.getDom('label');
  23612. label.innerHTML = text;
  23613. }
  23614. };
  23615. utils.inherits(Button, UIBase);
  23616. utils.extend(Button.prototype, Stateful);
  23617. })();
  23618. // ui/splitbutton.js
  23619. ///import core
  23620. ///import uicore
  23621. ///import ui/stateful.js
  23622. (function (){
  23623. var utils = baidu.editor.utils,
  23624. uiUtils = baidu.editor.ui.uiUtils,
  23625. domUtils = baidu.editor.dom.domUtils,
  23626. UIBase = baidu.editor.ui.UIBase,
  23627. Stateful = baidu.editor.ui.Stateful,
  23628. SplitButton = baidu.editor.ui.SplitButton = function (options){
  23629. this.initOptions(options);
  23630. this.initSplitButton();
  23631. };
  23632. SplitButton.prototype = {
  23633. popup: null,
  23634. uiName: 'splitbutton',
  23635. title: '',
  23636. initSplitButton: function (){
  23637. this.initUIBase();
  23638. this.Stateful_init();
  23639. var me = this;
  23640. if (this.popup != null) {
  23641. var popup = this.popup;
  23642. this.popup = null;
  23643. this.setPopup(popup);
  23644. }
  23645. },
  23646. _UIBase_postRender: UIBase.prototype.postRender,
  23647. postRender: function (){
  23648. this.Stateful_postRender();
  23649. this._UIBase_postRender();
  23650. },
  23651. setPopup: function (popup){
  23652. if (this.popup === popup) return;
  23653. if (this.popup != null) {
  23654. this.popup.dispose();
  23655. }
  23656. popup.addListener('show', utils.bind(this._onPopupShow, this));
  23657. popup.addListener('hide', utils.bind(this._onPopupHide, this));
  23658. popup.addListener('postrender', utils.bind(function (){
  23659. popup.getDom('body').appendChild(
  23660. uiUtils.createElementByHtml('<div id="' +
  23661. this.popup.id + '_bordereraser" class="edui-bordereraser edui-background" style="width:' +
  23662. (uiUtils.getClientRect(this.getDom()).width + 20) + 'px"></div>')
  23663. );
  23664. popup.getDom().className += ' ' + this.className;
  23665. }, this));
  23666. this.popup = popup;
  23667. },
  23668. _onPopupShow: function (){
  23669. this.addState('opened');
  23670. },
  23671. _onPopupHide: function (){
  23672. this.removeState('opened');
  23673. },
  23674. getHtmlTpl: function (){
  23675. return '<div id="##" class="edui-box %%">' +
  23676. '<div '+ (this.title ? 'title="' + this.title + '"' : '') +' id="##_state" stateful><div class="%%-body">' +
  23677. '<div id="##_button_body" class="edui-box edui-button-body" onclick="$$._onButtonClick(event, this);">' +
  23678. '<div class="edui-box edui-icon"></div>' +
  23679. '</div>' +
  23680. '<div class="edui-box edui-splitborder"></div>' +
  23681. '<div class="edui-box edui-arrow" onclick="$$._onArrowClick();"></div>' +
  23682. '</div></div></div>';
  23683. },
  23684. showPopup: function (){
  23685. // 当popup往上弹出的时候,做特殊处理
  23686. var rect = uiUtils.getClientRect(this.getDom());
  23687. rect.top -= this.popup.SHADOW_RADIUS;
  23688. rect.height += this.popup.SHADOW_RADIUS;
  23689. this.popup.showAnchorRect(rect);
  23690. },
  23691. _onArrowClick: function (event, el){
  23692. if (!this.isDisabled()) {
  23693. this.showPopup();
  23694. }
  23695. },
  23696. _onButtonClick: function (){
  23697. if (!this.isDisabled()) {
  23698. this.fireEvent('buttonclick');
  23699. }
  23700. }
  23701. };
  23702. utils.inherits(SplitButton, UIBase);
  23703. utils.extend(SplitButton.prototype, Stateful, true);
  23704. })();
  23705. // ui/colorbutton.js
  23706. ///import core
  23707. ///import uicore
  23708. ///import ui/colorpicker.js
  23709. ///import ui/popup.js
  23710. ///import ui/splitbutton.js
  23711. (function (){
  23712. var utils = baidu.editor.utils,
  23713. uiUtils = baidu.editor.ui.uiUtils,
  23714. ColorPicker = baidu.editor.ui.ColorPicker,
  23715. Popup = baidu.editor.ui.Popup,
  23716. SplitButton = baidu.editor.ui.SplitButton,
  23717. ColorButton = baidu.editor.ui.ColorButton = function (options){
  23718. this.initOptions(options);
  23719. this.initColorButton();
  23720. };
  23721. ColorButton.prototype = {
  23722. initColorButton: function (){
  23723. var me = this;
  23724. this.popup = new Popup({
  23725. content: new ColorPicker({
  23726. noColorText: me.editor.getLang("clearColor"),
  23727. editor:me.editor,
  23728. onpickcolor: function (t, color){
  23729. me._onPickColor(color);
  23730. },
  23731. onpicknocolor: function (t, color){
  23732. me._onPickNoColor(color);
  23733. }
  23734. }),
  23735. editor:me.editor
  23736. });
  23737. this.initSplitButton();
  23738. },
  23739. _SplitButton_postRender: SplitButton.prototype.postRender,
  23740. postRender: function (){
  23741. this._SplitButton_postRender();
  23742. this.getDom('button_body').appendChild(
  23743. uiUtils.createElementByHtml('<div id="' + this.id + '_colorlump" class="edui-colorlump"></div>')
  23744. );
  23745. this.getDom().className += ' edui-colorbutton';
  23746. },
  23747. setColor: function (color){
  23748. this.getDom('colorlump').style.backgroundColor = color;
  23749. this.color = color;
  23750. },
  23751. _onPickColor: function (color){
  23752. if (this.fireEvent('pickcolor', color) !== false) {
  23753. this.setColor(color);
  23754. this.popup.hide();
  23755. }
  23756. },
  23757. _onPickNoColor: function (color){
  23758. if (this.fireEvent('picknocolor') !== false) {
  23759. this.popup.hide();
  23760. }
  23761. }
  23762. };
  23763. utils.inherits(ColorButton, SplitButton);
  23764. })();
  23765. // ui/tablebutton.js
  23766. ///import core
  23767. ///import uicore
  23768. ///import ui/popup.js
  23769. ///import ui/tablepicker.js
  23770. ///import ui/splitbutton.js
  23771. (function (){
  23772. var utils = baidu.editor.utils,
  23773. Popup = baidu.editor.ui.Popup,
  23774. TablePicker = baidu.editor.ui.TablePicker,
  23775. SplitButton = baidu.editor.ui.SplitButton,
  23776. TableButton = baidu.editor.ui.TableButton = function (options){
  23777. this.initOptions(options);
  23778. this.initTableButton();
  23779. };
  23780. TableButton.prototype = {
  23781. initTableButton: function (){
  23782. var me = this;
  23783. this.popup = new Popup({
  23784. content: new TablePicker({
  23785. editor:me.editor,
  23786. onpicktable: function (t, numCols, numRows){
  23787. me._onPickTable(numCols, numRows);
  23788. }
  23789. }),
  23790. 'editor':me.editor
  23791. });
  23792. this.initSplitButton();
  23793. },
  23794. _onPickTable: function (numCols, numRows){
  23795. if (this.fireEvent('picktable', numCols, numRows) !== false) {
  23796. this.popup.hide();
  23797. }
  23798. }
  23799. };
  23800. utils.inherits(TableButton, SplitButton);
  23801. })();
  23802. // ui/autotypesetpicker.js
  23803. ///import core
  23804. ///import uicore
  23805. (function () {
  23806. var utils = baidu.editor.utils,
  23807. UIBase = baidu.editor.ui.UIBase;
  23808. var AutoTypeSetPicker = baidu.editor.ui.AutoTypeSetPicker = function (options) {
  23809. this.initOptions(options);
  23810. this.initAutoTypeSetPicker();
  23811. };
  23812. AutoTypeSetPicker.prototype = {
  23813. initAutoTypeSetPicker:function () {
  23814. this.initUIBase();
  23815. },
  23816. getHtmlTpl:function () {
  23817. var me = this.editor,
  23818. opt = me.options.autotypeset,
  23819. lang = me.getLang("autoTypeSet");
  23820. var textAlignInputName = 'textAlignValue' + me.uid,
  23821. imageBlockInputName = 'imageBlockLineValue' + me.uid,
  23822. symbolConverInputName = 'symbolConverValue' + me.uid;
  23823. return '<div id="##" class="edui-autotypesetpicker %%">' +
  23824. '<div class="edui-autotypesetpicker-body">' +
  23825. '<table >' +
  23826. '<tr><td nowrap><input type="checkbox" name="mergeEmptyline" ' + (opt["mergeEmptyline"] ? "checked" : "" ) + '>' + lang.mergeLine + '</td><td colspan="2"><input type="checkbox" name="removeEmptyline" ' + (opt["removeEmptyline"] ? "checked" : "" ) + '>' + lang.delLine + '</td></tr>' +
  23827. '<tr><td nowrap><input type="checkbox" name="removeClass" ' + (opt["removeClass"] ? "checked" : "" ) + '>' + lang.removeFormat + '</td><td colspan="2"><input type="checkbox" name="indent" ' + (opt["indent"] ? "checked" : "" ) + '>' + lang.indent + '</td></tr>' +
  23828. '<tr>' +
  23829. '<td nowrap><input type="checkbox" name="textAlign" ' + (opt["textAlign"] ? "checked" : "" ) + '>' + lang.alignment + '</td>' +
  23830. '<td colspan="2" id="' + textAlignInputName + '">' +
  23831. '<input type="radio" name="'+ textAlignInputName +'" value="left" ' + ((opt["textAlign"] && opt["textAlign"] == "left") ? "checked" : "") + '>' + me.getLang("justifyleft") +
  23832. '<input type="radio" name="'+ textAlignInputName +'" value="center" ' + ((opt["textAlign"] && opt["textAlign"] == "center") ? "checked" : "") + '>' + me.getLang("justifycenter") +
  23833. '<input type="radio" name="'+ textAlignInputName +'" value="right" ' + ((opt["textAlign"] && opt["textAlign"] == "right") ? "checked" : "") + '>' + me.getLang("justifyright") +
  23834. '</td>' +
  23835. '</tr>' +
  23836. '<tr>' +
  23837. '<td nowrap><input type="checkbox" name="imageBlockLine" ' + (opt["imageBlockLine"] ? "checked" : "" ) + '>' + lang.imageFloat + '</td>' +
  23838. '<td nowrap id="'+ imageBlockInputName +'">' +
  23839. '<input type="radio" name="'+ imageBlockInputName +'" value="none" ' + ((opt["imageBlockLine"] && opt["imageBlockLine"] == "none") ? "checked" : "") + '>' + me.getLang("default") +
  23840. '<input type="radio" name="'+ imageBlockInputName +'" value="left" ' + ((opt["imageBlockLine"] && opt["imageBlockLine"] == "left") ? "checked" : "") + '>' + me.getLang("justifyleft") +
  23841. '<input type="radio" name="'+ imageBlockInputName +'" value="center" ' + ((opt["imageBlockLine"] && opt["imageBlockLine"] == "center") ? "checked" : "") + '>' + me.getLang("justifycenter") +
  23842. '<input type="radio" name="'+ imageBlockInputName +'" value="right" ' + ((opt["imageBlockLine"] && opt["imageBlockLine"] == "right") ? "checked" : "") + '>' + me.getLang("justifyright") +
  23843. '</td>' +
  23844. '</tr>' +
  23845. '<tr><td nowrap><input type="checkbox" name="clearFontSize" ' + (opt["clearFontSize"] ? "checked" : "" ) + '>' + lang.removeFontsize + '</td><td colspan="2"><input type="checkbox" name="clearFontFamily" ' + (opt["clearFontFamily"] ? "checked" : "" ) + '>' + lang.removeFontFamily + '</td></tr>' +
  23846. '<tr><td nowrap colspan="3"><input type="checkbox" name="removeEmptyNode" ' + (opt["removeEmptyNode"] ? "checked" : "" ) + '>' + lang.removeHtml + '</td></tr>' +
  23847. '<tr><td nowrap colspan="3"><input type="checkbox" name="pasteFilter" ' + (opt["pasteFilter"] ? "checked" : "" ) + '>' + lang.pasteFilter + '</td></tr>' +
  23848. '<tr>' +
  23849. '<td nowrap><input type="checkbox" name="symbolConver" ' + (opt["bdc2sb"] || opt["tobdc"] ? "checked" : "" ) + '>' + lang.symbol + '</td>' +
  23850. '<td id="' + symbolConverInputName + '">' +
  23851. '<input type="radio" name="bdc" value="bdc2sb" ' + (opt["bdc2sb"] ? "checked" : "" ) + '>' + lang.bdc2sb +
  23852. '<input type="radio" name="bdc" value="tobdc" ' + (opt["tobdc"] ? "checked" : "" ) + '>' + lang.tobdc + '' +
  23853. '</td>' +
  23854. '<td nowrap align="right"><button >' + lang.run + '</button></td>' +
  23855. '</tr>' +
  23856. '</table>' +
  23857. '</div>' +
  23858. '</div>';
  23859. },
  23860. _UIBase_render:UIBase.prototype.render
  23861. };
  23862. utils.inherits(AutoTypeSetPicker, UIBase);
  23863. })();
  23864. // ui/autotypesetbutton.js
  23865. ///import core
  23866. ///import uicore
  23867. ///import ui/popup.js
  23868. ///import ui/autotypesetpicker.js
  23869. ///import ui/splitbutton.js
  23870. (function (){
  23871. var utils = baidu.editor.utils,
  23872. Popup = baidu.editor.ui.Popup,
  23873. AutoTypeSetPicker = baidu.editor.ui.AutoTypeSetPicker,
  23874. SplitButton = baidu.editor.ui.SplitButton,
  23875. AutoTypeSetButton = baidu.editor.ui.AutoTypeSetButton = function (options){
  23876. this.initOptions(options);
  23877. this.initAutoTypeSetButton();
  23878. };
  23879. function getPara(me){
  23880. var opt = {},
  23881. cont = me.getDom(),
  23882. editorId = me.editor.uid,
  23883. inputType = null,
  23884. attrName = null,
  23885. ipts = domUtils.getElementsByTagName(cont,"input");
  23886. for(var i=ipts.length-1,ipt;ipt=ipts[i--];){
  23887. inputType = ipt.getAttribute("type");
  23888. if(inputType=="checkbox"){
  23889. attrName = ipt.getAttribute("name");
  23890. opt[attrName] && delete opt[attrName];
  23891. if(ipt.checked){
  23892. var attrValue = document.getElementById( attrName + "Value" + editorId );
  23893. if(attrValue){
  23894. if(/input/ig.test(attrValue.tagName)){
  23895. opt[attrName] = attrValue.value;
  23896. } else {
  23897. var iptChilds = attrValue.getElementsByTagName("input");
  23898. for(var j=iptChilds.length-1,iptchild;iptchild=iptChilds[j--];){
  23899. if(iptchild.checked){
  23900. opt[attrName] = iptchild.value;
  23901. break;
  23902. }
  23903. }
  23904. }
  23905. } else {
  23906. opt[attrName] = true;
  23907. }
  23908. } else {
  23909. opt[attrName] = false;
  23910. }
  23911. } else {
  23912. opt[ipt.getAttribute("value")] = ipt.checked;
  23913. }
  23914. }
  23915. var selects = domUtils.getElementsByTagName(cont,"select");
  23916. for(var i=0,si;si=selects[i++];){
  23917. var attr = si.getAttribute('name');
  23918. opt[attr] = opt[attr] ? si.value : '';
  23919. }
  23920. utils.extend(me.editor.options.autotypeset,opt);
  23921. me.editor.setPreferences('autotypeset', opt);
  23922. }
  23923. AutoTypeSetButton.prototype = {
  23924. initAutoTypeSetButton: function (){
  23925. var me = this;
  23926. this.popup = new Popup({
  23927. //传入配置参数
  23928. content: new AutoTypeSetPicker({editor:me.editor}),
  23929. 'editor':me.editor,
  23930. hide : function(){
  23931. if (!this._hidden && this.getDom()) {
  23932. getPara(this);
  23933. this.getDom().style.display = 'none';
  23934. this._hidden = true;
  23935. this.fireEvent('hide');
  23936. }
  23937. }
  23938. });
  23939. var flag = 0;
  23940. this.popup.addListener('postRenderAfter',function(){
  23941. var popupUI = this;
  23942. if(flag)return;
  23943. var cont = this.getDom(),
  23944. btn = cont.getElementsByTagName('button')[0];
  23945. btn.onclick = function(){
  23946. getPara(popupUI);
  23947. me.editor.execCommand('autotypeset');
  23948. popupUI.hide()
  23949. };
  23950. domUtils.on(cont, 'click', function(e) {
  23951. var target = e.target || e.srcElement,
  23952. editorId = me.editor.uid;
  23953. if (target && target.tagName == 'INPUT') {
  23954. // 点击图片浮动的checkbox,去除对应的radio
  23955. if (target.name == 'imageBlockLine' || target.name == 'textAlign' || target.name == 'symbolConver') {
  23956. var checked = target.checked,
  23957. radioTd = document.getElementById( target.name + 'Value' + editorId),
  23958. radios = radioTd.getElementsByTagName('input'),
  23959. defalutSelect = {
  23960. 'imageBlockLine': 'none',
  23961. 'textAlign': 'left',
  23962. 'symbolConver': 'tobdc'
  23963. };
  23964. for (var i = 0; i < radios.length; i++) {
  23965. if (checked) {
  23966. if (radios[i].value == defalutSelect[target.name]) {
  23967. radios[i].checked = 'checked';
  23968. }
  23969. } else {
  23970. radios[i].checked = false;
  23971. }
  23972. }
  23973. }
  23974. // 点击radio,选中对应的checkbox
  23975. if (target.name == ('imageBlockLineValue' + editorId) || target.name == ('textAlignValue' + editorId) || target.name == 'bdc') {
  23976. var checkboxs = target.parentNode.previousSibling.getElementsByTagName('input');
  23977. checkboxs && (checkboxs[0].checked = true);
  23978. }
  23979. getPara(popupUI);
  23980. }
  23981. });
  23982. flag = 1;
  23983. });
  23984. this.initSplitButton();
  23985. }
  23986. };
  23987. utils.inherits(AutoTypeSetButton, SplitButton);
  23988. })();
  23989. // ui/cellalignpicker.js
  23990. ///import core
  23991. ///import uicore
  23992. (function () {
  23993. var utils = baidu.editor.utils,
  23994. Popup = baidu.editor.ui.Popup,
  23995. Stateful = baidu.editor.ui.Stateful,
  23996. UIBase = baidu.editor.ui.UIBase;
  23997. /**
  23998. * 该参数将新增一个参数: selected, 参数类型为一个Object, 形如{ 'align': 'center', 'valign': 'top' }, 表示单元格的初始
  23999. * 对齐状态为: 竖直居上,水平居中; 其中 align的取值为:'center', 'left', 'right'; valign的取值为: 'top', 'middle', 'bottom'
  24000. * @update 2013/4/2 hancong03@baidu.com
  24001. */
  24002. var CellAlignPicker = baidu.editor.ui.CellAlignPicker = function (options) {
  24003. this.initOptions(options);
  24004. this.initSelected();
  24005. this.initCellAlignPicker();
  24006. };
  24007. CellAlignPicker.prototype = {
  24008. //初始化选中状态, 该方法将根据传递进来的参数获取到应该选中的对齐方式图标的索引
  24009. initSelected: function(){
  24010. var status = {
  24011. valign: {
  24012. top: 0,
  24013. middle: 1,
  24014. bottom: 2
  24015. },
  24016. align: {
  24017. left: 0,
  24018. center: 1,
  24019. right: 2
  24020. },
  24021. count: 3
  24022. },
  24023. result = -1;
  24024. if( this.selected ) {
  24025. this.selectedIndex = status.valign[ this.selected.valign ] * status.count + status.align[ this.selected.align ];
  24026. }
  24027. },
  24028. initCellAlignPicker:function () {
  24029. this.initUIBase();
  24030. this.Stateful_init();
  24031. },
  24032. getHtmlTpl:function () {
  24033. var alignType = [ 'left', 'center', 'right' ],
  24034. COUNT = 9,
  24035. tempClassName = null,
  24036. tempIndex = -1,
  24037. tmpl = [];
  24038. for( var i= 0; i<COUNT; i++ ) {
  24039. tempClassName = this.selectedIndex === i ? ' class="edui-cellalign-selected" ' : '';
  24040. tempIndex = i % 3;
  24041. tempIndex === 0 && tmpl.push('<tr>');
  24042. tmpl.push( '<td index="'+ i +'" ' + tempClassName + ' stateful><div class="edui-icon edui-'+ alignType[ tempIndex ] +'"></div></td>' );
  24043. tempIndex === 2 && tmpl.push('</tr>');
  24044. }
  24045. return '<div id="##" class="edui-cellalignpicker %%">' +
  24046. '<div class="edui-cellalignpicker-body">' +
  24047. '<table onclick="$$._onClick(event);">' +
  24048. tmpl.join('') +
  24049. '</table>' +
  24050. '</div>' +
  24051. '</div>';
  24052. },
  24053. getStateDom: function (){
  24054. return this.target;
  24055. },
  24056. _onClick: function (evt){
  24057. var target= evt.target || evt.srcElement;
  24058. if(/icon/.test(target.className)){
  24059. this.items[target.parentNode.getAttribute("index")].onclick();
  24060. Popup.postHide(evt);
  24061. }
  24062. },
  24063. _UIBase_render:UIBase.prototype.render
  24064. };
  24065. utils.inherits(CellAlignPicker, UIBase);
  24066. utils.extend(CellAlignPicker.prototype, Stateful,true);
  24067. })();
  24068. // ui/pastepicker.js
  24069. ///import core
  24070. ///import uicore
  24071. (function () {
  24072. var utils = baidu.editor.utils,
  24073. Stateful = baidu.editor.ui.Stateful,
  24074. uiUtils = baidu.editor.ui.uiUtils,
  24075. UIBase = baidu.editor.ui.UIBase;
  24076. var PastePicker = baidu.editor.ui.PastePicker = function (options) {
  24077. this.initOptions(options);
  24078. this.initPastePicker();
  24079. };
  24080. PastePicker.prototype = {
  24081. initPastePicker:function () {
  24082. this.initUIBase();
  24083. this.Stateful_init();
  24084. },
  24085. getHtmlTpl:function () {
  24086. return '<div class="edui-pasteicon" onclick="$$._onClick(this)"></div>' +
  24087. '<div class="edui-pastecontainer">' +
  24088. '<div class="edui-title">' + this.editor.getLang("pasteOpt") + '</div>' +
  24089. '<div class="edui-button">' +
  24090. '<div title="' + this.editor.getLang("pasteSourceFormat") + '" onclick="$$.format(false)" stateful>' +
  24091. '<div class="edui-richtxticon"></div></div>' +
  24092. '<div title="' + this.editor.getLang("tagFormat") + '" onclick="$$.format(2)" stateful>' +
  24093. '<div class="edui-tagicon"></div></div>' +
  24094. '<div title="' + this.editor.getLang("pasteTextFormat") + '" onclick="$$.format(true)" stateful>' +
  24095. '<div class="edui-plaintxticon"></div></div>' +
  24096. '</div>' +
  24097. '</div>' +
  24098. '</div>'
  24099. },
  24100. getStateDom:function () {
  24101. return this.target;
  24102. },
  24103. format:function (param) {
  24104. this.editor.ui._isTransfer = true;
  24105. this.editor.fireEvent('pasteTransfer', param);
  24106. },
  24107. _onClick:function (cur) {
  24108. var node = domUtils.getNextDomNode(cur),
  24109. screenHt = uiUtils.getViewportRect().height,
  24110. subPop = uiUtils.getClientRect(node);
  24111. if ((subPop.top + subPop.height) > screenHt)
  24112. node.style.top = (-subPop.height - cur.offsetHeight) + "px";
  24113. else
  24114. node.style.top = "";
  24115. if (/hidden/ig.test(domUtils.getComputedStyle(node, "visibility"))) {
  24116. node.style.visibility = "visible";
  24117. domUtils.addClass(cur, "edui-state-opened");
  24118. } else {
  24119. node.style.visibility = "hidden";
  24120. domUtils.removeClasses(cur, "edui-state-opened")
  24121. }
  24122. },
  24123. _UIBase_render:UIBase.prototype.render
  24124. };
  24125. utils.inherits(PastePicker, UIBase);
  24126. utils.extend(PastePicker.prototype, Stateful, true);
  24127. })();
  24128. // ui/toolbar.js
  24129. (function (){
  24130. var utils = baidu.editor.utils,
  24131. uiUtils = baidu.editor.ui.uiUtils,
  24132. UIBase = baidu.editor.ui.UIBase,
  24133. Toolbar = baidu.editor.ui.Toolbar = function (options){
  24134. this.initOptions(options);
  24135. this.initToolbar();
  24136. };
  24137. Toolbar.prototype = {
  24138. items: null,
  24139. initToolbar: function (){
  24140. this.items = this.items || [];
  24141. this.initUIBase();
  24142. },
  24143. add: function (item,index){
  24144. if(index === undefined){
  24145. this.items.push(item);
  24146. }else{
  24147. this.items.splice(index,0,item)
  24148. }
  24149. },
  24150. getHtmlTpl: function (){
  24151. var buff = [];
  24152. for (var i=0; i<this.items.length; i++) {
  24153. buff[i] = this.items[i].renderHtml();
  24154. }
  24155. return '<div id="##" class="edui-toolbar %%" onselectstart="return false;" onmousedown="return $$._onMouseDown(event, this);">' +
  24156. buff.join('') +
  24157. '</div>'
  24158. },
  24159. postRender: function (){
  24160. var box = this.getDom();
  24161. for (var i=0; i<this.items.length; i++) {
  24162. this.items[i].postRender();
  24163. }
  24164. uiUtils.makeUnselectable(box);
  24165. },
  24166. _onMouseDown: function (e){
  24167. var target = e.target || e.srcElement,
  24168. tagName = target && target.tagName && target.tagName.toLowerCase();
  24169. if (tagName == 'input' || tagName == 'object' || tagName == 'object') {
  24170. return false;
  24171. }
  24172. }
  24173. };
  24174. utils.inherits(Toolbar, UIBase);
  24175. })();
  24176. // ui/menu.js
  24177. ///import core
  24178. ///import uicore
  24179. ///import ui\popup.js
  24180. ///import ui\stateful.js
  24181. (function () {
  24182. var utils = baidu.editor.utils,
  24183. domUtils = baidu.editor.dom.domUtils,
  24184. uiUtils = baidu.editor.ui.uiUtils,
  24185. UIBase = baidu.editor.ui.UIBase,
  24186. Popup = baidu.editor.ui.Popup,
  24187. Stateful = baidu.editor.ui.Stateful,
  24188. CellAlignPicker = baidu.editor.ui.CellAlignPicker,
  24189. Menu = baidu.editor.ui.Menu = function (options) {
  24190. this.initOptions(options);
  24191. this.initMenu();
  24192. };
  24193. var menuSeparator = {
  24194. renderHtml:function () {
  24195. return '<div class="edui-menuitem edui-menuseparator"><div class="edui-menuseparator-inner"></div></div>';
  24196. },
  24197. postRender:function () {
  24198. },
  24199. queryAutoHide:function () {
  24200. return true;
  24201. }
  24202. };
  24203. Menu.prototype = {
  24204. items:null,
  24205. uiName:'menu',
  24206. initMenu:function () {
  24207. this.items = this.items || [];
  24208. this.initPopup();
  24209. this.initItems();
  24210. },
  24211. initItems:function () {
  24212. for (var i = 0; i < this.items.length; i++) {
  24213. var item = this.items[i];
  24214. if (item == '-') {
  24215. this.items[i] = this.getSeparator();
  24216. } else if (!(item instanceof MenuItem)) {
  24217. item.editor = this.editor;
  24218. item.theme = this.editor.options.theme;
  24219. this.items[i] = this.createItem(item);
  24220. }
  24221. }
  24222. },
  24223. getSeparator:function () {
  24224. return menuSeparator;
  24225. },
  24226. createItem:function (item) {
  24227. //新增一个参数menu, 该参数存储了menuItem所对应的menu引用
  24228. item.menu = this;
  24229. return new MenuItem(item);
  24230. },
  24231. _Popup_getContentHtmlTpl:Popup.prototype.getContentHtmlTpl,
  24232. getContentHtmlTpl:function () {
  24233. if (this.items.length == 0) {
  24234. return this._Popup_getContentHtmlTpl();
  24235. }
  24236. var buff = [];
  24237. for (var i = 0; i < this.items.length; i++) {
  24238. var item = this.items[i];
  24239. buff[i] = item.renderHtml();
  24240. }
  24241. return ('<div class="%%-body">' + buff.join('') + '</div>');
  24242. },
  24243. _Popup_postRender:Popup.prototype.postRender,
  24244. postRender:function () {
  24245. var me = this;
  24246. for (var i = 0; i < this.items.length; i++) {
  24247. var item = this.items[i];
  24248. item.ownerMenu = this;
  24249. item.postRender();
  24250. }
  24251. domUtils.on(this.getDom(), 'mouseover', function (evt) {
  24252. evt = evt || event;
  24253. var rel = evt.relatedTarget || evt.fromElement;
  24254. var el = me.getDom();
  24255. if (!uiUtils.contains(el, rel) && el !== rel) {
  24256. me.fireEvent('over');
  24257. }
  24258. });
  24259. this._Popup_postRender();
  24260. },
  24261. queryAutoHide:function (el) {
  24262. if (el) {
  24263. if (uiUtils.contains(this.getDom(), el)) {
  24264. return false;
  24265. }
  24266. for (var i = 0; i < this.items.length; i++) {
  24267. var item = this.items[i];
  24268. if (item.queryAutoHide(el) === false) {
  24269. return false;
  24270. }
  24271. }
  24272. }
  24273. },
  24274. clearItems:function () {
  24275. for (var i = 0; i < this.items.length; i++) {
  24276. var item = this.items[i];
  24277. clearTimeout(item._showingTimer);
  24278. clearTimeout(item._closingTimer);
  24279. if (item.subMenu) {
  24280. item.subMenu.destroy();
  24281. }
  24282. }
  24283. this.items = [];
  24284. },
  24285. destroy:function () {
  24286. if (this.getDom()) {
  24287. domUtils.remove(this.getDom());
  24288. }
  24289. this.clearItems();
  24290. },
  24291. dispose:function () {
  24292. this.destroy();
  24293. }
  24294. };
  24295. utils.inherits(Menu, Popup);
  24296. /**
  24297. * @update 2013/04/03 hancong03 新增一个参数menu, 该参数存储了menuItem所对应的menu引用
  24298. * @type {Function}
  24299. */
  24300. var MenuItem = baidu.editor.ui.MenuItem = function (options) {
  24301. this.initOptions(options);
  24302. this.initUIBase();
  24303. this.Stateful_init();
  24304. if (this.subMenu && !(this.subMenu instanceof Menu)) {
  24305. if (options.className && options.className.indexOf("aligntd") != -1) {
  24306. var me = this;
  24307. //获取单元格对齐初始状态
  24308. this.subMenu.selected = this.editor.queryCommandValue( 'cellalignment' );
  24309. this.subMenu = new Popup({
  24310. content:new CellAlignPicker(this.subMenu),
  24311. parentMenu:me,
  24312. editor:me.editor,
  24313. destroy:function () {
  24314. if (this.getDom()) {
  24315. domUtils.remove(this.getDom());
  24316. }
  24317. }
  24318. });
  24319. this.subMenu.addListener("postRenderAfter", function () {
  24320. domUtils.on(this.getDom(), "mouseover", function () {
  24321. me.addState('opened');
  24322. });
  24323. });
  24324. } else {
  24325. this.subMenu = new Menu(this.subMenu);
  24326. }
  24327. }
  24328. };
  24329. MenuItem.prototype = {
  24330. label:'',
  24331. subMenu:null,
  24332. ownerMenu:null,
  24333. uiName:'menuitem',
  24334. alwalysHoverable:true,
  24335. getHtmlTpl:function () {
  24336. return '<div id="##" class="%%" stateful onclick="$$._onClick(event, this);">' +
  24337. '<div class="%%-body">' +
  24338. this.renderLabelHtml() +
  24339. '</div>' +
  24340. '</div>';
  24341. },
  24342. postRender:function () {
  24343. var me = this;
  24344. this.addListener('over', function () {
  24345. me.ownerMenu.fireEvent('submenuover', me);
  24346. if (me.subMenu) {
  24347. me.delayShowSubMenu();
  24348. }
  24349. });
  24350. if (this.subMenu) {
  24351. this.getDom().className += ' edui-hassubmenu';
  24352. this.subMenu.render();
  24353. this.addListener('out', function () {
  24354. me.delayHideSubMenu();
  24355. });
  24356. this.subMenu.addListener('over', function () {
  24357. clearTimeout(me._closingTimer);
  24358. me._closingTimer = null;
  24359. me.addState('opened');
  24360. });
  24361. this.ownerMenu.addListener('hide', function () {
  24362. me.hideSubMenu();
  24363. });
  24364. this.ownerMenu.addListener('submenuover', function (t, subMenu) {
  24365. if (subMenu !== me) {
  24366. me.delayHideSubMenu();
  24367. }
  24368. });
  24369. this.subMenu._bakQueryAutoHide = this.subMenu.queryAutoHide;
  24370. this.subMenu.queryAutoHide = function (el) {
  24371. if (el && uiUtils.contains(me.getDom(), el)) {
  24372. return false;
  24373. }
  24374. return this._bakQueryAutoHide(el);
  24375. };
  24376. }
  24377. this.getDom().style.tabIndex = '-1';
  24378. uiUtils.makeUnselectable(this.getDom());
  24379. this.Stateful_postRender();
  24380. },
  24381. delayShowSubMenu:function () {
  24382. var me = this;
  24383. if (!me.isDisabled()) {
  24384. me.addState('opened');
  24385. clearTimeout(me._showingTimer);
  24386. clearTimeout(me._closingTimer);
  24387. me._closingTimer = null;
  24388. me._showingTimer = setTimeout(function () {
  24389. me.showSubMenu();
  24390. }, 250);
  24391. }
  24392. },
  24393. delayHideSubMenu:function () {
  24394. var me = this;
  24395. if (!me.isDisabled()) {
  24396. me.removeState('opened');
  24397. clearTimeout(me._showingTimer);
  24398. if (!me._closingTimer) {
  24399. me._closingTimer = setTimeout(function () {
  24400. if (!me.hasState('opened')) {
  24401. me.hideSubMenu();
  24402. }
  24403. me._closingTimer = null;
  24404. }, 400);
  24405. }
  24406. }
  24407. },
  24408. renderLabelHtml:function () {
  24409. return '<div class="edui-arrow"></div>' +
  24410. '<div class="edui-box edui-icon"></div>' +
  24411. '<div class="edui-box edui-label %%-label">' + (this.label || '') + '</div>';
  24412. },
  24413. getStateDom:function () {
  24414. return this.getDom();
  24415. },
  24416. queryAutoHide:function (el) {
  24417. if (this.subMenu && this.hasState('opened')) {
  24418. return this.subMenu.queryAutoHide(el);
  24419. }
  24420. },
  24421. _onClick:function (event, this_) {
  24422. if (this.hasState('disabled')) return;
  24423. if (this.fireEvent('click', event, this_) !== false) {
  24424. if (this.subMenu) {
  24425. this.showSubMenu();
  24426. } else {
  24427. Popup.postHide(event);
  24428. }
  24429. }
  24430. },
  24431. showSubMenu:function () {
  24432. var rect = uiUtils.getClientRect(this.getDom());
  24433. rect.right -= 5;
  24434. rect.left += 2;
  24435. rect.width -= 7;
  24436. rect.top -= 4;
  24437. rect.bottom += 4;
  24438. rect.height += 8;
  24439. this.subMenu.showAnchorRect(rect, true, true);
  24440. },
  24441. hideSubMenu:function () {
  24442. this.subMenu.hide();
  24443. }
  24444. };
  24445. utils.inherits(MenuItem, UIBase);
  24446. utils.extend(MenuItem.prototype, Stateful, true);
  24447. })();
  24448. // ui/combox.js
  24449. ///import core
  24450. ///import uicore
  24451. ///import ui/menu.js
  24452. ///import ui/splitbutton.js
  24453. (function (){
  24454. // todo: menu和item提成通用list
  24455. var utils = baidu.editor.utils,
  24456. uiUtils = baidu.editor.ui.uiUtils,
  24457. Menu = baidu.editor.ui.Menu,
  24458. SplitButton = baidu.editor.ui.SplitButton,
  24459. Combox = baidu.editor.ui.Combox = function (options){
  24460. this.initOptions(options);
  24461. this.initCombox();
  24462. };
  24463. Combox.prototype = {
  24464. uiName: 'combox',
  24465. onbuttonclick:function () {
  24466. this.showPopup();
  24467. },
  24468. initCombox: function (){
  24469. var me = this;
  24470. this.items = this.items || [];
  24471. for (var i=0; i<this.items.length; i++) {
  24472. var item = this.items[i];
  24473. item.uiName = 'listitem';
  24474. item.index = i;
  24475. item.onclick = function (){
  24476. me.selectByIndex(this.index);
  24477. };
  24478. }
  24479. this.popup = new Menu({
  24480. items: this.items,
  24481. uiName: 'list',
  24482. editor:this.editor,
  24483. captureWheel: true,
  24484. combox: this
  24485. });
  24486. this.initSplitButton();
  24487. },
  24488. _SplitButton_postRender: SplitButton.prototype.postRender,
  24489. postRender: function (){
  24490. this._SplitButton_postRender();
  24491. this.setLabel(this.label || '');
  24492. this.setValue(this.initValue || '');
  24493. },
  24494. showPopup: function (){
  24495. var rect = uiUtils.getClientRect(this.getDom());
  24496. rect.top += 1;
  24497. rect.bottom -= 1;
  24498. rect.height -= 2;
  24499. this.popup.showAnchorRect(rect);
  24500. },
  24501. getValue: function (){
  24502. return this.value;
  24503. },
  24504. setValue: function (value){
  24505. var index = this.indexByValue(value);
  24506. if (index != -1) {
  24507. this.selectedIndex = index;
  24508. this.setLabel(this.items[index].label);
  24509. this.value = this.items[index].value;
  24510. } else {
  24511. this.selectedIndex = -1;
  24512. this.setLabel(this.getLabelForUnknowValue(value));
  24513. this.value = value;
  24514. }
  24515. },
  24516. setLabel: function (label){
  24517. this.getDom('button_body').innerHTML = label;
  24518. this.label = label;
  24519. },
  24520. getLabelForUnknowValue: function (value){
  24521. return value;
  24522. },
  24523. indexByValue: function (value){
  24524. for (var i=0; i<this.items.length; i++) {
  24525. if (value == this.items[i].value) {
  24526. return i;
  24527. }
  24528. }
  24529. return -1;
  24530. },
  24531. getItem: function (index){
  24532. return this.items[index];
  24533. },
  24534. selectByIndex: function (index){
  24535. if (index < this.items.length && this.fireEvent('select', index) !== false) {
  24536. this.selectedIndex = index;
  24537. this.value = this.items[index].value;
  24538. this.setLabel(this.items[index].label);
  24539. }
  24540. }
  24541. };
  24542. utils.inherits(Combox, SplitButton);
  24543. })();
  24544. // ui/dialog.js
  24545. ///import core
  24546. ///import uicore
  24547. ///import ui/mask.js
  24548. ///import ui/button.js
  24549. (function (){
  24550. var utils = baidu.editor.utils,
  24551. domUtils = baidu.editor.dom.domUtils,
  24552. uiUtils = baidu.editor.ui.uiUtils,
  24553. Mask = baidu.editor.ui.Mask,
  24554. UIBase = baidu.editor.ui.UIBase,
  24555. Button = baidu.editor.ui.Button,
  24556. Dialog = baidu.editor.ui.Dialog = function (options){
  24557. if(options.name){
  24558. var name = options.name;
  24559. var cssRules = options.cssRules;
  24560. if(!options.className){
  24561. options.className = 'edui-for-' + name;
  24562. }
  24563. if(cssRules){
  24564. options.cssRules = '.edui-default .edui-for-'+ name +' .edui-dialog-content {'+ cssRules +'}'
  24565. }
  24566. }
  24567. this.initOptions(utils.extend({
  24568. autoReset: true,
  24569. draggable: true,
  24570. onok: function (){},
  24571. oncancel: function (){},
  24572. onclose: function (t, ok){
  24573. return ok ? this.onok() : this.oncancel();
  24574. },
  24575. //是否控制dialog中的scroll事件, 默认为不阻止
  24576. holdScroll: false
  24577. },options));
  24578. this.initDialog();
  24579. };
  24580. var modalMask;
  24581. var dragMask;
  24582. var activeDialog;
  24583. Dialog.prototype = {
  24584. draggable: false,
  24585. uiName: 'dialog',
  24586. initDialog: function (){
  24587. var me = this,
  24588. theme=this.editor.options.theme;
  24589. if(this.cssRules){
  24590. utils.cssRule('edui-customize-'+this.name+'-style',this.cssRules);
  24591. }
  24592. this.initUIBase();
  24593. this.modalMask = (modalMask || (modalMask = new Mask({
  24594. className: 'edui-dialog-modalmask',
  24595. theme:theme,
  24596. onclick: function (){
  24597. activeDialog && activeDialog.close(false);
  24598. }
  24599. })));
  24600. this.dragMask = (dragMask || (dragMask = new Mask({
  24601. className: 'edui-dialog-dragmask',
  24602. theme:theme
  24603. })));
  24604. this.closeButton = new Button({
  24605. className: 'edui-dialog-closebutton',
  24606. title: me.closeDialog,
  24607. theme:theme,
  24608. onclick: function (){
  24609. me.close(false);
  24610. }
  24611. });
  24612. this.fullscreen && this.initResizeEvent();
  24613. if (this.buttons) {
  24614. for (var i=0; i<this.buttons.length; i++) {
  24615. if (!(this.buttons[i] instanceof Button)) {
  24616. this.buttons[i] = new Button(utils.extend(this.buttons[i],{
  24617. editor : this.editor
  24618. },true));
  24619. }
  24620. }
  24621. }
  24622. },
  24623. initResizeEvent: function () {
  24624. var me = this;
  24625. domUtils.on( window, "resize", function () {
  24626. if ( me._hidden || me._hidden === undefined ) {
  24627. return;
  24628. }
  24629. if ( me.__resizeTimer ) {
  24630. window.clearTimeout( me.__resizeTimer );
  24631. }
  24632. me.__resizeTimer = window.setTimeout( function () {
  24633. me.__resizeTimer = null;
  24634. var dialogWrapNode = me.getDom(),
  24635. contentNode = me.getDom('content'),
  24636. wrapRect = UE.ui.uiUtils.getClientRect( dialogWrapNode ),
  24637. contentRect = UE.ui.uiUtils.getClientRect( contentNode ),
  24638. vpRect = uiUtils.getViewportRect();
  24639. contentNode.style.width = ( vpRect.width - wrapRect.width + contentRect.width ) + "px";
  24640. contentNode.style.height = ( vpRect.height - wrapRect.height + contentRect.height ) + "px";
  24641. dialogWrapNode.style.width = vpRect.width + "px";
  24642. dialogWrapNode.style.height = vpRect.height + "px";
  24643. me.fireEvent( "resize" );
  24644. }, 100 );
  24645. } );
  24646. },
  24647. fitSize: function (){
  24648. var popBodyEl = this.getDom('body');
  24649. // if (!(baidu.editor.browser.ie && baidu.editor.browser.version == 7)) {
  24650. // uiUtils.removeStyle(popBodyEl, 'width');
  24651. // uiUtils.removeStyle(popBodyEl, 'height');
  24652. // }
  24653. var size = this.mesureSize();
  24654. popBodyEl.style.width = size.width + 'px';
  24655. popBodyEl.style.height = size.height + 'px';
  24656. return size;
  24657. },
  24658. safeSetOffset: function (offset){
  24659. var me = this;
  24660. var el = me.getDom();
  24661. var vpRect = uiUtils.getViewportRect();
  24662. var rect = uiUtils.getClientRect(el);
  24663. var left = offset.left;
  24664. if (left + rect.width > vpRect.right) {
  24665. left = vpRect.right - rect.width;
  24666. }
  24667. var top = offset.top;
  24668. if (top + rect.height > vpRect.bottom) {
  24669. top = vpRect.bottom - rect.height;
  24670. }
  24671. el.style.left = Math.max(left, 0) + 'px';
  24672. el.style.top = Math.max(top, 0) + 'px';
  24673. },
  24674. showAtCenter: function (){
  24675. var vpRect = uiUtils.getViewportRect();
  24676. if ( !this.fullscreen ) {
  24677. this.getDom().style.display = '';
  24678. var popSize = this.fitSize();
  24679. var titleHeight = this.getDom('titlebar').offsetHeight | 0;
  24680. var left = vpRect.width / 2 - popSize.width / 2;
  24681. var top = vpRect.height / 2 - (popSize.height - titleHeight) / 2 - titleHeight;
  24682. var popEl = this.getDom();
  24683. this.safeSetOffset({
  24684. left: Math.max(left | 0, 0),
  24685. top: Math.max(top | 0, 0)
  24686. });
  24687. if (!domUtils.hasClass(popEl, 'edui-state-centered')) {
  24688. popEl.className += ' edui-state-centered';
  24689. }
  24690. } else {
  24691. var dialogWrapNode = this.getDom(),
  24692. contentNode = this.getDom('content');
  24693. dialogWrapNode.style.display = "block";
  24694. var wrapRect = UE.ui.uiUtils.getClientRect( dialogWrapNode ),
  24695. contentRect = UE.ui.uiUtils.getClientRect( contentNode );
  24696. dialogWrapNode.style.left = "-100000px";
  24697. contentNode.style.width = ( vpRect.width - wrapRect.width + contentRect.width ) + "px";
  24698. contentNode.style.height = ( vpRect.height - wrapRect.height + contentRect.height ) + "px";
  24699. dialogWrapNode.style.width = vpRect.width + "px";
  24700. dialogWrapNode.style.height = vpRect.height + "px";
  24701. dialogWrapNode.style.left = 0;
  24702. //保存环境的overflow值
  24703. this._originalContext = {
  24704. html: {
  24705. overflowX: document.documentElement.style.overflowX,
  24706. overflowY: document.documentElement.style.overflowY
  24707. },
  24708. body: {
  24709. overflowX: document.body.style.overflowX,
  24710. overflowY: document.body.style.overflowY
  24711. }
  24712. };
  24713. document.documentElement.style.overflowX = 'hidden';
  24714. document.documentElement.style.overflowY = 'hidden';
  24715. document.body.style.overflowX = 'hidden';
  24716. document.body.style.overflowY = 'hidden';
  24717. }
  24718. this._show();
  24719. },
  24720. getContentHtml: function (){
  24721. var contentHtml = '';
  24722. if (typeof this.content == 'string') {
  24723. contentHtml = this.content;
  24724. } else if (this.iframeUrl) {
  24725. contentHtml = '<span id="'+ this.id +'_contmask" class="dialogcontmask"></span><iframe id="'+ this.id +
  24726. '_iframe" class="%%-iframe" height="100%" width="100%" frameborder="0" src="'+ this.iframeUrl +'"></iframe>';
  24727. }
  24728. return contentHtml;
  24729. },
  24730. getHtmlTpl: function (){
  24731. var footHtml = '';
  24732. if (this.buttons) {
  24733. var buff = [];
  24734. for (var i=0; i<this.buttons.length; i++) {
  24735. buff[i] = this.buttons[i].renderHtml();
  24736. }
  24737. footHtml = '<div class="%%-foot">' +
  24738. '<div id="##_buttons" class="%%-buttons">' + buff.join('') + '</div>' +
  24739. '</div>';
  24740. }
  24741. return '<div id="##" class="%%"><div '+ ( !this.fullscreen ? 'class="%%"' : 'class="%%-wrap edui-dialog-fullscreen-flag"' ) +'><div id="##_body" class="%%-body">' +
  24742. '<div class="%%-shadow"></div>' +
  24743. '<div id="##_titlebar" class="%%-titlebar">' +
  24744. '<div class="%%-draghandle" onmousedown="$$._onTitlebarMouseDown(event, this);">' +
  24745. '<span class="%%-caption">' + (this.title || '') + '</span>' +
  24746. '</div>' +
  24747. this.closeButton.renderHtml() +
  24748. '</div>' +
  24749. '<div id="##_content" class="%%-content">'+ ( this.autoReset ? '' : this.getContentHtml()) +'</div>' +
  24750. footHtml +
  24751. '</div></div></div>';
  24752. },
  24753. postRender: function (){
  24754. // todo: 保持居中/记住上次关闭位置选项
  24755. if (!this.modalMask.getDom()) {
  24756. this.modalMask.render();
  24757. this.modalMask.hide();
  24758. }
  24759. if (!this.dragMask.getDom()) {
  24760. this.dragMask.render();
  24761. this.dragMask.hide();
  24762. }
  24763. var me = this;
  24764. this.addListener('show', function (){
  24765. me.modalMask.show(this.getDom().style.zIndex - 2);
  24766. });
  24767. this.addListener('hide', function (){
  24768. me.modalMask.hide();
  24769. });
  24770. if (this.buttons) {
  24771. for (var i=0; i<this.buttons.length; i++) {
  24772. this.buttons[i].postRender();
  24773. }
  24774. }
  24775. domUtils.on(window, 'resize', function (){
  24776. setTimeout(function (){
  24777. if (!me.isHidden()) {
  24778. me.safeSetOffset(uiUtils.getClientRect(me.getDom()));
  24779. }
  24780. });
  24781. });
  24782. //hold住scroll事件,防止dialog的滚动影响页面
  24783. // if( this.holdScroll ) {
  24784. //
  24785. // if( !me.iframeUrl ) {
  24786. // domUtils.on( document.getElementById( me.id + "_iframe"), !browser.gecko ? "mousewheel" : "DOMMouseScroll", function(e){
  24787. // domUtils.preventDefault(e);
  24788. // } );
  24789. // } else {
  24790. // me.addListener('dialogafterreset', function(){
  24791. // window.setTimeout(function(){
  24792. // var iframeWindow = document.getElementById( me.id + "_iframe").contentWindow;
  24793. //
  24794. // if( browser.ie ) {
  24795. //
  24796. // var timer = window.setInterval(function(){
  24797. //
  24798. // if( iframeWindow.document && iframeWindow.document.body ) {
  24799. // window.clearInterval( timer );
  24800. // timer = null;
  24801. // domUtils.on( iframeWindow.document.body, !browser.gecko ? "mousewheel" : "DOMMouseScroll", function(e){
  24802. // domUtils.preventDefault(e);
  24803. // } );
  24804. // }
  24805. //
  24806. // }, 100);
  24807. //
  24808. // } else {
  24809. // domUtils.on( iframeWindow, !browser.gecko ? "mousewheel" : "DOMMouseScroll", function(e){
  24810. // domUtils.preventDefault(e);
  24811. // } );
  24812. // }
  24813. //
  24814. // }, 1);
  24815. // });
  24816. // }
  24817. //
  24818. // }
  24819. this._hide();
  24820. },
  24821. mesureSize: function (){
  24822. var body = this.getDom('body');
  24823. var width = uiUtils.getClientRect(this.getDom('content')).width;
  24824. var dialogBodyStyle = body.style;
  24825. dialogBodyStyle.width = width;
  24826. return uiUtils.getClientRect(body);
  24827. },
  24828. _onTitlebarMouseDown: function (evt, el){
  24829. if (this.draggable) {
  24830. var rect;
  24831. var vpRect = uiUtils.getViewportRect();
  24832. var me = this;
  24833. uiUtils.startDrag(evt, {
  24834. ondragstart: function (){
  24835. rect = uiUtils.getClientRect(me.getDom());
  24836. me.getDom('contmask').style.visibility = 'visible';
  24837. me.dragMask.show(me.getDom().style.zIndex - 1);
  24838. },
  24839. ondragmove: function (x, y){
  24840. var left = rect.left + x;
  24841. var top = rect.top + y;
  24842. me.safeSetOffset({
  24843. left: left,
  24844. top: top
  24845. });
  24846. },
  24847. ondragstop: function (){
  24848. me.getDom('contmask').style.visibility = 'hidden';
  24849. domUtils.removeClasses(me.getDom(), ['edui-state-centered']);
  24850. me.dragMask.hide();
  24851. }
  24852. });
  24853. }
  24854. },
  24855. reset: function (){
  24856. this.getDom('content').innerHTML = this.getContentHtml();
  24857. this.fireEvent('dialogafterreset');
  24858. },
  24859. _show: function (){
  24860. if (this._hidden) {
  24861. this.getDom().style.display = '';
  24862. //要高过编辑器的zindxe
  24863. this.editor.container.style.zIndex && (this.getDom().style.zIndex = this.editor.container.style.zIndex * 1 + 10);
  24864. this._hidden = false;
  24865. this.fireEvent('show');
  24866. baidu.editor.ui.uiUtils.getFixedLayer().style.zIndex = this.getDom().style.zIndex - 4;
  24867. }
  24868. },
  24869. isHidden: function (){
  24870. return this._hidden;
  24871. },
  24872. _hide: function (){
  24873. if (!this._hidden) {
  24874. var wrapNode = this.getDom();
  24875. wrapNode.style.display = 'none';
  24876. wrapNode.style.zIndex = '';
  24877. wrapNode.style.width = '';
  24878. wrapNode.style.height = '';
  24879. this._hidden = true;
  24880. this.fireEvent('hide');
  24881. }
  24882. },
  24883. open: function (){
  24884. if (this.autoReset) {
  24885. //有可能还没有渲染
  24886. try{
  24887. this.reset();
  24888. }catch(e){
  24889. this.render();
  24890. this.open()
  24891. }
  24892. }
  24893. this.showAtCenter();
  24894. if (this.iframeUrl) {
  24895. try {
  24896. this.getDom('iframe').focus();
  24897. } catch(ex){}
  24898. }
  24899. activeDialog = this;
  24900. },
  24901. _onCloseButtonClick: function (evt, el){
  24902. this.close(false);
  24903. },
  24904. close: function (ok){
  24905. if (this.fireEvent('close', ok) !== false) {
  24906. //还原环境
  24907. if ( this.fullscreen ) {
  24908. document.documentElement.style.overflowX = this._originalContext.html.overflowX;
  24909. document.documentElement.style.overflowY = this._originalContext.html.overflowY;
  24910. document.body.style.overflowX = this._originalContext.body.overflowX;
  24911. document.body.style.overflowY = this._originalContext.body.overflowY;
  24912. delete this._originalContext;
  24913. }
  24914. this._hide();
  24915. //销毁content
  24916. var content = this.getDom('content');
  24917. var iframe = this.getDom('iframe');
  24918. if (content && iframe) {
  24919. var doc = iframe.contentDocument || iframe.contentWindow.document;
  24920. doc && (doc.body.innerHTML = '');
  24921. domUtils.remove(content);
  24922. }
  24923. }
  24924. }
  24925. };
  24926. utils.inherits(Dialog, UIBase);
  24927. })();
  24928. // ui/menubutton.js
  24929. ///import core
  24930. ///import uicore
  24931. ///import ui/menu.js
  24932. ///import ui/splitbutton.js
  24933. (function (){
  24934. var utils = baidu.editor.utils,
  24935. Menu = baidu.editor.ui.Menu,
  24936. SplitButton = baidu.editor.ui.SplitButton,
  24937. MenuButton = baidu.editor.ui.MenuButton = function (options){
  24938. this.initOptions(options);
  24939. this.initMenuButton();
  24940. };
  24941. MenuButton.prototype = {
  24942. initMenuButton: function (){
  24943. var me = this;
  24944. this.uiName = "menubutton";
  24945. this.popup = new Menu({
  24946. items: me.items,
  24947. className: me.className,
  24948. editor:me.editor
  24949. });
  24950. this.popup.addListener('show', function (){
  24951. var list = this;
  24952. for (var i=0; i<list.items.length; i++) {
  24953. list.items[i].removeState('checked');
  24954. if (list.items[i].value == me._value) {
  24955. list.items[i].addState('checked');
  24956. this.value = me._value;
  24957. }
  24958. }
  24959. });
  24960. this.initSplitButton();
  24961. },
  24962. setValue : function(value){
  24963. this._value = value;
  24964. }
  24965. };
  24966. utils.inherits(MenuButton, SplitButton);
  24967. })();
  24968. // ui/multiMenu.js
  24969. ///import core
  24970. ///import uicore
  24971. ///commands 表情
  24972. (function(){
  24973. var utils = baidu.editor.utils,
  24974. Popup = baidu.editor.ui.Popup,
  24975. SplitButton = baidu.editor.ui.SplitButton,
  24976. MultiMenuPop = baidu.editor.ui.MultiMenuPop = function(options){
  24977. this.initOptions(options);
  24978. this.initMultiMenu();
  24979. };
  24980. MultiMenuPop.prototype = {
  24981. initMultiMenu: function (){
  24982. var me = this;
  24983. this.popup = new Popup({
  24984. content: '',
  24985. editor : me.editor,
  24986. iframe_rendered: false,
  24987. onshow: function (){
  24988. if (!this.iframe_rendered) {
  24989. this.iframe_rendered = true;
  24990. this.getDom('content').innerHTML = '<iframe id="'+me.id+'_iframe" src="'+ me.iframeUrl +'" frameborder="0"></iframe>';
  24991. me.editor.container.style.zIndex && (this.getDom().style.zIndex = me.editor.container.style.zIndex * 1 + 1);
  24992. }
  24993. }
  24994. // canSideUp:false,
  24995. // canSideLeft:false
  24996. });
  24997. this.onbuttonclick = function(){
  24998. this.showPopup();
  24999. };
  25000. this.initSplitButton();
  25001. }
  25002. };
  25003. utils.inherits(MultiMenuPop, SplitButton);
  25004. })();
  25005. // ui/shortcutmenu.js
  25006. (function () {
  25007. var UI = baidu.editor.ui,
  25008. UIBase = UI.UIBase,
  25009. uiUtils = UI.uiUtils,
  25010. utils = baidu.editor.utils,
  25011. domUtils = baidu.editor.dom.domUtils;
  25012. var allMenus = [],//存储所有快捷菜单
  25013. timeID,
  25014. isSubMenuShow = false;//是否有子pop显示
  25015. var ShortCutMenu = UI.ShortCutMenu = function (options) {
  25016. this.initOptions (options);
  25017. this.initShortCutMenu ();
  25018. };
  25019. ShortCutMenu.postHide = hideAllMenu;
  25020. ShortCutMenu.prototype = {
  25021. isHidden : true ,
  25022. SPACE : 5 ,
  25023. initShortCutMenu : function () {
  25024. this.items = this.items || [];
  25025. this.initUIBase ();
  25026. this.initItems ();
  25027. this.initEvent ();
  25028. allMenus.push (this);
  25029. } ,
  25030. initEvent : function () {
  25031. var me = this,
  25032. doc = me.editor.document;
  25033. domUtils.on (doc , "mousemove" , function (e) {
  25034. if (me.isHidden === false) {
  25035. //有pop显示就不隐藏快捷菜单
  25036. if (me.getSubMenuMark () || me.eventType == "contextmenu") return;
  25037. var flag = true,
  25038. el = me.getDom (),
  25039. wt = el.offsetWidth,
  25040. ht = el.offsetHeight,
  25041. distanceX = wt / 2 + me.SPACE,//距离中心X标准
  25042. distanceY = ht / 2,//距离中心Y标准
  25043. x = Math.abs (e.screenX - me.left),//离中心距离横坐标
  25044. y = Math.abs (e.screenY - me.top);//离中心距离纵坐标
  25045. clearTimeout (timeID);
  25046. timeID = setTimeout (function () {
  25047. if (y > 0 && y < distanceY) {
  25048. me.setOpacity (el , "1");
  25049. } else if (y > distanceY && y < distanceY + 70) {
  25050. me.setOpacity (el , "0.5");
  25051. flag = false;
  25052. } else if (y > distanceY + 70 && y < distanceY + 140) {
  25053. me.hide ();
  25054. }
  25055. if (flag && x > 0 && x < distanceX) {
  25056. me.setOpacity (el , "1")
  25057. } else if (x > distanceX && x < distanceX + 70) {
  25058. me.setOpacity (el , "0.5")
  25059. } else if (x > distanceX + 70 && x < distanceX + 140) {
  25060. me.hide ();
  25061. }
  25062. });
  25063. }
  25064. });
  25065. //ie\ff下 mouseout不准
  25066. if (browser.chrome) {
  25067. domUtils.on (doc , "mouseout" , function (e) {
  25068. var relatedTgt = e.relatedTarget || e.toElement;
  25069. if (relatedTgt == null || relatedTgt.tagName == "HTML") {
  25070. me.hide ();
  25071. }
  25072. });
  25073. }
  25074. me.editor.addListener ("afterhidepop" , function () {
  25075. if (!me.isHidden) {
  25076. isSubMenuShow = true;
  25077. }
  25078. });
  25079. } ,
  25080. initItems : function () {
  25081. if (utils.isArray (this.items)) {
  25082. for (var i = 0, len = this.items.length ; i < len ; i++) {
  25083. var item = this.items[i].toLowerCase ();
  25084. if (UI[item]) {
  25085. this.items[i] = new UI[item] (this.editor);
  25086. this.items[i].className += " edui-shortcutsubmenu ";
  25087. }
  25088. }
  25089. }
  25090. } ,
  25091. setOpacity : function (el , value) {
  25092. if (browser.ie && browser.version < 9) {
  25093. el.style.filter = "alpha(opacity = " + parseFloat (value) * 100 + ");"
  25094. } else {
  25095. el.style.opacity = value;
  25096. }
  25097. } ,
  25098. getSubMenuMark : function () {
  25099. isSubMenuShow = false;
  25100. var layerEle = uiUtils.getFixedLayer ();
  25101. var list = domUtils.getElementsByTagName (layerEle , "div" , function (node) {
  25102. return domUtils.hasClass (node , "edui-shortcutsubmenu edui-popup")
  25103. });
  25104. for (var i = 0, node ; node = list[i++] ;) {
  25105. if (node.style.display != "none") {
  25106. isSubMenuShow = true;
  25107. }
  25108. }
  25109. return isSubMenuShow;
  25110. } ,
  25111. show : function (e , hasContextmenu) {
  25112. var me = this,
  25113. offset = {},
  25114. el = this.getDom (),
  25115. fixedlayer = uiUtils.getFixedLayer ();
  25116. function setPos (offset) {
  25117. if (offset.left < 0) {
  25118. offset.left = 0;
  25119. }
  25120. if (offset.top < 0) {
  25121. offset.top = 0;
  25122. }
  25123. el.style.cssText = "position:absolute;left:" + offset.left + "px;top:" + offset.top + "px;";
  25124. }
  25125. function setPosByCxtMenu (menu) {
  25126. if (!menu.tagName) {
  25127. menu = menu.getDom ();
  25128. }
  25129. offset.left = parseInt (menu.style.left);
  25130. offset.top = parseInt (menu.style.top);
  25131. offset.top -= el.offsetHeight + 15;
  25132. setPos (offset);
  25133. }
  25134. me.eventType = e.type;
  25135. el.style.cssText = "display:block;left:-9999px";
  25136. if (e.type == "contextmenu" && hasContextmenu) {
  25137. var menu = domUtils.getElementsByTagName (fixedlayer , "div" , "edui-contextmenu")[0];
  25138. if (menu) {
  25139. setPosByCxtMenu (menu)
  25140. } else {
  25141. me.editor.addListener ("aftershowcontextmenu" , function (type , menu) {
  25142. setPosByCxtMenu (menu);
  25143. });
  25144. }
  25145. } else {
  25146. offset = uiUtils.getViewportOffsetByEvent (e);
  25147. offset.top -= el.offsetHeight + me.SPACE;
  25148. offset.left += me.SPACE + 20;
  25149. setPos (offset);
  25150. me.setOpacity (el , 0.2);
  25151. }
  25152. me.isHidden = false;
  25153. me.left = e.screenX + el.offsetWidth / 2 - me.SPACE;
  25154. me.top = e.screenY - (el.offsetHeight / 2) - me.SPACE;
  25155. if (me.editor) {
  25156. el.style.zIndex = me.editor.container.style.zIndex * 1 + 10;
  25157. fixedlayer.style.zIndex = el.style.zIndex - 1;
  25158. }
  25159. } ,
  25160. hide : function () {
  25161. if (this.getDom ()) {
  25162. this.getDom ().style.display = "none";
  25163. }
  25164. this.isHidden = true;
  25165. } ,
  25166. postRender : function () {
  25167. if (utils.isArray (this.items)) {
  25168. for (var i = 0, item ; item = this.items[i++] ;) {
  25169. item.postRender ();
  25170. }
  25171. }
  25172. } ,
  25173. getHtmlTpl : function () {
  25174. var buff;
  25175. if (utils.isArray (this.items)) {
  25176. buff = [];
  25177. for (var i = 0 ; i < this.items.length ; i++) {
  25178. buff[i] = this.items[i].renderHtml ();
  25179. }
  25180. buff = buff.join ("");
  25181. } else {
  25182. buff = this.items;
  25183. }
  25184. return '<div id="##" class="%% edui-toolbar" data-src="shortcutmenu" onmousedown="return false;" onselectstart="return false;" >' +
  25185. buff +
  25186. '</div>';
  25187. }
  25188. };
  25189. utils.inherits (ShortCutMenu , UIBase);
  25190. function hideAllMenu (e) {
  25191. var tgt = e.target || e.srcElement,
  25192. cur = domUtils.findParent (tgt , function (node) {
  25193. return domUtils.hasClass (node , "edui-shortcutmenu") || domUtils.hasClass (node , "edui-popup");
  25194. } , true);
  25195. if (!cur) {
  25196. for (var i = 0, menu ; menu = allMenus[i++] ;) {
  25197. menu.hide ()
  25198. }
  25199. }
  25200. }
  25201. domUtils.on (document , 'mousedown' , function (e) {
  25202. hideAllMenu (e);
  25203. });
  25204. domUtils.on (window , 'scroll' , function (e) {
  25205. hideAllMenu (e);
  25206. });
  25207. }) ();
  25208. // ui/breakline.js
  25209. (function (){
  25210. var utils = baidu.editor.utils,
  25211. UIBase = baidu.editor.ui.UIBase,
  25212. Breakline = baidu.editor.ui.Breakline = function (options){
  25213. this.initOptions(options);
  25214. this.initSeparator();
  25215. };
  25216. Breakline.prototype = {
  25217. uiName: 'Breakline',
  25218. initSeparator: function (){
  25219. this.initUIBase();
  25220. },
  25221. getHtmlTpl: function (){
  25222. return '<br/>';
  25223. }
  25224. };
  25225. utils.inherits(Breakline, UIBase);
  25226. })();
  25227. // ui/message.js
  25228. ///import core
  25229. ///import uicore
  25230. (function () {
  25231. var utils = baidu.editor.utils,
  25232. domUtils = baidu.editor.dom.domUtils,
  25233. UIBase = baidu.editor.ui.UIBase,
  25234. Message = baidu.editor.ui.Message = function (options){
  25235. this.initOptions(options);
  25236. this.initMessage();
  25237. };
  25238. Message.prototype = {
  25239. initMessage: function (){
  25240. this.initUIBase();
  25241. },
  25242. getHtmlTpl: function (){
  25243. return '<div id="##" class="edui-message %%">' +
  25244. ' <div id="##_closer" class="edui-message-closer">×</div>' +
  25245. ' <div id="##_body" class="edui-message-body edui-message-type-info">' +
  25246. ' <iframe style="position:absolute;z-index:-1;left:0;top:0;background-color: transparent;" frameborder="0" width="100%" height="100%" src="about:blank"></iframe>' +
  25247. ' <div class="edui-shadow"></div>' +
  25248. ' <div id="##_content" class="edui-message-content">' +
  25249. ' </div>' +
  25250. ' </div>' +
  25251. '</div>';
  25252. },
  25253. reset: function(opt){
  25254. var me = this;
  25255. if (!opt.keepshow) {
  25256. clearTimeout(this.timer);
  25257. me.timer = setTimeout(function(){
  25258. me.hide();
  25259. }, opt.timeout || 4000);
  25260. }
  25261. opt.content !== undefined && me.setContent(opt.content);
  25262. opt.type !== undefined && me.setType(opt.type);
  25263. me.show();
  25264. },
  25265. postRender: function(){
  25266. var me = this,
  25267. closer = this.getDom('closer');
  25268. closer && domUtils.on(closer, 'click', function(){
  25269. me.hide();
  25270. });
  25271. },
  25272. setContent: function(content){
  25273. this.getDom('content').innerHTML = content;
  25274. },
  25275. setType: function(type){
  25276. type = type || 'info';
  25277. var body = this.getDom('body');
  25278. body.className = body.className.replace(/edui-message-type-[\w-]+/, 'edui-message-type-' + type);
  25279. },
  25280. getContent: function(){
  25281. return this.getDom('content').innerHTML;
  25282. },
  25283. getType: function(){
  25284. var arr = this.getDom('body').match(/edui-message-type-([\w-]+)/);
  25285. return arr ? arr[1]:'';
  25286. },
  25287. show: function (){
  25288. this.getDom().style.display = 'block';
  25289. },
  25290. hide: function (){
  25291. var dom = this.getDom();
  25292. if (dom) {
  25293. dom.style.display = 'none';
  25294. dom.parentNode && dom.parentNode.removeChild(dom);
  25295. }
  25296. }
  25297. };
  25298. utils.inherits(Message, UIBase);
  25299. })();
  25300. // adapter/editorui.js
  25301. //ui跟编辑器的适配層
  25302. //那个按钮弹出是dialog,是下拉筐等都是在这个js中配置
  25303. //自己写的ui也要在这里配置,放到baidu.editor.ui下边,当编辑器实例化的时候会根据ueditor.config中的toolbars找到相应的进行实例化
  25304. (function () {
  25305. var utils = baidu.editor.utils;
  25306. var editorui = baidu.editor.ui;
  25307. var _Dialog = editorui.Dialog;
  25308. editorui.buttons = {};
  25309. editorui.Dialog = function (options) {
  25310. var dialog = new _Dialog(options);
  25311. dialog.addListener('hide', function () {
  25312. if (dialog.editor) {
  25313. var editor = dialog.editor;
  25314. try {
  25315. if (browser.gecko) {
  25316. var y = editor.window.scrollY,
  25317. x = editor.window.scrollX;
  25318. editor.body.focus();
  25319. editor.window.scrollTo(x, y);
  25320. } else {
  25321. editor.focus();
  25322. }
  25323. } catch (ex) {
  25324. }
  25325. }
  25326. });
  25327. return dialog;
  25328. };
  25329. var iframeUrlMap = {
  25330. 'anchor':'~/dialogs/anchor/anchor.html',
  25331. 'insertimage':'~/dialogs/image/image.html',
  25332. 'link':'~/dialogs/link/link.html',
  25333. 'spechars':'~/dialogs/spechars/spechars.html',
  25334. 'searchreplace':'~/dialogs/searchreplace/searchreplace.html',
  25335. 'map':'~/dialogs/map/map.html',
  25336. 'gmap':'~/dialogs/gmap/gmap.html',
  25337. 'insertvideo':'~/dialogs/video/video.html',
  25338. 'help':'~/dialogs/help/help.html',
  25339. 'preview':'~/dialogs/preview/preview.html',
  25340. 'emotion':'~/dialogs/emotion/emotion.html',
  25341. 'wordimage':'~/dialogs/wordimage/wordimage.html',
  25342. 'attachment':'~/dialogs/attachment/attachment.html',
  25343. 'insertframe':'~/dialogs/insertframe/insertframe.html',
  25344. 'edittip':'~/dialogs/table/edittip.html',
  25345. 'edittable':'~/dialogs/table/edittable.html',
  25346. 'edittd':'~/dialogs/table/edittd.html',
  25347. 'webapp':'~/dialogs/webapp/webapp.html',
  25348. 'snapscreen':'~/dialogs/snapscreen/snapscreen.html',
  25349. 'scrawl':'~/dialogs/scrawl/scrawl.html',
  25350. 'music':'~/dialogs/music/music.html',
  25351. 'template':'~/dialogs/template/template.html',
  25352. 'background':'~/dialogs/background/background.html',
  25353. 'charts': '~/dialogs/charts/charts.html'
  25354. };
  25355. //为工具栏添加按钮,以下都是统一的按钮触发命令,所以写在一起
  25356. var btnCmds = ['undo', 'redo', 'formatmatch',
  25357. 'bold', 'italic', 'underline', 'fontborder', 'touppercase', 'tolowercase',
  25358. 'strikethrough', 'subscript', 'superscript', 'source', 'indent', 'outdent',
  25359. 'blockquote', 'pasteplain', 'pagebreak',
  25360. 'selectall', 'print','horizontal', 'removeformat', 'time', 'date', 'unlink',
  25361. 'insertparagraphbeforetable', 'insertrow', 'insertcol', 'mergeright', 'mergedown', 'deleterow',
  25362. 'deletecol', 'splittorows', 'splittocols', 'splittocells', 'mergecells', 'deletetable', 'drafts'];
  25363. for (var i = 0, ci; ci = btnCmds[i++];) {
  25364. ci = ci.toLowerCase();
  25365. editorui[ci] = function (cmd) {
  25366. return function (editor) {
  25367. var ui = new editorui.Button({
  25368. className:'edui-for-' + cmd,
  25369. title:editor.options.labelMap[cmd] || editor.getLang("labelMap." + cmd) || '',
  25370. onclick:function () {
  25371. editor.execCommand(cmd);
  25372. },
  25373. theme:editor.options.theme,
  25374. showText:false
  25375. });
  25376. editorui.buttons[cmd] = ui;
  25377. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25378. var state = editor.queryCommandState(cmd);
  25379. if (state == -1) {
  25380. ui.setDisabled(true);
  25381. ui.setChecked(false);
  25382. } else {
  25383. if (!uiReady) {
  25384. ui.setDisabled(false);
  25385. ui.setChecked(state);
  25386. }
  25387. }
  25388. });
  25389. return ui;
  25390. };
  25391. }(ci);
  25392. }
  25393. //清除文档
  25394. editorui.cleardoc = function (editor) {
  25395. var ui = new editorui.Button({
  25396. className:'edui-for-cleardoc',
  25397. title:editor.options.labelMap.cleardoc || editor.getLang("labelMap.cleardoc") || '',
  25398. theme:editor.options.theme,
  25399. onclick:function () {
  25400. if (confirm(editor.getLang("confirmClear"))) {
  25401. editor.execCommand('cleardoc');
  25402. }
  25403. }
  25404. });
  25405. editorui.buttons["cleardoc"] = ui;
  25406. editor.addListener('selectionchange', function () {
  25407. ui.setDisabled(editor.queryCommandState('cleardoc') == -1);
  25408. });
  25409. return ui;
  25410. };
  25411. //排版,图片排版,文字方向
  25412. var typeset = {
  25413. 'justify':['left', 'right', 'center', 'justify'],
  25414. 'imagefloat':['none', 'left', 'center', 'right'],
  25415. 'directionality':['ltr', 'rtl']
  25416. };
  25417. for (var p in typeset) {
  25418. (function (cmd, val) {
  25419. for (var i = 0, ci; ci = val[i++];) {
  25420. (function (cmd2) {
  25421. editorui[cmd.replace('float', '') + cmd2] = function (editor) {
  25422. var ui = new editorui.Button({
  25423. className:'edui-for-' + cmd.replace('float', '') + cmd2,
  25424. title:editor.options.labelMap[cmd.replace('float', '') + cmd2] || editor.getLang("labelMap." + cmd.replace('float', '') + cmd2) || '',
  25425. theme:editor.options.theme,
  25426. onclick:function () {
  25427. editor.execCommand(cmd, cmd2);
  25428. }
  25429. });
  25430. editorui.buttons[cmd] = ui;
  25431. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25432. ui.setDisabled(editor.queryCommandState(cmd) == -1);
  25433. ui.setChecked(editor.queryCommandValue(cmd) == cmd2 && !uiReady);
  25434. });
  25435. return ui;
  25436. };
  25437. })(ci)
  25438. }
  25439. })(p, typeset[p])
  25440. }
  25441. //字体颜色和背景颜色
  25442. for (var i = 0, ci; ci = ['backcolor', 'forecolor'][i++];) {
  25443. editorui[ci] = function (cmd) {
  25444. return function (editor) {
  25445. var ui = new editorui.ColorButton({
  25446. className:'edui-for-' + cmd,
  25447. color:'default',
  25448. title:editor.options.labelMap[cmd] || editor.getLang("labelMap." + cmd) || '',
  25449. editor:editor,
  25450. onpickcolor:function (t, color) {
  25451. editor.execCommand(cmd, color);
  25452. },
  25453. onpicknocolor:function () {
  25454. editor.execCommand(cmd, 'default');
  25455. this.setColor('transparent');
  25456. this.color = 'default';
  25457. },
  25458. onbuttonclick:function () {
  25459. editor.execCommand(cmd, this.color);
  25460. }
  25461. });
  25462. editorui.buttons[cmd] = ui;
  25463. editor.addListener('selectionchange', function () {
  25464. ui.setDisabled(editor.queryCommandState(cmd) == -1);
  25465. });
  25466. return ui;
  25467. };
  25468. }(ci);
  25469. }
  25470. var dialogBtns = {
  25471. noOk:['searchreplace', 'help', 'spechars', 'webapp','preview'],
  25472. ok:['attachment', 'anchor', 'link', 'insertimage', 'map', 'gmap', 'insertframe', 'wordimage',
  25473. 'insertvideo', 'insertframe', 'edittip', 'edittable', 'edittd', 'scrawl', 'template', 'music', 'background', 'charts']
  25474. };
  25475. for (var p in dialogBtns) {
  25476. (function (type, vals) {
  25477. for (var i = 0, ci; ci = vals[i++];) {
  25478. //todo opera下存在问题
  25479. if (browser.opera && ci === "searchreplace") {
  25480. continue;
  25481. }
  25482. (function (cmd) {
  25483. editorui[cmd] = function (editor, iframeUrl, title) {
  25484. iframeUrl = iframeUrl || (editor.options.iframeUrlMap || {})[cmd] || iframeUrlMap[cmd];
  25485. title = editor.options.labelMap[cmd] || editor.getLang("labelMap." + cmd) || '';
  25486. var dialog;
  25487. //没有iframeUrl不创建dialog
  25488. if (iframeUrl) {
  25489. dialog = new editorui.Dialog(utils.extend({
  25490. iframeUrl:editor.ui.mapUrl(iframeUrl),
  25491. editor:editor,
  25492. className:'edui-for-' + cmd,
  25493. title:title,
  25494. holdScroll: cmd === 'insertimage',
  25495. fullscreen: /charts|preview/.test(cmd),
  25496. closeDialog:editor.getLang("closeDialog")
  25497. }, type == 'ok' ? {
  25498. buttons:[
  25499. {
  25500. className:'edui-okbutton',
  25501. label:editor.getLang("ok"),
  25502. editor:editor,
  25503. onclick:function () {
  25504. dialog.close(true);
  25505. }
  25506. },
  25507. {
  25508. className:'edui-cancelbutton',
  25509. label:editor.getLang("cancel"),
  25510. editor:editor,
  25511. onclick:function () {
  25512. dialog.close(false);
  25513. }
  25514. }
  25515. ]
  25516. } : {}));
  25517. editor.ui._dialogs[cmd + "Dialog"] = dialog;
  25518. }
  25519. var ui = new editorui.Button({
  25520. className:'edui-for-' + cmd,
  25521. title:title,
  25522. onclick:function () {
  25523. if (dialog) {
  25524. switch (cmd) {
  25525. case "wordimage":
  25526. var images = editor.execCommand("wordimage");
  25527. if (images && images.length) {
  25528. dialog.render();
  25529. dialog.open();
  25530. }
  25531. break;
  25532. case "scrawl":
  25533. if (editor.queryCommandState("scrawl") != -1) {
  25534. dialog.render();
  25535. dialog.open();
  25536. }
  25537. break;
  25538. default:
  25539. dialog.render();
  25540. dialog.open();
  25541. }
  25542. }
  25543. },
  25544. theme:editor.options.theme,
  25545. disabled:(cmd == 'scrawl' && editor.queryCommandState("scrawl") == -1) || ( cmd == 'charts' )
  25546. });
  25547. editorui.buttons[cmd] = ui;
  25548. editor.addListener('selectionchange', function () {
  25549. //只存在于右键菜单而无工具栏按钮的ui不需要检测状态
  25550. var unNeedCheckState = {'edittable':1};
  25551. if (cmd in unNeedCheckState)return;
  25552. var state = editor.queryCommandState(cmd);
  25553. if (ui.getDom()) {
  25554. ui.setDisabled(state == -1);
  25555. ui.setChecked(state);
  25556. }
  25557. });
  25558. return ui;
  25559. };
  25560. })(ci.toLowerCase())
  25561. }
  25562. })(p, dialogBtns[p]);
  25563. }
  25564. editorui.snapscreen = function (editor, iframeUrl, title) {
  25565. title = editor.options.labelMap['snapscreen'] || editor.getLang("labelMap.snapscreen") || '';
  25566. var ui = new editorui.Button({
  25567. className:'edui-for-snapscreen',
  25568. title:title,
  25569. onclick:function () {
  25570. editor.execCommand("snapscreen");
  25571. },
  25572. theme:editor.options.theme
  25573. });
  25574. editorui.buttons['snapscreen'] = ui;
  25575. iframeUrl = iframeUrl || (editor.options.iframeUrlMap || {})["snapscreen"] || iframeUrlMap["snapscreen"];
  25576. if (iframeUrl) {
  25577. var dialog = new editorui.Dialog({
  25578. iframeUrl:editor.ui.mapUrl(iframeUrl),
  25579. editor:editor,
  25580. className:'edui-for-snapscreen',
  25581. title:title,
  25582. buttons:[
  25583. {
  25584. className:'edui-okbutton',
  25585. label:editor.getLang("ok"),
  25586. editor:editor,
  25587. onclick:function () {
  25588. dialog.close(true);
  25589. }
  25590. },
  25591. {
  25592. className:'edui-cancelbutton',
  25593. label:editor.getLang("cancel"),
  25594. editor:editor,
  25595. onclick:function () {
  25596. dialog.close(false);
  25597. }
  25598. }
  25599. ]
  25600. });
  25601. dialog.render();
  25602. editor.ui._dialogs["snapscreenDialog"] = dialog;
  25603. }
  25604. editor.addListener('selectionchange', function () {
  25605. ui.setDisabled(editor.queryCommandState('snapscreen') == -1);
  25606. });
  25607. return ui;
  25608. };
  25609. editorui.insertcode = function (editor, list, title) {
  25610. list = editor.options['insertcode'] || [];
  25611. title = editor.options.labelMap['insertcode'] || editor.getLang("labelMap.insertcode") || '';
  25612. // if (!list.length) return;
  25613. var items = [];
  25614. utils.each(list,function(key,val){
  25615. items.push({
  25616. label:key,
  25617. value:val,
  25618. theme:editor.options.theme,
  25619. renderLabelHtml:function () {
  25620. return '<div class="edui-label %%-label" >' + (this.label || '') + '</div>';
  25621. }
  25622. });
  25623. });
  25624. var ui = new editorui.Combox({
  25625. editor:editor,
  25626. items:items,
  25627. onselect:function (t, index) {
  25628. editor.execCommand('insertcode', this.items[index].value);
  25629. },
  25630. onbuttonclick:function () {
  25631. this.showPopup();
  25632. },
  25633. title:title,
  25634. initValue:title,
  25635. className:'edui-for-insertcode',
  25636. indexByValue:function (value) {
  25637. if (value) {
  25638. for (var i = 0, ci; ci = this.items[i]; i++) {
  25639. if (ci.value.indexOf(value) != -1)
  25640. return i;
  25641. }
  25642. }
  25643. return -1;
  25644. }
  25645. });
  25646. editorui.buttons['insertcode'] = ui;
  25647. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25648. if (!uiReady) {
  25649. var state = editor.queryCommandState('insertcode');
  25650. if (state == -1) {
  25651. ui.setDisabled(true);
  25652. } else {
  25653. ui.setDisabled(false);
  25654. var value = editor.queryCommandValue('insertcode');
  25655. if(!value){
  25656. ui.setValue(title);
  25657. return;
  25658. }
  25659. //trace:1871 ie下从源码模式切换回来时,字体会带单引号,而且会有逗号
  25660. value && (value = value.replace(/['"]/g, '').split(',')[0]);
  25661. ui.setValue(value);
  25662. }
  25663. }
  25664. });
  25665. return ui;
  25666. };
  25667. editorui.fontfamily = function (editor, list, title) {
  25668. list = editor.options['fontfamily'] || [];
  25669. title = editor.options.labelMap['fontfamily'] || editor.getLang("labelMap.fontfamily") || '';
  25670. if (!list.length) return;
  25671. for (var i = 0, ci, items = []; ci = list[i]; i++) {
  25672. var langLabel = editor.getLang('fontfamily')[ci.name] || "";
  25673. (function (key, val) {
  25674. items.push({
  25675. label:key,
  25676. value:val,
  25677. theme:editor.options.theme,
  25678. renderLabelHtml:function () {
  25679. return '<div class="edui-label %%-label" style="font-family:' +
  25680. utils.unhtml(this.value) + '">' + (this.label || '') + '</div>';
  25681. }
  25682. });
  25683. })(ci.label || langLabel, ci.val)
  25684. }
  25685. var ui = new editorui.Combox({
  25686. editor:editor,
  25687. items:items,
  25688. onselect:function (t, index) {
  25689. editor.execCommand('FontFamily', this.items[index].value);
  25690. },
  25691. onbuttonclick:function () {
  25692. this.showPopup();
  25693. },
  25694. title:title,
  25695. initValue:title,
  25696. className:'edui-for-fontfamily',
  25697. indexByValue:function (value) {
  25698. if (value) {
  25699. for (var i = 0, ci; ci = this.items[i]; i++) {
  25700. if (ci.value.indexOf(value) != -1)
  25701. return i;
  25702. }
  25703. }
  25704. return -1;
  25705. }
  25706. });
  25707. editorui.buttons['fontfamily'] = ui;
  25708. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25709. if (!uiReady) {
  25710. var state = editor.queryCommandState('FontFamily');
  25711. if (state == -1) {
  25712. ui.setDisabled(true);
  25713. } else {
  25714. ui.setDisabled(false);
  25715. var value = editor.queryCommandValue('FontFamily');
  25716. //trace:1871 ie下从源码模式切换回来时,字体会带单引号,而且会有逗号
  25717. value && (value = value.replace(/['"]/g, '').split(',')[0]);
  25718. ui.setValue(value);
  25719. }
  25720. }
  25721. });
  25722. return ui;
  25723. };
  25724. editorui.fontsize = function (editor, list, title) {
  25725. title = editor.options.labelMap['fontsize'] || editor.getLang("labelMap.fontsize") || '';
  25726. list = list || editor.options['fontsize'] || [];
  25727. if (!list.length) return;
  25728. var items = [];
  25729. for (var i = 0; i < list.length; i++) {
  25730. var size = list[i] + 'px';
  25731. items.push({
  25732. label:size,
  25733. value:size,
  25734. theme:editor.options.theme,
  25735. renderLabelHtml:function () {
  25736. return '<div class="edui-label %%-label" style="line-height:1;font-size:' +
  25737. this.value + '">' + (this.label || '') + '</div>';
  25738. }
  25739. });
  25740. }
  25741. var ui = new editorui.Combox({
  25742. editor:editor,
  25743. items:items,
  25744. title:title,
  25745. initValue:title,
  25746. onselect:function (t, index) {
  25747. editor.execCommand('FontSize', this.items[index].value);
  25748. },
  25749. onbuttonclick:function () {
  25750. this.showPopup();
  25751. },
  25752. className:'edui-for-fontsize'
  25753. });
  25754. editorui.buttons['fontsize'] = ui;
  25755. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25756. if (!uiReady) {
  25757. var state = editor.queryCommandState('FontSize');
  25758. if (state == -1) {
  25759. ui.setDisabled(true);
  25760. } else {
  25761. ui.setDisabled(false);
  25762. ui.setValue(editor.queryCommandValue('FontSize'));
  25763. }
  25764. }
  25765. });
  25766. return ui;
  25767. };
  25768. editorui.paragraph = function (editor, list, title) {
  25769. title = editor.options.labelMap['paragraph'] || editor.getLang("labelMap.paragraph") || '';
  25770. list = editor.options['paragraph'] || [];
  25771. if (utils.isEmptyObject(list)) return;
  25772. var items = [];
  25773. for (var i in list) {
  25774. items.push({
  25775. value:i,
  25776. label:list[i] || editor.getLang("paragraph")[i],
  25777. theme:editor.options.theme,
  25778. renderLabelHtml:function () {
  25779. return '<div class="edui-label %%-label"><span class="edui-for-' + this.value + '">' + (this.label || '') + '</span></div>';
  25780. }
  25781. })
  25782. }
  25783. var ui = new editorui.Combox({
  25784. editor:editor,
  25785. items:items,
  25786. title:title,
  25787. initValue:title,
  25788. className:'edui-for-paragraph',
  25789. onselect:function (t, index) {
  25790. editor.execCommand('Paragraph', this.items[index].value);
  25791. },
  25792. onbuttonclick:function () {
  25793. this.showPopup();
  25794. }
  25795. });
  25796. editorui.buttons['paragraph'] = ui;
  25797. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25798. if (!uiReady) {
  25799. var state = editor.queryCommandState('Paragraph');
  25800. if (state == -1) {
  25801. ui.setDisabled(true);
  25802. } else {
  25803. ui.setDisabled(false);
  25804. var value = editor.queryCommandValue('Paragraph');
  25805. var index = ui.indexByValue(value);
  25806. if (index != -1) {
  25807. ui.setValue(value);
  25808. } else {
  25809. ui.setValue(ui.initValue);
  25810. }
  25811. }
  25812. }
  25813. });
  25814. return ui;
  25815. };
  25816. //自定义标题
  25817. editorui.customstyle = function (editor) {
  25818. var list = editor.options['customstyle'] || [],
  25819. title = editor.options.labelMap['customstyle'] || editor.getLang("labelMap.customstyle") || '';
  25820. if (!list.length)return;
  25821. var langCs = editor.getLang('customstyle');
  25822. for (var i = 0, items = [], t; t = list[i++];) {
  25823. (function (t) {
  25824. var ck = {};
  25825. ck.label = t.label ? t.label : langCs[t.name];
  25826. ck.style = t.style;
  25827. ck.className = t.className;
  25828. ck.tag = t.tag;
  25829. items.push({
  25830. label:ck.label,
  25831. value:ck,
  25832. theme:editor.options.theme,
  25833. renderLabelHtml:function () {
  25834. return '<div class="edui-label %%-label">' + '<' + ck.tag + ' ' + (ck.className ? ' class="' + ck.className + '"' : "")
  25835. + (ck.style ? ' style="' + ck.style + '"' : "") + '>' + ck.label + "<\/" + ck.tag + ">"
  25836. + '</div>';
  25837. }
  25838. });
  25839. })(t);
  25840. }
  25841. var ui = new editorui.Combox({
  25842. editor:editor,
  25843. items:items,
  25844. title:title,
  25845. initValue:title,
  25846. className:'edui-for-customstyle',
  25847. onselect:function (t, index) {
  25848. editor.execCommand('customstyle', this.items[index].value);
  25849. },
  25850. onbuttonclick:function () {
  25851. this.showPopup();
  25852. },
  25853. indexByValue:function (value) {
  25854. for (var i = 0, ti; ti = this.items[i++];) {
  25855. if (ti.label == value) {
  25856. return i - 1
  25857. }
  25858. }
  25859. return -1;
  25860. }
  25861. });
  25862. editorui.buttons['customstyle'] = ui;
  25863. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25864. if (!uiReady) {
  25865. var state = editor.queryCommandState('customstyle');
  25866. if (state == -1) {
  25867. ui.setDisabled(true);
  25868. } else {
  25869. ui.setDisabled(false);
  25870. var value = editor.queryCommandValue('customstyle');
  25871. var index = ui.indexByValue(value);
  25872. if (index != -1) {
  25873. ui.setValue(value);
  25874. } else {
  25875. ui.setValue(ui.initValue);
  25876. }
  25877. }
  25878. }
  25879. });
  25880. return ui;
  25881. };
  25882. editorui.inserttable = function (editor, iframeUrl, title) {
  25883. title = editor.options.labelMap['inserttable'] || editor.getLang("labelMap.inserttable") || '';
  25884. var ui = new editorui.TableButton({
  25885. editor:editor,
  25886. title:title,
  25887. className:'edui-for-inserttable',
  25888. onpicktable:function (t, numCols, numRows) {
  25889. editor.execCommand('InsertTable', {numRows:numRows, numCols:numCols, border:1});
  25890. },
  25891. onbuttonclick:function () {
  25892. this.showPopup();
  25893. }
  25894. });
  25895. editorui.buttons['inserttable'] = ui;
  25896. editor.addListener('selectionchange', function () {
  25897. ui.setDisabled(editor.queryCommandState('inserttable') == -1);
  25898. });
  25899. return ui;
  25900. };
  25901. editorui.lineheight = function (editor) {
  25902. var val = editor.options.lineheight || [];
  25903. if (!val.length)return;
  25904. for (var i = 0, ci, items = []; ci = val[i++];) {
  25905. items.push({
  25906. //todo:写死了
  25907. label:ci,
  25908. value:ci,
  25909. theme:editor.options.theme,
  25910. onclick:function () {
  25911. editor.execCommand("lineheight", this.value);
  25912. }
  25913. })
  25914. }
  25915. var ui = new editorui.MenuButton({
  25916. editor:editor,
  25917. className:'edui-for-lineheight',
  25918. title:editor.options.labelMap['lineheight'] || editor.getLang("labelMap.lineheight") || '',
  25919. items:items,
  25920. onbuttonclick:function () {
  25921. var value = editor.queryCommandValue('LineHeight') || this.value;
  25922. editor.execCommand("LineHeight", value);
  25923. }
  25924. });
  25925. editorui.buttons['lineheight'] = ui;
  25926. editor.addListener('selectionchange', function () {
  25927. var state = editor.queryCommandState('LineHeight');
  25928. if (state == -1) {
  25929. ui.setDisabled(true);
  25930. } else {
  25931. ui.setDisabled(false);
  25932. var value = editor.queryCommandValue('LineHeight');
  25933. value && ui.setValue((value + '').replace(/cm/, ''));
  25934. ui.setChecked(state)
  25935. }
  25936. });
  25937. return ui;
  25938. };
  25939. var rowspacings = ['top', 'bottom'];
  25940. for (var r = 0, ri; ri = rowspacings[r++];) {
  25941. (function (cmd) {
  25942. editorui['rowspacing' + cmd] = function (editor) {
  25943. var val = editor.options['rowspacing' + cmd] || [];
  25944. if (!val.length) return null;
  25945. for (var i = 0, ci, items = []; ci = val[i++];) {
  25946. items.push({
  25947. label:ci,
  25948. value:ci,
  25949. theme:editor.options.theme,
  25950. onclick:function () {
  25951. editor.execCommand("rowspacing", this.value, cmd);
  25952. }
  25953. })
  25954. }
  25955. var ui = new editorui.MenuButton({
  25956. editor:editor,
  25957. className:'edui-for-rowspacing' + cmd,
  25958. title:editor.options.labelMap['rowspacing' + cmd] || editor.getLang("labelMap.rowspacing" + cmd) || '',
  25959. items:items,
  25960. onbuttonclick:function () {
  25961. var value = editor.queryCommandValue('rowspacing', cmd) || this.value;
  25962. editor.execCommand("rowspacing", value, cmd);
  25963. }
  25964. });
  25965. editorui.buttons[cmd] = ui;
  25966. editor.addListener('selectionchange', function () {
  25967. var state = editor.queryCommandState('rowspacing', cmd);
  25968. if (state == -1) {
  25969. ui.setDisabled(true);
  25970. } else {
  25971. ui.setDisabled(false);
  25972. var value = editor.queryCommandValue('rowspacing', cmd);
  25973. value && ui.setValue((value + '').replace(/%/, ''));
  25974. ui.setChecked(state)
  25975. }
  25976. });
  25977. return ui;
  25978. }
  25979. })(ri)
  25980. }
  25981. //有序,无序列表
  25982. var lists = ['insertorderedlist', 'insertunorderedlist'];
  25983. for (var l = 0, cl; cl = lists[l++];) {
  25984. (function (cmd) {
  25985. editorui[cmd] = function (editor) {
  25986. var vals = editor.options[cmd],
  25987. _onMenuClick = function () {
  25988. editor.execCommand(cmd, this.value);
  25989. }, items = [];
  25990. for (var i in vals) {
  25991. items.push({
  25992. label:vals[i] || editor.getLang()[cmd][i] || "",
  25993. value:i,
  25994. theme:editor.options.theme,
  25995. onclick:_onMenuClick
  25996. })
  25997. }
  25998. var ui = new editorui.MenuButton({
  25999. editor:editor,
  26000. className:'edui-for-' + cmd,
  26001. title:editor.getLang("labelMap." + cmd) || '',
  26002. 'items':items,
  26003. onbuttonclick:function () {
  26004. var value = editor.queryCommandValue(cmd) || this.value;
  26005. editor.execCommand(cmd, value);
  26006. }
  26007. });
  26008. editorui.buttons[cmd] = ui;
  26009. editor.addListener('selectionchange', function () {
  26010. var state = editor.queryCommandState(cmd);
  26011. if (state == -1) {
  26012. ui.setDisabled(true);
  26013. } else {
  26014. ui.setDisabled(false);
  26015. var value = editor.queryCommandValue(cmd);
  26016. ui.setValue(value);
  26017. ui.setChecked(state)
  26018. }
  26019. });
  26020. return ui;
  26021. };
  26022. })(cl)
  26023. }
  26024. editorui.fullscreen = function (editor, title) {
  26025. title = editor.options.labelMap['fullscreen'] || editor.getLang("labelMap.fullscreen") || '';
  26026. var ui = new editorui.Button({
  26027. className:'edui-for-fullscreen',
  26028. title:title,
  26029. theme:editor.options.theme,
  26030. onclick:function () {
  26031. if (editor.ui) {
  26032. editor.ui.setFullScreen(!editor.ui.isFullScreen());
  26033. }
  26034. this.setChecked(editor.ui.isFullScreen());
  26035. }
  26036. });
  26037. editorui.buttons['fullscreen'] = ui;
  26038. editor.addListener('selectionchange', function () {
  26039. var state = editor.queryCommandState('fullscreen');
  26040. ui.setDisabled(state == -1);
  26041. ui.setChecked(editor.ui.isFullScreen());
  26042. });
  26043. return ui;
  26044. };
  26045. // 表情
  26046. editorui["emotion"] = function (editor, iframeUrl) {
  26047. var cmd = "emotion";
  26048. var ui = new editorui.MultiMenuPop({
  26049. title:editor.options.labelMap[cmd] || editor.getLang("labelMap." + cmd + "") || '',
  26050. editor:editor,
  26051. className:'edui-for-' + cmd,
  26052. iframeUrl:editor.ui.mapUrl(iframeUrl || (editor.options.iframeUrlMap || {})[cmd] || iframeUrlMap[cmd])
  26053. });
  26054. editorui.buttons[cmd] = ui;
  26055. editor.addListener('selectionchange', function () {
  26056. ui.setDisabled(editor.queryCommandState(cmd) == -1)
  26057. });
  26058. return ui;
  26059. };
  26060. editorui.autotypeset = function (editor) {
  26061. var ui = new editorui.AutoTypeSetButton({
  26062. editor:editor,
  26063. title:editor.options.labelMap['autotypeset'] || editor.getLang("labelMap.autotypeset") || '',
  26064. className:'edui-for-autotypeset',
  26065. onbuttonclick:function () {
  26066. editor.execCommand('autotypeset')
  26067. }
  26068. });
  26069. editorui.buttons['autotypeset'] = ui;
  26070. editor.addListener('selectionchange', function () {
  26071. ui.setDisabled(editor.queryCommandState('autotypeset') == -1);
  26072. });
  26073. return ui;
  26074. };
  26075. /* 简单上传插件 */
  26076. editorui["simpleupload"] = function (editor) {
  26077. var name = 'simpleupload',
  26078. ui = new editorui.Button({
  26079. className:'edui-for-' + name,
  26080. title:editor.options.labelMap[name] || editor.getLang("labelMap." + name) || '',
  26081. onclick:function () {},
  26082. theme:editor.options.theme,
  26083. showText:false
  26084. });
  26085. editorui.buttons[name] = ui;
  26086. editor.addListener('ready', function() {
  26087. var b = ui.getDom('body'),
  26088. iconSpan = b.children[0];
  26089. editor.fireEvent('simpleuploadbtnready', iconSpan);
  26090. });
  26091. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  26092. var state = editor.queryCommandState(name);
  26093. if (state == -1) {
  26094. ui.setDisabled(true);
  26095. ui.setChecked(false);
  26096. } else {
  26097. if (!uiReady) {
  26098. ui.setDisabled(false);
  26099. ui.setChecked(state);
  26100. }
  26101. }
  26102. });
  26103. return ui;
  26104. };
  26105. })();
  26106. // adapter/editor.js
  26107. ///import core
  26108. ///commands 全屏
  26109. ///commandsName FullScreen
  26110. ///commandsTitle 全屏
  26111. (function () {
  26112. var utils = baidu.editor.utils,
  26113. uiUtils = baidu.editor.ui.uiUtils,
  26114. UIBase = baidu.editor.ui.UIBase,
  26115. domUtils = baidu.editor.dom.domUtils;
  26116. var nodeStack = [];
  26117. function EditorUI(options) {
  26118. this.initOptions(options);
  26119. this.initEditorUI();
  26120. }
  26121. EditorUI.prototype = {
  26122. uiName:'editor',
  26123. initEditorUI:function () {
  26124. this.editor.ui = this;
  26125. this._dialogs = {};
  26126. this.initUIBase();
  26127. this._initToolbars();
  26128. var editor = this.editor,
  26129. me = this;
  26130. editor.addListener('ready', function () {
  26131. //提供getDialog方法
  26132. editor.getDialog = function (name) {
  26133. return editor.ui._dialogs[name + "Dialog"];
  26134. };
  26135. domUtils.on(editor.window, 'scroll', function (evt) {
  26136. baidu.editor.ui.Popup.postHide(evt);
  26137. });
  26138. //提供编辑器实时宽高(全屏时宽高不变化)
  26139. editor.ui._actualFrameWidth = editor.options.initialFrameWidth;
  26140. UE.browser.ie && UE.browser.version === 6 && editor.container.ownerDocument.execCommand("BackgroundImageCache", false, true);
  26141. //display bottom-bar label based on config
  26142. if (editor.options.elementPathEnabled) {
  26143. editor.ui.getDom('elementpath').innerHTML = '<div class="edui-editor-breadcrumb">' + editor.getLang("elementPathTip") + ':</div>';
  26144. }
  26145. if (editor.options.wordCount) {
  26146. function countFn() {
  26147. setCount(editor,me);
  26148. domUtils.un(editor.document, "click", arguments.callee);
  26149. }
  26150. domUtils.on(editor.document, "click", countFn);
  26151. editor.ui.getDom('wordcount').innerHTML = editor.getLang("wordCountTip");
  26152. }
  26153. editor.ui._scale();
  26154. if (editor.options.scaleEnabled) {
  26155. if (editor.autoHeightEnabled) {
  26156. editor.disableAutoHeight();
  26157. }
  26158. me.enableScale();
  26159. } else {
  26160. me.disableScale();
  26161. }
  26162. if (!editor.options.elementPathEnabled && !editor.options.wordCount && !editor.options.scaleEnabled) {
  26163. editor.ui.getDom('elementpath').style.display = "none";
  26164. editor.ui.getDom('wordcount').style.display = "none";
  26165. editor.ui.getDom('scale').style.display = "none";
  26166. }
  26167. if (!editor.selection.isFocus())return;
  26168. editor.fireEvent('selectionchange', false, true);
  26169. });
  26170. editor.addListener('mousedown', function (t, evt) {
  26171. var el = evt.target || evt.srcElement;
  26172. baidu.editor.ui.Popup.postHide(evt, el);
  26173. baidu.editor.ui.ShortCutMenu.postHide(evt);
  26174. });
  26175. editor.addListener("delcells", function () {
  26176. if (UE.ui['edittip']) {
  26177. new UE.ui['edittip'](editor);
  26178. }
  26179. editor.getDialog('edittip').open();
  26180. });
  26181. var pastePop, isPaste = false, timer;
  26182. editor.addListener("afterpaste", function () {
  26183. if(editor.queryCommandState('pasteplain'))
  26184. return;
  26185. if(baidu.editor.ui.PastePicker){
  26186. pastePop = new baidu.editor.ui.Popup({
  26187. content:new baidu.editor.ui.PastePicker({editor:editor}),
  26188. editor:editor,
  26189. className:'edui-wordpastepop'
  26190. });
  26191. pastePop.render();
  26192. }
  26193. isPaste = true;
  26194. });
  26195. editor.addListener("afterinserthtml", function () {
  26196. clearTimeout(timer);
  26197. timer = setTimeout(function () {
  26198. if (pastePop && (isPaste || editor.ui._isTransfer)) {
  26199. if(pastePop.isHidden()){
  26200. var span = domUtils.createElement(editor.document, 'span', {
  26201. 'style':"line-height:0px;",
  26202. 'innerHTML':'\ufeff'
  26203. }),
  26204. range = editor.selection.getRange();
  26205. range.insertNode(span);
  26206. var tmp= getDomNode(span, 'firstChild', 'previousSibling');
  26207. tmp && pastePop.showAnchor(tmp.nodeType == 3 ? tmp.parentNode : tmp);
  26208. domUtils.remove(span);
  26209. }else{
  26210. pastePop.show();
  26211. }
  26212. delete editor.ui._isTransfer;
  26213. isPaste = false;
  26214. }
  26215. }, 200)
  26216. });
  26217. editor.addListener('contextmenu', function (t, evt) {
  26218. baidu.editor.ui.Popup.postHide(evt);
  26219. });
  26220. editor.addListener('keydown', function (t, evt) {
  26221. if (pastePop) pastePop.dispose(evt);
  26222. var keyCode = evt.keyCode || evt.which;
  26223. if(evt.altKey&&keyCode==90){
  26224. UE.ui.buttons['fullscreen'].onclick();
  26225. }
  26226. });
  26227. editor.addListener('wordcount', function (type) {
  26228. setCount(this,me);
  26229. });
  26230. function setCount(editor,ui) {
  26231. editor.setOpt({
  26232. wordCount:true,
  26233. maximumWords:10000,
  26234. wordCountMsg:editor.options.wordCountMsg || editor.getLang("wordCountMsg"),
  26235. wordOverFlowMsg:editor.options.wordOverFlowMsg || editor.getLang("wordOverFlowMsg")
  26236. });
  26237. var opt = editor.options,
  26238. max = opt.maximumWords,
  26239. msg = opt.wordCountMsg ,
  26240. errMsg = opt.wordOverFlowMsg,
  26241. countDom = ui.getDom('wordcount');
  26242. if (!opt.wordCount) {
  26243. return;
  26244. }
  26245. var count = editor.getContentLength(true);
  26246. if (count > max) {
  26247. countDom.innerHTML = errMsg;
  26248. editor.fireEvent("wordcountoverflow");
  26249. } else {
  26250. countDom.innerHTML = msg.replace("{#leave}", max - count).replace("{#count}", count);
  26251. }
  26252. }
  26253. editor.addListener('selectionchange', function () {
  26254. if (editor.options.elementPathEnabled) {
  26255. me[(editor.queryCommandState('elementpath') == -1 ? 'dis' : 'en') + 'ableElementPath']()
  26256. }
  26257. if (editor.options.scaleEnabled) {
  26258. me[(editor.queryCommandState('scale') == -1 ? 'dis' : 'en') + 'ableScale']();
  26259. }
  26260. });
  26261. var popup = new baidu.editor.ui.Popup({
  26262. editor:editor,
  26263. content:'',
  26264. className:'edui-bubble',
  26265. _onEditButtonClick:function () {
  26266. this.hide();
  26267. editor.ui._dialogs.linkDialog.open();
  26268. },
  26269. _onImgEditButtonClick:function (name) {
  26270. this.hide();
  26271. editor.ui._dialogs[name] && editor.ui._dialogs[name].open();
  26272. },
  26273. _onImgSetFloat:function (value) {
  26274. this.hide();
  26275. editor.execCommand("imagefloat", value);
  26276. },
  26277. _setIframeAlign:function (value) {
  26278. var frame = popup.anchorEl;
  26279. var newFrame = frame.cloneNode(true);
  26280. switch (value) {
  26281. case -2:
  26282. newFrame.setAttribute("align", "");
  26283. break;
  26284. case -1:
  26285. newFrame.setAttribute("align", "left");
  26286. break;
  26287. case 1:
  26288. newFrame.setAttribute("align", "right");
  26289. break;
  26290. }
  26291. frame.parentNode.insertBefore(newFrame, frame);
  26292. domUtils.remove(frame);
  26293. popup.anchorEl = newFrame;
  26294. popup.showAnchor(popup.anchorEl);
  26295. },
  26296. _updateIframe:function () {
  26297. var frame = editor._iframe = popup.anchorEl;
  26298. if(domUtils.hasClass(frame, 'ueditor_baidumap')) {
  26299. editor.selection.getRange().selectNode(frame).select();
  26300. editor.ui._dialogs.mapDialog.open();
  26301. popup.hide();
  26302. } else {
  26303. editor.ui._dialogs.insertframeDialog.open();
  26304. popup.hide();
  26305. }
  26306. },
  26307. _onRemoveButtonClick:function (cmdName) {
  26308. editor.execCommand(cmdName);
  26309. this.hide();
  26310. },
  26311. queryAutoHide:function (el) {
  26312. if (el && el.ownerDocument == editor.document) {
  26313. if (el.tagName.toLowerCase() == 'img' || domUtils.findParentByTagName(el, 'a', true)) {
  26314. return el !== popup.anchorEl;
  26315. }
  26316. }
  26317. return baidu.editor.ui.Popup.prototype.queryAutoHide.call(this, el);
  26318. }
  26319. });
  26320. popup.render();
  26321. if (editor.options.imagePopup) {
  26322. editor.addListener('mouseover', function (t, evt) {
  26323. evt = evt || window.event;
  26324. var el = evt.target || evt.srcElement;
  26325. if (editor.ui._dialogs.insertframeDialog && /iframe/ig.test(el.tagName)) {
  26326. var html = popup.formatHtml(
  26327. '<nobr>' + editor.getLang("property") + ': <span onclick=$$._setIframeAlign(-2) class="edui-clickable">' + editor.getLang("default") + '</span>&nbsp;&nbsp;<span onclick=$$._setIframeAlign(-1) class="edui-clickable">' + editor.getLang("justifyleft") + '</span>&nbsp;&nbsp;<span onclick=$$._setIframeAlign(1) class="edui-clickable">' + editor.getLang("justifyright") + '</span>&nbsp;&nbsp;' +
  26328. ' <span onclick="$$._updateIframe( this);" class="edui-clickable">' + editor.getLang("modify") + '</span></nobr>');
  26329. if (html) {
  26330. popup.getDom('content').innerHTML = html;
  26331. popup.anchorEl = el;
  26332. popup.showAnchor(popup.anchorEl);
  26333. } else {
  26334. popup.hide();
  26335. }
  26336. }
  26337. });
  26338. editor.addListener('selectionchange', function (t, causeByUi) {
  26339. if (!causeByUi) return;
  26340. var html = '', str = "",
  26341. img = editor.selection.getRange().getClosedNode(),
  26342. dialogs = editor.ui._dialogs;
  26343. if (img && img.tagName == 'IMG') {
  26344. var dialogName = 'insertimageDialog';
  26345. if (img.className.indexOf("edui-faked-video") != -1 || img.className.indexOf("edui-upload-video") != -1) {
  26346. dialogName = "insertvideoDialog"
  26347. }
  26348. if (img.className.indexOf("edui-faked-webapp") != -1) {
  26349. dialogName = "webappDialog"
  26350. }
  26351. if (img.src.indexOf("http://api.map.baidu.com") != -1) {
  26352. dialogName = "mapDialog"
  26353. }
  26354. if (img.className.indexOf("edui-faked-music") != -1) {
  26355. dialogName = "musicDialog"
  26356. }
  26357. if (img.src.indexOf("http://maps.google.com/maps/api/staticmap") != -1) {
  26358. dialogName = "gmapDialog"
  26359. }
  26360. if (img.getAttribute("anchorname")) {
  26361. dialogName = "anchorDialog";
  26362. html = popup.formatHtml(
  26363. '<nobr>' + editor.getLang("property") + ': <span onclick=$$._onImgEditButtonClick("anchorDialog") class="edui-clickable">' + editor.getLang("modify") + '</span>&nbsp;&nbsp;' +
  26364. '<span onclick=$$._onRemoveButtonClick(\'anchor\') class="edui-clickable">' + editor.getLang("delete") + '</span></nobr>');
  26365. }
  26366. if (img.getAttribute("word_img")) {
  26367. //todo 放到dialog去做查询
  26368. editor.word_img = [img.getAttribute("word_img")];
  26369. dialogName = "wordimageDialog"
  26370. }
  26371. if(domUtils.hasClass(img, 'loadingclass') || domUtils.hasClass(img, 'loaderrorclass')) {
  26372. dialogName = "";
  26373. }
  26374. if (!dialogs[dialogName]) {
  26375. return;
  26376. }
  26377. str = '<nobr>' + editor.getLang("property") + ': '+
  26378. '<span onclick=$$._onImgSetFloat("none") class="edui-clickable">' + editor.getLang("default") + '</span>&nbsp;&nbsp;' +
  26379. '<span onclick=$$._onImgSetFloat("left") class="edui-clickable">' + editor.getLang("justifyleft") + '</span>&nbsp;&nbsp;' +
  26380. '<span onclick=$$._onImgSetFloat("right") class="edui-clickable">' + editor.getLang("justifyright") + '</span>&nbsp;&nbsp;' +
  26381. '<span onclick=$$._onImgSetFloat("center") class="edui-clickable">' + editor.getLang("justifycenter") + '</span>&nbsp;&nbsp;'+
  26382. '<span onclick="$$._onImgEditButtonClick(\'' + dialogName + '\');" class="edui-clickable">' + editor.getLang("modify") + '</span></nobr>';
  26383. !html && (html = popup.formatHtml(str))
  26384. }
  26385. if (editor.ui._dialogs.linkDialog) {
  26386. var link = editor.queryCommandValue('link');
  26387. var url;
  26388. if (link && (url = (link.getAttribute('_href') || link.getAttribute('href', 2)))) {
  26389. var txt = url;
  26390. if (url.length > 30) {
  26391. txt = url.substring(0, 20) + "...";
  26392. }
  26393. if (html) {
  26394. html += '<div style="height:5px;"></div>'
  26395. }
  26396. html += popup.formatHtml(
  26397. '<nobr>' + editor.getLang("anthorMsg") + ': <a target="_blank" href="' + url + '" title="' + url + '" >' + txt + '</a>' +
  26398. ' <span class="edui-clickable" onclick="$$._onEditButtonClick();">' + editor.getLang("modify") + '</span>' +
  26399. ' <span class="edui-clickable" onclick="$$._onRemoveButtonClick(\'unlink\');"> ' + editor.getLang("clear") + '</span></nobr>');
  26400. popup.showAnchor(link);
  26401. }
  26402. }
  26403. if (html) {
  26404. popup.getDom('content').innerHTML = html;
  26405. popup.anchorEl = img || link;
  26406. popup.showAnchor(popup.anchorEl);
  26407. } else {
  26408. popup.hide();
  26409. }
  26410. });
  26411. }
  26412. },
  26413. _initToolbars:function () {
  26414. var editor = this.editor;
  26415. var toolbars = this.toolbars || [];
  26416. var toolbarUis = [];
  26417. for (var i = 0; i < toolbars.length; i++) {
  26418. var toolbar = toolbars[i];
  26419. var toolbarUi = new baidu.editor.ui.Toolbar({theme:editor.options.theme});
  26420. for (var j = 0; j < toolbar.length; j++) {
  26421. var toolbarItem = toolbar[j];
  26422. var toolbarItemUi = null;
  26423. if (typeof toolbarItem == 'string') {
  26424. toolbarItem = toolbarItem.toLowerCase();
  26425. if (toolbarItem == '|') {
  26426. toolbarItem = 'Separator';
  26427. }
  26428. if(toolbarItem == '||'){
  26429. toolbarItem = 'Breakline';
  26430. }
  26431. if (baidu.editor.ui[toolbarItem]) {
  26432. toolbarItemUi = new baidu.editor.ui[toolbarItem](editor);
  26433. }
  26434. //fullscreen这里单独处理一下,放到首行去
  26435. if (toolbarItem == 'fullscreen') {
  26436. if (toolbarUis && toolbarUis[0]) {
  26437. toolbarUis[0].items.splice(0, 0, toolbarItemUi);
  26438. } else {
  26439. toolbarItemUi && toolbarUi.items.splice(0, 0, toolbarItemUi);
  26440. }
  26441. continue;
  26442. }
  26443. } else {
  26444. toolbarItemUi = toolbarItem;
  26445. }
  26446. if (toolbarItemUi && toolbarItemUi.id) {
  26447. toolbarUi.add(toolbarItemUi);
  26448. }
  26449. }
  26450. toolbarUis[i] = toolbarUi;
  26451. }
  26452. //接受外部定制的UI
  26453. utils.each(UE._customizeUI,function(obj,key){
  26454. var itemUI,index;
  26455. if(obj.id && obj.id != editor.key){
  26456. return false;
  26457. }
  26458. itemUI = obj.execFn.call(editor,editor,key);
  26459. if(itemUI){
  26460. index = obj.index;
  26461. if(index === undefined){
  26462. index = toolbarUi.items.length;
  26463. }
  26464. toolbarUi.add(itemUI,index)
  26465. }
  26466. });
  26467. this.toolbars = toolbarUis;
  26468. },
  26469. getHtmlTpl:function () {
  26470. return '<div id="##" class="%%">' +
  26471. '<div id="##_toolbarbox" class="%%-toolbarbox">' +
  26472. (this.toolbars.length ?
  26473. '<div id="##_toolbarboxouter" class="%%-toolbarboxouter"><div class="%%-toolbarboxinner">' +
  26474. this.renderToolbarBoxHtml() +
  26475. '</div></div>' : '') +
  26476. '<div id="##_toolbarmsg" class="%%-toolbarmsg" style="display:none;">' +
  26477. '<div id = "##_upload_dialog" class="%%-toolbarmsg-upload" onclick="$$.showWordImageDialog();">' + this.editor.getLang("clickToUpload") + '</div>' +
  26478. '<div class="%%-toolbarmsg-close" onclick="$$.hideToolbarMsg();">x</div>' +
  26479. '<div id="##_toolbarmsg_label" class="%%-toolbarmsg-label"></div>' +
  26480. '<div style="height:0;overflow:hidden;clear:both;"></div>' +
  26481. '</div>' +
  26482. '<div id="##_message_holder" class="%%-messageholder"></div>' +
  26483. '</div>' +
  26484. '<div id="##_iframeholder" class="%%-iframeholder">' +
  26485. '</div>' +
  26486. //modify wdcount by matao
  26487. '<div id="##_bottombar" class="%%-bottomContainer"><table><tr>' +
  26488. '<td id="##_elementpath" class="%%-bottombar"></td>' +
  26489. '<td id="##_wordcount" class="%%-wordcount"></td>' +
  26490. '<td id="##_scale" class="%%-scale"><div class="%%-icon"></div></td>' +
  26491. '</tr></table></div>' +
  26492. '<div id="##_scalelayer"></div>' +
  26493. '</div>';
  26494. },
  26495. showWordImageDialog:function () {
  26496. this._dialogs['wordimageDialog'].open();
  26497. },
  26498. renderToolbarBoxHtml:function () {
  26499. var buff = [];
  26500. for (var i = 0; i < this.toolbars.length; i++) {
  26501. buff.push(this.toolbars[i].renderHtml());
  26502. }
  26503. return buff.join('');
  26504. },
  26505. setFullScreen:function (fullscreen) {
  26506. var editor = this.editor,
  26507. container = editor.container.parentNode.parentNode;
  26508. if (this._fullscreen != fullscreen) {
  26509. this._fullscreen = fullscreen;
  26510. this.editor.fireEvent('beforefullscreenchange', fullscreen);
  26511. if (baidu.editor.browser.gecko) {
  26512. var bk = editor.selection.getRange().createBookmark();
  26513. }
  26514. if (fullscreen) {
  26515. while (container.tagName != "BODY") {
  26516. var position = baidu.editor.dom.domUtils.getComputedStyle(container, "position");
  26517. nodeStack.push(position);
  26518. container.style.position = "static";
  26519. container = container.parentNode;
  26520. }
  26521. this._bakHtmlOverflow = document.documentElement.style.overflow;
  26522. this._bakBodyOverflow = document.body.style.overflow;
  26523. this._bakAutoHeight = this.editor.autoHeightEnabled;
  26524. this._bakScrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
  26525. this._bakEditorContaninerWidth = editor.iframe.parentNode.offsetWidth;
  26526. if (this._bakAutoHeight) {
  26527. //当全屏时不能执行自动长高
  26528. editor.autoHeightEnabled = false;
  26529. this.editor.disableAutoHeight();
  26530. }
  26531. document.documentElement.style.overflow = 'hidden';
  26532. //修复,滚动条不收起的问题
  26533. window.scrollTo(0,window.scrollY);
  26534. this._bakCssText = this.getDom().style.cssText;
  26535. this._bakCssText1 = this.getDom('iframeholder').style.cssText;
  26536. editor.iframe.parentNode.style.width = '';
  26537. this._updateFullScreen();
  26538. } else {
  26539. while (container.tagName != "BODY") {
  26540. container.style.position = nodeStack.shift();
  26541. container = container.parentNode;
  26542. }
  26543. this.getDom().style.cssText = this._bakCssText;
  26544. this.getDom('iframeholder').style.cssText = this._bakCssText1;
  26545. if (this._bakAutoHeight) {
  26546. editor.autoHeightEnabled = true;
  26547. this.editor.enableAutoHeight();
  26548. }
  26549. document.documentElement.style.overflow = this._bakHtmlOverflow;
  26550. document.body.style.overflow = this._bakBodyOverflow;
  26551. editor.iframe.parentNode.style.width = this._bakEditorContaninerWidth + 'px';
  26552. window.scrollTo(0, this._bakScrollTop);
  26553. }
  26554. if (browser.gecko && editor.body.contentEditable === 'true') {
  26555. var input = document.createElement('input');
  26556. document.body.appendChild(input);
  26557. editor.body.contentEditable = false;
  26558. setTimeout(function () {
  26559. input.focus();
  26560. setTimeout(function () {
  26561. editor.body.contentEditable = true;
  26562. editor.fireEvent('fullscreenchanged', fullscreen);
  26563. editor.selection.getRange().moveToBookmark(bk).select(true);
  26564. baidu.editor.dom.domUtils.remove(input);
  26565. fullscreen && window.scroll(0, 0);
  26566. }, 0)
  26567. }, 0)
  26568. }
  26569. if(editor.body.contentEditable === 'true'){
  26570. this.editor.fireEvent('fullscreenchanged', fullscreen);
  26571. this.triggerLayout();
  26572. }
  26573. }
  26574. },
  26575. _updateFullScreen:function () {
  26576. if (this._fullscreen) {
  26577. var vpRect = uiUtils.getViewportRect();
  26578. this.getDom().style.cssText = 'border:0;position:absolute;left:0;top:' + (this.editor.options.topOffset || 0) + 'px;width:' + vpRect.width + 'px;height:' + vpRect.height + 'px;z-index:' + (this.getDom().style.zIndex * 1 + 100);
  26579. uiUtils.setViewportOffset(this.getDom(), { left:0, top:this.editor.options.topOffset || 0 });
  26580. this.editor.setHeight(vpRect.height - this.getDom('toolbarbox').offsetHeight - this.getDom('bottombar').offsetHeight - (this.editor.options.topOffset || 0),true);
  26581. //不手动调一下,会导致全屏失效
  26582. if(browser.gecko){
  26583. try{
  26584. window.onresize();
  26585. }catch(e){
  26586. }
  26587. }
  26588. }
  26589. },
  26590. _updateElementPath:function () {
  26591. var bottom = this.getDom('elementpath'), list;
  26592. if (this.elementPathEnabled && (list = this.editor.queryCommandValue('elementpath'))) {
  26593. var buff = [];
  26594. for (var i = 0, ci; ci = list[i]; i++) {
  26595. buff[i] = this.formatHtml('<span unselectable="on" onclick="$$.editor.execCommand(&quot;elementpath&quot;, &quot;' + i + '&quot;);">' + ci + '</span>');
  26596. }
  26597. bottom.innerHTML = '<div class="edui-editor-breadcrumb" onmousedown="return false;">' + this.editor.getLang("elementPathTip") + ': ' + buff.join(' &gt; ') + '</div>';
  26598. } else {
  26599. bottom.style.display = 'none'
  26600. }
  26601. },
  26602. disableElementPath:function () {
  26603. var bottom = this.getDom('elementpath');
  26604. bottom.innerHTML = '';
  26605. bottom.style.display = 'none';
  26606. this.elementPathEnabled = false;
  26607. },
  26608. enableElementPath:function () {
  26609. var bottom = this.getDom('elementpath');
  26610. bottom.style.display = '';
  26611. this.elementPathEnabled = true;
  26612. this._updateElementPath();
  26613. },
  26614. _scale:function () {
  26615. var doc = document,
  26616. editor = this.editor,
  26617. editorHolder = editor.container,
  26618. editorDocument = editor.document,
  26619. toolbarBox = this.getDom("toolbarbox"),
  26620. bottombar = this.getDom("bottombar"),
  26621. scale = this.getDom("scale"),
  26622. scalelayer = this.getDom("scalelayer");
  26623. var isMouseMove = false,
  26624. position = null,
  26625. minEditorHeight = 0,
  26626. minEditorWidth = editor.options.minFrameWidth,
  26627. pageX = 0,
  26628. pageY = 0,
  26629. scaleWidth = 0,
  26630. scaleHeight = 0;
  26631. function down() {
  26632. position = domUtils.getXY(editorHolder);
  26633. if (!minEditorHeight) {
  26634. minEditorHeight = editor.options.minFrameHeight + toolbarBox.offsetHeight + bottombar.offsetHeight;
  26635. }
  26636. scalelayer.style.cssText = "position:absolute;left:0;display:;top:0;background-color:#41ABFF;opacity:0.4;filter: Alpha(opacity=40);width:" + editorHolder.offsetWidth + "px;height:"
  26637. + editorHolder.offsetHeight + "px;z-index:" + (editor.options.zIndex + 1);
  26638. domUtils.on(doc, "mousemove", move);
  26639. domUtils.on(editorDocument, "mouseup", up);
  26640. domUtils.on(doc, "mouseup", up);
  26641. }
  26642. var me = this;
  26643. //by xuheng 全屏时关掉缩放
  26644. this.editor.addListener('fullscreenchanged', function (e, fullScreen) {
  26645. if (fullScreen) {
  26646. me.disableScale();
  26647. } else {
  26648. if (me.editor.options.scaleEnabled) {
  26649. me.enableScale();
  26650. var tmpNode = me.editor.document.createElement('span');
  26651. me.editor.body.appendChild(tmpNode);
  26652. me.editor.body.style.height = Math.max(domUtils.getXY(tmpNode).y, me.editor.iframe.offsetHeight - 20) + 'px';
  26653. domUtils.remove(tmpNode)
  26654. }
  26655. }
  26656. });
  26657. function move(event) {
  26658. clearSelection();
  26659. var e = event || window.event;
  26660. pageX = e.pageX || (doc.documentElement.scrollLeft + e.clientX);
  26661. pageY = e.pageY || (doc.documentElement.scrollTop + e.clientY);
  26662. scaleWidth = pageX - position.x;
  26663. scaleHeight = pageY - position.y;
  26664. if (scaleWidth >= minEditorWidth) {
  26665. isMouseMove = true;
  26666. scalelayer.style.width = scaleWidth + 'px';
  26667. }
  26668. if (scaleHeight >= minEditorHeight) {
  26669. isMouseMove = true;
  26670. scalelayer.style.height = scaleHeight + "px";
  26671. }
  26672. }
  26673. function up() {
  26674. if (isMouseMove) {
  26675. isMouseMove = false;
  26676. editor.ui._actualFrameWidth = scalelayer.offsetWidth - 2;
  26677. editorHolder.style.width = editor.ui._actualFrameWidth + 'px';
  26678. editor.setHeight(scalelayer.offsetHeight - bottombar.offsetHeight - toolbarBox.offsetHeight - 2,true);
  26679. }
  26680. if (scalelayer) {
  26681. scalelayer.style.display = "none";
  26682. }
  26683. clearSelection();
  26684. domUtils.un(doc, "mousemove", move);
  26685. domUtils.un(editorDocument, "mouseup", up);
  26686. domUtils.un(doc, "mouseup", up);
  26687. }
  26688. function clearSelection() {
  26689. if (browser.ie)
  26690. doc.selection.clear();
  26691. else
  26692. window.getSelection().removeAllRanges();
  26693. }
  26694. this.enableScale = function () {
  26695. //trace:2868
  26696. if (editor.queryCommandState("source") == 1) return;
  26697. scale.style.display = "";
  26698. this.scaleEnabled = true;
  26699. domUtils.on(scale, "mousedown", down);
  26700. };
  26701. this.disableScale = function () {
  26702. scale.style.display = "none";
  26703. this.scaleEnabled = false;
  26704. domUtils.un(scale, "mousedown", down);
  26705. };
  26706. },
  26707. isFullScreen:function () {
  26708. return this._fullscreen;
  26709. },
  26710. postRender:function () {
  26711. UIBase.prototype.postRender.call(this);
  26712. for (var i = 0; i < this.toolbars.length; i++) {
  26713. this.toolbars[i].postRender();
  26714. }
  26715. var me = this;
  26716. var timerId,
  26717. domUtils = baidu.editor.dom.domUtils,
  26718. updateFullScreenTime = function () {
  26719. clearTimeout(timerId);
  26720. timerId = setTimeout(function () {
  26721. me._updateFullScreen();
  26722. });
  26723. };
  26724. domUtils.on(window, 'resize', updateFullScreenTime);
  26725. me.addListener('destroy', function () {
  26726. domUtils.un(window, 'resize', updateFullScreenTime);
  26727. clearTimeout(timerId);
  26728. })
  26729. },
  26730. showToolbarMsg:function (msg, flag) {
  26731. this.getDom('toolbarmsg_label').innerHTML = msg;
  26732. this.getDom('toolbarmsg').style.display = '';
  26733. //
  26734. if (!flag) {
  26735. var w = this.getDom('upload_dialog');
  26736. w.style.display = 'none';
  26737. }
  26738. },
  26739. hideToolbarMsg:function () {
  26740. this.getDom('toolbarmsg').style.display = 'none';
  26741. },
  26742. mapUrl:function (url) {
  26743. return url ? url.replace('~/', this.editor.options.UEDITOR_HOME_URL || '') : ''
  26744. },
  26745. triggerLayout:function () {
  26746. var dom = this.getDom();
  26747. if (dom.style.zoom == '1') {
  26748. dom.style.zoom = '100%';
  26749. } else {
  26750. dom.style.zoom = '1';
  26751. }
  26752. }
  26753. };
  26754. utils.inherits(EditorUI, baidu.editor.ui.UIBase);
  26755. var instances = {};
  26756. UE.ui.Editor = function (options) {
  26757. var editor = new UE.Editor(options);
  26758. editor.options.editor = editor;
  26759. utils.loadFile(document, {
  26760. href:editor.options.themePath + editor.options.theme + "/css/ueditor.css",
  26761. tag:"link",
  26762. type:"text/css",
  26763. rel:"stylesheet"
  26764. });
  26765. var oldRender = editor.render;
  26766. editor.render = function (holder) {
  26767. if (holder.constructor === String) {
  26768. editor.key = holder;
  26769. instances[holder] = editor;
  26770. }
  26771. utils.domReady(function () {
  26772. editor.langIsReady ? renderUI() : editor.addListener("langReady", renderUI);
  26773. function renderUI() {
  26774. editor.setOpt({
  26775. labelMap:editor.options.labelMap || editor.getLang('labelMap')
  26776. });
  26777. new EditorUI(editor.options);
  26778. if (holder) {
  26779. if (holder.constructor === String) {
  26780. holder = document.getElementById(holder);
  26781. }
  26782. holder && holder.getAttribute('name') && ( editor.options.textarea = holder.getAttribute('name'));
  26783. if (holder && /script|textarea/ig.test(holder.tagName)) {
  26784. var newDiv = document.createElement('div');
  26785. holder.parentNode.insertBefore(newDiv, holder);
  26786. var cont = holder.value || holder.innerHTML;
  26787. editor.options.initialContent = /^[\t\r\n ]*$/.test(cont) ? editor.options.initialContent :
  26788. cont.replace(/>[\n\r\t]+([ ]{4})+/g, '>')
  26789. .replace(/[\n\r\t]+([ ]{4})+</g, '<')
  26790. .replace(/>[\n\r\t]+</g, '><');
  26791. holder.className && (newDiv.className = holder.className);
  26792. holder.style.cssText && (newDiv.style.cssText = holder.style.cssText);
  26793. if (/textarea/i.test(holder.tagName)) {
  26794. editor.textarea = holder;
  26795. editor.textarea.style.display = 'none';
  26796. } else {
  26797. holder.parentNode.removeChild(holder);
  26798. }
  26799. if(holder.id){
  26800. newDiv.id = holder.id;
  26801. domUtils.removeAttributes(holder,'id');
  26802. }
  26803. holder = newDiv;
  26804. holder.innerHTML = '';
  26805. }
  26806. }
  26807. domUtils.addClass(holder, "edui-" + editor.options.theme);
  26808. editor.ui.render(holder);
  26809. var opt = editor.options;
  26810. //给实例添加一个编辑器的容器引用
  26811. editor.container = editor.ui.getDom();
  26812. var parents = domUtils.findParents(holder,true);
  26813. var displays = [];
  26814. for(var i = 0 ,ci;ci=parents[i];i++){
  26815. displays[i] = ci.style.display;
  26816. ci.style.display = 'block'
  26817. }
  26818. if (opt.initialFrameWidth) {
  26819. opt.minFrameWidth = opt.initialFrameWidth;
  26820. } else {
  26821. opt.minFrameWidth = opt.initialFrameWidth = holder.offsetWidth;
  26822. var styleWidth = holder.style.width;
  26823. if(/%$/.test(styleWidth)) {
  26824. opt.initialFrameWidth = styleWidth;
  26825. }
  26826. }
  26827. if (opt.initialFrameHeight) {
  26828. opt.minFrameHeight = opt.initialFrameHeight;
  26829. } else {
  26830. opt.initialFrameHeight = opt.minFrameHeight = holder.offsetHeight;
  26831. }
  26832. for(var i = 0 ,ci;ci=parents[i];i++){
  26833. ci.style.display = displays[i]
  26834. }
  26835. //编辑器最外容器设置了高度,会导致,编辑器不占位
  26836. //todo 先去掉,没有找到原因
  26837. if(holder.style.height){
  26838. holder.style.height = ''
  26839. }
  26840. editor.container.style.width = opt.initialFrameWidth + (/%$/.test(opt.initialFrameWidth) ? '' : 'px');
  26841. editor.container.style.zIndex = opt.zIndex;
  26842. oldRender.call(editor, editor.ui.getDom('iframeholder'));
  26843. editor.fireEvent("afteruiready");
  26844. }
  26845. })
  26846. };
  26847. return editor;
  26848. };
  26849. /**
  26850. * @file
  26851. * @name UE
  26852. * @short UE
  26853. * @desc UEditor的顶部命名空间
  26854. */
  26855. /**
  26856. * @name getEditor
  26857. * @since 1.2.4+
  26858. * @grammar UE.getEditor(id,[opt]) => Editor实例
  26859. * @desc 提供一个全局的方法得到编辑器实例
  26860. *
  26861. * * ''id'' 放置编辑器的容器id, 如果容器下的编辑器已经存在,就直接返回
  26862. * * ''opt'' 编辑器的可选参数
  26863. * @example
  26864. * UE.getEditor('containerId',{onready:function(){//创建一个编辑器实例
  26865. * this.setContent('hello')
  26866. * }});
  26867. * UE.getEditor('containerId'); //返回刚创建的实例
  26868. *
  26869. */
  26870. UE.getEditor = function (id, opt) {
  26871. var editor = instances[id];
  26872. if (!editor) {
  26873. editor = instances[id] = new UE.ui.Editor(opt);
  26874. editor.render(id);
  26875. }
  26876. return editor;
  26877. };
  26878. UE.delEditor = function (id) {
  26879. var editor;
  26880. if (editor = instances[id]) {
  26881. editor.key && editor.destroy();
  26882. delete instances[id]
  26883. }
  26884. };
  26885. UE.registerUI = function(uiName,fn,index,editorId){
  26886. utils.each(uiName.split(/\s+/), function (name) {
  26887. UE._customizeUI[name] = {
  26888. id : editorId,
  26889. execFn:fn,
  26890. index:index
  26891. };
  26892. })
  26893. }
  26894. })();
  26895. // adapter/message.js
  26896. UE.registerUI('message', function(editor) {
  26897. var editorui = baidu.editor.ui;
  26898. var Message = editorui.Message;
  26899. var holder;
  26900. var _messageItems = [];
  26901. var me = editor;
  26902. me.addListener('ready', function(){
  26903. holder = document.getElementById(me.ui.id + '_message_holder');
  26904. updateHolderPos();
  26905. setTimeout(function(){
  26906. updateHolderPos();
  26907. }, 500);
  26908. });
  26909. me.addListener('showmessage', function(type, opt){
  26910. opt = utils.isString(opt) ? {
  26911. 'content': opt
  26912. } : opt;
  26913. var message = new Message({
  26914. 'timeout': opt.timeout,
  26915. 'type': opt.type,
  26916. 'content': opt.content,
  26917. 'keepshow': opt.keepshow,
  26918. 'editor': me
  26919. }),
  26920. mid = opt.id || ('msg_' + (+new Date()).toString(36));
  26921. message.render(holder);
  26922. _messageItems[mid] = message;
  26923. message.reset(opt);
  26924. updateHolderPos();
  26925. return mid;
  26926. });
  26927. me.addListener('updatemessage',function(type, id, opt){
  26928. opt = utils.isString(opt) ? {
  26929. 'content': opt
  26930. } : opt;
  26931. var message = _messageItems[id];
  26932. message.render(holder);
  26933. message && message.reset(opt);
  26934. });
  26935. me.addListener('hidemessage',function(type, id){
  26936. var message = _messageItems[id];
  26937. message && message.hide();
  26938. });
  26939. function updateHolderPos(){
  26940. var toolbarbox = me.ui.getDom('toolbarbox');
  26941. if (toolbarbox) {
  26942. holder.style.top = toolbarbox.offsetHeight + 3 + 'px';
  26943. }
  26944. holder.style.zIndex = Math.max(me.options.zIndex, me.iframe.style.zIndex) + 1;
  26945. }
  26946. });
  26947. // adapter/autosave.js
  26948. UE.registerUI('autosave', function(editor) {
  26949. var timer = null,uid = null;
  26950. editor.on('afterautosave',function(){
  26951. clearTimeout(timer);
  26952. timer = setTimeout(function(){
  26953. if(uid){
  26954. editor.trigger('hidemessage',uid);
  26955. }
  26956. uid = editor.trigger('showmessage',{
  26957. content : editor.getLang('autosave.success'),
  26958. timeout : 750
  26959. });
  26960. },2000)
  26961. })
  26962. });
  26963. })();