ueditor.all.js 1.1 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637
  1. /*!
  2. * UEditor
  3. * version: ueditor
  4. * build: Wed Aug 10 2016 11:06:16 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. * 将url中的html字符转义, 仅转义 ', ", <, > 四个字符
  710. * @param { String } str 需要转义的字符串
  711. * @param { RegExp } reg 自定义的正则
  712. * @return { String } 转义后的字符串
  713. */
  714. unhtmlForUrl:function (str, reg) {
  715. return str ? str.replace(reg || /[<">']/g, function (a) {
  716. return {
  717. '<':'&lt;',
  718. '&':'&amp;',
  719. '"':'&quot;',
  720. '>':'&gt;',
  721. "'":'&#39;'
  722. }[a]
  723. }) : '';
  724. },
  725. /**
  726. * 将str中的转义字符还原成html字符
  727. * @see UE.utils.unhtml(String);
  728. * @method html
  729. * @param { String } str 需要逆转义的字符串
  730. * @return { String } 逆转义后的字符串
  731. * @example
  732. * ```javascript
  733. *
  734. * var str = '&lt;body&gt;&amp;&lt;/body&gt;';
  735. *
  736. * //output: <body>&</body>
  737. * console.log( UE.utils.html( str ) );
  738. *
  739. * ```
  740. */
  741. html:function (str) {
  742. return str ? str.replace(/&((g|l|quo)t|amp|#39|nbsp);/g, function (m) {
  743. return {
  744. '&lt;':'<',
  745. '&amp;':'&',
  746. '&quot;':'"',
  747. '&gt;':'>',
  748. '&#39;':"'",
  749. '&nbsp;':' '
  750. }[m]
  751. }) : '';
  752. },
  753. /**
  754. * 将css样式转换为驼峰的形式
  755. * @method cssStyleToDomStyle
  756. * @param { String } cssName 需要转换的css样式名
  757. * @return { String } 转换成驼峰形式后的css样式名
  758. * @example
  759. * ```javascript
  760. *
  761. * var str = 'border-top';
  762. *
  763. * //output: borderTop
  764. * console.log( UE.utils.cssStyleToDomStyle( str ) );
  765. *
  766. * ```
  767. */
  768. cssStyleToDomStyle:function () {
  769. var test = document.createElement('div').style,
  770. cache = {
  771. 'float':test.cssFloat != undefined ? 'cssFloat' : test.styleFloat != undefined ? 'styleFloat' : 'float'
  772. };
  773. return function (cssName) {
  774. return cache[cssName] || (cache[cssName] = cssName.toLowerCase().replace(/-./g, function (match) {
  775. return match.charAt(1).toUpperCase();
  776. }));
  777. };
  778. }(),
  779. /**
  780. * 动态加载文件到doc中
  781. * @method loadFile
  782. * @param { DomDocument } document 需要加载资源文件的文档对象
  783. * @param { Object } options 加载资源文件的属性集合, 取值请参考代码示例
  784. * @example
  785. * ```javascript
  786. *
  787. * UE.utils.loadFile( document, {
  788. * src:"test.js",
  789. * tag:"script",
  790. * type:"text/javascript",
  791. * defer:"defer"
  792. * } );
  793. *
  794. * ```
  795. */
  796. /**
  797. * 动态加载文件到doc中,加载成功后执行的回调函数fn
  798. * @method loadFile
  799. * @param { DomDocument } document 需要加载资源文件的文档对象
  800. * @param { Object } options 加载资源文件的属性集合, 该集合支持的值是script标签和style标签支持的所有属性。
  801. * @param { Function } fn 资源文件加载成功之后执行的回调
  802. * @warning 对于在同一个文档中多次加载同一URL的文件, 该方法会在第一次加载之后缓存该请求,
  803. * 在此之后的所有同一URL的请求, 将会直接触发回调。
  804. * @example
  805. * ```javascript
  806. *
  807. * UE.utils.loadFile( document, {
  808. * src:"test.js",
  809. * tag:"script",
  810. * type:"text/javascript",
  811. * defer:"defer"
  812. * }, function () {
  813. * console.log('加载成功');
  814. * } );
  815. *
  816. * ```
  817. */
  818. loadFile:function () {
  819. var tmpList = [];
  820. function getItem(doc, obj) {
  821. try {
  822. for (var i = 0, ci; ci = tmpList[i++];) {
  823. if (ci.doc === doc && ci.url == (obj.src || obj.href)) {
  824. return ci;
  825. }
  826. }
  827. } catch (e) {
  828. return null;
  829. }
  830. }
  831. return function (doc, obj, fn) {
  832. var item = getItem(doc, obj);
  833. if (item) {
  834. if (item.ready) {
  835. fn && fn();
  836. } else {
  837. item.funs.push(fn)
  838. }
  839. return;
  840. }
  841. tmpList.push({
  842. doc:doc,
  843. url:obj.src || obj.href,
  844. funs:[fn]
  845. });
  846. if (!doc.body) {
  847. var html = [];
  848. for (var p in obj) {
  849. if (p == 'tag')continue;
  850. html.push(p + '="' + obj[p] + '"')
  851. }
  852. doc.write('<' + obj.tag + ' ' + html.join(' ') + ' ></' + obj.tag + '>');
  853. return;
  854. }
  855. if (obj.id && doc.getElementById(obj.id)) {
  856. return;
  857. }
  858. var element = doc.createElement(obj.tag);
  859. delete obj.tag;
  860. for (var p in obj) {
  861. element.setAttribute(p, obj[p]);
  862. }
  863. element.onload = element.onreadystatechange = function () {
  864. if (!this.readyState || /loaded|complete/.test(this.readyState)) {
  865. item = getItem(doc, obj);
  866. if (item.funs.length > 0) {
  867. item.ready = 1;
  868. for (var fi; fi = item.funs.pop();) {
  869. fi();
  870. }
  871. }
  872. element.onload = element.onreadystatechange = null;
  873. }
  874. };
  875. element.onerror = function () {
  876. throw Error('The load ' + (obj.href || obj.src) + ' fails,check the url settings of file ueditor.config.js ')
  877. };
  878. doc.getElementsByTagName("head")[0].appendChild(element);
  879. }
  880. }(),
  881. /**
  882. * 判断obj对象是否为空
  883. * @method isEmptyObject
  884. * @param { * } obj 需要判断的对象
  885. * @remind 如果判断的对象是NULL, 将直接返回true, 如果是数组且为空, 返回true, 如果是字符串, 且字符串为空,
  886. * 返回true, 如果是普通对象, 且该对象没有任何实例属性, 返回true
  887. * @return { Boolean } 对象是否为空
  888. * @example
  889. * ```javascript
  890. *
  891. * //output: true
  892. * console.log( UE.utils.isEmptyObject( {} ) );
  893. *
  894. * //output: true
  895. * console.log( UE.utils.isEmptyObject( [] ) );
  896. *
  897. * //output: true
  898. * console.log( UE.utils.isEmptyObject( "" ) );
  899. *
  900. * //output: false
  901. * console.log( UE.utils.isEmptyObject( { key: 1 } ) );
  902. *
  903. * //output: false
  904. * console.log( UE.utils.isEmptyObject( [1] ) );
  905. *
  906. * //output: false
  907. * console.log( UE.utils.isEmptyObject( "1" ) );
  908. *
  909. * ```
  910. */
  911. isEmptyObject:function (obj) {
  912. if (obj == null) return true;
  913. if (this.isArray(obj) || this.isString(obj)) return obj.length === 0;
  914. for (var key in obj) if (obj.hasOwnProperty(key)) return false;
  915. return true;
  916. },
  917. /**
  918. * 把rgb格式的颜色值转换成16进制格式
  919. * @method fixColor
  920. * @param { String } rgb格式的颜色值
  921. * @param { String }
  922. * @example
  923. * rgb(255,255,255) => "#ffffff"
  924. */
  925. fixColor:function (name, value) {
  926. if (/color/i.test(name) && /rgba?/.test(value)) {
  927. var array = value.split(",");
  928. if (array.length > 3)
  929. return "";
  930. value = "#";
  931. for (var i = 0, color; color = array[i++];) {
  932. color = parseInt(color.replace(/[^\d]/gi, ''), 10).toString(16);
  933. value += color.length == 1 ? "0" + color : color;
  934. }
  935. value = value.toUpperCase();
  936. }
  937. return value;
  938. },
  939. /**
  940. * 只针对border,padding,margin做了处理,因为性能问题
  941. * @public
  942. * @function
  943. * @param {String} val style字符串
  944. */
  945. optCss:function (val) {
  946. var padding, margin, border;
  947. val = val.replace(/(padding|margin|border)\-([^:]+):([^;]+);?/gi, function (str, key, name, val) {
  948. if (val.split(' ').length == 1) {
  949. switch (key) {
  950. case 'padding':
  951. !padding && (padding = {});
  952. padding[name] = val;
  953. return '';
  954. case 'margin':
  955. !margin && (margin = {});
  956. margin[name] = val;
  957. return '';
  958. case 'border':
  959. return val == 'initial' ? '' : str;
  960. }
  961. }
  962. return str;
  963. });
  964. function opt(obj, name) {
  965. if (!obj) {
  966. return '';
  967. }
  968. var t = obj.top , b = obj.bottom, l = obj.left, r = obj.right, val = '';
  969. if (!t || !l || !b || !r) {
  970. for (var p in obj) {
  971. val += ';' + name + '-' + p + ':' + obj[p] + ';';
  972. }
  973. } else {
  974. val += ';' + name + ':' +
  975. (t == b && b == l && l == r ? t :
  976. t == b && l == r ? (t + ' ' + l) :
  977. l == r ? (t + ' ' + l + ' ' + b) : (t + ' ' + r + ' ' + b + ' ' + l)) + ';'
  978. }
  979. return val;
  980. }
  981. val += opt(padding, 'padding') + opt(margin, 'margin');
  982. return val.replace(/^[ \n\r\t;]*|[ \n\r\t]*$/, '').replace(/;([ \n\r\t]+)|\1;/g, ';')
  983. .replace(/(&((l|g)t|quot|#39))?;{2,}/g, function (a, b) {
  984. return b ? b + ";;" : ';'
  985. });
  986. },
  987. /**
  988. * 克隆对象
  989. * @method clone
  990. * @param { Object } source 源对象
  991. * @return { Object } source的一个副本
  992. */
  993. /**
  994. * 深度克隆对象,将source的属性克隆到target对象, 会覆盖target重名的属性。
  995. * @method clone
  996. * @param { Object } source 源对象
  997. * @param { Object } target 目标对象
  998. * @return { Object } 附加了source对象所有属性的target对象
  999. */
  1000. clone:function (source, target) {
  1001. var tmp;
  1002. target = target || {};
  1003. for (var i in source) {
  1004. if (source.hasOwnProperty(i)) {
  1005. tmp = source[i];
  1006. if (typeof tmp == 'object') {
  1007. target[i] = utils.isArray(tmp) ? [] : {};
  1008. utils.clone(source[i], target[i])
  1009. } else {
  1010. target[i] = tmp;
  1011. }
  1012. }
  1013. }
  1014. return target;
  1015. },
  1016. /**
  1017. * 把cm/pt为单位的值转换为px为单位的值
  1018. * @method transUnitToPx
  1019. * @param { String } 待转换的带单位的字符串
  1020. * @return { String } 转换为px为计量单位的值的字符串
  1021. * @example
  1022. * ```javascript
  1023. *
  1024. * //output: 500px
  1025. * console.log( UE.utils.transUnitToPx( '20cm' ) );
  1026. *
  1027. * //output: 27px
  1028. * console.log( UE.utils.transUnitToPx( '20pt' ) );
  1029. *
  1030. * ```
  1031. */
  1032. transUnitToPx:function (val) {
  1033. if (!/(pt|cm)/.test(val)) {
  1034. return val
  1035. }
  1036. var unit;
  1037. val.replace(/([\d.]+)(\w+)/, function (str, v, u) {
  1038. val = v;
  1039. unit = u;
  1040. });
  1041. switch (unit) {
  1042. case 'cm':
  1043. val = parseFloat(val) * 25;
  1044. break;
  1045. case 'pt':
  1046. val = Math.round(parseFloat(val) * 96 / 72);
  1047. }
  1048. return val + (val ? 'px' : '');
  1049. },
  1050. /**
  1051. * 在dom树ready之后执行给定的回调函数
  1052. * @method domReady
  1053. * @remind 如果在执行该方法的时候, dom树已经ready, 那么回调函数将立刻执行
  1054. * @param { Function } fn dom树ready之后的回调函数
  1055. * @example
  1056. * ```javascript
  1057. *
  1058. * UE.utils.domReady( function () {
  1059. *
  1060. * console.log('123');
  1061. *
  1062. * } );
  1063. *
  1064. * ```
  1065. */
  1066. domReady:function () {
  1067. var fnArr = [];
  1068. function doReady(doc) {
  1069. //确保onready只执行一次
  1070. doc.isReady = true;
  1071. for (var ci; ci = fnArr.pop(); ci()) {
  1072. }
  1073. }
  1074. return function (onready, win) {
  1075. win = win || window;
  1076. var doc = win.document;
  1077. onready && fnArr.push(onready);
  1078. if (doc.readyState === "complete") {
  1079. doReady(doc);
  1080. } else {
  1081. doc.isReady && doReady(doc);
  1082. if (browser.ie && browser.version != 11) {
  1083. (function () {
  1084. if (doc.isReady) return;
  1085. try {
  1086. doc.documentElement.doScroll("left");
  1087. } catch (error) {
  1088. setTimeout(arguments.callee, 0);
  1089. return;
  1090. }
  1091. doReady(doc);
  1092. })();
  1093. win.attachEvent('onload', function () {
  1094. doReady(doc)
  1095. });
  1096. } else {
  1097. doc.addEventListener("DOMContentLoaded", function () {
  1098. doc.removeEventListener("DOMContentLoaded", arguments.callee, false);
  1099. doReady(doc);
  1100. }, false);
  1101. win.addEventListener('load', function () {
  1102. doReady(doc)
  1103. }, false);
  1104. }
  1105. }
  1106. }
  1107. }(),
  1108. /**
  1109. * 动态添加css样式
  1110. * @method cssRule
  1111. * @param { String } 节点名称
  1112. * @grammar UE.utils.cssRule('添加的样式的节点名称',['样式','放到哪个document上'])
  1113. * @grammar UE.utils.cssRule('body','body{background:#ccc}') => null //给body添加背景颜色
  1114. * @grammar UE.utils.cssRule('body') =>样式的字符串 //取得key值为body的样式的内容,如果没有找到key值先关的样式将返回空,例如刚才那个背景颜色,将返回 body{background:#ccc}
  1115. * @grammar UE.utils.cssRule('body',document) => 返回指定key的样式,并且指定是哪个document
  1116. * @grammar UE.utils.cssRule('body','') =>null //清空给定的key值的背景颜色
  1117. */
  1118. cssRule:browser.ie && browser.version != 11 ? function (key, style, doc) {
  1119. var indexList, index;
  1120. if(style === undefined || style && style.nodeType && style.nodeType == 9){
  1121. //获取样式
  1122. doc = style && style.nodeType && style.nodeType == 9 ? style : (doc || document);
  1123. indexList = doc.indexList || (doc.indexList = {});
  1124. index = indexList[key];
  1125. if(index !== undefined){
  1126. return doc.styleSheets[index].cssText
  1127. }
  1128. return undefined;
  1129. }
  1130. doc = doc || document;
  1131. indexList = doc.indexList || (doc.indexList = {});
  1132. index = indexList[key];
  1133. //清除样式
  1134. if(style === ''){
  1135. if(index!== undefined){
  1136. doc.styleSheets[index].cssText = '';
  1137. delete indexList[key];
  1138. return true
  1139. }
  1140. return false;
  1141. }
  1142. //添加样式
  1143. if(index!== undefined){
  1144. sheetStyle = doc.styleSheets[index];
  1145. }else{
  1146. sheetStyle = doc.createStyleSheet('', index = doc.styleSheets.length);
  1147. indexList[key] = index;
  1148. }
  1149. sheetStyle.cssText = style;
  1150. }: function (key, style, doc) {
  1151. var head, node;
  1152. if(style === undefined || style && style.nodeType && style.nodeType == 9){
  1153. //获取样式
  1154. doc = style && style.nodeType && style.nodeType == 9 ? style : (doc || document);
  1155. node = doc.getElementById(key);
  1156. return node ? node.innerHTML : undefined;
  1157. }
  1158. doc = doc || document;
  1159. node = doc.getElementById(key);
  1160. //清除样式
  1161. if(style === ''){
  1162. if(node){
  1163. node.parentNode.removeChild(node);
  1164. return true
  1165. }
  1166. return false;
  1167. }
  1168. //添加样式
  1169. if(node){
  1170. node.innerHTML = style;
  1171. }else{
  1172. node = doc.createElement('style');
  1173. node.id = key;
  1174. node.innerHTML = style;
  1175. doc.getElementsByTagName('head')[0].appendChild(node);
  1176. }
  1177. },
  1178. sort:function(array,compareFn){
  1179. compareFn = compareFn || function(item1, item2){ return item1.localeCompare(item2);};
  1180. for(var i= 0,len = array.length; i<len; i++){
  1181. for(var j = i,length = array.length; j<length; j++){
  1182. if(compareFn(array[i], array[j]) > 0){
  1183. var t = array[i];
  1184. array[i] = array[j];
  1185. array[j] = t;
  1186. }
  1187. }
  1188. }
  1189. return array;
  1190. },
  1191. serializeParam:function (json) {
  1192. var strArr = [];
  1193. for (var i in json) {
  1194. //忽略默认的几个参数
  1195. if(i=="method" || i=="timeout" || i=="async") continue;
  1196. //传递过来的对象和函数不在提交之列
  1197. if (!((typeof json[i]).toLowerCase() == "function" || (typeof json[i]).toLowerCase() == "object")) {
  1198. strArr.push( encodeURIComponent(i) + "="+encodeURIComponent(json[i]) );
  1199. } else if (utils.isArray(json[i])) {
  1200. //支持传数组内容
  1201. for(var j = 0; j < json[i].length; j++) {
  1202. strArr.push( encodeURIComponent(i) + "[]="+encodeURIComponent(json[i][j]) );
  1203. }
  1204. }
  1205. }
  1206. return strArr.join("&");
  1207. },
  1208. formatUrl:function (url) {
  1209. var u = url.replace(/&&/g, '&');
  1210. u = u.replace(/\?&/g, '?');
  1211. u = u.replace(/&$/g, '');
  1212. u = u.replace(/&#/g, '#');
  1213. u = u.replace(/&+/g, '&');
  1214. return u;
  1215. },
  1216. isCrossDomainUrl:function (url) {
  1217. var a = document.createElement('a');
  1218. a.href = url;
  1219. if (browser.ie) {
  1220. a.href = a.href;
  1221. }
  1222. return !(a.protocol == location.protocol && a.hostname == location.hostname &&
  1223. (a.port == location.port || (a.port == '80' && location.port == '') || (a.port == '' && location.port == '80')));
  1224. },
  1225. clearEmptyAttrs : function(obj){
  1226. for(var p in obj){
  1227. if(obj[p] === ''){
  1228. delete obj[p]
  1229. }
  1230. }
  1231. return obj;
  1232. },
  1233. str2json : function(s){
  1234. if (!utils.isString(s)) return null;
  1235. if (window.JSON) {
  1236. return JSON.parse(s);
  1237. } else {
  1238. return (new Function("return " + utils.trim(s || '')))();
  1239. }
  1240. },
  1241. json2str : (function(){
  1242. if (window.JSON) {
  1243. return JSON.stringify;
  1244. } else {
  1245. var escapeMap = {
  1246. "\b": '\\b',
  1247. "\t": '\\t',
  1248. "\n": '\\n',
  1249. "\f": '\\f',
  1250. "\r": '\\r',
  1251. '"' : '\\"',
  1252. "\\": '\\\\'
  1253. };
  1254. function encodeString(source) {
  1255. if (/["\\\x00-\x1f]/.test(source)) {
  1256. source = source.replace(
  1257. /["\\\x00-\x1f]/g,
  1258. function (match) {
  1259. var c = escapeMap[match];
  1260. if (c) {
  1261. return c;
  1262. }
  1263. c = match.charCodeAt();
  1264. return "\\u00"
  1265. + Math.floor(c / 16).toString(16)
  1266. + (c % 16).toString(16);
  1267. });
  1268. }
  1269. return '"' + source + '"';
  1270. }
  1271. function encodeArray(source) {
  1272. var result = ["["],
  1273. l = source.length,
  1274. preComma, i, item;
  1275. for (i = 0; i < l; i++) {
  1276. item = source[i];
  1277. switch (typeof item) {
  1278. case "undefined":
  1279. case "function":
  1280. case "unknown":
  1281. break;
  1282. default:
  1283. if(preComma) {
  1284. result.push(',');
  1285. }
  1286. result.push(utils.json2str(item));
  1287. preComma = 1;
  1288. }
  1289. }
  1290. result.push("]");
  1291. return result.join("");
  1292. }
  1293. function pad(source) {
  1294. return source < 10 ? '0' + source : source;
  1295. }
  1296. function encodeDate(source){
  1297. return '"' + source.getFullYear() + "-"
  1298. + pad(source.getMonth() + 1) + "-"
  1299. + pad(source.getDate()) + "T"
  1300. + pad(source.getHours()) + ":"
  1301. + pad(source.getMinutes()) + ":"
  1302. + pad(source.getSeconds()) + '"';
  1303. }
  1304. return function (value) {
  1305. switch (typeof value) {
  1306. case 'undefined':
  1307. return 'undefined';
  1308. case 'number':
  1309. return isFinite(value) ? String(value) : "null";
  1310. case 'string':
  1311. return encodeString(value);
  1312. case 'boolean':
  1313. return String(value);
  1314. default:
  1315. if (value === null) {
  1316. return 'null';
  1317. } else if (utils.isArray(value)) {
  1318. return encodeArray(value);
  1319. } else if (utils.isDate(value)) {
  1320. return encodeDate(value);
  1321. } else {
  1322. var result = ['{'],
  1323. encode = utils.json2str,
  1324. preComma,
  1325. item;
  1326. for (var key in value) {
  1327. if (Object.prototype.hasOwnProperty.call(value, key)) {
  1328. item = value[key];
  1329. switch (typeof item) {
  1330. case 'undefined':
  1331. case 'unknown':
  1332. case 'function':
  1333. break;
  1334. default:
  1335. if (preComma) {
  1336. result.push(',');
  1337. }
  1338. preComma = 1;
  1339. result.push(encode(key) + ':' + encode(item));
  1340. }
  1341. }
  1342. }
  1343. result.push('}');
  1344. return result.join('');
  1345. }
  1346. }
  1347. };
  1348. }
  1349. })()
  1350. };
  1351. /**
  1352. * 判断给定的对象是否是字符串
  1353. * @method isString
  1354. * @param { * } object 需要判断的对象
  1355. * @return { Boolean } 给定的对象是否是字符串
  1356. */
  1357. /**
  1358. * 判断给定的对象是否是数组
  1359. * @method isArray
  1360. * @param { * } object 需要判断的对象
  1361. * @return { Boolean } 给定的对象是否是数组
  1362. */
  1363. /**
  1364. * 判断给定的对象是否是一个Function
  1365. * @method isFunction
  1366. * @param { * } object 需要判断的对象
  1367. * @return { Boolean } 给定的对象是否是Function
  1368. */
  1369. /**
  1370. * 判断给定的对象是否是Number
  1371. * @method isNumber
  1372. * @param { * } object 需要判断的对象
  1373. * @return { Boolean } 给定的对象是否是Number
  1374. */
  1375. /**
  1376. * 判断给定的对象是否是一个正则表达式
  1377. * @method isRegExp
  1378. * @param { * } object 需要判断的对象
  1379. * @return { Boolean } 给定的对象是否是正则表达式
  1380. */
  1381. /**
  1382. * 判断给定的对象是否是一个普通对象
  1383. * @method isObject
  1384. * @param { * } object 需要判断的对象
  1385. * @return { Boolean } 给定的对象是否是普通对象
  1386. */
  1387. utils.each(['String', 'Function', 'Array', 'Number', 'RegExp', 'Object', 'Date'], function (v) {
  1388. UE.utils['is' + v] = function (obj) {
  1389. return Object.prototype.toString.apply(obj) == '[object ' + v + ']';
  1390. }
  1391. });
  1392. // core/EventBase.js
  1393. /**
  1394. * UE采用的事件基类
  1395. * @file
  1396. * @module UE
  1397. * @class EventBase
  1398. * @since 1.2.6.1
  1399. */
  1400. /**
  1401. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  1402. * @unfile
  1403. * @module UE
  1404. */
  1405. /**
  1406. * UE采用的事件基类,继承此类的对应类将获取addListener,removeListener,fireEvent方法。
  1407. * 在UE中,Editor以及所有ui实例都继承了该类,故可以在对应的ui对象以及editor对象上使用上述方法。
  1408. * @unfile
  1409. * @module UE
  1410. * @class EventBase
  1411. */
  1412. /**
  1413. * 通过此构造器,子类可以继承EventBase获取事件监听的方法
  1414. * @constructor
  1415. * @example
  1416. * ```javascript
  1417. * UE.EventBase.call(editor);
  1418. * ```
  1419. */
  1420. var EventBase = UE.EventBase = function () {};
  1421. EventBase.prototype = {
  1422. /**
  1423. * 注册事件监听器
  1424. * @method addListener
  1425. * @param { String } types 监听的事件名称,同时监听多个事件使用空格分隔
  1426. * @param { Function } fn 监听的事件被触发时,会执行该回调函数
  1427. * @waining 事件被触发时,监听的函数假如返回的值恒等于true,回调函数的队列中后面的函数将不执行
  1428. * @example
  1429. * ```javascript
  1430. * editor.addListener('selectionchange',function(){
  1431. * console.log("选区已经变化!");
  1432. * })
  1433. * editor.addListener('beforegetcontent aftergetcontent',function(type){
  1434. * if(type == 'beforegetcontent'){
  1435. * //do something
  1436. * }else{
  1437. * //do something
  1438. * }
  1439. * console.log(this.getContent) // this是注册的事件的编辑器实例
  1440. * })
  1441. * ```
  1442. * @see UE.EventBase:fireEvent(String)
  1443. */
  1444. addListener:function (types, listener) {
  1445. types = utils.trim(types).split(/\s+/);
  1446. for (var i = 0, ti; ti = types[i++];) {
  1447. getListener(this, ti, true).push(listener);
  1448. }
  1449. },
  1450. on : function(types, listener){
  1451. return this.addListener(types,listener);
  1452. },
  1453. off : function(types, listener){
  1454. return this.removeListener(types, listener)
  1455. },
  1456. trigger:function(){
  1457. return this.fireEvent.apply(this,arguments);
  1458. },
  1459. /**
  1460. * 移除事件监听器
  1461. * @method removeListener
  1462. * @param { String } types 移除的事件名称,同时移除多个事件使用空格分隔
  1463. * @param { Function } fn 移除监听事件的函数引用
  1464. * @example
  1465. * ```javascript
  1466. * //changeCallback为方法体
  1467. * editor.removeListener("selectionchange",changeCallback);
  1468. * ```
  1469. */
  1470. removeListener:function (types, listener) {
  1471. types = utils.trim(types).split(/\s+/);
  1472. for (var i = 0, ti; ti = types[i++];) {
  1473. utils.removeItem(getListener(this, ti) || [], listener);
  1474. }
  1475. },
  1476. /**
  1477. * 触发事件
  1478. * @method fireEvent
  1479. * @param { String } types 触发的事件名称,同时触发多个事件使用空格分隔
  1480. * @remind 该方法会触发addListener
  1481. * @return { * } 返回触发事件的队列中,最后执行的回调函数的返回值
  1482. * @example
  1483. * ```javascript
  1484. * editor.fireEvent("selectionchange");
  1485. * ```
  1486. */
  1487. /**
  1488. * 触发事件
  1489. * @method fireEvent
  1490. * @param { String } types 触发的事件名称,同时触发多个事件使用空格分隔
  1491. * @param { *... } options 可选参数,可以传入一个或多个参数,会传给事件触发的回调函数
  1492. * @return { * } 返回触发事件的队列中,最后执行的回调函数的返回值
  1493. * @example
  1494. * ```javascript
  1495. *
  1496. * editor.addListener( "selectionchange", function ( type, arg1, arg2 ) {
  1497. *
  1498. * console.log( arg1 + " " + arg2 );
  1499. *
  1500. * } );
  1501. *
  1502. * //触发selectionchange事件, 会执行上面的事件监听器
  1503. * //output: Hello World
  1504. * editor.fireEvent("selectionchange", "Hello", "World");
  1505. * ```
  1506. */
  1507. fireEvent:function () {
  1508. var types = arguments[0];
  1509. types = utils.trim(types).split(' ');
  1510. for (var i = 0, ti; ti = types[i++];) {
  1511. var listeners = getListener(this, ti),
  1512. r, t, k;
  1513. if (listeners) {
  1514. k = listeners.length;
  1515. while (k--) {
  1516. if(!listeners[k])continue;
  1517. t = listeners[k].apply(this, arguments);
  1518. if(t === true){
  1519. return t;
  1520. }
  1521. if (t !== undefined) {
  1522. r = t;
  1523. }
  1524. }
  1525. }
  1526. if (t = this['on' + ti.toLowerCase()]) {
  1527. r = t.apply(this, arguments);
  1528. }
  1529. }
  1530. return r;
  1531. }
  1532. };
  1533. /**
  1534. * 获得对象所拥有监听类型的所有监听器
  1535. * @unfile
  1536. * @module UE
  1537. * @since 1.2.6.1
  1538. * @method getListener
  1539. * @public
  1540. * @param { Object } obj 查询监听器的对象
  1541. * @param { String } type 事件类型
  1542. * @param { Boolean } force 为true且当前所有type类型的侦听器不存在时,创建一个空监听器数组
  1543. * @return { Array } 监听器数组
  1544. */
  1545. function getListener(obj, type, force) {
  1546. var allListeners;
  1547. type = type.toLowerCase();
  1548. return ( ( allListeners = ( obj.__allListeners || force && ( obj.__allListeners = {} ) ) )
  1549. && ( allListeners[type] || force && ( allListeners[type] = [] ) ) );
  1550. }
  1551. // core/dtd.js
  1552. ///import editor.js
  1553. ///import core/dom/dom.js
  1554. ///import core/utils.js
  1555. /**
  1556. * dtd html语义化的体现类
  1557. * @constructor
  1558. * @namespace dtd
  1559. */
  1560. var dtd = dom.dtd = (function() {
  1561. function _( s ) {
  1562. for (var k in s) {
  1563. s[k.toUpperCase()] = s[k];
  1564. }
  1565. return s;
  1566. }
  1567. var X = utils.extend2;
  1568. var A = _({isindex:1,fieldset:1}),
  1569. B = _({input:1,button:1,select:1,textarea:1,label:1}),
  1570. C = X( _({a:1}), B ),
  1571. D = X( {iframe:1}, C ),
  1572. 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}),
  1573. F = _({ins:1,del:1,script:1,style:1}),
  1574. 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 ),
  1575. 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 ),
  1576. I = X( _({p:1}), H ),
  1577. J = X( _({iframe:1}), H, B ),
  1578. 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}),
  1579. L = X( _({a:0}), J ),//a不能被切开,所以把他
  1580. M = _({tr:1}),
  1581. N = _({'#':1}),
  1582. O = X( _({param:1}), K ),
  1583. P = X( _({form:1}), A, D, E, I ),
  1584. Q = _({li:1,ol:1,ul:1}),
  1585. R = _({style:1,script:1}),
  1586. S = _({base:1,link:1,meta:1,title:1}),
  1587. T = X( S, R ),
  1588. U = _({head:1,body:1}),
  1589. V = _({html:1});
  1590. 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}),
  1591. 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});
  1592. return _({
  1593. // $ 表示自定的属性
  1594. // body外的元素列表.
  1595. $nonBodyContent: X( V, U, S ),
  1596. //块结构元素列表
  1597. $block : block,
  1598. //内联元素列表
  1599. $inline : L,
  1600. $inlineWithA : X(_({a:1}),L),
  1601. $body : X( _({script:1,style:1}), block ),
  1602. $cdata : _({script:1,style:1}),
  1603. //自闭和元素
  1604. $empty : empty,
  1605. //不是自闭合,但不能让range选中里边
  1606. $nonChild : _({iframe:1,textarea:1}),
  1607. //列表元素列表
  1608. $listItem : _({dd:1,dt:1,li:1}),
  1609. //列表根元素列表
  1610. $list: _({ul:1,ol:1,dl:1}),
  1611. //不能认为是空的元素
  1612. $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}),
  1613. //如果没有子节点就可以删除的元素列表,像span,a
  1614. $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}),
  1615. $removeEmptyBlock : _({'p':1,'div':1}),
  1616. //在table元素里的元素列表
  1617. $tableContent : _({caption:1,col:1,colgroup:1,tbody:1,td:1,tfoot:1,th:1,thead:1,tr:1,table:1}),
  1618. //不转换的标签
  1619. $notTransContent : _({pre:1,script:1,style:1,textarea:1}),
  1620. html: U,
  1621. head: T,
  1622. style: N,
  1623. script: N,
  1624. body: P,
  1625. base: {},
  1626. link: {},
  1627. meta: {},
  1628. title: N,
  1629. col : {},
  1630. tr : _({td:1,th:1}),
  1631. img : {},
  1632. embed: {},
  1633. colgroup : _({thead:1,col:1,tbody:1,tr:1,tfoot:1}),
  1634. noscript : P,
  1635. td : P,
  1636. br : {},
  1637. th : P,
  1638. center : P,
  1639. kbd : L,
  1640. button : X( I, E ),
  1641. basefont : {},
  1642. h5 : L,
  1643. h4 : L,
  1644. samp : L,
  1645. h6 : L,
  1646. ol : Q,
  1647. h1 : L,
  1648. h3 : L,
  1649. option : N,
  1650. h2 : L,
  1651. form : X( A, D, E, I ),
  1652. select : _({optgroup:1,option:1}),
  1653. font : L,
  1654. ins : L,
  1655. menu : Q,
  1656. abbr : L,
  1657. label : L,
  1658. table : _({thead:1,col:1,tbody:1,tr:1,colgroup:1,caption:1,tfoot:1}),
  1659. code : L,
  1660. tfoot : M,
  1661. cite : L,
  1662. li : P,
  1663. input : {},
  1664. iframe : P,
  1665. strong : L,
  1666. textarea : N,
  1667. noframes : P,
  1668. big : L,
  1669. small : L,
  1670. //trace:
  1671. span :_({'#':1,br:1,b:1,strong:1,u:1,i:1,em:1,sub:1,sup:1,strike:1,span:1}),
  1672. hr : L,
  1673. dt : L,
  1674. sub : L,
  1675. optgroup : _({option:1}),
  1676. param : {},
  1677. bdo : L,
  1678. 'var' : L,
  1679. div : P,
  1680. object : O,
  1681. sup : L,
  1682. dd : P,
  1683. strike : L,
  1684. area : {},
  1685. dir : Q,
  1686. map : X( _({area:1,form:1,p:1}), A, F, E ),
  1687. applet : O,
  1688. dl : _({dt:1,dd:1}),
  1689. del : L,
  1690. isindex : {},
  1691. fieldset : X( _({legend:1}), K ),
  1692. thead : M,
  1693. ul : Q,
  1694. acronym : L,
  1695. b : L,
  1696. a : X( _({a:1}), J ),
  1697. blockquote :X(_({td:1,tr:1,tbody:1,li:1}),P),
  1698. caption : L,
  1699. i : L,
  1700. u : L,
  1701. tbody : M,
  1702. s : L,
  1703. address : X( D, I ),
  1704. tt : L,
  1705. legend : L,
  1706. q : L,
  1707. pre : X( G, C ),
  1708. p : X(_({'a':1}),L),
  1709. em :L,
  1710. dfn : L
  1711. });
  1712. })();
  1713. // core/domUtils.js
  1714. /**
  1715. * Dom操作工具包
  1716. * @file
  1717. * @module UE.dom.domUtils
  1718. * @since 1.2.6.1
  1719. */
  1720. /**
  1721. * Dom操作工具包
  1722. * @unfile
  1723. * @module UE.dom.domUtils
  1724. */
  1725. function getDomNode(node, start, ltr, startFromChild, fn, guard) {
  1726. var tmpNode = startFromChild && node[start],
  1727. parent;
  1728. !tmpNode && (tmpNode = node[ltr]);
  1729. while (!tmpNode && (parent = (parent || node).parentNode)) {
  1730. if (parent.tagName == 'BODY' || guard && !guard(parent)) {
  1731. return null;
  1732. }
  1733. tmpNode = parent[ltr];
  1734. }
  1735. if (tmpNode && fn && !fn(tmpNode)) {
  1736. return getDomNode(tmpNode, start, ltr, false, fn);
  1737. }
  1738. return tmpNode;
  1739. }
  1740. var attrFix = ie && browser.version < 9 ? {
  1741. tabindex:"tabIndex",
  1742. readonly:"readOnly",
  1743. "for":"htmlFor",
  1744. "class":"className",
  1745. maxlength:"maxLength",
  1746. cellspacing:"cellSpacing",
  1747. cellpadding:"cellPadding",
  1748. rowspan:"rowSpan",
  1749. colspan:"colSpan",
  1750. usemap:"useMap",
  1751. frameborder:"frameBorder"
  1752. } : {
  1753. tabindex:"tabIndex",
  1754. readonly:"readOnly"
  1755. },
  1756. styleBlock = utils.listToMap([
  1757. '-webkit-box', '-moz-box', 'block' ,
  1758. 'list-item' , 'table' , 'table-row-group' ,
  1759. 'table-header-group', 'table-footer-group' ,
  1760. 'table-row' , 'table-column-group' , 'table-column' ,
  1761. 'table-cell' , 'table-caption'
  1762. ]);
  1763. var domUtils = dom.domUtils = {
  1764. //节点常量
  1765. NODE_ELEMENT:1,
  1766. NODE_DOCUMENT:9,
  1767. NODE_TEXT:3,
  1768. NODE_COMMENT:8,
  1769. NODE_DOCUMENT_FRAGMENT:11,
  1770. //位置关系
  1771. POSITION_IDENTICAL:0,
  1772. POSITION_DISCONNECTED:1,
  1773. POSITION_FOLLOWING:2,
  1774. POSITION_PRECEDING:4,
  1775. POSITION_IS_CONTAINED:8,
  1776. POSITION_CONTAINS:16,
  1777. //ie6使用其他的会有一段空白出现
  1778. fillChar:ie && browser.version == '6' ? '\ufeff' : '\u200B',
  1779. //-------------------------Node部分--------------------------------
  1780. keys:{
  1781. /*Backspace*/ 8:1, /*Delete*/ 46:1,
  1782. /*Shift*/ 16:1, /*Ctrl*/ 17:1, /*Alt*/ 18:1,
  1783. 37:1, 38:1, 39:1, 40:1,
  1784. 13:1 /*enter*/
  1785. },
  1786. /**
  1787. * 获取节点A相对于节点B的位置关系
  1788. * @method getPosition
  1789. * @param { Node } nodeA 需要查询位置关系的节点A
  1790. * @param { Node } nodeB 需要查询位置关系的节点B
  1791. * @return { Number } 节点A与节点B的关系
  1792. * @example
  1793. * ```javascript
  1794. * //output: 20
  1795. * var position = UE.dom.domUtils.getPosition( document.documentElement, document.body );
  1796. *
  1797. * switch ( position ) {
  1798. *
  1799. * //0
  1800. * case UE.dom.domUtils.POSITION_IDENTICAL:
  1801. * console.log('元素相同');
  1802. * break;
  1803. * //1
  1804. * case UE.dom.domUtils.POSITION_DISCONNECTED:
  1805. * console.log('两个节点在不同的文档中');
  1806. * break;
  1807. * //2
  1808. * case UE.dom.domUtils.POSITION_FOLLOWING:
  1809. * console.log('节点A在节点B之后');
  1810. * break;
  1811. * //4
  1812. * case UE.dom.domUtils.POSITION_PRECEDING;
  1813. * console.log('节点A在节点B之前');
  1814. * break;
  1815. * //8
  1816. * case UE.dom.domUtils.POSITION_IS_CONTAINED:
  1817. * console.log('节点A被节点B包含');
  1818. * break;
  1819. * case 10:
  1820. * console.log('节点A被节点B包含且节点A在节点B之后');
  1821. * break;
  1822. * //16
  1823. * case UE.dom.domUtils.POSITION_CONTAINS:
  1824. * console.log('节点A包含节点B');
  1825. * break;
  1826. * case 20:
  1827. * console.log('节点A包含节点B且节点A在节点B之前');
  1828. * break;
  1829. *
  1830. * }
  1831. * ```
  1832. */
  1833. getPosition:function (nodeA, nodeB) {
  1834. // 如果两个节点是同一个节点
  1835. if (nodeA === nodeB) {
  1836. // domUtils.POSITION_IDENTICAL
  1837. return 0;
  1838. }
  1839. var node,
  1840. parentsA = [nodeA],
  1841. parentsB = [nodeB];
  1842. node = nodeA;
  1843. while (node = node.parentNode) {
  1844. // 如果nodeB是nodeA的祖先节点
  1845. if (node === nodeB) {
  1846. // domUtils.POSITION_IS_CONTAINED + domUtils.POSITION_FOLLOWING
  1847. return 10;
  1848. }
  1849. parentsA.push(node);
  1850. }
  1851. node = nodeB;
  1852. while (node = node.parentNode) {
  1853. // 如果nodeA是nodeB的祖先节点
  1854. if (node === nodeA) {
  1855. // domUtils.POSITION_CONTAINS + domUtils.POSITION_PRECEDING
  1856. return 20;
  1857. }
  1858. parentsB.push(node);
  1859. }
  1860. parentsA.reverse();
  1861. parentsB.reverse();
  1862. if (parentsA[0] !== parentsB[0]) {
  1863. // domUtils.POSITION_DISCONNECTED
  1864. return 1;
  1865. }
  1866. var i = -1;
  1867. while (i++, parentsA[i] === parentsB[i]) {
  1868. }
  1869. nodeA = parentsA[i];
  1870. nodeB = parentsB[i];
  1871. while (nodeA = nodeA.nextSibling) {
  1872. if (nodeA === nodeB) {
  1873. // domUtils.POSITION_PRECEDING
  1874. return 4
  1875. }
  1876. }
  1877. // domUtils.POSITION_FOLLOWING
  1878. return 2;
  1879. },
  1880. /**
  1881. * 检测节点node在父节点中的索引位置
  1882. * @method getNodeIndex
  1883. * @param { Node } node 需要检测的节点对象
  1884. * @return { Number } 该节点在父节点中的位置
  1885. * @see UE.dom.domUtils.getNodeIndex(Node,Boolean)
  1886. */
  1887. /**
  1888. * 检测节点node在父节点中的索引位置, 根据给定的mergeTextNode参数决定是否要合并多个连续的文本节点为一个节点
  1889. * @method getNodeIndex
  1890. * @param { Node } node 需要检测的节点对象
  1891. * @param { Boolean } mergeTextNode 是否合并多个连续的文本节点为一个节点
  1892. * @return { Number } 该节点在父节点中的位置
  1893. * @example
  1894. * ```javascript
  1895. *
  1896. * var node = document.createElement("div");
  1897. *
  1898. * node.appendChild( document.createTextNode( "hello" ) );
  1899. * node.appendChild( document.createTextNode( "world" ) );
  1900. * node.appendChild( node = document.createElement( "div" ) );
  1901. *
  1902. * //output: 2
  1903. * console.log( UE.dom.domUtils.getNodeIndex( node ) );
  1904. *
  1905. * //output: 1
  1906. * console.log( UE.dom.domUtils.getNodeIndex( node, true ) );
  1907. *
  1908. * ```
  1909. */
  1910. getNodeIndex:function (node, ignoreTextNode) {
  1911. var preNode = node,
  1912. i = 0;
  1913. while (preNode = preNode.previousSibling) {
  1914. if (ignoreTextNode && preNode.nodeType == 3) {
  1915. if(preNode.nodeType != preNode.nextSibling.nodeType ){
  1916. i++;
  1917. }
  1918. continue;
  1919. }
  1920. i++;
  1921. }
  1922. return i;
  1923. },
  1924. /**
  1925. * 检测节点node是否在给定的document对象上
  1926. * @method inDoc
  1927. * @param { Node } node 需要检测的节点对象
  1928. * @param { DomDocument } doc 需要检测的document对象
  1929. * @return { Boolean } 该节点node是否在给定的document的dom树上
  1930. * @example
  1931. * ```javascript
  1932. *
  1933. * var node = document.createElement("div");
  1934. *
  1935. * //output: false
  1936. * console.log( UE.do.domUtils.inDoc( node, document ) );
  1937. *
  1938. * document.body.appendChild( node );
  1939. *
  1940. * //output: true
  1941. * console.log( UE.do.domUtils.inDoc( node, document ) );
  1942. *
  1943. * ```
  1944. */
  1945. inDoc:function (node, doc) {
  1946. return domUtils.getPosition(node, doc) == 10;
  1947. },
  1948. /**
  1949. * 根据给定的过滤规则filterFn, 查找符合该过滤规则的node节点的第一个祖先节点,
  1950. * 查找的起点是给定node节点的父节点。
  1951. * @method findParent
  1952. * @param { Node } node 需要查找的节点
  1953. * @param { Function } filterFn 自定义的过滤方法。
  1954. * @warning 查找的终点是到body节点为止
  1955. * @remind 自定义的过滤方法filterFn接受一个Node对象作为参数, 该对象代表当前执行检测的祖先节点。 如果该
  1956. * 节点满足过滤条件, 则要求返回true, 这时将直接返回该节点作为findParent()的结果, 否则, 请返回false。
  1957. * @return { Node | Null } 如果找到符合过滤条件的节点, 就返回该节点, 否则返回NULL
  1958. * @example
  1959. * ```javascript
  1960. * var filterNode = UE.dom.domUtils.findParent( document.body.firstChild, function ( node ) {
  1961. *
  1962. * //由于查找的终点是body节点, 所以永远也不会匹配当前过滤器的条件, 即这里永远会返回false
  1963. * return node.tagName === "HTML";
  1964. *
  1965. * } );
  1966. *
  1967. * //output: true
  1968. * console.log( filterNode === null );
  1969. * ```
  1970. */
  1971. /**
  1972. * 根据给定的过滤规则filterFn, 查找符合该过滤规则的node节点的第一个祖先节点,
  1973. * 如果includeSelf的值为true,则查找的起点是给定的节点node, 否则, 起点是node的父节点
  1974. * @method findParent
  1975. * @param { Node } node 需要查找的节点
  1976. * @param { Function } filterFn 自定义的过滤方法。
  1977. * @param { Boolean } includeSelf 查找过程是否包含自身
  1978. * @warning 查找的终点是到body节点为止
  1979. * @remind 自定义的过滤方法filterFn接受一个Node对象作为参数, 该对象代表当前执行检测的祖先节点。 如果该
  1980. * 节点满足过滤条件, 则要求返回true, 这时将直接返回该节点作为findParent()的结果, 否则, 请返回false。
  1981. * @remind 如果includeSelf为true, 则过滤器第一次执行时的参数会是节点本身。
  1982. * 反之, 过滤器第一次执行时的参数将是该节点的父节点。
  1983. * @return { Node | Null } 如果找到符合过滤条件的节点, 就返回该节点, 否则返回NULL
  1984. * @example
  1985. * ```html
  1986. * <body>
  1987. *
  1988. * <div id="test">
  1989. * </div>
  1990. *
  1991. * <script type="text/javascript">
  1992. *
  1993. * //output: DIV, BODY
  1994. * var filterNode = UE.dom.domUtils.findParent( document.getElementById( "test" ), function ( node ) {
  1995. *
  1996. * console.log( node.tagName );
  1997. * return false;
  1998. *
  1999. * }, true );
  2000. *
  2001. * </script>
  2002. * </body>
  2003. * ```
  2004. */
  2005. findParent:function (node, filterFn, includeSelf) {
  2006. if (node && !domUtils.isBody(node)) {
  2007. node = includeSelf ? node : node.parentNode;
  2008. while (node) {
  2009. if (!filterFn || filterFn(node) || domUtils.isBody(node)) {
  2010. return filterFn && !filterFn(node) && domUtils.isBody(node) ? null : node;
  2011. }
  2012. node = node.parentNode;
  2013. }
  2014. }
  2015. return null;
  2016. },
  2017. /**
  2018. * 查找node的节点名为tagName的第一个祖先节点, 查找的起点是node节点的父节点。
  2019. * @method findParentByTagName
  2020. * @param { Node } node 需要查找的节点对象
  2021. * @param { Array } tagNames 需要查找的父节点的名称数组
  2022. * @warning 查找的终点是到body节点为止
  2023. * @return { Node | NULL } 如果找到符合条件的节点, 则返回该节点, 否则返回NULL
  2024. * @example
  2025. * ```javascript
  2026. * var node = UE.dom.domUtils.findParentByTagName( document.getElementsByTagName("div")[0], [ "BODY" ] );
  2027. * //output: BODY
  2028. * console.log( node.tagName );
  2029. * ```
  2030. */
  2031. /**
  2032. * 查找node的节点名为tagName的祖先节点, 如果includeSelf的值为true,则查找的起点是给定的节点node,
  2033. * 否则, 起点是node的父节点。
  2034. * @method findParentByTagName
  2035. * @param { Node } node 需要查找的节点对象
  2036. * @param { Array } tagNames 需要查找的父节点的名称数组
  2037. * @param { Boolean } includeSelf 查找过程是否包含node节点自身
  2038. * @warning 查找的终点是到body节点为止
  2039. * @return { Node | NULL } 如果找到符合条件的节点, 则返回该节点, 否则返回NULL
  2040. * @example
  2041. * ```javascript
  2042. * var queryTarget = document.getElementsByTagName("div")[0];
  2043. * var node = UE.dom.domUtils.findParentByTagName( queryTarget, [ "DIV" ], true );
  2044. * //output: true
  2045. * console.log( queryTarget === node );
  2046. * ```
  2047. */
  2048. findParentByTagName:function (node, tagNames, includeSelf, excludeFn) {
  2049. tagNames = utils.listToMap(utils.isArray(tagNames) ? tagNames : [tagNames]);
  2050. return domUtils.findParent(node, function (node) {
  2051. return tagNames[node.tagName] && !(excludeFn && excludeFn(node));
  2052. }, includeSelf);
  2053. },
  2054. /**
  2055. * 查找节点node的祖先节点集合, 查找的起点是给定节点的父节点,结果集中不包含给定的节点。
  2056. * @method findParents
  2057. * @param { Node } node 需要查找的节点对象
  2058. * @return { Array } 给定节点的祖先节点数组
  2059. * @grammar UE.dom.domUtils.findParents(node) => Array //返回一个祖先节点数组集合,不包含自身
  2060. * @grammar UE.dom.domUtils.findParents(node,includeSelf) => Array //返回一个祖先节点数组集合,includeSelf指定是否包含自身
  2061. * @grammar UE.dom.domUtils.findParents(node,includeSelf,filterFn) => Array //返回一个祖先节点数组集合,filterFn指定过滤条件,返回true的node将被选取
  2062. * @grammar UE.dom.domUtils.findParents(node,includeSelf,filterFn,closerFirst) => Array //返回一个祖先节点数组集合,closerFirst为true的话,node的直接父亲节点是数组的第0个
  2063. */
  2064. /**
  2065. * 查找节点node的祖先节点集合, 如果includeSelf的值为true,
  2066. * 则返回的结果集中允许出现当前给定的节点, 否则, 该节点不会出现在其结果集中。
  2067. * @method findParents
  2068. * @param { Node } node 需要查找的节点对象
  2069. * @param { Boolean } includeSelf 查找的结果中是否允许包含当前查找的节点对象
  2070. * @return { Array } 给定节点的祖先节点数组
  2071. */
  2072. findParents:function (node, includeSelf, filterFn, closerFirst) {
  2073. var parents = includeSelf && ( filterFn && filterFn(node) || !filterFn ) ? [node] : [];
  2074. while (node = domUtils.findParent(node, filterFn)) {
  2075. parents.push(node);
  2076. }
  2077. return closerFirst ? parents : parents.reverse();
  2078. },
  2079. /**
  2080. * 在节点node后面插入新节点newNode
  2081. * @method insertAfter
  2082. * @param { Node } node 目标节点
  2083. * @param { Node } newNode 新插入的节点, 该节点将置于目标节点之后
  2084. * @return { Node } 新插入的节点
  2085. */
  2086. insertAfter:function (node, newNode) {
  2087. return node.nextSibling ? node.parentNode.insertBefore(newNode, node.nextSibling):
  2088. node.parentNode.appendChild(newNode);
  2089. },
  2090. /**
  2091. * 删除节点node及其下属的所有节点
  2092. * @method remove
  2093. * @param { Node } node 需要删除的节点对象
  2094. * @return { Node } 返回刚删除的节点对象
  2095. * @example
  2096. * ```html
  2097. * <div id="test">
  2098. * <div id="child">你好</div>
  2099. * </div>
  2100. * <script>
  2101. * UE.dom.domUtils.remove( document.body, false );
  2102. * //output: false
  2103. * console.log( document.getElementById( "child" ) !== null );
  2104. * </script>
  2105. * ```
  2106. */
  2107. /**
  2108. * 删除节点node,并根据keepChildren的值决定是否保留子节点
  2109. * @method remove
  2110. * @param { Node } node 需要删除的节点对象
  2111. * @param { Boolean } keepChildren 是否需要保留子节点
  2112. * @return { Node } 返回刚删除的节点对象
  2113. * @example
  2114. * ```html
  2115. * <div id="test">
  2116. * <div id="child">你好</div>
  2117. * </div>
  2118. * <script>
  2119. * UE.dom.domUtils.remove( document.body, true );
  2120. * //output: true
  2121. * console.log( document.getElementById( "child" ) !== null );
  2122. * </script>
  2123. * ```
  2124. */
  2125. remove:function (node, keepChildren) {
  2126. var parent = node.parentNode,
  2127. child;
  2128. if (parent) {
  2129. if (keepChildren && node.hasChildNodes()) {
  2130. while (child = node.firstChild) {
  2131. parent.insertBefore(child, node);
  2132. }
  2133. }
  2134. parent.removeChild(node);
  2135. }
  2136. return node;
  2137. },
  2138. /**
  2139. * 取得node节点的下一个兄弟节点, 如果该节点其后没有兄弟节点, 则递归查找其父节点之后的第一个兄弟节点,
  2140. * 直到找到满足条件的节点或者递归到BODY节点之后才会结束。
  2141. * @method getNextDomNode
  2142. * @param { Node } node 需要获取其后的兄弟节点的节点对象
  2143. * @return { Node | NULL } 如果找满足条件的节点, 则返回该节点, 否则返回NULL
  2144. * @example
  2145. * ```html
  2146. * <body>
  2147. * <div id="test">
  2148. * <span></span>
  2149. * </div>
  2150. * <i>xxx</i>
  2151. * </body>
  2152. * <script>
  2153. *
  2154. * //output: i节点
  2155. * console.log( UE.dom.domUtils.getNextDomNode( document.getElementById( "test" ) ) );
  2156. *
  2157. * </script>
  2158. * ```
  2159. * @example
  2160. * ```html
  2161. * <body>
  2162. * <div>
  2163. * <span></span>
  2164. * <i id="test">xxx</i>
  2165. * </div>
  2166. * <b>xxx</b>
  2167. * </body>
  2168. * <script>
  2169. *
  2170. * //由于id为test的i节点之后没有兄弟节点, 则查找其父节点(div)后面的兄弟节点
  2171. * //output: b节点
  2172. * console.log( UE.dom.domUtils.getNextDomNode( document.getElementById( "test" ) ) );
  2173. *
  2174. * </script>
  2175. * ```
  2176. */
  2177. /**
  2178. * 取得node节点的下一个兄弟节点, 如果startFromChild的值为ture,则先获取其子节点,
  2179. * 如果有子节点则直接返回第一个子节点;如果没有子节点或者startFromChild的值为false,
  2180. * 则执行<a href="#UE.dom.domUtils.getNextDomNode(Node)">getNextDomNode(Node node)</a>的查找过程。
  2181. * @method getNextDomNode
  2182. * @param { Node } node 需要获取其后的兄弟节点的节点对象
  2183. * @param { Boolean } startFromChild 查找过程是否从其子节点开始
  2184. * @return { Node | NULL } 如果找满足条件的节点, 则返回该节点, 否则返回NULL
  2185. * @see UE.dom.domUtils.getNextDomNode(Node)
  2186. */
  2187. getNextDomNode:function (node, startFromChild, filterFn, guard) {
  2188. return getDomNode(node, 'firstChild', 'nextSibling', startFromChild, filterFn, guard);
  2189. },
  2190. getPreDomNode:function (node, startFromChild, filterFn, guard) {
  2191. return getDomNode(node, 'lastChild', 'previousSibling', startFromChild, filterFn, guard);
  2192. },
  2193. /**
  2194. * 检测节点node是否属是UEditor定义的bookmark节点
  2195. * @method isBookmarkNode
  2196. * @private
  2197. * @param { Node } node 需要检测的节点对象
  2198. * @return { Boolean } 是否是bookmark节点
  2199. * @example
  2200. * ```html
  2201. * <span id="_baidu_bookmark_1"></span>
  2202. * <script>
  2203. * var bookmarkNode = document.getElementById("_baidu_bookmark_1");
  2204. * //output: true
  2205. * console.log( UE.dom.domUtils.isBookmarkNode( bookmarkNode ) );
  2206. * </script>
  2207. * ```
  2208. */
  2209. isBookmarkNode:function (node) {
  2210. return node.nodeType == 1 && node.id && /^_baidu_bookmark_/i.test(node.id);
  2211. },
  2212. /**
  2213. * 获取节点node所属的window对象
  2214. * @method getWindow
  2215. * @param { Node } node 节点对象
  2216. * @return { Window } 当前节点所属的window对象
  2217. * @example
  2218. * ```javascript
  2219. * //output: true
  2220. * console.log( UE.dom.domUtils.getWindow( document.body ) === window );
  2221. * ```
  2222. */
  2223. getWindow:function (node) {
  2224. var doc = node.ownerDocument || node;
  2225. return doc.defaultView || doc.parentWindow;
  2226. },
  2227. /**
  2228. * 获取离nodeA与nodeB最近的公共的祖先节点
  2229. * @method getCommonAncestor
  2230. * @param { Node } nodeA 第一个节点
  2231. * @param { Node } nodeB 第二个节点
  2232. * @remind 如果给定的两个节点是同一个节点, 将直接返回该节点。
  2233. * @return { Node | NULL } 如果未找到公共节点, 返回NULL, 否则返回最近的公共祖先节点。
  2234. * @example
  2235. * ```javascript
  2236. * var commonAncestor = UE.dom.domUtils.getCommonAncestor( document.body, document.body.firstChild );
  2237. * //output: true
  2238. * console.log( commonAncestor.tagName.toLowerCase() === 'body' );
  2239. * ```
  2240. */
  2241. getCommonAncestor:function (nodeA, nodeB) {
  2242. if (nodeA === nodeB)
  2243. return nodeA;
  2244. var parentsA = [nodeA] , parentsB = [nodeB], parent = nodeA, i = -1;
  2245. while (parent = parent.parentNode) {
  2246. if (parent === nodeB) {
  2247. return parent;
  2248. }
  2249. parentsA.push(parent);
  2250. }
  2251. parent = nodeB;
  2252. while (parent = parent.parentNode) {
  2253. if (parent === nodeA)
  2254. return parent;
  2255. parentsB.push(parent);
  2256. }
  2257. parentsA.reverse();
  2258. parentsB.reverse();
  2259. while (i++, parentsA[i] === parentsB[i]) {
  2260. }
  2261. return i == 0 ? null : parentsA[i - 1];
  2262. },
  2263. /**
  2264. * 清除node节点左右连续为空的兄弟inline节点
  2265. * @method clearEmptySibling
  2266. * @param { Node } node 执行的节点对象, 如果该节点的左右连续的兄弟节点是空的inline节点,
  2267. * 则这些兄弟节点将被删除
  2268. * @grammar UE.dom.domUtils.clearEmptySibling(node,ignoreNext) //ignoreNext指定是否忽略右边空节点
  2269. * @grammar UE.dom.domUtils.clearEmptySibling(node,ignoreNext,ignorePre) //ignorePre指定是否忽略左边空节点
  2270. * @example
  2271. * ```html
  2272. * <body>
  2273. * <div></div>
  2274. * <span id="test"></span>
  2275. * <i></i>
  2276. * <b></b>
  2277. * <em>xxx</em>
  2278. * <span></span>
  2279. * </body>
  2280. * <script>
  2281. *
  2282. * UE.dom.domUtils.clearEmptySibling( document.getElementById( "test" ) );
  2283. *
  2284. * //output: <div></div><span id="test"></span><em>xxx</em><span></span>
  2285. * console.log( document.body.innerHTML );
  2286. *
  2287. * </script>
  2288. * ```
  2289. */
  2290. /**
  2291. * 清除node节点左右连续为空的兄弟inline节点, 如果ignoreNext的值为true,
  2292. * 则忽略对右边兄弟节点的操作。
  2293. * @method clearEmptySibling
  2294. * @param { Node } node 执行的节点对象, 如果该节点的左右连续的兄弟节点是空的inline节点,
  2295. * @param { Boolean } ignoreNext 是否忽略忽略对右边的兄弟节点的操作
  2296. * 则这些兄弟节点将被删除
  2297. * @see UE.dom.domUtils.clearEmptySibling(Node)
  2298. */
  2299. /**
  2300. * 清除node节点左右连续为空的兄弟inline节点, 如果ignoreNext的值为true,
  2301. * 则忽略对右边兄弟节点的操作, 如果ignorePre的值为true,则忽略对左边兄弟节点的操作。
  2302. * @method clearEmptySibling
  2303. * @param { Node } node 执行的节点对象, 如果该节点的左右连续的兄弟节点是空的inline节点,
  2304. * @param { Boolean } ignoreNext 是否忽略忽略对右边的兄弟节点的操作
  2305. * @param { Boolean } ignorePre 是否忽略忽略对左边的兄弟节点的操作
  2306. * 则这些兄弟节点将被删除
  2307. * @see UE.dom.domUtils.clearEmptySibling(Node)
  2308. */
  2309. clearEmptySibling:function (node, ignoreNext, ignorePre) {
  2310. function clear(next, dir) {
  2311. var tmpNode;
  2312. while (next && !domUtils.isBookmarkNode(next) && (domUtils.isEmptyInlineElement(next)
  2313. //这里不能把空格算进来会吧空格干掉,出现文字间的空格丢掉了
  2314. || !new RegExp('[^\t\n\r' + domUtils.fillChar + ']').test(next.nodeValue) )) {
  2315. tmpNode = next[dir];
  2316. domUtils.remove(next);
  2317. next = tmpNode;
  2318. }
  2319. }
  2320. !ignoreNext && clear(node.nextSibling, 'nextSibling');
  2321. !ignorePre && clear(node.previousSibling, 'previousSibling');
  2322. },
  2323. /**
  2324. * 将一个文本节点textNode拆分成两个文本节点,offset指定拆分位置
  2325. * @method split
  2326. * @param { Node } textNode 需要拆分的文本节点对象
  2327. * @param { int } offset 需要拆分的位置, 位置计算从0开始
  2328. * @return { Node } 拆分后形成的新节点
  2329. * @example
  2330. * ```html
  2331. * <div id="test">abcdef</div>
  2332. * <script>
  2333. * var newNode = UE.dom.domUtils.split( document.getElementById( "test" ).firstChild, 3 );
  2334. * //output: def
  2335. * console.log( newNode.nodeValue );
  2336. * </script>
  2337. * ```
  2338. */
  2339. split:function (node, offset) {
  2340. var doc = node.ownerDocument;
  2341. if (browser.ie && offset == node.nodeValue.length) {
  2342. var next = doc.createTextNode('');
  2343. return domUtils.insertAfter(node, next);
  2344. }
  2345. var retval = node.splitText(offset);
  2346. //ie8下splitText不会跟新childNodes,我们手动触发他的更新
  2347. if (browser.ie8) {
  2348. var tmpNode = doc.createTextNode('');
  2349. domUtils.insertAfter(retval, tmpNode);
  2350. domUtils.remove(tmpNode);
  2351. }
  2352. return retval;
  2353. },
  2354. /**
  2355. * 检测文本节点textNode是否为空节点(包括空格、换行、占位符等字符)
  2356. * @method isWhitespace
  2357. * @param { Node } node 需要检测的节点对象
  2358. * @return { Boolean } 检测的节点是否为空
  2359. * @example
  2360. * ```html
  2361. * <div id="test">
  2362. *
  2363. * </div>
  2364. * <script>
  2365. * //output: true
  2366. * console.log( UE.dom.domUtils.isWhitespace( document.getElementById("test").firstChild ) );
  2367. * </script>
  2368. * ```
  2369. */
  2370. isWhitespace:function (node) {
  2371. return !new RegExp('[^ \t\n\r' + domUtils.fillChar + ']').test(node.nodeValue);
  2372. },
  2373. /**
  2374. * 获取元素element相对于viewport的位置坐标
  2375. * @method getXY
  2376. * @param { Node } element 需要计算位置的节点对象
  2377. * @return { Object } 返回形如{x:left,y:top}的一个key-value映射对象, 其中键x代表水平偏移距离,
  2378. * y代表垂直偏移距离。
  2379. *
  2380. * @example
  2381. * ```javascript
  2382. * var location = UE.dom.domUtils.getXY( document.getElementById("test") );
  2383. * //output: test的坐标为: 12, 24
  2384. * console.log( 'test的坐标为: ', location.x, ',', location.y );
  2385. * ```
  2386. */
  2387. getXY:function (element) {
  2388. var x = 0, y = 0;
  2389. while (element.offsetParent) {
  2390. y += element.offsetTop;
  2391. x += element.offsetLeft;
  2392. element = element.offsetParent;
  2393. }
  2394. return { 'x':x, 'y':y};
  2395. },
  2396. /**
  2397. * 为元素element绑定原生DOM事件,type为事件类型,handler为处理函数
  2398. * @method on
  2399. * @param { Node } element 需要绑定事件的节点对象
  2400. * @param { String } type 绑定的事件类型
  2401. * @param { Function } handler 事件处理器
  2402. * @example
  2403. * ```javascript
  2404. * UE.dom.domUtils.on(document.body,"click",function(e){
  2405. * //e为事件对象,this为被点击元素对戏那个
  2406. * });
  2407. * ```
  2408. */
  2409. /**
  2410. * 为元素element绑定原生DOM事件,type为事件类型,handler为处理函数
  2411. * @method on
  2412. * @param { Node } element 需要绑定事件的节点对象
  2413. * @param { Array } type 绑定的事件类型数组
  2414. * @param { Function } handler 事件处理器
  2415. * @example
  2416. * ```javascript
  2417. * UE.dom.domUtils.on(document.body,["click","mousedown"],function(evt){
  2418. * //evt为事件对象,this为被点击元素对象
  2419. * });
  2420. * ```
  2421. */
  2422. on:function (element, type, handler) {
  2423. var types = utils.isArray(type) ? type : utils.trim(type).split(/\s+/),
  2424. k = types.length;
  2425. if (k) while (k--) {
  2426. type = types[k];
  2427. if (element.addEventListener) {
  2428. element.addEventListener(type, handler, false);
  2429. } else {
  2430. if (!handler._d) {
  2431. handler._d = {
  2432. els : []
  2433. };
  2434. }
  2435. var key = type + handler.toString(),index = utils.indexOf(handler._d.els,element);
  2436. if (!handler._d[key] || index == -1) {
  2437. if(index == -1){
  2438. handler._d.els.push(element);
  2439. }
  2440. if(!handler._d[key]){
  2441. handler._d[key] = function (evt) {
  2442. return handler.call(evt.srcElement, evt || window.event);
  2443. };
  2444. }
  2445. element.attachEvent('on' + type, handler._d[key]);
  2446. }
  2447. }
  2448. }
  2449. element = null;
  2450. },
  2451. /**
  2452. * 解除DOM事件绑定
  2453. * @method un
  2454. * @param { Node } element 需要解除事件绑定的节点对象
  2455. * @param { String } type 需要接触绑定的事件类型
  2456. * @param { Function } handler 对应的事件处理器
  2457. * @example
  2458. * ```javascript
  2459. * UE.dom.domUtils.un(document.body,"click",function(evt){
  2460. * //evt为事件对象,this为被点击元素对象
  2461. * });
  2462. * ```
  2463. */
  2464. /**
  2465. * 解除DOM事件绑定
  2466. * @method un
  2467. * @param { Node } element 需要解除事件绑定的节点对象
  2468. * @param { Array } type 需要接触绑定的事件类型数组
  2469. * @param { Function } handler 对应的事件处理器
  2470. * @example
  2471. * ```javascript
  2472. * UE.dom.domUtils.un(document.body, ["click","mousedown"],function(evt){
  2473. * //evt为事件对象,this为被点击元素对象
  2474. * });
  2475. * ```
  2476. */
  2477. un:function (element, type, handler) {
  2478. var types = utils.isArray(type) ? type : utils.trim(type).split(/\s+/),
  2479. k = types.length;
  2480. if (k) while (k--) {
  2481. type = types[k];
  2482. if (element.removeEventListener) {
  2483. element.removeEventListener(type, handler, false);
  2484. } else {
  2485. var key = type + handler.toString();
  2486. try{
  2487. element.detachEvent('on' + type, handler._d ? handler._d[key] : handler);
  2488. }catch(e){}
  2489. if (handler._d && handler._d[key]) {
  2490. var index = utils.indexOf(handler._d.els,element);
  2491. if(index!=-1){
  2492. handler._d.els.splice(index,1);
  2493. }
  2494. handler._d.els.length == 0 && delete handler._d[key];
  2495. }
  2496. }
  2497. }
  2498. },
  2499. /**
  2500. * 比较节点nodeA与节点nodeB是否具有相同的标签名、属性名以及属性值
  2501. * @method isSameElement
  2502. * @param { Node } nodeA 需要比较的节点
  2503. * @param { Node } nodeB 需要比较的节点
  2504. * @return { Boolean } 两个节点是否具有相同的标签名、属性名以及属性值
  2505. * @example
  2506. * ```html
  2507. * <span style="font-size:12px">ssss</span>
  2508. * <span style="font-size:12px">bbbbb</span>
  2509. * <span style="font-size:13px">ssss</span>
  2510. * <span style="font-size:14px">bbbbb</span>
  2511. *
  2512. * <script>
  2513. *
  2514. * var nodes = document.getElementsByTagName( "span" );
  2515. *
  2516. * //output: true
  2517. * console.log( UE.dom.domUtils.isSameElement( nodes[0], nodes[1] ) );
  2518. *
  2519. * //output: false
  2520. * console.log( UE.dom.domUtils.isSameElement( nodes[2], nodes[3] ) );
  2521. *
  2522. * </script>
  2523. * ```
  2524. */
  2525. isSameElement:function (nodeA, nodeB) {
  2526. if (nodeA.tagName != nodeB.tagName) {
  2527. return false;
  2528. }
  2529. var thisAttrs = nodeA.attributes,
  2530. otherAttrs = nodeB.attributes;
  2531. if (!ie && thisAttrs.length != otherAttrs.length) {
  2532. return false;
  2533. }
  2534. var attrA, attrB, al = 0, bl = 0;
  2535. for (var i = 0; attrA = thisAttrs[i++];) {
  2536. if (attrA.nodeName == 'style') {
  2537. if (attrA.specified) {
  2538. al++;
  2539. }
  2540. if (domUtils.isSameStyle(nodeA, nodeB)) {
  2541. continue;
  2542. } else {
  2543. return false;
  2544. }
  2545. }
  2546. if (ie) {
  2547. if (attrA.specified) {
  2548. al++;
  2549. attrB = otherAttrs.getNamedItem(attrA.nodeName);
  2550. } else {
  2551. continue;
  2552. }
  2553. } else {
  2554. attrB = nodeB.attributes[attrA.nodeName];
  2555. }
  2556. if (!attrB.specified || attrA.nodeValue != attrB.nodeValue) {
  2557. return false;
  2558. }
  2559. }
  2560. // 有可能attrB的属性包含了attrA的属性之外还有自己的属性
  2561. if (ie) {
  2562. for (i = 0; attrB = otherAttrs[i++];) {
  2563. if (attrB.specified) {
  2564. bl++;
  2565. }
  2566. }
  2567. if (al != bl) {
  2568. return false;
  2569. }
  2570. }
  2571. return true;
  2572. },
  2573. /**
  2574. * 判断节点nodeA与节点nodeB的元素的style属性是否一致
  2575. * @method isSameStyle
  2576. * @param { Node } nodeA 需要比较的节点
  2577. * @param { Node } nodeB 需要比较的节点
  2578. * @return { Boolean } 两个节点是否具有相同的style属性值
  2579. * @example
  2580. * ```html
  2581. * <span style="font-size:12px">ssss</span>
  2582. * <span style="font-size:12px">bbbbb</span>
  2583. * <span style="font-size:13px">ssss</span>
  2584. * <span style="font-size:14px">bbbbb</span>
  2585. *
  2586. * <script>
  2587. *
  2588. * var nodes = document.getElementsByTagName( "span" );
  2589. *
  2590. * //output: true
  2591. * console.log( UE.dom.domUtils.isSameStyle( nodes[0], nodes[1] ) );
  2592. *
  2593. * //output: false
  2594. * console.log( UE.dom.domUtils.isSameStyle( nodes[2], nodes[3] ) );
  2595. *
  2596. * </script>
  2597. * ```
  2598. */
  2599. isSameStyle:function (nodeA, nodeB) {
  2600. var styleA = nodeA.style.cssText.replace(/( ?; ?)/g, ';').replace(/( ?: ?)/g, ':'),
  2601. styleB = nodeB.style.cssText.replace(/( ?; ?)/g, ';').replace(/( ?: ?)/g, ':');
  2602. if (browser.opera) {
  2603. styleA = nodeA.style;
  2604. styleB = nodeB.style;
  2605. if (styleA.length != styleB.length)
  2606. return false;
  2607. for (var p in styleA) {
  2608. if (/^(\d+|csstext)$/i.test(p)) {
  2609. continue;
  2610. }
  2611. if (styleA[p] != styleB[p]) {
  2612. return false;
  2613. }
  2614. }
  2615. return true;
  2616. }
  2617. if (!styleA || !styleB) {
  2618. return styleA == styleB;
  2619. }
  2620. styleA = styleA.split(';');
  2621. styleB = styleB.split(';');
  2622. if (styleA.length != styleB.length) {
  2623. return false;
  2624. }
  2625. for (var i = 0, ci; ci = styleA[i++];) {
  2626. if (utils.indexOf(styleB, ci) == -1) {
  2627. return false;
  2628. }
  2629. }
  2630. return true;
  2631. },
  2632. /**
  2633. * 检查节点node是否为block元素
  2634. * @method isBlockElm
  2635. * @param { Node } node 需要检测的节点对象
  2636. * @return { Boolean } 是否是block元素节点
  2637. * @warning 该方法的判断规则如下: 如果该元素原本是block元素, 则不论该元素当前的css样式是什么都会返回true;
  2638. * 否则,检测该元素的css样式, 如果该元素当前是block元素, 则返回true。 其余情况下都返回false。
  2639. * @example
  2640. * ```html
  2641. * <span id="test1" style="display: block"></span>
  2642. * <span id="test2"></span>
  2643. * <div id="test3" style="display: inline"></div>
  2644. *
  2645. * <script>
  2646. *
  2647. * //output: true
  2648. * console.log( UE.dom.domUtils.isBlockElm( document.getElementById("test1") ) );
  2649. *
  2650. * //output: false
  2651. * console.log( UE.dom.domUtils.isBlockElm( document.getElementById("test2") ) );
  2652. *
  2653. * //output: true
  2654. * console.log( UE.dom.domUtils.isBlockElm( document.getElementById("test3") ) );
  2655. *
  2656. * </script>
  2657. * ```
  2658. */
  2659. isBlockElm:function (node) {
  2660. return node.nodeType == 1 && (dtd.$block[node.tagName] || styleBlock[domUtils.getComputedStyle(node, 'display')]) && !dtd.$nonChild[node.tagName];
  2661. },
  2662. /**
  2663. * 检测node节点是否为body节点
  2664. * @method isBody
  2665. * @param { Element } node 需要检测的dom元素
  2666. * @return { Boolean } 给定的元素是否是body元素
  2667. * @example
  2668. * ```javascript
  2669. * //output: true
  2670. * console.log( UE.dom.domUtils.isBody( document.body ) );
  2671. * ```
  2672. */
  2673. isBody:function (node) {
  2674. return node && node.nodeType == 1 && node.tagName.toLowerCase() == 'body';
  2675. },
  2676. /**
  2677. * 以node节点为分界,将该节点的指定祖先节点parent拆分成两个独立的节点,
  2678. * 拆分形成的两个节点之间是node节点
  2679. * @method breakParent
  2680. * @param { Node } node 作为分界的节点对象
  2681. * @param { Node } parent 该节点必须是node节点的祖先节点, 且是block节点。
  2682. * @return { Node } 给定的node分界节点
  2683. * @example
  2684. * ```javascript
  2685. *
  2686. * var node = document.createElement("span"),
  2687. * wrapNode = document.createElement( "div" ),
  2688. * parent = document.createElement("p");
  2689. *
  2690. * parent.appendChild( node );
  2691. * wrapNode.appendChild( parent );
  2692. *
  2693. * //拆分前
  2694. * //output: <p><span></span></p>
  2695. * console.log( wrapNode.innerHTML );
  2696. *
  2697. *
  2698. * UE.dom.domUtils.breakParent( node, parent );
  2699. * //拆分后
  2700. * //output: <p></p><span></span><p></p>
  2701. * console.log( wrapNode.innerHTML );
  2702. *
  2703. * ```
  2704. */
  2705. breakParent:function (node, parent) {
  2706. var tmpNode,
  2707. parentClone = node,
  2708. clone = node,
  2709. leftNodes,
  2710. rightNodes;
  2711. do {
  2712. parentClone = parentClone.parentNode;
  2713. if (leftNodes) {
  2714. tmpNode = parentClone.cloneNode(false);
  2715. tmpNode.appendChild(leftNodes);
  2716. leftNodes = tmpNode;
  2717. tmpNode = parentClone.cloneNode(false);
  2718. tmpNode.appendChild(rightNodes);
  2719. rightNodes = tmpNode;
  2720. } else {
  2721. leftNodes = parentClone.cloneNode(false);
  2722. rightNodes = leftNodes.cloneNode(false);
  2723. }
  2724. while (tmpNode = clone.previousSibling) {
  2725. leftNodes.insertBefore(tmpNode, leftNodes.firstChild);
  2726. }
  2727. while (tmpNode = clone.nextSibling) {
  2728. rightNodes.appendChild(tmpNode);
  2729. }
  2730. clone = parentClone;
  2731. } while (parent !== parentClone);
  2732. tmpNode = parent.parentNode;
  2733. tmpNode.insertBefore(leftNodes, parent);
  2734. tmpNode.insertBefore(rightNodes, parent);
  2735. tmpNode.insertBefore(node, rightNodes);
  2736. domUtils.remove(parent);
  2737. return node;
  2738. },
  2739. /**
  2740. * 检查节点node是否是空inline节点
  2741. * @method isEmptyInlineElement
  2742. * @param { Node } node 需要检测的节点对象
  2743. * @return { Number } 如果给定的节点是空的inline节点, 则返回1, 否则返回0。
  2744. * @example
  2745. * ```html
  2746. * <b><i></i></b> => 1
  2747. * <b><i></i><u></u></b> => 1
  2748. * <b></b> => 1
  2749. * <b>xx<i></i></b> => 0
  2750. * ```
  2751. */
  2752. isEmptyInlineElement:function (node) {
  2753. if (node.nodeType != 1 || !dtd.$removeEmpty[ node.tagName ]) {
  2754. return 0;
  2755. }
  2756. node = node.firstChild;
  2757. while (node) {
  2758. //如果是创建的bookmark就跳过
  2759. if (domUtils.isBookmarkNode(node)) {
  2760. return 0;
  2761. }
  2762. if (node.nodeType == 1 && !domUtils.isEmptyInlineElement(node) ||
  2763. node.nodeType == 3 && !domUtils.isWhitespace(node)
  2764. ) {
  2765. return 0;
  2766. }
  2767. node = node.nextSibling;
  2768. }
  2769. return 1;
  2770. },
  2771. /**
  2772. * 删除node节点下首尾两端的空白文本子节点
  2773. * @method trimWhiteTextNode
  2774. * @param { Element } node 需要执行删除操作的元素对象
  2775. * @example
  2776. * ```javascript
  2777. * var node = document.createElement("div");
  2778. *
  2779. * node.appendChild( document.createTextNode( "" ) );
  2780. *
  2781. * node.appendChild( document.createElement("div") );
  2782. *
  2783. * node.appendChild( document.createTextNode( "" ) );
  2784. *
  2785. * //3
  2786. * console.log( node.childNodes.length );
  2787. *
  2788. * UE.dom.domUtils.trimWhiteTextNode( node );
  2789. *
  2790. * //1
  2791. * console.log( node.childNodes.length );
  2792. * ```
  2793. */
  2794. trimWhiteTextNode:function (node) {
  2795. function remove(dir) {
  2796. var child;
  2797. while ((child = node[dir]) && child.nodeType == 3 && domUtils.isWhitespace(child)) {
  2798. node.removeChild(child);
  2799. }
  2800. }
  2801. remove('firstChild');
  2802. remove('lastChild');
  2803. },
  2804. /**
  2805. * 合并node节点下相同的子节点
  2806. * @name mergeChild
  2807. * @desc
  2808. * UE.dom.domUtils.mergeChild(node,tagName) //tagName要合并的子节点的标签
  2809. * @example
  2810. * <p><span style="font-size:12px;">xx<span style="font-size:12px;">aa</span>xx</span></p>
  2811. * ==> UE.dom.domUtils.mergeChild(node,'span')
  2812. * <p><span style="font-size:12px;">xxaaxx</span></p>
  2813. */
  2814. mergeChild:function (node, tagName, attrs) {
  2815. var list = domUtils.getElementsByTagName(node, node.tagName.toLowerCase());
  2816. for (var i = 0, ci; ci = list[i++];) {
  2817. if (!ci.parentNode || domUtils.isBookmarkNode(ci)) {
  2818. continue;
  2819. }
  2820. //span单独处理
  2821. if (ci.tagName.toLowerCase() == 'span') {
  2822. if (node === ci.parentNode) {
  2823. domUtils.trimWhiteTextNode(node);
  2824. if (node.childNodes.length == 1) {
  2825. node.style.cssText = ci.style.cssText + ";" + node.style.cssText;
  2826. domUtils.remove(ci, true);
  2827. continue;
  2828. }
  2829. }
  2830. ci.style.cssText = node.style.cssText + ';' + ci.style.cssText;
  2831. if (attrs) {
  2832. var style = attrs.style;
  2833. if (style) {
  2834. style = style.split(';');
  2835. for (var j = 0, s; s = style[j++];) {
  2836. ci.style[utils.cssStyleToDomStyle(s.split(':')[0])] = s.split(':')[1];
  2837. }
  2838. }
  2839. }
  2840. if (domUtils.isSameStyle(ci, node)) {
  2841. domUtils.remove(ci, true);
  2842. }
  2843. continue;
  2844. }
  2845. if (domUtils.isSameElement(node, ci)) {
  2846. domUtils.remove(ci, true);
  2847. }
  2848. }
  2849. },
  2850. /**
  2851. * 原生方法getElementsByTagName的封装
  2852. * @method getElementsByTagName
  2853. * @param { Node } node 目标节点对象
  2854. * @param { String } tagName 需要查找的节点的tagName, 多个tagName以空格分割
  2855. * @return { Array } 符合条件的节点集合
  2856. */
  2857. getElementsByTagName:function (node, name,filter) {
  2858. if(filter && utils.isString(filter)){
  2859. var className = filter;
  2860. filter = function(node){return domUtils.hasClass(node,className)}
  2861. }
  2862. name = utils.trim(name).replace(/[ ]{2,}/g,' ').split(' ');
  2863. var arr = [];
  2864. for(var n = 0,ni;ni=name[n++];){
  2865. var list = node.getElementsByTagName(ni);
  2866. for (var i = 0, ci; ci = list[i++];) {
  2867. if(!filter || filter(ci))
  2868. arr.push(ci);
  2869. }
  2870. }
  2871. return arr;
  2872. },
  2873. /**
  2874. * 将节点node提取到父节点上
  2875. * @method mergeToParent
  2876. * @param { Element } node 需要提取的元素对象
  2877. * @example
  2878. * ```html
  2879. * <div id="parent">
  2880. * <div id="sub">
  2881. * <span id="child"></span>
  2882. * </div>
  2883. * </div>
  2884. *
  2885. * <script>
  2886. *
  2887. * var child = document.getElementById( "child" );
  2888. *
  2889. * //output: sub
  2890. * console.log( child.parentNode.id );
  2891. *
  2892. * UE.dom.domUtils.mergeToParent( child );
  2893. *
  2894. * //output: parent
  2895. * console.log( child.parentNode.id );
  2896. *
  2897. * </script>
  2898. * ```
  2899. */
  2900. mergeToParent:function (node) {
  2901. var parent = node.parentNode;
  2902. while (parent && dtd.$removeEmpty[parent.tagName]) {
  2903. if (parent.tagName == node.tagName || parent.tagName == 'A') {//针对a标签单独处理
  2904. domUtils.trimWhiteTextNode(parent);
  2905. //span需要特殊处理 不处理这样的情况 <span stlye="color:#fff">xxx<span style="color:#ccc">xxx</span>xxx</span>
  2906. if (parent.tagName == 'SPAN' && !domUtils.isSameStyle(parent, node)
  2907. || (parent.tagName == 'A' && node.tagName == 'SPAN')) {
  2908. if (parent.childNodes.length > 1 || parent !== node.parentNode) {
  2909. node.style.cssText = parent.style.cssText + ";" + node.style.cssText;
  2910. parent = parent.parentNode;
  2911. continue;
  2912. } else {
  2913. parent.style.cssText += ";" + node.style.cssText;
  2914. //trace:952 a标签要保持下划线
  2915. if (parent.tagName == 'A') {
  2916. parent.style.textDecoration = 'underline';
  2917. }
  2918. }
  2919. }
  2920. if (parent.tagName != 'A') {
  2921. parent === node.parentNode && domUtils.remove(node, true);
  2922. break;
  2923. }
  2924. }
  2925. parent = parent.parentNode;
  2926. }
  2927. },
  2928. /**
  2929. * 合并节点node的左右兄弟节点
  2930. * @method mergeSibling
  2931. * @param { Element } node 需要合并的目标节点
  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 );
  2939. * //output: xxxxoooxxxx
  2940. * console.log( demoNode.innerHTML );
  2941. * </script>
  2942. * ```
  2943. */
  2944. /**
  2945. * 合并节点node的左右兄弟节点, 可以根据给定的条件选择是否忽略合并左节点。
  2946. * @method mergeSibling
  2947. * @param { Element } node 需要合并的目标节点
  2948. * @param { Boolean } ignorePre 是否忽略合并左节点
  2949. * @example
  2950. * ```html
  2951. * <b>xxxx</b><b id="test">ooo</b><b>xxxx</b>
  2952. *
  2953. * <script>
  2954. * var demoNode = document.getElementById("test");
  2955. * UE.dom.domUtils.mergeSibling( demoNode, true );
  2956. * //output: oooxxxx
  2957. * console.log( demoNode.innerHTML );
  2958. * </script>
  2959. * ```
  2960. */
  2961. /**
  2962. * 合并节点node的左右兄弟节点,可以根据给定的条件选择是否忽略合并左右节点。
  2963. * @method mergeSibling
  2964. * @param { Element } node 需要合并的目标节点
  2965. * @param { Boolean } ignorePre 是否忽略合并左节点
  2966. * @param { Boolean } ignoreNext 是否忽略合并右节点
  2967. * @remind 如果同时忽略左右节点, 则该操作什么也不会做
  2968. * @example
  2969. * ```html
  2970. * <b>xxxx</b><b id="test">ooo</b><b>xxxx</b>
  2971. *
  2972. * <script>
  2973. * var demoNode = document.getElementById("test");
  2974. * UE.dom.domUtils.mergeSibling( demoNode, false, true );
  2975. * //output: xxxxooo
  2976. * console.log( demoNode.innerHTML );
  2977. * </script>
  2978. * ```
  2979. */
  2980. mergeSibling:function (node, ignorePre, ignoreNext) {
  2981. function merge(rtl, start, node) {
  2982. var next;
  2983. if ((next = node[rtl]) && !domUtils.isBookmarkNode(next) && next.nodeType == 1 && domUtils.isSameElement(node, next)) {
  2984. while (next.firstChild) {
  2985. if (start == 'firstChild') {
  2986. node.insertBefore(next.lastChild, node.firstChild);
  2987. } else {
  2988. node.appendChild(next.firstChild);
  2989. }
  2990. }
  2991. domUtils.remove(next);
  2992. }
  2993. }
  2994. !ignorePre && merge('previousSibling', 'firstChild', node);
  2995. !ignoreNext && merge('nextSibling', 'lastChild', node);
  2996. },
  2997. /**
  2998. * 设置节点node及其子节点不会被选中
  2999. * @method unSelectable
  3000. * @param { Element } node 需要执行操作的dom元素
  3001. * @remind 执行该操作后的节点, 将不能被鼠标选中
  3002. * @example
  3003. * ```javascript
  3004. * UE.dom.domUtils.unSelectable( document.body );
  3005. * ```
  3006. */
  3007. unSelectable:ie && browser.ie9below || browser.opera ? function (node) {
  3008. //for ie9
  3009. node.onselectstart = function () {
  3010. return false;
  3011. };
  3012. node.onclick = node.onkeyup = node.onkeydown = function () {
  3013. return false;
  3014. };
  3015. node.unselectable = 'on';
  3016. node.setAttribute("unselectable", "on");
  3017. for (var i = 0, ci; ci = node.all[i++];) {
  3018. switch (ci.tagName.toLowerCase()) {
  3019. case 'iframe' :
  3020. case 'textarea' :
  3021. case 'input' :
  3022. case 'select' :
  3023. break;
  3024. default :
  3025. ci.unselectable = 'on';
  3026. node.setAttribute("unselectable", "on");
  3027. }
  3028. }
  3029. } : function (node) {
  3030. node.style.MozUserSelect =
  3031. node.style.webkitUserSelect =
  3032. node.style.msUserSelect =
  3033. node.style.KhtmlUserSelect = 'none';
  3034. },
  3035. /**
  3036. * 删除节点node上的指定属性名称的属性
  3037. * @method removeAttributes
  3038. * @param { Node } node 需要删除属性的节点对象
  3039. * @param { String } attrNames 可以是空格隔开的多个属性名称,该操作将会依次删除相应的属性
  3040. * @example
  3041. * ```html
  3042. * <div id="wrap">
  3043. * <span style="font-size:14px;" id="test" name="followMe">xxxxx</span>
  3044. * </div>
  3045. *
  3046. * <script>
  3047. *
  3048. * UE.dom.domUtils.removeAttributes( document.getElementById( "test" ), "id name" );
  3049. *
  3050. * //output: <span style="font-size:14px;">xxxxx</span>
  3051. * console.log( document.getElementById("wrap").innerHTML );
  3052. *
  3053. * </script>
  3054. * ```
  3055. */
  3056. /**
  3057. * 删除节点node上的指定属性名称的属性
  3058. * @method removeAttributes
  3059. * @param { Node } node 需要删除属性的节点对象
  3060. * @param { Array } attrNames 需要删除的属性名数组
  3061. * @example
  3062. * ```html
  3063. * <div id="wrap">
  3064. * <span style="font-size:14px;" id="test" name="followMe">xxxxx</span>
  3065. * </div>
  3066. *
  3067. * <script>
  3068. *
  3069. * UE.dom.domUtils.removeAttributes( document.getElementById( "test" ), ["id", "name"] );
  3070. *
  3071. * //output: <span style="font-size:14px;">xxxxx</span>
  3072. * console.log( document.getElementById("wrap").innerHTML );
  3073. *
  3074. * </script>
  3075. * ```
  3076. */
  3077. removeAttributes:function (node, attrNames) {
  3078. attrNames = utils.isArray(attrNames) ? attrNames : utils.trim(attrNames).replace(/[ ]{2,}/g,' ').split(' ');
  3079. for (var i = 0, ci; ci = attrNames[i++];) {
  3080. ci = attrFix[ci] || ci;
  3081. switch (ci) {
  3082. case 'className':
  3083. node[ci] = '';
  3084. break;
  3085. case 'style':
  3086. node.style.cssText = '';
  3087. var val = node.getAttributeNode('style');
  3088. !browser.ie && val && node.removeAttributeNode(val);
  3089. }
  3090. node.removeAttribute(ci);
  3091. }
  3092. },
  3093. /**
  3094. * 在doc下创建一个标签名为tag,属性为attrs的元素
  3095. * @method createElement
  3096. * @param { DomDocument } doc 新创建的元素属于该document节点创建
  3097. * @param { String } tagName 需要创建的元素的标签名
  3098. * @param { Object } attrs 新创建的元素的属性key-value集合
  3099. * @return { Element } 新创建的元素对象
  3100. * @example
  3101. * ```javascript
  3102. * var ele = UE.dom.domUtils.createElement( document, 'div', {
  3103. * id: 'test'
  3104. * } );
  3105. *
  3106. * //output: DIV
  3107. * console.log( ele.tagName );
  3108. *
  3109. * //output: test
  3110. * console.log( ele.id );
  3111. *
  3112. * ```
  3113. */
  3114. createElement:function (doc, tag, attrs) {
  3115. return domUtils.setAttributes(doc.createElement(tag), attrs)
  3116. },
  3117. /**
  3118. * 为节点node添加属性attrs,attrs为属性键值对
  3119. * @method setAttributes
  3120. * @param { Element } node 需要设置属性的元素对象
  3121. * @param { Object } attrs 需要设置的属性名-值对
  3122. * @return { Element } 设置属性的元素对象
  3123. * @example
  3124. * ```html
  3125. * <span id="test"></span>
  3126. *
  3127. * <script>
  3128. *
  3129. * var testNode = UE.dom.domUtils.setAttributes( document.getElementById( "test" ), {
  3130. * id: 'demo'
  3131. * } );
  3132. *
  3133. * //output: demo
  3134. * console.log( testNode.id );
  3135. *
  3136. * </script>
  3137. *
  3138. */
  3139. setAttributes:function (node, attrs) {
  3140. for (var attr in attrs) {
  3141. if(attrs.hasOwnProperty(attr)){
  3142. var value = attrs[attr];
  3143. switch (attr) {
  3144. case 'class':
  3145. //ie下要这样赋值,setAttribute不起作用
  3146. node.className = value;
  3147. break;
  3148. case 'style' :
  3149. node.style.cssText = node.style.cssText + ";" + value;
  3150. break;
  3151. case 'innerHTML':
  3152. node[attr] = value;
  3153. break;
  3154. case 'value':
  3155. node.value = value;
  3156. break;
  3157. default:
  3158. node.setAttribute(attrFix[attr] || attr, value);
  3159. }
  3160. }
  3161. }
  3162. return node;
  3163. },
  3164. /**
  3165. * 获取元素element经过计算后的样式值
  3166. * @method getComputedStyle
  3167. * @param { Element } element 需要获取样式的元素对象
  3168. * @param { String } styleName 需要获取的样式名
  3169. * @return { String } 获取到的样式值
  3170. * @example
  3171. * ```html
  3172. * <style type="text/css">
  3173. * #test {
  3174. * font-size: 15px;
  3175. * }
  3176. * </style>
  3177. *
  3178. * <span id="test"></span>
  3179. *
  3180. * <script>
  3181. * //output: 15px
  3182. * console.log( UE.dom.domUtils.getComputedStyle( document.getElementById( "test" ), 'font-size' ) );
  3183. * </script>
  3184. * ```
  3185. */
  3186. getComputedStyle:function (element, styleName) {
  3187. //一下的属性单独处理
  3188. var pros = 'width height top left';
  3189. if(pros.indexOf(styleName) > -1){
  3190. return element['offset' + styleName.replace(/^\w/,function(s){return s.toUpperCase()})] + 'px';
  3191. }
  3192. //忽略文本节点
  3193. if (element.nodeType == 3) {
  3194. element = element.parentNode;
  3195. }
  3196. //ie下font-size若body下定义了font-size,则从currentStyle里会取到这个font-size. 取不到实际值,故此修改.
  3197. if (browser.ie && browser.version < 9 && styleName == 'font-size' && !element.style.fontSize &&
  3198. !dtd.$empty[element.tagName] && !dtd.$nonChild[element.tagName]) {
  3199. var span = element.ownerDocument.createElement('span');
  3200. span.style.cssText = 'padding:0;border:0;font-family:simsun;';
  3201. span.innerHTML = '.';
  3202. element.appendChild(span);
  3203. var result = span.offsetHeight;
  3204. element.removeChild(span);
  3205. span = null;
  3206. return result + 'px';
  3207. }
  3208. try {
  3209. var value = domUtils.getStyle(element, styleName) ||
  3210. (window.getComputedStyle ? domUtils.getWindow(element).getComputedStyle(element, '').getPropertyValue(styleName) :
  3211. ( element.currentStyle || element.style )[utils.cssStyleToDomStyle(styleName)]);
  3212. } catch (e) {
  3213. return "";
  3214. }
  3215. return utils.transUnitToPx(utils.fixColor(styleName, value));
  3216. },
  3217. /**
  3218. * 删除元素element指定的className
  3219. * @method removeClasses
  3220. * @param { Element } ele 需要删除class的元素节点
  3221. * @param { String } classNames 需要删除的className, 多个className之间以空格分开
  3222. * @example
  3223. * ```html
  3224. * <span id="test" class="test1 test2 test3">xxx</span>
  3225. *
  3226. * <script>
  3227. *
  3228. * var testNode = document.getElementById( "test" );
  3229. * UE.dom.domUtils.removeClasses( testNode, "test1 test2" );
  3230. *
  3231. * //output: test3
  3232. * console.log( testNode.className );
  3233. *
  3234. * </script>
  3235. * ```
  3236. */
  3237. /**
  3238. * 删除元素element指定的className
  3239. * @method removeClasses
  3240. * @param { Element } ele 需要删除class的元素节点
  3241. * @param { Array } classNames 需要删除的className数组
  3242. * @example
  3243. * ```html
  3244. * <span id="test" class="test1 test2 test3">xxx</span>
  3245. *
  3246. * <script>
  3247. *
  3248. * var testNode = document.getElementById( "test" );
  3249. * UE.dom.domUtils.removeClasses( testNode, ["test1", "test2"] );
  3250. *
  3251. * //output: test3
  3252. * console.log( testNode.className );
  3253. *
  3254. * </script>
  3255. * ```
  3256. */
  3257. removeClasses:function (elm, classNames) {
  3258. classNames = utils.isArray(classNames) ? classNames :
  3259. utils.trim(classNames).replace(/[ ]{2,}/g,' ').split(' ');
  3260. for(var i = 0,ci,cls = elm.className;ci=classNames[i++];){
  3261. cls = cls.replace(new RegExp('\\b' + ci + '\\b'),'')
  3262. }
  3263. cls = utils.trim(cls).replace(/[ ]{2,}/g,' ');
  3264. if(cls){
  3265. elm.className = cls;
  3266. }else{
  3267. domUtils.removeAttributes(elm,['class']);
  3268. }
  3269. },
  3270. /**
  3271. * 给元素element添加className
  3272. * @method addClass
  3273. * @param { Node } ele 需要增加className的元素
  3274. * @param { String } classNames 需要添加的className, 多个className之间以空格分割
  3275. * @remind 相同的类名不会被重复添加
  3276. * @example
  3277. * ```html
  3278. * <span id="test" class="cls1 cls2"></span>
  3279. *
  3280. * <script>
  3281. * var testNode = document.getElementById("test");
  3282. *
  3283. * UE.dom.domUtils.addClass( testNode, "cls2 cls3 cls4" );
  3284. *
  3285. * //output: cl1 cls2 cls3 cls4
  3286. * console.log( testNode.className );
  3287. *
  3288. * <script>
  3289. * ```
  3290. */
  3291. /**
  3292. * 给元素element添加className
  3293. * @method addClass
  3294. * @param { Node } ele 需要增加className的元素
  3295. * @param { Array } classNames 需要添加的className的数组
  3296. * @remind 相同的类名不会被重复添加
  3297. * @example
  3298. * ```html
  3299. * <span id="test" class="cls1 cls2"></span>
  3300. *
  3301. * <script>
  3302. * var testNode = document.getElementById("test");
  3303. *
  3304. * UE.dom.domUtils.addClass( testNode, ["cls2", "cls3", "cls4"] );
  3305. *
  3306. * //output: cl1 cls2 cls3 cls4
  3307. * console.log( testNode.className );
  3308. *
  3309. * <script>
  3310. * ```
  3311. */
  3312. addClass:function (elm, classNames) {
  3313. if(!elm)return;
  3314. classNames = utils.trim(classNames).replace(/[ ]{2,}/g,' ').split(' ');
  3315. for(var i = 0,ci,cls = elm.className;ci=classNames[i++];){
  3316. if(!new RegExp('\\b' + ci + '\\b').test(cls)){
  3317. cls += ' ' + ci;
  3318. }
  3319. }
  3320. elm.className = utils.trim(cls);
  3321. },
  3322. /**
  3323. * 判断元素element是否包含给定的样式类名className
  3324. * @method hasClass
  3325. * @param { Node } ele 需要检测的元素
  3326. * @param { String } classNames 需要检测的className, 多个className之间用空格分割
  3327. * @return { Boolean } 元素是否包含所有给定的className
  3328. * @example
  3329. * ```html
  3330. * <span id="test1" class="cls1 cls2"></span>
  3331. *
  3332. * <script>
  3333. * var test1 = document.getElementById("test1");
  3334. *
  3335. * //output: false
  3336. * console.log( UE.dom.domUtils.hasClass( test1, "cls2 cls1 cls3" ) );
  3337. *
  3338. * //output: true
  3339. * console.log( UE.dom.domUtils.hasClass( test1, "cls2 cls1" ) );
  3340. * </script>
  3341. * ```
  3342. */
  3343. /**
  3344. * 判断元素element是否包含给定的样式类名className
  3345. * @method hasClass
  3346. * @param { Node } ele 需要检测的元素
  3347. * @param { Array } classNames 需要检测的className数组
  3348. * @return { Boolean } 元素是否包含所有给定的className
  3349. * @example
  3350. * ```html
  3351. * <span id="test1" class="cls1 cls2"></span>
  3352. *
  3353. * <script>
  3354. * var test1 = document.getElementById("test1");
  3355. *
  3356. * //output: false
  3357. * console.log( UE.dom.domUtils.hasClass( test1, [ "cls2", "cls1", "cls3" ] ) );
  3358. *
  3359. * //output: true
  3360. * console.log( UE.dom.domUtils.hasClass( test1, [ "cls2", "cls1" ]) );
  3361. * </script>
  3362. * ```
  3363. */
  3364. hasClass:function (element, className) {
  3365. if(utils.isRegExp(className)){
  3366. return className.test(element.className)
  3367. }
  3368. className = utils.trim(className).replace(/[ ]{2,}/g,' ').split(' ');
  3369. for(var i = 0,ci,cls = element.className;ci=className[i++];){
  3370. if(!new RegExp('\\b' + ci + '\\b','i').test(cls)){
  3371. return false;
  3372. }
  3373. }
  3374. return i - 1 == className.length;
  3375. },
  3376. /**
  3377. * 阻止事件默认行为
  3378. * @method preventDefault
  3379. * @param { Event } evt 需要阻止默认行为的事件对象
  3380. * @example
  3381. * ```javascript
  3382. * UE.dom.domUtils.preventDefault( evt );
  3383. * ```
  3384. */
  3385. preventDefault:function (evt) {
  3386. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  3387. },
  3388. /**
  3389. * 删除元素element指定的样式
  3390. * @method removeStyle
  3391. * @param { Element } element 需要删除样式的元素
  3392. * @param { String } styleName 需要删除的样式名
  3393. * @example
  3394. * ```html
  3395. * <span id="test" style="color: red; background: blue;"></span>
  3396. *
  3397. * <script>
  3398. *
  3399. * var testNode = document.getElementById("test");
  3400. *
  3401. * UE.dom.domUtils.removeStyle( testNode, 'color' );
  3402. *
  3403. * //output: background: blue;
  3404. * console.log( testNode.style.cssText );
  3405. *
  3406. * </script>
  3407. * ```
  3408. */
  3409. removeStyle:function (element, name) {
  3410. if(browser.ie ){
  3411. //针对color先单独处理一下
  3412. if(name == 'color'){
  3413. name = '(^|;)' + name;
  3414. }
  3415. element.style.cssText = element.style.cssText.replace(new RegExp(name + '[^:]*:[^;]+;?','ig'),'')
  3416. }else{
  3417. if (element.style.removeProperty) {
  3418. element.style.removeProperty (name);
  3419. }else {
  3420. element.style.removeAttribute (utils.cssStyleToDomStyle(name));
  3421. }
  3422. }
  3423. if (!element.style.cssText) {
  3424. domUtils.removeAttributes(element, ['style']);
  3425. }
  3426. },
  3427. /**
  3428. * 获取元素element的style属性的指定值
  3429. * @method getStyle
  3430. * @param { Element } element 需要获取属性值的元素
  3431. * @param { String } styleName 需要获取的style的名称
  3432. * @warning 该方法仅获取元素style属性中所标明的值
  3433. * @return { String } 该元素包含指定的style属性值
  3434. * @example
  3435. * ```html
  3436. * <div id="test" style="color: red;"></div>
  3437. *
  3438. * <script>
  3439. *
  3440. * var testNode = document.getElementById( "test" );
  3441. *
  3442. * //output: red
  3443. * console.log( UE.dom.domUtils.getStyle( testNode, "color" ) );
  3444. *
  3445. * //output: ""
  3446. * console.log( UE.dom.domUtils.getStyle( testNode, "background" ) );
  3447. *
  3448. * </script>
  3449. * ```
  3450. */
  3451. getStyle:function (element, name) {
  3452. var value = element.style[ utils.cssStyleToDomStyle(name) ];
  3453. return utils.fixColor(name, value);
  3454. },
  3455. /**
  3456. * 为元素element设置样式属性值
  3457. * @method setStyle
  3458. * @param { Element } element 需要设置样式的元素
  3459. * @param { String } styleName 样式名
  3460. * @param { String } styleValue 样式值
  3461. * @example
  3462. * ```html
  3463. * <div id="test"></div>
  3464. *
  3465. * <script>
  3466. *
  3467. * var testNode = document.getElementById( "test" );
  3468. *
  3469. * //output: ""
  3470. * console.log( testNode.style.color );
  3471. *
  3472. * UE.dom.domUtils.setStyle( testNode, 'color', 'red' );
  3473. * //output: "red"
  3474. * console.log( testNode.style.color );
  3475. *
  3476. * </script>
  3477. * ```
  3478. */
  3479. setStyle:function (element, name, value) {
  3480. element.style[utils.cssStyleToDomStyle(name)] = value;
  3481. if(!utils.trim(element.style.cssText)){
  3482. this.removeAttributes(element,'style')
  3483. }
  3484. },
  3485. /**
  3486. * 为元素element设置多个样式属性值
  3487. * @method setStyles
  3488. * @param { Element } element 需要设置样式的元素
  3489. * @param { Object } styles 样式名值对
  3490. * @example
  3491. * ```html
  3492. * <div id="test"></div>
  3493. *
  3494. * <script>
  3495. *
  3496. * var testNode = document.getElementById( "test" );
  3497. *
  3498. * //output: ""
  3499. * console.log( testNode.style.color );
  3500. *
  3501. * UE.dom.domUtils.setStyles( testNode, {
  3502. * 'color': 'red'
  3503. * } );
  3504. * //output: "red"
  3505. * console.log( testNode.style.color );
  3506. *
  3507. * </script>
  3508. * ```
  3509. */
  3510. setStyles:function (element, styles) {
  3511. for (var name in styles) {
  3512. if (styles.hasOwnProperty(name)) {
  3513. domUtils.setStyle(element, name, styles[name]);
  3514. }
  3515. }
  3516. },
  3517. /**
  3518. * 删除_moz_dirty属性
  3519. * @private
  3520. * @method removeDirtyAttr
  3521. */
  3522. removeDirtyAttr:function (node) {
  3523. for (var i = 0, ci, nodes = node.getElementsByTagName('*'); ci = nodes[i++];) {
  3524. ci.removeAttribute('_moz_dirty');
  3525. }
  3526. node.removeAttribute('_moz_dirty');
  3527. },
  3528. /**
  3529. * 获取子节点的数量
  3530. * @method getChildCount
  3531. * @param { Element } node 需要检测的元素
  3532. * @return { Number } 给定的node元素的子节点数量
  3533. * @example
  3534. * ```html
  3535. * <div id="test">
  3536. * <span></span>
  3537. * </div>
  3538. *
  3539. * <script>
  3540. *
  3541. * //output: 3
  3542. * console.log( UE.dom.domUtils.getChildCount( document.getElementById("test") ) );
  3543. *
  3544. * </script>
  3545. * ```
  3546. */
  3547. /**
  3548. * 根据给定的过滤规则, 获取符合条件的子节点的数量
  3549. * @method getChildCount
  3550. * @param { Element } node 需要检测的元素
  3551. * @param { Function } fn 过滤器, 要求对符合条件的子节点返回true, 反之则要求返回false
  3552. * @return { Number } 符合过滤条件的node元素的子节点数量
  3553. * @example
  3554. * ```html
  3555. * <div id="test">
  3556. * <span></span>
  3557. * </div>
  3558. *
  3559. * <script>
  3560. *
  3561. * //output: 1
  3562. * console.log( UE.dom.domUtils.getChildCount( document.getElementById("test"), function ( node ) {
  3563. *
  3564. * return node.nodeType === 1;
  3565. *
  3566. * } ) );
  3567. *
  3568. * </script>
  3569. * ```
  3570. */
  3571. getChildCount:function (node, fn) {
  3572. var count = 0, first = node.firstChild;
  3573. fn = fn || function () {
  3574. return 1;
  3575. };
  3576. while (first) {
  3577. if (fn(first)) {
  3578. count++;
  3579. }
  3580. first = first.nextSibling;
  3581. }
  3582. return count;
  3583. },
  3584. /**
  3585. * 判断给定节点是否为空节点
  3586. * @method isEmptyNode
  3587. * @param { Node } node 需要检测的节点对象
  3588. * @return { Boolean } 节点是否为空
  3589. * @example
  3590. * ```javascript
  3591. * UE.dom.domUtils.isEmptyNode( document.body );
  3592. * ```
  3593. */
  3594. isEmptyNode:function (node) {
  3595. return !node.firstChild || domUtils.getChildCount(node, function (node) {
  3596. return !domUtils.isBr(node) && !domUtils.isBookmarkNode(node) && !domUtils.isWhitespace(node)
  3597. }) == 0
  3598. },
  3599. clearSelectedArr:function (nodes) {
  3600. var node;
  3601. while (node = nodes.pop()) {
  3602. domUtils.removeAttributes(node, ['class']);
  3603. }
  3604. },
  3605. /**
  3606. * 将显示区域滚动到指定节点的位置
  3607. * @method scrollToView
  3608. * @param {Node} node 节点
  3609. * @param {window} win window对象
  3610. * @param {Number} offsetTop 距离上方的偏移量
  3611. */
  3612. scrollToView:function (node, win, offsetTop) {
  3613. var getViewPaneSize = function () {
  3614. var doc = win.document,
  3615. mode = doc.compatMode == 'CSS1Compat';
  3616. return {
  3617. width:( mode ? doc.documentElement.clientWidth : doc.body.clientWidth ) || 0,
  3618. height:( mode ? doc.documentElement.clientHeight : doc.body.clientHeight ) || 0
  3619. };
  3620. },
  3621. getScrollPosition = function (win) {
  3622. if ('pageXOffset' in win) {
  3623. return {
  3624. x:win.pageXOffset || 0,
  3625. y:win.pageYOffset || 0
  3626. };
  3627. }
  3628. else {
  3629. var doc = win.document;
  3630. return {
  3631. x:doc.documentElement.scrollLeft || doc.body.scrollLeft || 0,
  3632. y:doc.documentElement.scrollTop || doc.body.scrollTop || 0
  3633. };
  3634. }
  3635. };
  3636. var winHeight = getViewPaneSize().height, offset = winHeight * -1 + offsetTop;
  3637. offset += (node.offsetHeight || 0);
  3638. var elementPosition = domUtils.getXY(node);
  3639. offset += elementPosition.y;
  3640. var currentScroll = getScrollPosition(win).y;
  3641. // offset += 50;
  3642. if (offset > currentScroll || offset < currentScroll - winHeight) {
  3643. win.scrollTo(0, offset + (offset < 0 ? -20 : 20));
  3644. }
  3645. },
  3646. /**
  3647. * 判断给定节点是否为br
  3648. * @method isBr
  3649. * @param { Node } node 需要判断的节点对象
  3650. * @return { Boolean } 给定的节点是否是br节点
  3651. */
  3652. isBr:function (node) {
  3653. return node.nodeType == 1 && node.tagName == 'BR';
  3654. },
  3655. /**
  3656. * 判断给定的节点是否是一个“填充”节点
  3657. * @private
  3658. * @method isFillChar
  3659. * @param { Node } node 需要判断的节点
  3660. * @param { Boolean } isInStart 是否从节点内容的开始位置匹配
  3661. * @returns { Boolean } 节点是否是填充节点
  3662. */
  3663. isFillChar:function (node,isInStart) {
  3664. if(node.nodeType != 3)
  3665. return false;
  3666. var text = node.nodeValue;
  3667. if(isInStart){
  3668. return new RegExp('^' + domUtils.fillChar).test(text)
  3669. }
  3670. return !text.replace(new RegExp(domUtils.fillChar,'g'), '').length
  3671. },
  3672. isStartInblock:function (range) {
  3673. var tmpRange = range.cloneRange(),
  3674. flag = 0,
  3675. start = tmpRange.startContainer,
  3676. tmp;
  3677. if(start.nodeType == 1 && start.childNodes[tmpRange.startOffset]){
  3678. start = start.childNodes[tmpRange.startOffset];
  3679. var pre = start.previousSibling;
  3680. while(pre && domUtils.isFillChar(pre)){
  3681. start = pre;
  3682. pre = pre.previousSibling;
  3683. }
  3684. }
  3685. if(this.isFillChar(start,true) && tmpRange.startOffset == 1){
  3686. tmpRange.setStartBefore(start);
  3687. start = tmpRange.startContainer;
  3688. }
  3689. while (start && domUtils.isFillChar(start)) {
  3690. tmp = start;
  3691. start = start.previousSibling
  3692. }
  3693. if (tmp) {
  3694. tmpRange.setStartBefore(tmp);
  3695. start = tmpRange.startContainer;
  3696. }
  3697. if (start.nodeType == 1 && domUtils.isEmptyNode(start) && tmpRange.startOffset == 1) {
  3698. tmpRange.setStart(start, 0).collapse(true);
  3699. }
  3700. while (!tmpRange.startOffset) {
  3701. start = tmpRange.startContainer;
  3702. if (domUtils.isBlockElm(start) || domUtils.isBody(start)) {
  3703. flag = 1;
  3704. break;
  3705. }
  3706. var pre = tmpRange.startContainer.previousSibling,
  3707. tmpNode;
  3708. if (!pre) {
  3709. tmpRange.setStartBefore(tmpRange.startContainer);
  3710. } else {
  3711. while (pre && domUtils.isFillChar(pre)) {
  3712. tmpNode = pre;
  3713. pre = pre.previousSibling;
  3714. }
  3715. if (tmpNode) {
  3716. tmpRange.setStartBefore(tmpNode);
  3717. } else {
  3718. tmpRange.setStartBefore(tmpRange.startContainer);
  3719. }
  3720. }
  3721. }
  3722. return flag && !domUtils.isBody(tmpRange.startContainer) ? 1 : 0;
  3723. },
  3724. /**
  3725. * 判断给定的元素是否是一个空元素
  3726. * @method isEmptyBlock
  3727. * @param { Element } node 需要判断的元素
  3728. * @return { Boolean } 是否是空元素
  3729. * @example
  3730. * ```html
  3731. * <div id="test"></div>
  3732. *
  3733. * <script>
  3734. * //output: true
  3735. * console.log( UE.dom.domUtils.isEmptyBlock( document.getElementById("test") ) );
  3736. * </script>
  3737. * ```
  3738. */
  3739. /**
  3740. * 根据指定的判断规则判断给定的元素是否是一个空元素
  3741. * @method isEmptyBlock
  3742. * @param { Element } node 需要判断的元素
  3743. * @param { RegExp } reg 对内容执行判断的正则表达式对象
  3744. * @return { Boolean } 是否是空元素
  3745. */
  3746. isEmptyBlock:function (node,reg) {
  3747. if(node.nodeType != 1)
  3748. return 0;
  3749. reg = reg || new RegExp('[ \xa0\t\r\n' + domUtils.fillChar + ']', 'g');
  3750. if (node[browser.ie ? 'innerText' : 'textContent'].replace(reg, '').length > 0) {
  3751. return 0;
  3752. }
  3753. for (var n in dtd.$isNotEmpty) {
  3754. if (node.getElementsByTagName(n).length) {
  3755. return 0;
  3756. }
  3757. }
  3758. return 1;
  3759. },
  3760. /**
  3761. * 移动元素使得该元素的位置移动指定的偏移量的距离
  3762. * @method setViewportOffset
  3763. * @param { Element } element 需要设置偏移量的元素
  3764. * @param { Object } offset 偏移量, 形如{ left: 100, top: 50 }的一个键值对, 表示该元素将在
  3765. * 现有的位置上向水平方向偏移offset.left的距离, 在竖直方向上偏移
  3766. * offset.top的距离
  3767. * @example
  3768. * ```html
  3769. * <div id="test" style="top: 100px; left: 50px; position: absolute;"></div>
  3770. *
  3771. * <script>
  3772. *
  3773. * var testNode = document.getElementById("test");
  3774. *
  3775. * UE.dom.domUtils.setViewportOffset( testNode, {
  3776. * left: 200,
  3777. * top: 50
  3778. * } );
  3779. *
  3780. * //output: top: 300px; left: 100px; position: absolute;
  3781. * console.log( testNode.style.cssText );
  3782. *
  3783. * </script>
  3784. * ```
  3785. */
  3786. setViewportOffset:function (element, offset) {
  3787. var left = parseInt(element.style.left) | 0;
  3788. var top = parseInt(element.style.top) | 0;
  3789. var rect = element.getBoundingClientRect();
  3790. var offsetLeft = offset.left - rect.left;
  3791. var offsetTop = offset.top - rect.top;
  3792. if (offsetLeft) {
  3793. element.style.left = left + offsetLeft + 'px';
  3794. }
  3795. if (offsetTop) {
  3796. element.style.top = top + offsetTop + 'px';
  3797. }
  3798. },
  3799. /**
  3800. * 用“填充字符”填充节点
  3801. * @method fillNode
  3802. * @private
  3803. * @param { DomDocument } doc 填充的节点所在的docment对象
  3804. * @param { Node } node 需要填充的节点对象
  3805. * @example
  3806. * ```html
  3807. * <div id="test"></div>
  3808. *
  3809. * <script>
  3810. * var testNode = document.getElementById("test");
  3811. *
  3812. * //output: 0
  3813. * console.log( testNode.childNodes.length );
  3814. *
  3815. * UE.dom.domUtils.fillNode( document, testNode );
  3816. *
  3817. * //output: 1
  3818. * console.log( testNode.childNodes.length );
  3819. *
  3820. * </script>
  3821. * ```
  3822. */
  3823. fillNode:function (doc, node) {
  3824. var tmpNode = browser.ie ? doc.createTextNode(domUtils.fillChar) : doc.createElement('br');
  3825. node.innerHTML = '';
  3826. node.appendChild(tmpNode);
  3827. },
  3828. /**
  3829. * 把节点src的所有子节点追加到另一个节点tag上去
  3830. * @method moveChild
  3831. * @param { Node } src 源节点, 该节点下的所有子节点将被移除
  3832. * @param { Node } tag 目标节点, 从源节点移除的子节点将被追加到该节点下
  3833. * @example
  3834. * ```html
  3835. * <div id="test1">
  3836. * <span></span>
  3837. * </div>
  3838. * <div id="test2">
  3839. * <div></div>
  3840. * </div>
  3841. *
  3842. * <script>
  3843. *
  3844. * var test1 = document.getElementById("test1"),
  3845. * test2 = document.getElementById("test2");
  3846. *
  3847. * UE.dom.domUtils.moveChild( test1, test2 );
  3848. *
  3849. * //output: ""(空字符串)
  3850. * console.log( test1.innerHTML );
  3851. *
  3852. * //output: "<div></div><span></span>"
  3853. * console.log( test2.innerHTML );
  3854. *
  3855. * </script>
  3856. * ```
  3857. */
  3858. /**
  3859. * 把节点src的所有子节点移动到另一个节点tag上去, 可以通过dir参数控制附加的行为是“追加”还是“插入顶部”
  3860. * @method moveChild
  3861. * @param { Node } src 源节点, 该节点下的所有子节点将被移除
  3862. * @param { Node } tag 目标节点, 从源节点移除的子节点将被附加到该节点下
  3863. * @param { Boolean } dir 附加方式, 如果为true, 则附加进去的节点将被放到目标节点的顶部, 反之,则放到末尾
  3864. * @example
  3865. * ```html
  3866. * <div id="test1">
  3867. * <span></span>
  3868. * </div>
  3869. * <div id="test2">
  3870. * <div></div>
  3871. * </div>
  3872. *
  3873. * <script>
  3874. *
  3875. * var test1 = document.getElementById("test1"),
  3876. * test2 = document.getElementById("test2");
  3877. *
  3878. * UE.dom.domUtils.moveChild( test1, test2, true );
  3879. *
  3880. * //output: ""(空字符串)
  3881. * console.log( test1.innerHTML );
  3882. *
  3883. * //output: "<span></span><div></div>"
  3884. * console.log( test2.innerHTML );
  3885. *
  3886. * </script>
  3887. * ```
  3888. */
  3889. moveChild:function (src, tag, dir) {
  3890. while (src.firstChild) {
  3891. if (dir && tag.firstChild) {
  3892. tag.insertBefore(src.lastChild, tag.firstChild);
  3893. } else {
  3894. tag.appendChild(src.firstChild);
  3895. }
  3896. }
  3897. },
  3898. /**
  3899. * 判断节点的标签上是否不存在任何属性
  3900. * @method hasNoAttributes
  3901. * @private
  3902. * @param { Node } node 需要检测的节点对象
  3903. * @return { Boolean } 节点是否不包含任何属性
  3904. * @example
  3905. * ```html
  3906. * <div id="test"><span>xxxx</span></div>
  3907. *
  3908. * <script>
  3909. *
  3910. * //output: false
  3911. * console.log( UE.dom.domUtils.hasNoAttributes( document.getElementById("test") ) );
  3912. *
  3913. * //output: true
  3914. * console.log( UE.dom.domUtils.hasNoAttributes( document.getElementById("test").firstChild ) );
  3915. *
  3916. * </script>
  3917. * ```
  3918. */
  3919. hasNoAttributes:function (node) {
  3920. return browser.ie ? /^<\w+\s*?>/.test(node.outerHTML) : node.attributes.length == 0;
  3921. },
  3922. /**
  3923. * 检测节点是否是UEditor所使用的辅助节点
  3924. * @method isCustomeNode
  3925. * @private
  3926. * @param { Node } node 需要检测的节点
  3927. * @remind 辅助节点是指编辑器要完成工作临时添加的节点, 在输出的时候将会从编辑器内移除, 不会影响最终的结果。
  3928. * @return { Boolean } 给定的节点是否是一个辅助节点
  3929. */
  3930. isCustomeNode:function (node) {
  3931. return node.nodeType == 1 && node.getAttribute('_ue_custom_node_');
  3932. },
  3933. /**
  3934. * 检测节点的标签是否是给定的标签
  3935. * @method isTagNode
  3936. * @param { Node } node 需要检测的节点对象
  3937. * @param { String } tagName 标签
  3938. * @return { Boolean } 节点的标签是否是给定的标签
  3939. * @example
  3940. * ```html
  3941. * <div id="test"></div>
  3942. *
  3943. * <script>
  3944. *
  3945. * //output: true
  3946. * console.log( UE.dom.domUtils.isTagNode( document.getElementById("test"), "div" ) );
  3947. *
  3948. * </script>
  3949. * ```
  3950. */
  3951. isTagNode:function (node, tagNames) {
  3952. return node.nodeType == 1 && new RegExp('\\b' + node.tagName + '\\b','i').test(tagNames)
  3953. },
  3954. /**
  3955. * 给定一个节点数组,在通过指定的过滤器过滤后, 获取其中满足过滤条件的第一个节点
  3956. * @method filterNodeList
  3957. * @param { Array } nodeList 需要过滤的节点数组
  3958. * @param { Function } fn 过滤器, 对符合条件的节点, 执行结果返回true, 反之则返回false
  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, function ( node ) {
  3967. * return node.tagName.toLowerCase() !== 'div';
  3968. * } ) );
  3969. * ```
  3970. */
  3971. /**
  3972. * 给定一个节点数组nodeList和一组标签名tagNames, 获取其中能够匹配标签名的节点集合中的第一个节点
  3973. * @method filterNodeList
  3974. * @param { Array } nodeList 需要过滤的节点数组
  3975. * @param { String } tagNames 需要匹配的标签名, 多个标签名之间用空格分割
  3976. * @return { Node | NULL } 如果找到标签名匹配的节点, 则返回该节点, 否则返回NULL
  3977. * @example
  3978. * ```javascript
  3979. * var divNodes = document.getElementsByTagName("div");
  3980. * divNodes = [].slice.call( divNodes, 0 );
  3981. *
  3982. * //output: null
  3983. * console.log( UE.dom.domUtils.filterNodeList( divNodes, 'a span' ) );
  3984. * ```
  3985. */
  3986. /**
  3987. * 给定一个节点数组,在通过指定的过滤器过滤后, 如果参数forAll为true, 则会返回所有满足过滤
  3988. * 条件的节点集合, 否则, 返回满足条件的节点集合中的第一个节点
  3989. * @method filterNodeList
  3990. * @param { Array } nodeList 需要过滤的节点数组
  3991. * @param { Function } fn 过滤器, 对符合条件的节点, 执行结果返回true, 反之则返回false
  3992. * @param { Boolean } forAll 是否返回整个节点数组, 如果该参数为false, 则返回节点集合中的第一个节点
  3993. * @return { Array | Node | NULL } 如果找到符合过滤条件的节点, 则根据参数forAll的值决定返回满足
  3994. * 过滤条件的节点数组或第一个节点, 否则返回NULL
  3995. * @example
  3996. * ```javascript
  3997. * var divNodes = document.getElementsByTagName("div");
  3998. * divNodes = [].slice.call( divNodes, 0 );
  3999. *
  4000. * //output: 3(假定有3个div)
  4001. * console.log( divNodes.length );
  4002. *
  4003. * var nodes = UE.dom.domUtils.filterNodeList( divNodes, function ( node ) {
  4004. * return node.tagName.toLowerCase() === 'div';
  4005. * }, true );
  4006. *
  4007. * //output: 3
  4008. * console.log( nodes.length );
  4009. *
  4010. * var node = UE.dom.domUtils.filterNodeList( divNodes, function ( node ) {
  4011. * return node.tagName.toLowerCase() === 'div';
  4012. * }, false );
  4013. *
  4014. * //output: div
  4015. * console.log( node.nodeName );
  4016. * ```
  4017. */
  4018. filterNodeList : function(nodelist,filter,forAll){
  4019. var results = [];
  4020. if(!utils .isFunction(filter)){
  4021. var str = filter;
  4022. filter = function(n){
  4023. return utils.indexOf(utils.isArray(str) ? str:str.split(' '), n.tagName.toLowerCase()) != -1
  4024. };
  4025. }
  4026. utils.each(nodelist,function(n){
  4027. filter(n) && results.push(n)
  4028. });
  4029. return results.length == 0 ? null : results.length == 1 || !forAll ? results[0] : results
  4030. },
  4031. /**
  4032. * 查询给定的range选区是否在给定的node节点内,且在该节点的最末尾
  4033. * @method isInNodeEndBoundary
  4034. * @param { UE.dom.Range } rng 需要判断的range对象, 该对象的startContainer不能为NULL
  4035. * @param node 需要检测的节点对象
  4036. * @return { Number } 如果给定的选取range对象是在node内部的最末端, 则返回1, 否则返回0
  4037. */
  4038. isInNodeEndBoundary : function (rng,node){
  4039. var start = rng.startContainer;
  4040. if(start.nodeType == 3 && rng.startOffset != start.nodeValue.length){
  4041. return 0;
  4042. }
  4043. if(start.nodeType == 1 && rng.startOffset != start.childNodes.length){
  4044. return 0;
  4045. }
  4046. while(start !== node){
  4047. if(start.nextSibling){
  4048. return 0
  4049. };
  4050. start = start.parentNode;
  4051. }
  4052. return 1;
  4053. },
  4054. isBoundaryNode : function (node,dir){
  4055. var tmp;
  4056. while(!domUtils.isBody(node)){
  4057. tmp = node;
  4058. node = node.parentNode;
  4059. if(tmp !== node[dir]){
  4060. return false;
  4061. }
  4062. }
  4063. return true;
  4064. },
  4065. fillHtml : browser.ie11below ? '&nbsp;' : '<br/>'
  4066. };
  4067. var fillCharReg = new RegExp(domUtils.fillChar, 'g');
  4068. // core/Range.js
  4069. /**
  4070. * Range封装
  4071. * @file
  4072. * @module UE.dom
  4073. * @class Range
  4074. * @since 1.2.6.1
  4075. */
  4076. /**
  4077. * dom操作封装
  4078. * @unfile
  4079. * @module UE.dom
  4080. */
  4081. /**
  4082. * Range实现类,本类是UEditor底层核心类,封装不同浏览器之间的Range操作。
  4083. * @unfile
  4084. * @module UE.dom
  4085. * @class Range
  4086. */
  4087. (function () {
  4088. var guid = 0,
  4089. fillChar = domUtils.fillChar,
  4090. fillData;
  4091. /**
  4092. * 更新range的collapse状态
  4093. * @param {Range} range range对象
  4094. */
  4095. function updateCollapse(range) {
  4096. range.collapsed =
  4097. range.startContainer && range.endContainer &&
  4098. range.startContainer === range.endContainer &&
  4099. range.startOffset == range.endOffset;
  4100. }
  4101. function selectOneNode(rng){
  4102. return !rng.collapsed && rng.startContainer.nodeType == 1 && rng.startContainer === rng.endContainer && rng.endOffset - rng.startOffset == 1
  4103. }
  4104. function setEndPoint(toStart, node, offset, range) {
  4105. //如果node是自闭合标签要处理
  4106. if (node.nodeType == 1 && (dtd.$empty[node.tagName] || dtd.$nonChild[node.tagName])) {
  4107. offset = domUtils.getNodeIndex(node) + (toStart ? 0 : 1);
  4108. node = node.parentNode;
  4109. }
  4110. if (toStart) {
  4111. range.startContainer = node;
  4112. range.startOffset = offset;
  4113. if (!range.endContainer) {
  4114. range.collapse(true);
  4115. }
  4116. } else {
  4117. range.endContainer = node;
  4118. range.endOffset = offset;
  4119. if (!range.startContainer) {
  4120. range.collapse(false);
  4121. }
  4122. }
  4123. updateCollapse(range);
  4124. return range;
  4125. }
  4126. function execContentsAction(range, action) {
  4127. //调整边界
  4128. //range.includeBookmark();
  4129. var start = range.startContainer,
  4130. end = range.endContainer,
  4131. startOffset = range.startOffset,
  4132. endOffset = range.endOffset,
  4133. doc = range.document,
  4134. frag = doc.createDocumentFragment(),
  4135. tmpStart, tmpEnd;
  4136. if (start.nodeType == 1) {
  4137. start = start.childNodes[startOffset] || (tmpStart = start.appendChild(doc.createTextNode('')));
  4138. }
  4139. if (end.nodeType == 1) {
  4140. end = end.childNodes[endOffset] || (tmpEnd = end.appendChild(doc.createTextNode('')));
  4141. }
  4142. if (start === end && start.nodeType == 3) {
  4143. frag.appendChild(doc.createTextNode(start.substringData(startOffset, endOffset - startOffset)));
  4144. //is not clone
  4145. if (action) {
  4146. start.deleteData(startOffset, endOffset - startOffset);
  4147. range.collapse(true);
  4148. }
  4149. return frag;
  4150. }
  4151. var current, currentLevel, clone = frag,
  4152. startParents = domUtils.findParents(start, true), endParents = domUtils.findParents(end, true);
  4153. for (var i = 0; startParents[i] == endParents[i];) {
  4154. i++;
  4155. }
  4156. for (var j = i, si; si = startParents[j]; j++) {
  4157. current = si.nextSibling;
  4158. if (si == start) {
  4159. if (!tmpStart) {
  4160. if (range.startContainer.nodeType == 3) {
  4161. clone.appendChild(doc.createTextNode(start.nodeValue.slice(startOffset)));
  4162. //is not clone
  4163. if (action) {
  4164. start.deleteData(startOffset, start.nodeValue.length - startOffset);
  4165. }
  4166. } else {
  4167. clone.appendChild(!action ? start.cloneNode(true) : start);
  4168. }
  4169. }
  4170. } else {
  4171. currentLevel = si.cloneNode(false);
  4172. clone.appendChild(currentLevel);
  4173. }
  4174. while (current) {
  4175. if (current === end || current === endParents[j]) {
  4176. break;
  4177. }
  4178. si = current.nextSibling;
  4179. clone.appendChild(!action ? current.cloneNode(true) : current);
  4180. current = si;
  4181. }
  4182. clone = currentLevel;
  4183. }
  4184. clone = frag;
  4185. if (!startParents[i]) {
  4186. clone.appendChild(startParents[i - 1].cloneNode(false));
  4187. clone = clone.firstChild;
  4188. }
  4189. for (var j = i, ei; ei = endParents[j]; j++) {
  4190. current = ei.previousSibling;
  4191. if (ei == end) {
  4192. if (!tmpEnd && range.endContainer.nodeType == 3) {
  4193. clone.appendChild(doc.createTextNode(end.substringData(0, endOffset)));
  4194. //is not clone
  4195. if (action) {
  4196. end.deleteData(0, endOffset);
  4197. }
  4198. }
  4199. } else {
  4200. currentLevel = ei.cloneNode(false);
  4201. clone.appendChild(currentLevel);
  4202. }
  4203. //如果两端同级,右边第一次已经被开始做了
  4204. if (j != i || !startParents[i]) {
  4205. while (current) {
  4206. if (current === start) {
  4207. break;
  4208. }
  4209. ei = current.previousSibling;
  4210. clone.insertBefore(!action ? current.cloneNode(true) : current, clone.firstChild);
  4211. current = ei;
  4212. }
  4213. }
  4214. clone = currentLevel;
  4215. }
  4216. if (action) {
  4217. range.setStartBefore(!endParents[i] ? endParents[i - 1] : !startParents[i] ? startParents[i - 1] : endParents[i]).collapse(true);
  4218. }
  4219. tmpStart && domUtils.remove(tmpStart);
  4220. tmpEnd && domUtils.remove(tmpEnd);
  4221. return frag;
  4222. }
  4223. /**
  4224. * 创建一个跟document绑定的空的Range实例
  4225. * @constructor
  4226. * @param { Document } document 新建的选区所属的文档对象
  4227. */
  4228. /**
  4229. * @property { Node } startContainer 当前Range的开始边界的容器节点, 可以是一个元素节点或者是文本节点
  4230. */
  4231. /**
  4232. * @property { Node } startOffset 当前Range的开始边界容器节点的偏移量, 如果是元素节点,
  4233. * 该值就是childNodes中的第几个节点, 如果是文本节点就是文本内容的第几个字符
  4234. */
  4235. /**
  4236. * @property { Node } endContainer 当前Range的结束边界的容器节点, 可以是一个元素节点或者是文本节点
  4237. */
  4238. /**
  4239. * @property { Node } endOffset 当前Range的结束边界容器节点的偏移量, 如果是元素节点,
  4240. * 该值就是childNodes中的第几个节点, 如果是文本节点就是文本内容的第几个字符
  4241. */
  4242. /**
  4243. * @property { Boolean } collapsed 当前Range是否闭合
  4244. * @default true
  4245. * @remind Range是闭合的时候, startContainer === endContainer && startOffset === endOffset
  4246. */
  4247. /**
  4248. * @property { Document } document 当前Range所属的Document对象
  4249. * @remind 不同range的的document属性可以是不同的
  4250. */
  4251. var Range = dom.Range = function (document) {
  4252. var me = this;
  4253. me.startContainer =
  4254. me.startOffset =
  4255. me.endContainer =
  4256. me.endOffset = null;
  4257. me.document = document;
  4258. me.collapsed = true;
  4259. };
  4260. /**
  4261. * 删除fillData
  4262. * @param doc
  4263. * @param excludeNode
  4264. */
  4265. function removeFillData(doc, excludeNode) {
  4266. try {
  4267. if (fillData && domUtils.inDoc(fillData, doc)) {
  4268. if (!fillData.nodeValue.replace(fillCharReg, '').length) {
  4269. var tmpNode = fillData.parentNode;
  4270. domUtils.remove(fillData);
  4271. while (tmpNode && domUtils.isEmptyInlineElement(tmpNode) &&
  4272. //safari的contains有bug
  4273. (browser.safari ? !(domUtils.getPosition(tmpNode,excludeNode) & domUtils.POSITION_CONTAINS) : !tmpNode.contains(excludeNode))
  4274. ) {
  4275. fillData = tmpNode.parentNode;
  4276. domUtils.remove(tmpNode);
  4277. tmpNode = fillData;
  4278. }
  4279. } else {
  4280. fillData.nodeValue = fillData.nodeValue.replace(fillCharReg, '');
  4281. }
  4282. }
  4283. } catch (e) {
  4284. }
  4285. }
  4286. /**
  4287. * @param node
  4288. * @param dir
  4289. */
  4290. function mergeSibling(node, dir) {
  4291. var tmpNode;
  4292. node = node[dir];
  4293. while (node && domUtils.isFillChar(node)) {
  4294. tmpNode = node[dir];
  4295. domUtils.remove(node);
  4296. node = tmpNode;
  4297. }
  4298. }
  4299. Range.prototype = {
  4300. /**
  4301. * 克隆选区的内容到一个DocumentFragment里
  4302. * @method cloneContents
  4303. * @return { DocumentFragment | NULL } 如果选区是闭合的将返回null, 否则, 返回包含所clone内容的DocumentFragment元素
  4304. * @example
  4305. * ```html
  4306. * <body>
  4307. * <!-- 中括号表示选区 -->
  4308. * <b>x<i>x[x</i>xx]x</b>
  4309. *
  4310. * <script>
  4311. * //range是已选中的选区
  4312. * var fragment = range.cloneContents(),
  4313. * node = document.createElement("div");
  4314. *
  4315. * node.appendChild( fragment );
  4316. *
  4317. * //output: <i>x</i>xx
  4318. * console.log( node.innerHTML );
  4319. *
  4320. * </script>
  4321. * </body>
  4322. * ```
  4323. */
  4324. cloneContents:function () {
  4325. return this.collapsed ? null : execContentsAction(this, 0);
  4326. },
  4327. /**
  4328. * 删除当前选区范围中的所有内容
  4329. * @method deleteContents
  4330. * @remind 执行完该操作后, 当前Range对象变成了闭合状态
  4331. * @return { UE.dom.Range } 当前操作的Range对象
  4332. * @example
  4333. * ```html
  4334. * <body>
  4335. * <!-- 中括号表示选区 -->
  4336. * <b>x<i>x[x</i>xx]x</b>
  4337. *
  4338. * <script>
  4339. * //range是已选中的选区
  4340. * range.deleteContents();
  4341. *
  4342. * //竖线表示闭合后的选区位置
  4343. * //output: <b>x<i>x</i>|x</b>
  4344. * console.log( document.body.innerHTML );
  4345. *
  4346. * //此时, range的各项属性为
  4347. * //output: B
  4348. * console.log( range.startContainer.tagName );
  4349. * //output: 2
  4350. * console.log( range.startOffset );
  4351. * //output: B
  4352. * console.log( range.endContainer.tagName );
  4353. * //output: 2
  4354. * console.log( range.endOffset );
  4355. * //output: true
  4356. * console.log( range.collapsed );
  4357. *
  4358. * </script>
  4359. * </body>
  4360. * ```
  4361. */
  4362. deleteContents:function () {
  4363. var txt;
  4364. if (!this.collapsed) {
  4365. execContentsAction(this, 1);
  4366. }
  4367. if (browser.webkit) {
  4368. txt = this.startContainer;
  4369. if (txt.nodeType == 3 && !txt.nodeValue.length) {
  4370. this.setStartBefore(txt).collapse(true);
  4371. domUtils.remove(txt);
  4372. }
  4373. }
  4374. return this;
  4375. },
  4376. /**
  4377. * 将当前选区的内容提取到一个DocumentFragment里
  4378. * @method extractContents
  4379. * @remind 执行该操作后, 选区将变成闭合状态
  4380. * @warning 执行该操作后, 原来选区所选中的内容将从dom树上剥离出来
  4381. * @return { DocumentFragment } 返回包含所提取内容的DocumentFragment对象
  4382. * @example
  4383. * ```html
  4384. * <body>
  4385. * <!-- 中括号表示选区 -->
  4386. * <b>x<i>x[x</i>xx]x</b>
  4387. *
  4388. * <script>
  4389. * //range是已选中的选区
  4390. * var fragment = range.extractContents(),
  4391. * node = document.createElement( "div" );
  4392. *
  4393. * node.appendChild( fragment );
  4394. *
  4395. * //竖线表示闭合后的选区位置
  4396. *
  4397. * //output: <b>x<i>x</i>|x</b>
  4398. * console.log( document.body.innerHTML );
  4399. * //output: <i>x</i>xx
  4400. * console.log( node.innerHTML );
  4401. *
  4402. * //此时, range的各项属性为
  4403. * //output: B
  4404. * console.log( range.startContainer.tagName );
  4405. * //output: 2
  4406. * console.log( range.startOffset );
  4407. * //output: B
  4408. * console.log( range.endContainer.tagName );
  4409. * //output: 2
  4410. * console.log( range.endOffset );
  4411. * //output: true
  4412. * console.log( range.collapsed );
  4413. *
  4414. * </script>
  4415. * </body>
  4416. */
  4417. extractContents:function () {
  4418. return this.collapsed ? null : execContentsAction(this, 2);
  4419. },
  4420. /**
  4421. * 设置Range的开始容器节点和偏移量
  4422. * @method setStart
  4423. * @remind 如果给定的节点是元素节点,那么offset指的是其子元素中索引为offset的元素,
  4424. * 如果是文本节点,那么offset指的是其文本内容的第offset个字符
  4425. * @remind 如果提供的容器节点是一个不能包含子元素的节点, 则该选区的开始容器将被设置
  4426. * 为该节点的父节点, 此时, 其距离开始容器的偏移量也变成了该节点在其父节点
  4427. * 中的索引
  4428. * @param { Node } node 将被设为当前选区开始边界容器的节点对象
  4429. * @param { int } offset 选区的开始位置偏移量
  4430. * @return { UE.dom.Range } 当前range对象
  4431. * @example
  4432. * ```html
  4433. * <!-- 选区 -->
  4434. * <b>xxx<i>x<span>xx</span>xx<em>xx</em>xxx</i>[xxx]</b>
  4435. *
  4436. * <script>
  4437. *
  4438. * //执行操作
  4439. * range.setStart( document.getElementsByTagName("i")[0], 1 );
  4440. *
  4441. * //此时, 选区变成了
  4442. * //<b>xxx<i>x[<span>xx</span>xx<em>xx</em>xxx</i>xxx]</b>
  4443. *
  4444. * </script>
  4445. * ```
  4446. * @example
  4447. * ```html
  4448. * <!-- 选区 -->
  4449. * <b>xxx<img>[xx]x</b>
  4450. *
  4451. * <script>
  4452. *
  4453. * //执行操作
  4454. * range.setStart( document.getElementsByTagName("img")[0], 3 );
  4455. *
  4456. * //此时, 选区变成了
  4457. * //<b>xxx[<img>xx]x</b>
  4458. *
  4459. * </script>
  4460. * ```
  4461. */
  4462. setStart:function (node, offset) {
  4463. return setEndPoint(true, node, offset, this);
  4464. },
  4465. /**
  4466. * 设置Range的结束容器和偏移量
  4467. * @method setEnd
  4468. * @param { Node } node 作为当前选区结束边界容器的节点对象
  4469. * @param { int } offset 结束边界的偏移量
  4470. * @see UE.dom.Range:setStart(Node,int)
  4471. * @return { UE.dom.Range } 当前range对象
  4472. */
  4473. setEnd:function (node, offset) {
  4474. return setEndPoint(false, node, offset, this);
  4475. },
  4476. /**
  4477. * 将Range开始位置设置到node节点之后
  4478. * @method setStartAfter
  4479. * @remind 该操作将会把给定节点的父节点作为range的开始容器, 且偏移量是该节点在其父节点中的位置索引+1
  4480. * @param { Node } node 选区的开始边界将紧接着该节点之后
  4481. * @return { UE.dom.Range } 当前range对象
  4482. * @example
  4483. * ```html
  4484. * <!-- 选区示例 -->
  4485. * <b>xx<i>xxx</i><span>xx[x</span>xxx]</b>
  4486. *
  4487. * <script>
  4488. *
  4489. * //执行操作
  4490. * range.setStartAfter( document.getElementsByTagName("i")[0] );
  4491. *
  4492. * //结果选区
  4493. * //<b>xx<i>xxx</i>[<span>xxx</span>xxx]</b>
  4494. *
  4495. * </script>
  4496. * ```
  4497. */
  4498. setStartAfter:function (node) {
  4499. return this.setStart(node.parentNode, domUtils.getNodeIndex(node) + 1);
  4500. },
  4501. /**
  4502. * 将Range开始位置设置到node节点之前
  4503. * @method setStartBefore
  4504. * @remind 该操作将会把给定节点的父节点作为range的开始容器, 且偏移量是该节点在其父节点中的位置索引
  4505. * @param { Node } node 新的选区开始位置在该节点之前
  4506. * @see UE.dom.Range:setStartAfter(Node)
  4507. * @return { UE.dom.Range } 当前range对象
  4508. */
  4509. setStartBefore:function (node) {
  4510. return this.setStart(node.parentNode, domUtils.getNodeIndex(node));
  4511. },
  4512. /**
  4513. * 将Range结束位置设置到node节点之后
  4514. * @method setEndAfter
  4515. * @remind 该操作将会把给定节点的父节点作为range的结束容器, 且偏移量是该节点在其父节点中的位置索引+1
  4516. * @param { Node } node 目标节点
  4517. * @see UE.dom.Range:setStartAfter(Node)
  4518. * @return { UE.dom.Range } 当前range对象
  4519. * @example
  4520. * ```html
  4521. * <!-- 选区示例 -->
  4522. * <b>[xx<i>xxx</i><span>xx]x</span>xxx</b>
  4523. *
  4524. * <script>
  4525. *
  4526. * //执行操作
  4527. * range.setStartAfter( document.getElementsByTagName("span")[0] );
  4528. *
  4529. * //结果选区
  4530. * //<b>[xx<i>xxx</i><span>xxx</span>]xxx</b>
  4531. *
  4532. * </script>
  4533. * ```
  4534. */
  4535. setEndAfter:function (node) {
  4536. return this.setEnd(node.parentNode, domUtils.getNodeIndex(node) + 1);
  4537. },
  4538. /**
  4539. * 将Range结束位置设置到node节点之前
  4540. * @method setEndBefore
  4541. * @remind 该操作将会把给定节点的父节点作为range的结束容器, 且偏移量是该节点在其父节点中的位置索引
  4542. * @param { Node } node 目标节点
  4543. * @see UE.dom.Range:setEndAfter(Node)
  4544. * @return { UE.dom.Range } 当前range对象
  4545. */
  4546. setEndBefore:function (node) {
  4547. return this.setEnd(node.parentNode, domUtils.getNodeIndex(node));
  4548. },
  4549. /**
  4550. * 设置Range的开始位置到node节点内的第一个子节点之前
  4551. * @method setStartAtFirst
  4552. * @remind 选区的开始容器将变成给定的节点, 且偏移量为0
  4553. * @remind 如果给定的节点是元素节点, 则该节点必须是允许包含子节点的元素。
  4554. * @param { Node } node 目标节点
  4555. * @see UE.dom.Range:setStartBefore(Node)
  4556. * @return { UE.dom.Range } 当前range对象
  4557. * @example
  4558. * ```html
  4559. * <!-- 选区示例 -->
  4560. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  4561. *
  4562. * <script>
  4563. *
  4564. * //执行操作
  4565. * range.setStartAtFirst( document.getElementsByTagName("i")[0] );
  4566. *
  4567. * //结果选区
  4568. * //<b>xx<i>[xxx</i><span>xx]x</span>xxx</b>
  4569. *
  4570. * </script>
  4571. * ```
  4572. */
  4573. setStartAtFirst:function (node) {
  4574. return this.setStart(node, 0);
  4575. },
  4576. /**
  4577. * 设置Range的开始位置到node节点内的最后一个节点之后
  4578. * @method setStartAtLast
  4579. * @remind 选区的开始容器将变成给定的节点, 且偏移量为该节点的子节点数
  4580. * @remind 如果给定的节点是元素节点, 则该节点必须是允许包含子节点的元素。
  4581. * @param { Node } node 目标节点
  4582. * @see UE.dom.Range:setStartAtFirst(Node)
  4583. * @return { UE.dom.Range } 当前range对象
  4584. */
  4585. setStartAtLast:function (node) {
  4586. return this.setStart(node, node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length);
  4587. },
  4588. /**
  4589. * 设置Range的结束位置到node节点内的第一个节点之前
  4590. * @method setEndAtFirst
  4591. * @param { Node } node 目标节点
  4592. * @remind 选区的结束容器将变成给定的节点, 且偏移量为0
  4593. * @remind node必须是一个元素节点, 且必须是允许包含子节点的元素。
  4594. * @see UE.dom.Range:setStartAtFirst(Node)
  4595. * @return { UE.dom.Range } 当前range对象
  4596. */
  4597. setEndAtFirst:function (node) {
  4598. return this.setEnd(node, 0);
  4599. },
  4600. /**
  4601. * 设置Range的结束位置到node节点内的最后一个节点之后
  4602. * @method setEndAtLast
  4603. * @param { Node } node 目标节点
  4604. * @remind 选区的结束容器将变成给定的节点, 且偏移量为该节点的子节点数量
  4605. * @remind node必须是一个元素节点, 且必须是允许包含子节点的元素。
  4606. * @see UE.dom.Range:setStartAtFirst(Node)
  4607. * @return { UE.dom.Range } 当前range对象
  4608. */
  4609. setEndAtLast:function (node) {
  4610. return this.setEnd(node, node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length);
  4611. },
  4612. /**
  4613. * 选中给定节点
  4614. * @method selectNode
  4615. * @remind 此时, 选区的开始容器和结束容器都是该节点的父节点, 其startOffset是该节点在父节点中的位置索引,
  4616. * 而endOffset为startOffset+1
  4617. * @param { Node } node 需要选中的节点
  4618. * @return { UE.dom.Range } 当前range对象,此时的range仅包含当前给定的节点对象
  4619. * @example
  4620. * ```html
  4621. * <!-- 选区示例 -->
  4622. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  4623. *
  4624. * <script>
  4625. *
  4626. * //执行操作
  4627. * range.selectNode( document.getElementsByTagName("i")[0] );
  4628. *
  4629. * //结果选区
  4630. * //<b>xx[<i>xxx</i>]<span>xxx</span>xxx</b>
  4631. *
  4632. * </script>
  4633. * ```
  4634. */
  4635. selectNode:function (node) {
  4636. return this.setStartBefore(node).setEndAfter(node);
  4637. },
  4638. /**
  4639. * 选中给定节点内部的所有节点
  4640. * @method selectNodeContents
  4641. * @remind 此时, 选区的开始容器和结束容器都是该节点, 其startOffset为0,
  4642. * 而endOffset是该节点的子节点数。
  4643. * @param { Node } node 目标节点, 当前range将包含该节点内的所有节点
  4644. * @return { UE.dom.Range } 当前range对象, 此时range仅包含给定节点的所有子节点
  4645. * @example
  4646. * ```html
  4647. * <!-- 选区示例 -->
  4648. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  4649. *
  4650. * <script>
  4651. *
  4652. * //执行操作
  4653. * range.selectNode( document.getElementsByTagName("b")[0] );
  4654. *
  4655. * //结果选区
  4656. * //<b>[xx<i>xxx</i><span>xxx</span>xxx]</b>
  4657. *
  4658. * </script>
  4659. * ```
  4660. */
  4661. selectNodeContents:function (node) {
  4662. return this.setStart(node, 0).setEndAtLast(node);
  4663. },
  4664. /**
  4665. * clone当前Range对象
  4666. * @method cloneRange
  4667. * @remind 返回的range是一个全新的range对象, 其内部所有属性与当前被clone的range相同。
  4668. * @return { UE.dom.Range } 当前range对象的一个副本
  4669. */
  4670. cloneRange:function () {
  4671. var me = this;
  4672. return new Range(me.document).setStart(me.startContainer, me.startOffset).setEnd(me.endContainer, me.endOffset);
  4673. },
  4674. /**
  4675. * 向当前选区的结束处闭合选区
  4676. * @method collapse
  4677. * @return { UE.dom.Range } 当前range对象
  4678. * @example
  4679. * ```html
  4680. * <!-- 选区示例 -->
  4681. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  4682. *
  4683. * <script>
  4684. *
  4685. * //执行操作
  4686. * range.collapse();
  4687. *
  4688. * //结果选区
  4689. * //“|”表示选区已闭合
  4690. * //<b>xx<i>xxx</i><span>xx|x</span>xxx</b>
  4691. *
  4692. * </script>
  4693. * ```
  4694. */
  4695. /**
  4696. * 闭合当前选区,根据给定的toStart参数项决定是向当前选区开始处闭合还是向结束处闭合,
  4697. * 如果toStart的值为true,则向开始位置闭合, 反之,向结束位置闭合。
  4698. * @method collapse
  4699. * @param { Boolean } toStart 是否向选区开始处闭合
  4700. * @return { UE.dom.Range } 当前range对象,此时range对象处于闭合状态
  4701. * @see UE.dom.Range:collapse()
  4702. * @example
  4703. * ```html
  4704. * <!-- 选区示例 -->
  4705. * <b>xx<i>xxx</i><span>[xx]x</span>xxx</b>
  4706. *
  4707. * <script>
  4708. *
  4709. * //执行操作
  4710. * range.collapse( true );
  4711. *
  4712. * //结果选区
  4713. * //“|”表示选区已闭合
  4714. * //<b>xx<i>xxx</i><span>|xxx</span>xxx</b>
  4715. *
  4716. * </script>
  4717. * ```
  4718. */
  4719. collapse:function (toStart) {
  4720. var me = this;
  4721. if (toStart) {
  4722. me.endContainer = me.startContainer;
  4723. me.endOffset = me.startOffset;
  4724. } else {
  4725. me.startContainer = me.endContainer;
  4726. me.startOffset = me.endOffset;
  4727. }
  4728. me.collapsed = true;
  4729. return me;
  4730. },
  4731. /**
  4732. * 调整range的开始位置和结束位置,使其"收缩"到最小的位置
  4733. * @method shrinkBoundary
  4734. * @return { UE.dom.Range } 当前range对象
  4735. * @example
  4736. * ```html
  4737. * <span>xx<b>xx[</b>xxxxx]</span> => <span>xx<b>xx</b>[xxxxx]</span>
  4738. * ```
  4739. *
  4740. * @example
  4741. * ```html
  4742. * <!-- 选区示例 -->
  4743. * <b>x[xx</b><i>]xxx</i>
  4744. *
  4745. * <script>
  4746. *
  4747. * //执行收缩
  4748. * range.shrinkBoundary();
  4749. *
  4750. * //结果选区
  4751. * //<b>x[xx]</b><i>xxx</i>
  4752. * </script>
  4753. * ```
  4754. *
  4755. * @example
  4756. * ```html
  4757. * [<b><i>xxxx</i>xxxxxxx</b>] => <b><i>[xxxx</i>xxxxxxx]</b>
  4758. * ```
  4759. */
  4760. /**
  4761. * 调整range的开始位置和结束位置,使其"收缩"到最小的位置,
  4762. * 如果ignoreEnd的值为true,则忽略对结束位置的调整
  4763. * @method shrinkBoundary
  4764. * @param { Boolean } ignoreEnd 是否忽略对结束位置的调整
  4765. * @return { UE.dom.Range } 当前range对象
  4766. * @see UE.dom.domUtils.Range:shrinkBoundary()
  4767. */
  4768. shrinkBoundary:function (ignoreEnd) {
  4769. var me = this, child,
  4770. collapsed = me.collapsed;
  4771. function check(node){
  4772. return node.nodeType == 1 && !domUtils.isBookmarkNode(node) && !dtd.$empty[node.tagName] && !dtd.$nonChild[node.tagName]
  4773. }
  4774. while (me.startContainer.nodeType == 1 //是element
  4775. && (child = me.startContainer.childNodes[me.startOffset]) //子节点也是element
  4776. && check(child)) {
  4777. me.setStart(child, 0);
  4778. }
  4779. if (collapsed) {
  4780. return me.collapse(true);
  4781. }
  4782. if (!ignoreEnd) {
  4783. while (me.endContainer.nodeType == 1//是element
  4784. && me.endOffset > 0 //如果是空元素就退出 endOffset=0那么endOffst-1为负值,childNodes[endOffset]报错
  4785. && (child = me.endContainer.childNodes[me.endOffset - 1]) //子节点也是element
  4786. && check(child)) {
  4787. me.setEnd(child, child.childNodes.length);
  4788. }
  4789. }
  4790. return me;
  4791. },
  4792. /**
  4793. * 获取离当前选区内包含的所有节点最近的公共祖先节点,
  4794. * @method getCommonAncestor
  4795. * @remind 返回的公共祖先节点一定不是range自身的容器节点, 但有可能是一个文本节点
  4796. * @return { Node } 当前range对象内所有节点的公共祖先节点
  4797. * @example
  4798. * ```html
  4799. * //选区示例
  4800. * <span>xxx<b>x[x<em>xx]x</em>xxx</b>xx</span>
  4801. * <script>
  4802. *
  4803. * var node = range.getCommonAncestor();
  4804. *
  4805. * //公共祖先节点是: b节点
  4806. * //输出: B
  4807. * console.log(node.tagName);
  4808. *
  4809. * </script>
  4810. * ```
  4811. */
  4812. /**
  4813. * 获取当前选区所包含的所有节点的公共祖先节点, 可以根据给定的参数 includeSelf 决定获取到
  4814. * 的公共祖先节点是否可以是当前选区的startContainer或endContainer节点, 如果 includeSelf
  4815. * 的取值为true, 则返回的节点可以是自身的容器节点, 否则, 则不能是容器节点
  4816. * @method getCommonAncestor
  4817. * @param { Boolean } includeSelf 是否允许获取到的公共祖先节点是当前range对象的容器节点
  4818. * @return { Node } 当前range对象内所有节点的公共祖先节点
  4819. * @see UE.dom.Range:getCommonAncestor()
  4820. * @example
  4821. * ```html
  4822. * <body>
  4823. *
  4824. * <!-- 选区示例 -->
  4825. * <b>xxx<i>xxxx<span>xx[x</span>xx]x</i>xxxxxxx</b>
  4826. *
  4827. * <script>
  4828. *
  4829. * var node = range.getCommonAncestor( false );
  4830. *
  4831. * //这里的公共祖先节点是B而不是I, 是因为参数限制了获取到的节点不能是容器节点
  4832. * //output: B
  4833. * console.log( node.tagName );
  4834. *
  4835. * </script>
  4836. *
  4837. * </body>
  4838. * ```
  4839. */
  4840. /**
  4841. * 获取当前选区所包含的所有节点的公共祖先节点, 可以根据给定的参数 includeSelf 决定获取到
  4842. * 的公共祖先节点是否可以是当前选区的startContainer或endContainer节点, 如果 includeSelf
  4843. * 的取值为true, 则返回的节点可以是自身的容器节点, 否则, 则不能是容器节点; 同时可以根据
  4844. * ignoreTextNode 参数的取值决定是否忽略类型为文本节点的祖先节点。
  4845. * @method getCommonAncestor
  4846. * @param { Boolean } includeSelf 是否允许获取到的公共祖先节点是当前range对象的容器节点
  4847. * @param { Boolean } ignoreTextNode 获取祖先节点的过程中是否忽略类型为文本节点的祖先节点
  4848. * @return { Node } 当前range对象内所有节点的公共祖先节点
  4849. * @see UE.dom.Range:getCommonAncestor()
  4850. * @see UE.dom.Range:getCommonAncestor(Boolean)
  4851. * @example
  4852. * ```html
  4853. * <body>
  4854. *
  4855. * <!-- 选区示例 -->
  4856. * <b>xxx<i>xxxx<span>x[x]x</span>xxx</i>xxxxxxx</b>
  4857. *
  4858. * <script>
  4859. *
  4860. * var node = range.getCommonAncestor( true, false );
  4861. *
  4862. * //output: SPAN
  4863. * console.log( node.tagName );
  4864. *
  4865. * </script>
  4866. *
  4867. * </body>
  4868. * ```
  4869. */
  4870. getCommonAncestor:function (includeSelf, ignoreTextNode) {
  4871. var me = this,
  4872. start = me.startContainer,
  4873. end = me.endContainer;
  4874. if (start === end) {
  4875. if (includeSelf && selectOneNode(this)) {
  4876. start = start.childNodes[me.startOffset];
  4877. if(start.nodeType == 1)
  4878. return start;
  4879. }
  4880. //只有在上来就相等的情况下才会出现是文本的情况
  4881. return ignoreTextNode && start.nodeType == 3 ? start.parentNode : start;
  4882. }
  4883. return domUtils.getCommonAncestor(start, end);
  4884. },
  4885. /**
  4886. * 调整当前Range的开始和结束边界容器,如果是容器节点是文本节点,就调整到包含该文本节点的父节点上
  4887. * @method trimBoundary
  4888. * @remind 该操作有可能会引起文本节点被切开
  4889. * @return { UE.dom.Range } 当前range对象
  4890. * @example
  4891. * ```html
  4892. *
  4893. * //选区示例
  4894. * <b>xxx<i>[xxxxx]</i>xxx</b>
  4895. *
  4896. * <script>
  4897. * //未调整前, 选区的开始容器和结束都是文本节点
  4898. * //执行调整
  4899. * range.trimBoundary();
  4900. *
  4901. * //调整之后, 容器节点变成了i节点
  4902. * //<b>xxx[<i>xxxxx</i>]xxx</b>
  4903. * </script>
  4904. * ```
  4905. */
  4906. /**
  4907. * 调整当前Range的开始和结束边界容器,如果是容器节点是文本节点,就调整到包含该文本节点的父节点上,
  4908. * 可以根据 ignoreEnd 参数的值决定是否调整对结束边界的调整
  4909. * @method trimBoundary
  4910. * @param { Boolean } ignoreEnd 是否忽略对结束边界的调整
  4911. * @return { UE.dom.Range } 当前range对象
  4912. * @example
  4913. * ```html
  4914. *
  4915. * //选区示例
  4916. * <b>xxx<i>[xxxxx]</i>xxx</b>
  4917. *
  4918. * <script>
  4919. * //未调整前, 选区的开始容器和结束都是文本节点
  4920. * //执行调整
  4921. * range.trimBoundary( true );
  4922. *
  4923. * //调整之后, 开始容器节点变成了i节点
  4924. * //但是, 结束容器没有发生变化
  4925. * //<b>xxx[<i>xxxxx]</i>xxx</b>
  4926. * </script>
  4927. * ```
  4928. */
  4929. trimBoundary:function (ignoreEnd) {
  4930. this.txtToElmBoundary();
  4931. var start = this.startContainer,
  4932. offset = this.startOffset,
  4933. collapsed = this.collapsed,
  4934. end = this.endContainer;
  4935. if (start.nodeType == 3) {
  4936. if (offset == 0) {
  4937. this.setStartBefore(start);
  4938. } else {
  4939. if (offset >= start.nodeValue.length) {
  4940. this.setStartAfter(start);
  4941. } else {
  4942. var textNode = domUtils.split(start, offset);
  4943. //跟新结束边界
  4944. if (start === end) {
  4945. this.setEnd(textNode, this.endOffset - offset);
  4946. } else if (start.parentNode === end) {
  4947. this.endOffset += 1;
  4948. }
  4949. this.setStartBefore(textNode);
  4950. }
  4951. }
  4952. if (collapsed) {
  4953. return this.collapse(true);
  4954. }
  4955. }
  4956. if (!ignoreEnd) {
  4957. offset = this.endOffset;
  4958. end = this.endContainer;
  4959. if (end.nodeType == 3) {
  4960. if (offset == 0) {
  4961. this.setEndBefore(end);
  4962. } else {
  4963. offset < end.nodeValue.length && domUtils.split(end, offset);
  4964. this.setEndAfter(end);
  4965. }
  4966. }
  4967. }
  4968. return this;
  4969. },
  4970. /**
  4971. * 如果选区在文本的边界上,就扩展选区到文本的父节点上, 如果当前选区是闭合的, 则什么也不做
  4972. * @method txtToElmBoundary
  4973. * @remind 该操作不会修改dom节点
  4974. * @return { UE.dom.Range } 当前range对象
  4975. */
  4976. /**
  4977. * 如果选区在文本的边界上,就扩展选区到文本的父节点上, 如果当前选区是闭合的, 则根据参数项
  4978. * ignoreCollapsed 的值决定是否执行该调整
  4979. * @method txtToElmBoundary
  4980. * @param { Boolean } ignoreCollapsed 是否忽略选区的闭合状态, 如果该参数取值为true, 则
  4981. * 不论选区是否闭合, 都会执行该操作, 反之, 则不会对闭合的选区执行该操作
  4982. * @return { UE.dom.Range } 当前range对象
  4983. */
  4984. txtToElmBoundary:function (ignoreCollapsed) {
  4985. function adjust(r, c) {
  4986. var container = r[c + 'Container'],
  4987. offset = r[c + 'Offset'];
  4988. if (container.nodeType == 3) {
  4989. if (!offset) {
  4990. r['set' + c.replace(/(\w)/, function (a) {
  4991. return a.toUpperCase();
  4992. }) + 'Before'](container);
  4993. } else if (offset >= container.nodeValue.length) {
  4994. r['set' + c.replace(/(\w)/, function (a) {
  4995. return a.toUpperCase();
  4996. }) + 'After' ](container);
  4997. }
  4998. }
  4999. }
  5000. if (ignoreCollapsed || !this.collapsed) {
  5001. adjust(this, 'start');
  5002. adjust(this, 'end');
  5003. }
  5004. return this;
  5005. },
  5006. /**
  5007. * 在当前选区的开始位置前插入节点,新插入的节点会被该range包含
  5008. * @method insertNode
  5009. * @param { Node } node 需要插入的节点
  5010. * @remind 插入的节点可以是一个DocumentFragment依次插入多个节点
  5011. * @return { UE.dom.Range } 当前range对象
  5012. */
  5013. insertNode:function (node) {
  5014. var first = node, length = 1;
  5015. if (node.nodeType == 11) {
  5016. first = node.firstChild;
  5017. length = node.childNodes.length;
  5018. }
  5019. this.trimBoundary(true);
  5020. var start = this.startContainer,
  5021. offset = this.startOffset;
  5022. var nextNode = start.childNodes[ offset ];
  5023. if (nextNode) {
  5024. start.insertBefore(node, nextNode);
  5025. } else {
  5026. start.appendChild(node);
  5027. }
  5028. if (first.parentNode === this.endContainer) {
  5029. this.endOffset = this.endOffset + length;
  5030. }
  5031. return this.setStartBefore(first);
  5032. },
  5033. /**
  5034. * 闭合选区到当前选区的开始位置, 并且定位光标到闭合后的位置
  5035. * @method setCursor
  5036. * @return { UE.dom.Range } 当前range对象
  5037. * @see UE.dom.Range:collapse()
  5038. */
  5039. /**
  5040. * 闭合选区,可以根据参数toEnd的值控制选区是向前闭合还是向后闭合, 并且定位光标到闭合后的位置。
  5041. * @method setCursor
  5042. * @param { Boolean } toEnd 是否向后闭合, 如果为true, 则闭合选区时, 将向结束容器方向闭合,
  5043. * 反之,则向开始容器方向闭合
  5044. * @return { UE.dom.Range } 当前range对象
  5045. * @see UE.dom.Range:collapse(Boolean)
  5046. */
  5047. setCursor:function (toEnd, noFillData) {
  5048. return this.collapse(!toEnd).select(noFillData);
  5049. },
  5050. /**
  5051. * 创建当前range的一个书签,记录下当前range的位置,方便当dom树改变时,还能找回原来的选区位置
  5052. * @method createBookmark
  5053. * @param { Boolean } serialize 控制返回的标记位置是对当前位置的引用还是ID,如果该值为true,则
  5054. * 返回标记位置的ID, 反之则返回标记位置节点的引用
  5055. * @return { Object } 返回一个书签记录键值对, 其包含的key有: start => 开始标记的ID或者引用,
  5056. * end => 结束标记的ID或引用, id => 当前标记的类型, 如果为true,则表示
  5057. * 返回的记录的类型为ID, 反之则为引用
  5058. */
  5059. createBookmark:function (serialize, same) {
  5060. var endNode,
  5061. startNode = this.document.createElement('span');
  5062. startNode.style.cssText = 'display:none;line-height:0px;';
  5063. startNode.appendChild(this.document.createTextNode('\u200D'));
  5064. startNode.id = '_baidu_bookmark_start_' + (same ? '' : guid++);
  5065. if (!this.collapsed) {
  5066. endNode = startNode.cloneNode(true);
  5067. endNode.id = '_baidu_bookmark_end_' + (same ? '' : guid++);
  5068. }
  5069. this.insertNode(startNode);
  5070. if (endNode) {
  5071. this.collapse().insertNode(endNode).setEndBefore(endNode);
  5072. }
  5073. this.setStartAfter(startNode);
  5074. return {
  5075. start:serialize ? startNode.id : startNode,
  5076. end:endNode ? serialize ? endNode.id : endNode : null,
  5077. id:serialize
  5078. }
  5079. },
  5080. /**
  5081. * 调整当前range的边界到书签位置,并删除该书签对象所标记的位置内的节点
  5082. * @method moveToBookmark
  5083. * @param { BookMark } bookmark createBookmark所创建的标签对象
  5084. * @return { UE.dom.Range } 当前range对象
  5085. * @see UE.dom.Range:createBookmark(Boolean)
  5086. */
  5087. moveToBookmark:function (bookmark) {
  5088. var start = bookmark.id ? this.document.getElementById(bookmark.start) : bookmark.start,
  5089. end = bookmark.end && bookmark.id ? this.document.getElementById(bookmark.end) : bookmark.end;
  5090. this.setStartBefore(start);
  5091. domUtils.remove(start);
  5092. if (end) {
  5093. this.setEndBefore(end);
  5094. domUtils.remove(end);
  5095. } else {
  5096. this.collapse(true);
  5097. }
  5098. return this;
  5099. },
  5100. /**
  5101. * 调整range的边界,使其"放大"到最近的父节点
  5102. * @method enlarge
  5103. * @remind 会引起选区的变化
  5104. * @return { UE.dom.Range } 当前range对象
  5105. */
  5106. /**
  5107. * 调整range的边界,使其"放大"到最近的父节点,根据参数 toBlock 的取值, 可以
  5108. * 要求扩大之后的父节点是block节点
  5109. * @method enlarge
  5110. * @param { Boolean } toBlock 是否要求扩大之后的父节点必须是block节点
  5111. * @return { UE.dom.Range } 当前range对象
  5112. */
  5113. enlarge:function (toBlock, stopFn) {
  5114. var isBody = domUtils.isBody,
  5115. pre, node, tmp = this.document.createTextNode('');
  5116. if (toBlock) {
  5117. node = this.startContainer;
  5118. if (node.nodeType == 1) {
  5119. if (node.childNodes[this.startOffset]) {
  5120. pre = node = node.childNodes[this.startOffset]
  5121. } else {
  5122. node.appendChild(tmp);
  5123. pre = node = tmp;
  5124. }
  5125. } else {
  5126. pre = node;
  5127. }
  5128. while (1) {
  5129. if (domUtils.isBlockElm(node)) {
  5130. node = pre;
  5131. while ((pre = node.previousSibling) && !domUtils.isBlockElm(pre)) {
  5132. node = pre;
  5133. }
  5134. this.setStartBefore(node);
  5135. break;
  5136. }
  5137. pre = node;
  5138. node = node.parentNode;
  5139. }
  5140. node = this.endContainer;
  5141. if (node.nodeType == 1) {
  5142. if (pre = node.childNodes[this.endOffset]) {
  5143. node.insertBefore(tmp, pre);
  5144. } else {
  5145. node.appendChild(tmp);
  5146. }
  5147. pre = node = tmp;
  5148. } else {
  5149. pre = node;
  5150. }
  5151. while (1) {
  5152. if (domUtils.isBlockElm(node)) {
  5153. node = pre;
  5154. while ((pre = node.nextSibling) && !domUtils.isBlockElm(pre)) {
  5155. node = pre;
  5156. }
  5157. this.setEndAfter(node);
  5158. break;
  5159. }
  5160. pre = node;
  5161. node = node.parentNode;
  5162. }
  5163. if (tmp.parentNode === this.endContainer) {
  5164. this.endOffset--;
  5165. }
  5166. domUtils.remove(tmp);
  5167. }
  5168. // 扩展边界到最大
  5169. if (!this.collapsed) {
  5170. while (this.startOffset == 0) {
  5171. if (stopFn && stopFn(this.startContainer)) {
  5172. break;
  5173. }
  5174. if (isBody(this.startContainer)) {
  5175. break;
  5176. }
  5177. this.setStartBefore(this.startContainer);
  5178. }
  5179. while (this.endOffset == (this.endContainer.nodeType == 1 ? this.endContainer.childNodes.length : this.endContainer.nodeValue.length)) {
  5180. if (stopFn && stopFn(this.endContainer)) {
  5181. break;
  5182. }
  5183. if (isBody(this.endContainer)) {
  5184. break;
  5185. }
  5186. this.setEndAfter(this.endContainer);
  5187. }
  5188. }
  5189. return this;
  5190. },
  5191. enlargeToBlockElm:function(ignoreEnd){
  5192. while(!domUtils.isBlockElm(this.startContainer)){
  5193. this.setStartBefore(this.startContainer);
  5194. }
  5195. if(!ignoreEnd){
  5196. while(!domUtils.isBlockElm(this.endContainer)){
  5197. this.setEndAfter(this.endContainer);
  5198. }
  5199. }
  5200. return this;
  5201. },
  5202. /**
  5203. * 调整Range的边界,使其"缩小"到最合适的位置
  5204. * @method adjustmentBoundary
  5205. * @return { UE.dom.Range } 当前range对象
  5206. * @see UE.dom.Range:shrinkBoundary()
  5207. */
  5208. adjustmentBoundary:function () {
  5209. if (!this.collapsed) {
  5210. while (!domUtils.isBody(this.startContainer) &&
  5211. this.startOffset == this.startContainer[this.startContainer.nodeType == 3 ? 'nodeValue' : 'childNodes'].length &&
  5212. this.startContainer[this.startContainer.nodeType == 3 ? 'nodeValue' : 'childNodes'].length
  5213. ) {
  5214. this.setStartAfter(this.startContainer);
  5215. }
  5216. while (!domUtils.isBody(this.endContainer) && !this.endOffset &&
  5217. this.endContainer[this.endContainer.nodeType == 3 ? 'nodeValue' : 'childNodes'].length
  5218. ) {
  5219. this.setEndBefore(this.endContainer);
  5220. }
  5221. }
  5222. return this;
  5223. },
  5224. /**
  5225. * 给range选区中的内容添加给定的inline标签
  5226. * @method applyInlineStyle
  5227. * @param { String } tagName 需要添加的标签名
  5228. * @example
  5229. * ```html
  5230. * <p>xxxx[xxxx]x</p> ==> range.applyInlineStyle("strong") ==> <p>xxxx[<strong>xxxx</strong>]x</p>
  5231. * ```
  5232. */
  5233. /**
  5234. * 给range选区中的内容添加给定的inline标签, 并且为标签附加上一些初始化属性。
  5235. * @method applyInlineStyle
  5236. * @param { String } tagName 需要添加的标签名
  5237. * @param { Object } attrs 跟随新添加的标签的属性
  5238. * @return { UE.dom.Range } 当前选区
  5239. * @example
  5240. * ```html
  5241. * <p>xxxx[xxxx]x</p>
  5242. *
  5243. * ==>
  5244. *
  5245. * <!-- 执行操作 -->
  5246. * range.applyInlineStyle("strong",{"style":"font-size:12px"})
  5247. *
  5248. * ==>
  5249. *
  5250. * <p>xxxx[<strong style="font-size:12px">xxxx</strong>]x</p>
  5251. * ```
  5252. */
  5253. applyInlineStyle:function (tagName, attrs, list) {
  5254. if (this.collapsed)return this;
  5255. this.trimBoundary().enlarge(false,
  5256. function (node) {
  5257. return node.nodeType == 1 && domUtils.isBlockElm(node)
  5258. }).adjustmentBoundary();
  5259. var bookmark = this.createBookmark(),
  5260. end = bookmark.end,
  5261. filterFn = function (node) {
  5262. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' : !domUtils.isWhitespace(node);
  5263. },
  5264. current = domUtils.getNextDomNode(bookmark.start, false, filterFn),
  5265. node,
  5266. pre,
  5267. range = this.cloneRange();
  5268. while (current && (domUtils.getPosition(current, end) & domUtils.POSITION_PRECEDING)) {
  5269. if (current.nodeType == 3 || dtd[tagName][current.tagName]) {
  5270. range.setStartBefore(current);
  5271. node = current;
  5272. while (node && (node.nodeType == 3 || dtd[tagName][node.tagName]) && node !== end) {
  5273. pre = node;
  5274. node = domUtils.getNextDomNode(node, node.nodeType == 1, null, function (parent) {
  5275. return dtd[tagName][parent.tagName];
  5276. });
  5277. }
  5278. var frag = range.setEndAfter(pre).extractContents(), elm;
  5279. if (list && list.length > 0) {
  5280. var level, top;
  5281. top = level = list[0].cloneNode(false);
  5282. for (var i = 1, ci; ci = list[i++];) {
  5283. level.appendChild(ci.cloneNode(false));
  5284. level = level.firstChild;
  5285. }
  5286. elm = level;
  5287. } else {
  5288. elm = range.document.createElement(tagName);
  5289. }
  5290. if (attrs) {
  5291. domUtils.setAttributes(elm, attrs);
  5292. }
  5293. elm.appendChild(frag);
  5294. range.insertNode(list ? top : elm);
  5295. //处理下滑线在a上的情况
  5296. var aNode;
  5297. if (tagName == 'span' && attrs.style && /text\-decoration/.test(attrs.style) && (aNode = domUtils.findParentByTagName(elm, 'a', true))) {
  5298. domUtils.setAttributes(aNode, attrs);
  5299. domUtils.remove(elm, true);
  5300. elm = aNode;
  5301. } else {
  5302. domUtils.mergeSibling(elm);
  5303. domUtils.clearEmptySibling(elm);
  5304. }
  5305. //去除子节点相同的
  5306. domUtils.mergeChild(elm, attrs);
  5307. current = domUtils.getNextDomNode(elm, false, filterFn);
  5308. domUtils.mergeToParent(elm);
  5309. if (node === end) {
  5310. break;
  5311. }
  5312. } else {
  5313. current = domUtils.getNextDomNode(current, true, filterFn);
  5314. }
  5315. }
  5316. return this.moveToBookmark(bookmark);
  5317. },
  5318. /**
  5319. * 移除当前选区内指定的inline标签,但保留其中的内容
  5320. * @method removeInlineStyle
  5321. * @param { String } tagName 需要移除的标签名
  5322. * @return { UE.dom.Range } 当前的range对象
  5323. * @example
  5324. * ```html
  5325. * xx[x<span>xxx<em>yyy</em>zz]z</span> => range.removeInlineStyle(["em"]) => xx[x<span>xxxyyyzz]z</span>
  5326. * ```
  5327. */
  5328. /**
  5329. * 移除当前选区内指定的一组inline标签,但保留其中的内容
  5330. * @method removeInlineStyle
  5331. * @param { Array } tagNameArr 需要移除的标签名的数组
  5332. * @return { UE.dom.Range } 当前的range对象
  5333. * @see UE.dom.Range:removeInlineStyle(String)
  5334. */
  5335. removeInlineStyle:function (tagNames) {
  5336. if (this.collapsed)return this;
  5337. tagNames = utils.isArray(tagNames) ? tagNames : [tagNames];
  5338. this.shrinkBoundary().adjustmentBoundary();
  5339. var start = this.startContainer, end = this.endContainer;
  5340. while (1) {
  5341. if (start.nodeType == 1) {
  5342. if (utils.indexOf(tagNames, start.tagName.toLowerCase()) > -1) {
  5343. break;
  5344. }
  5345. if (start.tagName.toLowerCase() == 'body') {
  5346. start = null;
  5347. break;
  5348. }
  5349. }
  5350. start = start.parentNode;
  5351. }
  5352. while (1) {
  5353. if (end.nodeType == 1) {
  5354. if (utils.indexOf(tagNames, end.tagName.toLowerCase()) > -1) {
  5355. break;
  5356. }
  5357. if (end.tagName.toLowerCase() == 'body') {
  5358. end = null;
  5359. break;
  5360. }
  5361. }
  5362. end = end.parentNode;
  5363. }
  5364. var bookmark = this.createBookmark(),
  5365. frag,
  5366. tmpRange;
  5367. if (start) {
  5368. tmpRange = this.cloneRange().setEndBefore(bookmark.start).setStartBefore(start);
  5369. frag = tmpRange.extractContents();
  5370. tmpRange.insertNode(frag);
  5371. domUtils.clearEmptySibling(start, true);
  5372. start.parentNode.insertBefore(bookmark.start, start);
  5373. }
  5374. if (end) {
  5375. tmpRange = this.cloneRange().setStartAfter(bookmark.end).setEndAfter(end);
  5376. frag = tmpRange.extractContents();
  5377. tmpRange.insertNode(frag);
  5378. domUtils.clearEmptySibling(end, false, true);
  5379. end.parentNode.insertBefore(bookmark.end, end.nextSibling);
  5380. }
  5381. var current = domUtils.getNextDomNode(bookmark.start, false, function (node) {
  5382. return node.nodeType == 1;
  5383. }), next;
  5384. while (current && current !== bookmark.end) {
  5385. next = domUtils.getNextDomNode(current, true, function (node) {
  5386. return node.nodeType == 1;
  5387. });
  5388. if (utils.indexOf(tagNames, current.tagName.toLowerCase()) > -1) {
  5389. domUtils.remove(current, true);
  5390. }
  5391. current = next;
  5392. }
  5393. return this.moveToBookmark(bookmark);
  5394. },
  5395. /**
  5396. * 获取当前选中的自闭合的节点
  5397. * @method getClosedNode
  5398. * @return { Node | NULL } 如果当前选中的是自闭合节点, 则返回该节点, 否则返回NULL
  5399. */
  5400. getClosedNode:function () {
  5401. var node;
  5402. if (!this.collapsed) {
  5403. var range = this.cloneRange().adjustmentBoundary().shrinkBoundary();
  5404. if (selectOneNode(range)) {
  5405. var child = range.startContainer.childNodes[range.startOffset];
  5406. if (child && child.nodeType == 1 && (dtd.$empty[child.tagName] || dtd.$nonChild[child.tagName])) {
  5407. node = child;
  5408. }
  5409. }
  5410. }
  5411. return node;
  5412. },
  5413. /**
  5414. * 在页面上高亮range所表示的选区
  5415. * @method select
  5416. * @return { UE.dom.Range } 返回当前Range对象
  5417. */
  5418. //这里不区分ie9以上,trace:3824
  5419. select:browser.ie ? function (noFillData, textRange) {
  5420. var nativeRange;
  5421. if (!this.collapsed)
  5422. this.shrinkBoundary();
  5423. var node = this.getClosedNode();
  5424. if (node && !textRange) {
  5425. try {
  5426. nativeRange = this.document.body.createControlRange();
  5427. nativeRange.addElement(node);
  5428. nativeRange.select();
  5429. } catch (e) {}
  5430. return this;
  5431. }
  5432. var bookmark = this.createBookmark(),
  5433. start = bookmark.start,
  5434. end;
  5435. nativeRange = this.document.body.createTextRange();
  5436. nativeRange.moveToElementText(start);
  5437. nativeRange.moveStart('character', 1);
  5438. if (!this.collapsed) {
  5439. var nativeRangeEnd = this.document.body.createTextRange();
  5440. end = bookmark.end;
  5441. nativeRangeEnd.moveToElementText(end);
  5442. nativeRange.setEndPoint('EndToEnd', nativeRangeEnd);
  5443. } else {
  5444. if (!noFillData && this.startContainer.nodeType != 3) {
  5445. //使用<span>|x<span>固定住光标
  5446. var tmpText = this.document.createTextNode(fillChar),
  5447. tmp = this.document.createElement('span');
  5448. tmp.appendChild(this.document.createTextNode(fillChar));
  5449. start.parentNode.insertBefore(tmp, start);
  5450. start.parentNode.insertBefore(tmpText, start);
  5451. //当点b,i,u时,不能清除i上边的b
  5452. removeFillData(this.document, tmpText);
  5453. fillData = tmpText;
  5454. mergeSibling(tmp, 'previousSibling');
  5455. mergeSibling(start, 'nextSibling');
  5456. nativeRange.moveStart('character', -1);
  5457. nativeRange.collapse(true);
  5458. }
  5459. }
  5460. this.moveToBookmark(bookmark);
  5461. tmp && domUtils.remove(tmp);
  5462. //IE在隐藏状态下不支持range操作,catch一下
  5463. try {
  5464. nativeRange.select();
  5465. } catch (e) {
  5466. }
  5467. return this;
  5468. } : function (notInsertFillData) {
  5469. function checkOffset(rng){
  5470. function check(node,offset,dir){
  5471. if(node.nodeType == 3 && node.nodeValue.length < offset){
  5472. rng[dir + 'Offset'] = node.nodeValue.length
  5473. }
  5474. }
  5475. check(rng.startContainer,rng.startOffset,'start');
  5476. check(rng.endContainer,rng.endOffset,'end');
  5477. }
  5478. var win = domUtils.getWindow(this.document),
  5479. sel = win.getSelection(),
  5480. txtNode;
  5481. //FF下关闭自动长高时滚动条在关闭dialog时会跳
  5482. //ff下如果不body.focus将不能定位闭合光标到编辑器内
  5483. browser.gecko ? this.document.body.focus() : win.focus();
  5484. if (sel) {
  5485. sel.removeAllRanges();
  5486. // trace:870 chrome/safari后边是br对于闭合得range不能定位 所以去掉了判断
  5487. // this.startContainer.nodeType != 3 &&! ((child = this.startContainer.childNodes[this.startOffset]) && child.nodeType == 1 && child.tagName == 'BR'
  5488. if (this.collapsed && !notInsertFillData) {
  5489. // //opear如果没有节点接着,原生的不能够定位,不能在body的第一级插入空白节点
  5490. // if (notInsertFillData && browser.opera && !domUtils.isBody(this.startContainer) && this.startContainer.nodeType == 1) {
  5491. // var tmp = this.document.createTextNode('');
  5492. // this.insertNode(tmp).setStart(tmp, 0).collapse(true);
  5493. // }
  5494. //
  5495. //处理光标落在文本节点的情况
  5496. //处理以下的情况
  5497. //<b>|xxxx</b>
  5498. //<b>xxxx</b>|xxxx
  5499. //xxxx<b>|</b>
  5500. var start = this.startContainer,child = start;
  5501. if(start.nodeType == 1){
  5502. child = start.childNodes[this.startOffset];
  5503. }
  5504. if( !(start.nodeType == 3 && this.startOffset) &&
  5505. (child ?
  5506. (!child.previousSibling || child.previousSibling.nodeType != 3)
  5507. :
  5508. (!start.lastChild || start.lastChild.nodeType != 3)
  5509. )
  5510. ){
  5511. txtNode = this.document.createTextNode(fillChar);
  5512. //跟着前边走
  5513. this.insertNode(txtNode);
  5514. removeFillData(this.document, txtNode);
  5515. mergeSibling(txtNode, 'previousSibling');
  5516. mergeSibling(txtNode, 'nextSibling');
  5517. fillData = txtNode;
  5518. this.setStart(txtNode, browser.webkit ? 1 : 0).collapse(true);
  5519. }
  5520. }
  5521. var nativeRange = this.document.createRange();
  5522. if(this.collapsed && browser.opera && this.startContainer.nodeType == 1){
  5523. var child = this.startContainer.childNodes[this.startOffset];
  5524. if(!child){
  5525. //往前靠拢
  5526. child = this.startContainer.lastChild;
  5527. if( child && domUtils.isBr(child)){
  5528. this.setStartBefore(child).collapse(true);
  5529. }
  5530. }else{
  5531. //向后靠拢
  5532. while(child && domUtils.isBlockElm(child)){
  5533. if(child.nodeType == 1 && child.childNodes[0]){
  5534. child = child.childNodes[0]
  5535. }else{
  5536. break;
  5537. }
  5538. }
  5539. child && this.setStartBefore(child).collapse(true)
  5540. }
  5541. }
  5542. //是createAddress最后一位算的不准,现在这里进行微调
  5543. checkOffset(this);
  5544. nativeRange.setStart(this.startContainer, this.startOffset);
  5545. nativeRange.setEnd(this.endContainer, this.endOffset);
  5546. sel.addRange(nativeRange);
  5547. }
  5548. return this;
  5549. },
  5550. /**
  5551. * 滚动到当前range开始的位置
  5552. * @method scrollToView
  5553. * @param { Window } win 当前range对象所属的window对象
  5554. * @return { UE.dom.Range } 当前Range对象
  5555. */
  5556. /**
  5557. * 滚动到距离当前range开始位置 offset 的位置处
  5558. * @method scrollToView
  5559. * @param { Window } win 当前range对象所属的window对象
  5560. * @param { Number } offset 距离range开始位置处的偏移量, 如果为正数, 则向下偏移, 反之, 则向上偏移
  5561. * @return { UE.dom.Range } 当前Range对象
  5562. */
  5563. scrollToView:function (win, offset) {
  5564. win = win ? window : domUtils.getWindow(this.document);
  5565. var me = this,
  5566. span = me.document.createElement('span');
  5567. //trace:717
  5568. span.innerHTML = '&nbsp;';
  5569. me.cloneRange().insertNode(span);
  5570. domUtils.scrollToView(span, win, offset);
  5571. domUtils.remove(span);
  5572. return me;
  5573. },
  5574. /**
  5575. * 判断当前选区内容是否占位符
  5576. * @private
  5577. * @method inFillChar
  5578. * @return { Boolean } 如果是占位符返回true,否则返回false
  5579. */
  5580. inFillChar : function(){
  5581. var start = this.startContainer;
  5582. if(this.collapsed && start.nodeType == 3
  5583. && start.nodeValue.replace(new RegExp('^' + domUtils.fillChar),'').length + 1 == start.nodeValue.length
  5584. ){
  5585. return true;
  5586. }
  5587. return false;
  5588. },
  5589. /**
  5590. * 保存
  5591. * @method createAddress
  5592. * @private
  5593. * @return { Boolean } 返回开始和结束的位置
  5594. * @example
  5595. * ```html
  5596. * <body>
  5597. * <p>
  5598. * aaaa
  5599. * <em>
  5600. * <!-- 选区开始 -->
  5601. * bbbb
  5602. * <!-- 选区结束 -->
  5603. * </em>
  5604. * </p>
  5605. *
  5606. * <script>
  5607. * //output: {startAddress:[0,1,0,0],endAddress:[0,1,0,4]}
  5608. * console.log( range.createAddress() );
  5609. * </script>
  5610. * </body>
  5611. * ```
  5612. */
  5613. createAddress : function(ignoreEnd,ignoreTxt){
  5614. var addr = {},me = this;
  5615. function getAddress(isStart){
  5616. var node = isStart ? me.startContainer : me.endContainer;
  5617. var parents = domUtils.findParents(node,true,function(node){return !domUtils.isBody(node)}),
  5618. addrs = [];
  5619. for(var i = 0,ci;ci = parents[i++];){
  5620. addrs.push(domUtils.getNodeIndex(ci,ignoreTxt));
  5621. }
  5622. var firstIndex = 0;
  5623. if(ignoreTxt){
  5624. if(node.nodeType == 3){
  5625. var tmpNode = node.previousSibling;
  5626. while(tmpNode && tmpNode.nodeType == 3){
  5627. firstIndex += tmpNode.nodeValue.replace(fillCharReg,'').length;
  5628. tmpNode = tmpNode.previousSibling;
  5629. }
  5630. firstIndex += (isStart ? me.startOffset : me.endOffset)// - (fillCharReg.test(node.nodeValue) ? 1 : 0 )
  5631. }else{
  5632. node = node.childNodes[ isStart ? me.startOffset : me.endOffset];
  5633. if(node){
  5634. firstIndex = domUtils.getNodeIndex(node,ignoreTxt);
  5635. }else{
  5636. node = isStart ? me.startContainer : me.endContainer;
  5637. var first = node.firstChild;
  5638. while(first){
  5639. if(domUtils.isFillChar(first)){
  5640. first = first.nextSibling;
  5641. continue;
  5642. }
  5643. firstIndex++;
  5644. if(first.nodeType == 3){
  5645. while( first && first.nodeType == 3){
  5646. first = first.nextSibling;
  5647. }
  5648. }else{
  5649. first = first.nextSibling;
  5650. }
  5651. }
  5652. }
  5653. }
  5654. }else{
  5655. firstIndex = isStart ? domUtils.isFillChar(node) ? 0 : me.startOffset : me.endOffset
  5656. }
  5657. if(firstIndex < 0){
  5658. firstIndex = 0;
  5659. }
  5660. addrs.push(firstIndex);
  5661. return addrs;
  5662. }
  5663. addr.startAddress = getAddress(true);
  5664. if(!ignoreEnd){
  5665. addr.endAddress = me.collapsed ? [].concat(addr.startAddress) : getAddress();
  5666. }
  5667. return addr;
  5668. },
  5669. /**
  5670. * 保存
  5671. * @method createAddress
  5672. * @private
  5673. * @return { Boolean } 返回开始和结束的位置
  5674. * @example
  5675. * ```html
  5676. * <body>
  5677. * <p>
  5678. * aaaa
  5679. * <em>
  5680. * <!-- 选区开始 -->
  5681. * bbbb
  5682. * <!-- 选区结束 -->
  5683. * </em>
  5684. * </p>
  5685. *
  5686. * <script>
  5687. * var range = editor.selection.getRange();
  5688. * range.moveToAddress({startAddress:[0,1,0,0],endAddress:[0,1,0,4]});
  5689. * range.select();
  5690. * //output: 'bbbb'
  5691. * console.log(editor.selection.getText());
  5692. * </script>
  5693. * </body>
  5694. * ```
  5695. */
  5696. moveToAddress : function(addr,ignoreEnd){
  5697. var me = this;
  5698. function getNode(address,isStart){
  5699. var tmpNode = me.document.body,
  5700. parentNode,offset;
  5701. for(var i= 0,ci,l=address.length;i<l;i++){
  5702. ci = address[i];
  5703. parentNode = tmpNode;
  5704. tmpNode = tmpNode.childNodes[ci];
  5705. if(!tmpNode){
  5706. offset = ci;
  5707. break;
  5708. }
  5709. }
  5710. if(isStart){
  5711. if(tmpNode){
  5712. me.setStartBefore(tmpNode)
  5713. }else{
  5714. me.setStart(parentNode,offset)
  5715. }
  5716. }else{
  5717. if(tmpNode){
  5718. me.setEndBefore(tmpNode)
  5719. }else{
  5720. me.setEnd(parentNode,offset)
  5721. }
  5722. }
  5723. }
  5724. getNode(addr.startAddress,true);
  5725. !ignoreEnd && addr.endAddress && getNode(addr.endAddress);
  5726. return me;
  5727. },
  5728. /**
  5729. * 判断给定的Range对象是否和当前Range对象表示的是同一个选区
  5730. * @method equals
  5731. * @param { UE.dom.Range } 需要判断的Range对象
  5732. * @return { Boolean } 如果给定的Range对象与当前Range对象表示的是同一个选区, 则返回true, 否则返回false
  5733. */
  5734. equals : function(rng){
  5735. for(var p in this){
  5736. if(this.hasOwnProperty(p)){
  5737. if(this[p] !== rng[p])
  5738. return false
  5739. }
  5740. }
  5741. return true;
  5742. },
  5743. /**
  5744. * 遍历range内的节点。每当遍历一个节点时, 都会执行参数项 doFn 指定的函数, 该函数的接受当前遍历的节点
  5745. * 作为其参数。
  5746. * @method traversal
  5747. * @param { Function } doFn 对每个遍历的节点要执行的方法, 该方法接受当前遍历的节点作为其参数
  5748. * @return { UE.dom.Range } 当前range对象
  5749. * @example
  5750. * ```html
  5751. *
  5752. * <body>
  5753. *
  5754. * <!-- 选区开始 -->
  5755. * <span></span>
  5756. * <a></a>
  5757. * <!-- 选区结束 -->
  5758. * </body>
  5759. *
  5760. * <script>
  5761. *
  5762. * //output: <span></span><a></a>
  5763. * console.log( range.cloneContents() );
  5764. *
  5765. * range.traversal( function ( node ) {
  5766. *
  5767. * if ( node.nodeType === 1 ) {
  5768. * node.className = "test";
  5769. * }
  5770. *
  5771. * } );
  5772. *
  5773. * //output: <span class="test"></span><a class="test"></a>
  5774. * console.log( range.cloneContents() );
  5775. *
  5776. * </script>
  5777. * ```
  5778. */
  5779. /**
  5780. * 遍历range内的节点。
  5781. * 每当遍历一个节点时, 都会执行参数项 doFn 指定的函数, 该函数的接受当前遍历的节点
  5782. * 作为其参数。
  5783. * 可以通过参数项 filterFn 来指定一个过滤器, 只有符合该过滤器过滤规则的节点才会触
  5784. * 发doFn函数的执行
  5785. * @method traversal
  5786. * @param { Function } doFn 对每个遍历的节点要执行的方法, 该方法接受当前遍历的节点作为其参数
  5787. * @param { Function } filterFn 过滤器, 该函数接受当前遍历的节点作为参数, 如果该节点满足过滤
  5788. * 规则, 请返回true, 该节点会触发doFn, 否则, 请返回false, 则该节点不
  5789. * 会触发doFn。
  5790. * @return { UE.dom.Range } 当前range对象
  5791. * @see UE.dom.Range:traversal(Function)
  5792. * @example
  5793. * ```html
  5794. *
  5795. * <body>
  5796. *
  5797. * <!-- 选区开始 -->
  5798. * <span></span>
  5799. * <a></a>
  5800. * <!-- 选区结束 -->
  5801. * </body>
  5802. *
  5803. * <script>
  5804. *
  5805. * //output: <span></span><a></a>
  5806. * console.log( range.cloneContents() );
  5807. *
  5808. * range.traversal( function ( node ) {
  5809. *
  5810. * node.className = "test";
  5811. *
  5812. * }, function ( node ) {
  5813. * return node.nodeType === 1;
  5814. * } );
  5815. *
  5816. * //output: <span class="test"></span><a class="test"></a>
  5817. * console.log( range.cloneContents() );
  5818. *
  5819. * </script>
  5820. * ```
  5821. */
  5822. traversal:function(doFn,filterFn){
  5823. if (this.collapsed)
  5824. return this;
  5825. var bookmark = this.createBookmark(),
  5826. end = bookmark.end,
  5827. current = domUtils.getNextDomNode(bookmark.start, false, filterFn);
  5828. while (current && current !== end && (domUtils.getPosition(current, end) & domUtils.POSITION_PRECEDING)) {
  5829. var tmpNode = domUtils.getNextDomNode(current,false,filterFn);
  5830. doFn(current);
  5831. current = tmpNode;
  5832. }
  5833. return this.moveToBookmark(bookmark);
  5834. }
  5835. };
  5836. })();
  5837. // core/Selection.js
  5838. /**
  5839. * 选集
  5840. * @file
  5841. * @module UE.dom
  5842. * @class Selection
  5843. * @since 1.2.6.1
  5844. */
  5845. /**
  5846. * 选区集合
  5847. * @unfile
  5848. * @module UE.dom
  5849. * @class Selection
  5850. */
  5851. (function () {
  5852. function getBoundaryInformation( range, start ) {
  5853. var getIndex = domUtils.getNodeIndex;
  5854. range = range.duplicate();
  5855. range.collapse( start );
  5856. var parent = range.parentElement();
  5857. //如果节点里没有子节点,直接退出
  5858. if ( !parent.hasChildNodes() ) {
  5859. return {container:parent, offset:0};
  5860. }
  5861. var siblings = parent.children,
  5862. child,
  5863. testRange = range.duplicate(),
  5864. startIndex = 0, endIndex = siblings.length - 1, index = -1,
  5865. distance;
  5866. while ( startIndex <= endIndex ) {
  5867. index = Math.floor( (startIndex + endIndex) / 2 );
  5868. child = siblings[index];
  5869. testRange.moveToElementText( child );
  5870. var position = testRange.compareEndPoints( 'StartToStart', range );
  5871. if ( position > 0 ) {
  5872. endIndex = index - 1;
  5873. } else if ( position < 0 ) {
  5874. startIndex = index + 1;
  5875. } else {
  5876. //trace:1043
  5877. return {container:parent, offset:getIndex( child )};
  5878. }
  5879. }
  5880. if ( index == -1 ) {
  5881. testRange.moveToElementText( parent );
  5882. testRange.setEndPoint( 'StartToStart', range );
  5883. distance = testRange.text.replace( /(\r\n|\r)/g, '\n' ).length;
  5884. siblings = parent.childNodes;
  5885. if ( !distance ) {
  5886. child = siblings[siblings.length - 1];
  5887. return {container:child, offset:child.nodeValue.length};
  5888. }
  5889. var i = siblings.length;
  5890. while ( distance > 0 ){
  5891. distance -= siblings[ --i ].nodeValue.length;
  5892. }
  5893. return {container:siblings[i], offset:-distance};
  5894. }
  5895. testRange.collapse( position > 0 );
  5896. testRange.setEndPoint( position > 0 ? 'StartToStart' : 'EndToStart', range );
  5897. distance = testRange.text.replace( /(\r\n|\r)/g, '\n' ).length;
  5898. if ( !distance ) {
  5899. return dtd.$empty[child.tagName] || dtd.$nonChild[child.tagName] ?
  5900. {container:parent, offset:getIndex( child ) + (position > 0 ? 0 : 1)} :
  5901. {container:child, offset:position > 0 ? 0 : child.childNodes.length}
  5902. }
  5903. while ( distance > 0 ) {
  5904. try {
  5905. var pre = child;
  5906. child = child[position > 0 ? 'previousSibling' : 'nextSibling'];
  5907. distance -= child.nodeValue.length;
  5908. } catch ( e ) {
  5909. return {container:parent, offset:getIndex( pre )};
  5910. }
  5911. }
  5912. return {container:child, offset:position > 0 ? -distance : child.nodeValue.length + distance}
  5913. }
  5914. /**
  5915. * 将ieRange转换为Range对象
  5916. * @param {Range} ieRange ieRange对象
  5917. * @param {Range} range Range对象
  5918. * @return {Range} range 返回转换后的Range对象
  5919. */
  5920. function transformIERangeToRange( ieRange, range ) {
  5921. if ( ieRange.item ) {
  5922. range.selectNode( ieRange.item( 0 ) );
  5923. } else {
  5924. var bi = getBoundaryInformation( ieRange, true );
  5925. range.setStart( bi.container, bi.offset );
  5926. if ( ieRange.compareEndPoints( 'StartToEnd', ieRange ) != 0 ) {
  5927. bi = getBoundaryInformation( ieRange, false );
  5928. range.setEnd( bi.container, bi.offset );
  5929. }
  5930. }
  5931. return range;
  5932. }
  5933. /**
  5934. * 获得ieRange
  5935. * @param {Selection} sel Selection对象
  5936. * @return {ieRange} 得到ieRange
  5937. */
  5938. function _getIERange( sel ) {
  5939. var ieRange;
  5940. //ie下有可能报错
  5941. try {
  5942. ieRange = sel.getNative().createRange();
  5943. } catch ( e ) {
  5944. return null;
  5945. }
  5946. var el = ieRange.item ? ieRange.item( 0 ) : ieRange.parentElement();
  5947. if ( ( el.ownerDocument || el ) === sel.document ) {
  5948. return ieRange;
  5949. }
  5950. return null;
  5951. }
  5952. var Selection = dom.Selection = function ( doc ) {
  5953. var me = this, iframe;
  5954. me.document = doc;
  5955. if ( browser.ie9below ) {
  5956. iframe = domUtils.getWindow( doc ).frameElement;
  5957. domUtils.on( iframe, 'beforedeactivate', function () {
  5958. me._bakIERange = me.getIERange();
  5959. } );
  5960. domUtils.on( iframe, 'activate', function () {
  5961. try {
  5962. if ( !_getIERange( me ) && me._bakIERange ) {
  5963. me._bakIERange.select();
  5964. }
  5965. } catch ( ex ) {
  5966. }
  5967. me._bakIERange = null;
  5968. } );
  5969. }
  5970. iframe = doc = null;
  5971. };
  5972. Selection.prototype = {
  5973. rangeInBody : function(rng,txtRange){
  5974. var node = browser.ie9below || txtRange ? rng.item ? rng.item() : rng.parentElement() : rng.startContainer;
  5975. return node === this.document.body || domUtils.inDoc(node,this.document);
  5976. },
  5977. /**
  5978. * 获取原生seleciton对象
  5979. * @method getNative
  5980. * @return { Object } 获得selection对象
  5981. * @example
  5982. * ```javascript
  5983. * editor.selection.getNative();
  5984. * ```
  5985. */
  5986. getNative:function () {
  5987. var doc = this.document;
  5988. try {
  5989. return !doc ? null : browser.ie9below ? doc.selection : domUtils.getWindow( doc ).getSelection();
  5990. } catch ( e ) {
  5991. return null;
  5992. }
  5993. },
  5994. /**
  5995. * 获得ieRange
  5996. * @method getIERange
  5997. * @return { Object } 返回ie原生的Range
  5998. * @example
  5999. * ```javascript
  6000. * editor.selection.getIERange();
  6001. * ```
  6002. */
  6003. getIERange:function () {
  6004. var ieRange = _getIERange( this );
  6005. if ( !ieRange ) {
  6006. if ( this._bakIERange ) {
  6007. return this._bakIERange;
  6008. }
  6009. }
  6010. return ieRange;
  6011. },
  6012. /**
  6013. * 缓存当前选区的range和选区的开始节点
  6014. * @method cache
  6015. */
  6016. cache:function () {
  6017. this.clear();
  6018. this._cachedRange = this.getRange();
  6019. this._cachedStartElement = this.getStart();
  6020. this._cachedStartElementPath = this.getStartElementPath();
  6021. },
  6022. /**
  6023. * 获取选区开始位置的父节点到body
  6024. * @method getStartElementPath
  6025. * @return { Array } 返回父节点集合
  6026. * @example
  6027. * ```javascript
  6028. * editor.selection.getStartElementPath();
  6029. * ```
  6030. */
  6031. getStartElementPath:function () {
  6032. if ( this._cachedStartElementPath ) {
  6033. return this._cachedStartElementPath;
  6034. }
  6035. var start = this.getStart();
  6036. if ( start ) {
  6037. return domUtils.findParents( start, true, null, true )
  6038. }
  6039. return [];
  6040. },
  6041. /**
  6042. * 清空缓存
  6043. * @method clear
  6044. */
  6045. clear:function () {
  6046. this._cachedStartElementPath = this._cachedRange = this._cachedStartElement = null;
  6047. },
  6048. /**
  6049. * 编辑器是否得到了选区
  6050. * @method isFocus
  6051. */
  6052. isFocus:function () {
  6053. try {
  6054. if(browser.ie9below){
  6055. var nativeRange = _getIERange(this);
  6056. return !!(nativeRange && this.rangeInBody(nativeRange));
  6057. }else{
  6058. return !!this.getNative().rangeCount;
  6059. }
  6060. } catch ( e ) {
  6061. return false;
  6062. }
  6063. },
  6064. /**
  6065. * 获取选区对应的Range
  6066. * @method getRange
  6067. * @return { Object } 得到Range对象
  6068. * @example
  6069. * ```javascript
  6070. * editor.selection.getRange();
  6071. * ```
  6072. */
  6073. getRange:function () {
  6074. var me = this;
  6075. function optimze( range ) {
  6076. var child = me.document.body.firstChild,
  6077. collapsed = range.collapsed;
  6078. while ( child && child.firstChild ) {
  6079. range.setStart( child, 0 );
  6080. child = child.firstChild;
  6081. }
  6082. if ( !range.startContainer ) {
  6083. range.setStart( me.document.body, 0 )
  6084. }
  6085. if ( collapsed ) {
  6086. range.collapse( true );
  6087. }
  6088. }
  6089. if ( me._cachedRange != null ) {
  6090. return this._cachedRange;
  6091. }
  6092. var range = new baidu.editor.dom.Range( me.document );
  6093. if ( browser.ie9below ) {
  6094. var nativeRange = me.getIERange();
  6095. if ( nativeRange ) {
  6096. //备份的_bakIERange可能已经实效了,dom树发生了变化比如从源码模式切回来,所以try一下,实效就放到body开始位置
  6097. try{
  6098. transformIERangeToRange( nativeRange, range );
  6099. }catch(e){
  6100. optimze( range );
  6101. }
  6102. } else {
  6103. optimze( range );
  6104. }
  6105. } else {
  6106. var sel = me.getNative();
  6107. if ( sel && sel.rangeCount ) {
  6108. var firstRange = sel.getRangeAt( 0 );
  6109. var lastRange = sel.getRangeAt( sel.rangeCount - 1 );
  6110. range.setStart( firstRange.startContainer, firstRange.startOffset ).setEnd( lastRange.endContainer, lastRange.endOffset );
  6111. if ( range.collapsed && domUtils.isBody( range.startContainer ) && !range.startOffset ) {
  6112. optimze( range );
  6113. }
  6114. } else {
  6115. //trace:1734 有可能已经不在dom树上了,标识的节点
  6116. if ( this._bakRange && domUtils.inDoc( this._bakRange.startContainer, this.document ) ){
  6117. return this._bakRange;
  6118. }
  6119. optimze( range );
  6120. }
  6121. }
  6122. return this._bakRange = range;
  6123. },
  6124. /**
  6125. * 获取开始元素,用于状态反射
  6126. * @method getStart
  6127. * @return { Element } 获得开始元素
  6128. * @example
  6129. * ```javascript
  6130. * editor.selection.getStart();
  6131. * ```
  6132. */
  6133. getStart:function () {
  6134. if ( this._cachedStartElement ) {
  6135. return this._cachedStartElement;
  6136. }
  6137. var range = browser.ie9below ? this.getIERange() : this.getRange(),
  6138. tmpRange,
  6139. start, tmp, parent;
  6140. if ( browser.ie9below ) {
  6141. if ( !range ) {
  6142. //todo 给第一个值可能会有问题
  6143. return this.document.body.firstChild;
  6144. }
  6145. //control元素
  6146. if ( range.item ){
  6147. return range.item( 0 );
  6148. }
  6149. tmpRange = range.duplicate();
  6150. //修正ie下<b>x</b>[xx] 闭合后 <b>x|</b>xx
  6151. tmpRange.text.length > 0 && tmpRange.moveStart( 'character', 1 );
  6152. tmpRange.collapse( 1 );
  6153. start = tmpRange.parentElement();
  6154. parent = tmp = range.parentElement();
  6155. while ( tmp = tmp.parentNode ) {
  6156. if ( tmp == start ) {
  6157. start = parent;
  6158. break;
  6159. }
  6160. }
  6161. } else {
  6162. range.shrinkBoundary();
  6163. start = range.startContainer;
  6164. if ( start.nodeType == 1 && start.hasChildNodes() ){
  6165. start = start.childNodes[Math.min( start.childNodes.length - 1, range.startOffset )];
  6166. }
  6167. if ( start.nodeType == 3 ){
  6168. return start.parentNode;
  6169. }
  6170. }
  6171. return start;
  6172. },
  6173. /**
  6174. * 得到选区中的文本
  6175. * @method getText
  6176. * @return { String } 选区中包含的文本
  6177. * @example
  6178. * ```javascript
  6179. * editor.selection.getText();
  6180. * ```
  6181. */
  6182. getText:function () {
  6183. var nativeSel, nativeRange;
  6184. if ( this.isFocus() && (nativeSel = this.getNative()) ) {
  6185. nativeRange = browser.ie9below ? nativeSel.createRange() : nativeSel.getRangeAt( 0 );
  6186. return browser.ie9below ? nativeRange.text : nativeRange.toString();
  6187. }
  6188. return '';
  6189. },
  6190. /**
  6191. * 清除选区
  6192. * @method clearRange
  6193. * @example
  6194. * ```javascript
  6195. * editor.selection.clearRange();
  6196. * ```
  6197. */
  6198. clearRange : function(){
  6199. this.getNative()[browser.ie9below ? 'empty' : 'removeAllRanges']();
  6200. }
  6201. };
  6202. })();
  6203. // core/Editor.js
  6204. /**
  6205. * 编辑器主类,包含编辑器提供的大部分公用接口
  6206. * @file
  6207. * @module UE
  6208. * @class Editor
  6209. * @since 1.2.6.1
  6210. */
  6211. /**
  6212. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  6213. * @unfile
  6214. * @module UE
  6215. */
  6216. /**
  6217. * UEditor的核心类,为用户提供与编辑器交互的接口。
  6218. * @unfile
  6219. * @module UE
  6220. * @class Editor
  6221. */
  6222. (function () {
  6223. var uid = 0, _selectionChangeTimer;
  6224. /**
  6225. * 获取编辑器的html内容,赋值到编辑器所在表单的textarea文本域里面
  6226. * @private
  6227. * @method setValue
  6228. * @param { UE.Editor } editor 编辑器事例
  6229. */
  6230. function setValue(form, editor) {
  6231. var textarea;
  6232. if (editor.textarea) {
  6233. if (utils.isString(editor.textarea)) {
  6234. for (var i = 0, ti, tis = domUtils.getElementsByTagName(form, 'textarea'); ti = tis[i++];) {
  6235. if (ti.id == 'ueditor_textarea_' + editor.options.textarea) {
  6236. textarea = ti;
  6237. break;
  6238. }
  6239. }
  6240. } else {
  6241. textarea = editor.textarea;
  6242. }
  6243. }
  6244. if (!textarea) {
  6245. form.appendChild(textarea = domUtils.createElement(document, 'textarea', {
  6246. 'name': editor.options.textarea,
  6247. 'id': 'ueditor_textarea_' + editor.options.textarea,
  6248. 'style': "display:none"
  6249. }));
  6250. //不要产生多个textarea
  6251. editor.textarea = textarea;
  6252. }
  6253. !textarea.getAttribute('name') && textarea.setAttribute('name', editor.options.textarea );
  6254. textarea.value = editor.hasContents() ?
  6255. (editor.options.allHtmlEnabled ? editor.getAllHtml() : editor.getContent(null, null, true)) :
  6256. ''
  6257. }
  6258. function loadPlugins(me){
  6259. //初始化插件
  6260. for (var pi in UE.plugins) {
  6261. UE.plugins[pi].call(me);
  6262. }
  6263. }
  6264. function checkCurLang(I18N){
  6265. for(var lang in I18N){
  6266. return lang
  6267. }
  6268. }
  6269. function langReadied(me){
  6270. me.langIsReady = true;
  6271. me.fireEvent("langReady");
  6272. }
  6273. /**
  6274. * 编辑器准备就绪后会触发该事件
  6275. * @module UE
  6276. * @class Editor
  6277. * @event ready
  6278. * @remind render方法执行完成之后,会触发该事件
  6279. * @remind
  6280. * @example
  6281. * ```javascript
  6282. * editor.addListener( 'ready', function( editor ) {
  6283. * editor.execCommand( 'focus' ); //编辑器家在完成后,让编辑器拿到焦点
  6284. * } );
  6285. * ```
  6286. */
  6287. /**
  6288. * 执行destroy方法,会触发该事件
  6289. * @module UE
  6290. * @class Editor
  6291. * @event destroy
  6292. * @see UE.Editor:destroy()
  6293. */
  6294. /**
  6295. * 执行reset方法,会触发该事件
  6296. * @module UE
  6297. * @class Editor
  6298. * @event reset
  6299. * @see UE.Editor:reset()
  6300. */
  6301. /**
  6302. * 执行focus方法,会触发该事件
  6303. * @module UE
  6304. * @class Editor
  6305. * @event focus
  6306. * @see UE.Editor:focus(Boolean)
  6307. */
  6308. /**
  6309. * 语言加载完成会触发该事件
  6310. * @module UE
  6311. * @class Editor
  6312. * @event langReady
  6313. */
  6314. /**
  6315. * 运行命令之后会触发该命令
  6316. * @module UE
  6317. * @class Editor
  6318. * @event beforeExecCommand
  6319. */
  6320. /**
  6321. * 运行命令之后会触发该命令
  6322. * @module UE
  6323. * @class Editor
  6324. * @event afterExecCommand
  6325. */
  6326. /**
  6327. * 运行命令之前会触发该命令
  6328. * @module UE
  6329. * @class Editor
  6330. * @event firstBeforeExecCommand
  6331. */
  6332. /**
  6333. * 在getContent方法执行之前会触发该事件
  6334. * @module UE
  6335. * @class Editor
  6336. * @event beforeGetContent
  6337. * @see UE.Editor:getContent()
  6338. */
  6339. /**
  6340. * 在getContent方法执行之后会触发该事件
  6341. * @module UE
  6342. * @class Editor
  6343. * @event afterGetContent
  6344. * @see UE.Editor:getContent()
  6345. */
  6346. /**
  6347. * 在getAllHtml方法执行时会触发该事件
  6348. * @module UE
  6349. * @class Editor
  6350. * @event getAllHtml
  6351. * @see UE.Editor:getAllHtml()
  6352. */
  6353. /**
  6354. * 在setContent方法执行之前会触发该事件
  6355. * @module UE
  6356. * @class Editor
  6357. * @event beforeSetContent
  6358. * @see UE.Editor:setContent(String)
  6359. */
  6360. /**
  6361. * 在setContent方法执行之后会触发该事件
  6362. * @module UE
  6363. * @class Editor
  6364. * @event afterSetContent
  6365. * @see UE.Editor:setContent(String)
  6366. */
  6367. /**
  6368. * 每当编辑器内部选区发生改变时,将触发该事件
  6369. * @event selectionchange
  6370. * @warning 该事件的触发非常频繁,不建议在该事件的处理过程中做重量级的处理
  6371. * @example
  6372. * ```javascript
  6373. * editor.addListener( 'selectionchange', function( editor ) {
  6374. * console.log('选区发生改变');
  6375. * }
  6376. */
  6377. /**
  6378. * 在所有selectionchange的监听函数执行之前,会触发该事件
  6379. * @module UE
  6380. * @class Editor
  6381. * @event beforeSelectionChange
  6382. * @see UE.Editor:selectionchange
  6383. */
  6384. /**
  6385. * 在所有selectionchange的监听函数执行完之后,会触发该事件
  6386. * @module UE
  6387. * @class Editor
  6388. * @event afterSelectionChange
  6389. * @see UE.Editor:selectionchange
  6390. */
  6391. /**
  6392. * 编辑器内容发生改变时会触发该事件
  6393. * @module UE
  6394. * @class Editor
  6395. * @event contentChange
  6396. */
  6397. /**
  6398. * 以默认参数构建一个编辑器实例
  6399. * @constructor
  6400. * @remind 通过 改构造方法实例化的编辑器,不带ui层.需要render到一个容器,编辑器实例才能正常渲染到页面
  6401. * @example
  6402. * ```javascript
  6403. * var editor = new UE.Editor();
  6404. * editor.execCommand('blod');
  6405. * ```
  6406. * @see UE.Config
  6407. */
  6408. /**
  6409. * 以给定的参数集合创建一个编辑器实例,对于未指定的参数,将应用默认参数。
  6410. * @constructor
  6411. * @remind 通过 改构造方法实例化的编辑器,不带ui层.需要render到一个容器,编辑器实例才能正常渲染到页面
  6412. * @param { Object } setting 创建编辑器的参数
  6413. * @example
  6414. * ```javascript
  6415. * var editor = new UE.Editor();
  6416. * editor.execCommand('blod');
  6417. * ```
  6418. * @see UE.Config
  6419. */
  6420. var Editor = UE.Editor = function (options) {
  6421. var me = this;
  6422. me.uid = uid++;
  6423. EventBase.call(me);
  6424. me.commands = {};
  6425. me.options = utils.extend(utils.clone(options || {}), UEDITOR_CONFIG, true);
  6426. me.shortcutkeys = {};
  6427. me.inputRules = [];
  6428. me.outputRules = [];
  6429. //设置默认的常用属性
  6430. me.setOpt(Editor.defaultOptions(me));
  6431. /* 尝试异步加载后台配置 */
  6432. me.loadServerConfig();
  6433. if(!utils.isEmptyObject(UE.I18N)){
  6434. //修改默认的语言类型
  6435. me.options.lang = checkCurLang(UE.I18N);
  6436. UE.plugin.load(me);
  6437. langReadied(me);
  6438. }else{
  6439. utils.loadFile(document, {
  6440. src: me.options.langPath + me.options.lang + "/" + me.options.lang + ".js",
  6441. tag: "script",
  6442. type: "text/javascript",
  6443. defer: "defer"
  6444. }, function () {
  6445. UE.plugin.load(me);
  6446. langReadied(me);
  6447. });
  6448. }
  6449. UE.instants['ueditorInstant' + me.uid] = me;
  6450. };
  6451. Editor.prototype = {
  6452. registerCommand : function(name,obj){
  6453. this.commands[name] = obj;
  6454. },
  6455. /**
  6456. * 编辑器对外提供的监听ready事件的接口, 通过调用该方法,达到的效果与监听ready事件是一致的
  6457. * @method ready
  6458. * @param { Function } fn 编辑器ready之后所执行的回调, 如果在注册事件之前编辑器已经ready,将会
  6459. * 立即触发该回调。
  6460. * @remind 需要等待编辑器加载完成后才能执行的代码,可以使用该方法传入
  6461. * @example
  6462. * ```javascript
  6463. * editor.ready( function( editor ) {
  6464. * editor.setContent('初始化完毕');
  6465. * } );
  6466. * ```
  6467. * @see UE.Editor.event:ready
  6468. */
  6469. ready: function (fn) {
  6470. var me = this;
  6471. if (fn) {
  6472. me.isReady ? fn.apply(me) : me.addListener('ready', fn);
  6473. }
  6474. },
  6475. /**
  6476. * 该方法是提供给插件里面使用,设置配置项默认值
  6477. * @method setOpt
  6478. * @warning 三处设置配置项的优先级: 实例化时传入参数 > setOpt()设置 > config文件里设置
  6479. * @warning 该方法仅供编辑器插件内部和编辑器初始化时调用,其他地方不能调用。
  6480. * @param { String } key 编辑器的可接受的选项名称
  6481. * @param { * } val 该选项可接受的值
  6482. * @example
  6483. * ```javascript
  6484. * editor.setOpt( 'initContent', '欢迎使用编辑器' );
  6485. * ```
  6486. */
  6487. /**
  6488. * 该方法是提供给插件里面使用,以{key:value}集合的方式设置插件内用到的配置项默认值
  6489. * @method setOpt
  6490. * @warning 三处设置配置项的优先级: 实例化时传入参数 > setOpt()设置 > config文件里设置
  6491. * @warning 该方法仅供编辑器插件内部和编辑器初始化时调用,其他地方不能调用。
  6492. * @param { Object } options 将要设置的选项的键值对对象
  6493. * @example
  6494. * ```javascript
  6495. * editor.setOpt( {
  6496. * 'initContent': '欢迎使用编辑器'
  6497. * } );
  6498. * ```
  6499. */
  6500. setOpt: function (key, val) {
  6501. var obj = {};
  6502. if (utils.isString(key)) {
  6503. obj[key] = val
  6504. } else {
  6505. obj = key;
  6506. }
  6507. utils.extend(this.options, obj, true);
  6508. },
  6509. getOpt:function(key){
  6510. return this.options[key]
  6511. },
  6512. /**
  6513. * 销毁编辑器实例,使用textarea代替
  6514. * @method destroy
  6515. * @example
  6516. * ```javascript
  6517. * editor.destroy();
  6518. * ```
  6519. */
  6520. destroy: function () {
  6521. var me = this;
  6522. me.fireEvent('destroy');
  6523. var container = me.container.parentNode;
  6524. var textarea = me.textarea;
  6525. if (!textarea) {
  6526. textarea = document.createElement('textarea');
  6527. container.parentNode.insertBefore(textarea, container);
  6528. } else {
  6529. textarea.style.display = ''
  6530. }
  6531. textarea.style.width = me.iframe.offsetWidth + 'px';
  6532. textarea.style.height = me.iframe.offsetHeight + 'px';
  6533. textarea.value = me.getContent();
  6534. textarea.id = me.key;
  6535. container.innerHTML = '';
  6536. domUtils.remove(container);
  6537. var key = me.key;
  6538. //trace:2004
  6539. for (var p in me) {
  6540. if (me.hasOwnProperty(p)) {
  6541. delete this[p];
  6542. }
  6543. }
  6544. UE.delEditor(key);
  6545. },
  6546. /**
  6547. * 渲染编辑器的DOM到指定容器
  6548. * @method render
  6549. * @param { String } containerId 指定一个容器ID
  6550. * @remind 执行该方法,会触发ready事件
  6551. * @warning 必须且只能调用一次
  6552. */
  6553. /**
  6554. * 渲染编辑器的DOM到指定容器
  6555. * @method render
  6556. * @param { Element } containerDom 直接指定容器对象
  6557. * @remind 执行该方法,会触发ready事件
  6558. * @warning 必须且只能调用一次
  6559. */
  6560. render: function (container) {
  6561. var me = this,
  6562. options = me.options,
  6563. getStyleValue=function(attr){
  6564. return parseInt(domUtils.getComputedStyle(container,attr));
  6565. };
  6566. if (utils.isString(container)) {
  6567. container = document.getElementById(container);
  6568. }
  6569. if (container) {
  6570. if(options.initialFrameWidth){
  6571. options.minFrameWidth = options.initialFrameWidth
  6572. }else{
  6573. options.minFrameWidth = options.initialFrameWidth = container.offsetWidth;
  6574. }
  6575. if(options.initialFrameHeight){
  6576. options.minFrameHeight = options.initialFrameHeight
  6577. }else{
  6578. options.initialFrameHeight = options.minFrameHeight = container.offsetHeight;
  6579. }
  6580. container.style.width = /%$/.test(options.initialFrameWidth) ? '100%' : options.initialFrameWidth-
  6581. getStyleValue("padding-left")- getStyleValue("padding-right") +'px';
  6582. container.style.height = /%$/.test(options.initialFrameHeight) ? '100%' : options.initialFrameHeight -
  6583. getStyleValue("padding-top")- getStyleValue("padding-bottom") +'px';
  6584. container.style.zIndex = options.zIndex;
  6585. var html = ( ie && browser.version < 9 ? '' : '<!DOCTYPE html>') +
  6586. '<html xmlns=\'http://www.w3.org/1999/xhtml\' class=\'view\' ><head>' +
  6587. '<style type=\'text/css\'>' +
  6588. //设置四周的留边
  6589. '.view{padding:0;word-wrap:break-word;cursor:text;height:90%;}\n' +
  6590. //设置默认字体和字号
  6591. //font-family不能呢随便改,在safari下fillchar会有解析问题
  6592. 'body{margin:8px;font-family:sans-serif;font-size:16px;}' +
  6593. //设置段落间距
  6594. 'p{margin:5px 0;}</style>' +
  6595. ( options.iframeCssUrl ? '<link rel=\'stylesheet\' type=\'text/css\' href=\'' + utils.unhtml(options.iframeCssUrl) + '\'/>' : '' ) +
  6596. (options.initialStyle ? '<style>' + options.initialStyle + '</style>' : '') +
  6597. '</head><body class=\'view\' ></body>' +
  6598. '<script type=\'text/javascript\' ' + (ie ? 'defer=\'defer\'' : '' ) +' id=\'_initialScript\'>' +
  6599. 'setTimeout(function(){editor = window.parent.UE.instants[\'ueditorInstant' + me.uid + '\'];editor._setup(document);},0);' +
  6600. 'var _tmpScript = document.getElementById(\'_initialScript\');_tmpScript.parentNode.removeChild(_tmpScript);</script></html>';
  6601. container.appendChild(domUtils.createElement(document, 'iframe', {
  6602. id: 'ueditor_' + me.uid,
  6603. width: "100%",
  6604. height: "100%",
  6605. frameborder: "0",
  6606. //先注释掉了,加的原因忘记了,但开启会直接导致全屏模式下内容多时不会出现滚动条
  6607. // scrolling :'no',
  6608. src: 'javascript:void(function(){document.open();' + (options.customDomain && document.domain != location.hostname ? 'document.domain="' + document.domain + '";' : '') +
  6609. 'document.write("' + html + '");document.close();}())'
  6610. }));
  6611. container.style.overflow = 'hidden';
  6612. //解决如果是给定的百分比,会导致高度算不对的问题
  6613. setTimeout(function(){
  6614. if( /%$/.test(options.initialFrameWidth)){
  6615. options.minFrameWidth = options.initialFrameWidth = container.offsetWidth;
  6616. //如果这里给定宽度,会导致ie在拖动窗口大小时,编辑区域不随着变化
  6617. // container.style.width = options.initialFrameWidth + 'px';
  6618. }
  6619. if(/%$/.test(options.initialFrameHeight)){
  6620. options.minFrameHeight = options.initialFrameHeight = container.offsetHeight;
  6621. container.style.height = options.initialFrameHeight + 'px';
  6622. }
  6623. })
  6624. }
  6625. },
  6626. /**
  6627. * 编辑器初始化
  6628. * @method _setup
  6629. * @private
  6630. * @param { Element } doc 编辑器Iframe中的文档对象
  6631. */
  6632. _setup: function (doc) {
  6633. var me = this,
  6634. options = me.options;
  6635. if (ie) {
  6636. doc.body.disabled = true;
  6637. doc.body.contentEditable = true;
  6638. doc.body.disabled = false;
  6639. } else {
  6640. doc.body.contentEditable = true;
  6641. }
  6642. doc.body.spellcheck = false;
  6643. me.document = doc;
  6644. me.window = doc.defaultView || doc.parentWindow;
  6645. me.iframe = me.window.frameElement;
  6646. me.body = doc.body;
  6647. me.selection = new dom.Selection(doc);
  6648. //gecko初始化就能得到range,无法判断isFocus了
  6649. var geckoSel;
  6650. if (browser.gecko && (geckoSel = this.selection.getNative())) {
  6651. geckoSel.removeAllRanges();
  6652. }
  6653. this._initEvents();
  6654. //为form提交提供一个隐藏的textarea
  6655. for (var form = this.iframe.parentNode; !domUtils.isBody(form); form = form.parentNode) {
  6656. if (form.tagName == 'FORM') {
  6657. me.form = form;
  6658. if(me.options.autoSyncData){
  6659. domUtils.on(me.window,'blur',function(){
  6660. setValue(form,me);
  6661. });
  6662. }else{
  6663. domUtils.on(form, 'submit', function () {
  6664. setValue(this, me);
  6665. });
  6666. }
  6667. break;
  6668. }
  6669. }
  6670. if (options.initialContent) {
  6671. if (options.autoClearinitialContent) {
  6672. var oldExecCommand = me.execCommand;
  6673. me.execCommand = function () {
  6674. me.fireEvent('firstBeforeExecCommand');
  6675. return oldExecCommand.apply(me, arguments);
  6676. };
  6677. this._setDefaultContent(options.initialContent);
  6678. } else
  6679. this.setContent(options.initialContent, false, true);
  6680. }
  6681. //编辑器不能为空内容
  6682. if (domUtils.isEmptyNode(me.body)) {
  6683. me.body.innerHTML = '<p>' + (browser.ie ? '' : '<br/>') + '</p>';
  6684. }
  6685. //如果要求focus, 就把光标定位到内容开始
  6686. if (options.focus) {
  6687. setTimeout(function () {
  6688. me.focus(me.options.focusInEnd);
  6689. //如果自动清除开着,就不需要做selectionchange;
  6690. !me.options.autoClearinitialContent && me._selectionChange();
  6691. }, 0);
  6692. }
  6693. if (!me.container) {
  6694. me.container = this.iframe.parentNode;
  6695. }
  6696. if (options.fullscreen && me.ui) {
  6697. me.ui.setFullScreen(true);
  6698. }
  6699. try {
  6700. me.document.execCommand('2D-position', false, false);
  6701. } catch (e) {
  6702. }
  6703. try {
  6704. me.document.execCommand('enableInlineTableEditing', false, false);
  6705. } catch (e) {
  6706. }
  6707. try {
  6708. me.document.execCommand('enableObjectResizing', false, false);
  6709. } catch (e) {
  6710. }
  6711. //挂接快捷键
  6712. me._bindshortcutKeys();
  6713. me.isReady = 1;
  6714. me.fireEvent('ready');
  6715. options.onready && options.onready.call(me);
  6716. if (!browser.ie9below) {
  6717. domUtils.on(me.window, ['blur', 'focus'], function (e) {
  6718. //chrome下会出现alt+tab切换时,导致选区位置不对
  6719. if (e.type == 'blur') {
  6720. me._bakRange = me.selection.getRange();
  6721. try {
  6722. me._bakNativeRange = me.selection.getNative().getRangeAt(0);
  6723. me.selection.getNative().removeAllRanges();
  6724. } catch (e) {
  6725. me._bakNativeRange = null;
  6726. }
  6727. } else {
  6728. try {
  6729. me._bakRange && me._bakRange.select();
  6730. } catch (e) {
  6731. }
  6732. }
  6733. });
  6734. }
  6735. //trace:1518 ff3.6body不够寛,会导致点击空白处无法获得焦点
  6736. if (browser.gecko && browser.version <= 10902) {
  6737. //修复ff3.6初始化进来,不能点击获得焦点
  6738. me.body.contentEditable = false;
  6739. setTimeout(function () {
  6740. me.body.contentEditable = true;
  6741. }, 100);
  6742. setInterval(function () {
  6743. me.body.style.height = me.iframe.offsetHeight - 20 + 'px'
  6744. }, 100)
  6745. }
  6746. !options.isShow && me.setHide();
  6747. options.readonly && me.setDisabled();
  6748. },
  6749. /**
  6750. * 同步数据到编辑器所在的form
  6751. * 从编辑器的容器节点向上查找form元素,若找到,就同步编辑内容到找到的form里,为提交数据做准备,主要用于是手动提交的情况
  6752. * 后台取得数据的键值,使用你容器上的name属性,如果没有就使用参数里的textarea项
  6753. * @method sync
  6754. * @example
  6755. * ```javascript
  6756. * editor.sync();
  6757. * form.sumbit(); //form变量已经指向了form元素
  6758. * ```
  6759. */
  6760. /**
  6761. * 根据传入的formId,在页面上查找要同步数据的表单,若找到,就同步编辑内容到找到的form里,为提交数据做准备
  6762. * 后台取得数据的键值,该键值默认使用给定的编辑器容器的name属性,如果没有name属性则使用参数项里给定的“textarea”项
  6763. * @method sync
  6764. * @param { String } formID 指定一个要同步数据的form的id,编辑器的数据会同步到你指定form下
  6765. */
  6766. sync: function (formId) {
  6767. var me = this,
  6768. form = formId ? document.getElementById(formId) :
  6769. domUtils.findParent(me.iframe.parentNode, function (node) {
  6770. return node.tagName == 'FORM'
  6771. }, true);
  6772. form && setValue(form, me);
  6773. },
  6774. /**
  6775. * 设置编辑器高度
  6776. * @method setHeight
  6777. * @remind 当配置项autoHeightEnabled为真时,该方法无效
  6778. * @param { Number } number 设置的高度值,纯数值,不带单位
  6779. * @example
  6780. * ```javascript
  6781. * editor.setHeight(number);
  6782. * ```
  6783. */
  6784. setHeight: function (height,notSetHeight) {
  6785. if (height !== parseInt(this.iframe.parentNode.style.height)) {
  6786. this.iframe.parentNode.style.height = height + 'px';
  6787. }
  6788. !notSetHeight && (this.options.minFrameHeight = this.options.initialFrameHeight = height);
  6789. this.body.style.height = height + 'px';
  6790. !notSetHeight && this.trigger('setHeight')
  6791. },
  6792. /**
  6793. * 为编辑器的编辑命令提供快捷键
  6794. * 这个接口是为插件扩展提供的接口,主要是为新添加的插件,如果需要添加快捷键,所提供的接口
  6795. * @method addshortcutkey
  6796. * @param { Object } keyset 命令名和快捷键键值对对象,多个按钮的快捷键用“+”分隔
  6797. * @example
  6798. * ```javascript
  6799. * editor.addshortcutkey({
  6800. * "Bold" : "ctrl+66",//^B
  6801. * "Italic" : "ctrl+73", //^I
  6802. * });
  6803. * ```
  6804. */
  6805. /**
  6806. * 这个接口是为插件扩展提供的接口,主要是为新添加的插件,如果需要添加快捷键,所提供的接口
  6807. * @method addshortcutkey
  6808. * @param { String } cmd 触发快捷键时,响应的命令
  6809. * @param { String } keys 快捷键的字符串,多个按钮用“+”分隔
  6810. * @example
  6811. * ```javascript
  6812. * editor.addshortcutkey("Underline", "ctrl+85"); //^U
  6813. * ```
  6814. */
  6815. addshortcutkey: function (cmd, keys) {
  6816. var obj = {};
  6817. if (keys) {
  6818. obj[cmd] = keys
  6819. } else {
  6820. obj = cmd;
  6821. }
  6822. utils.extend(this.shortcutkeys, obj)
  6823. },
  6824. /**
  6825. * 对编辑器设置keydown事件监听,绑定快捷键和命令,当快捷键组合触发成功,会响应对应的命令
  6826. * @method _bindshortcutKeys
  6827. * @private
  6828. */
  6829. _bindshortcutKeys: function () {
  6830. var me = this, shortcutkeys = this.shortcutkeys;
  6831. me.addListener('keydown', function (type, e) {
  6832. var keyCode = e.keyCode || e.which;
  6833. for (var i in shortcutkeys) {
  6834. var tmp = shortcutkeys[i].split(',');
  6835. for (var t = 0, ti; ti = tmp[t++];) {
  6836. ti = ti.split(':');
  6837. var key = ti[0], param = ti[1];
  6838. if (/^(ctrl)(\+shift)?\+(\d+)$/.test(key.toLowerCase()) || /^(\d+)$/.test(key)) {
  6839. if (( (RegExp.$1 == 'ctrl' ? (e.ctrlKey || e.metaKey) : 0)
  6840. && (RegExp.$2 != "" ? e[RegExp.$2.slice(1) + "Key"] : 1)
  6841. && keyCode == RegExp.$3
  6842. ) ||
  6843. keyCode == RegExp.$1
  6844. ) {
  6845. if (me.queryCommandState(i,param) != -1)
  6846. me.execCommand(i, param);
  6847. domUtils.preventDefault(e);
  6848. }
  6849. }
  6850. }
  6851. }
  6852. });
  6853. },
  6854. /**
  6855. * 获取编辑器的内容
  6856. * @method getContent
  6857. * @warning 该方法获取到的是经过编辑器内置的过滤规则进行过滤后得到的内容
  6858. * @return { String } 编辑器的内容字符串, 如果编辑器的内容为空,或者是空的标签内容(如:”&lt;p&gt;&lt;br/&gt;&lt;/p&gt;“), 则返回空字符串
  6859. * @example
  6860. * ```javascript
  6861. * //编辑器html内容:<p>1<strong>2<em>34</em>5</strong>6</p>
  6862. * var content = editor.getContent(); //返回值:<p>1<strong>2<em>34</em>5</strong>6</p>
  6863. * ```
  6864. */
  6865. /**
  6866. * 获取编辑器的内容。 可以通过参数定义编辑器内置的判空规则
  6867. * @method getContent
  6868. * @param { Function } fn 自定的判空规则, 要求该方法返回一个boolean类型的值,
  6869. * 代表当前编辑器的内容是否空,
  6870. * 如果返回true, 则该方法将直接返回空字符串;如果返回false,则编辑器将返回
  6871. * 经过内置过滤规则处理后的内容。
  6872. * @remind 该方法在处理包含有初始化内容的时候能起到很好的作用。
  6873. * @warning 该方法获取到的是经过编辑器内置的过滤规则进行过滤后得到的内容
  6874. * @return { String } 编辑器的内容字符串
  6875. * @example
  6876. * ```javascript
  6877. * // editor 是一个编辑器的实例
  6878. * var content = editor.getContent( function ( editor ) {
  6879. * return editor.body.innerHTML === '欢迎使用UEditor'; //返回空字符串
  6880. * } );
  6881. * ```
  6882. */
  6883. getContent: function (cmd, fn,notSetCursor,ignoreBlank,formatter) {
  6884. var me = this;
  6885. if (cmd && utils.isFunction(cmd)) {
  6886. fn = cmd;
  6887. cmd = '';
  6888. }
  6889. if (fn ? !fn() : !this.hasContents()) {
  6890. return '';
  6891. }
  6892. me.fireEvent('beforegetcontent');
  6893. var root = UE.htmlparser(me.body.innerHTML,ignoreBlank);
  6894. me.filterOutputRule(root);
  6895. me.fireEvent('aftergetcontent', cmd,root);
  6896. return root.toHtml(formatter);
  6897. },
  6898. /**
  6899. * 取得完整的html代码,可以直接显示成完整的html文档
  6900. * @method getAllHtml
  6901. * @return { String } 编辑器的内容html文档字符串
  6902. * @eaxmple
  6903. * ```javascript
  6904. * editor.getAllHtml(); //返回格式大致是: <html><head>...</head><body>...</body></html>
  6905. * ```
  6906. */
  6907. getAllHtml: function () {
  6908. var me = this,
  6909. headHtml = [],
  6910. html = '';
  6911. me.fireEvent('getAllHtml', headHtml);
  6912. if (browser.ie && browser.version > 8) {
  6913. var headHtmlForIE9 = '';
  6914. utils.each(me.document.styleSheets, function (si) {
  6915. headHtmlForIE9 += ( si.href ? '<link rel="stylesheet" type="text/css" href="' + si.href + '" />' : '<style>' + si.cssText + '</style>');
  6916. });
  6917. utils.each(me.document.getElementsByTagName('script'), function (si) {
  6918. headHtmlForIE9 += si.outerHTML;
  6919. });
  6920. }
  6921. return '<html><head>' + (me.options.charset ? '<meta http-equiv="Content-Type" content="text/html; charset=' + me.options.charset + '"/>' : '')
  6922. + (headHtmlForIE9 || me.document.getElementsByTagName('head')[0].innerHTML) + headHtml.join('\n') + '</head>'
  6923. + '<body ' + (ie && browser.version < 9 ? 'class="view"' : '') + '>' + me.getContent(null, null, true) + '</body></html>';
  6924. },
  6925. /**
  6926. * 得到编辑器的纯文本内容,但会保留段落格式
  6927. * @method getPlainTxt
  6928. * @return { String } 编辑器带段落格式的纯文本内容字符串
  6929. * @example
  6930. * ```javascript
  6931. * //编辑器html内容:<p><strong>1</strong></p><p><strong>2</strong></p>
  6932. * console.log(editor.getPlainTxt()); //输出:"1\n2\n
  6933. * ```
  6934. */
  6935. getPlainTxt: function () {
  6936. var reg = new RegExp(domUtils.fillChar, 'g'),
  6937. html = this.body.innerHTML.replace(/[\n\r]/g, '');//ie要先去了\n在处理
  6938. html = html.replace(/<(p|div)[^>]*>(<br\/?>|&nbsp;)<\/\1>/gi, '\n')
  6939. .replace(/<br\/?>/gi, '\n')
  6940. .replace(/<[^>/]+>/g, '')
  6941. .replace(/(\n)?<\/([^>]+)>/g, function (a, b, c) {
  6942. return dtd.$block[c] ? '\n' : b ? b : '';
  6943. });
  6944. //取出来的空格会有c2a0会变成乱码,处理这种情况\u00a0
  6945. return html.replace(reg, '').replace(/\u00a0/g, ' ').replace(/&nbsp;/g, ' ');
  6946. },
  6947. /**
  6948. * 获取编辑器中的纯文本内容,没有段落格式
  6949. * @method getContentTxt
  6950. * @return { String } 编辑器不带段落格式的纯文本内容字符串
  6951. * @example
  6952. * ```javascript
  6953. * //编辑器html内容:<p><strong>1</strong></p><p><strong>2</strong></p>
  6954. * console.log(editor.getPlainTxt()); //输出:"12
  6955. * ```
  6956. */
  6957. getContentTxt: function () {
  6958. var reg = new RegExp(domUtils.fillChar, 'g');
  6959. //取出来的空格会有c2a0会变成乱码,处理这种情况\u00a0
  6960. return this.body[browser.ie ? 'innerText' : 'textContent'].replace(reg, '').replace(/\u00a0/g, ' ');
  6961. },
  6962. /**
  6963. * 设置编辑器的内容,可修改编辑器当前的html内容
  6964. * @method setContent
  6965. * @warning 通过该方法插入的内容,是经过编辑器内置的过滤规则进行过滤后得到的内容
  6966. * @warning 该方法会触发selectionchange事件
  6967. * @param { String } html 要插入的html内容
  6968. * @example
  6969. * ```javascript
  6970. * editor.getContent('<p>test</p>');
  6971. * ```
  6972. */
  6973. /**
  6974. * 设置编辑器的内容,可修改编辑器当前的html内容
  6975. * @method setContent
  6976. * @warning 通过该方法插入的内容,是经过编辑器内置的过滤规则进行过滤后得到的内容
  6977. * @warning 该方法会触发selectionchange事件
  6978. * @param { String } html 要插入的html内容
  6979. * @param { Boolean } isAppendTo 若传入true,不清空原来的内容,在最后插入内容,否则,清空内容再插入
  6980. * @example
  6981. * ```javascript
  6982. * //假设设置前的编辑器内容是 <p>old text</p>
  6983. * editor.setContent('<p>new text</p>', true); //插入的结果是<p>old text</p><p>new text</p>
  6984. * ```
  6985. */
  6986. setContent: function (html, isAppendTo, notFireSelectionchange) {
  6987. var me = this;
  6988. me.fireEvent('beforesetcontent', html);
  6989. var root = UE.htmlparser(html);
  6990. me.filterInputRule(root);
  6991. html = root.toHtml();
  6992. me.body.innerHTML = (isAppendTo ? me.body.innerHTML : '') + html;
  6993. function isCdataDiv(node){
  6994. return node.tagName == 'DIV' && node.getAttribute('cdata_tag');
  6995. }
  6996. //给文本或者inline节点套p标签
  6997. if (me.options.enterTag == 'p') {
  6998. var child = this.body.firstChild, tmpNode;
  6999. if (!child || child.nodeType == 1 &&
  7000. (dtd.$cdata[child.tagName] || isCdataDiv(child) ||
  7001. domUtils.isCustomeNode(child)
  7002. )
  7003. && child === this.body.lastChild) {
  7004. this.body.innerHTML = '<p>' + (browser.ie ? '&nbsp;' : '<br/>') + '</p>' + this.body.innerHTML;
  7005. } else {
  7006. var p = me.document.createElement('p');
  7007. while (child) {
  7008. while (child && (child.nodeType == 3 || child.nodeType == 1 && dtd.p[child.tagName] && !dtd.$cdata[child.tagName])) {
  7009. tmpNode = child.nextSibling;
  7010. p.appendChild(child);
  7011. child = tmpNode;
  7012. }
  7013. if (p.firstChild) {
  7014. if (!child) {
  7015. me.body.appendChild(p);
  7016. break;
  7017. } else {
  7018. child.parentNode.insertBefore(p, child);
  7019. p = me.document.createElement('p');
  7020. }
  7021. }
  7022. child = child.nextSibling;
  7023. }
  7024. }
  7025. }
  7026. me.fireEvent('aftersetcontent');
  7027. me.fireEvent('contentchange');
  7028. !notFireSelectionchange && me._selectionChange();
  7029. //清除保存的选区
  7030. me._bakRange = me._bakIERange = me._bakNativeRange = null;
  7031. //trace:1742 setContent后gecko能得到焦点问题
  7032. var geckoSel;
  7033. if (browser.gecko && (geckoSel = this.selection.getNative())) {
  7034. geckoSel.removeAllRanges();
  7035. }
  7036. if(me.options.autoSyncData){
  7037. me.form && setValue(me.form,me);
  7038. }
  7039. },
  7040. /**
  7041. * 让编辑器获得焦点,默认focus到编辑器头部
  7042. * @method focus
  7043. * @example
  7044. * ```javascript
  7045. * editor.focus()
  7046. * ```
  7047. */
  7048. /**
  7049. * 让编辑器获得焦点,toEnd确定focus位置
  7050. * @method focus
  7051. * @param { Boolean } toEnd 默认focus到编辑器头部,toEnd为true时focus到内容尾部
  7052. * @example
  7053. * ```javascript
  7054. * editor.focus(true)
  7055. * ```
  7056. */
  7057. focus: function (toEnd) {
  7058. try {
  7059. var me = this,
  7060. rng = me.selection.getRange();
  7061. if (toEnd) {
  7062. var node = me.body.lastChild;
  7063. if(node && node.nodeType == 1 && !dtd.$empty[node.tagName]){
  7064. if(domUtils.isEmptyBlock(node)){
  7065. rng.setStartAtFirst(node)
  7066. }else{
  7067. rng.setStartAtLast(node)
  7068. }
  7069. rng.collapse(true);
  7070. }
  7071. rng.setCursor(true);
  7072. } else {
  7073. if(!rng.collapsed && domUtils.isBody(rng.startContainer) && rng.startOffset == 0){
  7074. var node = me.body.firstChild;
  7075. if(node && node.nodeType == 1 && !dtd.$empty[node.tagName]){
  7076. rng.setStartAtFirst(node).collapse(true);
  7077. }
  7078. }
  7079. rng.select(true);
  7080. }
  7081. this.fireEvent('focus selectionchange');
  7082. } catch (e) {
  7083. }
  7084. },
  7085. isFocus:function(){
  7086. return this.selection.isFocus();
  7087. },
  7088. blur:function(){
  7089. var sel = this.selection.getNative();
  7090. if(sel.empty && browser.ie){
  7091. var nativeRng = document.body.createTextRange();
  7092. nativeRng.moveToElementText(document.body);
  7093. nativeRng.collapse(true);
  7094. nativeRng.select();
  7095. sel.empty()
  7096. }else{
  7097. sel.removeAllRanges()
  7098. }
  7099. //this.fireEvent('blur selectionchange');
  7100. },
  7101. /**
  7102. * 初始化UE事件及部分事件代理
  7103. * @method _initEvents
  7104. * @private
  7105. */
  7106. _initEvents: function () {
  7107. var me = this,
  7108. doc = me.document,
  7109. win = me.window;
  7110. me._proxyDomEvent = utils.bind(me._proxyDomEvent, me);
  7111. domUtils.on(doc, ['click', 'contextmenu', 'mousedown', 'keydown', 'keyup', 'keypress', 'mouseup', 'mouseover', 'mouseout', 'selectstart'], me._proxyDomEvent);
  7112. domUtils.on(win, ['focus', 'blur'], me._proxyDomEvent);
  7113. domUtils.on(me.body,'drop',function(e){
  7114. //阻止ff下默认的弹出新页面打开图片
  7115. if(browser.gecko && e.stopPropagation) { e.stopPropagation(); }
  7116. me.fireEvent('contentchange')
  7117. });
  7118. domUtils.on(doc, ['mouseup', 'keydown'], function (evt) {
  7119. //特殊键不触发selectionchange
  7120. if (evt.type == 'keydown' && (evt.ctrlKey || evt.metaKey || evt.shiftKey || evt.altKey)) {
  7121. return;
  7122. }
  7123. if (evt.button == 2)return;
  7124. me._selectionChange(250, evt);
  7125. });
  7126. },
  7127. /**
  7128. * 触发事件代理
  7129. * @method _proxyDomEvent
  7130. * @private
  7131. * @return { * } fireEvent的返回值
  7132. * @see UE.EventBase:fireEvent(String)
  7133. */
  7134. _proxyDomEvent: function (evt) {
  7135. if(this.fireEvent('before' + evt.type.replace(/^on/, '').toLowerCase()) === false){
  7136. return false;
  7137. }
  7138. if(this.fireEvent(evt.type.replace(/^on/, ''), evt) === false){
  7139. return false;
  7140. }
  7141. return this.fireEvent('after' + evt.type.replace(/^on/, '').toLowerCase())
  7142. },
  7143. /**
  7144. * 变化选区
  7145. * @method _selectionChange
  7146. * @private
  7147. */
  7148. _selectionChange: function (delay, evt) {
  7149. var me = this;
  7150. //有光标才做selectionchange 为了解决未focus时点击source不能触发更改工具栏状态的问题(source命令notNeedUndo=1)
  7151. // if ( !me.selection.isFocus() ){
  7152. // return;
  7153. // }
  7154. var hackForMouseUp = false;
  7155. var mouseX, mouseY;
  7156. if (browser.ie && browser.version < 9 && evt && evt.type == 'mouseup') {
  7157. var range = this.selection.getRange();
  7158. if (!range.collapsed) {
  7159. hackForMouseUp = true;
  7160. mouseX = evt.clientX;
  7161. mouseY = evt.clientY;
  7162. }
  7163. }
  7164. clearTimeout(_selectionChangeTimer);
  7165. _selectionChangeTimer = setTimeout(function () {
  7166. if (!me.selection || !me.selection.getNative()) {
  7167. return;
  7168. }
  7169. //修复一个IE下的bug: 鼠标点击一段已选择的文本中间时,可能在mouseup后的一段时间内取到的range是在selection的type为None下的错误值.
  7170. //IE下如果用户是拖拽一段已选择文本,则不会触发mouseup事件,所以这里的特殊处理不会对其有影响
  7171. var ieRange;
  7172. if (hackForMouseUp && me.selection.getNative().type == 'None') {
  7173. ieRange = me.document.body.createTextRange();
  7174. try {
  7175. ieRange.moveToPoint(mouseX, mouseY);
  7176. } catch (ex) {
  7177. ieRange = null;
  7178. }
  7179. }
  7180. var bakGetIERange;
  7181. if (ieRange) {
  7182. bakGetIERange = me.selection.getIERange;
  7183. me.selection.getIERange = function () {
  7184. return ieRange;
  7185. };
  7186. }
  7187. me.selection.cache();
  7188. if (bakGetIERange) {
  7189. me.selection.getIERange = bakGetIERange;
  7190. }
  7191. if (me.selection._cachedRange && me.selection._cachedStartElement) {
  7192. me.fireEvent('beforeselectionchange');
  7193. // 第二个参数causeByUi为true代表由用户交互造成的selectionchange.
  7194. me.fireEvent('selectionchange', !!evt);
  7195. me.fireEvent('afterselectionchange');
  7196. me.selection.clear();
  7197. }
  7198. }, delay || 50);
  7199. },
  7200. /**
  7201. * 执行编辑命令
  7202. * @method _callCmdFn
  7203. * @private
  7204. * @param { String } fnName 函数名称
  7205. * @param { * } args 传给命令函数的参数
  7206. * @return { * } 返回命令函数运行的返回值
  7207. */
  7208. _callCmdFn: function (fnName, args) {
  7209. var cmdName = args[0].toLowerCase(),
  7210. cmd, cmdFn;
  7211. cmd = this.commands[cmdName] || UE.commands[cmdName];
  7212. cmdFn = cmd && cmd[fnName];
  7213. //没有querycommandstate或者没有command的都默认返回0
  7214. if ((!cmd || !cmdFn) && fnName == 'queryCommandState') {
  7215. return 0;
  7216. } else if (cmdFn) {
  7217. return cmdFn.apply(this, args);
  7218. }
  7219. },
  7220. /**
  7221. * 执行编辑命令cmdName,完成富文本编辑效果
  7222. * @method execCommand
  7223. * @param { String } cmdName 需要执行的命令
  7224. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  7225. * @return { * } 返回命令函数运行的返回值
  7226. * @example
  7227. * ```javascript
  7228. * editor.execCommand(cmdName);
  7229. * ```
  7230. */
  7231. execCommand: function (cmdName) {
  7232. cmdName = cmdName.toLowerCase();
  7233. var me = this,
  7234. result,
  7235. cmd = me.commands[cmdName] || UE.commands[cmdName];
  7236. if (!cmd || !cmd.execCommand) {
  7237. return null;
  7238. }
  7239. if (!cmd.notNeedUndo && !me.__hasEnterExecCommand) {
  7240. me.__hasEnterExecCommand = true;
  7241. if (me.queryCommandState.apply(me,arguments) != -1) {
  7242. me.fireEvent('saveScene');
  7243. me.fireEvent.apply(me, ['beforeexeccommand', cmdName].concat(arguments));
  7244. result = this._callCmdFn('execCommand', arguments);
  7245. //保存场景时,做了内容对比,再看是否进行contentchange触发,这里多触发了一次,去掉
  7246. // (!cmd.ignoreContentChange && !me._ignoreContentChange) && me.fireEvent('contentchange');
  7247. me.fireEvent.apply(me, ['afterexeccommand', cmdName].concat(arguments));
  7248. me.fireEvent('saveScene');
  7249. }
  7250. me.__hasEnterExecCommand = false;
  7251. } else {
  7252. result = this._callCmdFn('execCommand', arguments);
  7253. (!me.__hasEnterExecCommand && !cmd.ignoreContentChange && !me._ignoreContentChange) && me.fireEvent('contentchange')
  7254. }
  7255. (!me.__hasEnterExecCommand && !cmd.ignoreContentChange && !me._ignoreContentChange) && me._selectionChange();
  7256. return result;
  7257. },
  7258. /**
  7259. * 根据传入的command命令,查选编辑器当前的选区,返回命令的状态
  7260. * @method queryCommandState
  7261. * @param { String } cmdName 需要查询的命令名称
  7262. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  7263. * @return { Number } number 返回放前命令的状态,返回值三种情况:(-1|0|1)
  7264. * @example
  7265. * ```javascript
  7266. * editor.queryCommandState(cmdName) => (-1|0|1)
  7267. * ```
  7268. * @see COMMAND.LIST
  7269. */
  7270. queryCommandState: function (cmdName) {
  7271. return this._callCmdFn('queryCommandState', arguments);
  7272. },
  7273. /**
  7274. * 根据传入的command命令,查选编辑器当前的选区,根据命令返回相关的值
  7275. * @method queryCommandValue
  7276. * @param { String } cmdName 需要查询的命令名称
  7277. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  7278. * @remind 只有部分插件有此方法
  7279. * @return { * } 返回每个命令特定的当前状态值
  7280. * @grammar editor.queryCommandValue(cmdName) => {*}
  7281. * @see COMMAND.LIST
  7282. */
  7283. queryCommandValue: function (cmdName) {
  7284. return this._callCmdFn('queryCommandValue', arguments);
  7285. },
  7286. /**
  7287. * 检查编辑区域中是否有内容
  7288. * @method hasContents
  7289. * @remind 默认有文本内容,或者有以下节点都不认为是空
  7290. * table,ul,ol,dl,iframe,area,base,col,hr,img,embed,input,link,meta,param
  7291. * @return { Boolean } 检查有内容返回true,否则返回false
  7292. * @example
  7293. * ```javascript
  7294. * editor.hasContents()
  7295. * ```
  7296. */
  7297. /**
  7298. * 检查编辑区域中是否有内容,若包含参数tags中的节点类型,直接返回true
  7299. * @method hasContents
  7300. * @param { Array } tags 传入数组判断时用到的节点类型
  7301. * @return { Boolean } 若文档中包含tags数组里对应的tag,返回true,否则返回false
  7302. * @example
  7303. * ```javascript
  7304. * editor.hasContents(['span']);
  7305. * ```
  7306. */
  7307. hasContents: function (tags) {
  7308. if (tags) {
  7309. for (var i = 0, ci; ci = tags[i++];) {
  7310. if (this.document.getElementsByTagName(ci).length > 0) {
  7311. return true;
  7312. }
  7313. }
  7314. }
  7315. if (!domUtils.isEmptyBlock(this.body)) {
  7316. return true
  7317. }
  7318. //随时添加,定义的特殊标签如果存在,不能认为是空
  7319. tags = ['div'];
  7320. for (i = 0; ci = tags[i++];) {
  7321. var nodes = domUtils.getElementsByTagName(this.document, ci);
  7322. for (var n = 0, cn; cn = nodes[n++];) {
  7323. if (domUtils.isCustomeNode(cn)) {
  7324. return true;
  7325. }
  7326. }
  7327. }
  7328. return false;
  7329. },
  7330. /**
  7331. * 重置编辑器,可用来做多个tab使用同一个编辑器实例
  7332. * @method reset
  7333. * @remind 此方法会清空编辑器内容,清空回退列表,会触发reset事件
  7334. * @example
  7335. * ```javascript
  7336. * editor.reset()
  7337. * ```
  7338. */
  7339. reset: function () {
  7340. this.fireEvent('reset');
  7341. },
  7342. /**
  7343. * 设置当前编辑区域可以编辑
  7344. * @method setEnabled
  7345. * @example
  7346. * ```javascript
  7347. * editor.setEnabled()
  7348. * ```
  7349. */
  7350. setEnabled: function () {
  7351. var me = this, range;
  7352. if (me.body.contentEditable == 'false') {
  7353. me.body.contentEditable = true;
  7354. range = me.selection.getRange();
  7355. //有可能内容丢失了
  7356. try {
  7357. range.moveToBookmark(me.lastBk);
  7358. delete me.lastBk
  7359. } catch (e) {
  7360. range.setStartAtFirst(me.body).collapse(true)
  7361. }
  7362. range.select(true);
  7363. if (me.bkqueryCommandState) {
  7364. me.queryCommandState = me.bkqueryCommandState;
  7365. delete me.bkqueryCommandState;
  7366. }
  7367. if (me.bkqueryCommandValue) {
  7368. me.queryCommandValue = me.bkqueryCommandValue;
  7369. delete me.bkqueryCommandValue;
  7370. }
  7371. me.fireEvent('selectionchange');
  7372. }
  7373. },
  7374. enable: function () {
  7375. return this.setEnabled();
  7376. },
  7377. /** 设置当前编辑区域不可编辑
  7378. * @method setDisabled
  7379. */
  7380. /** 设置当前编辑区域不可编辑,except中的命令除外
  7381. * @method setDisabled
  7382. * @param { String } except 例外命令的字符串
  7383. * @remind 即使设置了disable,此处配置的例外命令仍然可以执行
  7384. * @example
  7385. * ```javascript
  7386. * editor.setDisabled('bold'); //禁用工具栏中除加粗之外的所有功能
  7387. * ```
  7388. */
  7389. /** 设置当前编辑区域不可编辑,except中的命令除外
  7390. * @method setDisabled
  7391. * @param { Array } except 例外命令的字符串数组,数组中的命令仍然可以执行
  7392. * @remind 即使设置了disable,此处配置的例外命令仍然可以执行
  7393. * @example
  7394. * ```javascript
  7395. * editor.setDisabled(['bold','insertimage']); //禁用工具栏中除加粗和插入图片之外的所有功能
  7396. * ```
  7397. */
  7398. setDisabled: function (except) {
  7399. var me = this;
  7400. except = except ? utils.isArray(except) ? except : [except] : [];
  7401. if (me.body.contentEditable == 'true') {
  7402. if (!me.lastBk) {
  7403. me.lastBk = me.selection.getRange().createBookmark(true);
  7404. }
  7405. me.body.contentEditable = false;
  7406. me.bkqueryCommandState = me.queryCommandState;
  7407. me.bkqueryCommandValue = me.queryCommandValue;
  7408. me.queryCommandState = function (type) {
  7409. if (utils.indexOf(except, type) != -1) {
  7410. return me.bkqueryCommandState.apply(me, arguments);
  7411. }
  7412. return -1;
  7413. };
  7414. me.queryCommandValue = function (type) {
  7415. if (utils.indexOf(except, type) != -1) {
  7416. return me.bkqueryCommandValue.apply(me, arguments);
  7417. }
  7418. return null;
  7419. };
  7420. me.fireEvent('selectionchange');
  7421. }
  7422. },
  7423. disable: function (except) {
  7424. return this.setDisabled(except);
  7425. },
  7426. /**
  7427. * 设置默认内容
  7428. * @method _setDefaultContent
  7429. * @private
  7430. * @param { String } cont 要存入的内容
  7431. */
  7432. _setDefaultContent: function () {
  7433. function clear() {
  7434. var me = this;
  7435. if (me.document.getElementById('initContent')) {
  7436. me.body.innerHTML = '<p>' + (ie ? '' : '<br/>') + '</p>';
  7437. me.removeListener('firstBeforeExecCommand focus', clear);
  7438. setTimeout(function () {
  7439. me.focus();
  7440. me._selectionChange();
  7441. }, 0)
  7442. }
  7443. }
  7444. return function (cont) {
  7445. var me = this;
  7446. me.body.innerHTML = '<p id="initContent">' + cont + '</p>';
  7447. me.addListener('firstBeforeExecCommand focus', clear);
  7448. }
  7449. }(),
  7450. /**
  7451. * 显示编辑器
  7452. * @method setShow
  7453. * @example
  7454. * ```javascript
  7455. * editor.setShow()
  7456. * ```
  7457. */
  7458. setShow: function () {
  7459. var me = this, range = me.selection.getRange();
  7460. if (me.container.style.display == 'none') {
  7461. //有可能内容丢失了
  7462. try {
  7463. range.moveToBookmark(me.lastBk);
  7464. delete me.lastBk
  7465. } catch (e) {
  7466. range.setStartAtFirst(me.body).collapse(true)
  7467. }
  7468. //ie下focus实效,所以做了个延迟
  7469. setTimeout(function () {
  7470. range.select(true);
  7471. }, 100);
  7472. me.container.style.display = '';
  7473. }
  7474. },
  7475. show: function () {
  7476. return this.setShow();
  7477. },
  7478. /**
  7479. * 隐藏编辑器
  7480. * @method setHide
  7481. * @example
  7482. * ```javascript
  7483. * editor.setHide()
  7484. * ```
  7485. */
  7486. setHide: function () {
  7487. var me = this;
  7488. if (!me.lastBk) {
  7489. me.lastBk = me.selection.getRange().createBookmark(true);
  7490. }
  7491. me.container.style.display = 'none'
  7492. },
  7493. hide: function () {
  7494. return this.setHide();
  7495. },
  7496. /**
  7497. * 根据指定的路径,获取对应的语言资源
  7498. * @method getLang
  7499. * @param { String } path 路径根据的是lang目录下的语言文件的路径结构
  7500. * @return { Object | String } 根据路径返回语言资源的Json格式对象或者语言字符串
  7501. * @example
  7502. * ```javascript
  7503. * editor.getLang('contextMenu.delete'); //如果当前是中文,那返回是的是'删除'
  7504. * ```
  7505. */
  7506. getLang: function (path) {
  7507. var lang = UE.I18N[this.options.lang];
  7508. if (!lang) {
  7509. throw Error("not import language file");
  7510. }
  7511. path = (path || "").split(".");
  7512. for (var i = 0, ci; ci = path[i++];) {
  7513. lang = lang[ci];
  7514. if (!lang)break;
  7515. }
  7516. return lang;
  7517. },
  7518. /**
  7519. * 计算编辑器html内容字符串的长度
  7520. * @method getContentLength
  7521. * @return { Number } 返回计算的长度
  7522. * @example
  7523. * ```javascript
  7524. * //编辑器html内容<p><strong>132</strong></p>
  7525. * editor.getContentLength() //返回27
  7526. * ```
  7527. */
  7528. /**
  7529. * 计算编辑器当前纯文本内容的长度
  7530. * @method getContentLength
  7531. * @param { Boolean } ingoneHtml 传入true时,只按照纯文本来计算
  7532. * @return { Number } 返回计算的长度,内容中有hr/img/iframe标签,长度加1
  7533. * @example
  7534. * ```javascript
  7535. * //编辑器html内容<p><strong>132</strong></p>
  7536. * editor.getContentLength() //返回3
  7537. * ```
  7538. */
  7539. getContentLength: function (ingoneHtml, tagNames) {
  7540. var count = this.getContent(false,false,true).length;
  7541. if (ingoneHtml) {
  7542. tagNames = (tagNames || []).concat([ 'hr', 'img', 'iframe']);
  7543. count = this.getContentTxt().replace(/[\t\r\n]+/g, '').length;
  7544. for (var i = 0, ci; ci = tagNames[i++];) {
  7545. count += this.document.getElementsByTagName(ci).length;
  7546. }
  7547. }
  7548. return count;
  7549. },
  7550. /**
  7551. * 注册输入过滤规则
  7552. * @method addInputRule
  7553. * @param { Function } rule 要添加的过滤规则
  7554. * @example
  7555. * ```javascript
  7556. * editor.addInputRule(function(root){
  7557. * $.each(root.getNodesByTagName('div'),function(i,node){
  7558. * node.tagName="p";
  7559. * });
  7560. * });
  7561. * ```
  7562. */
  7563. addInputRule: function (rule) {
  7564. this.inputRules.push(rule);
  7565. },
  7566. /**
  7567. * 执行注册的过滤规则
  7568. * @method filterInputRule
  7569. * @param { UE.uNode } root 要过滤的uNode节点
  7570. * @remind 执行editor.setContent方法和执行'inserthtml'命令后,会运行该过滤函数
  7571. * @example
  7572. * ```javascript
  7573. * editor.filterInputRule(editor.body);
  7574. * ```
  7575. * @see UE.Editor:addInputRule
  7576. */
  7577. filterInputRule: function (root) {
  7578. for (var i = 0, ci; ci = this.inputRules[i++];) {
  7579. ci.call(this, root)
  7580. }
  7581. },
  7582. /**
  7583. * 注册输出过滤规则
  7584. * @method addOutputRule
  7585. * @param { Function } rule 要添加的过滤规则
  7586. * @example
  7587. * ```javascript
  7588. * editor.addOutputRule(function(root){
  7589. * $.each(root.getNodesByTagName('p'),function(i,node){
  7590. * node.tagName="div";
  7591. * });
  7592. * });
  7593. * ```
  7594. */
  7595. addOutputRule: function (rule) {
  7596. this.outputRules.push(rule)
  7597. },
  7598. /**
  7599. * 根据输出过滤规则,过滤编辑器内容
  7600. * @method filterOutputRule
  7601. * @remind 执行editor.getContent方法的时候,会先运行该过滤函数
  7602. * @param { UE.uNode } root 要过滤的uNode节点
  7603. * @example
  7604. * ```javascript
  7605. * editor.filterOutputRule(editor.body);
  7606. * ```
  7607. * @see UE.Editor:addOutputRule
  7608. */
  7609. filterOutputRule: function (root) {
  7610. for (var i = 0, ci; ci = this.outputRules[i++];) {
  7611. ci.call(this, root)
  7612. }
  7613. },
  7614. /**
  7615. * 根据action名称获取请求的路径
  7616. * @method getActionUrl
  7617. * @remind 假如没有设置serverUrl,会根据imageUrl设置默认的controller路径
  7618. * @param { String } action action名称
  7619. * @example
  7620. * ```javascript
  7621. * editor.getActionUrl('config'); //返回 "/ueditor/php/controller.php?action=config"
  7622. * editor.getActionUrl('image'); //返回 "/ueditor/php/controller.php?action=uplaodimage"
  7623. * editor.getActionUrl('scrawl'); //返回 "/ueditor/php/controller.php?action=uplaodscrawl"
  7624. * editor.getActionUrl('imageManager'); //返回 "/ueditor/php/controller.php?action=listimage"
  7625. * ```
  7626. */
  7627. getActionUrl: function(action){
  7628. var actionName = this.getOpt(action) || action,
  7629. imageUrl = this.getOpt('imageUrl'),
  7630. serverUrl = this.getOpt('serverUrl');
  7631. if(!serverUrl && imageUrl) {
  7632. serverUrl = imageUrl.replace(/^(.*[\/]).+([\.].+)$/, '$1controller$2');
  7633. }
  7634. if(serverUrl) {
  7635. serverUrl = serverUrl + (serverUrl.indexOf('?') == -1 ? '?':'&') + 'action=' + (actionName || '');
  7636. return utils.formatUrl(serverUrl);
  7637. } else {
  7638. return '';
  7639. }
  7640. }
  7641. };
  7642. utils.inherits(Editor, EventBase);
  7643. })();
  7644. // core/Editor.defaultoptions.js
  7645. //维护编辑器一下默认的不在插件中的配置项
  7646. UE.Editor.defaultOptions = function(editor){
  7647. var _url = editor.options.UEDITOR_HOME_URL;
  7648. return {
  7649. isShow: true,
  7650. initialContent: '',
  7651. initialStyle:'',
  7652. autoClearinitialContent: false,
  7653. iframeCssUrl: _url + 'themes/iframe.css',
  7654. textarea: 'editorValue',
  7655. focus: false,
  7656. focusInEnd: true,
  7657. autoClearEmptyNode: true,
  7658. fullscreen: false,
  7659. readonly: false,
  7660. zIndex: 9999,
  7661. imagePopup: true,
  7662. enterTag: 'p',
  7663. customDomain: false,
  7664. lang: 'zh-cn',
  7665. langPath: _url + 'lang/',
  7666. theme: 'default',
  7667. themePath: _url + 'themes/',
  7668. allHtmlEnabled: false,
  7669. scaleEnabled: false,
  7670. tableNativeEditInFF: false,
  7671. autoSyncData : true,
  7672. fileNameFormat: '{time}{rand:6}'
  7673. }
  7674. };
  7675. // core/loadconfig.js
  7676. (function(){
  7677. UE.Editor.prototype.loadServerConfig = function(){
  7678. var me = this;
  7679. setTimeout(function(){
  7680. try{
  7681. me.options.imageUrl && me.setOpt('serverUrl', me.options.imageUrl.replace(/^(.*[\/]).+([\.].+)$/, '$1controller$2'));
  7682. var configUrl = me.getActionUrl('config'),
  7683. //isJsonp = utils.isCrossDomainUrl(configUrl);
  7684. isJsonp = false;
  7685. /* 发出ajax请求 */
  7686. me._serverConfigLoaded = false;
  7687. configUrl && UE.ajax.request(configUrl,{
  7688. 'method': 'GET',
  7689. 'dataType': isJsonp ? 'jsonp':'',
  7690. 'onsuccess':function(r){
  7691. try {
  7692. var config = isJsonp ? r:eval("("+r.responseText+")");
  7693. utils.extend(me.options, config);
  7694. me.fireEvent('serverConfigLoaded');
  7695. me._serverConfigLoaded = true;
  7696. } catch (e) {
  7697. showErrorMsg(me.getLang('loadconfigFormatError'));
  7698. }
  7699. },
  7700. 'onerror':function(){
  7701. showErrorMsg(me.getLang('loadconfigHttpError'));
  7702. }
  7703. });
  7704. } catch(e){
  7705. showErrorMsg(me.getLang('loadconfigError'));
  7706. }
  7707. });
  7708. function showErrorMsg(msg) {
  7709. console && console.error(msg);
  7710. //me.fireEvent('showMessage', {
  7711. // 'title': msg,
  7712. // 'type': 'error'
  7713. //});
  7714. }
  7715. };
  7716. UE.Editor.prototype.isServerConfigLoaded = function(){
  7717. var me = this;
  7718. return me._serverConfigLoaded || false;
  7719. };
  7720. UE.Editor.prototype.afterConfigReady = function(handler){
  7721. if (!handler || !utils.isFunction(handler)) return;
  7722. var me = this;
  7723. var readyHandler = function(){
  7724. handler.apply(me, arguments);
  7725. me.removeListener('serverConfigLoaded', readyHandler);
  7726. };
  7727. if (me.isServerConfigLoaded()) {
  7728. handler.call(me, 'serverConfigLoaded');
  7729. } else {
  7730. me.addListener('serverConfigLoaded', readyHandler);
  7731. }
  7732. };
  7733. })();
  7734. // core/ajax.js
  7735. /**
  7736. * @file
  7737. * @module UE.ajax
  7738. * @since 1.2.6.1
  7739. */
  7740. /**
  7741. * 提供对ajax请求的支持
  7742. * @module UE.ajax
  7743. */
  7744. UE.ajax = function() {
  7745. //创建一个ajaxRequest对象
  7746. var fnStr = 'XMLHttpRequest()';
  7747. try {
  7748. new ActiveXObject("Msxml2.XMLHTTP");
  7749. fnStr = 'ActiveXObject(\'Msxml2.XMLHTTP\')';
  7750. } catch (e) {
  7751. try {
  7752. new ActiveXObject("Microsoft.XMLHTTP");
  7753. fnStr = 'ActiveXObject(\'Microsoft.XMLHTTP\')'
  7754. } catch (e) {
  7755. }
  7756. }
  7757. var creatAjaxRequest = new Function('return new ' + fnStr);
  7758. /**
  7759. * 将json参数转化成适合ajax提交的参数列表
  7760. * @param json
  7761. */
  7762. function json2str(json) {
  7763. var strArr = [];
  7764. for (var i in json) {
  7765. //忽略默认的几个参数
  7766. if(i=="method" || i=="timeout" || i=="async" || i=="dataType" || i=="callback") continue;
  7767. //忽略控制
  7768. if(json[i] == undefined || json[i] == null) continue;
  7769. //传递过来的对象和函数不在提交之列
  7770. if (!((typeof json[i]).toLowerCase() == "function" || (typeof json[i]).toLowerCase() == "object")) {
  7771. strArr.push( encodeURIComponent(i) + "="+encodeURIComponent(json[i]) );
  7772. } else if (utils.isArray(json[i])) {
  7773. //支持传数组内容
  7774. for(var j = 0; j < json[i].length; j++) {
  7775. strArr.push( encodeURIComponent(i) + "[]="+encodeURIComponent(json[i][j]) );
  7776. }
  7777. }
  7778. }
  7779. return strArr.join("&");
  7780. }
  7781. function doAjax(url, ajaxOptions) {
  7782. var xhr = creatAjaxRequest(),
  7783. //是否超时
  7784. timeIsOut = false,
  7785. //默认参数
  7786. defaultAjaxOptions = {
  7787. method:"POST",
  7788. timeout:5000,
  7789. async:true,
  7790. data:{},//需要传递对象的话只能覆盖
  7791. onsuccess:function() {
  7792. },
  7793. onerror:function() {
  7794. }
  7795. };
  7796. if (typeof url === "object") {
  7797. ajaxOptions = url;
  7798. url = ajaxOptions.url;
  7799. }
  7800. if (!xhr || !url) return;
  7801. var ajaxOpts = ajaxOptions ? utils.extend(defaultAjaxOptions,ajaxOptions) : defaultAjaxOptions;
  7802. var submitStr = json2str(ajaxOpts); // { name:"Jim",city:"Beijing" } --> "name=Jim&city=Beijing"
  7803. //如果用户直接通过data参数传递json对象过来,则也要将此json对象转化为字符串
  7804. if (!utils.isEmptyObject(ajaxOpts.data)){
  7805. submitStr += (submitStr? "&":"") + json2str(ajaxOpts.data);
  7806. }
  7807. //超时检测
  7808. var timerID = setTimeout(function() {
  7809. if (xhr.readyState != 4) {
  7810. timeIsOut = true;
  7811. xhr.abort();
  7812. clearTimeout(timerID);
  7813. }
  7814. }, ajaxOpts.timeout);
  7815. var method = ajaxOpts.method.toUpperCase();
  7816. var str = url + (url.indexOf("?")==-1?"?":"&") + (method=="POST"?"":submitStr+ "&noCache=" + +new Date);
  7817. xhr.open(method, str, ajaxOpts.async);
  7818. xhr.onreadystatechange = function() {
  7819. if (xhr.readyState == 4) {
  7820. if (!timeIsOut && xhr.status == 200) {
  7821. ajaxOpts.onsuccess(xhr);
  7822. } else {
  7823. ajaxOpts.onerror(xhr);
  7824. }
  7825. }
  7826. };
  7827. xhr.setRequestHeader('Authorization', sessionStorage.getItem("token") );
  7828. if (method == "POST") {
  7829. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  7830. xhr.send(submitStr);
  7831. } else {
  7832. xhr.send(null);
  7833. }
  7834. }
  7835. function doJsonp(url, opts) {
  7836. var successhandler = opts.onsuccess || function(){},
  7837. scr = document.createElement('SCRIPT'),
  7838. options = opts || {},
  7839. charset = options['charset'],
  7840. callbackField = options['jsonp'] || 'callback',
  7841. callbackFnName,
  7842. timeOut = options['timeOut'] || 0,
  7843. timer,
  7844. reg = new RegExp('(\\?|&)' + callbackField + '=([^&]*)'),
  7845. matches;
  7846. if (utils.isFunction(successhandler)) {
  7847. callbackFnName = 'bd__editor__' + Math.floor(Math.random() * 2147483648).toString(36);
  7848. window[callbackFnName] = getCallBack(0);
  7849. } else if(utils.isString(successhandler)){
  7850. callbackFnName = successhandler;
  7851. } else {
  7852. if (matches = reg.exec(url)) {
  7853. callbackFnName = matches[2];
  7854. }
  7855. }
  7856. url = url.replace(reg, '\x241' + callbackField + '=' + callbackFnName);
  7857. if (url.search(reg) < 0) {
  7858. url += (url.indexOf('?') < 0 ? '?' : '&') + callbackField + '=' + callbackFnName;
  7859. }
  7860. var queryStr = json2str(opts); // { name:"Jim",city:"Beijing" } --> "name=Jim&city=Beijing"
  7861. //如果用户直接通过data参数传递json对象过来,则也要将此json对象转化为字符串
  7862. if (!utils.isEmptyObject(opts.data)){
  7863. queryStr += (queryStr? "&":"") + json2str(opts.data);
  7864. }
  7865. if (queryStr) {
  7866. url = url.replace(/\?/, '?' + queryStr + '&');
  7867. }
  7868. scr.onerror = getCallBack(1);
  7869. if( timeOut ){
  7870. timer = setTimeout(getCallBack(1), timeOut);
  7871. }
  7872. createScriptTag(scr, url, charset);
  7873. function createScriptTag(scr, url, charset) {
  7874. scr.setAttribute('type', 'text/javascript');
  7875. scr.setAttribute('defer', 'defer');
  7876. charset && scr.setAttribute('charset', charset);
  7877. scr.setAttribute('src', url);
  7878. document.getElementsByTagName('head')[0].appendChild(scr);
  7879. }
  7880. function getCallBack(onTimeOut){
  7881. return function(){
  7882. try {
  7883. if(onTimeOut){
  7884. options.onerror && options.onerror();
  7885. }else{
  7886. try{
  7887. clearTimeout(timer);
  7888. successhandler.apply(window, arguments);
  7889. } catch (e){}
  7890. }
  7891. } catch (exception) {
  7892. options.onerror && options.onerror.call(window, exception);
  7893. } finally {
  7894. options.oncomplete && options.oncomplete.apply(window, arguments);
  7895. scr.parentNode && scr.parentNode.removeChild(scr);
  7896. window[callbackFnName] = null;
  7897. try {
  7898. delete window[callbackFnName];
  7899. }catch(e){}
  7900. }
  7901. }
  7902. }
  7903. }
  7904. return {
  7905. /**
  7906. * 根据给定的参数项,向指定的url发起一个ajax请求。 ajax请求完成后,会根据请求结果调用相应回调: 如果请求
  7907. * 成功, 则调用onsuccess回调, 失败则调用 onerror 回调
  7908. * @method request
  7909. * @param { URLString } url ajax请求的url地址
  7910. * @param { Object } ajaxOptions ajax请求选项的键值对,支持的选项如下:
  7911. * @example
  7912. * ```javascript
  7913. * //向sayhello.php发起一个异步的Ajax GET请求, 请求超时时间为10s, 请求完成后执行相应的回调。
  7914. * UE.ajax.requeset( 'sayhello.php', {
  7915. *
  7916. * //请求方法。可选值: 'GET', 'POST',默认值是'POST'
  7917. * method: 'GET',
  7918. *
  7919. * //超时时间。 默认为5000, 单位是ms
  7920. * timeout: 10000,
  7921. *
  7922. * //是否是异步请求。 true为异步请求, false为同步请求
  7923. * async: true,
  7924. *
  7925. * //请求携带的数据。如果请求为GET请求, data会经过stringify后附加到请求url之后。
  7926. * data: {
  7927. * name: 'ueditor'
  7928. * },
  7929. *
  7930. * //请求成功后的回调, 该回调接受当前的XMLHttpRequest对象作为参数。
  7931. * onsuccess: function ( xhr ) {
  7932. * console.log( xhr.responseText );
  7933. * },
  7934. *
  7935. * //请求失败或者超时后的回调。
  7936. * onerror: function ( xhr ) {
  7937. * alert( 'Ajax请求失败' );
  7938. * }
  7939. *
  7940. * } );
  7941. * ```
  7942. */
  7943. /**
  7944. * 根据给定的参数项发起一个ajax请求, 参数项里必须包含一个url地址。 ajax请求完成后,会根据请求结果调用相应回调: 如果请求
  7945. * 成功, 则调用onsuccess回调, 失败则调用 onerror 回调。
  7946. * @method request
  7947. * @warning 如果在参数项里未提供一个key为“url”的地址值,则该请求将直接退出。
  7948. * @param { Object } ajaxOptions ajax请求选项的键值对,支持的选项如下:
  7949. * @example
  7950. * ```javascript
  7951. *
  7952. * //向sayhello.php发起一个异步的Ajax POST请求, 请求超时时间为5s, 请求完成后不执行任何回调。
  7953. * UE.ajax.requeset( 'sayhello.php', {
  7954. *
  7955. * //请求的地址, 该项是必须的。
  7956. * url: 'sayhello.php'
  7957. *
  7958. * } );
  7959. * ```
  7960. */
  7961. request:function(url, opts) {
  7962. if (opts && opts.dataType == 'jsonp') {
  7963. doJsonp(url, opts);
  7964. } else {
  7965. doAjax(url, opts);
  7966. }
  7967. },
  7968. getJSONP:function(url, data, fn) {
  7969. var opts = {
  7970. 'data': data,
  7971. 'oncomplete': fn
  7972. };
  7973. doJsonp(url, opts);
  7974. }
  7975. };
  7976. }();
  7977. // core/filterword.js
  7978. /**
  7979. * UE过滤word的静态方法
  7980. * @file
  7981. */
  7982. /**
  7983. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  7984. * @module UE
  7985. */
  7986. /**
  7987. * 根据传入html字符串过滤word
  7988. * @module UE
  7989. * @since 1.2.6.1
  7990. * @method filterWord
  7991. * @param { String } html html字符串
  7992. * @return { String } 已过滤后的结果字符串
  7993. * @example
  7994. * ```javascript
  7995. * UE.filterWord(html);
  7996. * ```
  7997. */
  7998. var filterWord = UE.filterWord = function () {
  7999. //是否是word过来的内容
  8000. function isWordDocument( str ) {
  8001. return /(class="?Mso|style="[^"]*\bmso\-|w:WordDocument|<(v|o):|lang=)/ig.test( str );
  8002. }
  8003. //去掉小数
  8004. function transUnit( v ) {
  8005. v = v.replace( /[\d.]+\w+/g, function ( m ) {
  8006. return utils.transUnitToPx(m);
  8007. } );
  8008. return v;
  8009. }
  8010. function filterPasteWord( str ) {
  8011. return str.replace(/[\t\r\n]+/g,' ')
  8012. .replace( /<!--[\s\S]*?-->/ig, "" )
  8013. //转换图片
  8014. .replace(/<v:shape [^>]*>[\s\S]*?.<\/v:shape>/gi,function(str){
  8015. //opera能自己解析出image所这里直接返回空
  8016. if(browser.opera){
  8017. return '';
  8018. }
  8019. try{
  8020. //有可能是bitmap占为图,无用,直接过滤掉,主要体现在粘贴excel表格中
  8021. if(/Bitmap/i.test(str)){
  8022. return '';
  8023. }
  8024. var width = str.match(/width:([ \d.]*p[tx])/i)[1],
  8025. height = str.match(/height:([ \d.]*p[tx])/i)[1],
  8026. src = str.match(/src=\s*"([^"]*)"/i)[1];
  8027. return '<img width="'+ transUnit(width) +'" height="'+transUnit(height) +'" src="' + src + '" />';
  8028. } catch(e){
  8029. return '';
  8030. }
  8031. })
  8032. //针对wps添加的多余标签处理
  8033. .replace(/<\/?div[^>]*>/g,'')
  8034. //去掉多余的属性
  8035. .replace( /v:\w+=(["']?)[^'"]+\1/g, '' )
  8036. .replace( /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|xml|meta|link|style|\w+:\w+)(?=[\s\/>]))[^>]*>/gi, "" )
  8037. .replace( /<p [^>]*class="?MsoHeading"?[^>]*>(.*?)<\/p>/gi, "<p><strong>$1</strong></p>" )
  8038. //去掉多余的属性
  8039. .replace( /\s+(class|lang|align)\s*=\s*(['"]?)([\w-]+)\2/ig, function(str,name,marks,val){
  8040. //保留list的标示
  8041. return name == 'class' && val == 'MsoListParagraph' ? str : ''
  8042. })
  8043. //清除多余的font/span不能匹配&nbsp;有可能是空格
  8044. .replace( /<(font|span)[^>]*>(\s*)<\/\1>/gi, function(a,b,c){
  8045. return c.replace(/[\t\r\n ]+/g,' ')
  8046. })
  8047. //处理style的问题
  8048. .replace( /(<[a-z][^>]*)\sstyle=(["'])([^\2]*?)\2/gi, function( str, tag, tmp, style ) {
  8049. var n = [],
  8050. s = style.replace( /^\s+|\s+$/, '' )
  8051. .replace(/&#39;/g,'\'')
  8052. .replace( /&quot;/gi, "'" )
  8053. .replace(/[\d.]+(cm|pt)/g,function(str){
  8054. return utils.transUnitToPx(str)
  8055. })
  8056. .split( /;\s*/g );
  8057. for ( var i = 0,v; v = s[i];i++ ) {
  8058. var name, value,
  8059. parts = v.split( ":" );
  8060. if ( parts.length == 2 ) {
  8061. name = parts[0].toLowerCase();
  8062. value = parts[1].toLowerCase();
  8063. if(/^(background)\w*/.test(name) && value.replace(/(initial|\s)/g,'').length == 0
  8064. ||
  8065. /^(margin)\w*/.test(name) && /^0\w+$/.test(value)
  8066. ){
  8067. continue;
  8068. }
  8069. switch ( name ) {
  8070. case "mso-padding-alt":
  8071. case "mso-padding-top-alt":
  8072. case "mso-padding-right-alt":
  8073. case "mso-padding-bottom-alt":
  8074. case "mso-padding-left-alt":
  8075. case "mso-margin-alt":
  8076. case "mso-margin-top-alt":
  8077. case "mso-margin-right-alt":
  8078. case "mso-margin-bottom-alt":
  8079. case "mso-margin-left-alt":
  8080. //ie下会出现挤到一起的情况
  8081. //case "mso-table-layout-alt":
  8082. case "mso-height":
  8083. case "mso-width":
  8084. case "mso-vertical-align-alt":
  8085. //trace:1819 ff下会解析出padding在table上
  8086. if(!/<table/.test(tag))
  8087. n[i] = name.replace( /^mso-|-alt$/g, "" ) + ":" + transUnit( value );
  8088. continue;
  8089. case "horiz-align":
  8090. n[i] = "text-align:" + value;
  8091. continue;
  8092. case "vert-align":
  8093. n[i] = "vertical-align:" + value;
  8094. continue;
  8095. case "font-color":
  8096. case "mso-foreground":
  8097. n[i] = "color:" + value;
  8098. continue;
  8099. case "mso-background":
  8100. case "mso-highlight":
  8101. n[i] = "background:" + value;
  8102. continue;
  8103. case "mso-default-height":
  8104. n[i] = "min-height:" + transUnit( value );
  8105. continue;
  8106. case "mso-default-width":
  8107. n[i] = "min-width:" + transUnit( value );
  8108. continue;
  8109. case "mso-padding-between-alt":
  8110. n[i] = "border-collapse:separate;border-spacing:" + transUnit( value );
  8111. continue;
  8112. case "text-line-through":
  8113. if ( (value == "single") || (value == "double") ) {
  8114. n[i] = "text-decoration:line-through";
  8115. }
  8116. continue;
  8117. case "mso-zero-height":
  8118. if ( value == "yes" ) {
  8119. n[i] = "display:none";
  8120. }
  8121. continue;
  8122. // case 'background':
  8123. // break;
  8124. case 'margin':
  8125. if ( !/[1-9]/.test( value ) ) {
  8126. continue;
  8127. }
  8128. }
  8129. 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 )
  8130. ||
  8131. /text\-indent|padding|margin/.test(name) && /\-[\d.]+/.test(value)
  8132. ) {
  8133. continue;
  8134. }
  8135. n[i] = name + ":" + parts[1];
  8136. }
  8137. }
  8138. return tag + (n.length ? ' style="' + n.join( ';').replace(/;{2,}/g,';') + '"' : '');
  8139. })
  8140. }
  8141. return function ( html ) {
  8142. return (isWordDocument( html ) ? filterPasteWord( html ) : html);
  8143. };
  8144. }();
  8145. // core/node.js
  8146. /**
  8147. * 编辑器模拟的节点类
  8148. * @file
  8149. * @module UE
  8150. * @class uNode
  8151. * @since 1.2.6.1
  8152. */
  8153. /**
  8154. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  8155. * @unfile
  8156. * @module UE
  8157. */
  8158. (function () {
  8159. /**
  8160. * 编辑器模拟的节点类
  8161. * @unfile
  8162. * @module UE
  8163. * @class uNode
  8164. */
  8165. /**
  8166. * 通过一个键值对,创建一个uNode对象
  8167. * @constructor
  8168. * @param { Object } attr 传入要创建的uNode的初始属性
  8169. * @example
  8170. * ```javascript
  8171. * var node = new uNode({
  8172. * type:'element',
  8173. * tagName:'span',
  8174. * attrs:{style:'font-size:14px;'}
  8175. * }
  8176. * ```
  8177. */
  8178. var uNode = UE.uNode = function (obj) {
  8179. this.type = obj.type;
  8180. this.data = obj.data;
  8181. this.tagName = obj.tagName;
  8182. this.parentNode = obj.parentNode;
  8183. this.attrs = obj.attrs || {};
  8184. this.children = obj.children;
  8185. };
  8186. var notTransAttrs = {
  8187. 'href':1,
  8188. 'src':1,
  8189. '_src':1,
  8190. '_href':1,
  8191. 'cdata_data':1
  8192. };
  8193. var notTransTagName = {
  8194. style:1,
  8195. script:1
  8196. };
  8197. var indentChar = ' ',
  8198. breakChar = '\n';
  8199. function insertLine(arr, current, begin) {
  8200. arr.push(breakChar);
  8201. return current + (begin ? 1 : -1);
  8202. }
  8203. function insertIndent(arr, current) {
  8204. //插入缩进
  8205. for (var i = 0; i < current; i++) {
  8206. arr.push(indentChar);
  8207. }
  8208. }
  8209. //创建uNode的静态方法
  8210. //支持标签和html
  8211. uNode.createElement = function (html) {
  8212. if (/[<>]/.test(html)) {
  8213. return UE.htmlparser(html).children[0]
  8214. } else {
  8215. return new uNode({
  8216. type:'element',
  8217. children:[],
  8218. tagName:html
  8219. })
  8220. }
  8221. };
  8222. uNode.createText = function (data,noTrans) {
  8223. return new UE.uNode({
  8224. type:'text',
  8225. 'data':noTrans ? data : utils.unhtml(data || '')
  8226. })
  8227. };
  8228. function nodeToHtml(node, arr, formatter, current) {
  8229. switch (node.type) {
  8230. case 'root':
  8231. for (var i = 0, ci; ci = node.children[i++];) {
  8232. //插入新行
  8233. if (formatter && ci.type == 'element' && !dtd.$inlineWithA[ci.tagName] && i > 1) {
  8234. insertLine(arr, current, true);
  8235. insertIndent(arr, current)
  8236. }
  8237. nodeToHtml(ci, arr, formatter, current)
  8238. }
  8239. break;
  8240. case 'text':
  8241. isText(node, arr);
  8242. break;
  8243. case 'element':
  8244. isElement(node, arr, formatter, current);
  8245. break;
  8246. case 'comment':
  8247. isComment(node, arr, formatter);
  8248. }
  8249. return arr;
  8250. }
  8251. function isText(node, arr) {
  8252. if(node.parentNode.tagName == 'pre'){
  8253. //源码模式下输入html标签,不能做转换处理,直接输出
  8254. arr.push(node.data)
  8255. }else{
  8256. arr.push(notTransTagName[node.parentNode.tagName] ? utils.html(node.data) : node.data.replace(/[ ]{2}/g,' &nbsp;'))
  8257. }
  8258. }
  8259. function isElement(node, arr, formatter, current) {
  8260. var attrhtml = '';
  8261. if (node.attrs) {
  8262. attrhtml = [];
  8263. var attrs = node.attrs;
  8264. for (var a in attrs) {
  8265. //这里就针对
  8266. //<p>'<img src='http://nsclick.baidu.com/u.gif?&asdf=\"sdf&asdfasdfs;asdf'></p>
  8267. //这里边的\"做转换,要不用innerHTML直接被截断了,属性src
  8268. //有可能做的不够
  8269. attrhtml.push(a + (attrs[a] !== undefined ? '="' + (notTransAttrs[a] ? utils.html(attrs[a]).replace(/["]/g, function (a) {
  8270. return '&quot;'
  8271. }) : utils.unhtml(attrs[a])) + '"' : ''))
  8272. }
  8273. attrhtml = attrhtml.join(' ');
  8274. }
  8275. arr.push('<' + node.tagName +
  8276. (attrhtml ? ' ' + attrhtml : '') +
  8277. (dtd.$empty[node.tagName] ? '\/' : '' ) + '>'
  8278. );
  8279. //插入新行
  8280. if (formatter && !dtd.$inlineWithA[node.tagName] && node.tagName != 'pre') {
  8281. if(node.children && node.children.length){
  8282. current = insertLine(arr, current, true);
  8283. insertIndent(arr, current)
  8284. }
  8285. }
  8286. if (node.children && node.children.length) {
  8287. for (var i = 0, ci; ci = node.children[i++];) {
  8288. if (formatter && ci.type == 'element' && !dtd.$inlineWithA[ci.tagName] && i > 1) {
  8289. insertLine(arr, current);
  8290. insertIndent(arr, current)
  8291. }
  8292. nodeToHtml(ci, arr, formatter, current)
  8293. }
  8294. }
  8295. if (!dtd.$empty[node.tagName]) {
  8296. if (formatter && !dtd.$inlineWithA[node.tagName] && node.tagName != 'pre') {
  8297. if(node.children && node.children.length){
  8298. current = insertLine(arr, current);
  8299. insertIndent(arr, current)
  8300. }
  8301. }
  8302. arr.push('<\/' + node.tagName + '>');
  8303. }
  8304. }
  8305. function isComment(node, arr) {
  8306. arr.push('<!--' + node.data + '-->');
  8307. }
  8308. function getNodeById(root, id) {
  8309. var node;
  8310. if (root.type == 'element' && root.getAttr('id') == id) {
  8311. return root;
  8312. }
  8313. if (root.children && root.children.length) {
  8314. for (var i = 0, ci; ci = root.children[i++];) {
  8315. if (node = getNodeById(ci, id)) {
  8316. return node;
  8317. }
  8318. }
  8319. }
  8320. }
  8321. function getNodesByTagName(node, tagName, arr) {
  8322. if (node.type == 'element' && node.tagName == tagName) {
  8323. arr.push(node);
  8324. }
  8325. if (node.children && node.children.length) {
  8326. for (var i = 0, ci; ci = node.children[i++];) {
  8327. getNodesByTagName(ci, tagName, arr)
  8328. }
  8329. }
  8330. }
  8331. function nodeTraversal(root,fn){
  8332. if(root.children && root.children.length){
  8333. for(var i= 0,ci;ci=root.children[i];){
  8334. nodeTraversal(ci,fn);
  8335. //ci被替换的情况,这里就不再走 fn了
  8336. if(ci.parentNode ){
  8337. if(ci.children && ci.children.length){
  8338. fn(ci)
  8339. }
  8340. if(ci.parentNode) i++
  8341. }
  8342. }
  8343. }else{
  8344. fn(root)
  8345. }
  8346. }
  8347. uNode.prototype = {
  8348. /**
  8349. * 当前节点对象,转换成html文本
  8350. * @method toHtml
  8351. * @return { String } 返回转换后的html字符串
  8352. * @example
  8353. * ```javascript
  8354. * node.toHtml();
  8355. * ```
  8356. */
  8357. /**
  8358. * 当前节点对象,转换成html文本
  8359. * @method toHtml
  8360. * @param { Boolean } formatter 是否格式化返回值
  8361. * @return { String } 返回转换后的html字符串
  8362. * @example
  8363. * ```javascript
  8364. * node.toHtml( true );
  8365. * ```
  8366. */
  8367. toHtml:function (formatter) {
  8368. var arr = [];
  8369. nodeToHtml(this, arr, formatter, 0);
  8370. return arr.join('')
  8371. },
  8372. /**
  8373. * 获取节点的html内容
  8374. * @method innerHTML
  8375. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  8376. * @return { String } 返回节点的html内容
  8377. * @example
  8378. * ```javascript
  8379. * var htmlstr = node.innerHTML();
  8380. * ```
  8381. */
  8382. /**
  8383. * 设置节点的html内容
  8384. * @method innerHTML
  8385. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  8386. * @param { String } htmlstr 传入要设置的html内容
  8387. * @return { UE.uNode } 返回节点本身
  8388. * @example
  8389. * ```javascript
  8390. * node.innerHTML('<span>text</span>');
  8391. * ```
  8392. */
  8393. innerHTML:function (htmlstr) {
  8394. if (this.type != 'element' || dtd.$empty[this.tagName]) {
  8395. return this;
  8396. }
  8397. if (utils.isString(htmlstr)) {
  8398. if(this.children){
  8399. for (var i = 0, ci; ci = this.children[i++];) {
  8400. ci.parentNode = null;
  8401. }
  8402. }
  8403. this.children = [];
  8404. var tmpRoot = UE.htmlparser(htmlstr);
  8405. for (var i = 0, ci; ci = tmpRoot.children[i++];) {
  8406. this.children.push(ci);
  8407. ci.parentNode = this;
  8408. }
  8409. return this;
  8410. } else {
  8411. var tmpRoot = new UE.uNode({
  8412. type:'root',
  8413. children:this.children
  8414. });
  8415. return tmpRoot.toHtml();
  8416. }
  8417. },
  8418. /**
  8419. * 获取节点的纯文本内容
  8420. * @method innerText
  8421. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  8422. * @return { String } 返回节点的存文本内容
  8423. * @example
  8424. * ```javascript
  8425. * var textStr = node.innerText();
  8426. * ```
  8427. */
  8428. /**
  8429. * 设置节点的纯文本内容
  8430. * @method innerText
  8431. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  8432. * @param { String } textStr 传入要设置的文本内容
  8433. * @return { UE.uNode } 返回节点本身
  8434. * @example
  8435. * ```javascript
  8436. * node.innerText('<span>text</span>');
  8437. * ```
  8438. */
  8439. innerText:function (textStr,noTrans) {
  8440. if (this.type != 'element' || dtd.$empty[this.tagName]) {
  8441. return this;
  8442. }
  8443. if (textStr) {
  8444. if(this.children){
  8445. for (var i = 0, ci; ci = this.children[i++];) {
  8446. ci.parentNode = null;
  8447. }
  8448. }
  8449. this.children = [];
  8450. this.appendChild(uNode.createText(textStr,noTrans));
  8451. return this;
  8452. } else {
  8453. return this.toHtml().replace(/<[^>]+>/g, '');
  8454. }
  8455. },
  8456. /**
  8457. * 获取当前对象的data属性
  8458. * @method getData
  8459. * @return { Object } 若节点的type值是elemenet,返回空字符串,否则返回节点的data属性
  8460. * @example
  8461. * ```javascript
  8462. * node.getData();
  8463. * ```
  8464. */
  8465. getData:function () {
  8466. if (this.type == 'element')
  8467. return '';
  8468. return this.data
  8469. },
  8470. /**
  8471. * 获取当前节点下的第一个子节点
  8472. * @method firstChild
  8473. * @return { UE.uNode } 返回第一个子节点
  8474. * @example
  8475. * ```javascript
  8476. * node.firstChild(); //返回第一个子节点
  8477. * ```
  8478. */
  8479. firstChild:function () {
  8480. // if (this.type != 'element' || dtd.$empty[this.tagName]) {
  8481. // return this;
  8482. // }
  8483. return this.children ? this.children[0] : null;
  8484. },
  8485. /**
  8486. * 获取当前节点下的最后一个子节点
  8487. * @method lastChild
  8488. * @return { UE.uNode } 返回最后一个子节点
  8489. * @example
  8490. * ```javascript
  8491. * node.lastChild(); //返回最后一个子节点
  8492. * ```
  8493. */
  8494. lastChild:function () {
  8495. // if (this.type != 'element' || dtd.$empty[this.tagName] ) {
  8496. // return this;
  8497. // }
  8498. return this.children ? this.children[this.children.length - 1] : null;
  8499. },
  8500. /**
  8501. * 获取和当前节点有相同父亲节点的前一个节点
  8502. * @method previousSibling
  8503. * @return { UE.uNode } 返回前一个节点
  8504. * @example
  8505. * ```javascript
  8506. * node.children[2].previousSibling(); //返回子节点node.children[1]
  8507. * ```
  8508. */
  8509. previousSibling : function(){
  8510. var parent = this.parentNode;
  8511. for (var i = 0, ci; ci = parent.children[i]; i++) {
  8512. if (ci === this) {
  8513. return i == 0 ? null : parent.children[i-1];
  8514. }
  8515. }
  8516. },
  8517. /**
  8518. * 获取和当前节点有相同父亲节点的后一个节点
  8519. * @method nextSibling
  8520. * @return { UE.uNode } 返回后一个节点,找不到返回null
  8521. * @example
  8522. * ```javascript
  8523. * node.children[2].nextSibling(); //如果有,返回子节点node.children[3]
  8524. * ```
  8525. */
  8526. nextSibling : function(){
  8527. var parent = this.parentNode;
  8528. for (var i = 0, ci; ci = parent.children[i++];) {
  8529. if (ci === this) {
  8530. return parent.children[i];
  8531. }
  8532. }
  8533. },
  8534. /**
  8535. * 用新的节点替换当前节点
  8536. * @method replaceChild
  8537. * @param { UE.uNode } target 要替换成该节点参数
  8538. * @param { UE.uNode } source 要被替换掉的节点
  8539. * @return { UE.uNode } 返回替换之后的节点对象
  8540. * @example
  8541. * ```javascript
  8542. * node.replaceChild(newNode, childNode); //用newNode替换childNode,childNode是node的子节点
  8543. * ```
  8544. */
  8545. replaceChild:function (target, source) {
  8546. if (this.children) {
  8547. if(target.parentNode){
  8548. target.parentNode.removeChild(target);
  8549. }
  8550. for (var i = 0, ci; ci = this.children[i]; i++) {
  8551. if (ci === source) {
  8552. this.children.splice(i, 1, target);
  8553. source.parentNode = null;
  8554. target.parentNode = this;
  8555. return target;
  8556. }
  8557. }
  8558. }
  8559. },
  8560. /**
  8561. * 在节点的子节点列表最后位置插入一个节点
  8562. * @method appendChild
  8563. * @param { UE.uNode } node 要插入的节点
  8564. * @return { UE.uNode } 返回刚插入的子节点
  8565. * @example
  8566. * ```javascript
  8567. * node.appendChild( newNode ); //在node内插入子节点newNode
  8568. * ```
  8569. */
  8570. appendChild:function (node) {
  8571. if (this.type == 'root' || (this.type == 'element' && !dtd.$empty[this.tagName])) {
  8572. if (!this.children) {
  8573. this.children = []
  8574. }
  8575. if(node.parentNode){
  8576. node.parentNode.removeChild(node);
  8577. }
  8578. for (var i = 0, ci; ci = this.children[i]; i++) {
  8579. if (ci === node) {
  8580. this.children.splice(i, 1);
  8581. break;
  8582. }
  8583. }
  8584. this.children.push(node);
  8585. node.parentNode = this;
  8586. return node;
  8587. }
  8588. },
  8589. /**
  8590. * 在传入节点的前面插入一个节点
  8591. * @method insertBefore
  8592. * @param { UE.uNode } target 要插入的节点
  8593. * @param { UE.uNode } source 在该参数节点前面插入
  8594. * @return { UE.uNode } 返回刚插入的子节点
  8595. * @example
  8596. * ```javascript
  8597. * node.parentNode.insertBefore(newNode, node); //在node节点后面插入newNode
  8598. * ```
  8599. */
  8600. insertBefore:function (target, source) {
  8601. if (this.children) {
  8602. if(target.parentNode){
  8603. target.parentNode.removeChild(target);
  8604. }
  8605. for (var i = 0, ci; ci = this.children[i]; i++) {
  8606. if (ci === source) {
  8607. this.children.splice(i, 0, target);
  8608. target.parentNode = this;
  8609. return target;
  8610. }
  8611. }
  8612. }
  8613. },
  8614. /**
  8615. * 在传入节点的后面插入一个节点
  8616. * @method insertAfter
  8617. * @param { UE.uNode } target 要插入的节点
  8618. * @param { UE.uNode } source 在该参数节点后面插入
  8619. * @return { UE.uNode } 返回刚插入的子节点
  8620. * @example
  8621. * ```javascript
  8622. * node.parentNode.insertAfter(newNode, node); //在node节点后面插入newNode
  8623. * ```
  8624. */
  8625. insertAfter:function (target, source) {
  8626. if (this.children) {
  8627. if(target.parentNode){
  8628. target.parentNode.removeChild(target);
  8629. }
  8630. for (var i = 0, ci; ci = this.children[i]; i++) {
  8631. if (ci === source) {
  8632. this.children.splice(i + 1, 0, target);
  8633. target.parentNode = this;
  8634. return target;
  8635. }
  8636. }
  8637. }
  8638. },
  8639. /**
  8640. * 从当前节点的子节点列表中,移除节点
  8641. * @method removeChild
  8642. * @param { UE.uNode } node 要移除的节点引用
  8643. * @param { Boolean } keepChildren 是否保留移除节点的子节点,若传入true,自动把移除节点的子节点插入到移除的位置
  8644. * @return { * } 返回刚移除的子节点
  8645. * @example
  8646. * ```javascript
  8647. * node.removeChild(childNode,true); //在node的子节点列表中移除child节点,并且吧child的子节点插入到移除的位置
  8648. * ```
  8649. */
  8650. removeChild:function (node,keepChildren) {
  8651. if (this.children) {
  8652. for (var i = 0, ci; ci = this.children[i]; i++) {
  8653. if (ci === node) {
  8654. this.children.splice(i, 1);
  8655. ci.parentNode = null;
  8656. if(keepChildren && ci.children && ci.children.length){
  8657. for(var j= 0,cj;cj=ci.children[j];j++){
  8658. this.children.splice(i+j,0,cj);
  8659. cj.parentNode = this;
  8660. }
  8661. }
  8662. return ci;
  8663. }
  8664. }
  8665. }
  8666. },
  8667. /**
  8668. * 获取当前节点所代表的元素属性,即获取attrs对象下的属性值
  8669. * @method getAttr
  8670. * @param { String } attrName 要获取的属性名称
  8671. * @return { * } 返回attrs对象下的属性值
  8672. * @example
  8673. * ```javascript
  8674. * node.getAttr('title');
  8675. * ```
  8676. */
  8677. getAttr:function (attrName) {
  8678. return this.attrs && this.attrs[attrName.toLowerCase()]
  8679. },
  8680. /**
  8681. * 设置当前节点所代表的元素属性,即设置attrs对象下的属性值
  8682. * @method setAttr
  8683. * @param { String } attrName 要设置的属性名称
  8684. * @param { * } attrVal 要设置的属性值,类型视设置的属性而定
  8685. * @return { * } 返回attrs对象下的属性值
  8686. * @example
  8687. * ```javascript
  8688. * node.setAttr('title','标题');
  8689. * ```
  8690. */
  8691. setAttr:function (attrName, attrVal) {
  8692. if (!attrName) {
  8693. delete this.attrs;
  8694. return;
  8695. }
  8696. if(!this.attrs){
  8697. this.attrs = {};
  8698. }
  8699. if (utils.isObject(attrName)) {
  8700. for (var a in attrName) {
  8701. if (!attrName[a]) {
  8702. delete this.attrs[a]
  8703. } else {
  8704. this.attrs[a.toLowerCase()] = attrName[a];
  8705. }
  8706. }
  8707. } else {
  8708. if (!attrVal) {
  8709. delete this.attrs[attrName]
  8710. } else {
  8711. this.attrs[attrName.toLowerCase()] = attrVal;
  8712. }
  8713. }
  8714. },
  8715. /**
  8716. * 获取当前节点在父节点下的位置索引
  8717. * @method getIndex
  8718. * @return { Number } 返回索引数值,如果没有父节点,返回-1
  8719. * @example
  8720. * ```javascript
  8721. * node.getIndex();
  8722. * ```
  8723. */
  8724. getIndex:function(){
  8725. var parent = this.parentNode;
  8726. for(var i= 0,ci;ci=parent.children[i];i++){
  8727. if(ci === this){
  8728. return i;
  8729. }
  8730. }
  8731. return -1;
  8732. },
  8733. /**
  8734. * 在当前节点下,根据id查找节点
  8735. * @method getNodeById
  8736. * @param { String } id 要查找的id
  8737. * @return { UE.uNode } 返回找到的节点
  8738. * @example
  8739. * ```javascript
  8740. * node.getNodeById('textId');
  8741. * ```
  8742. */
  8743. getNodeById:function (id) {
  8744. var node;
  8745. if (this.children && this.children.length) {
  8746. for (var i = 0, ci; ci = this.children[i++];) {
  8747. if (node = getNodeById(ci, id)) {
  8748. return node;
  8749. }
  8750. }
  8751. }
  8752. },
  8753. /**
  8754. * 在当前节点下,根据元素名称查找节点列表
  8755. * @method getNodesByTagName
  8756. * @param { String } tagNames 要查找的元素名称
  8757. * @return { Array } 返回找到的节点列表
  8758. * @example
  8759. * ```javascript
  8760. * node.getNodesByTagName('span');
  8761. * ```
  8762. */
  8763. getNodesByTagName:function (tagNames) {
  8764. tagNames = utils.trim(tagNames).replace(/[ ]{2,}/g, ' ').split(' ');
  8765. var arr = [], me = this;
  8766. utils.each(tagNames, function (tagName) {
  8767. if (me.children && me.children.length) {
  8768. for (var i = 0, ci; ci = me.children[i++];) {
  8769. getNodesByTagName(ci, tagName, arr)
  8770. }
  8771. }
  8772. });
  8773. return arr;
  8774. },
  8775. /**
  8776. * 根据样式名称,获取节点的样式值
  8777. * @method getStyle
  8778. * @param { String } name 要获取的样式名称
  8779. * @return { String } 返回样式值
  8780. * @example
  8781. * ```javascript
  8782. * node.getStyle('font-size');
  8783. * ```
  8784. */
  8785. getStyle:function (name) {
  8786. var cssStyle = this.getAttr('style');
  8787. if (!cssStyle) {
  8788. return ''
  8789. }
  8790. var reg = new RegExp('(^|;)\\s*' + name + ':([^;]+)','i');
  8791. var match = cssStyle.match(reg);
  8792. if (match && match[0]) {
  8793. return match[2]
  8794. }
  8795. return '';
  8796. },
  8797. /**
  8798. * 给节点设置样式
  8799. * @method setStyle
  8800. * @param { String } name 要设置的的样式名称
  8801. * @param { String } val 要设置的的样值
  8802. * @example
  8803. * ```javascript
  8804. * node.setStyle('font-size', '12px');
  8805. * ```
  8806. */
  8807. setStyle:function (name, val) {
  8808. function exec(name, val) {
  8809. var reg = new RegExp('(^|;)\\s*' + name + ':([^;]+;?)', 'gi');
  8810. cssStyle = cssStyle.replace(reg, '$1');
  8811. if (val) {
  8812. cssStyle = name + ':' + utils.unhtml(val) + ';' + cssStyle
  8813. }
  8814. }
  8815. var cssStyle = this.getAttr('style');
  8816. if (!cssStyle) {
  8817. cssStyle = '';
  8818. }
  8819. if (utils.isObject(name)) {
  8820. for (var a in name) {
  8821. exec(a, name[a])
  8822. }
  8823. } else {
  8824. exec(name, val)
  8825. }
  8826. this.setAttr('style', utils.trim(cssStyle))
  8827. },
  8828. /**
  8829. * 传入一个函数,递归遍历当前节点下的所有节点
  8830. * @method traversal
  8831. * @param { Function } fn 遍历到节点的时,传入节点作为参数,运行此函数
  8832. * @example
  8833. * ```javascript
  8834. * traversal(node, function(){
  8835. * console.log(node.type);
  8836. * });
  8837. * ```
  8838. */
  8839. traversal:function(fn){
  8840. if(this.children && this.children.length){
  8841. nodeTraversal(this,fn);
  8842. }
  8843. return this;
  8844. }
  8845. }
  8846. })();
  8847. // core/htmlparser.js
  8848. /**
  8849. * html字符串转换成uNode节点
  8850. * @file
  8851. * @module UE
  8852. * @since 1.2.6.1
  8853. */
  8854. /**
  8855. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  8856. * @unfile
  8857. * @module UE
  8858. */
  8859. /**
  8860. * html字符串转换成uNode节点的静态方法
  8861. * @method htmlparser
  8862. * @param { String } htmlstr 要转换的html代码
  8863. * @param { Boolean } ignoreBlank 若设置为true,转换的时候忽略\n\r\t等空白字符
  8864. * @return { uNode } 给定的html片段转换形成的uNode对象
  8865. * @example
  8866. * ```javascript
  8867. * var root = UE.htmlparser('<p><b>htmlparser</b></p>', true);
  8868. * ```
  8869. */
  8870. var htmlparser = UE.htmlparser = function (htmlstr,ignoreBlank) {
  8871. //todo 原来的方式 [^"'<>\/] 有\/就不能配对上 <TD vAlign=top background=../AAA.JPG> 这样的标签了
  8872. //先去掉了,加上的原因忘了,这里先记录
  8873. var re_tag = /<(?:(?:\/([^>]+)>)|(?:!--([\S|\s]*?)-->)|(?:([^\s\/<>]+)\s*((?:(?:"[^"]*")|(?:'[^']*')|[^"'<>])*)\/?>))/g,
  8874. re_attr = /([\w\-:.]+)(?:(?:\s*=\s*(?:(?:"([^"]*)")|(?:'([^']*)')|([^\s>]+)))|(?=\s|$))/g;
  8875. //ie下取得的html可能会有\n存在,要去掉,在处理replace(/[\t\r\n]*/g,'');代码高量的\n不能去除
  8876. var allowEmptyTags = {
  8877. b:1,code:1,i:1,u:1,strike:1,s:1,tt:1,strong:1,q:1,samp:1,em:1,span:1,
  8878. sub:1,img:1,sup:1,font:1,big:1,small:1,iframe:1,a:1,br:1,pre:1
  8879. };
  8880. htmlstr = htmlstr.replace(new RegExp(domUtils.fillChar, 'g'), '');
  8881. if(!ignoreBlank){
  8882. htmlstr = htmlstr.replace(new RegExp('[\\r\\t\\n'+(ignoreBlank?'':' ')+']*<\/?(\\w+)\\s*(?:[^>]*)>[\\r\\t\\n'+(ignoreBlank?'':' ')+']*','g'), function(a,b){
  8883. //br暂时单独处理
  8884. if(b && allowEmptyTags[b.toLowerCase()]){
  8885. return a.replace(/(^[\n\r]+)|([\n\r]+$)/g,'');
  8886. }
  8887. return a.replace(new RegExp('^[\\r\\n'+(ignoreBlank?'':' ')+']+'),'').replace(new RegExp('[\\r\\n'+(ignoreBlank?'':' ')+']+$'),'');
  8888. });
  8889. }
  8890. var notTransAttrs = {
  8891. 'href':1,
  8892. 'src':1
  8893. };
  8894. var uNode = UE.uNode,
  8895. needParentNode = {
  8896. 'td':'tr',
  8897. 'tr':['tbody','thead','tfoot'],
  8898. 'tbody':'table',
  8899. 'th':'tr',
  8900. 'thead':'table',
  8901. 'tfoot':'table',
  8902. 'caption':'table',
  8903. 'li':['ul', 'ol'],
  8904. 'dt':'dl',
  8905. 'dd':'dl',
  8906. 'option':'select'
  8907. },
  8908. needChild = {
  8909. 'ol':'li',
  8910. 'ul':'li'
  8911. };
  8912. function text(parent, data) {
  8913. if(needChild[parent.tagName]){
  8914. var tmpNode = uNode.createElement(needChild[parent.tagName]);
  8915. parent.appendChild(tmpNode);
  8916. tmpNode.appendChild(uNode.createText(data));
  8917. parent = tmpNode;
  8918. }else{
  8919. parent.appendChild(uNode.createText(data));
  8920. }
  8921. }
  8922. function element(parent, tagName, htmlattr) {
  8923. var needParentTag;
  8924. if (needParentTag = needParentNode[tagName]) {
  8925. var tmpParent = parent,hasParent;
  8926. while(tmpParent.type != 'root'){
  8927. if(utils.isArray(needParentTag) ? utils.indexOf(needParentTag, tmpParent.tagName) != -1 : needParentTag == tmpParent.tagName){
  8928. parent = tmpParent;
  8929. hasParent = true;
  8930. break;
  8931. }
  8932. tmpParent = tmpParent.parentNode;
  8933. }
  8934. if(!hasParent){
  8935. parent = element(parent, utils.isArray(needParentTag) ? needParentTag[0] : needParentTag)
  8936. }
  8937. }
  8938. //按dtd处理嵌套
  8939. // if(parent.type != 'root' && !dtd[parent.tagName][tagName])
  8940. // parent = parent.parentNode;
  8941. var elm = new uNode({
  8942. parentNode:parent,
  8943. type:'element',
  8944. tagName:tagName.toLowerCase(),
  8945. //是自闭合的处理一下
  8946. children:dtd.$empty[tagName] ? null : []
  8947. });
  8948. //如果属性存在,处理属性
  8949. if (htmlattr) {
  8950. var attrs = {}, match;
  8951. while (match = re_attr.exec(htmlattr)) {
  8952. attrs[match[1].toLowerCase()] = notTransAttrs[match[1].toLowerCase()] ? (match[2] || match[3] || match[4]) : utils.unhtml(match[2] || match[3] || match[4])
  8953. }
  8954. elm.attrs = attrs;
  8955. }
  8956. //trace:3970
  8957. // //如果parent下不能放elm
  8958. // if(dtd.$inline[parent.tagName] && dtd.$block[elm.tagName] && !dtd[parent.tagName][elm.tagName]){
  8959. // parent = parent.parentNode;
  8960. // elm.parentNode = parent;
  8961. // }
  8962. parent.children.push(elm);
  8963. //如果是自闭合节点返回父亲节点
  8964. return dtd.$empty[tagName] ? parent : elm
  8965. }
  8966. function comment(parent, data) {
  8967. parent.children.push(new uNode({
  8968. type:'comment',
  8969. data:data,
  8970. parentNode:parent
  8971. }));
  8972. }
  8973. var match, currentIndex = 0, nextIndex = 0;
  8974. //设置根节点
  8975. var root = new uNode({
  8976. type:'root',
  8977. children:[]
  8978. });
  8979. var currentParent = root;
  8980. while (match = re_tag.exec(htmlstr)) {
  8981. currentIndex = match.index;
  8982. try{
  8983. if (currentIndex > nextIndex) {
  8984. //text node
  8985. text(currentParent, htmlstr.slice(nextIndex, currentIndex));
  8986. }
  8987. if (match[3]) {
  8988. if(dtd.$cdata[currentParent.tagName]){
  8989. text(currentParent, match[0]);
  8990. }else{
  8991. //start tag
  8992. currentParent = element(currentParent, match[3].toLowerCase(), match[4]);
  8993. }
  8994. } else if (match[1]) {
  8995. if(currentParent.type != 'root'){
  8996. if(dtd.$cdata[currentParent.tagName] && !dtd.$cdata[match[1]]){
  8997. text(currentParent, match[0]);
  8998. }else{
  8999. var tmpParent = currentParent;
  9000. while(currentParent.type == 'element' && currentParent.tagName != match[1].toLowerCase()){
  9001. currentParent = currentParent.parentNode;
  9002. if(currentParent.type == 'root'){
  9003. currentParent = tmpParent;
  9004. throw 'break'
  9005. }
  9006. }
  9007. //end tag
  9008. currentParent = currentParent.parentNode;
  9009. }
  9010. }
  9011. } else if (match[2]) {
  9012. //comment
  9013. comment(currentParent, match[2])
  9014. }
  9015. }catch(e){}
  9016. nextIndex = re_tag.lastIndex;
  9017. }
  9018. //如果结束是文本,就有可能丢掉,所以这里手动判断一下
  9019. //例如 <li>sdfsdfsdf<li>sdfsdfsdfsdf
  9020. if (nextIndex < htmlstr.length) {
  9021. text(currentParent, htmlstr.slice(nextIndex));
  9022. }
  9023. return root;
  9024. };
  9025. // core/filternode.js
  9026. /**
  9027. * UE过滤节点的静态方法
  9028. * @file
  9029. */
  9030. /**
  9031. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  9032. * @module UE
  9033. */
  9034. /**
  9035. * 根据传入节点和过滤规则过滤相应节点
  9036. * @module UE
  9037. * @since 1.2.6.1
  9038. * @method filterNode
  9039. * @param { Object } root 指定root节点
  9040. * @param { Object } rules 过滤规则json对象
  9041. * @example
  9042. * ```javascript
  9043. * UE.filterNode(root,editor.options.filterRules);
  9044. * ```
  9045. */
  9046. var filterNode = UE.filterNode = function () {
  9047. function filterNode(node,rules){
  9048. switch (node.type) {
  9049. case 'text':
  9050. break;
  9051. case 'element':
  9052. var val;
  9053. if(val = rules[node.tagName]){
  9054. if(val === '-'){
  9055. node.parentNode.removeChild(node)
  9056. }else if(utils.isFunction(val)){
  9057. var parentNode = node.parentNode,
  9058. index = node.getIndex();
  9059. val(node);
  9060. if(node.parentNode){
  9061. if(node.children){
  9062. for(var i = 0,ci;ci=node.children[i];){
  9063. filterNode(ci,rules);
  9064. if(ci.parentNode){
  9065. i++;
  9066. }
  9067. }
  9068. }
  9069. }else{
  9070. for(var i = index,ci;ci=parentNode.children[i];){
  9071. filterNode(ci,rules);
  9072. if(ci.parentNode){
  9073. i++;
  9074. }
  9075. }
  9076. }
  9077. }else{
  9078. var attrs = val['$'];
  9079. if(attrs && node.attrs){
  9080. var tmpAttrs = {},tmpVal;
  9081. for(var a in attrs){
  9082. tmpVal = node.getAttr(a);
  9083. //todo 只先对style单独处理
  9084. if(a == 'style' && utils.isArray(attrs[a])){
  9085. var tmpCssStyle = [];
  9086. utils.each(attrs[a],function(v){
  9087. var tmp;
  9088. if(tmp = node.getStyle(v)){
  9089. tmpCssStyle.push(v + ':' + tmp);
  9090. }
  9091. });
  9092. tmpVal = tmpCssStyle.join(';')
  9093. }
  9094. if(tmpVal){
  9095. tmpAttrs[a] = tmpVal;
  9096. }
  9097. }
  9098. node.attrs = tmpAttrs;
  9099. }
  9100. if(node.children){
  9101. for(var i = 0,ci;ci=node.children[i];){
  9102. filterNode(ci,rules);
  9103. if(ci.parentNode){
  9104. i++;
  9105. }
  9106. }
  9107. }
  9108. }
  9109. }else{
  9110. //如果不在名单里扣出子节点并删除该节点,cdata除外
  9111. if(dtd.$cdata[node.tagName]){
  9112. node.parentNode.removeChild(node)
  9113. }else{
  9114. var parentNode = node.parentNode,
  9115. index = node.getIndex();
  9116. node.parentNode.removeChild(node,true);
  9117. for(var i = index,ci;ci=parentNode.children[i];){
  9118. filterNode(ci,rules);
  9119. if(ci.parentNode){
  9120. i++;
  9121. }
  9122. }
  9123. }
  9124. }
  9125. break;
  9126. case 'comment':
  9127. node.parentNode.removeChild(node)
  9128. }
  9129. }
  9130. return function(root,rules){
  9131. if(utils.isEmptyObject(rules)){
  9132. return root;
  9133. }
  9134. var val;
  9135. if(val = rules['-']){
  9136. utils.each(val.split(' '),function(k){
  9137. rules[k] = '-'
  9138. })
  9139. }
  9140. for(var i= 0,ci;ci=root.children[i];){
  9141. filterNode(ci,rules);
  9142. if(ci.parentNode){
  9143. i++;
  9144. }
  9145. }
  9146. return root;
  9147. }
  9148. }();
  9149. // core/plugin.js
  9150. /**
  9151. * Created with JetBrains PhpStorm.
  9152. * User: campaign
  9153. * Date: 10/8/13
  9154. * Time: 6:15 PM
  9155. * To change this template use File | Settings | File Templates.
  9156. */
  9157. UE.plugin = function(){
  9158. var _plugins = {};
  9159. return {
  9160. register : function(pluginName,fn,oldOptionName,afterDisabled){
  9161. if(oldOptionName && utils.isFunction(oldOptionName)){
  9162. afterDisabled = oldOptionName;
  9163. oldOptionName = null
  9164. }
  9165. _plugins[pluginName] = {
  9166. optionName : oldOptionName || pluginName,
  9167. execFn : fn,
  9168. //当插件被禁用时执行
  9169. afterDisabled : afterDisabled
  9170. }
  9171. },
  9172. load : function(editor){
  9173. utils.each(_plugins,function(plugin){
  9174. var _export = plugin.execFn.call(editor);
  9175. if(editor.options[plugin.optionName] !== false){
  9176. if(_export){
  9177. //后边需要再做扩展
  9178. utils.each(_export,function(v,k){
  9179. switch(k.toLowerCase()){
  9180. case 'shortcutkey':
  9181. editor.addshortcutkey(v);
  9182. break;
  9183. case 'bindevents':
  9184. utils.each(v,function(fn,eventName){
  9185. editor.addListener(eventName,fn);
  9186. });
  9187. break;
  9188. case 'bindmultievents':
  9189. utils.each(utils.isArray(v) ? v:[v],function(event){
  9190. var types = utils.trim(event.type).split(/\s+/);
  9191. utils.each(types,function(eventName){
  9192. editor.addListener(eventName, event.handler);
  9193. });
  9194. });
  9195. break;
  9196. case 'commands':
  9197. utils.each(v,function(execFn,execName){
  9198. editor.commands[execName] = execFn
  9199. });
  9200. break;
  9201. case 'outputrule':
  9202. editor.addOutputRule(v);
  9203. break;
  9204. case 'inputrule':
  9205. editor.addInputRule(v);
  9206. break;
  9207. case 'defaultoptions':
  9208. editor.setOpt(v)
  9209. }
  9210. })
  9211. }
  9212. }else if(plugin.afterDisabled){
  9213. plugin.afterDisabled.call(editor)
  9214. }
  9215. });
  9216. //向下兼容
  9217. utils.each(UE.plugins,function(plugin){
  9218. plugin.call(editor);
  9219. });
  9220. },
  9221. run : function(pluginName,editor){
  9222. var plugin = _plugins[pluginName];
  9223. if(plugin){
  9224. plugin.exeFn.call(editor)
  9225. }
  9226. }
  9227. }
  9228. }();
  9229. // core/keymap.js
  9230. var keymap = UE.keymap = {
  9231. 'Backspace' : 8,
  9232. 'Tab' : 9,
  9233. 'Enter' : 13,
  9234. 'Shift':16,
  9235. 'Control':17,
  9236. 'Alt':18,
  9237. 'CapsLock':20,
  9238. 'Esc':27,
  9239. 'Spacebar':32,
  9240. 'PageUp':33,
  9241. 'PageDown':34,
  9242. 'End':35,
  9243. 'Home':36,
  9244. 'Left':37,
  9245. 'Up':38,
  9246. 'Right':39,
  9247. 'Down':40,
  9248. 'Insert':45,
  9249. 'Del':46,
  9250. 'NumLock':144,
  9251. 'Cmd':91,
  9252. '=':187,
  9253. '-':189,
  9254. "b":66,
  9255. 'i':73,
  9256. //回退
  9257. 'z':90,
  9258. 'y':89,
  9259. //粘贴
  9260. 'v' : 86,
  9261. 'x' : 88,
  9262. 's' : 83,
  9263. 'n' : 78
  9264. };
  9265. // core/localstorage.js
  9266. //存储媒介封装
  9267. var LocalStorage = UE.LocalStorage = (function () {
  9268. var storage = window.localStorage || getUserData() || null,
  9269. LOCAL_FILE = 'localStorage';
  9270. return {
  9271. saveLocalData: function (key, data) {
  9272. if (storage && data) {
  9273. storage.setItem(key, data);
  9274. return true;
  9275. }
  9276. return false;
  9277. },
  9278. getLocalData: function (key) {
  9279. if (storage) {
  9280. return storage.getItem(key);
  9281. }
  9282. return null;
  9283. },
  9284. removeItem: function (key) {
  9285. storage && storage.removeItem(key);
  9286. }
  9287. };
  9288. function getUserData() {
  9289. var container = document.createElement("div");
  9290. container.style.display = "none";
  9291. if (!container.addBehavior) {
  9292. return null;
  9293. }
  9294. container.addBehavior("#default#userdata");
  9295. return {
  9296. getItem: function (key) {
  9297. var result = null;
  9298. try {
  9299. document.body.appendChild(container);
  9300. container.load(LOCAL_FILE);
  9301. result = container.getAttribute(key);
  9302. document.body.removeChild(container);
  9303. } catch (e) {
  9304. }
  9305. return result;
  9306. },
  9307. setItem: function (key, value) {
  9308. document.body.appendChild(container);
  9309. container.setAttribute(key, value);
  9310. container.save(LOCAL_FILE);
  9311. document.body.removeChild(container);
  9312. },
  9313. //// 暂时没有用到
  9314. //clear: function () {
  9315. //
  9316. // var expiresTime = new Date();
  9317. // expiresTime.setFullYear(expiresTime.getFullYear() - 1);
  9318. // document.body.appendChild(container);
  9319. // container.expires = expiresTime.toUTCString();
  9320. // container.save(LOCAL_FILE);
  9321. // document.body.removeChild(container);
  9322. //
  9323. //},
  9324. removeItem: function (key) {
  9325. document.body.appendChild(container);
  9326. container.removeAttribute(key);
  9327. container.save(LOCAL_FILE);
  9328. document.body.removeChild(container);
  9329. }
  9330. };
  9331. }
  9332. })();
  9333. (function () {
  9334. var ROOTKEY = 'ueditor_preference';
  9335. UE.Editor.prototype.setPreferences = function(key,value){
  9336. var obj = {};
  9337. if (utils.isString(key)) {
  9338. obj[ key ] = value;
  9339. } else {
  9340. obj = key;
  9341. }
  9342. var data = LocalStorage.getLocalData(ROOTKEY);
  9343. if (data && (data = utils.str2json(data))) {
  9344. utils.extend(data, obj);
  9345. } else {
  9346. data = obj;
  9347. }
  9348. data && LocalStorage.saveLocalData(ROOTKEY, utils.json2str(data));
  9349. };
  9350. UE.Editor.prototype.getPreferences = function(key){
  9351. var data = LocalStorage.getLocalData(ROOTKEY);
  9352. if (data && (data = utils.str2json(data))) {
  9353. return key ? data[key] : data
  9354. }
  9355. return null;
  9356. };
  9357. UE.Editor.prototype.removePreferences = function (key) {
  9358. var data = LocalStorage.getLocalData(ROOTKEY);
  9359. if (data && (data = utils.str2json(data))) {
  9360. data[key] = undefined;
  9361. delete data[key]
  9362. }
  9363. data && LocalStorage.saveLocalData(ROOTKEY, utils.json2str(data));
  9364. };
  9365. })();
  9366. // plugins/defaultfilter.js
  9367. ///import core
  9368. ///plugin 编辑器默认的过滤转换机制
  9369. UE.plugins['defaultfilter'] = function () {
  9370. var me = this;
  9371. me.setOpt({
  9372. 'allowDivTransToP':true,
  9373. 'disabledTableInTable':true
  9374. });
  9375. //默认的过滤处理
  9376. //进入编辑器的内容处理
  9377. me.addInputRule(function (root) {
  9378. var allowDivTransToP = this.options.allowDivTransToP;
  9379. var val;
  9380. function tdParent(node){
  9381. while(node && node.type == 'element'){
  9382. if(node.tagName == 'td'){
  9383. return true;
  9384. }
  9385. node = node.parentNode;
  9386. }
  9387. return false;
  9388. }
  9389. //进行默认的处理
  9390. root.traversal(function (node) {
  9391. if (node.type == 'element') {
  9392. if (!dtd.$cdata[node.tagName] && me.options.autoClearEmptyNode && dtd.$inline[node.tagName] && !dtd.$empty[node.tagName] && (!node.attrs || utils.isEmptyObject(node.attrs))) {
  9393. if (!node.firstChild()) node.parentNode.removeChild(node);
  9394. else if (node.tagName == 'span' && (!node.attrs || utils.isEmptyObject(node.attrs))) {
  9395. node.parentNode.removeChild(node, true)
  9396. }
  9397. return;
  9398. }
  9399. switch (node.tagName) {
  9400. case 'style':
  9401. case 'script':
  9402. node.setAttr({
  9403. cdata_tag: node.tagName,
  9404. cdata_data: (node.innerHTML() || ''),
  9405. '_ue_custom_node_':'true'
  9406. });
  9407. node.tagName = 'div';
  9408. node.innerHTML('');
  9409. break;
  9410. case 'a':
  9411. if (val = node.getAttr('href')) {
  9412. node.setAttr('_href', val)
  9413. }
  9414. break;
  9415. case 'img':
  9416. //todo base64暂时去掉,后边做远程图片上传后,干掉这个
  9417. if (val = node.getAttr('src')) {
  9418. if (/^data:/.test(val)) {
  9419. node.parentNode.removeChild(node);
  9420. break;
  9421. }
  9422. }
  9423. node.setAttr('_src', node.getAttr('src'));
  9424. break;
  9425. case 'span':
  9426. if (browser.webkit && (val = node.getStyle('white-space'))) {
  9427. if (/nowrap|normal/.test(val)) {
  9428. node.setStyle('white-space', '');
  9429. if (me.options.autoClearEmptyNode && utils.isEmptyObject(node.attrs)) {
  9430. node.parentNode.removeChild(node, true)
  9431. }
  9432. }
  9433. }
  9434. val = node.getAttr('id');
  9435. if(val && /^_baidu_bookmark_/i.test(val)){
  9436. node.parentNode.removeChild(node)
  9437. }
  9438. break;
  9439. case 'p':
  9440. if (val = node.getAttr('align')) {
  9441. node.setAttr('align');
  9442. node.setStyle('text-align', val)
  9443. }
  9444. //trace:3431
  9445. // var cssStyle = node.getAttr('style');
  9446. // if (cssStyle) {
  9447. // cssStyle = cssStyle.replace(/(margin|padding)[^;]+/g, '');
  9448. // node.setAttr('style', cssStyle)
  9449. //
  9450. // }
  9451. //p标签不允许嵌套
  9452. utils.each(node.children,function(n){
  9453. if(n.type == 'element' && n.tagName == 'p'){
  9454. var next = n.nextSibling();
  9455. node.parentNode.insertAfter(n,node);
  9456. var last = n;
  9457. while(next){
  9458. var tmp = next.nextSibling();
  9459. node.parentNode.insertAfter(next,last);
  9460. last = next;
  9461. next = tmp;
  9462. }
  9463. return false;
  9464. }
  9465. });
  9466. if (!node.firstChild()) {
  9467. node.innerHTML(browser.ie ? '&nbsp;' : '<br/>')
  9468. }
  9469. break;
  9470. case 'div':
  9471. if(node.getAttr('cdata_tag')){
  9472. break;
  9473. }
  9474. //针对代码这里不处理插入代码的div
  9475. val = node.getAttr('class');
  9476. if(val && /^line number\d+/.test(val)){
  9477. break;
  9478. }
  9479. if(!allowDivTransToP){
  9480. break;
  9481. }
  9482. var tmpNode, p = UE.uNode.createElement('p');
  9483. while (tmpNode = node.firstChild()) {
  9484. if (tmpNode.type == 'text' || !UE.dom.dtd.$block[tmpNode.tagName]) {
  9485. p.appendChild(tmpNode);
  9486. } else {
  9487. if (p.firstChild()) {
  9488. node.parentNode.insertBefore(p, node);
  9489. p = UE.uNode.createElement('p');
  9490. } else {
  9491. node.parentNode.insertBefore(tmpNode, node);
  9492. }
  9493. }
  9494. }
  9495. if (p.firstChild()) {
  9496. node.parentNode.insertBefore(p, node);
  9497. }
  9498. node.parentNode.removeChild(node);
  9499. break;
  9500. case 'dl':
  9501. node.tagName = 'ul';
  9502. break;
  9503. case 'dt':
  9504. case 'dd':
  9505. node.tagName = 'li';
  9506. break;
  9507. case 'li':
  9508. var className = node.getAttr('class');
  9509. if (!className || !/list\-/.test(className)) {
  9510. node.setAttr()
  9511. }
  9512. var tmpNodes = node.getNodesByTagName('ol ul');
  9513. UE.utils.each(tmpNodes, function (n) {
  9514. node.parentNode.insertAfter(n, node);
  9515. });
  9516. break;
  9517. case 'td':
  9518. case 'th':
  9519. case 'caption':
  9520. if(!node.children || !node.children.length){
  9521. node.appendChild(browser.ie11below ? UE.uNode.createText(' ') : UE.uNode.createElement('br'))
  9522. }
  9523. break;
  9524. case 'table':
  9525. if(me.options.disabledTableInTable && tdParent(node)){
  9526. node.parentNode.insertBefore(UE.uNode.createText(node.innerText()),node);
  9527. node.parentNode.removeChild(node)
  9528. }
  9529. }
  9530. }
  9531. // if(node.type == 'comment'){
  9532. // node.parentNode.removeChild(node);
  9533. // }
  9534. })
  9535. });
  9536. //从编辑器出去的内容处理
  9537. me.addOutputRule(function (root) {
  9538. var val;
  9539. root.traversal(function (node) {
  9540. if (node.type == 'element') {
  9541. if (me.options.autoClearEmptyNode && dtd.$inline[node.tagName] && !dtd.$empty[node.tagName] && (!node.attrs || utils.isEmptyObject(node.attrs))) {
  9542. if (!node.firstChild()) node.parentNode.removeChild(node);
  9543. else if (node.tagName == 'span' && (!node.attrs || utils.isEmptyObject(node.attrs))) {
  9544. node.parentNode.removeChild(node, true)
  9545. }
  9546. return;
  9547. }
  9548. switch (node.tagName) {
  9549. case 'div':
  9550. if (val = node.getAttr('cdata_tag')) {
  9551. node.tagName = val;
  9552. node.appendChild(UE.uNode.createText(node.getAttr('cdata_data')));
  9553. node.setAttr({cdata_tag: '', cdata_data: '','_ue_custom_node_':''});
  9554. }
  9555. break;
  9556. case 'a':
  9557. if (val = node.getAttr('_href')) {
  9558. node.setAttr({
  9559. 'href': utils.html(val),
  9560. '_href': ''
  9561. })
  9562. }
  9563. break;
  9564. break;
  9565. case 'span':
  9566. val = node.getAttr('id');
  9567. if(val && /^_baidu_bookmark_/i.test(val)){
  9568. node.parentNode.removeChild(node)
  9569. }
  9570. break;
  9571. case 'img':
  9572. if (val = node.getAttr('_src')) {
  9573. node.setAttr({
  9574. 'src': node.getAttr('_src'),
  9575. '_src': ''
  9576. })
  9577. }
  9578. }
  9579. }
  9580. })
  9581. });
  9582. };
  9583. // plugins/inserthtml.js
  9584. /**
  9585. * 插入html字符串插件
  9586. * @file
  9587. * @since 1.2.6.1
  9588. */
  9589. /**
  9590. * 插入html代码
  9591. * @command inserthtml
  9592. * @method execCommand
  9593. * @param { String } cmd 命令字符串
  9594. * @param { String } html 插入的html字符串
  9595. * @remaind 插入的标签内容是在当前的选区位置上插入,如果当前是闭合状态,那直接插入内容, 如果当前是选中状态,将先清除当前选中内容后,再做插入
  9596. * @warning 注意:该命令会对当前选区的位置,对插入的内容进行过滤转换处理。 过滤的规则遵循html语意化的原则。
  9597. * @example
  9598. * ```javascript
  9599. * //xxx[BB]xxx 当前选区为非闭合选区,选中BB这两个文本
  9600. * //执行命令,插入<b>CC</b>
  9601. * //插入后的效果 xxx<b>CC</b>xxx
  9602. * //<p>xx|xxx</p> 当前选区为闭合状态
  9603. * //插入<p>CC</p>
  9604. * //结果 <p>xx</p><p>CC</p><p>xxx</p>
  9605. * //<p>xxxx</p>|</p>xxx</p> 当前选区在两个p标签之间
  9606. * //插入 xxxx
  9607. * //结果 <p>xxxx</p><p>xxxx</p></p>xxx</p>
  9608. * ```
  9609. */
  9610. UE.commands['inserthtml'] = {
  9611. execCommand: function (command,html,notNeedFilter){
  9612. var me = this,
  9613. range,
  9614. div;
  9615. if(!html){
  9616. return;
  9617. }
  9618. if(me.fireEvent('beforeinserthtml',html) === true){
  9619. return;
  9620. }
  9621. range = me.selection.getRange();
  9622. div = range.document.createElement( 'div' );
  9623. div.style.display = 'inline';
  9624. if (!notNeedFilter) {
  9625. var root = UE.htmlparser(html);
  9626. //如果给了过滤规则就先进行过滤
  9627. if(me.options.filterRules){
  9628. UE.filterNode(root,me.options.filterRules);
  9629. }
  9630. //执行默认的处理
  9631. me.filterInputRule(root);
  9632. html = root.toHtml()
  9633. }
  9634. div.innerHTML = utils.trim( html );
  9635. if ( !range.collapsed ) {
  9636. var tmpNode = range.startContainer;
  9637. if(domUtils.isFillChar(tmpNode)){
  9638. range.setStartBefore(tmpNode)
  9639. }
  9640. tmpNode = range.endContainer;
  9641. if(domUtils.isFillChar(tmpNode)){
  9642. range.setEndAfter(tmpNode)
  9643. }
  9644. range.txtToElmBoundary();
  9645. //结束边界可能放到了br的前边,要把br包含进来
  9646. // x[xxx]<br/>
  9647. if(range.endContainer && range.endContainer.nodeType == 1){
  9648. tmpNode = range.endContainer.childNodes[range.endOffset];
  9649. if(tmpNode && domUtils.isBr(tmpNode)){
  9650. range.setEndAfter(tmpNode);
  9651. }
  9652. }
  9653. if(range.startOffset == 0){
  9654. tmpNode = range.startContainer;
  9655. if(domUtils.isBoundaryNode(tmpNode,'firstChild') ){
  9656. tmpNode = range.endContainer;
  9657. if(range.endOffset == (tmpNode.nodeType == 3 ? tmpNode.nodeValue.length : tmpNode.childNodes.length) && domUtils.isBoundaryNode(tmpNode,'lastChild')){
  9658. me.body.innerHTML = '<p>'+(browser.ie ? '' : '<br/>')+'</p>';
  9659. range.setStart(me.body.firstChild,0).collapse(true)
  9660. }
  9661. }
  9662. }
  9663. !range.collapsed && range.deleteContents();
  9664. if(range.startContainer.nodeType == 1){
  9665. var child = range.startContainer.childNodes[range.startOffset],pre;
  9666. if(child && domUtils.isBlockElm(child) && (pre = child.previousSibling) && domUtils.isBlockElm(pre)){
  9667. range.setEnd(pre,pre.childNodes.length).collapse();
  9668. while(child.firstChild){
  9669. pre.appendChild(child.firstChild);
  9670. }
  9671. domUtils.remove(child);
  9672. }
  9673. }
  9674. }
  9675. var child,parent,pre,tmp,hadBreak = 0, nextNode;
  9676. //如果当前位置选中了fillchar要干掉,要不会产生空行
  9677. if(range.inFillChar()){
  9678. child = range.startContainer;
  9679. if(domUtils.isFillChar(child)){
  9680. range.setStartBefore(child).collapse(true);
  9681. domUtils.remove(child);
  9682. }else if(domUtils.isFillChar(child,true)){
  9683. child.nodeValue = child.nodeValue.replace(fillCharReg,'');
  9684. range.startOffset--;
  9685. range.collapsed && range.collapse(true)
  9686. }
  9687. }
  9688. //列表单独处理
  9689. var li = domUtils.findParentByTagName(range.startContainer,'li',true);
  9690. if(li){
  9691. var next,last;
  9692. while(child = div.firstChild){
  9693. //针对hr单独处理一下先
  9694. while(child && (child.nodeType == 3 || !domUtils.isBlockElm(child) || child.tagName=='HR' )){
  9695. next = child.nextSibling;
  9696. range.insertNode( child).collapse();
  9697. last = child;
  9698. child = next;
  9699. }
  9700. if(child){
  9701. if(/^(ol|ul)$/i.test(child.tagName)){
  9702. while(child.firstChild){
  9703. last = child.firstChild;
  9704. domUtils.insertAfter(li,child.firstChild);
  9705. li = li.nextSibling;
  9706. }
  9707. domUtils.remove(child)
  9708. }else{
  9709. var tmpLi;
  9710. next = child.nextSibling;
  9711. tmpLi = me.document.createElement('li');
  9712. domUtils.insertAfter(li,tmpLi);
  9713. tmpLi.appendChild(child);
  9714. last = child;
  9715. child = next;
  9716. li = tmpLi;
  9717. }
  9718. }
  9719. }
  9720. li = domUtils.findParentByTagName(range.startContainer,'li',true);
  9721. if(domUtils.isEmptyBlock(li)){
  9722. domUtils.remove(li)
  9723. }
  9724. if(last){
  9725. range.setStartAfter(last).collapse(true).select(true)
  9726. }
  9727. }else{
  9728. while ( child = div.firstChild ) {
  9729. if(hadBreak){
  9730. var p = me.document.createElement('p');
  9731. while(child && (child.nodeType == 3 || !dtd.$block[child.tagName])){
  9732. nextNode = child.nextSibling;
  9733. p.appendChild(child);
  9734. child = nextNode;
  9735. }
  9736. if(p.firstChild){
  9737. child = p
  9738. }
  9739. }
  9740. range.insertNode( child );
  9741. nextNode = child.nextSibling;
  9742. if ( !hadBreak && child.nodeType == domUtils.NODE_ELEMENT && domUtils.isBlockElm( child ) ){
  9743. parent = domUtils.findParent( child,function ( node ){ return domUtils.isBlockElm( node ); } );
  9744. if ( parent && parent.tagName.toLowerCase() != 'body' && !(dtd[parent.tagName][child.nodeName] && child.parentNode === parent)){
  9745. if(!dtd[parent.tagName][child.nodeName]){
  9746. pre = parent;
  9747. }else{
  9748. tmp = child.parentNode;
  9749. while (tmp !== parent){
  9750. pre = tmp;
  9751. tmp = tmp.parentNode;
  9752. }
  9753. }
  9754. domUtils.breakParent( child, pre || tmp );
  9755. //去掉break后前一个多余的节点 <p>|<[p> ==> <p></p><div></div><p>|</p>
  9756. var pre = child.previousSibling;
  9757. domUtils.trimWhiteTextNode(pre);
  9758. if(!pre.childNodes.length){
  9759. domUtils.remove(pre);
  9760. }
  9761. //trace:2012,在非ie的情况,切开后剩下的节点有可能不能点入光标添加br占位
  9762. if(!browser.ie &&
  9763. (next = child.nextSibling) &&
  9764. domUtils.isBlockElm(next) &&
  9765. next.lastChild &&
  9766. !domUtils.isBr(next.lastChild)){
  9767. next.appendChild(me.document.createElement('br'));
  9768. }
  9769. hadBreak = 1;
  9770. }
  9771. }
  9772. var next = child.nextSibling;
  9773. if(!div.firstChild && next && domUtils.isBlockElm(next)){
  9774. range.setStart(next,0).collapse(true);
  9775. break;
  9776. }
  9777. range.setEndAfter( child ).collapse();
  9778. }
  9779. child = range.startContainer;
  9780. if(nextNode && domUtils.isBr(nextNode)){
  9781. domUtils.remove(nextNode)
  9782. }
  9783. //用chrome可能有空白展位符
  9784. if(domUtils.isBlockElm(child) && domUtils.isEmptyNode(child)){
  9785. if(nextNode = child.nextSibling){
  9786. domUtils.remove(child);
  9787. if(nextNode.nodeType == 1 && dtd.$block[nextNode.tagName]){
  9788. range.setStart(nextNode,0).collapse(true).shrinkBoundary()
  9789. }
  9790. }else{
  9791. try{
  9792. child.innerHTML = browser.ie ? domUtils.fillChar : '<br/>';
  9793. }catch(e){
  9794. range.setStartBefore(child);
  9795. domUtils.remove(child)
  9796. }
  9797. }
  9798. }
  9799. //加上true因为在删除表情等时会删两次,第一次是删的fillData
  9800. try{
  9801. range.select(true);
  9802. }catch(e){}
  9803. }
  9804. setTimeout(function(){
  9805. range = me.selection.getRange();
  9806. range.scrollToView(me.autoHeightEnabled,me.autoHeightEnabled ? domUtils.getXY(me.iframe).y:0);
  9807. me.fireEvent('afterinserthtml', html);
  9808. },200);
  9809. }
  9810. };
  9811. // plugins/autotypeset.js
  9812. /**
  9813. * 自动排版
  9814. * @file
  9815. * @since 1.2.6.1
  9816. */
  9817. /**
  9818. * 对当前编辑器的内容执行自动排版, 排版的行为根据config配置文件里的“autotypeset”选项进行控制。
  9819. * @command autotypeset
  9820. * @method execCommand
  9821. * @param { String } cmd 命令字符串
  9822. * @example
  9823. * ```javascript
  9824. * editor.execCommand( 'autotypeset' );
  9825. * ```
  9826. */
  9827. UE.plugins['autotypeset'] = function(){
  9828. this.setOpt({'autotypeset': {
  9829. mergeEmptyline: true, //合并空行
  9830. removeClass: true, //去掉冗余的class
  9831. removeEmptyline: false, //去掉空行
  9832. textAlign:"left", //段落的排版方式,可以是 left,right,center,justify 去掉这个属性表示不执行排版
  9833. imageBlockLine: 'center', //图片的浮动方式,独占一行剧中,左右浮动,默认: center,left,right,none 去掉这个属性表示不执行排版
  9834. pasteFilter: false, //根据规则过滤没事粘贴进来的内容
  9835. clearFontSize: false, //去掉所有的内嵌字号,使用编辑器默认的字号
  9836. clearFontFamily: false, //去掉所有的内嵌字体,使用编辑器默认的字体
  9837. removeEmptyNode: false, // 去掉空节点
  9838. //可以去掉的标签
  9839. removeTagNames: utils.extend({div:1},dtd.$removeEmpty),
  9840. indent: false, // 行首缩进
  9841. indentValue : '2em', //行首缩进的大小
  9842. bdc2sb: false,
  9843. tobdc: false
  9844. }});
  9845. var me = this,
  9846. opt = me.options.autotypeset,
  9847. remainClass = {
  9848. 'selectTdClass':1,
  9849. 'pagebreak':1,
  9850. 'anchorclass':1
  9851. },
  9852. remainTag = {
  9853. 'li':1
  9854. },
  9855. tags = {
  9856. div:1,
  9857. p:1,
  9858. //trace:2183 这些也认为是行
  9859. blockquote:1,center:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,
  9860. span:1
  9861. },
  9862. highlightCont;
  9863. //升级了版本,但配置项目里没有autotypeset
  9864. if(!opt){
  9865. return;
  9866. }
  9867. readLocalOpts();
  9868. function isLine(node,notEmpty){
  9869. if(!node || node.nodeType == 3)
  9870. return 0;
  9871. if(domUtils.isBr(node))
  9872. return 1;
  9873. if(node && node.parentNode && tags[node.tagName.toLowerCase()]){
  9874. if(highlightCont && highlightCont.contains(node)
  9875. ||
  9876. node.getAttribute('pagebreak')
  9877. ){
  9878. return 0;
  9879. }
  9880. return notEmpty ? !domUtils.isEmptyBlock(node) : domUtils.isEmptyBlock(node,new RegExp('[\\s'+domUtils.fillChar
  9881. +']','g'));
  9882. }
  9883. }
  9884. function removeNotAttributeSpan(node){
  9885. if(!node.style.cssText){
  9886. domUtils.removeAttributes(node,['style']);
  9887. if(node.tagName.toLowerCase() == 'span' && domUtils.hasNoAttributes(node)){
  9888. domUtils.remove(node,true);
  9889. }
  9890. }
  9891. }
  9892. function autotype(type,html){
  9893. var me = this,cont;
  9894. if(html){
  9895. if(!opt.pasteFilter){
  9896. return;
  9897. }
  9898. cont = me.document.createElement('div');
  9899. cont.innerHTML = html.html;
  9900. }else{
  9901. cont = me.document.body;
  9902. }
  9903. var nodes = domUtils.getElementsByTagName(cont,'*');
  9904. // 行首缩进,段落方向,段间距,段内间距
  9905. for(var i=0,ci;ci=nodes[i++];){
  9906. if(me.fireEvent('excludeNodeinautotype',ci) === true){
  9907. continue;
  9908. }
  9909. //font-size
  9910. if(opt.clearFontSize && ci.style.fontSize){
  9911. domUtils.removeStyle(ci,'font-size');
  9912. removeNotAttributeSpan(ci);
  9913. }
  9914. //font-family
  9915. if(opt.clearFontFamily && ci.style.fontFamily){
  9916. domUtils.removeStyle(ci,'font-family');
  9917. removeNotAttributeSpan(ci);
  9918. }
  9919. if(isLine(ci)){
  9920. //合并空行
  9921. if(opt.mergeEmptyline ){
  9922. var next = ci.nextSibling,tmpNode,isBr = domUtils.isBr(ci);
  9923. while(isLine(next)){
  9924. tmpNode = next;
  9925. next = tmpNode.nextSibling;
  9926. if(isBr && (!next || next && !domUtils.isBr(next))){
  9927. break;
  9928. }
  9929. domUtils.remove(tmpNode);
  9930. }
  9931. }
  9932. //去掉空行,保留占位的空行
  9933. if(opt.removeEmptyline && domUtils.inDoc(ci,cont) && !remainTag[ci.parentNode.tagName.toLowerCase()] ){
  9934. if(domUtils.isBr(ci)){
  9935. next = ci.nextSibling;
  9936. if(next && !domUtils.isBr(next)){
  9937. continue;
  9938. }
  9939. }
  9940. domUtils.remove(ci);
  9941. continue;
  9942. }
  9943. }
  9944. if(isLine(ci,true) && ci.tagName != 'SPAN'){
  9945. if(opt.indent){
  9946. ci.style.textIndent = opt.indentValue;
  9947. }
  9948. if(opt.textAlign){
  9949. ci.style.textAlign = opt.textAlign;
  9950. }
  9951. // if(opt.lineHeight)
  9952. // ci.style.lineHeight = opt.lineHeight + 'cm';
  9953. }
  9954. //去掉class,保留的class不去掉
  9955. if(opt.removeClass && ci.className && !remainClass[ci.className.toLowerCase()]){
  9956. if(highlightCont && highlightCont.contains(ci)){
  9957. continue;
  9958. }
  9959. domUtils.removeAttributes(ci,['class']);
  9960. }
  9961. //表情不处理
  9962. if(opt.imageBlockLine && ci.tagName.toLowerCase() == 'img' && !ci.getAttribute('emotion')){
  9963. if(html){
  9964. var img = ci;
  9965. switch (opt.imageBlockLine){
  9966. case 'left':
  9967. case 'right':
  9968. case 'none':
  9969. var pN = img.parentNode,tmpNode,pre,next;
  9970. while(dtd.$inline[pN.tagName] || pN.tagName == 'A'){
  9971. pN = pN.parentNode;
  9972. }
  9973. tmpNode = pN;
  9974. if(tmpNode.tagName == 'P' && domUtils.getStyle(tmpNode,'text-align') == 'center'){
  9975. if(!domUtils.isBody(tmpNode) && domUtils.getChildCount(tmpNode,function(node){return !domUtils.isBr(node) && !domUtils.isWhitespace(node)}) == 1){
  9976. pre = tmpNode.previousSibling;
  9977. next = tmpNode.nextSibling;
  9978. if(pre && next && pre.nodeType == 1 && next.nodeType == 1 && pre.tagName == next.tagName && domUtils.isBlockElm(pre)){
  9979. pre.appendChild(tmpNode.firstChild);
  9980. while(next.firstChild){
  9981. pre.appendChild(next.firstChild);
  9982. }
  9983. domUtils.remove(tmpNode);
  9984. domUtils.remove(next);
  9985. }else{
  9986. domUtils.setStyle(tmpNode,'text-align','');
  9987. }
  9988. }
  9989. }
  9990. domUtils.setStyle(img,'float', opt.imageBlockLine);
  9991. break;
  9992. case 'center':
  9993. if(me.queryCommandValue('imagefloat') != 'center'){
  9994. pN = img.parentNode;
  9995. domUtils.setStyle(img,'float','none');
  9996. tmpNode = img;
  9997. while(pN && domUtils.getChildCount(pN,function(node){return !domUtils.isBr(node) && !domUtils.isWhitespace(node)}) == 1
  9998. && (dtd.$inline[pN.tagName] || pN.tagName == 'A')){
  9999. tmpNode = pN;
  10000. pN = pN.parentNode;
  10001. }
  10002. var pNode = me.document.createElement('p');
  10003. domUtils.setAttributes(pNode,{
  10004. style:'text-align:center'
  10005. });
  10006. tmpNode.parentNode.insertBefore(pNode,tmpNode);
  10007. pNode.appendChild(tmpNode);
  10008. domUtils.setStyle(tmpNode,'float','');
  10009. }
  10010. }
  10011. } else {
  10012. var range = me.selection.getRange();
  10013. range.selectNode(ci).select();
  10014. me.execCommand('imagefloat', opt.imageBlockLine);
  10015. }
  10016. }
  10017. //去掉冗余的标签
  10018. if(opt.removeEmptyNode){
  10019. if(opt.removeTagNames[ci.tagName.toLowerCase()] && domUtils.hasNoAttributes(ci) && domUtils.isEmptyBlock(ci)){
  10020. domUtils.remove(ci);
  10021. }
  10022. }
  10023. }
  10024. if(opt.tobdc){
  10025. var root = UE.htmlparser(cont.innerHTML);
  10026. root.traversal(function(node){
  10027. if(node.type == 'text'){
  10028. node.data = ToDBC(node.data)
  10029. }
  10030. });
  10031. cont.innerHTML = root.toHtml()
  10032. }
  10033. if(opt.bdc2sb){
  10034. var root = UE.htmlparser(cont.innerHTML);
  10035. root.traversal(function(node){
  10036. if(node.type == 'text'){
  10037. node.data = DBC2SB(node.data)
  10038. }
  10039. });
  10040. cont.innerHTML = root.toHtml()
  10041. }
  10042. if(html){
  10043. html.html = cont.innerHTML;
  10044. }
  10045. }
  10046. if(opt.pasteFilter){
  10047. me.addListener('beforepaste',autotype);
  10048. }
  10049. function DBC2SB(str) {
  10050. var result = '';
  10051. for (var i = 0; i < str.length; i++) {
  10052. var code = str.charCodeAt(i); //获取当前字符的unicode编码
  10053. if (code >= 65281 && code <= 65373)//在这个unicode编码范围中的是所有的英文字母已经各种字符
  10054. {
  10055. result += String.fromCharCode(str.charCodeAt(i) - 65248); //把全角字符的unicode编码转换为对应半角字符的unicode码
  10056. } else if (code == 12288)//空格
  10057. {
  10058. result += String.fromCharCode(str.charCodeAt(i) - 12288 + 32);
  10059. } else {
  10060. result += str.charAt(i);
  10061. }
  10062. }
  10063. return result;
  10064. }
  10065. function ToDBC(txtstring) {
  10066. txtstring = utils.html(txtstring);
  10067. var tmp = "";
  10068. var mark = "";/*用于判断,如果是html尖括里的标记,则不进行全角的转换*/
  10069. for (var i = 0; i < txtstring.length; i++) {
  10070. if (txtstring.charCodeAt(i) == 32) {
  10071. tmp = tmp + String.fromCharCode(12288);
  10072. }
  10073. else if (txtstring.charCodeAt(i) < 127) {
  10074. tmp = tmp + String.fromCharCode(txtstring.charCodeAt(i) + 65248);
  10075. }
  10076. else {
  10077. tmp += txtstring.charAt(i);
  10078. }
  10079. }
  10080. return tmp;
  10081. }
  10082. function readLocalOpts() {
  10083. var cookieOpt = me.getPreferences('autotypeset');
  10084. utils.extend(me.options.autotypeset, cookieOpt);
  10085. }
  10086. me.commands['autotypeset'] = {
  10087. execCommand:function () {
  10088. me.removeListener('beforepaste',autotype);
  10089. if(opt.pasteFilter){
  10090. me.addListener('beforepaste',autotype);
  10091. }
  10092. autotype.call(me)
  10093. }
  10094. };
  10095. };
  10096. // plugins/autosubmit.js
  10097. /**
  10098. * 快捷键提交
  10099. * @file
  10100. * @since 1.2.6.1
  10101. */
  10102. /**
  10103. * 提交表单
  10104. * @command autosubmit
  10105. * @method execCommand
  10106. * @param { String } cmd 命令字符串
  10107. * @example
  10108. * ```javascript
  10109. * editor.execCommand( 'autosubmit' );
  10110. * ```
  10111. */
  10112. UE.plugin.register('autosubmit',function(){
  10113. return {
  10114. shortcutkey:{
  10115. "autosubmit":"ctrl+13" //手动提交
  10116. },
  10117. commands:{
  10118. 'autosubmit':{
  10119. execCommand:function () {
  10120. var me=this,
  10121. form = domUtils.findParentByTagName(me.iframe,"form", false);
  10122. if (form){
  10123. if(me.fireEvent("beforesubmit")===false){
  10124. return;
  10125. }
  10126. me.sync();
  10127. form.submit();
  10128. }
  10129. }
  10130. }
  10131. }
  10132. }
  10133. });
  10134. // plugins/background.js
  10135. /**
  10136. * 背景插件,为UEditor提供设置背景功能
  10137. * @file
  10138. * @since 1.2.6.1
  10139. */
  10140. UE.plugin.register('background', function () {
  10141. var me = this,
  10142. cssRuleId = 'editor_background',
  10143. isSetColored,
  10144. reg = new RegExp('body[\\s]*\\{(.+)\\}', 'i');
  10145. function stringToObj(str) {
  10146. var obj = {}, styles = str.split(';');
  10147. utils.each(styles, function (v) {
  10148. var index = v.indexOf(':'),
  10149. key = utils.trim(v.substr(0, index)).toLowerCase();
  10150. key && (obj[key] = utils.trim(v.substr(index + 1) || ''));
  10151. });
  10152. return obj;
  10153. }
  10154. function setBackground(obj) {
  10155. if (obj) {
  10156. var styles = [];
  10157. for (var name in obj) {
  10158. if (obj.hasOwnProperty(name)) {
  10159. styles.push(name + ":" + obj[name] + '; ');
  10160. }
  10161. }
  10162. utils.cssRule(cssRuleId, styles.length ? ('body{' + styles.join("") + '}') : '', me.document);
  10163. } else {
  10164. utils.cssRule(cssRuleId, '', me.document)
  10165. }
  10166. }
  10167. //重写editor.hasContent方法
  10168. var orgFn = me.hasContents;
  10169. me.hasContents = function(){
  10170. if(me.queryCommandValue('background')){
  10171. return true
  10172. }
  10173. return orgFn.apply(me,arguments);
  10174. };
  10175. return {
  10176. bindEvents: {
  10177. 'getAllHtml': function (type, headHtml) {
  10178. var body = this.body,
  10179. su = domUtils.getComputedStyle(body, "background-image"),
  10180. url = "";
  10181. if (su.indexOf(me.options.imagePath) > 0) {
  10182. url = su.substring(su.indexOf(me.options.imagePath), su.length - 1).replace(/"|\(|\)/ig, "");
  10183. } else {
  10184. url = su != "none" ? su.replace(/url\("?|"?\)/ig, "") : "";
  10185. }
  10186. var html = '<style type="text/css">body{';
  10187. var bgObj = {
  10188. "background-color": domUtils.getComputedStyle(body, "background-color") || "#ffffff",
  10189. 'background-image': url ? 'url(' + url + ')' : '',
  10190. 'background-repeat': domUtils.getComputedStyle(body, "background-repeat") || "",
  10191. 'background-position': browser.ie ? (domUtils.getComputedStyle(body, "background-position-x") + " " + domUtils.getComputedStyle(body, "background-position-y")) : domUtils.getComputedStyle(body, "background-position"),
  10192. 'height': domUtils.getComputedStyle(body, "height")
  10193. };
  10194. for (var name in bgObj) {
  10195. if (bgObj.hasOwnProperty(name)) {
  10196. html += name + ":" + bgObj[name] + "; ";
  10197. }
  10198. }
  10199. html += '}</style> ';
  10200. headHtml.push(html);
  10201. },
  10202. 'aftersetcontent': function () {
  10203. if(isSetColored == false) setBackground();
  10204. }
  10205. },
  10206. inputRule: function (root) {
  10207. isSetColored = false;
  10208. utils.each(root.getNodesByTagName('p'), function (p) {
  10209. var styles = p.getAttr('data-background');
  10210. if (styles) {
  10211. isSetColored = true;
  10212. setBackground(stringToObj(styles));
  10213. p.parentNode.removeChild(p);
  10214. }
  10215. })
  10216. },
  10217. outputRule: function (root) {
  10218. var me = this,
  10219. styles = (utils.cssRule(cssRuleId, me.document) || '').replace(/[\n\r]+/g, '').match(reg);
  10220. if (styles) {
  10221. root.appendChild(UE.uNode.createElement('<p style="display:none;" data-background="' + utils.trim(styles[1].replace(/"/g, '').replace(/[\s]+/g, ' ')) + '"><br/></p>'));
  10222. }
  10223. },
  10224. commands: {
  10225. 'background': {
  10226. execCommand: function (cmd, obj) {
  10227. setBackground(obj);
  10228. },
  10229. queryCommandValue: function () {
  10230. var me = this,
  10231. styles = (utils.cssRule(cssRuleId, me.document) || '').replace(/[\n\r]+/g, '').match(reg);
  10232. return styles ? stringToObj(styles[1]) : null;
  10233. },
  10234. notNeedUndo: true
  10235. }
  10236. }
  10237. }
  10238. });
  10239. // plugins/image.js
  10240. /**
  10241. * 图片插入、排版插件
  10242. * @file
  10243. * @since 1.2.6.1
  10244. */
  10245. /**
  10246. * 图片对齐方式
  10247. * @command imagefloat
  10248. * @method execCommand
  10249. * @remind 值center为独占一行居中
  10250. * @param { String } cmd 命令字符串
  10251. * @param { String } align 对齐方式,可传left、right、none、center
  10252. * @remaind center表示图片独占一行
  10253. * @example
  10254. * ```javascript
  10255. * editor.execCommand( 'imagefloat', 'center' );
  10256. * ```
  10257. */
  10258. /**
  10259. * 如果选区所在位置是图片区域
  10260. * @command imagefloat
  10261. * @method queryCommandValue
  10262. * @param { String } cmd 命令字符串
  10263. * @return { String } 返回图片对齐方式
  10264. * @example
  10265. * ```javascript
  10266. * editor.queryCommandValue( 'imagefloat' );
  10267. * ```
  10268. */
  10269. UE.commands['imagefloat'] = {
  10270. execCommand:function (cmd, align) {
  10271. var me = this,
  10272. range = me.selection.getRange();
  10273. if (!range.collapsed) {
  10274. var img = range.getClosedNode();
  10275. if (img && img.tagName == 'IMG') {
  10276. switch (align) {
  10277. case 'left':
  10278. case 'right':
  10279. case 'none':
  10280. var pN = img.parentNode, tmpNode, pre, next;
  10281. while (dtd.$inline[pN.tagName] || pN.tagName == 'A') {
  10282. pN = pN.parentNode;
  10283. }
  10284. tmpNode = pN;
  10285. if (tmpNode.tagName == 'P' && domUtils.getStyle(tmpNode, 'text-align') == 'center') {
  10286. if (!domUtils.isBody(tmpNode) && domUtils.getChildCount(tmpNode, function (node) {
  10287. return !domUtils.isBr(node) && !domUtils.isWhitespace(node);
  10288. }) == 1) {
  10289. pre = tmpNode.previousSibling;
  10290. next = tmpNode.nextSibling;
  10291. if (pre && next && pre.nodeType == 1 && next.nodeType == 1 && pre.tagName == next.tagName && domUtils.isBlockElm(pre)) {
  10292. pre.appendChild(tmpNode.firstChild);
  10293. while (next.firstChild) {
  10294. pre.appendChild(next.firstChild);
  10295. }
  10296. domUtils.remove(tmpNode);
  10297. domUtils.remove(next);
  10298. } else {
  10299. domUtils.setStyle(tmpNode, 'text-align', '');
  10300. }
  10301. }
  10302. range.selectNode(img).select();
  10303. }
  10304. domUtils.setStyle(img, 'float', align == 'none' ? '' : align);
  10305. if(align == 'none'){
  10306. domUtils.removeAttributes(img,'align');
  10307. }
  10308. break;
  10309. case 'center':
  10310. if (me.queryCommandValue('imagefloat') != 'center') {
  10311. pN = img.parentNode;
  10312. domUtils.setStyle(img, 'float', '');
  10313. domUtils.removeAttributes(img,'align');
  10314. tmpNode = img;
  10315. while (pN && domUtils.getChildCount(pN, function (node) {
  10316. return !domUtils.isBr(node) && !domUtils.isWhitespace(node);
  10317. }) == 1
  10318. && (dtd.$inline[pN.tagName] || pN.tagName == 'A')) {
  10319. tmpNode = pN;
  10320. pN = pN.parentNode;
  10321. }
  10322. range.setStartBefore(tmpNode).setCursor(false);
  10323. pN = me.document.createElement('div');
  10324. pN.appendChild(tmpNode);
  10325. domUtils.setStyle(tmpNode, 'float', '');
  10326. me.execCommand('insertHtml', '<p id="_img_parent_tmp" style="text-align:center">' + pN.innerHTML + '</p>');
  10327. tmpNode = me.document.getElementById('_img_parent_tmp');
  10328. tmpNode.removeAttribute('id');
  10329. tmpNode = tmpNode.firstChild;
  10330. range.selectNode(tmpNode).select();
  10331. //去掉后边多余的元素
  10332. next = tmpNode.parentNode.nextSibling;
  10333. if (next && domUtils.isEmptyNode(next)) {
  10334. domUtils.remove(next);
  10335. }
  10336. }
  10337. break;
  10338. }
  10339. }
  10340. }
  10341. },
  10342. queryCommandValue:function () {
  10343. var range = this.selection.getRange(),
  10344. startNode, floatStyle;
  10345. if (range.collapsed) {
  10346. return 'none';
  10347. }
  10348. startNode = range.getClosedNode();
  10349. if (startNode && startNode.nodeType == 1 && startNode.tagName == 'IMG') {
  10350. floatStyle = domUtils.getComputedStyle(startNode, 'float') || startNode.getAttribute('align');
  10351. if (floatStyle == 'none') {
  10352. floatStyle = domUtils.getComputedStyle(startNode.parentNode, 'text-align') == 'center' ? 'center' : floatStyle;
  10353. }
  10354. return {
  10355. left:1,
  10356. right:1,
  10357. center:1
  10358. }[floatStyle] ? floatStyle : 'none';
  10359. }
  10360. return 'none';
  10361. },
  10362. queryCommandState:function () {
  10363. var range = this.selection.getRange(),
  10364. startNode;
  10365. if (range.collapsed) return -1;
  10366. startNode = range.getClosedNode();
  10367. if (startNode && startNode.nodeType == 1 && startNode.tagName == 'IMG') {
  10368. return 0;
  10369. }
  10370. return -1;
  10371. }
  10372. };
  10373. /**
  10374. * 插入图片
  10375. * @command insertimage
  10376. * @method execCommand
  10377. * @param { String } cmd 命令字符串
  10378. * @param { Object } opt 属性键值对,这些属性都将被复制到当前插入图片
  10379. * @remind 该命令第二个参数可接受一个图片配置项对象的数组,可以插入多张图片,
  10380. * 此时数组的每一个元素都是一个Object类型的图片属性集合。
  10381. * @example
  10382. * ```javascript
  10383. * editor.execCommand( 'insertimage', {
  10384. * src:'a/b/c.jpg',
  10385. * width:'100',
  10386. * height:'100'
  10387. * } );
  10388. * ```
  10389. * @example
  10390. * ```javascript
  10391. * editor.execCommand( 'insertimage', [{
  10392. * src:'a/b/c.jpg',
  10393. * width:'100',
  10394. * height:'100'
  10395. * },{
  10396. * src:'a/b/d.jpg',
  10397. * width:'100',
  10398. * height:'100'
  10399. * }] );
  10400. * ```
  10401. */
  10402. UE.commands['insertimage'] = {
  10403. execCommand:function (cmd, opt) {
  10404. opt = utils.isArray(opt) ? opt : [opt];
  10405. if (!opt.length) {
  10406. return;
  10407. }
  10408. var me = this,
  10409. range = me.selection.getRange(),
  10410. img = range.getClosedNode();
  10411. if(me.fireEvent('beforeinsertimage', opt) === true){
  10412. return;
  10413. }
  10414. function unhtmlData(imgCi) {
  10415. utils.each('width,height,border,hspace,vspace'.split(','), function (item) {
  10416. if (imgCi[item]) {
  10417. imgCi[item] = parseInt(imgCi[item], 10) || 0;
  10418. }
  10419. });
  10420. utils.each('src,_src'.split(','), function (item) {
  10421. if (imgCi[item]) {
  10422. imgCi[item] = utils.unhtmlForUrl(imgCi[item]);
  10423. }
  10424. });
  10425. utils.each('title,alt'.split(','), function (item) {
  10426. if (imgCi[item]) {
  10427. imgCi[item] = utils.unhtml(imgCi[item]);
  10428. }
  10429. });
  10430. }
  10431. if (img && /img/i.test(img.tagName) && (img.className != "edui-faked-video" || img.className.indexOf("edui-upload-video")!=-1) && !img.getAttribute("word_img")) {
  10432. var first = opt.shift();
  10433. var floatStyle = first['floatStyle'];
  10434. delete first['floatStyle'];
  10435. //// img.style.border = (first.border||0) +"px solid #000";
  10436. //// img.style.margin = (first.margin||0) +"px";
  10437. // img.style.cssText += ';margin:' + (first.margin||0) +"px;" + 'border:' + (first.border||0) +"px solid #000";
  10438. domUtils.setAttributes(img, first);
  10439. me.execCommand('imagefloat', floatStyle);
  10440. if (opt.length > 0) {
  10441. range.setStartAfter(img).setCursor(false, true);
  10442. me.execCommand('insertimage', opt);
  10443. }
  10444. } else {
  10445. var html = [], str = '', ci;
  10446. ci = opt[0];
  10447. if (opt.length == 1) {
  10448. unhtmlData(ci);
  10449. str = '<img src="' + ci.src + '" ' + (ci._src ? ' _src="' + ci._src + '" ' : '') +
  10450. (ci.width ? 'width="' + ci.width + '" ' : '') +
  10451. (ci.height ? ' height="' + ci.height + '" ' : '') +
  10452. (ci['floatStyle'] == 'left' || ci['floatStyle'] == 'right' ? ' style="float:' + ci['floatStyle'] + ';"' : '') +
  10453. (ci.title && ci.title != "" ? ' title="' + ci.title + '"' : '') +
  10454. (ci.border && ci.border != "0" ? ' border="' + ci.border + '"' : '') +
  10455. (ci.alt && ci.alt != "" ? ' alt="' + ci.alt + '"' : '') +
  10456. (ci.hspace && ci.hspace != "0" ? ' hspace = "' + ci.hspace + '"' : '') +
  10457. (ci.vspace && ci.vspace != "0" ? ' vspace = "' + ci.vspace + '"' : '') + '/>';
  10458. if (ci['floatStyle'] == 'center') {
  10459. str = '<p style="text-align: center">' + str + '</p>';
  10460. }
  10461. html.push(str);
  10462. } else {
  10463. for (var i = 0; ci = opt[i++];) {
  10464. unhtmlData(ci);
  10465. str = '<p ' + (ci['floatStyle'] == 'center' ? 'style="text-align: center" ' : '') + '><img src="' + ci.src + '" ' +
  10466. (ci.width ? 'width="' + ci.width + '" ' : '') + (ci._src ? ' _src="' + ci._src + '" ' : '') +
  10467. (ci.height ? ' height="' + ci.height + '" ' : '') +
  10468. ' style="' + (ci['floatStyle'] && ci['floatStyle'] != 'center' ? 'float:' + ci['floatStyle'] + ';' : '') +
  10469. (ci.border || '') + '" ' +
  10470. (ci.title ? ' title="' + ci.title + '"' : '') + ' /></p>';
  10471. html.push(str);
  10472. }
  10473. }
  10474. me.execCommand('insertHtml', html.join(''));
  10475. }
  10476. me.fireEvent('afterinsertimage', opt)
  10477. }
  10478. };
  10479. // plugins/justify.js
  10480. /**
  10481. * 段落格式
  10482. * @file
  10483. * @since 1.2.6.1
  10484. */
  10485. /**
  10486. * 段落对齐方式
  10487. * @command justify
  10488. * @method execCommand
  10489. * @param { String } cmd 命令字符串
  10490. * @param { String } align 对齐方式:left => 居左,right => 居右,center => 居中,justify => 两端对齐
  10491. * @example
  10492. * ```javascript
  10493. * editor.execCommand( 'justify', 'center' );
  10494. * ```
  10495. */
  10496. /**
  10497. * 如果选区所在位置是段落区域,返回当前段落对齐方式
  10498. * @command justify
  10499. * @method queryCommandValue
  10500. * @param { String } cmd 命令字符串
  10501. * @return { String } 返回段落对齐方式
  10502. * @example
  10503. * ```javascript
  10504. * editor.queryCommandValue( 'justify' );
  10505. * ```
  10506. */
  10507. UE.plugins['justify']=function(){
  10508. var me=this,
  10509. block = domUtils.isBlockElm,
  10510. defaultValue = {
  10511. left:1,
  10512. right:1,
  10513. center:1,
  10514. justify:1
  10515. },
  10516. doJustify = function (range, style) {
  10517. var bookmark = range.createBookmark(),
  10518. filterFn = function (node) {
  10519. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' && !domUtils.isBookmarkNode(node) : !domUtils.isWhitespace(node);
  10520. };
  10521. range.enlarge(true);
  10522. var bookmark2 = range.createBookmark(),
  10523. current = domUtils.getNextDomNode(bookmark2.start, false, filterFn),
  10524. tmpRange = range.cloneRange(),
  10525. tmpNode;
  10526. while (current && !(domUtils.getPosition(current, bookmark2.end) & domUtils.POSITION_FOLLOWING)) {
  10527. if (current.nodeType == 3 || !block(current)) {
  10528. tmpRange.setStartBefore(current);
  10529. while (current && current !== bookmark2.end && !block(current)) {
  10530. tmpNode = current;
  10531. current = domUtils.getNextDomNode(current, false, null, function (node) {
  10532. return !block(node);
  10533. });
  10534. }
  10535. tmpRange.setEndAfter(tmpNode);
  10536. var common = tmpRange.getCommonAncestor();
  10537. if (!domUtils.isBody(common) && block(common)) {
  10538. domUtils.setStyles(common, utils.isString(style) ? {'text-align':style} : style);
  10539. current = common;
  10540. } else {
  10541. var p = range.document.createElement('p');
  10542. domUtils.setStyles(p, utils.isString(style) ? {'text-align':style} : style);
  10543. var frag = tmpRange.extractContents();
  10544. p.appendChild(frag);
  10545. tmpRange.insertNode(p);
  10546. current = p;
  10547. }
  10548. current = domUtils.getNextDomNode(current, false, filterFn);
  10549. } else {
  10550. current = domUtils.getNextDomNode(current, true, filterFn);
  10551. }
  10552. }
  10553. return range.moveToBookmark(bookmark2).moveToBookmark(bookmark);
  10554. };
  10555. UE.commands['justify'] = {
  10556. execCommand:function (cmdName, align) {
  10557. var range = this.selection.getRange(),
  10558. txt;
  10559. //闭合时单独处理
  10560. if (range.collapsed) {
  10561. txt = this.document.createTextNode('p');
  10562. range.insertNode(txt);
  10563. }
  10564. doJustify(range, align);
  10565. if (txt) {
  10566. range.setStartBefore(txt).collapse(true);
  10567. domUtils.remove(txt);
  10568. }
  10569. range.select();
  10570. return true;
  10571. },
  10572. queryCommandValue:function () {
  10573. var startNode = this.selection.getStart(),
  10574. value = domUtils.getComputedStyle(startNode, 'text-align');
  10575. return defaultValue[value] ? value : 'left';
  10576. },
  10577. queryCommandState:function () {
  10578. var start = this.selection.getStart(),
  10579. cell = start && domUtils.findParentByTagName(start, ["td", "th","caption"], true);
  10580. return cell? -1:0;
  10581. }
  10582. };
  10583. };
  10584. // plugins/font.js
  10585. /**
  10586. * 字体颜色,背景色,字号,字体,下划线,删除线
  10587. * @file
  10588. * @since 1.2.6.1
  10589. */
  10590. /**
  10591. * 字体颜色
  10592. * @command forecolor
  10593. * @method execCommand
  10594. * @param { String } cmd 命令字符串
  10595. * @param { String } value 色值(必须十六进制)
  10596. * @example
  10597. * ```javascript
  10598. * editor.execCommand( 'forecolor', '#000' );
  10599. * ```
  10600. */
  10601. /**
  10602. * 返回选区字体颜色
  10603. * @command forecolor
  10604. * @method queryCommandValue
  10605. * @param { String } cmd 命令字符串
  10606. * @return { String } 返回字体颜色
  10607. * @example
  10608. * ```javascript
  10609. * editor.queryCommandValue( 'forecolor' );
  10610. * ```
  10611. */
  10612. /**
  10613. * 字体背景颜色
  10614. * @command backcolor
  10615. * @method execCommand
  10616. * @param { String } cmd 命令字符串
  10617. * @param { String } value 色值(必须十六进制)
  10618. * @example
  10619. * ```javascript
  10620. * editor.execCommand( 'backcolor', '#000' );
  10621. * ```
  10622. */
  10623. /**
  10624. * 返回选区字体颜色
  10625. * @command backcolor
  10626. * @method queryCommandValue
  10627. * @param { String } cmd 命令字符串
  10628. * @return { String } 返回字体背景颜色
  10629. * @example
  10630. * ```javascript
  10631. * editor.queryCommandValue( 'backcolor' );
  10632. * ```
  10633. */
  10634. /**
  10635. * 字体大小
  10636. * @command fontsize
  10637. * @method execCommand
  10638. * @param { String } cmd 命令字符串
  10639. * @param { String } value 字体大小
  10640. * @example
  10641. * ```javascript
  10642. * editor.execCommand( 'fontsize', '14px' );
  10643. * ```
  10644. */
  10645. /**
  10646. * 返回选区字体大小
  10647. * @command fontsize
  10648. * @method queryCommandValue
  10649. * @param { String } cmd 命令字符串
  10650. * @return { String } 返回字体大小
  10651. * @example
  10652. * ```javascript
  10653. * editor.queryCommandValue( 'fontsize' );
  10654. * ```
  10655. */
  10656. /**
  10657. * 字体样式
  10658. * @command fontfamily
  10659. * @method execCommand
  10660. * @param { String } cmd 命令字符串
  10661. * @param { String } value 字体样式
  10662. * @example
  10663. * ```javascript
  10664. * editor.execCommand( 'fontfamily', '微软雅黑' );
  10665. * ```
  10666. */
  10667. /**
  10668. * 返回选区字体样式
  10669. * @command fontfamily
  10670. * @method queryCommandValue
  10671. * @param { String } cmd 命令字符串
  10672. * @return { String } 返回字体样式
  10673. * @example
  10674. * ```javascript
  10675. * editor.queryCommandValue( 'fontfamily' );
  10676. * ```
  10677. */
  10678. /**
  10679. * 字体下划线,与删除线互斥
  10680. * @command underline
  10681. * @method execCommand
  10682. * @param { String } cmd 命令字符串
  10683. * @example
  10684. * ```javascript
  10685. * editor.execCommand( 'underline' );
  10686. * ```
  10687. */
  10688. /**
  10689. * 字体删除线,与下划线互斥
  10690. * @command strikethrough
  10691. * @method execCommand
  10692. * @param { String } cmd 命令字符串
  10693. * @example
  10694. * ```javascript
  10695. * editor.execCommand( 'strikethrough' );
  10696. * ```
  10697. */
  10698. /**
  10699. * 字体边框
  10700. * @command fontborder
  10701. * @method execCommand
  10702. * @param { String } cmd 命令字符串
  10703. * @example
  10704. * ```javascript
  10705. * editor.execCommand( 'fontborder' );
  10706. * ```
  10707. */
  10708. UE.plugins['font'] = function () {
  10709. var me = this,
  10710. fonts = {
  10711. 'forecolor': 'color',
  10712. 'backcolor': 'background-color',
  10713. 'fontsize': 'font-size',
  10714. 'fontfamily': 'font-family',
  10715. 'underline': 'text-decoration',
  10716. 'strikethrough': 'text-decoration',
  10717. 'fontborder': 'border'
  10718. },
  10719. needCmd = {'underline': 1, 'strikethrough': 1, 'fontborder': 1},
  10720. needSetChild = {
  10721. 'forecolor': 'color',
  10722. 'backcolor': 'background-color',
  10723. 'fontsize': 'font-size',
  10724. 'fontfamily': 'font-family'
  10725. };
  10726. me.setOpt({
  10727. 'fontfamily': [
  10728. { name: 'songti', val: '宋体,SimSun'},
  10729. { name: 'yahei', val: '微软雅黑,Microsoft YaHei'},
  10730. { name: 'kaiti', val: '楷体,楷体_GB2312, SimKai'},
  10731. { name: 'heiti', val: '黑体, SimHei'},
  10732. { name: 'lishu', val: '隶书, SimLi'},
  10733. { name: 'andaleMono', val: 'andale mono'},
  10734. { name: 'arial', val: 'arial, helvetica,sans-serif'},
  10735. { name: 'arialBlack', val: 'arial black,avant garde'},
  10736. { name: 'comicSansMs', val: 'comic sans ms'},
  10737. { name: 'impact', val: 'impact,chicago'},
  10738. { name: 'timesNewRoman', val: 'times new roman'}
  10739. ],
  10740. 'fontsize': [10, 11, 12, 14, 16, 18, 20, 24, 36]
  10741. });
  10742. function mergeWithParent(node){
  10743. var parent;
  10744. while(parent = node.parentNode){
  10745. if(parent.tagName == 'SPAN' && domUtils.getChildCount(parent,function(child){
  10746. return !domUtils.isBookmarkNode(child) && !domUtils.isBr(child)
  10747. }) == 1) {
  10748. parent.style.cssText += node.style.cssText;
  10749. domUtils.remove(node,true);
  10750. node = parent;
  10751. }else{
  10752. break;
  10753. }
  10754. }
  10755. }
  10756. function mergeChild(rng,cmdName,value){
  10757. if(needSetChild[cmdName]){
  10758. rng.adjustmentBoundary();
  10759. if(!rng.collapsed && rng.startContainer.nodeType == 1){
  10760. var start = rng.startContainer.childNodes[rng.startOffset];
  10761. if(start && domUtils.isTagNode(start,'span')){
  10762. var bk = rng.createBookmark();
  10763. utils.each(domUtils.getElementsByTagName(start, 'span'), function (span) {
  10764. if (!span.parentNode || domUtils.isBookmarkNode(span))return;
  10765. if(cmdName == 'backcolor' && domUtils.getComputedStyle(span,'background-color').toLowerCase() === value){
  10766. return;
  10767. }
  10768. domUtils.removeStyle(span,needSetChild[cmdName]);
  10769. if(span.style.cssText.replace(/^\s+$/,'').length == 0){
  10770. domUtils.remove(span,true)
  10771. }
  10772. });
  10773. rng.moveToBookmark(bk)
  10774. }
  10775. }
  10776. }
  10777. }
  10778. function mergesibling(rng,cmdName,value) {
  10779. var collapsed = rng.collapsed,
  10780. bk = rng.createBookmark(), common;
  10781. if (collapsed) {
  10782. common = bk.start.parentNode;
  10783. while (dtd.$inline[common.tagName]) {
  10784. common = common.parentNode;
  10785. }
  10786. } else {
  10787. common = domUtils.getCommonAncestor(bk.start, bk.end);
  10788. }
  10789. utils.each(domUtils.getElementsByTagName(common, 'span'), function (span) {
  10790. if (!span.parentNode || domUtils.isBookmarkNode(span))return;
  10791. if (/\s*border\s*:\s*none;?\s*/i.test(span.style.cssText)) {
  10792. if(/^\s*border\s*:\s*none;?\s*$/.test(span.style.cssText)){
  10793. domUtils.remove(span, true);
  10794. }else{
  10795. domUtils.removeStyle(span,'border');
  10796. }
  10797. return
  10798. }
  10799. if (/border/i.test(span.style.cssText) && span.parentNode.tagName == 'SPAN' && /border/i.test(span.parentNode.style.cssText)) {
  10800. span.style.cssText = span.style.cssText.replace(/border[^:]*:[^;]+;?/gi, '');
  10801. }
  10802. if(!(cmdName=='fontborder' && value=='none')){
  10803. var next = span.nextSibling;
  10804. while (next && next.nodeType == 1 && next.tagName == 'SPAN' ) {
  10805. if(domUtils.isBookmarkNode(next) && cmdName == 'fontborder') {
  10806. span.appendChild(next);
  10807. next = span.nextSibling;
  10808. continue;
  10809. }
  10810. if (next.style.cssText == span.style.cssText) {
  10811. domUtils.moveChild(next, span);
  10812. domUtils.remove(next);
  10813. }
  10814. if (span.nextSibling === next)
  10815. break;
  10816. next = span.nextSibling;
  10817. }
  10818. }
  10819. mergeWithParent(span);
  10820. if(browser.ie && browser.version > 8 ){
  10821. //拷贝父亲们的特别的属性,这里只做背景颜色的处理
  10822. var parent = domUtils.findParent(span,function(n){return n.tagName == 'SPAN' && /background-color/.test(n.style.cssText)});
  10823. if(parent && !/background-color/.test(span.style.cssText)){
  10824. span.style.backgroundColor = parent.style.backgroundColor;
  10825. }
  10826. }
  10827. });
  10828. rng.moveToBookmark(bk);
  10829. mergeChild(rng,cmdName,value)
  10830. }
  10831. me.addInputRule(function (root) {
  10832. utils.each(root.getNodesByTagName('u s del font strike'), function (node) {
  10833. if (node.tagName == 'font') {
  10834. var cssStyle = [];
  10835. for (var p in node.attrs) {
  10836. switch (p) {
  10837. case 'size':
  10838. cssStyle.push('font-size:' +
  10839. ({
  10840. '1':'10',
  10841. '2':'12',
  10842. '3':'16',
  10843. '4':'18',
  10844. '5':'24',
  10845. '6':'32',
  10846. '7':'48'
  10847. }[node.attrs[p]] || node.attrs[p]) + 'px');
  10848. break;
  10849. case 'color':
  10850. cssStyle.push('color:' + node.attrs[p]);
  10851. break;
  10852. case 'face':
  10853. cssStyle.push('font-family:' + node.attrs[p]);
  10854. break;
  10855. case 'style':
  10856. cssStyle.push(node.attrs[p]);
  10857. }
  10858. }
  10859. node.attrs = {
  10860. 'style': cssStyle.join(';')
  10861. };
  10862. } else {
  10863. var val = node.tagName == 'u' ? 'underline' : 'line-through';
  10864. node.attrs = {
  10865. 'style': (node.getAttr('style') || '') + 'text-decoration:' + val + ';'
  10866. }
  10867. }
  10868. node.tagName = 'span';
  10869. });
  10870. // utils.each(root.getNodesByTagName('span'), function (node) {
  10871. // var val;
  10872. // if(val = node.getAttr('class')){
  10873. // if(/fontstrikethrough/.test(val)){
  10874. // node.setStyle('text-decoration','line-through');
  10875. // if(node.attrs['class']){
  10876. // node.attrs['class'] = node.attrs['class'].replace(/fontstrikethrough/,'');
  10877. // }else{
  10878. // node.setAttr('class')
  10879. // }
  10880. // }
  10881. // if(/fontborder/.test(val)){
  10882. // node.setStyle('border','1px solid #000');
  10883. // if(node.attrs['class']){
  10884. // node.attrs['class'] = node.attrs['class'].replace(/fontborder/,'');
  10885. // }else{
  10886. // node.setAttr('class')
  10887. // }
  10888. // }
  10889. // }
  10890. // });
  10891. });
  10892. // me.addOutputRule(function(root){
  10893. // utils.each(root.getNodesByTagName('span'), function (node) {
  10894. // var val;
  10895. // if(val = node.getStyle('text-decoration')){
  10896. // if(/line-through/.test(val)){
  10897. // if(node.attrs['class']){
  10898. // node.attrs['class'] += ' fontstrikethrough';
  10899. // }else{
  10900. // node.setAttr('class','fontstrikethrough')
  10901. // }
  10902. // }
  10903. //
  10904. // node.setStyle('text-decoration')
  10905. // }
  10906. // if(val = node.getStyle('border')){
  10907. // if(/1px/.test(val) && /solid/.test(val)){
  10908. // if(node.attrs['class']){
  10909. // node.attrs['class'] += ' fontborder';
  10910. //
  10911. // }else{
  10912. // node.setAttr('class','fontborder')
  10913. // }
  10914. // }
  10915. // node.setStyle('border')
  10916. //
  10917. // }
  10918. // });
  10919. // });
  10920. for (var p in fonts) {
  10921. (function (cmd, style) {
  10922. UE.commands[cmd] = {
  10923. execCommand: function (cmdName, value) {
  10924. value = value || (this.queryCommandState(cmdName) ? 'none' : cmdName == 'underline' ? 'underline' :
  10925. cmdName == 'fontborder' ? '1px solid #000' :
  10926. 'line-through');
  10927. var me = this,
  10928. range = this.selection.getRange(),
  10929. text;
  10930. if (value == 'default') {
  10931. if (range.collapsed) {
  10932. text = me.document.createTextNode('font');
  10933. range.insertNode(text).select();
  10934. }
  10935. me.execCommand('removeFormat', 'span,a', style);
  10936. if (text) {
  10937. range.setStartBefore(text).collapse(true);
  10938. domUtils.remove(text);
  10939. }
  10940. mergesibling(range,cmdName,value);
  10941. range.select()
  10942. } else {
  10943. if (!range.collapsed) {
  10944. if (needCmd[cmd] && me.queryCommandValue(cmd)) {
  10945. me.execCommand('removeFormat', 'span,a', style);
  10946. }
  10947. range = me.selection.getRange();
  10948. range.applyInlineStyle('span', {'style': style + ':' + value});
  10949. mergesibling(range, cmdName,value);
  10950. range.select();
  10951. } else {
  10952. var span = domUtils.findParentByTagName(range.startContainer, 'span', true);
  10953. text = me.document.createTextNode('font');
  10954. if (span && !span.children.length && !span[browser.ie ? 'innerText' : 'textContent'].replace(fillCharReg, '').length) {
  10955. //for ie hack when enter
  10956. range.insertNode(text);
  10957. if (needCmd[cmd]) {
  10958. range.selectNode(text).select();
  10959. me.execCommand('removeFormat', 'span,a', style, null);
  10960. span = domUtils.findParentByTagName(text, 'span', true);
  10961. range.setStartBefore(text);
  10962. }
  10963. span && (span.style.cssText += ';' + style + ':' + value);
  10964. range.collapse(true).select();
  10965. } else {
  10966. range.insertNode(text);
  10967. range.selectNode(text).select();
  10968. span = range.document.createElement('span');
  10969. if (needCmd[cmd]) {
  10970. //a标签内的不处理跳过
  10971. if (domUtils.findParentByTagName(text, 'a', true)) {
  10972. range.setStartBefore(text).setCursor();
  10973. domUtils.remove(text);
  10974. return;
  10975. }
  10976. me.execCommand('removeFormat', 'span,a', style);
  10977. }
  10978. span.style.cssText = style + ':' + value;
  10979. text.parentNode.insertBefore(span, text);
  10980. //修复,span套span 但样式不继承的问题
  10981. if (!browser.ie || browser.ie && browser.version == 9) {
  10982. var spanParent = span.parentNode;
  10983. while (!domUtils.isBlockElm(spanParent)) {
  10984. if (spanParent.tagName == 'SPAN') {
  10985. //opera合并style不会加入";"
  10986. span.style.cssText = spanParent.style.cssText + ";" + span.style.cssText;
  10987. }
  10988. spanParent = spanParent.parentNode;
  10989. }
  10990. }
  10991. if (opera) {
  10992. setTimeout(function () {
  10993. range.setStart(span, 0).collapse(true);
  10994. mergesibling(range, cmdName,value);
  10995. range.select();
  10996. });
  10997. } else {
  10998. range.setStart(span, 0).collapse(true);
  10999. mergesibling(range,cmdName,value);
  11000. range.select();
  11001. }
  11002. //trace:981
  11003. //domUtils.mergeToParent(span)
  11004. }
  11005. domUtils.remove(text);
  11006. }
  11007. }
  11008. return true;
  11009. },
  11010. queryCommandValue: function (cmdName) {
  11011. var startNode = this.selection.getStart();
  11012. //trace:946
  11013. if (cmdName == 'underline' || cmdName == 'strikethrough') {
  11014. var tmpNode = startNode, value;
  11015. while (tmpNode && !domUtils.isBlockElm(tmpNode) && !domUtils.isBody(tmpNode)) {
  11016. if (tmpNode.nodeType == 1) {
  11017. value = domUtils.getComputedStyle(tmpNode, style);
  11018. if (value != 'none') {
  11019. return value;
  11020. }
  11021. }
  11022. tmpNode = tmpNode.parentNode;
  11023. }
  11024. return 'none';
  11025. }
  11026. if (cmdName == 'fontborder') {
  11027. var tmp = startNode, val;
  11028. while (tmp && dtd.$inline[tmp.tagName]) {
  11029. if (val = domUtils.getComputedStyle(tmp, 'border')) {
  11030. if (/1px/.test(val) && /solid/.test(val)) {
  11031. return val;
  11032. }
  11033. }
  11034. tmp = tmp.parentNode;
  11035. }
  11036. return ''
  11037. }
  11038. if( cmdName == 'FontSize' ) {
  11039. var styleVal = domUtils.getComputedStyle(startNode, style),
  11040. tmp = /^([\d\.]+)(\w+)$/.exec( styleVal );
  11041. if( tmp ) {
  11042. return Math.floor( tmp[1] ) + tmp[2];
  11043. }
  11044. return styleVal;
  11045. }
  11046. return domUtils.getComputedStyle(startNode, style);
  11047. },
  11048. queryCommandState: function (cmdName) {
  11049. if (!needCmd[cmdName])
  11050. return 0;
  11051. var val = this.queryCommandValue(cmdName);
  11052. if (cmdName == 'fontborder') {
  11053. return /1px/.test(val) && /solid/.test(val)
  11054. } else {
  11055. return cmdName == 'underline' ? /underline/.test(val) : /line\-through/.test(val);
  11056. }
  11057. }
  11058. };
  11059. })(p, fonts[p]);
  11060. }
  11061. };
  11062. // plugins/link.js
  11063. /**
  11064. * 超链接
  11065. * @file
  11066. * @since 1.2.6.1
  11067. */
  11068. /**
  11069. * 插入超链接
  11070. * @command link
  11071. * @method execCommand
  11072. * @param { String } cmd 命令字符串
  11073. * @param { Object } options 设置自定义属性,例如:url、title、target
  11074. * @example
  11075. * ```javascript
  11076. * editor.execCommand( 'link', '{
  11077. * url:'ueditor.baidu.com',
  11078. * title:'ueditor',
  11079. * target:'_blank'
  11080. * }' );
  11081. * ```
  11082. */
  11083. /**
  11084. * 返回当前选中的第一个超链接节点
  11085. * @command link
  11086. * @method queryCommandValue
  11087. * @param { String } cmd 命令字符串
  11088. * @return { Element } 超链接节点
  11089. * @example
  11090. * ```javascript
  11091. * editor.queryCommandValue( 'link' );
  11092. * ```
  11093. */
  11094. /**
  11095. * 取消超链接
  11096. * @command unlink
  11097. * @method execCommand
  11098. * @param { String } cmd 命令字符串
  11099. * @example
  11100. * ```javascript
  11101. * editor.execCommand( 'unlink');
  11102. * ```
  11103. */
  11104. UE.plugins['link'] = function(){
  11105. function optimize( range ) {
  11106. var start = range.startContainer,end = range.endContainer;
  11107. if ( start = domUtils.findParentByTagName( start, 'a', true ) ) {
  11108. range.setStartBefore( start );
  11109. }
  11110. if ( end = domUtils.findParentByTagName( end, 'a', true ) ) {
  11111. range.setEndAfter( end );
  11112. }
  11113. }
  11114. UE.commands['unlink'] = {
  11115. execCommand : function() {
  11116. var range = this.selection.getRange(),
  11117. bookmark;
  11118. if(range.collapsed && !domUtils.findParentByTagName( range.startContainer, 'a', true )){
  11119. return;
  11120. }
  11121. bookmark = range.createBookmark();
  11122. optimize( range );
  11123. range.removeInlineStyle( 'a' ).moveToBookmark( bookmark ).select();
  11124. },
  11125. queryCommandState : function(){
  11126. return !this.highlight && this.queryCommandValue('link') ? 0 : -1;
  11127. }
  11128. };
  11129. function doLink(range,opt,me){
  11130. var rngClone = range.cloneRange(),
  11131. link = me.queryCommandValue('link');
  11132. optimize( range = range.adjustmentBoundary() );
  11133. var start = range.startContainer;
  11134. if(start.nodeType == 1 && link){
  11135. start = start.childNodes[range.startOffset];
  11136. if(start && start.nodeType == 1 && start.tagName == 'A' && /^(?:https?|ftp|file)\s*:\s*\/\//.test(start[browser.ie?'innerText':'textContent'])){
  11137. start[browser.ie ? 'innerText' : 'textContent'] = utils.html(opt.textValue||opt.href);
  11138. }
  11139. }
  11140. if( !rngClone.collapsed || link){
  11141. range.removeInlineStyle( 'a' );
  11142. rngClone = range.cloneRange();
  11143. }
  11144. if ( rngClone.collapsed ) {
  11145. var a = range.document.createElement( 'a'),
  11146. text = '';
  11147. if(opt.textValue){
  11148. text = utils.html(opt.textValue);
  11149. delete opt.textValue;
  11150. }else{
  11151. text = utils.html(opt.href);
  11152. }
  11153. domUtils.setAttributes( a, opt );
  11154. start = domUtils.findParentByTagName( rngClone.startContainer, 'a', true );
  11155. if(start && domUtils.isInNodeEndBoundary(rngClone,start)){
  11156. range.setStartAfter(start).collapse(true);
  11157. }
  11158. a[browser.ie ? 'innerText' : 'textContent'] = text;
  11159. range.insertNode(a).selectNode( a );
  11160. } else {
  11161. range.applyInlineStyle( 'a', opt );
  11162. }
  11163. }
  11164. UE.commands['link'] = {
  11165. execCommand : function( cmdName, opt ) {
  11166. var range;
  11167. opt._href && (opt._href = utils.unhtml(opt._href,/[<">]/g));
  11168. opt.href && (opt.href = utils.unhtml(opt.href,/[<">]/g));
  11169. opt.textValue && (opt.textValue = utils.unhtml(opt.textValue,/[<">]/g));
  11170. doLink(range=this.selection.getRange(),opt,this);
  11171. //闭合都不加占位符,如果加了会在a后边多个占位符节点,导致a是图片背景组成的列表,出现空白问题
  11172. range.collapse().select(true);
  11173. },
  11174. queryCommandValue : function() {
  11175. var range = this.selection.getRange(),
  11176. node;
  11177. if ( range.collapsed ) {
  11178. // node = this.selection.getStart();
  11179. //在ie下getstart()取值偏上了
  11180. node = range.startContainer;
  11181. node = node.nodeType == 1 ? node : node.parentNode;
  11182. if ( node && (node = domUtils.findParentByTagName( node, 'a', true )) && ! domUtils.isInNodeEndBoundary(range,node)) {
  11183. return node;
  11184. }
  11185. } else {
  11186. //trace:1111 如果是<p><a>xx</a></p> startContainer是p就会找不到a
  11187. range.shrinkBoundary();
  11188. var start = range.startContainer.nodeType == 3 || !range.startContainer.childNodes[range.startOffset] ? range.startContainer : range.startContainer.childNodes[range.startOffset],
  11189. end = range.endContainer.nodeType == 3 || range.endOffset == 0 ? range.endContainer : range.endContainer.childNodes[range.endOffset-1],
  11190. common = range.getCommonAncestor();
  11191. node = domUtils.findParentByTagName( common, 'a', true );
  11192. if ( !node && common.nodeType == 1){
  11193. var as = common.getElementsByTagName( 'a' ),
  11194. ps,pe;
  11195. for ( var i = 0,ci; ci = as[i++]; ) {
  11196. ps = domUtils.getPosition( ci, start ),pe = domUtils.getPosition( ci,end);
  11197. if ( (ps & domUtils.POSITION_FOLLOWING || ps & domUtils.POSITION_CONTAINS)
  11198. &&
  11199. (pe & domUtils.POSITION_PRECEDING || pe & domUtils.POSITION_CONTAINS)
  11200. ) {
  11201. node = ci;
  11202. break;
  11203. }
  11204. }
  11205. }
  11206. return node;
  11207. }
  11208. },
  11209. queryCommandState : function() {
  11210. //判断如果是视频的话连接不可用
  11211. //fix 853
  11212. var img = this.selection.getRange().getClosedNode(),
  11213. flag = img && (img.className == "edui-faked-video" || img.className.indexOf("edui-upload-video")!=-1);
  11214. return flag ? -1 : 0;
  11215. }
  11216. };
  11217. };
  11218. // plugins/iframe.js
  11219. ///import core
  11220. ///import plugins\inserthtml.js
  11221. ///commands 插入框架
  11222. ///commandsName InsertFrame
  11223. ///commandsTitle 插入Iframe
  11224. ///commandsDialog dialogs\insertframe
  11225. UE.plugins['insertframe'] = function() {
  11226. var me =this;
  11227. function deleteIframe(){
  11228. me._iframe && delete me._iframe;
  11229. }
  11230. me.addListener("selectionchange",function(){
  11231. deleteIframe();
  11232. });
  11233. };
  11234. // plugins/scrawl.js
  11235. ///import core
  11236. ///commands 涂鸦
  11237. ///commandsName Scrawl
  11238. ///commandsTitle 涂鸦
  11239. ///commandsDialog dialogs\scrawl
  11240. UE.commands['scrawl'] = {
  11241. queryCommandState : function(){
  11242. return ( browser.ie && browser.version <= 8 ) ? -1 :0;
  11243. }
  11244. };
  11245. // plugins/removeformat.js
  11246. /**
  11247. * 清除格式
  11248. * @file
  11249. * @since 1.2.6.1
  11250. */
  11251. /**
  11252. * 清除文字样式
  11253. * @command removeformat
  11254. * @method execCommand
  11255. * @param { String } cmd 命令字符串
  11256. * @param {String} tags 以逗号隔开的标签。如:strong
  11257. * @param {String} style 样式如:color
  11258. * @param {String} attrs 属性如:width
  11259. * @example
  11260. * ```javascript
  11261. * editor.execCommand( 'removeformat', 'strong','color','width' );
  11262. * ```
  11263. */
  11264. UE.plugins['removeformat'] = function(){
  11265. var me = this;
  11266. me.setOpt({
  11267. 'removeFormatTags': 'b,big,code,del,dfn,em,font,i,ins,kbd,q,samp,small,span,strike,strong,sub,sup,tt,u,var',
  11268. 'removeFormatAttributes':'class,style,lang,width,height,align,hspace,valign'
  11269. });
  11270. me.commands['removeformat'] = {
  11271. execCommand : function( cmdName, tags, style, attrs,notIncludeA ) {
  11272. var tagReg = new RegExp( '^(?:' + (tags || this.options.removeFormatTags).replace( /,/g, '|' ) + ')$', 'i' ) ,
  11273. removeFormatAttributes = style ? [] : (attrs || this.options.removeFormatAttributes).split( ',' ),
  11274. range = new dom.Range( this.document ),
  11275. bookmark,node,parent,
  11276. filter = function( node ) {
  11277. return node.nodeType == 1;
  11278. };
  11279. function isRedundantSpan (node) {
  11280. if (node.nodeType == 3 || node.tagName.toLowerCase() != 'span'){
  11281. return 0;
  11282. }
  11283. if (browser.ie) {
  11284. //ie 下判断实效,所以只能简单用style来判断
  11285. //return node.style.cssText == '' ? 1 : 0;
  11286. var attrs = node.attributes;
  11287. if ( attrs.length ) {
  11288. for ( var i = 0,l = attrs.length; i<l; i++ ) {
  11289. if ( attrs[i].specified ) {
  11290. return 0;
  11291. }
  11292. }
  11293. return 1;
  11294. }
  11295. }
  11296. return !node.attributes.length;
  11297. }
  11298. function doRemove( range ) {
  11299. var bookmark1 = range.createBookmark();
  11300. if ( range.collapsed ) {
  11301. range.enlarge( true );
  11302. }
  11303. //不能把a标签切了
  11304. if(!notIncludeA){
  11305. var aNode = domUtils.findParentByTagName(range.startContainer,'a',true);
  11306. if(aNode){
  11307. range.setStartBefore(aNode);
  11308. }
  11309. aNode = domUtils.findParentByTagName(range.endContainer,'a',true);
  11310. if(aNode){
  11311. range.setEndAfter(aNode);
  11312. }
  11313. }
  11314. bookmark = range.createBookmark();
  11315. node = bookmark.start;
  11316. //切开始
  11317. while ( (parent = node.parentNode) && !domUtils.isBlockElm( parent ) ) {
  11318. domUtils.breakParent( node, parent );
  11319. domUtils.clearEmptySibling( node );
  11320. }
  11321. if ( bookmark.end ) {
  11322. //切结束
  11323. node = bookmark.end;
  11324. while ( (parent = node.parentNode) && !domUtils.isBlockElm( parent ) ) {
  11325. domUtils.breakParent( node, parent );
  11326. domUtils.clearEmptySibling( node );
  11327. }
  11328. //开始去除样式
  11329. var current = domUtils.getNextDomNode( bookmark.start, false, filter ),
  11330. next;
  11331. while ( current ) {
  11332. if ( current == bookmark.end ) {
  11333. break;
  11334. }
  11335. next = domUtils.getNextDomNode( current, true, filter );
  11336. if ( !dtd.$empty[current.tagName.toLowerCase()] && !domUtils.isBookmarkNode( current ) ) {
  11337. if ( tagReg.test( current.tagName ) ) {
  11338. if ( style ) {
  11339. domUtils.removeStyle( current, style );
  11340. if ( isRedundantSpan( current ) && style != 'text-decoration'){
  11341. domUtils.remove( current, true );
  11342. }
  11343. } else {
  11344. domUtils.remove( current, true );
  11345. }
  11346. } else {
  11347. //trace:939 不能把list上的样式去掉
  11348. if(!dtd.$tableContent[current.tagName] && !dtd.$list[current.tagName]){
  11349. domUtils.removeAttributes( current, removeFormatAttributes );
  11350. if ( isRedundantSpan( current ) ){
  11351. domUtils.remove( current, true );
  11352. }
  11353. }
  11354. }
  11355. }
  11356. current = next;
  11357. }
  11358. }
  11359. //trace:1035
  11360. //trace:1096 不能把td上的样式去掉,比如边框
  11361. var pN = bookmark.start.parentNode;
  11362. if(domUtils.isBlockElm(pN) && !dtd.$tableContent[pN.tagName] && !dtd.$list[pN.tagName]){
  11363. domUtils.removeAttributes( pN,removeFormatAttributes );
  11364. }
  11365. pN = bookmark.end.parentNode;
  11366. if(bookmark.end && domUtils.isBlockElm(pN) && !dtd.$tableContent[pN.tagName]&& !dtd.$list[pN.tagName]){
  11367. domUtils.removeAttributes( pN,removeFormatAttributes );
  11368. }
  11369. range.moveToBookmark( bookmark ).moveToBookmark(bookmark1);
  11370. //清除冗余的代码 <b><bookmark></b>
  11371. var node = range.startContainer,
  11372. tmp,
  11373. collapsed = range.collapsed;
  11374. while(node.nodeType == 1 && domUtils.isEmptyNode(node) && dtd.$removeEmpty[node.tagName]){
  11375. tmp = node.parentNode;
  11376. range.setStartBefore(node);
  11377. //trace:937
  11378. //更新结束边界
  11379. if(range.startContainer === range.endContainer){
  11380. range.endOffset--;
  11381. }
  11382. domUtils.remove(node);
  11383. node = tmp;
  11384. }
  11385. if(!collapsed){
  11386. node = range.endContainer;
  11387. while(node.nodeType == 1 && domUtils.isEmptyNode(node) && dtd.$removeEmpty[node.tagName]){
  11388. tmp = node.parentNode;
  11389. range.setEndBefore(node);
  11390. domUtils.remove(node);
  11391. node = tmp;
  11392. }
  11393. }
  11394. }
  11395. range = this.selection.getRange();
  11396. doRemove( range );
  11397. range.select();
  11398. }
  11399. };
  11400. };
  11401. // plugins/blockquote.js
  11402. /**
  11403. * 添加引用
  11404. * @file
  11405. * @since 1.2.6.1
  11406. */
  11407. /**
  11408. * 添加引用
  11409. * @command blockquote
  11410. * @method execCommand
  11411. * @param { String } cmd 命令字符串
  11412. * @example
  11413. * ```javascript
  11414. * editor.execCommand( 'blockquote' );
  11415. * ```
  11416. */
  11417. /**
  11418. * 添加引用
  11419. * @command blockquote
  11420. * @method execCommand
  11421. * @param { String } cmd 命令字符串
  11422. * @param { Object } attrs 节点属性
  11423. * @example
  11424. * ```javascript
  11425. * editor.execCommand( 'blockquote',{
  11426. * style: "color: red;"
  11427. * } );
  11428. * ```
  11429. */
  11430. UE.plugins['blockquote'] = function(){
  11431. var me = this;
  11432. function getObj(editor){
  11433. return domUtils.filterNodeList(editor.selection.getStartElementPath(),'blockquote');
  11434. }
  11435. me.commands['blockquote'] = {
  11436. execCommand : function( cmdName, attrs ) {
  11437. var range = this.selection.getRange(),
  11438. obj = getObj(this),
  11439. blockquote = dtd.blockquote,
  11440. bookmark = range.createBookmark();
  11441. if ( obj ) {
  11442. var start = range.startContainer,
  11443. startBlock = domUtils.isBlockElm(start) ? start : domUtils.findParent(start,function(node){return domUtils.isBlockElm(node)}),
  11444. end = range.endContainer,
  11445. endBlock = domUtils.isBlockElm(end) ? end : domUtils.findParent(end,function(node){return domUtils.isBlockElm(node)});
  11446. //处理一下li
  11447. startBlock = domUtils.findParentByTagName(startBlock,'li',true) || startBlock;
  11448. endBlock = domUtils.findParentByTagName(endBlock,'li',true) || endBlock;
  11449. if(startBlock.tagName == 'LI' || startBlock.tagName == 'TD' || startBlock === obj || domUtils.isBody(startBlock)){
  11450. domUtils.remove(obj,true);
  11451. }else{
  11452. domUtils.breakParent(startBlock,obj);
  11453. }
  11454. if(startBlock !== endBlock){
  11455. obj = domUtils.findParentByTagName(endBlock,'blockquote');
  11456. if(obj){
  11457. if(endBlock.tagName == 'LI' || endBlock.tagName == 'TD'|| domUtils.isBody(endBlock)){
  11458. obj.parentNode && domUtils.remove(obj,true);
  11459. }else{
  11460. domUtils.breakParent(endBlock,obj);
  11461. }
  11462. }
  11463. }
  11464. var blockquotes = domUtils.getElementsByTagName(this.document,'blockquote');
  11465. for(var i=0,bi;bi=blockquotes[i++];){
  11466. if(!bi.childNodes.length){
  11467. domUtils.remove(bi);
  11468. }else if(domUtils.getPosition(bi,startBlock)&domUtils.POSITION_FOLLOWING && domUtils.getPosition(bi,endBlock)&domUtils.POSITION_PRECEDING){
  11469. domUtils.remove(bi,true);
  11470. }
  11471. }
  11472. } else {
  11473. var tmpRange = range.cloneRange(),
  11474. node = tmpRange.startContainer.nodeType == 1 ? tmpRange.startContainer : tmpRange.startContainer.parentNode,
  11475. preNode = node,
  11476. doEnd = 1;
  11477. //调整开始
  11478. while ( 1 ) {
  11479. if ( domUtils.isBody(node) ) {
  11480. if ( preNode !== node ) {
  11481. if ( range.collapsed ) {
  11482. tmpRange.selectNode( preNode );
  11483. doEnd = 0;
  11484. } else {
  11485. tmpRange.setStartBefore( preNode );
  11486. }
  11487. }else{
  11488. tmpRange.setStart(node,0);
  11489. }
  11490. break;
  11491. }
  11492. if ( !blockquote[node.tagName] ) {
  11493. if ( range.collapsed ) {
  11494. tmpRange.selectNode( preNode );
  11495. } else{
  11496. tmpRange.setStartBefore( preNode);
  11497. }
  11498. break;
  11499. }
  11500. preNode = node;
  11501. node = node.parentNode;
  11502. }
  11503. //调整结束
  11504. if ( doEnd ) {
  11505. preNode = node = node = tmpRange.endContainer.nodeType == 1 ? tmpRange.endContainer : tmpRange.endContainer.parentNode;
  11506. while ( 1 ) {
  11507. if ( domUtils.isBody( node ) ) {
  11508. if ( preNode !== node ) {
  11509. tmpRange.setEndAfter( preNode );
  11510. } else {
  11511. tmpRange.setEnd( node, node.childNodes.length );
  11512. }
  11513. break;
  11514. }
  11515. if ( !blockquote[node.tagName] ) {
  11516. tmpRange.setEndAfter( preNode );
  11517. break;
  11518. }
  11519. preNode = node;
  11520. node = node.parentNode;
  11521. }
  11522. }
  11523. node = range.document.createElement( 'blockquote' );
  11524. domUtils.setAttributes( node, attrs );
  11525. node.appendChild( tmpRange.extractContents() );
  11526. tmpRange.insertNode( node );
  11527. //去除重复的
  11528. var childs = domUtils.getElementsByTagName(node,'blockquote');
  11529. for(var i=0,ci;ci=childs[i++];){
  11530. if(ci.parentNode){
  11531. domUtils.remove(ci,true);
  11532. }
  11533. }
  11534. }
  11535. range.moveToBookmark( bookmark ).select();
  11536. },
  11537. queryCommandState : function() {
  11538. return getObj(this) ? 1 : 0;
  11539. }
  11540. };
  11541. };
  11542. // plugins/convertcase.js
  11543. /**
  11544. * 大小写转换
  11545. * @file
  11546. * @since 1.2.6.1
  11547. */
  11548. /**
  11549. * 把选区内文本变大写,与“tolowercase”命令互斥
  11550. * @command touppercase
  11551. * @method execCommand
  11552. * @param { String } cmd 命令字符串
  11553. * @example
  11554. * ```javascript
  11555. * editor.execCommand( 'touppercase' );
  11556. * ```
  11557. */
  11558. /**
  11559. * 把选区内文本变小写,与“touppercase”命令互斥
  11560. * @command tolowercase
  11561. * @method execCommand
  11562. * @param { String } cmd 命令字符串
  11563. * @example
  11564. * ```javascript
  11565. * editor.execCommand( 'tolowercase' );
  11566. * ```
  11567. */
  11568. UE.commands['touppercase'] =
  11569. UE.commands['tolowercase'] = {
  11570. execCommand:function (cmd) {
  11571. var me = this;
  11572. var rng = me.selection.getRange();
  11573. if(rng.collapsed){
  11574. return rng;
  11575. }
  11576. var bk = rng.createBookmark(),
  11577. bkEnd = bk.end,
  11578. filterFn = function( node ) {
  11579. return !domUtils.isBr(node) && !domUtils.isWhitespace( node );
  11580. },
  11581. curNode = domUtils.getNextDomNode( bk.start, false, filterFn );
  11582. while ( curNode && (domUtils.getPosition( curNode, bkEnd ) & domUtils.POSITION_PRECEDING) ) {
  11583. if ( curNode.nodeType == 3 ) {
  11584. curNode.nodeValue = curNode.nodeValue[cmd == 'touppercase' ? 'toUpperCase' : 'toLowerCase']();
  11585. }
  11586. curNode = domUtils.getNextDomNode( curNode, true, filterFn );
  11587. if(curNode === bkEnd){
  11588. break;
  11589. }
  11590. }
  11591. rng.moveToBookmark(bk).select();
  11592. }
  11593. };
  11594. // plugins/indent.js
  11595. /**
  11596. * 首行缩进
  11597. * @file
  11598. * @since 1.2.6.1
  11599. */
  11600. /**
  11601. * 缩进
  11602. * @command indent
  11603. * @method execCommand
  11604. * @param { String } cmd 命令字符串
  11605. * @example
  11606. * ```javascript
  11607. * editor.execCommand( 'indent' );
  11608. * ```
  11609. */
  11610. UE.commands['indent'] = {
  11611. execCommand : function() {
  11612. var me = this,value = me.queryCommandState("indent") ? "0em" : (me.options.indentValue || '2em');
  11613. me.execCommand('Paragraph','p',{style:'text-indent:'+ value});
  11614. },
  11615. queryCommandState : function() {
  11616. var pN = domUtils.filterNodeList(this.selection.getStartElementPath(),'p h1 h2 h3 h4 h5 h6');
  11617. return pN && pN.style.textIndent && parseInt(pN.style.textIndent) ? 1 : 0;
  11618. }
  11619. };
  11620. // plugins/print.js
  11621. /**
  11622. * 打印
  11623. * @file
  11624. * @since 1.2.6.1
  11625. */
  11626. /**
  11627. * 打印
  11628. * @command print
  11629. * @method execCommand
  11630. * @param { String } cmd 命令字符串
  11631. * @example
  11632. * ```javascript
  11633. * editor.execCommand( 'print' );
  11634. * ```
  11635. */
  11636. UE.commands['print'] = {
  11637. execCommand : function(){
  11638. this.window.print();
  11639. },
  11640. notNeedUndo : 1
  11641. };
  11642. // plugins/preview.js
  11643. /**
  11644. * 预览
  11645. * @file
  11646. * @since 1.2.6.1
  11647. */
  11648. /**
  11649. * 预览
  11650. * @command preview
  11651. * @method execCommand
  11652. * @param { String } cmd 命令字符串
  11653. * @example
  11654. * ```javascript
  11655. * editor.execCommand( 'preview' );
  11656. * ```
  11657. */
  11658. UE.commands['preview'] = {
  11659. execCommand : function(){
  11660. var w = window.open('', '_blank', ''),
  11661. d = w.document;
  11662. d.open();
  11663. d.write('<!DOCTYPE html><html><head><meta charset="utf-8"/><script src="'+this.options.UEDITOR_HOME_URL+'ueditor.parse.js"></script><script>' +
  11664. "setTimeout(function(){uParse('div',{rootPath: '"+ this.options.UEDITOR_HOME_URL +"'})},300)" +
  11665. '</script></head><body><div>'+this.getContent(null,null,true)+'</div></body></html>');
  11666. d.close();
  11667. },
  11668. notNeedUndo : 1
  11669. };
  11670. // plugins/selectall.js
  11671. /**
  11672. * 全选
  11673. * @file
  11674. * @since 1.2.6.1
  11675. */
  11676. /**
  11677. * 选中所有内容
  11678. * @command selectall
  11679. * @method execCommand
  11680. * @param { String } cmd 命令字符串
  11681. * @example
  11682. * ```javascript
  11683. * editor.execCommand( 'selectall' );
  11684. * ```
  11685. */
  11686. UE.plugins['selectall'] = function(){
  11687. var me = this;
  11688. me.commands['selectall'] = {
  11689. execCommand : function(){
  11690. //去掉了原生的selectAll,因为会出现报错和当内容为空时,不能出现闭合状态的光标
  11691. var me = this,body = me.body,
  11692. range = me.selection.getRange();
  11693. range.selectNodeContents(body);
  11694. if(domUtils.isEmptyBlock(body)){
  11695. //opera不能自动合并到元素的里边,要手动处理一下
  11696. if(browser.opera && body.firstChild && body.firstChild.nodeType == 1){
  11697. range.setStartAtFirst(body.firstChild);
  11698. }
  11699. range.collapse(true);
  11700. }
  11701. range.select(true);
  11702. },
  11703. notNeedUndo : 1
  11704. };
  11705. //快捷键
  11706. me.addshortcutkey({
  11707. "selectAll" : "ctrl+65"
  11708. });
  11709. };
  11710. // plugins/paragraph.js
  11711. /**
  11712. * 段落样式
  11713. * @file
  11714. * @since 1.2.6.1
  11715. */
  11716. /**
  11717. * 段落格式
  11718. * @command paragraph
  11719. * @method execCommand
  11720. * @param { String } cmd 命令字符串
  11721. * @param {String} style 标签值为:'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
  11722. * @param {Object} attrs 标签的属性
  11723. * @example
  11724. * ```javascript
  11725. * editor.execCommand( 'Paragraph','h1','{
  11726. * class:'test'
  11727. * }' );
  11728. * ```
  11729. */
  11730. /**
  11731. * 返回选区内节点标签名
  11732. * @command paragraph
  11733. * @method queryCommandValue
  11734. * @param { String } cmd 命令字符串
  11735. * @return { String } 节点标签名
  11736. * @example
  11737. * ```javascript
  11738. * editor.queryCommandValue( 'Paragraph' );
  11739. * ```
  11740. */
  11741. UE.plugins['paragraph'] = function() {
  11742. var me = this,
  11743. block = domUtils.isBlockElm,
  11744. notExchange = ['TD','LI','PRE'],
  11745. doParagraph = function(range,style,attrs,sourceCmdName){
  11746. var bookmark = range.createBookmark(),
  11747. filterFn = function( node ) {
  11748. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' && !domUtils.isBookmarkNode(node) : !domUtils.isWhitespace( node );
  11749. },
  11750. para;
  11751. range.enlarge( true );
  11752. var bookmark2 = range.createBookmark(),
  11753. current = domUtils.getNextDomNode( bookmark2.start, false, filterFn ),
  11754. tmpRange = range.cloneRange(),
  11755. tmpNode;
  11756. while ( current && !(domUtils.getPosition( current, bookmark2.end ) & domUtils.POSITION_FOLLOWING) ) {
  11757. if ( current.nodeType == 3 || !block( current ) ) {
  11758. tmpRange.setStartBefore( current );
  11759. while ( current && current !== bookmark2.end && !block( current ) ) {
  11760. tmpNode = current;
  11761. current = domUtils.getNextDomNode( current, false, null, function( node ) {
  11762. return !block( node );
  11763. } );
  11764. }
  11765. tmpRange.setEndAfter( tmpNode );
  11766. para = range.document.createElement( style );
  11767. if(attrs){
  11768. domUtils.setAttributes(para,attrs);
  11769. if(sourceCmdName && sourceCmdName == 'customstyle' && attrs.style){
  11770. para.style.cssText = attrs.style;
  11771. }
  11772. }
  11773. para.appendChild( tmpRange.extractContents() );
  11774. //需要内容占位
  11775. if(domUtils.isEmptyNode(para)){
  11776. domUtils.fillChar(range.document,para);
  11777. }
  11778. tmpRange.insertNode( para );
  11779. var parent = para.parentNode;
  11780. //如果para上一级是一个block元素且不是body,td就删除它
  11781. if ( block( parent ) && !domUtils.isBody( para.parentNode ) && utils.indexOf(notExchange,parent.tagName)==-1) {
  11782. //存储dir,style
  11783. if(!(sourceCmdName && sourceCmdName == 'customstyle')){
  11784. parent.getAttribute('dir') && para.setAttribute('dir',parent.getAttribute('dir'));
  11785. //trace:1070
  11786. parent.style.cssText && (para.style.cssText = parent.style.cssText + ';' + para.style.cssText);
  11787. //trace:1030
  11788. parent.style.textAlign && !para.style.textAlign && (para.style.textAlign = parent.style.textAlign);
  11789. parent.style.textIndent && !para.style.textIndent && (para.style.textIndent = parent.style.textIndent);
  11790. parent.style.padding && !para.style.padding && (para.style.padding = parent.style.padding);
  11791. }
  11792. //trace:1706 选择的就是h1-6要删除
  11793. if(attrs && /h\d/i.test(parent.tagName) && !/h\d/i.test(para.tagName) ){
  11794. domUtils.setAttributes(parent,attrs);
  11795. if(sourceCmdName && sourceCmdName == 'customstyle' && attrs.style){
  11796. parent.style.cssText = attrs.style;
  11797. }
  11798. domUtils.remove(para,true);
  11799. para = parent;
  11800. }else{
  11801. domUtils.remove( para.parentNode, true );
  11802. }
  11803. }
  11804. if( utils.indexOf(notExchange,parent.tagName)!=-1){
  11805. current = parent;
  11806. }else{
  11807. current = para;
  11808. }
  11809. current = domUtils.getNextDomNode( current, false, filterFn );
  11810. } else {
  11811. current = domUtils.getNextDomNode( current, true, filterFn );
  11812. }
  11813. }
  11814. return range.moveToBookmark( bookmark2 ).moveToBookmark( bookmark );
  11815. };
  11816. me.setOpt('paragraph',{'p':'', 'h1':'', 'h2':'', 'h3':'', 'h4':'', 'h5':'', 'h6':''});
  11817. me.commands['paragraph'] = {
  11818. execCommand : function( cmdName, style,attrs,sourceCmdName ) {
  11819. var range = this.selection.getRange();
  11820. //闭合时单独处理
  11821. if(range.collapsed){
  11822. var txt = this.document.createTextNode('p');
  11823. range.insertNode(txt);
  11824. //去掉冗余的fillchar
  11825. if(browser.ie){
  11826. var node = txt.previousSibling;
  11827. if(node && domUtils.isWhitespace(node)){
  11828. domUtils.remove(node);
  11829. }
  11830. node = txt.nextSibling;
  11831. if(node && domUtils.isWhitespace(node)){
  11832. domUtils.remove(node);
  11833. }
  11834. }
  11835. }
  11836. range = doParagraph(range,style,attrs,sourceCmdName);
  11837. if(txt){
  11838. range.setStartBefore(txt).collapse(true);
  11839. pN = txt.parentNode;
  11840. domUtils.remove(txt);
  11841. if(domUtils.isBlockElm(pN)&&domUtils.isEmptyNode(pN)){
  11842. domUtils.fillNode(this.document,pN);
  11843. }
  11844. }
  11845. if(browser.gecko && range.collapsed && range.startContainer.nodeType == 1){
  11846. var child = range.startContainer.childNodes[range.startOffset];
  11847. if(child && child.nodeType == 1 && child.tagName.toLowerCase() == style){
  11848. range.setStart(child,0).collapse(true);
  11849. }
  11850. }
  11851. //trace:1097 原来有true,原因忘了,但去了就不能清除多余的占位符了
  11852. range.select();
  11853. return true;
  11854. },
  11855. queryCommandValue : function() {
  11856. var node = domUtils.filterNodeList(this.selection.getStartElementPath(),'p h1 h2 h3 h4 h5 h6');
  11857. return node ? node.tagName.toLowerCase() : '';
  11858. }
  11859. };
  11860. };
  11861. // plugins/directionality.js
  11862. /**
  11863. * 设置文字输入的方向的插件
  11864. * @file
  11865. * @since 1.2.6.1
  11866. */
  11867. (function() {
  11868. var block = domUtils.isBlockElm ,
  11869. getObj = function(editor){
  11870. // var startNode = editor.selection.getStart(),
  11871. // parents;
  11872. // if ( startNode ) {
  11873. // //查找所有的是block的父亲节点
  11874. // parents = domUtils.findParents( startNode, true, block, true );
  11875. // for ( var i = 0,ci; ci = parents[i++]; ) {
  11876. // if ( ci.getAttribute( 'dir' ) ) {
  11877. // return ci;
  11878. // }
  11879. // }
  11880. // }
  11881. return domUtils.filterNodeList(editor.selection.getStartElementPath(),function(n){return n && n.nodeType == 1 && n.getAttribute('dir')});
  11882. },
  11883. doDirectionality = function(range,editor,forward){
  11884. var bookmark,
  11885. filterFn = function( node ) {
  11886. return node.nodeType == 1 ? !domUtils.isBookmarkNode(node) : !domUtils.isWhitespace(node);
  11887. },
  11888. obj = getObj( editor );
  11889. if ( obj && range.collapsed ) {
  11890. obj.setAttribute( 'dir', forward );
  11891. return range;
  11892. }
  11893. bookmark = range.createBookmark();
  11894. range.enlarge( true );
  11895. var bookmark2 = range.createBookmark(),
  11896. current = domUtils.getNextDomNode( bookmark2.start, false, filterFn ),
  11897. tmpRange = range.cloneRange(),
  11898. tmpNode;
  11899. while ( current && !(domUtils.getPosition( current, bookmark2.end ) & domUtils.POSITION_FOLLOWING) ) {
  11900. if ( current.nodeType == 3 || !block( current ) ) {
  11901. tmpRange.setStartBefore( current );
  11902. while ( current && current !== bookmark2.end && !block( current ) ) {
  11903. tmpNode = current;
  11904. current = domUtils.getNextDomNode( current, false, null, function( node ) {
  11905. return !block( node );
  11906. } );
  11907. }
  11908. tmpRange.setEndAfter( tmpNode );
  11909. var common = tmpRange.getCommonAncestor();
  11910. if ( !domUtils.isBody( common ) && block( common ) ) {
  11911. //遍历到了block节点
  11912. common.setAttribute( 'dir', forward );
  11913. current = common;
  11914. } else {
  11915. //没有遍历到,添加一个block节点
  11916. var p = range.document.createElement( 'p' );
  11917. p.setAttribute( 'dir', forward );
  11918. var frag = tmpRange.extractContents();
  11919. p.appendChild( frag );
  11920. tmpRange.insertNode( p );
  11921. current = p;
  11922. }
  11923. current = domUtils.getNextDomNode( current, false, filterFn );
  11924. } else {
  11925. current = domUtils.getNextDomNode( current, true, filterFn );
  11926. }
  11927. }
  11928. return range.moveToBookmark( bookmark2 ).moveToBookmark( bookmark );
  11929. };
  11930. /**
  11931. * 文字输入方向
  11932. * @command directionality
  11933. * @method execCommand
  11934. * @param { String } cmdName 命令字符串
  11935. * @param { String } forward 传入'ltr'表示从左向右输入,传入'rtl'表示从右向左输入
  11936. * @example
  11937. * ```javascript
  11938. * editor.execCommand( 'directionality', 'ltr');
  11939. * ```
  11940. */
  11941. /**
  11942. * 查询当前选区的文字输入方向
  11943. * @command directionality
  11944. * @method queryCommandValue
  11945. * @param { String } cmdName 命令字符串
  11946. * @return { String } 返回'ltr'表示从左向右输入,返回'rtl'表示从右向左输入
  11947. * @example
  11948. * ```javascript
  11949. * editor.queryCommandValue( 'directionality');
  11950. * ```
  11951. */
  11952. UE.commands['directionality'] = {
  11953. execCommand : function( cmdName,forward ) {
  11954. var range = this.selection.getRange();
  11955. //闭合时单独处理
  11956. if(range.collapsed){
  11957. var txt = this.document.createTextNode('d');
  11958. range.insertNode(txt);
  11959. }
  11960. doDirectionality(range,this,forward);
  11961. if(txt){
  11962. range.setStartBefore(txt).collapse(true);
  11963. domUtils.remove(txt);
  11964. }
  11965. range.select();
  11966. return true;
  11967. },
  11968. queryCommandValue : function() {
  11969. var node = getObj(this);
  11970. return node ? node.getAttribute('dir') : 'ltr';
  11971. }
  11972. };
  11973. })();
  11974. // plugins/horizontal.js
  11975. /**
  11976. * 插入分割线插件
  11977. * @file
  11978. * @since 1.2.6.1
  11979. */
  11980. /**
  11981. * 插入分割线
  11982. * @command horizontal
  11983. * @method execCommand
  11984. * @param { String } cmdName 命令字符串
  11985. * @example
  11986. * ```javascript
  11987. * editor.execCommand( 'horizontal' );
  11988. * ```
  11989. */
  11990. UE.plugins['horizontal'] = function(){
  11991. var me = this;
  11992. me.commands['horizontal'] = {
  11993. execCommand : function( cmdName ) {
  11994. var me = this;
  11995. if(me.queryCommandState(cmdName)!==-1){
  11996. me.execCommand('insertHtml','<hr>');
  11997. var range = me.selection.getRange(),
  11998. start = range.startContainer;
  11999. if(start.nodeType == 1 && !start.childNodes[range.startOffset] ){
  12000. var tmp;
  12001. if(tmp = start.childNodes[range.startOffset - 1]){
  12002. if(tmp.nodeType == 1 && tmp.tagName == 'HR'){
  12003. if(me.options.enterTag == 'p'){
  12004. tmp = me.document.createElement('p');
  12005. range.insertNode(tmp);
  12006. range.setStart(tmp,0).setCursor();
  12007. }else{
  12008. tmp = me.document.createElement('br');
  12009. range.insertNode(tmp);
  12010. range.setStartBefore(tmp).setCursor();
  12011. }
  12012. }
  12013. }
  12014. }
  12015. return true;
  12016. }
  12017. },
  12018. //边界在table里不能加分隔线
  12019. queryCommandState : function() {
  12020. return domUtils.filterNodeList(this.selection.getStartElementPath(),'table') ? -1 : 0;
  12021. }
  12022. };
  12023. // me.addListener('delkeyup',function(){
  12024. // var rng = this.selection.getRange();
  12025. // if(browser.ie && browser.version > 8){
  12026. // rng.txtToElmBoundary(true);
  12027. // if(domUtils.isStartInblock(rng)){
  12028. // var tmpNode = rng.startContainer;
  12029. // var pre = tmpNode.previousSibling;
  12030. // if(pre && domUtils.isTagNode(pre,'hr')){
  12031. // domUtils.remove(pre);
  12032. // rng.select();
  12033. // return;
  12034. // }
  12035. // }
  12036. // }
  12037. // if(domUtils.isBody(rng.startContainer)){
  12038. // var hr = rng.startContainer.childNodes[rng.startOffset -1];
  12039. // if(hr && hr.nodeName == 'HR'){
  12040. // var next = hr.nextSibling;
  12041. // if(next){
  12042. // rng.setStart(next,0)
  12043. // }else if(hr.previousSibling){
  12044. // rng.setStartAtLast(hr.previousSibling)
  12045. // }else{
  12046. // var p = this.document.createElement('p');
  12047. // hr.parentNode.insertBefore(p,hr);
  12048. // domUtils.fillNode(this.document,p);
  12049. // rng.setStart(p,0);
  12050. // }
  12051. // domUtils.remove(hr);
  12052. // rng.setCursor(false,true);
  12053. // }
  12054. // }
  12055. // })
  12056. me.addListener('delkeydown',function(name,evt){
  12057. var rng = this.selection.getRange();
  12058. rng.txtToElmBoundary(true);
  12059. if(domUtils.isStartInblock(rng)){
  12060. var tmpNode = rng.startContainer;
  12061. var pre = tmpNode.previousSibling;
  12062. if(pre && domUtils.isTagNode(pre,'hr')){
  12063. domUtils.remove(pre);
  12064. rng.select();
  12065. domUtils.preventDefault(evt);
  12066. return true;
  12067. }
  12068. }
  12069. })
  12070. };
  12071. // plugins/time.js
  12072. /**
  12073. * 插入时间和日期
  12074. * @file
  12075. * @since 1.2.6.1
  12076. */
  12077. /**
  12078. * 插入时间,默认格式:12:59:59
  12079. * @command time
  12080. * @method execCommand
  12081. * @param { String } cmd 命令字符串
  12082. * @example
  12083. * ```javascript
  12084. * editor.execCommand( 'time');
  12085. * ```
  12086. */
  12087. /**
  12088. * 插入日期,默认格式:2013-08-30
  12089. * @command date
  12090. * @method execCommand
  12091. * @param { String } cmd 命令字符串
  12092. * @example
  12093. * ```javascript
  12094. * editor.execCommand( 'date');
  12095. * ```
  12096. */
  12097. UE.commands['time'] = UE.commands["date"] = {
  12098. execCommand : function(cmd, format){
  12099. var date = new Date;
  12100. function formatTime(date, format) {
  12101. var hh = ('0' + date.getHours()).slice(-2),
  12102. ii = ('0' + date.getMinutes()).slice(-2),
  12103. ss = ('0' + date.getSeconds()).slice(-2);
  12104. format = format || 'hh:ii:ss';
  12105. return format.replace(/hh/ig, hh).replace(/ii/ig, ii).replace(/ss/ig, ss);
  12106. }
  12107. function formatDate(date, format) {
  12108. var yyyy = ('000' + date.getFullYear()).slice(-4),
  12109. yy = yyyy.slice(-2),
  12110. mm = ('0' + (date.getMonth()+1)).slice(-2),
  12111. dd = ('0' + date.getDate()).slice(-2);
  12112. format = format || 'yyyy-mm-dd';
  12113. return format.replace(/yyyy/ig, yyyy).replace(/yy/ig, yy).replace(/mm/ig, mm).replace(/dd/ig, dd);
  12114. }
  12115. this.execCommand('insertHtml',cmd == "time" ? formatTime(date, format):formatDate(date, format) );
  12116. }
  12117. };
  12118. // plugins/rowspacing.js
  12119. /**
  12120. * 段前段后间距插件
  12121. * @file
  12122. * @since 1.2.6.1
  12123. */
  12124. /**
  12125. * 设置段间距
  12126. * @command rowspacing
  12127. * @method execCommand
  12128. * @param { String } cmd 命令字符串
  12129. * @param { String } value 段间距的值,以px为单位
  12130. * @param { String } dir 间距位置,top或bottom,分别表示段前和段后
  12131. * @example
  12132. * ```javascript
  12133. * editor.execCommand( 'rowspacing', '10', 'top' );
  12134. * ```
  12135. */
  12136. UE.plugins['rowspacing'] = function(){
  12137. var me = this;
  12138. me.setOpt({
  12139. 'rowspacingtop':['5', '10', '15', '20', '25'],
  12140. 'rowspacingbottom':['5', '10', '15', '20', '25']
  12141. });
  12142. me.commands['rowspacing'] = {
  12143. execCommand : function( cmdName,value,dir ) {
  12144. this.execCommand('paragraph','p',{style:'margin-'+dir+':'+value + 'px'});
  12145. return true;
  12146. },
  12147. queryCommandValue : function(cmdName,dir) {
  12148. var pN = domUtils.filterNodeList(this.selection.getStartElementPath(),function(node){return domUtils.isBlockElm(node) }),
  12149. value;
  12150. //trace:1026
  12151. if(pN){
  12152. value = domUtils.getComputedStyle(pN,'margin-'+dir).replace(/[^\d]/g,'');
  12153. return !value ? 0 : value;
  12154. }
  12155. return 0;
  12156. }
  12157. };
  12158. };
  12159. // plugins/lineheight.js
  12160. /**
  12161. * 设置行内间距
  12162. * @file
  12163. * @since 1.2.6.1
  12164. */
  12165. UE.plugins['lineheight'] = function(){
  12166. var me = this;
  12167. me.setOpt({'lineheight':['1', '1.5','1.75','2', '3', '4', '5']});
  12168. /**
  12169. * 行距
  12170. * @command lineheight
  12171. * @method execCommand
  12172. * @param { String } cmdName 命令字符串
  12173. * @param { String } value 传入的行高值, 该值是当前字体的倍数, 例如: 1.5, 1.75
  12174. * @example
  12175. * ```javascript
  12176. * editor.execCommand( 'lineheight', 1.5);
  12177. * ```
  12178. */
  12179. /**
  12180. * 查询当前选区内容的行高大小
  12181. * @command lineheight
  12182. * @method queryCommandValue
  12183. * @param { String } cmd 命令字符串
  12184. * @return { String } 返回当前行高大小
  12185. * @example
  12186. * ```javascript
  12187. * editor.queryCommandValue( 'lineheight' );
  12188. * ```
  12189. */
  12190. me.commands['lineheight'] = {
  12191. execCommand : function( cmdName,value ) {
  12192. this.execCommand('paragraph','p',{style:'line-height:'+ (value == "1" ? "normal" : value + 'em') });
  12193. return true;
  12194. },
  12195. queryCommandValue : function() {
  12196. var pN = domUtils.filterNodeList(this.selection.getStartElementPath(),function(node){return domUtils.isBlockElm(node)});
  12197. if(pN){
  12198. var value = domUtils.getComputedStyle(pN,'line-height');
  12199. return value == 'normal' ? 1 : value.replace(/[^\d.]*/ig,"");
  12200. }
  12201. }
  12202. };
  12203. };
  12204. // plugins/insertcode.js
  12205. /**
  12206. * 插入代码插件
  12207. * @file
  12208. * @since 1.2.6.1
  12209. */
  12210. UE.plugins['insertcode'] = function() {
  12211. var me = this;
  12212. me.ready(function(){
  12213. utils.cssRule('pre','pre{margin:.5em 0;padding:.4em .6em;border-radius:8px;background:#f8f8f8;}',
  12214. me.document)
  12215. });
  12216. me.setOpt('insertcode',{
  12217. 'as3':'ActionScript3',
  12218. 'bash':'Bash/Shell',
  12219. 'cpp':'C/C++',
  12220. 'css':'Css',
  12221. 'cf':'CodeFunction',
  12222. 'c#':'C#',
  12223. 'delphi':'Delphi',
  12224. 'diff':'Diff',
  12225. 'erlang':'Erlang',
  12226. 'groovy':'Groovy',
  12227. 'html':'Html',
  12228. 'java':'Java',
  12229. 'jfx':'JavaFx',
  12230. 'js':'Javascript',
  12231. 'pl':'Perl',
  12232. 'php':'Php',
  12233. 'plain':'Plain Text',
  12234. 'ps':'PowerShell',
  12235. 'python':'Python',
  12236. 'ruby':'Ruby',
  12237. 'scala':'Scala',
  12238. 'sql':'Sql',
  12239. 'vb':'Vb',
  12240. 'xml':'Xml'
  12241. });
  12242. /**
  12243. * 插入代码
  12244. * @command insertcode
  12245. * @method execCommand
  12246. * @param { String } cmd 命令字符串
  12247. * @param { String } lang 插入代码的语言
  12248. * @example
  12249. * ```javascript
  12250. * editor.execCommand( 'insertcode', 'javascript' );
  12251. * ```
  12252. */
  12253. /**
  12254. * 如果选区所在位置是插入插入代码区域,返回代码的语言
  12255. * @command insertcode
  12256. * @method queryCommandValue
  12257. * @param { String } cmd 命令字符串
  12258. * @return { String } 返回代码的语言
  12259. * @example
  12260. * ```javascript
  12261. * editor.queryCommandValue( 'insertcode' );
  12262. * ```
  12263. */
  12264. me.commands['insertcode'] = {
  12265. execCommand : function(cmd,lang){
  12266. var me = this,
  12267. rng = me.selection.getRange(),
  12268. pre = domUtils.findParentByTagName(rng.startContainer,'pre',true);
  12269. if(pre){
  12270. pre.className = 'brush:'+lang+';toolbar:false;';
  12271. }else{
  12272. var code = '';
  12273. if(rng.collapsed){
  12274. code = browser.ie && browser.ie11below ? (browser.version <= 8 ? '&nbsp;':''):'<br/>';
  12275. }else{
  12276. var frag = rng.extractContents();
  12277. var div = me.document.createElement('div');
  12278. div.appendChild(frag);
  12279. utils.each(UE.filterNode(UE.htmlparser(div.innerHTML.replace(/[\r\t]/g,'')),me.options.filterTxtRules).children,function(node){
  12280. if(browser.ie && browser.ie11below && browser.version > 8){
  12281. if(node.type =='element'){
  12282. if(node.tagName == 'br'){
  12283. code += '\n'
  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 += '\n'
  12289. }else if(!dtd.$empty[node.tagName]){
  12290. code += cn.innerText();
  12291. }
  12292. }else{
  12293. code += cn.data
  12294. }
  12295. })
  12296. if(!/\n$/.test(code)){
  12297. code += '\n';
  12298. }
  12299. }
  12300. }else{
  12301. code += node.data + '\n'
  12302. }
  12303. if(!node.nextSibling() && /\n$/.test(code)){
  12304. code = code.replace(/\n$/,'');
  12305. }
  12306. }else{
  12307. if(browser.ie && browser.ie11below){
  12308. if(node.type =='element'){
  12309. if(node.tagName == 'br'){
  12310. code += '<br>'
  12311. }else if(!dtd.$empty[node.tagName]){
  12312. utils.each(node.children,function(cn){
  12313. if(cn.type =='element'){
  12314. if(cn.tagName == 'br'){
  12315. code += '<br>'
  12316. }else if(!dtd.$empty[node.tagName]){
  12317. code += cn.innerText();
  12318. }
  12319. }else{
  12320. code += cn.data
  12321. }
  12322. });
  12323. if(!/br>$/.test(code)){
  12324. code += '<br>';
  12325. }
  12326. }
  12327. }else{
  12328. code += node.data + '<br>'
  12329. }
  12330. if(!node.nextSibling() && /<br>$/.test(code)){
  12331. code = code.replace(/<br>$/,'');
  12332. }
  12333. }else{
  12334. code += (node.type == 'element' ? (dtd.$empty[node.tagName] ? '' : node.innerText()) : node.data);
  12335. if(!/br\/?\s*>$/.test(code)){
  12336. if(!node.nextSibling())
  12337. return;
  12338. code += '<br>'
  12339. }
  12340. }
  12341. }
  12342. });
  12343. }
  12344. me.execCommand('inserthtml','<pre id="coder"class="brush:'+lang+';toolbar:false">'+code+'</pre>',true);
  12345. pre = me.document.getElementById('coder');
  12346. domUtils.removeAttributes(pre,'id');
  12347. var tmpNode = pre.previousSibling;
  12348. if(tmpNode && (tmpNode.nodeType == 3 && tmpNode.nodeValue.length == 1 && browser.ie && browser.version == 6 || domUtils.isEmptyBlock(tmpNode))){
  12349. domUtils.remove(tmpNode)
  12350. }
  12351. var rng = me.selection.getRange();
  12352. if(domUtils.isEmptyBlock(pre)){
  12353. rng.setStart(pre,0).setCursor(false,true)
  12354. }else{
  12355. rng.selectNodeContents(pre).select()
  12356. }
  12357. }
  12358. },
  12359. queryCommandValue : function(){
  12360. var path = this.selection.getStartElementPath();
  12361. var lang = '';
  12362. utils.each(path,function(node){
  12363. if(node.nodeName =='PRE'){
  12364. var match = node.className.match(/brush:([^;]+)/);
  12365. lang = match && match[1] ? match[1] : '';
  12366. return false;
  12367. }
  12368. });
  12369. return lang;
  12370. }
  12371. };
  12372. me.addInputRule(function(root){
  12373. utils.each(root.getNodesByTagName('pre'),function(pre){
  12374. var brs = pre.getNodesByTagName('br');
  12375. if(brs.length){
  12376. browser.ie && browser.ie11below && browser.version > 8 && utils.each(brs,function(br){
  12377. var txt = UE.uNode.createText('\n');
  12378. br.parentNode.insertBefore(txt,br);
  12379. br.parentNode.removeChild(br);
  12380. });
  12381. return;
  12382. }
  12383. if(browser.ie && browser.ie11below && browser.version > 8)
  12384. return;
  12385. var code = pre.innerText().split(/\n/);
  12386. pre.innerHTML('');
  12387. utils.each(code,function(c){
  12388. if(c.length){
  12389. pre.appendChild(UE.uNode.createText(c));
  12390. }
  12391. pre.appendChild(UE.uNode.createElement('br'))
  12392. })
  12393. })
  12394. });
  12395. me.addOutputRule(function(root){
  12396. utils.each(root.getNodesByTagName('pre'),function(pre){
  12397. var code = '';
  12398. utils.each(pre.children,function(n){
  12399. if(n.type == 'text'){
  12400. //在ie下文本内容有可能末尾带有\n要去掉
  12401. //trace:3396
  12402. code += n.data.replace(/[ ]/g,'&nbsp;').replace(/\n$/,'');
  12403. }else{
  12404. if(n.tagName == 'br'){
  12405. code += '\n'
  12406. }else{
  12407. code += (!dtd.$empty[n.tagName] ? '' : n.innerText());
  12408. }
  12409. }
  12410. });
  12411. pre.innerText(code.replace(/(&nbsp;|\n)+$/,''))
  12412. })
  12413. });
  12414. //不需要判断highlight的command列表
  12415. me.notNeedCodeQuery ={
  12416. help:1,
  12417. undo:1,
  12418. redo:1,
  12419. source:1,
  12420. print:1,
  12421. searchreplace:1,
  12422. fullscreen:1,
  12423. preview:1,
  12424. insertparagraph:1,
  12425. elementpath:1,
  12426. insertcode:1,
  12427. inserthtml:1,
  12428. selectall:1
  12429. };
  12430. //将queyCommamndState重置
  12431. var orgQuery = me.queryCommandState;
  12432. me.queryCommandState = function(cmd){
  12433. var me = this;
  12434. if(!me.notNeedCodeQuery[cmd.toLowerCase()] && me.selection && me.queryCommandValue('insertcode')){
  12435. return -1;
  12436. }
  12437. return UE.Editor.prototype.queryCommandState.apply(this,arguments)
  12438. };
  12439. me.addListener('beforeenterkeydown',function(){
  12440. var rng = me.selection.getRange();
  12441. var pre = domUtils.findParentByTagName(rng.startContainer,'pre',true);
  12442. if(pre){
  12443. me.fireEvent('saveScene');
  12444. if(!rng.collapsed){
  12445. rng.deleteContents();
  12446. }
  12447. if(!browser.ie || browser.ie9above){
  12448. var tmpNode = me.document.createElement('br'),pre;
  12449. rng.insertNode(tmpNode).setStartAfter(tmpNode).collapse(true);
  12450. var next = tmpNode.nextSibling;
  12451. if(!next && (!browser.ie || browser.version > 10)){
  12452. rng.insertNode(tmpNode.cloneNode(false));
  12453. }else{
  12454. rng.setStartAfter(tmpNode);
  12455. }
  12456. pre = tmpNode.previousSibling;
  12457. var tmp;
  12458. while(pre ){
  12459. tmp = pre;
  12460. pre = pre.previousSibling;
  12461. if(!pre || pre.nodeName == 'BR'){
  12462. pre = tmp;
  12463. break;
  12464. }
  12465. }
  12466. if(pre){
  12467. var str = '';
  12468. while(pre && pre.nodeName != 'BR' && new RegExp('^[\\s'+domUtils.fillChar+']*$').test(pre.nodeValue)){
  12469. str += pre.nodeValue;
  12470. pre = pre.nextSibling;
  12471. }
  12472. if(pre.nodeName != 'BR'){
  12473. var match = pre.nodeValue.match(new RegExp('^([\\s'+domUtils.fillChar+']+)'));
  12474. if(match && match[1]){
  12475. str += match[1]
  12476. }
  12477. }
  12478. if(str){
  12479. str = me.document.createTextNode(str);
  12480. rng.insertNode(str).setStartAfter(str);
  12481. }
  12482. }
  12483. rng.collapse(true).select(true);
  12484. }else{
  12485. if(browser.version > 8){
  12486. var txt = me.document.createTextNode('\n');
  12487. var start = rng.startContainer;
  12488. if(rng.startOffset == 0){
  12489. var preNode = start.previousSibling;
  12490. if(preNode){
  12491. rng.insertNode(txt);
  12492. var fillchar = me.document.createTextNode(' ');
  12493. rng.setStartAfter(txt).insertNode(fillchar).setStart(fillchar,0).collapse(true).select(true)
  12494. }
  12495. }else{
  12496. rng.insertNode(txt).setStartAfter(txt);
  12497. var fillchar = me.document.createTextNode(' ');
  12498. start = rng.startContainer.childNodes[rng.startOffset];
  12499. if(start && !/^\n/.test(start.nodeValue)){
  12500. rng.setStartBefore(txt)
  12501. }
  12502. rng.insertNode(fillchar).setStart(fillchar,0).collapse(true).select(true)
  12503. }
  12504. }else{
  12505. var tmpNode = me.document.createElement('br');
  12506. rng.insertNode(tmpNode);
  12507. rng.insertNode(me.document.createTextNode(domUtils.fillChar));
  12508. rng.setStartAfter(tmpNode);
  12509. pre = tmpNode.previousSibling;
  12510. var tmp;
  12511. while(pre ){
  12512. tmp = pre;
  12513. pre = pre.previousSibling;
  12514. if(!pre || pre.nodeName == 'BR'){
  12515. pre = tmp;
  12516. break;
  12517. }
  12518. }
  12519. if(pre){
  12520. var str = '';
  12521. while(pre && pre.nodeName != 'BR' && new RegExp('^[ '+domUtils.fillChar+']*$').test(pre.nodeValue)){
  12522. str += pre.nodeValue;
  12523. pre = pre.nextSibling;
  12524. }
  12525. if(pre.nodeName != 'BR'){
  12526. var match = pre.nodeValue.match(new RegExp('^([ '+domUtils.fillChar+']+)'));
  12527. if(match && match[1]){
  12528. str += match[1]
  12529. }
  12530. }
  12531. str = me.document.createTextNode(str);
  12532. rng.insertNode(str).setStartAfter(str);
  12533. }
  12534. rng.collapse(true).select();
  12535. }
  12536. }
  12537. me.fireEvent('saveScene');
  12538. return true;
  12539. }
  12540. });
  12541. me.addListener('tabkeydown',function(cmd,evt){
  12542. var rng = me.selection.getRange();
  12543. var pre = domUtils.findParentByTagName(rng.startContainer,'pre',true);
  12544. if(pre){
  12545. me.fireEvent('saveScene');
  12546. if(evt.shiftKey){
  12547. }else{
  12548. if(!rng.collapsed){
  12549. var bk = rng.createBookmark();
  12550. var start = bk.start.previousSibling;
  12551. while(start){
  12552. if(pre.firstChild === start && !domUtils.isBr(start)){
  12553. pre.insertBefore(me.document.createTextNode(' '),start);
  12554. break;
  12555. }
  12556. if(domUtils.isBr(start)){
  12557. pre.insertBefore(me.document.createTextNode(' '),start.nextSibling);
  12558. break;
  12559. }
  12560. start = start.previousSibling;
  12561. }
  12562. var end = bk.end;
  12563. start = bk.start.nextSibling;
  12564. if(pre.firstChild === bk.start){
  12565. pre.insertBefore(me.document.createTextNode(' '),start.nextSibling)
  12566. }
  12567. while(start && start !== end){
  12568. if(domUtils.isBr(start) && start.nextSibling){
  12569. if(start.nextSibling === end){
  12570. break;
  12571. }
  12572. pre.insertBefore(me.document.createTextNode(' '),start.nextSibling)
  12573. }
  12574. start = start.nextSibling;
  12575. }
  12576. rng.moveToBookmark(bk).select();
  12577. }else{
  12578. var tmpNode = me.document.createTextNode(' ');
  12579. rng.insertNode(tmpNode).setStartAfter(tmpNode).collapse(true).select(true);
  12580. }
  12581. }
  12582. me.fireEvent('saveScene');
  12583. return true;
  12584. }
  12585. });
  12586. me.addListener('beforeinserthtml',function(evtName,html){
  12587. var me = this,
  12588. rng = me.selection.getRange(),
  12589. pre = domUtils.findParentByTagName(rng.startContainer,'pre',true);
  12590. if(pre){
  12591. if(!rng.collapsed){
  12592. rng.deleteContents()
  12593. }
  12594. var htmlstr = '';
  12595. if(browser.ie && browser.version > 8){
  12596. utils.each(UE.filterNode(UE.htmlparser(html),me.options.filterTxtRules).children,function(node){
  12597. if(node.type =='element'){
  12598. if(node.tagName == 'br'){
  12599. htmlstr += '\n'
  12600. }else if(!dtd.$empty[node.tagName]){
  12601. utils.each(node.children,function(cn){
  12602. if(cn.type =='element'){
  12603. if(cn.tagName == 'br'){
  12604. htmlstr += '\n'
  12605. }else if(!dtd.$empty[node.tagName]){
  12606. htmlstr += cn.innerText();
  12607. }
  12608. }else{
  12609. htmlstr += cn.data
  12610. }
  12611. })
  12612. if(!/\n$/.test(htmlstr)){
  12613. htmlstr += '\n';
  12614. }
  12615. }
  12616. }else{
  12617. htmlstr += node.data + '\n'
  12618. }
  12619. if(!node.nextSibling() && /\n$/.test(htmlstr)){
  12620. htmlstr = htmlstr.replace(/\n$/,'');
  12621. }
  12622. });
  12623. var tmpNode = me.document.createTextNode(utils.html(htmlstr.replace(/&nbsp;/g,' ')));
  12624. rng.insertNode(tmpNode).selectNode(tmpNode).select();
  12625. }else{
  12626. var frag = me.document.createDocumentFragment();
  12627. utils.each(UE.filterNode(UE.htmlparser(html),me.options.filterTxtRules).children,function(node){
  12628. if(node.type =='element'){
  12629. if(node.tagName == 'br'){
  12630. frag.appendChild(me.document.createElement('br'))
  12631. }else if(!dtd.$empty[node.tagName]){
  12632. utils.each(node.children,function(cn){
  12633. if(cn.type =='element'){
  12634. if(cn.tagName == 'br'){
  12635. frag.appendChild(me.document.createElement('br'))
  12636. }else if(!dtd.$empty[node.tagName]){
  12637. frag.appendChild(me.document.createTextNode(utils.html(cn.innerText().replace(/&nbsp;/g,' '))));
  12638. }
  12639. }else{
  12640. frag.appendChild(me.document.createTextNode(utils.html( cn.data.replace(/&nbsp;/g,' '))));
  12641. }
  12642. })
  12643. if(frag.lastChild.nodeName != 'BR'){
  12644. frag.appendChild(me.document.createElement('br'))
  12645. }
  12646. }
  12647. }else{
  12648. frag.appendChild(me.document.createTextNode(utils.html( node.data.replace(/&nbsp;/g,' '))));
  12649. }
  12650. if(!node.nextSibling() && frag.lastChild.nodeName == 'BR'){
  12651. frag.removeChild(frag.lastChild)
  12652. }
  12653. });
  12654. rng.insertNode(frag).select();
  12655. }
  12656. return true;
  12657. }
  12658. });
  12659. //方向键的处理
  12660. me.addListener('keydown',function(cmd,evt){
  12661. var me = this,keyCode = evt.keyCode || evt.which;
  12662. if(keyCode == 40){
  12663. var rng = me.selection.getRange(),pre,start = rng.startContainer;
  12664. if(rng.collapsed && (pre = domUtils.findParentByTagName(rng.startContainer,'pre',true)) && !pre.nextSibling){
  12665. var last = pre.lastChild
  12666. while(last && last.nodeName == 'BR'){
  12667. last = last.previousSibling;
  12668. }
  12669. if(last === start || rng.startContainer === pre && rng.startOffset == pre.childNodes.length){
  12670. me.execCommand('insertparagraph');
  12671. domUtils.preventDefault(evt)
  12672. }
  12673. }
  12674. }
  12675. });
  12676. //trace:3395
  12677. me.addListener('delkeydown',function(type,evt){
  12678. var rng = this.selection.getRange();
  12679. rng.txtToElmBoundary(true);
  12680. var start = rng.startContainer;
  12681. if(domUtils.isTagNode(start,'pre') && rng.collapsed && domUtils.isStartInblock(rng)){
  12682. var p = me.document.createElement('p');
  12683. domUtils.fillNode(me.document,p);
  12684. start.parentNode.insertBefore(p,start);
  12685. domUtils.remove(start);
  12686. rng.setStart(p,0).setCursor(false,true);
  12687. domUtils.preventDefault(evt);
  12688. return true;
  12689. }
  12690. })
  12691. };
  12692. // plugins/cleardoc.js
  12693. /**
  12694. * 清空文档插件
  12695. * @file
  12696. * @since 1.2.6.1
  12697. */
  12698. /**
  12699. * 清空文档
  12700. * @command cleardoc
  12701. * @method execCommand
  12702. * @param { String } cmd 命令字符串
  12703. * @example
  12704. * ```javascript
  12705. * //editor 是编辑器实例
  12706. * editor.execCommand('cleardoc');
  12707. * ```
  12708. */
  12709. UE.commands['cleardoc'] = {
  12710. execCommand : function( cmdName) {
  12711. var me = this,
  12712. enterTag = me.options.enterTag,
  12713. range = me.selection.getRange();
  12714. if(enterTag == "br"){
  12715. me.body.innerHTML = "<br/>";
  12716. range.setStart(me.body,0).setCursor();
  12717. }else{
  12718. me.body.innerHTML = "<p>"+(ie ? "" : "<br/>")+"</p>";
  12719. range.setStart(me.body.firstChild,0).setCursor(false,true);
  12720. }
  12721. setTimeout(function(){
  12722. me.fireEvent("clearDoc");
  12723. },0);
  12724. }
  12725. };
  12726. // plugins/anchor.js
  12727. /**
  12728. * 锚点插件,为UEditor提供插入锚点支持
  12729. * @file
  12730. * @since 1.2.6.1
  12731. */
  12732. UE.plugin.register('anchor', function (){
  12733. return {
  12734. bindEvents:{
  12735. 'ready':function(){
  12736. utils.cssRule('anchor',
  12737. '.anchorclass{background: url(\''
  12738. + this.options.themePath
  12739. + this.options.theme +'/images/anchor.gif\') no-repeat scroll left center transparent;cursor: auto;display: inline-block;height: 16px;width: 15px;}',
  12740. this.document);
  12741. }
  12742. },
  12743. outputRule: function(root){
  12744. utils.each(root.getNodesByTagName('img'),function(a){
  12745. var val;
  12746. if(val = a.getAttr('anchorname')){
  12747. a.tagName = 'a';
  12748. a.setAttr({
  12749. anchorname : '',
  12750. name : val,
  12751. 'class' : ''
  12752. })
  12753. }
  12754. })
  12755. },
  12756. inputRule:function(root){
  12757. utils.each(root.getNodesByTagName('a'),function(a){
  12758. var val;
  12759. if((val = a.getAttr('name')) && !a.getAttr('href')){
  12760. a.tagName = 'img';
  12761. a.setAttr({
  12762. anchorname :a.getAttr('name'),
  12763. 'class' : 'anchorclass'
  12764. });
  12765. a.setAttr('name')
  12766. }
  12767. })
  12768. },
  12769. commands:{
  12770. /**
  12771. * 插入锚点
  12772. * @command anchor
  12773. * @method execCommand
  12774. * @param { String } cmd 命令字符串
  12775. * @param { String } name 锚点名称字符串
  12776. * @example
  12777. * ```javascript
  12778. * //editor 是编辑器实例
  12779. * editor.execCommand('anchor', 'anchor1');
  12780. * ```
  12781. */
  12782. 'anchor':{
  12783. execCommand:function (cmd, name) {
  12784. var range = this.selection.getRange(),img = range.getClosedNode();
  12785. if (img && img.getAttribute('anchorname')) {
  12786. if (name) {
  12787. img.setAttribute('anchorname', name);
  12788. } else {
  12789. range.setStartBefore(img).setCursor();
  12790. domUtils.remove(img);
  12791. }
  12792. } else {
  12793. if (name) {
  12794. //只在选区的开始插入
  12795. var anchor = this.document.createElement('img');
  12796. range.collapse(true);
  12797. domUtils.setAttributes(anchor,{
  12798. 'anchorname':name,
  12799. 'class':'anchorclass'
  12800. });
  12801. range.insertNode(anchor).setStartAfter(anchor).setCursor(false,true);
  12802. }
  12803. }
  12804. }
  12805. }
  12806. }
  12807. }
  12808. });
  12809. // plugins/wordcount.js
  12810. ///import core
  12811. ///commands 字数统计
  12812. ///commandsName WordCount,wordCount
  12813. ///commandsTitle 字数统计
  12814. /*
  12815. * Created by JetBrains WebStorm.
  12816. * User: taoqili
  12817. * Date: 11-9-7
  12818. * Time: 下午8:18
  12819. * To change this template use File | Settings | File Templates.
  12820. */
  12821. UE.plugins['wordcount'] = function(){
  12822. var me = this;
  12823. me.setOpt('wordCount',true);
  12824. me.addListener('contentchange',function(){
  12825. me.fireEvent('wordcount');
  12826. });
  12827. var timer;
  12828. me.addListener('ready',function(){
  12829. var me = this;
  12830. domUtils.on(me.body,"keyup",function(evt){
  12831. var code = evt.keyCode||evt.which,
  12832. //忽略的按键,ctr,alt,shift,方向键
  12833. ignores = {"16":1,"18":1,"20":1,"37":1,"38":1,"39":1,"40":1};
  12834. if(code in ignores) return;
  12835. clearTimeout(timer);
  12836. timer = setTimeout(function(){
  12837. me.fireEvent('wordcount');
  12838. },200)
  12839. })
  12840. });
  12841. };
  12842. // plugins/pagebreak.js
  12843. /**
  12844. * 分页功能插件
  12845. * @file
  12846. * @since 1.2.6.1
  12847. */
  12848. UE.plugins['pagebreak'] = function () {
  12849. var me = this,
  12850. notBreakTags = ['td'];
  12851. me.setOpt('pageBreakTag','_ueditor_page_break_tag_');
  12852. function fillNode(node){
  12853. if(domUtils.isEmptyBlock(node)){
  12854. var firstChild = node.firstChild,tmpNode;
  12855. while(firstChild && firstChild.nodeType == 1 && domUtils.isEmptyBlock(firstChild)){
  12856. tmpNode = firstChild;
  12857. firstChild = firstChild.firstChild;
  12858. }
  12859. !tmpNode && (tmpNode = node);
  12860. domUtils.fillNode(me.document,tmpNode);
  12861. }
  12862. }
  12863. //分页符样式添加
  12864. me.ready(function(){
  12865. utils.cssRule('pagebreak','.pagebreak{display:block;clear:both !important;cursor:default !important;width: 100% !important;margin:0;}',me.document);
  12866. });
  12867. function isHr(node){
  12868. return node && node.nodeType == 1 && node.tagName == 'HR' && node.className == 'pagebreak';
  12869. }
  12870. me.addInputRule(function(root){
  12871. root.traversal(function(node){
  12872. if(node.type == 'text' && node.data == me.options.pageBreakTag){
  12873. var hr = UE.uNode.createElement('<hr class="pagebreak" noshade="noshade" size="5" style="-webkit-user-select: none;">');
  12874. node.parentNode.insertBefore(hr,node);
  12875. node.parentNode.removeChild(node)
  12876. }
  12877. })
  12878. });
  12879. me.addOutputRule(function(node){
  12880. utils.each(node.getNodesByTagName('hr'),function(n){
  12881. if(n.getAttr('class') == 'pagebreak'){
  12882. var txt = UE.uNode.createText(me.options.pageBreakTag);
  12883. n.parentNode.insertBefore(txt,n);
  12884. n.parentNode.removeChild(n);
  12885. }
  12886. })
  12887. });
  12888. /**
  12889. * 插入分页符
  12890. * @command pagebreak
  12891. * @method execCommand
  12892. * @param { String } cmd 命令字符串
  12893. * @remind 在表格中插入分页符会把表格切分成两部分
  12894. * @remind 获取编辑器内的数据时, 编辑器会把分页符转换成“_ueditor_page_break_tag_”字符串,
  12895. * 以便于提交数据到服务器端后处理分页。
  12896. * @example
  12897. * ```javascript
  12898. * editor.execCommand( 'pagebreak'); //插入一个hr标签,带有样式类名pagebreak
  12899. * ```
  12900. */
  12901. me.commands['pagebreak'] = {
  12902. execCommand:function () {
  12903. var range = me.selection.getRange(),hr = me.document.createElement('hr');
  12904. domUtils.setAttributes(hr,{
  12905. 'class' : 'pagebreak',
  12906. noshade:"noshade",
  12907. size:"5"
  12908. });
  12909. domUtils.unSelectable(hr);
  12910. //table单独处理
  12911. var node = domUtils.findParentByTagName(range.startContainer, notBreakTags, true),
  12912. parents = [], pN;
  12913. if (node) {
  12914. switch (node.tagName) {
  12915. case 'TD':
  12916. pN = node.parentNode;
  12917. if (!pN.previousSibling) {
  12918. var table = domUtils.findParentByTagName(pN, 'table');
  12919. // var tableWrapDiv = table.parentNode;
  12920. // if(tableWrapDiv && tableWrapDiv.nodeType == 1
  12921. // && tableWrapDiv.tagName == 'DIV'
  12922. // && tableWrapDiv.getAttribute('dropdrag')
  12923. // ){
  12924. // domUtils.remove(tableWrapDiv,true);
  12925. // }
  12926. table.parentNode.insertBefore(hr, table);
  12927. parents = domUtils.findParents(hr, true);
  12928. } else {
  12929. pN.parentNode.insertBefore(hr, pN);
  12930. parents = domUtils.findParents(hr);
  12931. }
  12932. pN = parents[1];
  12933. if (hr !== pN) {
  12934. domUtils.breakParent(hr, pN);
  12935. }
  12936. //table要重写绑定一下拖拽
  12937. me.fireEvent('afteradjusttable',me.document);
  12938. }
  12939. } else {
  12940. if (!range.collapsed) {
  12941. range.deleteContents();
  12942. var start = range.startContainer;
  12943. while ( !domUtils.isBody(start) && domUtils.isBlockElm(start) && domUtils.isEmptyNode(start)) {
  12944. range.setStartBefore(start).collapse(true);
  12945. domUtils.remove(start);
  12946. start = range.startContainer;
  12947. }
  12948. }
  12949. range.insertNode(hr);
  12950. var pN = hr.parentNode, nextNode;
  12951. while (!domUtils.isBody(pN)) {
  12952. domUtils.breakParent(hr, pN);
  12953. nextNode = hr.nextSibling;
  12954. if (nextNode && domUtils.isEmptyBlock(nextNode)) {
  12955. domUtils.remove(nextNode);
  12956. }
  12957. pN = hr.parentNode;
  12958. }
  12959. nextNode = hr.nextSibling;
  12960. var pre = hr.previousSibling;
  12961. if(isHr(pre)){
  12962. domUtils.remove(pre);
  12963. }else{
  12964. pre && fillNode(pre);
  12965. }
  12966. if(!nextNode){
  12967. var p = me.document.createElement('p');
  12968. hr.parentNode.appendChild(p);
  12969. domUtils.fillNode(me.document,p);
  12970. range.setStart(p,0).collapse(true);
  12971. }else{
  12972. if(isHr(nextNode)){
  12973. domUtils.remove(nextNode);
  12974. }else{
  12975. fillNode(nextNode);
  12976. }
  12977. range.setEndAfter(hr).collapse(false);
  12978. }
  12979. range.select(true);
  12980. }
  12981. }
  12982. };
  12983. };
  12984. // plugins/wordimage.js
  12985. ///import core
  12986. ///commands 本地图片引导上传
  12987. ///commandsName WordImage
  12988. ///commandsTitle 本地图片引导上传
  12989. ///commandsDialog dialogs\wordimage
  12990. UE.plugin.register('wordimage',function(){
  12991. var me = this,
  12992. images = [];
  12993. return {
  12994. commands : {
  12995. 'wordimage':{
  12996. execCommand:function () {
  12997. var images = domUtils.getElementsByTagName(me.body, "img");
  12998. var urlList = [];
  12999. for (var i = 0, ci; ci = images[i++];) {
  13000. var url = ci.getAttribute("word_img");
  13001. url && urlList.push(url);
  13002. }
  13003. return urlList;
  13004. },
  13005. queryCommandState:function () {
  13006. images = domUtils.getElementsByTagName(me.body, "img");
  13007. for (var i = 0, ci; ci = images[i++];) {
  13008. if (ci.getAttribute("word_img")) {
  13009. return 1;
  13010. }
  13011. }
  13012. return -1;
  13013. },
  13014. notNeedUndo:true
  13015. }
  13016. },
  13017. inputRule : function (root) {
  13018. utils.each(root.getNodesByTagName('img'), function (img) {
  13019. var attrs = img.attrs,
  13020. flag = parseInt(attrs.width) < 128 || parseInt(attrs.height) < 43,
  13021. opt = me.options,
  13022. src = opt.UEDITOR_HOME_URL + 'themes/default/images/spacer.gif';
  13023. if (attrs['src'] && /^(?:(file:\/+))/.test(attrs['src'])) {
  13024. img.setAttr({
  13025. width:attrs.width,
  13026. height:attrs.height,
  13027. alt:attrs.alt,
  13028. word_img: attrs.src,
  13029. src:src,
  13030. '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'
  13031. })
  13032. }
  13033. })
  13034. }
  13035. }
  13036. });
  13037. // plugins/dragdrop.js
  13038. UE.plugins['dragdrop'] = function (){
  13039. var me = this;
  13040. me.ready(function(){
  13041. domUtils.on(this.body,'dragend',function(){
  13042. var rng = me.selection.getRange();
  13043. var node = rng.getClosedNode()||me.selection.getStart();
  13044. if(node && node.tagName == 'IMG'){
  13045. var pre = node.previousSibling,next;
  13046. while(next = node.nextSibling){
  13047. if(next.nodeType == 1 && next.tagName == 'SPAN' && !next.firstChild){
  13048. domUtils.remove(next)
  13049. }else{
  13050. break;
  13051. }
  13052. }
  13053. if((pre && pre.nodeType == 1 && !domUtils.isEmptyBlock(pre) || !pre) && (!next || next && !domUtils.isEmptyBlock(next))){
  13054. if(pre && pre.tagName == 'P' && !domUtils.isEmptyBlock(pre)){
  13055. pre.appendChild(node);
  13056. domUtils.moveChild(next,pre);
  13057. domUtils.remove(next);
  13058. }else if(next && next.tagName == 'P' && !domUtils.isEmptyBlock(next)){
  13059. next.insertBefore(node,next.firstChild);
  13060. }
  13061. if(pre && pre.tagName == 'P' && domUtils.isEmptyBlock(pre)){
  13062. domUtils.remove(pre)
  13063. }
  13064. if(next && next.tagName == 'P' && domUtils.isEmptyBlock(next)){
  13065. domUtils.remove(next)
  13066. }
  13067. rng.selectNode(node).select();
  13068. me.fireEvent('saveScene');
  13069. }
  13070. }
  13071. })
  13072. });
  13073. me.addListener('keyup', function(type, evt) {
  13074. var keyCode = evt.keyCode || evt.which;
  13075. if (keyCode == 13) {
  13076. var rng = me.selection.getRange(),node;
  13077. if(node = domUtils.findParentByTagName(rng.startContainer,'p',true)){
  13078. if(domUtils.getComputedStyle(node,'text-align') == 'center'){
  13079. domUtils.removeStyle(node,'text-align')
  13080. }
  13081. }
  13082. }
  13083. })
  13084. };
  13085. // plugins/undo.js
  13086. /**
  13087. * undo redo
  13088. * @file
  13089. * @since 1.2.6.1
  13090. */
  13091. /**
  13092. * 撤销上一次执行的命令
  13093. * @command undo
  13094. * @method execCommand
  13095. * @param { String } cmd 命令字符串
  13096. * @example
  13097. * ```javascript
  13098. * editor.execCommand( 'undo' );
  13099. * ```
  13100. */
  13101. /**
  13102. * 重做上一次执行的命令
  13103. * @command redo
  13104. * @method execCommand
  13105. * @param { String } cmd 命令字符串
  13106. * @example
  13107. * ```javascript
  13108. * editor.execCommand( 'redo' );
  13109. * ```
  13110. */
  13111. UE.plugins['undo'] = function () {
  13112. var saveSceneTimer;
  13113. var me = this,
  13114. maxUndoCount = me.options.maxUndoCount || 20,
  13115. maxInputCount = me.options.maxInputCount || 20,
  13116. fillchar = new RegExp(domUtils.fillChar + '|<\/hr>', 'gi');// ie会产生多余的</hr>
  13117. var noNeedFillCharTags = {
  13118. ol:1,ul:1,table:1,tbody:1,tr:1,body:1
  13119. };
  13120. var orgState = me.options.autoClearEmptyNode;
  13121. function compareAddr(indexA, indexB) {
  13122. if (indexA.length != indexB.length)
  13123. return 0;
  13124. for (var i = 0, l = indexA.length; i < l; i++) {
  13125. if (indexA[i] != indexB[i])
  13126. return 0
  13127. }
  13128. return 1;
  13129. }
  13130. function compareRangeAddress(rngAddrA, rngAddrB) {
  13131. if (rngAddrA.collapsed != rngAddrB.collapsed) {
  13132. return 0;
  13133. }
  13134. if (!compareAddr(rngAddrA.startAddress, rngAddrB.startAddress) || !compareAddr(rngAddrA.endAddress, rngAddrB.endAddress)) {
  13135. return 0;
  13136. }
  13137. return 1;
  13138. }
  13139. function UndoManager() {
  13140. this.list = [];
  13141. this.index = 0;
  13142. this.hasUndo = false;
  13143. this.hasRedo = false;
  13144. this.undo = function () {
  13145. if (this.hasUndo) {
  13146. if (!this.list[this.index - 1] && this.list.length == 1) {
  13147. this.reset();
  13148. return;
  13149. }
  13150. while (this.list[this.index].content == this.list[this.index - 1].content) {
  13151. this.index--;
  13152. if (this.index == 0) {
  13153. return this.restore(0);
  13154. }
  13155. }
  13156. this.restore(--this.index);
  13157. }
  13158. };
  13159. this.redo = function () {
  13160. if (this.hasRedo) {
  13161. while (this.list[this.index].content == this.list[this.index + 1].content) {
  13162. this.index++;
  13163. if (this.index == this.list.length - 1) {
  13164. return this.restore(this.index);
  13165. }
  13166. }
  13167. this.restore(++this.index);
  13168. }
  13169. };
  13170. this.restore = function () {
  13171. var me = this.editor;
  13172. var scene = this.list[this.index];
  13173. var root = UE.htmlparser(scene.content.replace(fillchar, ''));
  13174. me.options.autoClearEmptyNode = false;
  13175. me.filterInputRule(root);
  13176. me.options.autoClearEmptyNode = orgState;
  13177. //trace:873
  13178. //去掉展位符
  13179. me.document.body.innerHTML = root.toHtml();
  13180. me.fireEvent('afterscencerestore');
  13181. //处理undo后空格不展位的问题
  13182. if (browser.ie) {
  13183. utils.each(domUtils.getElementsByTagName(me.document,'td th caption p'),function(node){
  13184. if(domUtils.isEmptyNode(node)){
  13185. domUtils.fillNode(me.document, node);
  13186. }
  13187. })
  13188. }
  13189. try{
  13190. var rng = new dom.Range(me.document).moveToAddress(scene.address);
  13191. rng.select(noNeedFillCharTags[rng.startContainer.nodeName.toLowerCase()]);
  13192. }catch(e){}
  13193. this.update();
  13194. this.clearKey();
  13195. //不能把自己reset了
  13196. me.fireEvent('reset', true);
  13197. };
  13198. this.getScene = function () {
  13199. var me = this.editor;
  13200. var rng = me.selection.getRange(),
  13201. rngAddress = rng.createAddress(false,true);
  13202. me.fireEvent('beforegetscene');
  13203. var root = UE.htmlparser(me.body.innerHTML);
  13204. me.options.autoClearEmptyNode = false;
  13205. me.filterOutputRule(root);
  13206. me.options.autoClearEmptyNode = orgState;
  13207. var cont = root.toHtml();
  13208. //trace:3461
  13209. //这个会引起回退时导致空格丢失的情况
  13210. // browser.ie && (cont = cont.replace(/>&nbsp;</g, '><').replace(/\s*</g, '<').replace(/>\s*/g, '>'));
  13211. me.fireEvent('aftergetscene');
  13212. return {
  13213. address:rngAddress,
  13214. content:cont
  13215. }
  13216. };
  13217. this.save = function (notCompareRange,notSetCursor) {
  13218. clearTimeout(saveSceneTimer);
  13219. var currentScene = this.getScene(notSetCursor),
  13220. lastScene = this.list[this.index];
  13221. if(lastScene && lastScene.content != currentScene.content){
  13222. me.trigger('contentchange')
  13223. }
  13224. //内容相同位置相同不存
  13225. if (lastScene && lastScene.content == currentScene.content &&
  13226. ( notCompareRange ? 1 : compareRangeAddress(lastScene.address, currentScene.address) )
  13227. ) {
  13228. return;
  13229. }
  13230. this.list = this.list.slice(0, this.index + 1);
  13231. this.list.push(currentScene);
  13232. //如果大于最大数量了,就把最前的剔除
  13233. if (this.list.length > maxUndoCount) {
  13234. this.list.shift();
  13235. }
  13236. this.index = this.list.length - 1;
  13237. this.clearKey();
  13238. //跟新undo/redo状态
  13239. this.update();
  13240. };
  13241. this.update = function () {
  13242. this.hasRedo = !!this.list[this.index + 1];
  13243. this.hasUndo = !!this.list[this.index - 1];
  13244. };
  13245. this.reset = function () {
  13246. this.list = [];
  13247. this.index = 0;
  13248. this.hasUndo = false;
  13249. this.hasRedo = false;
  13250. this.clearKey();
  13251. };
  13252. this.clearKey = function () {
  13253. keycont = 0;
  13254. lastKeyCode = null;
  13255. };
  13256. }
  13257. me.undoManger = new UndoManager();
  13258. me.undoManger.editor = me;
  13259. function saveScene() {
  13260. this.undoManger.save();
  13261. }
  13262. me.addListener('saveScene', function () {
  13263. var args = Array.prototype.splice.call(arguments,1);
  13264. this.undoManger.save.apply(this.undoManger,args);
  13265. });
  13266. // me.addListener('beforeexeccommand', saveScene);
  13267. // me.addListener('afterexeccommand', saveScene);
  13268. me.addListener('reset', function (type, exclude) {
  13269. if (!exclude) {
  13270. this.undoManger.reset();
  13271. }
  13272. });
  13273. me.commands['redo'] = me.commands['undo'] = {
  13274. execCommand:function (cmdName) {
  13275. this.undoManger[cmdName]();
  13276. },
  13277. queryCommandState:function (cmdName) {
  13278. return this.undoManger['has' + (cmdName.toLowerCase() == 'undo' ? 'Undo' : 'Redo')] ? 0 : -1;
  13279. },
  13280. notNeedUndo:1
  13281. };
  13282. var keys = {
  13283. // /*Backspace*/ 8:1, /*Delete*/ 46:1,
  13284. /*Shift*/ 16:1, /*Ctrl*/ 17:1, /*Alt*/ 18:1,
  13285. 37:1, 38:1, 39:1, 40:1
  13286. },
  13287. keycont = 0,
  13288. lastKeyCode;
  13289. //输入法状态下不计算字符数
  13290. var inputType = false;
  13291. me.addListener('ready', function () {
  13292. domUtils.on(this.body, 'compositionstart', function () {
  13293. inputType = true;
  13294. });
  13295. domUtils.on(this.body, 'compositionend', function () {
  13296. inputType = false;
  13297. })
  13298. });
  13299. //快捷键
  13300. me.addshortcutkey({
  13301. "Undo":"ctrl+90", //undo
  13302. "Redo":"ctrl+89" //redo
  13303. });
  13304. var isCollapsed = true;
  13305. me.addListener('keydown', function (type, evt) {
  13306. var me = this;
  13307. var keyCode = evt.keyCode || evt.which;
  13308. if (!keys[keyCode] && !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey) {
  13309. if (inputType)
  13310. return;
  13311. if(!me.selection.getRange().collapsed){
  13312. me.undoManger.save(false,true);
  13313. isCollapsed = false;
  13314. return;
  13315. }
  13316. if (me.undoManger.list.length == 0) {
  13317. me.undoManger.save(true);
  13318. }
  13319. clearTimeout(saveSceneTimer);
  13320. function save(cont){
  13321. cont.undoManger.save(false,true);
  13322. cont.fireEvent('selectionchange');
  13323. }
  13324. saveSceneTimer = setTimeout(function(){
  13325. if(inputType){
  13326. var interalTimer = setInterval(function(){
  13327. if(!inputType){
  13328. save(me);
  13329. clearInterval(interalTimer)
  13330. }
  13331. },300)
  13332. return;
  13333. }
  13334. save(me);
  13335. },200);
  13336. lastKeyCode = keyCode;
  13337. keycont++;
  13338. if (keycont >= maxInputCount ) {
  13339. save(me)
  13340. }
  13341. }
  13342. });
  13343. me.addListener('keyup', function (type, evt) {
  13344. var keyCode = evt.keyCode || evt.which;
  13345. if (!keys[keyCode] && !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey) {
  13346. if (inputType)
  13347. return;
  13348. if(!isCollapsed){
  13349. this.undoManger.save(false,true);
  13350. isCollapsed = true;
  13351. }
  13352. }
  13353. });
  13354. //扩展实例,添加关闭和开启命令undo
  13355. me.stopCmdUndo = function(){
  13356. me.__hasEnterExecCommand = true;
  13357. };
  13358. me.startCmdUndo = function(){
  13359. me.__hasEnterExecCommand = false;
  13360. }
  13361. };
  13362. // plugins/copy.js
  13363. UE.plugin.register('copy', function () {
  13364. var me = this;
  13365. function initZeroClipboard() {
  13366. ZeroClipboard.config({
  13367. debug: false,
  13368. swfPath: me.options.UEDITOR_HOME_URL + 'third-party/zeroclipboard/ZeroClipboard.swf'
  13369. });
  13370. var client = me.zeroclipboard = new ZeroClipboard();
  13371. // 复制内容
  13372. client.on('copy', function (e) {
  13373. var client = e.client,
  13374. rng = me.selection.getRange(),
  13375. div = document.createElement('div');
  13376. div.appendChild(rng.cloneContents());
  13377. client.setText(div.innerText || div.textContent);
  13378. client.setHtml(div.innerHTML);
  13379. rng.select();
  13380. });
  13381. // hover事件传递到target
  13382. client.on('mouseover mouseout', function (e) {
  13383. var target = e.target;
  13384. if (e.type == 'mouseover') {
  13385. domUtils.addClass(target, 'edui-state-hover');
  13386. } else if (e.type == 'mouseout') {
  13387. domUtils.removeClasses(target, 'edui-state-hover');
  13388. }
  13389. });
  13390. // flash加载不成功
  13391. client.on('wrongflash noflash', function () {
  13392. ZeroClipboard.destroy();
  13393. });
  13394. }
  13395. return {
  13396. bindEvents: {
  13397. 'ready': function () {
  13398. if (!browser.ie) {
  13399. if (window.ZeroClipboard) {
  13400. initZeroClipboard();
  13401. } else {
  13402. utils.loadFile(document, {
  13403. src: me.options.UEDITOR_HOME_URL + "third-party/zeroclipboard/ZeroClipboard.js",
  13404. tag: "script",
  13405. type: "text/javascript",
  13406. defer: "defer"
  13407. }, function () {
  13408. initZeroClipboard();
  13409. });
  13410. }
  13411. }
  13412. }
  13413. },
  13414. commands: {
  13415. 'copy': {
  13416. execCommand: function (cmd) {
  13417. if (!me.document.execCommand('copy')) {
  13418. alert(me.getLang('copymsg'));
  13419. }
  13420. }
  13421. }
  13422. }
  13423. }
  13424. });
  13425. // plugins/paste.js
  13426. ///import core
  13427. ///import plugins/inserthtml.js
  13428. ///import plugins/undo.js
  13429. ///import plugins/serialize.js
  13430. ///commands 粘贴
  13431. ///commandsName PastePlain
  13432. ///commandsTitle 纯文本粘贴模式
  13433. /**
  13434. * @description 粘贴
  13435. * @author zhanyi
  13436. */
  13437. UE.plugins['paste'] = function () {
  13438. function getClipboardData(callback) {
  13439. var doc = this.document;
  13440. if (doc.getElementById('baidu_pastebin')) {
  13441. return;
  13442. }
  13443. var range = this.selection.getRange(),
  13444. bk = range.createBookmark(),
  13445. //创建剪贴的容器div
  13446. pastebin = doc.createElement('div');
  13447. pastebin.id = 'baidu_pastebin';
  13448. // Safari 要求div必须有内容,才能粘贴内容进来
  13449. browser.webkit && pastebin.appendChild(doc.createTextNode(domUtils.fillChar + domUtils.fillChar));
  13450. doc.body.appendChild(pastebin);
  13451. //trace:717 隐藏的span不能得到top
  13452. //bk.start.innerHTML = '&nbsp;';
  13453. bk.start.style.display = '';
  13454. pastebin.style.cssText = "position:absolute;width:1px;height:1px;overflow:hidden;left:-1000px;white-space:nowrap;top:" +
  13455. //要在现在光标平行的位置加入,否则会出现跳动的问题
  13456. domUtils.getXY(bk.start).y + 'px';
  13457. range.selectNodeContents(pastebin).select(true);
  13458. setTimeout(function () {
  13459. if (browser.webkit) {
  13460. for (var i = 0, pastebins = doc.querySelectorAll('#baidu_pastebin'), pi; pi = pastebins[i++];) {
  13461. if (domUtils.isEmptyNode(pi)) {
  13462. domUtils.remove(pi);
  13463. } else {
  13464. pastebin = pi;
  13465. break;
  13466. }
  13467. }
  13468. }
  13469. try {
  13470. pastebin.parentNode.removeChild(pastebin);
  13471. } catch (e) {
  13472. }
  13473. range.moveToBookmark(bk).select(true);
  13474. callback(pastebin);
  13475. }, 0);
  13476. }
  13477. var me = this;
  13478. me.setOpt({
  13479. retainOnlyLabelPasted : false
  13480. });
  13481. var txtContent, htmlContent, address;
  13482. function getPureHtml(html){
  13483. return html.replace(/<(\/?)([\w\-]+)([^>]*)>/gi, function (a, b, tagName, attrs) {
  13484. tagName = tagName.toLowerCase();
  13485. if ({img: 1}[tagName]) {
  13486. return a;
  13487. }
  13488. attrs = attrs.replace(/([\w\-]*?)\s*=\s*(("([^"]*)")|('([^']*)')|([^\s>]+))/gi, function (str, atr, val) {
  13489. if ({
  13490. 'src': 1,
  13491. 'href': 1,
  13492. 'name': 1
  13493. }[atr.toLowerCase()]) {
  13494. return atr + '=' + val + ' '
  13495. }
  13496. return ''
  13497. });
  13498. if ({
  13499. 'span': 1,
  13500. 'div': 1
  13501. }[tagName]) {
  13502. return ''
  13503. } else {
  13504. return '<' + b + tagName + ' ' + utils.trim(attrs) + '>'
  13505. }
  13506. });
  13507. }
  13508. function filter(div) {
  13509. var html;
  13510. if (div.firstChild) {
  13511. //去掉cut中添加的边界值
  13512. var nodes = domUtils.getElementsByTagName(div, 'span');
  13513. for (var i = 0, ni; ni = nodes[i++];) {
  13514. if (ni.id == '_baidu_cut_start' || ni.id == '_baidu_cut_end') {
  13515. domUtils.remove(ni);
  13516. }
  13517. }
  13518. if (browser.webkit) {
  13519. var brs = div.querySelectorAll('div br');
  13520. for (var i = 0, bi; bi = brs[i++];) {
  13521. var pN = bi.parentNode;
  13522. if (pN.tagName == 'DIV' && pN.childNodes.length == 1) {
  13523. pN.innerHTML = '<p><br/></p>';
  13524. domUtils.remove(pN);
  13525. }
  13526. }
  13527. var divs = div.querySelectorAll('#baidu_pastebin');
  13528. for (var i = 0, di; di = divs[i++];) {
  13529. var tmpP = me.document.createElement('p');
  13530. di.parentNode.insertBefore(tmpP, di);
  13531. while (di.firstChild) {
  13532. tmpP.appendChild(di.firstChild);
  13533. }
  13534. domUtils.remove(di);
  13535. }
  13536. var metas = div.querySelectorAll('meta');
  13537. for (var i = 0, ci; ci = metas[i++];) {
  13538. domUtils.remove(ci);
  13539. }
  13540. var brs = div.querySelectorAll('br');
  13541. for (i = 0; ci = brs[i++];) {
  13542. if (/^apple-/i.test(ci.className)) {
  13543. domUtils.remove(ci);
  13544. }
  13545. }
  13546. }
  13547. if (browser.gecko) {
  13548. var dirtyNodes = div.querySelectorAll('[_moz_dirty]');
  13549. for (i = 0; ci = dirtyNodes[i++];) {
  13550. ci.removeAttribute('_moz_dirty');
  13551. }
  13552. }
  13553. if (!browser.ie) {
  13554. var spans = div.querySelectorAll('span.Apple-style-span');
  13555. for (var i = 0, ci; ci = spans[i++];) {
  13556. domUtils.remove(ci, true);
  13557. }
  13558. }
  13559. //ie下使用innerHTML会产生多余的\r\n字符,也会产生&nbsp;这里过滤掉
  13560. html = div.innerHTML;//.replace(/>(?:(\s|&nbsp;)*?)</g,'><');
  13561. //过滤word粘贴过来的冗余属性
  13562. html = UE.filterWord(html);
  13563. //取消了忽略空白的第二个参数,粘贴过来的有些是有空白的,会被套上相关的标签
  13564. var root = UE.htmlparser(html);
  13565. //如果给了过滤规则就先进行过滤
  13566. if (me.options.filterRules) {
  13567. UE.filterNode(root, me.options.filterRules);
  13568. }
  13569. //执行默认的处理
  13570. me.filterInputRule(root);
  13571. //针对chrome的处理
  13572. if (browser.webkit) {
  13573. var br = root.lastChild();
  13574. if (br && br.type == 'element' && br.tagName == 'br') {
  13575. root.removeChild(br)
  13576. }
  13577. utils.each(me.body.querySelectorAll('div'), function (node) {
  13578. if (domUtils.isEmptyBlock(node)) {
  13579. domUtils.remove(node,true)
  13580. }
  13581. })
  13582. }
  13583. html = {'html': root.toHtml()};
  13584. me.fireEvent('beforepaste', html, root);
  13585. //抢了默认的粘贴,那后边的内容就不执行了,比如表格粘贴
  13586. if(!html.html){
  13587. return;
  13588. }
  13589. root = UE.htmlparser(html.html,true);
  13590. //如果开启了纯文本模式
  13591. if (me.queryCommandState('pasteplain') === 1) {
  13592. me.execCommand('insertHtml', UE.filterNode(root, me.options.filterTxtRules).toHtml(), true);
  13593. } else {
  13594. //文本模式
  13595. UE.filterNode(root, me.options.filterTxtRules);
  13596. txtContent = root.toHtml();
  13597. //完全模式
  13598. htmlContent = html.html;
  13599. address = me.selection.getRange().createAddress(true);
  13600. me.execCommand('insertHtml', me.getOpt('retainOnlyLabelPasted') === true ? getPureHtml(htmlContent) : htmlContent, true);
  13601. }
  13602. me.fireEvent("afterpaste", html);
  13603. }
  13604. }
  13605. me.addListener('pasteTransfer', function (cmd, plainType) {
  13606. if (address && txtContent && htmlContent && txtContent != htmlContent) {
  13607. var range = me.selection.getRange();
  13608. range.moveToAddress(address, true);
  13609. if (!range.collapsed) {
  13610. while (!domUtils.isBody(range.startContainer)
  13611. ) {
  13612. var start = range.startContainer;
  13613. if(start.nodeType == 1){
  13614. start = start.childNodes[range.startOffset];
  13615. if(!start){
  13616. range.setStartBefore(range.startContainer);
  13617. continue;
  13618. }
  13619. var pre = start.previousSibling;
  13620. if(pre && pre.nodeType == 3 && new RegExp('^[\n\r\t '+domUtils.fillChar+']*$').test(pre.nodeValue)){
  13621. range.setStartBefore(pre)
  13622. }
  13623. }
  13624. if(range.startOffset == 0){
  13625. range.setStartBefore(range.startContainer);
  13626. }else{
  13627. break;
  13628. }
  13629. }
  13630. while (!domUtils.isBody(range.endContainer)
  13631. ) {
  13632. var end = range.endContainer;
  13633. if(end.nodeType == 1){
  13634. end = end.childNodes[range.endOffset];
  13635. if(!end){
  13636. range.setEndAfter(range.endContainer);
  13637. continue;
  13638. }
  13639. var next = end.nextSibling;
  13640. if(next && next.nodeType == 3 && new RegExp('^[\n\r\t'+domUtils.fillChar+']*$').test(next.nodeValue)){
  13641. range.setEndAfter(next)
  13642. }
  13643. }
  13644. if(range.endOffset == range.endContainer[range.endContainer.nodeType == 3 ? 'nodeValue' : 'childNodes'].length){
  13645. range.setEndAfter(range.endContainer);
  13646. }else{
  13647. break;
  13648. }
  13649. }
  13650. }
  13651. range.deleteContents();
  13652. range.select(true);
  13653. me.__hasEnterExecCommand = true;
  13654. var html = htmlContent;
  13655. if (plainType === 2 ) {
  13656. html = getPureHtml(html);
  13657. } else if (plainType) {
  13658. html = txtContent;
  13659. }
  13660. me.execCommand('inserthtml', html, true);
  13661. me.__hasEnterExecCommand = false;
  13662. var rng = me.selection.getRange();
  13663. while (!domUtils.isBody(rng.startContainer) && !rng.startOffset &&
  13664. rng.startContainer[rng.startContainer.nodeType == 3 ? 'nodeValue' : 'childNodes'].length
  13665. ) {
  13666. rng.setStartBefore(rng.startContainer);
  13667. }
  13668. var tmpAddress = rng.createAddress(true);
  13669. address.endAddress = tmpAddress.startAddress;
  13670. }
  13671. });
  13672. me.addListener('ready', function () {
  13673. domUtils.on(me.body, 'cut', function () {
  13674. var range = me.selection.getRange();
  13675. if (!range.collapsed && me.undoManger) {
  13676. me.undoManger.save();
  13677. }
  13678. });
  13679. //ie下beforepaste在点击右键时也会触发,所以用监控键盘才处理
  13680. domUtils.on(me.body, browser.ie || browser.opera ? 'keydown' : 'paste', function (e) {
  13681. if ((browser.ie || browser.opera) && ((!e.ctrlKey && !e.metaKey) || e.keyCode != '86')) {
  13682. return;
  13683. }
  13684. getClipboardData.call(me, function (div) {
  13685. filter(div);
  13686. });
  13687. });
  13688. });
  13689. me.commands['paste'] = {
  13690. execCommand: function (cmd) {
  13691. if (browser.ie) {
  13692. getClipboardData.call(me, function (div) {
  13693. filter(div);
  13694. });
  13695. me.document.execCommand('paste');
  13696. } else {
  13697. alert(me.getLang('pastemsg'));
  13698. }
  13699. }
  13700. }
  13701. };
  13702. // plugins/puretxtpaste.js
  13703. /**
  13704. * 纯文本粘贴插件
  13705. * @file
  13706. * @since 1.2.6.1
  13707. */
  13708. UE.plugins['pasteplain'] = function(){
  13709. var me = this;
  13710. me.setOpt({
  13711. 'pasteplain':false,
  13712. 'filterTxtRules' : function(){
  13713. function transP(node){
  13714. node.tagName = 'p';
  13715. node.setStyle();
  13716. }
  13717. function removeNode(node){
  13718. node.parentNode.removeChild(node,true)
  13719. }
  13720. return {
  13721. //直接删除及其字节点内容
  13722. '-' : 'script style object iframe embed input select',
  13723. 'p': {$:{}},
  13724. 'br':{$:{}},
  13725. div: function (node) {
  13726. var tmpNode, p = UE.uNode.createElement('p');
  13727. while (tmpNode = node.firstChild()) {
  13728. if (tmpNode.type == 'text' || !UE.dom.dtd.$block[tmpNode.tagName]) {
  13729. p.appendChild(tmpNode);
  13730. } else {
  13731. if (p.firstChild()) {
  13732. node.parentNode.insertBefore(p, node);
  13733. p = UE.uNode.createElement('p');
  13734. } else {
  13735. node.parentNode.insertBefore(tmpNode, node);
  13736. }
  13737. }
  13738. }
  13739. if (p.firstChild()) {
  13740. node.parentNode.insertBefore(p, node);
  13741. }
  13742. node.parentNode.removeChild(node);
  13743. },
  13744. ol: removeNode,
  13745. ul: removeNode,
  13746. dl:removeNode,
  13747. dt:removeNode,
  13748. dd:removeNode,
  13749. 'li':removeNode,
  13750. 'caption':transP,
  13751. 'th':transP,
  13752. 'tr':transP,
  13753. 'h1':transP,'h2':transP,'h3':transP,'h4':transP,'h5':transP,'h6':transP,
  13754. 'td':function(node){
  13755. //没有内容的td直接删掉
  13756. var txt = !!node.innerText();
  13757. if(txt){
  13758. node.parentNode.insertAfter(UE.uNode.createText(' &nbsp; &nbsp;'),node);
  13759. }
  13760. node.parentNode.removeChild(node,node.innerText())
  13761. }
  13762. }
  13763. }()
  13764. });
  13765. //暂时这里支持一下老版本的属性
  13766. var pasteplain = me.options.pasteplain;
  13767. /**
  13768. * 启用或取消纯文本粘贴模式
  13769. * @command pasteplain
  13770. * @method execCommand
  13771. * @param { String } cmd 命令字符串
  13772. * @example
  13773. * ```javascript
  13774. * editor.queryCommandState( 'pasteplain' );
  13775. * ```
  13776. */
  13777. /**
  13778. * 查询当前是否处于纯文本粘贴模式
  13779. * @command pasteplain
  13780. * @method queryCommandState
  13781. * @param { String } cmd 命令字符串
  13782. * @return { int } 如果处于纯文本模式,返回1,否则,返回0
  13783. * @example
  13784. * ```javascript
  13785. * editor.queryCommandState( 'pasteplain' );
  13786. * ```
  13787. */
  13788. me.commands['pasteplain'] = {
  13789. queryCommandState: function (){
  13790. return pasteplain ? 1 : 0;
  13791. },
  13792. execCommand: function (){
  13793. pasteplain = !pasteplain|0;
  13794. },
  13795. notNeedUndo : 1
  13796. };
  13797. };
  13798. // plugins/list.js
  13799. /**
  13800. * 有序列表,无序列表插件
  13801. * @file
  13802. * @since 1.2.6.1
  13803. */
  13804. UE.plugins['list'] = function () {
  13805. var me = this,
  13806. notExchange = {
  13807. 'TD':1,
  13808. 'PRE':1,
  13809. 'BLOCKQUOTE':1
  13810. };
  13811. var customStyle = {
  13812. 'cn' : 'cn-1-',
  13813. 'cn1' : 'cn-2-',
  13814. 'cn2' : 'cn-3-',
  13815. 'num': 'num-1-',
  13816. 'num1' : 'num-2-',
  13817. 'num2' : 'num-3-',
  13818. 'dash' : 'dash',
  13819. 'dot':'dot'
  13820. };
  13821. me.setOpt( {
  13822. 'autoTransWordToList':false,
  13823. 'insertorderedlist':{
  13824. 'num':'',
  13825. 'num1':'',
  13826. 'num2':'',
  13827. 'cn':'',
  13828. 'cn1':'',
  13829. 'cn2':'',
  13830. 'decimal':'',
  13831. 'lower-alpha':'',
  13832. 'lower-roman':'',
  13833. 'upper-alpha':'',
  13834. 'upper-roman':''
  13835. },
  13836. 'insertunorderedlist':{
  13837. 'circle':'',
  13838. 'disc':'',
  13839. 'square':'',
  13840. 'dash' : '',
  13841. 'dot':''
  13842. },
  13843. listDefaultPaddingLeft : '30',
  13844. listiconpath : 'http://bs.baidu.com/listicon/',
  13845. maxListLevel : -1,//-1不限制
  13846. disablePInList:false
  13847. } );
  13848. function listToArray(list){
  13849. var arr = [];
  13850. for(var p in list){
  13851. arr.push(p)
  13852. }
  13853. return arr;
  13854. }
  13855. var listStyle = {
  13856. 'OL':listToArray(me.options.insertorderedlist),
  13857. 'UL':listToArray(me.options.insertunorderedlist)
  13858. };
  13859. var liiconpath = me.options.listiconpath;
  13860. //根据用户配置,调整customStyle
  13861. for(var s in customStyle){
  13862. if(!me.options.insertorderedlist.hasOwnProperty(s) && !me.options.insertunorderedlist.hasOwnProperty(s)){
  13863. delete customStyle[s];
  13864. }
  13865. }
  13866. me.ready(function () {
  13867. var customCss = [];
  13868. for(var p in customStyle){
  13869. if(p == 'dash' || p == 'dot'){
  13870. customCss.push('li.list-' + customStyle[p] + '{background-image:url(' + liiconpath +customStyle[p]+'.gif)}');
  13871. customCss.push('ul.custom_'+p+'{list-style:none;}ul.custom_'+p+' li{background-position:0 3px;background-repeat:no-repeat}');
  13872. }else{
  13873. for(var i= 0;i<99;i++){
  13874. customCss.push('li.list-' + customStyle[p] + i + '{background-image:url(' + liiconpath + 'list-'+customStyle[p] + i + '.gif)}')
  13875. }
  13876. customCss.push('ol.custom_'+p+'{list-style:none;}ol.custom_'+p+' li{background-position:0 3px;background-repeat:no-repeat}');
  13877. }
  13878. switch(p){
  13879. case 'cn':
  13880. customCss.push('li.list-'+p+'-paddingleft-1{padding-left:25px}');
  13881. customCss.push('li.list-'+p+'-paddingleft-2{padding-left:40px}');
  13882. customCss.push('li.list-'+p+'-paddingleft-3{padding-left:55px}');
  13883. break;
  13884. case 'cn1':
  13885. customCss.push('li.list-'+p+'-paddingleft-1{padding-left:30px}');
  13886. customCss.push('li.list-'+p+'-paddingleft-2{padding-left:40px}');
  13887. customCss.push('li.list-'+p+'-paddingleft-3{padding-left:55px}');
  13888. break;
  13889. case 'cn2':
  13890. customCss.push('li.list-'+p+'-paddingleft-1{padding-left:40px}');
  13891. customCss.push('li.list-'+p+'-paddingleft-2{padding-left:55px}');
  13892. customCss.push('li.list-'+p+'-paddingleft-3{padding-left:68px}');
  13893. break;
  13894. case 'num':
  13895. case 'num1':
  13896. customCss.push('li.list-'+p+'-paddingleft-1{padding-left:25px}');
  13897. break;
  13898. case 'num2':
  13899. customCss.push('li.list-'+p+'-paddingleft-1{padding-left:35px}');
  13900. customCss.push('li.list-'+p+'-paddingleft-2{padding-left:40px}');
  13901. break;
  13902. case 'dash':
  13903. customCss.push('li.list-'+p+'-paddingleft{padding-left:35px}');
  13904. break;
  13905. case 'dot':
  13906. customCss.push('li.list-'+p+'-paddingleft{padding-left:20px}');
  13907. }
  13908. }
  13909. customCss.push('.list-paddingleft-1{padding-left:0}');
  13910. customCss.push('.list-paddingleft-2{padding-left:'+me.options.listDefaultPaddingLeft+'px}');
  13911. customCss.push('.list-paddingleft-3{padding-left:'+me.options.listDefaultPaddingLeft*2+'px}');
  13912. //如果不给宽度会在自定应样式里出现滚动条
  13913. utils.cssRule('list', 'ol,ul{margin:0;pading:0;'+(browser.ie ? '' : 'width:95%')+'}li{clear:both;}'+customCss.join('\n'), me.document);
  13914. });
  13915. //单独处理剪切的问题
  13916. me.ready(function(){
  13917. domUtils.on(me.body,'cut',function(){
  13918. setTimeout(function(){
  13919. var rng = me.selection.getRange(),li;
  13920. //trace:3416
  13921. if(!rng.collapsed){
  13922. if(li = domUtils.findParentByTagName(rng.startContainer,'li',true)){
  13923. if(!li.nextSibling && domUtils.isEmptyBlock(li)){
  13924. var pn = li.parentNode,node;
  13925. if(node = pn.previousSibling){
  13926. domUtils.remove(pn);
  13927. rng.setStartAtLast(node).collapse(true);
  13928. rng.select(true);
  13929. }else if(node = pn.nextSibling){
  13930. domUtils.remove(pn);
  13931. rng.setStartAtFirst(node).collapse(true);
  13932. rng.select(true);
  13933. }else{
  13934. var tmpNode = me.document.createElement('p');
  13935. domUtils.fillNode(me.document,tmpNode);
  13936. pn.parentNode.insertBefore(tmpNode,pn);
  13937. domUtils.remove(pn);
  13938. rng.setStart(tmpNode,0).collapse(true);
  13939. rng.select(true);
  13940. }
  13941. }
  13942. }
  13943. }
  13944. })
  13945. })
  13946. });
  13947. function getStyle(node){
  13948. var cls = node.className;
  13949. if(domUtils.hasClass(node,/custom_/)){
  13950. return cls.match(/custom_(\w+)/)[1]
  13951. }
  13952. return domUtils.getStyle(node, 'list-style-type')
  13953. }
  13954. me.addListener('beforepaste',function(type,html){
  13955. var me = this,
  13956. rng = me.selection.getRange(),li;
  13957. var root = UE.htmlparser(html.html,true);
  13958. if(li = domUtils.findParentByTagName(rng.startContainer,'li',true)){
  13959. var list = li.parentNode,tagName = list.tagName == 'OL' ? 'ul':'ol';
  13960. utils.each(root.getNodesByTagName(tagName),function(n){
  13961. n.tagName = list.tagName;
  13962. n.setAttr();
  13963. if(n.parentNode === root){
  13964. type = getStyle(list) || (list.tagName == 'OL' ? 'decimal' : 'disc')
  13965. }else{
  13966. var className = n.parentNode.getAttr('class');
  13967. if(className && /custom_/.test(className)){
  13968. type = className.match(/custom_(\w+)/)[1]
  13969. }else{
  13970. type = n.parentNode.getStyle('list-style-type');
  13971. }
  13972. if(!type){
  13973. type = list.tagName == 'OL' ? 'decimal' : 'disc';
  13974. }
  13975. }
  13976. var index = utils.indexOf(listStyle[list.tagName], type);
  13977. if(n.parentNode !== root)
  13978. index = index + 1 == listStyle[list.tagName].length ? 0 : index + 1;
  13979. var currentStyle = listStyle[list.tagName][index];
  13980. if(customStyle[currentStyle]){
  13981. n.setAttr('class', 'custom_' + currentStyle)
  13982. }else{
  13983. n.setStyle('list-style-type',currentStyle)
  13984. }
  13985. })
  13986. }
  13987. html.html = root.toHtml();
  13988. });
  13989. //导出时,去掉p标签
  13990. me.getOpt('disablePInList') === true && me.addOutputRule(function(root){
  13991. utils.each(root.getNodesByTagName('li'),function(li){
  13992. var newChildrens = [],index=0;
  13993. utils.each(li.children,function(n){
  13994. if(n.tagName == 'p'){
  13995. var tmpNode;
  13996. while(tmpNode = n.children.pop()) {
  13997. newChildrens.splice(index,0,tmpNode);
  13998. tmpNode.parentNode = li;
  13999. lastNode = tmpNode;
  14000. }
  14001. tmpNode = newChildrens[newChildrens.length-1];
  14002. if(!tmpNode || tmpNode.type != 'element' || tmpNode.tagName != 'br'){
  14003. var br = UE.uNode.createElement('br');
  14004. br.parentNode = li;
  14005. newChildrens.push(br);
  14006. }
  14007. index = newChildrens.length;
  14008. }
  14009. });
  14010. if(newChildrens.length){
  14011. li.children = newChildrens;
  14012. }
  14013. });
  14014. });
  14015. //进入编辑器的li要套p标签
  14016. me.addInputRule(function(root){
  14017. utils.each(root.getNodesByTagName('li'),function(li){
  14018. var tmpP = UE.uNode.createElement('p');
  14019. for(var i= 0,ci;ci=li.children[i];){
  14020. if(ci.type == 'text' || dtd.p[ci.tagName]){
  14021. tmpP.appendChild(ci);
  14022. }else{
  14023. if(tmpP.firstChild()){
  14024. li.insertBefore(tmpP,ci);
  14025. tmpP = UE.uNode.createElement('p');
  14026. i = i + 2;
  14027. }else{
  14028. i++;
  14029. }
  14030. }
  14031. }
  14032. if(tmpP.firstChild() && !tmpP.parentNode || !li.firstChild()){
  14033. li.appendChild(tmpP);
  14034. }
  14035. //trace:3357
  14036. //p不能为空
  14037. if (!tmpP.firstChild()) {
  14038. tmpP.innerHTML(browser.ie ? '&nbsp;' : '<br/>')
  14039. }
  14040. //去掉末尾的空白
  14041. var p = li.firstChild();
  14042. var lastChild = p.lastChild();
  14043. if(lastChild && lastChild.type == 'text' && /^\s*$/.test(lastChild.data)){
  14044. p.removeChild(lastChild)
  14045. }
  14046. });
  14047. if(me.options.autoTransWordToList){
  14048. var orderlisttype = {
  14049. 'num1':/^\d+\)/,
  14050. 'decimal':/^\d+\./,
  14051. 'lower-alpha':/^[a-z]+\)/,
  14052. 'upper-alpha':/^[A-Z]+\./,
  14053. 'cn':/^[\u4E00\u4E8C\u4E09\u56DB\u516d\u4e94\u4e03\u516b\u4e5d]+[\u3001]/,
  14054. 'cn2':/^\([\u4E00\u4E8C\u4E09\u56DB\u516d\u4e94\u4e03\u516b\u4e5d]+\)/
  14055. },
  14056. unorderlisttype = {
  14057. 'square':'n'
  14058. };
  14059. function checkListType(content,container){
  14060. var span = container.firstChild();
  14061. if(span && span.type == 'element' && span.tagName == 'span' && /Wingdings|Symbol/.test(span.getStyle('font-family'))){
  14062. for(var p in unorderlisttype){
  14063. if(unorderlisttype[p] == span.data){
  14064. return p
  14065. }
  14066. }
  14067. return 'disc'
  14068. }
  14069. for(var p in orderlisttype){
  14070. if(orderlisttype[p].test(content)){
  14071. return p;
  14072. }
  14073. }
  14074. }
  14075. utils.each(root.getNodesByTagName('p'),function(node){
  14076. if(node.getAttr('class') != 'MsoListParagraph'){
  14077. return
  14078. }
  14079. //word粘贴过来的会带有margin要去掉,但这样也可能会误命中一些央视
  14080. node.setStyle('margin','');
  14081. node.setStyle('margin-left','');
  14082. node.setAttr('class','');
  14083. function appendLi(list,p,type){
  14084. if(list.tagName == 'ol'){
  14085. if(browser.ie){
  14086. var first = p.firstChild();
  14087. if(first.type =='element' && first.tagName == 'span' && orderlisttype[type].test(first.innerText())){
  14088. p.removeChild(first);
  14089. }
  14090. }else{
  14091. p.innerHTML(p.innerHTML().replace(orderlisttype[type],''));
  14092. }
  14093. }else{
  14094. p.removeChild(p.firstChild())
  14095. }
  14096. var li = UE.uNode.createElement('li');
  14097. li.appendChild(p);
  14098. list.appendChild(li);
  14099. }
  14100. var tmp = node,type,cacheNode = node;
  14101. if(node.parentNode.tagName != 'li' && (type = checkListType(node.innerText(),node))){
  14102. var list = UE.uNode.createElement(me.options.insertorderedlist.hasOwnProperty(type) ? 'ol' : 'ul');
  14103. if(customStyle[type]){
  14104. list.setAttr('class','custom_'+type)
  14105. }else{
  14106. list.setStyle('list-style-type',type)
  14107. }
  14108. while(node && node.parentNode.tagName != 'li' && checkListType(node.innerText(),node)){
  14109. tmp = node.nextSibling();
  14110. if(!tmp){
  14111. node.parentNode.insertBefore(list,node)
  14112. }
  14113. appendLi(list,node,type);
  14114. node = tmp;
  14115. }
  14116. if(!list.parentNode && node && node.parentNode){
  14117. node.parentNode.insertBefore(list,node)
  14118. }
  14119. }
  14120. var span = cacheNode.firstChild();
  14121. if(span && span.type == 'element' && span.tagName == 'span' && /^\s*(&nbsp;)+\s*$/.test(span.innerText())){
  14122. span.parentNode.removeChild(span)
  14123. }
  14124. })
  14125. }
  14126. });
  14127. //调整索引标签
  14128. me.addListener('contentchange',function(){
  14129. adjustListStyle(me.document)
  14130. });
  14131. function adjustListStyle(doc,ignore){
  14132. utils.each(domUtils.getElementsByTagName(doc,'ol ul'),function(node){
  14133. if(!domUtils.inDoc(node,doc))
  14134. return;
  14135. var parent = node.parentNode;
  14136. if(parent.tagName == node.tagName){
  14137. var nodeStyleType = getStyle(node) || (node.tagName == 'OL' ? 'decimal' : 'disc'),
  14138. parentStyleType = getStyle(parent) || (parent.tagName == 'OL' ? 'decimal' : 'disc');
  14139. if(nodeStyleType == parentStyleType){
  14140. var styleIndex = utils.indexOf(listStyle[node.tagName], nodeStyleType);
  14141. styleIndex = styleIndex + 1 == listStyle[node.tagName].length ? 0 : styleIndex + 1;
  14142. setListStyle(node,listStyle[node.tagName][styleIndex])
  14143. }
  14144. }
  14145. var index = 0,type = 2;
  14146. if( domUtils.hasClass(node,/custom_/)){
  14147. if(!(/[ou]l/i.test(parent.tagName) && domUtils.hasClass(parent,/custom_/))){
  14148. type = 1;
  14149. }
  14150. }else{
  14151. if(/[ou]l/i.test(parent.tagName) && domUtils.hasClass(parent,/custom_/)){
  14152. type = 3;
  14153. }
  14154. }
  14155. var style = domUtils.getStyle(node, 'list-style-type');
  14156. style && (node.style.cssText = 'list-style-type:' + style);
  14157. node.className = utils.trim(node.className.replace(/list-paddingleft-\w+/,'')) + ' list-paddingleft-' + type;
  14158. utils.each(domUtils.getElementsByTagName(node,'li'),function(li){
  14159. li.style.cssText && (li.style.cssText = '');
  14160. if(!li.firstChild){
  14161. domUtils.remove(li);
  14162. return;
  14163. }
  14164. if(li.parentNode !== node){
  14165. return;
  14166. }
  14167. index++;
  14168. if(domUtils.hasClass(node,/custom_/) ){
  14169. var paddingLeft = 1,currentStyle = getStyle(node);
  14170. if(node.tagName == 'OL'){
  14171. if(currentStyle){
  14172. switch(currentStyle){
  14173. case 'cn' :
  14174. case 'cn1':
  14175. case 'cn2':
  14176. if(index > 10 && (index % 10 == 0 || index > 10 && index < 20)){
  14177. paddingLeft = 2
  14178. }else if(index > 20){
  14179. paddingLeft = 3
  14180. }
  14181. break;
  14182. case 'num2' :
  14183. if(index > 9){
  14184. paddingLeft = 2
  14185. }
  14186. }
  14187. }
  14188. li.className = 'list-'+customStyle[currentStyle]+ index + ' ' + 'list-'+currentStyle+'-paddingleft-' + paddingLeft;
  14189. }else{
  14190. li.className = 'list-'+customStyle[currentStyle] + ' ' + 'list-'+currentStyle+'-paddingleft';
  14191. }
  14192. }else{
  14193. li.className = li.className.replace(/list-[\w\-]+/gi,'');
  14194. }
  14195. var className = li.getAttribute('class');
  14196. if(className !== null && !className.replace(/\s/g,'')){
  14197. domUtils.removeAttributes(li,'class')
  14198. }
  14199. });
  14200. !ignore && adjustList(node,node.tagName.toLowerCase(),getStyle(node)||domUtils.getStyle(node, 'list-style-type'),true);
  14201. })
  14202. }
  14203. function adjustList(list, tag, style,ignoreEmpty) {
  14204. var nextList = list.nextSibling;
  14205. if (nextList && nextList.nodeType == 1 && nextList.tagName.toLowerCase() == tag && (getStyle(nextList) || domUtils.getStyle(nextList, 'list-style-type') || (tag == 'ol' ? 'decimal' : 'disc')) == style) {
  14206. domUtils.moveChild(nextList, list);
  14207. if (nextList.childNodes.length == 0) {
  14208. domUtils.remove(nextList);
  14209. }
  14210. }
  14211. if(nextList && domUtils.isFillChar(nextList)){
  14212. domUtils.remove(nextList);
  14213. }
  14214. var preList = list.previousSibling;
  14215. if (preList && preList.nodeType == 1 && preList.tagName.toLowerCase() == tag && (getStyle(preList) || domUtils.getStyle(preList, 'list-style-type') || (tag == 'ol' ? 'decimal' : 'disc')) == style) {
  14216. domUtils.moveChild(list, preList);
  14217. }
  14218. if(preList && domUtils.isFillChar(preList)){
  14219. domUtils.remove(preList);
  14220. }
  14221. !ignoreEmpty && domUtils.isEmptyBlock(list) && domUtils.remove(list);
  14222. if(getStyle(list)){
  14223. adjustListStyle(list.ownerDocument,true)
  14224. }
  14225. }
  14226. function setListStyle(list,style){
  14227. if(customStyle[style]){
  14228. list.className = 'custom_' + style;
  14229. }
  14230. try{
  14231. domUtils.setStyle(list, 'list-style-type', style);
  14232. }catch(e){}
  14233. }
  14234. function clearEmptySibling(node) {
  14235. var tmpNode = node.previousSibling;
  14236. if (tmpNode && domUtils.isEmptyBlock(tmpNode)) {
  14237. domUtils.remove(tmpNode);
  14238. }
  14239. tmpNode = node.nextSibling;
  14240. if (tmpNode && domUtils.isEmptyBlock(tmpNode)) {
  14241. domUtils.remove(tmpNode);
  14242. }
  14243. }
  14244. me.addListener('keydown', function (type, evt) {
  14245. function preventAndSave() {
  14246. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  14247. me.fireEvent('contentchange');
  14248. me.undoManger && me.undoManger.save();
  14249. }
  14250. function findList(node,filterFn){
  14251. while(node && !domUtils.isBody(node)){
  14252. if(filterFn(node)){
  14253. return null
  14254. }
  14255. if(node.nodeType == 1 && /[ou]l/i.test(node.tagName)){
  14256. return node;
  14257. }
  14258. node = node.parentNode;
  14259. }
  14260. return null;
  14261. }
  14262. var keyCode = evt.keyCode || evt.which;
  14263. if (keyCode == 13 && !evt.shiftKey) {//回车
  14264. var rng = me.selection.getRange(),
  14265. parent = domUtils.findParent(rng.startContainer,function(node){return domUtils.isBlockElm(node)},true),
  14266. li = domUtils.findParentByTagName(rng.startContainer,'li',true);
  14267. if(parent && parent.tagName != 'PRE' && !li){
  14268. var html = parent.innerHTML.replace(new RegExp(domUtils.fillChar, 'g'),'');
  14269. if(/^\s*1\s*\.[^\d]/.test(html)){
  14270. parent.innerHTML = html.replace(/^\s*1\s*\./,'');
  14271. rng.setStartAtLast(parent).collapse(true).select();
  14272. me.__hasEnterExecCommand = true;
  14273. me.execCommand('insertorderedlist');
  14274. me.__hasEnterExecCommand = false;
  14275. }
  14276. }
  14277. var range = me.selection.getRange(),
  14278. start = findList(range.startContainer,function (node) {
  14279. return node.tagName == 'TABLE';
  14280. }),
  14281. end = range.collapsed ? start : findList(range.endContainer,function (node) {
  14282. return node.tagName == 'TABLE';
  14283. });
  14284. if (start && end && start === end) {
  14285. if (!range.collapsed) {
  14286. start = domUtils.findParentByTagName(range.startContainer, 'li', true);
  14287. end = domUtils.findParentByTagName(range.endContainer, 'li', true);
  14288. if (start && end && start === end) {
  14289. range.deleteContents();
  14290. li = domUtils.findParentByTagName(range.startContainer, 'li', true);
  14291. if (li && domUtils.isEmptyBlock(li)) {
  14292. pre = li.previousSibling;
  14293. next = li.nextSibling;
  14294. p = me.document.createElement('p');
  14295. domUtils.fillNode(me.document, p);
  14296. parentList = li.parentNode;
  14297. if (pre && next) {
  14298. range.setStart(next, 0).collapse(true).select(true);
  14299. domUtils.remove(li);
  14300. } else {
  14301. if (!pre && !next || !pre) {
  14302. parentList.parentNode.insertBefore(p, parentList);
  14303. } else {
  14304. li.parentNode.parentNode.insertBefore(p, parentList.nextSibling);
  14305. }
  14306. domUtils.remove(li);
  14307. if (!parentList.firstChild) {
  14308. domUtils.remove(parentList);
  14309. }
  14310. range.setStart(p, 0).setCursor();
  14311. }
  14312. preventAndSave();
  14313. return;
  14314. }
  14315. } else {
  14316. var tmpRange = range.cloneRange(),
  14317. bk = tmpRange.collapse(false).createBookmark();
  14318. range.deleteContents();
  14319. tmpRange.moveToBookmark(bk);
  14320. var li = domUtils.findParentByTagName(tmpRange.startContainer, 'li', true);
  14321. clearEmptySibling(li);
  14322. tmpRange.select();
  14323. preventAndSave();
  14324. return;
  14325. }
  14326. }
  14327. li = domUtils.findParentByTagName(range.startContainer, 'li', true);
  14328. if (li) {
  14329. if (domUtils.isEmptyBlock(li)) {
  14330. bk = range.createBookmark();
  14331. var parentList = li.parentNode;
  14332. if (li !== parentList.lastChild) {
  14333. domUtils.breakParent(li, parentList);
  14334. clearEmptySibling(li);
  14335. } else {
  14336. parentList.parentNode.insertBefore(li, parentList.nextSibling);
  14337. if (domUtils.isEmptyNode(parentList)) {
  14338. domUtils.remove(parentList);
  14339. }
  14340. }
  14341. //嵌套不处理
  14342. if (!dtd.$list[li.parentNode.tagName]) {
  14343. if (!domUtils.isBlockElm(li.firstChild)) {
  14344. p = me.document.createElement('p');
  14345. li.parentNode.insertBefore(p, li);
  14346. while (li.firstChild) {
  14347. p.appendChild(li.firstChild);
  14348. }
  14349. domUtils.remove(li);
  14350. } else {
  14351. domUtils.remove(li, true);
  14352. }
  14353. }
  14354. range.moveToBookmark(bk).select();
  14355. } else {
  14356. var first = li.firstChild;
  14357. if (!first || !domUtils.isBlockElm(first)) {
  14358. var p = me.document.createElement('p');
  14359. !li.firstChild && domUtils.fillNode(me.document, p);
  14360. while (li.firstChild) {
  14361. p.appendChild(li.firstChild);
  14362. }
  14363. li.appendChild(p);
  14364. first = p;
  14365. }
  14366. var span = me.document.createElement('span');
  14367. range.insertNode(span);
  14368. domUtils.breakParent(span, li);
  14369. var nextLi = span.nextSibling;
  14370. first = nextLi.firstChild;
  14371. if (!first) {
  14372. p = me.document.createElement('p');
  14373. domUtils.fillNode(me.document, p);
  14374. nextLi.appendChild(p);
  14375. first = p;
  14376. }
  14377. if (domUtils.isEmptyNode(first)) {
  14378. first.innerHTML = '';
  14379. domUtils.fillNode(me.document, first);
  14380. }
  14381. range.setStart(first, 0).collapse(true).shrinkBoundary().select();
  14382. domUtils.remove(span);
  14383. var pre = nextLi.previousSibling;
  14384. if (pre && domUtils.isEmptyBlock(pre)) {
  14385. pre.innerHTML = '<p></p>';
  14386. domUtils.fillNode(me.document, pre.firstChild);
  14387. }
  14388. }
  14389. // }
  14390. preventAndSave();
  14391. }
  14392. }
  14393. }
  14394. if (keyCode == 8) {
  14395. //修中ie中li下的问题
  14396. range = me.selection.getRange();
  14397. if (range.collapsed && domUtils.isStartInblock(range)) {
  14398. tmpRange = range.cloneRange().trimBoundary();
  14399. li = domUtils.findParentByTagName(range.startContainer, 'li', true);
  14400. //要在li的最左边,才能处理
  14401. if (li && domUtils.isStartInblock(tmpRange)) {
  14402. start = domUtils.findParentByTagName(range.startContainer, 'p', true);
  14403. if (start && start !== li.firstChild) {
  14404. var parentList = domUtils.findParentByTagName(start,['ol','ul']);
  14405. domUtils.breakParent(start,parentList);
  14406. clearEmptySibling(start);
  14407. me.fireEvent('contentchange');
  14408. range.setStart(start,0).setCursor(false,true);
  14409. me.fireEvent('saveScene');
  14410. domUtils.preventDefault(evt);
  14411. return;
  14412. }
  14413. if (li && (pre = li.previousSibling)) {
  14414. if (keyCode == 46 && li.childNodes.length) {
  14415. return;
  14416. }
  14417. //有可能上边的兄弟节点是个2级菜单,要追加到2级菜单的最后的li
  14418. if (dtd.$list[pre.tagName]) {
  14419. pre = pre.lastChild;
  14420. }
  14421. me.undoManger && me.undoManger.save();
  14422. first = li.firstChild;
  14423. if (domUtils.isBlockElm(first)) {
  14424. if (domUtils.isEmptyNode(first)) {
  14425. // range.setEnd(pre, pre.childNodes.length).shrinkBoundary().collapse().select(true);
  14426. pre.appendChild(first);
  14427. range.setStart(first, 0).setCursor(false, true);
  14428. //first不是唯一的节点
  14429. while (li.firstChild) {
  14430. pre.appendChild(li.firstChild);
  14431. }
  14432. } else {
  14433. span = me.document.createElement('span');
  14434. range.insertNode(span);
  14435. //判断pre是否是空的节点,如果是<p><br/></p>类型的空节点,干掉p标签防止它占位
  14436. if (domUtils.isEmptyBlock(pre)) {
  14437. pre.innerHTML = '';
  14438. }
  14439. domUtils.moveChild(li, pre);
  14440. range.setStartBefore(span).collapse(true).select(true);
  14441. domUtils.remove(span);
  14442. }
  14443. } else {
  14444. if (domUtils.isEmptyNode(li)) {
  14445. var p = me.document.createElement('p');
  14446. pre.appendChild(p);
  14447. range.setStart(p, 0).setCursor();
  14448. // range.setEnd(pre, pre.childNodes.length).shrinkBoundary().collapse().select(true);
  14449. } else {
  14450. range.setEnd(pre, pre.childNodes.length).collapse().select(true);
  14451. while (li.firstChild) {
  14452. pre.appendChild(li.firstChild);
  14453. }
  14454. }
  14455. }
  14456. domUtils.remove(li);
  14457. me.fireEvent('contentchange');
  14458. me.fireEvent('saveScene');
  14459. domUtils.preventDefault(evt);
  14460. return;
  14461. }
  14462. //trace:980
  14463. if (li && !li.previousSibling) {
  14464. var parentList = li.parentNode;
  14465. var bk = range.createBookmark();
  14466. if(domUtils.isTagNode(parentList.parentNode,'ol ul')){
  14467. parentList.parentNode.insertBefore(li,parentList);
  14468. if(domUtils.isEmptyNode(parentList)){
  14469. domUtils.remove(parentList)
  14470. }
  14471. }else{
  14472. while(li.firstChild){
  14473. parentList.parentNode.insertBefore(li.firstChild,parentList);
  14474. }
  14475. domUtils.remove(li);
  14476. if(domUtils.isEmptyNode(parentList)){
  14477. domUtils.remove(parentList)
  14478. }
  14479. }
  14480. range.moveToBookmark(bk).setCursor(false,true);
  14481. me.fireEvent('contentchange');
  14482. me.fireEvent('saveScene');
  14483. domUtils.preventDefault(evt);
  14484. return;
  14485. }
  14486. }
  14487. }
  14488. }
  14489. });
  14490. me.addListener('keyup',function(type, evt){
  14491. var keyCode = evt.keyCode || evt.which;
  14492. if (keyCode == 8) {
  14493. var rng = me.selection.getRange(),list;
  14494. if(list = domUtils.findParentByTagName(rng.startContainer,['ol', 'ul'],true)){
  14495. adjustList(list,list.tagName.toLowerCase(),getStyle(list)||domUtils.getComputedStyle(list,'list-style-type'),true)
  14496. }
  14497. }
  14498. });
  14499. //处理tab键
  14500. me.addListener('tabkeydown',function(){
  14501. var range = me.selection.getRange();
  14502. //控制级数
  14503. function checkLevel(li){
  14504. if(me.options.maxListLevel != -1){
  14505. var level = li.parentNode,levelNum = 0;
  14506. while(/[ou]l/i.test(level.tagName)){
  14507. levelNum++;
  14508. level = level.parentNode;
  14509. }
  14510. if(levelNum >= me.options.maxListLevel){
  14511. return true;
  14512. }
  14513. }
  14514. }
  14515. //只以开始为准
  14516. //todo 后续改进
  14517. var li = domUtils.findParentByTagName(range.startContainer, 'li', true);
  14518. if(li){
  14519. var bk;
  14520. if(range.collapsed){
  14521. if(checkLevel(li))
  14522. return true;
  14523. var parentLi = li.parentNode,
  14524. list = me.document.createElement(parentLi.tagName),
  14525. index = utils.indexOf(listStyle[list.tagName], getStyle(parentLi)||domUtils.getComputedStyle(parentLi, 'list-style-type'));
  14526. index = index + 1 == listStyle[list.tagName].length ? 0 : index + 1;
  14527. var currentStyle = listStyle[list.tagName][index];
  14528. setListStyle(list,currentStyle);
  14529. if(domUtils.isStartInblock(range)){
  14530. me.fireEvent('saveScene');
  14531. bk = range.createBookmark();
  14532. parentLi.insertBefore(list, li);
  14533. list.appendChild(li);
  14534. adjustList(list,list.tagName.toLowerCase(),currentStyle);
  14535. me.fireEvent('contentchange');
  14536. range.moveToBookmark(bk).select(true);
  14537. return true;
  14538. }
  14539. }else{
  14540. me.fireEvent('saveScene');
  14541. bk = range.createBookmark();
  14542. for(var i= 0,closeList,parents = domUtils.findParents(li),ci;ci=parents[i++];){
  14543. if(domUtils.isTagNode(ci,'ol ul')){
  14544. closeList = ci;
  14545. break;
  14546. }
  14547. }
  14548. var current = li;
  14549. if(bk.end){
  14550. while(current && !(domUtils.getPosition(current, bk.end) & domUtils.POSITION_FOLLOWING)){
  14551. if(checkLevel(current)){
  14552. current = domUtils.getNextDomNode(current,false,null,function(node){return node !== closeList});
  14553. continue;
  14554. }
  14555. var parentLi = current.parentNode,
  14556. list = me.document.createElement(parentLi.tagName),
  14557. index = utils.indexOf(listStyle[list.tagName], getStyle(parentLi)||domUtils.getComputedStyle(parentLi, 'list-style-type'));
  14558. var currentIndex = index + 1 == listStyle[list.tagName].length ? 0 : index + 1;
  14559. var currentStyle = listStyle[list.tagName][currentIndex];
  14560. setListStyle(list,currentStyle);
  14561. parentLi.insertBefore(list, current);
  14562. while(current && !(domUtils.getPosition(current, bk.end) & domUtils.POSITION_FOLLOWING)){
  14563. li = current.nextSibling;
  14564. list.appendChild(current);
  14565. if(!li || domUtils.isTagNode(li,'ol ul')){
  14566. if(li){
  14567. while(li = li.firstChild){
  14568. if(li.tagName == 'LI'){
  14569. break;
  14570. }
  14571. }
  14572. }else{
  14573. li = domUtils.getNextDomNode(current,false,null,function(node){return node !== closeList});
  14574. }
  14575. break;
  14576. }
  14577. current = li;
  14578. }
  14579. adjustList(list,list.tagName.toLowerCase(),currentStyle);
  14580. current = li;
  14581. }
  14582. }
  14583. me.fireEvent('contentchange');
  14584. range.moveToBookmark(bk).select();
  14585. return true;
  14586. }
  14587. }
  14588. });
  14589. function getLi(start){
  14590. while(start && !domUtils.isBody(start)){
  14591. if(start.nodeName == 'TABLE'){
  14592. return null;
  14593. }
  14594. if(start.nodeName == 'LI'){
  14595. return start
  14596. }
  14597. start = start.parentNode;
  14598. }
  14599. }
  14600. /**
  14601. * 有序列表,与“insertunorderedlist”命令互斥
  14602. * @command insertorderedlist
  14603. * @method execCommand
  14604. * @param { String } command 命令字符串
  14605. * @param { String } style 插入的有序列表类型,值为:decimal,lower-alpha,lower-roman,upper-alpha,upper-roman,cn,cn1,cn2,num,num1,num2
  14606. * @example
  14607. * ```javascript
  14608. * editor.execCommand( 'insertorderedlist','decimal');
  14609. * ```
  14610. */
  14611. /**
  14612. * 查询当前选区内容是否有序列表
  14613. * @command insertorderedlist
  14614. * @method queryCommandState
  14615. * @param { String } cmd 命令字符串
  14616. * @return { int } 如果当前选区是有序列表返回1,否则返回0
  14617. * @example
  14618. * ```javascript
  14619. * editor.queryCommandState( 'insertorderedlist' );
  14620. * ```
  14621. */
  14622. /**
  14623. * 查询当前选区内容是否有序列表
  14624. * @command insertorderedlist
  14625. * @method queryCommandValue
  14626. * @param { String } cmd 命令字符串
  14627. * @return { String } 返回当前有序列表的类型,值为null或decimal,lower-alpha,lower-roman,upper-alpha,upper-roman,cn,cn1,cn2,num,num1,num2
  14628. * @example
  14629. * ```javascript
  14630. * editor.queryCommandValue( 'insertorderedlist' );
  14631. * ```
  14632. */
  14633. /**
  14634. * 无序列表,与“insertorderedlist”命令互斥
  14635. * @command insertunorderedlist
  14636. * @method execCommand
  14637. * @param { String } command 命令字符串
  14638. * @param { String } style 插入的无序列表类型,值为:circle,disc,square,dash,dot
  14639. * @example
  14640. * ```javascript
  14641. * editor.execCommand( 'insertunorderedlist','circle');
  14642. * ```
  14643. */
  14644. /**
  14645. * 查询当前是否有word文档粘贴进来的图片
  14646. * @command insertunorderedlist
  14647. * @method insertunorderedlist
  14648. * @param { String } command 命令字符串
  14649. * @return { int } 如果当前选区是无序列表返回1,否则返回0
  14650. * @example
  14651. * ```javascript
  14652. * editor.queryCommandState( 'insertunorderedlist' );
  14653. * ```
  14654. */
  14655. /**
  14656. * 查询当前选区内容是否有序列表
  14657. * @command insertunorderedlist
  14658. * @method queryCommandValue
  14659. * @param { String } command 命令字符串
  14660. * @return { String } 返回当前无序列表的类型,值为null或circle,disc,square,dash,dot
  14661. * @example
  14662. * ```javascript
  14663. * editor.queryCommandValue( 'insertunorderedlist' );
  14664. * ```
  14665. */
  14666. me.commands['insertorderedlist'] =
  14667. me.commands['insertunorderedlist'] = {
  14668. execCommand:function (command, style) {
  14669. if (!style) {
  14670. style = command.toLowerCase() == 'insertorderedlist' ? 'decimal' : 'disc';
  14671. }
  14672. var me = this,
  14673. range = this.selection.getRange(),
  14674. filterFn = function (node) {
  14675. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' : !domUtils.isWhitespace(node);
  14676. },
  14677. tag = command.toLowerCase() == 'insertorderedlist' ? 'ol' : 'ul',
  14678. frag = me.document.createDocumentFragment();
  14679. //去掉是因为会出现选到末尾,导致adjustmentBoundary缩到ol/ul的位置
  14680. //range.shrinkBoundary();//.adjustmentBoundary();
  14681. range.adjustmentBoundary().shrinkBoundary();
  14682. var bko = range.createBookmark(true),
  14683. start = getLi(me.document.getElementById(bko.start)),
  14684. modifyStart = 0,
  14685. end = getLi(me.document.getElementById(bko.end)),
  14686. modifyEnd = 0,
  14687. startParent, endParent,
  14688. list, tmp;
  14689. if (start || end) {
  14690. start && (startParent = start.parentNode);
  14691. if (!bko.end) {
  14692. end = start;
  14693. }
  14694. end && (endParent = end.parentNode);
  14695. if (startParent === endParent) {
  14696. while (start !== end) {
  14697. tmp = start;
  14698. start = start.nextSibling;
  14699. if (!domUtils.isBlockElm(tmp.firstChild)) {
  14700. var p = me.document.createElement('p');
  14701. while (tmp.firstChild) {
  14702. p.appendChild(tmp.firstChild);
  14703. }
  14704. tmp.appendChild(p);
  14705. }
  14706. frag.appendChild(tmp);
  14707. }
  14708. tmp = me.document.createElement('span');
  14709. startParent.insertBefore(tmp, end);
  14710. if (!domUtils.isBlockElm(end.firstChild)) {
  14711. p = me.document.createElement('p');
  14712. while (end.firstChild) {
  14713. p.appendChild(end.firstChild);
  14714. }
  14715. end.appendChild(p);
  14716. }
  14717. frag.appendChild(end);
  14718. domUtils.breakParent(tmp, startParent);
  14719. if (domUtils.isEmptyNode(tmp.previousSibling)) {
  14720. domUtils.remove(tmp.previousSibling);
  14721. }
  14722. if (domUtils.isEmptyNode(tmp.nextSibling)) {
  14723. domUtils.remove(tmp.nextSibling)
  14724. }
  14725. var nodeStyle = getStyle(startParent) || domUtils.getComputedStyle(startParent, 'list-style-type') || (command.toLowerCase() == 'insertorderedlist' ? 'decimal' : 'disc');
  14726. if (startParent.tagName.toLowerCase() == tag && nodeStyle == style) {
  14727. for (var i = 0, ci, tmpFrag = me.document.createDocumentFragment(); ci = frag.firstChild;) {
  14728. if(domUtils.isTagNode(ci,'ol ul')){
  14729. // 删除时,子列表不处理
  14730. // utils.each(domUtils.getElementsByTagName(ci,'li'),function(li){
  14731. // while(li.firstChild){
  14732. // tmpFrag.appendChild(li.firstChild);
  14733. // }
  14734. //
  14735. // });
  14736. tmpFrag.appendChild(ci);
  14737. }else{
  14738. while (ci.firstChild) {
  14739. tmpFrag.appendChild(ci.firstChild);
  14740. domUtils.remove(ci);
  14741. }
  14742. }
  14743. }
  14744. tmp.parentNode.insertBefore(tmpFrag, tmp);
  14745. } else {
  14746. list = me.document.createElement(tag);
  14747. setListStyle(list,style);
  14748. list.appendChild(frag);
  14749. tmp.parentNode.insertBefore(list, tmp);
  14750. }
  14751. domUtils.remove(tmp);
  14752. list && adjustList(list, tag, style);
  14753. range.moveToBookmark(bko).select();
  14754. return;
  14755. }
  14756. //开始
  14757. if (start) {
  14758. while (start) {
  14759. tmp = start.nextSibling;
  14760. if (domUtils.isTagNode(start, 'ol ul')) {
  14761. frag.appendChild(start);
  14762. } else {
  14763. var tmpfrag = me.document.createDocumentFragment(),
  14764. hasBlock = 0;
  14765. while (start.firstChild) {
  14766. if (domUtils.isBlockElm(start.firstChild)) {
  14767. hasBlock = 1;
  14768. }
  14769. tmpfrag.appendChild(start.firstChild);
  14770. }
  14771. if (!hasBlock) {
  14772. var tmpP = me.document.createElement('p');
  14773. tmpP.appendChild(tmpfrag);
  14774. frag.appendChild(tmpP);
  14775. } else {
  14776. frag.appendChild(tmpfrag);
  14777. }
  14778. domUtils.remove(start);
  14779. }
  14780. start = tmp;
  14781. }
  14782. startParent.parentNode.insertBefore(frag, startParent.nextSibling);
  14783. if (domUtils.isEmptyNode(startParent)) {
  14784. range.setStartBefore(startParent);
  14785. domUtils.remove(startParent);
  14786. } else {
  14787. range.setStartAfter(startParent);
  14788. }
  14789. modifyStart = 1;
  14790. }
  14791. if (end && domUtils.inDoc(endParent, me.document)) {
  14792. //结束
  14793. start = endParent.firstChild;
  14794. while (start && start !== end) {
  14795. tmp = start.nextSibling;
  14796. if (domUtils.isTagNode(start, 'ol ul')) {
  14797. frag.appendChild(start);
  14798. } else {
  14799. tmpfrag = me.document.createDocumentFragment();
  14800. hasBlock = 0;
  14801. while (start.firstChild) {
  14802. if (domUtils.isBlockElm(start.firstChild)) {
  14803. hasBlock = 1;
  14804. }
  14805. tmpfrag.appendChild(start.firstChild);
  14806. }
  14807. if (!hasBlock) {
  14808. tmpP = me.document.createElement('p');
  14809. tmpP.appendChild(tmpfrag);
  14810. frag.appendChild(tmpP);
  14811. } else {
  14812. frag.appendChild(tmpfrag);
  14813. }
  14814. domUtils.remove(start);
  14815. }
  14816. start = tmp;
  14817. }
  14818. var tmpDiv = domUtils.createElement(me.document, 'div', {
  14819. 'tmpDiv':1
  14820. });
  14821. domUtils.moveChild(end, tmpDiv);
  14822. frag.appendChild(tmpDiv);
  14823. domUtils.remove(end);
  14824. endParent.parentNode.insertBefore(frag, endParent);
  14825. range.setEndBefore(endParent);
  14826. if (domUtils.isEmptyNode(endParent)) {
  14827. domUtils.remove(endParent);
  14828. }
  14829. modifyEnd = 1;
  14830. }
  14831. }
  14832. if (!modifyStart) {
  14833. range.setStartBefore(me.document.getElementById(bko.start));
  14834. }
  14835. if (bko.end && !modifyEnd) {
  14836. range.setEndAfter(me.document.getElementById(bko.end));
  14837. }
  14838. range.enlarge(true, function (node) {
  14839. return notExchange[node.tagName];
  14840. });
  14841. frag = me.document.createDocumentFragment();
  14842. var bk = range.createBookmark(),
  14843. current = domUtils.getNextDomNode(bk.start, false, filterFn),
  14844. tmpRange = range.cloneRange(),
  14845. tmpNode,
  14846. block = domUtils.isBlockElm;
  14847. while (current && current !== bk.end && (domUtils.getPosition(current, bk.end) & domUtils.POSITION_PRECEDING)) {
  14848. if (current.nodeType == 3 || dtd.li[current.tagName]) {
  14849. if (current.nodeType == 1 && dtd.$list[current.tagName]) {
  14850. while (current.firstChild) {
  14851. frag.appendChild(current.firstChild);
  14852. }
  14853. tmpNode = domUtils.getNextDomNode(current, false, filterFn);
  14854. domUtils.remove(current);
  14855. current = tmpNode;
  14856. continue;
  14857. }
  14858. tmpNode = current;
  14859. tmpRange.setStartBefore(current);
  14860. while (current && current !== bk.end && (!block(current) || domUtils.isBookmarkNode(current) )) {
  14861. tmpNode = current;
  14862. current = domUtils.getNextDomNode(current, false, null, function (node) {
  14863. return !notExchange[node.tagName];
  14864. });
  14865. }
  14866. if (current && block(current)) {
  14867. tmp = domUtils.getNextDomNode(tmpNode, false, filterFn);
  14868. if (tmp && domUtils.isBookmarkNode(tmp)) {
  14869. current = domUtils.getNextDomNode(tmp, false, filterFn);
  14870. tmpNode = tmp;
  14871. }
  14872. }
  14873. tmpRange.setEndAfter(tmpNode);
  14874. current = domUtils.getNextDomNode(tmpNode, false, filterFn);
  14875. var li = range.document.createElement('li');
  14876. li.appendChild(tmpRange.extractContents());
  14877. if(domUtils.isEmptyNode(li)){
  14878. var tmpNode = range.document.createElement('p');
  14879. while(li.firstChild){
  14880. tmpNode.appendChild(li.firstChild)
  14881. }
  14882. li.appendChild(tmpNode);
  14883. }
  14884. frag.appendChild(li);
  14885. } else {
  14886. current = domUtils.getNextDomNode(current, true, filterFn);
  14887. }
  14888. }
  14889. range.moveToBookmark(bk).collapse(true);
  14890. list = me.document.createElement(tag);
  14891. setListStyle(list,style);
  14892. list.appendChild(frag);
  14893. range.insertNode(list);
  14894. //当前list上下看能否合并
  14895. adjustList(list, tag, style);
  14896. //去掉冗余的tmpDiv
  14897. for (var i = 0, ci, tmpDivs = domUtils.getElementsByTagName(list, 'div'); ci = tmpDivs[i++];) {
  14898. if (ci.getAttribute('tmpDiv')) {
  14899. domUtils.remove(ci, true)
  14900. }
  14901. }
  14902. range.moveToBookmark(bko).select();
  14903. },
  14904. queryCommandState:function (command) {
  14905. var tag = command.toLowerCase() == 'insertorderedlist' ? 'ol' : 'ul';
  14906. var path = this.selection.getStartElementPath();
  14907. for(var i= 0,ci;ci = path[i++];){
  14908. if(ci.nodeName == 'TABLE'){
  14909. return 0
  14910. }
  14911. if(tag == ci.nodeName.toLowerCase()){
  14912. return 1
  14913. };
  14914. }
  14915. return 0;
  14916. },
  14917. queryCommandValue:function (command) {
  14918. var tag = command.toLowerCase() == 'insertorderedlist' ? 'ol' : 'ul';
  14919. var path = this.selection.getStartElementPath(),
  14920. node;
  14921. for(var i= 0,ci;ci = path[i++];){
  14922. if(ci.nodeName == 'TABLE'){
  14923. node = null;
  14924. break;
  14925. }
  14926. if(tag == ci.nodeName.toLowerCase()){
  14927. node = ci;
  14928. break;
  14929. };
  14930. }
  14931. return node ? getStyle(node) || domUtils.getComputedStyle(node, 'list-style-type') : null;
  14932. }
  14933. };
  14934. };
  14935. // plugins/source.js
  14936. /**
  14937. * 源码编辑插件
  14938. * @file
  14939. * @since 1.2.6.1
  14940. */
  14941. (function (){
  14942. var sourceEditors = {
  14943. textarea: function (editor, holder){
  14944. var textarea = holder.ownerDocument.createElement('textarea');
  14945. textarea.style.cssText = 'position:absolute;resize:none;width:100%;height:100%;border:0;padding:0;margin:0;overflow-y:auto;';
  14946. // todo: IE下只有onresize属性可用... 很纠结
  14947. if (browser.ie && browser.version < 8) {
  14948. textarea.style.width = holder.offsetWidth + 'px';
  14949. textarea.style.height = holder.offsetHeight + 'px';
  14950. holder.onresize = function (){
  14951. textarea.style.width = holder.offsetWidth + 'px';
  14952. textarea.style.height = holder.offsetHeight + 'px';
  14953. };
  14954. }
  14955. holder.appendChild(textarea);
  14956. return {
  14957. setContent: function (content){
  14958. textarea.value = content;
  14959. },
  14960. getContent: function (){
  14961. return textarea.value;
  14962. },
  14963. select: function (){
  14964. var range;
  14965. if (browser.ie) {
  14966. range = textarea.createTextRange();
  14967. range.collapse(true);
  14968. range.select();
  14969. } else {
  14970. //todo: chrome下无法设置焦点
  14971. textarea.setSelectionRange(0, 0);
  14972. textarea.focus();
  14973. }
  14974. },
  14975. dispose: function (){
  14976. holder.removeChild(textarea);
  14977. // todo
  14978. holder.onresize = null;
  14979. textarea = null;
  14980. holder = null;
  14981. }
  14982. };
  14983. },
  14984. codemirror: function (editor, holder){
  14985. var codeEditor = window.CodeMirror(holder, {
  14986. mode: "text/html",
  14987. tabMode: "indent",
  14988. lineNumbers: true,
  14989. lineWrapping:true
  14990. });
  14991. var dom = codeEditor.getWrapperElement();
  14992. dom.style.cssText = 'position:absolute;left:0;top:0;width:100%;height:100%;font-family:consolas,"Courier new",monospace;font-size:13px;';
  14993. codeEditor.getScrollerElement().style.cssText = 'position:absolute;left:0;top:0;width:100%;height:100%;';
  14994. codeEditor.refresh();
  14995. return {
  14996. getCodeMirror:function(){
  14997. return codeEditor;
  14998. },
  14999. setContent: function (content){
  15000. codeEditor.setValue(content);
  15001. },
  15002. getContent: function (){
  15003. return codeEditor.getValue();
  15004. },
  15005. select: function (){
  15006. codeEditor.focus();
  15007. },
  15008. dispose: function (){
  15009. holder.removeChild(dom);
  15010. dom = null;
  15011. codeEditor = null;
  15012. }
  15013. };
  15014. }
  15015. };
  15016. UE.plugins['source'] = function (){
  15017. var me = this;
  15018. var opt = this.options;
  15019. var sourceMode = false;
  15020. var sourceEditor;
  15021. var orgSetContent;
  15022. opt.sourceEditor = browser.ie ? 'textarea' : (opt.sourceEditor || 'codemirror');
  15023. me.setOpt({
  15024. sourceEditorFirst:false
  15025. });
  15026. function createSourceEditor(holder){
  15027. return sourceEditors[opt.sourceEditor == 'codemirror' && window.CodeMirror ? 'codemirror' : 'textarea'](me, holder);
  15028. }
  15029. var bakCssText;
  15030. //解决在源码模式下getContent不能得到最新的内容问题
  15031. var oldGetContent,
  15032. bakAddress;
  15033. /**
  15034. * 切换源码模式和编辑模式
  15035. * @command source
  15036. * @method execCommand
  15037. * @param { String } cmd 命令字符串
  15038. * @example
  15039. * ```javascript
  15040. * editor.execCommand( 'source');
  15041. * ```
  15042. */
  15043. /**
  15044. * 查询当前编辑区域的状态是源码模式还是可视化模式
  15045. * @command source
  15046. * @method queryCommandState
  15047. * @param { String } cmd 命令字符串
  15048. * @return { int } 如果当前是源码编辑模式,返回1,否则返回0
  15049. * @example
  15050. * ```javascript
  15051. * editor.queryCommandState( 'source' );
  15052. * ```
  15053. */
  15054. me.commands['source'] = {
  15055. execCommand: function (){
  15056. sourceMode = !sourceMode;
  15057. if (sourceMode) {
  15058. bakAddress = me.selection.getRange().createAddress(false,true);
  15059. me.undoManger && me.undoManger.save(true);
  15060. if(browser.gecko){
  15061. me.body.contentEditable = false;
  15062. }
  15063. bakCssText = me.iframe.style.cssText;
  15064. me.iframe.style.cssText += 'position:absolute;left:-32768px;top:-32768px;';
  15065. me.fireEvent('beforegetcontent');
  15066. var root = UE.htmlparser(me.body.innerHTML);
  15067. me.filterOutputRule(root);
  15068. root.traversal(function (node) {
  15069. if (node.type == 'element') {
  15070. switch (node.tagName) {
  15071. case 'td':
  15072. case 'th':
  15073. case 'caption':
  15074. if(node.children && node.children.length == 1){
  15075. if(node.firstChild().tagName == 'br' ){
  15076. node.removeChild(node.firstChild())
  15077. }
  15078. };
  15079. break;
  15080. case 'pre':
  15081. node.innerText(node.innerText().replace(/&nbsp;/g,' '))
  15082. }
  15083. }
  15084. });
  15085. me.fireEvent('aftergetcontent');
  15086. var content = root.toHtml(true);
  15087. sourceEditor = createSourceEditor(me.iframe.parentNode);
  15088. sourceEditor.setContent(content);
  15089. orgSetContent = me.setContent;
  15090. me.setContent = function(html){
  15091. //这里暂时不触发事件,防止报错
  15092. var root = UE.htmlparser(html);
  15093. me.filterInputRule(root);
  15094. html = root.toHtml();
  15095. sourceEditor.setContent(html);
  15096. };
  15097. setTimeout(function (){
  15098. sourceEditor.select();
  15099. me.addListener('fullscreenchanged', function(){
  15100. try{
  15101. sourceEditor.getCodeMirror().refresh()
  15102. }catch(e){}
  15103. });
  15104. });
  15105. //重置getContent,源码模式下取值也能是最新的数据
  15106. oldGetContent = me.getContent;
  15107. me.getContent = function (){
  15108. return sourceEditor.getContent() || '<p>' + (browser.ie ? '' : '<br/>')+'</p>';
  15109. };
  15110. } else {
  15111. me.iframe.style.cssText = bakCssText;
  15112. var cont = sourceEditor.getContent() || '<p>' + (browser.ie ? '' : '<br/>')+'</p>';
  15113. //处理掉block节点前后的空格,有可能会误命中,暂时不考虑
  15114. cont = cont.replace(new RegExp('[\\r\\t\\n ]*<\/?(\\w+)\\s*(?:[^>]*)>','g'), function(a,b){
  15115. if(b && !dtd.$inlineWithA[b.toLowerCase()]){
  15116. return a.replace(/(^[\n\r\t ]*)|([\n\r\t ]*$)/g,'');
  15117. }
  15118. return a.replace(/(^[\n\r\t]*)|([\n\r\t]*$)/g,'')
  15119. });
  15120. me.setContent = orgSetContent;
  15121. me.setContent(cont);
  15122. sourceEditor.dispose();
  15123. sourceEditor = null;
  15124. //还原getContent方法
  15125. me.getContent = oldGetContent;
  15126. var first = me.body.firstChild;
  15127. //trace:1106 都删除空了,下边会报错,所以补充一个p占位
  15128. if(!first){
  15129. me.body.innerHTML = '<p>'+(browser.ie?'':'<br/>')+'</p>';
  15130. first = me.body.firstChild;
  15131. }
  15132. //要在ifm为显示时ff才能取到selection,否则报错
  15133. //这里不能比较位置了
  15134. me.undoManger && me.undoManger.save(true);
  15135. if(browser.gecko){
  15136. var input = document.createElement('input');
  15137. input.style.cssText = 'position:absolute;left:0;top:-32768px';
  15138. document.body.appendChild(input);
  15139. me.body.contentEditable = false;
  15140. setTimeout(function(){
  15141. domUtils.setViewportOffset(input, { left: -32768, top: 0 });
  15142. input.focus();
  15143. setTimeout(function(){
  15144. me.body.contentEditable = true;
  15145. me.selection.getRange().moveToAddress(bakAddress).select(true);
  15146. domUtils.remove(input);
  15147. });
  15148. });
  15149. }else{
  15150. //ie下有可能报错,比如在代码顶头的情况
  15151. try{
  15152. me.selection.getRange().moveToAddress(bakAddress).select(true);
  15153. }catch(e){}
  15154. }
  15155. }
  15156. this.fireEvent('sourcemodechanged', sourceMode);
  15157. },
  15158. queryCommandState: function (){
  15159. return sourceMode|0;
  15160. },
  15161. notNeedUndo : 1
  15162. };
  15163. var oldQueryCommandState = me.queryCommandState;
  15164. me.queryCommandState = function (cmdName){
  15165. cmdName = cmdName.toLowerCase();
  15166. if (sourceMode) {
  15167. //源码模式下可以开启的命令
  15168. return cmdName in {
  15169. 'source' : 1,
  15170. 'fullscreen' : 1
  15171. } ? 1 : -1
  15172. }
  15173. return oldQueryCommandState.apply(this, arguments);
  15174. };
  15175. if(opt.sourceEditor == "codemirror"){
  15176. me.addListener("ready",function(){
  15177. utils.loadFile(document,{
  15178. src : opt.codeMirrorJsUrl || opt.UEDITOR_HOME_URL + "third-party/codemirror/codemirror.js",
  15179. tag : "script",
  15180. type : "text/javascript",
  15181. defer : "defer"
  15182. },function(){
  15183. if(opt.sourceEditorFirst){
  15184. setTimeout(function(){
  15185. me.execCommand("source");
  15186. },0);
  15187. }
  15188. });
  15189. utils.loadFile(document,{
  15190. tag : "link",
  15191. rel : "stylesheet",
  15192. type : "text/css",
  15193. href : opt.codeMirrorCssUrl || opt.UEDITOR_HOME_URL + "third-party/codemirror/codemirror.css"
  15194. });
  15195. });
  15196. }
  15197. };
  15198. })();
  15199. // plugins/enterkey.js
  15200. ///import core
  15201. ///import plugins/undo.js
  15202. ///commands 设置回车标签p或br
  15203. ///commandsName EnterKey
  15204. ///commandsTitle 设置回车标签p或br
  15205. /**
  15206. * @description 处理回车
  15207. * @author zhanyi
  15208. */
  15209. UE.plugins['enterkey'] = function() {
  15210. var hTag,
  15211. me = this,
  15212. tag = me.options.enterTag;
  15213. me.addListener('keyup', function(type, evt) {
  15214. var keyCode = evt.keyCode || evt.which;
  15215. if (keyCode == 13) {
  15216. var range = me.selection.getRange(),
  15217. start = range.startContainer,
  15218. doSave;
  15219. //修正在h1-h6里边回车后不能嵌套p的问题
  15220. if (!browser.ie) {
  15221. if (/h\d/i.test(hTag)) {
  15222. if (browser.gecko) {
  15223. var h = domUtils.findParentByTagName(start, [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6','blockquote','caption','table'], true);
  15224. if (!h) {
  15225. me.document.execCommand('formatBlock', false, '<p>');
  15226. doSave = 1;
  15227. }
  15228. } else {
  15229. //chrome remove div
  15230. if (start.nodeType == 1) {
  15231. var tmp = me.document.createTextNode(''),div;
  15232. range.insertNode(tmp);
  15233. div = domUtils.findParentByTagName(tmp, 'div', true);
  15234. if (div) {
  15235. var p = me.document.createElement('p');
  15236. while (div.firstChild) {
  15237. p.appendChild(div.firstChild);
  15238. }
  15239. div.parentNode.insertBefore(p, div);
  15240. domUtils.remove(div);
  15241. range.setStartBefore(tmp).setCursor();
  15242. doSave = 1;
  15243. }
  15244. domUtils.remove(tmp);
  15245. }
  15246. }
  15247. if (me.undoManger && doSave) {
  15248. me.undoManger.save();
  15249. }
  15250. }
  15251. //没有站位符,会出现多行的问题
  15252. browser.opera && range.select();
  15253. }else{
  15254. me.fireEvent('saveScene',true,true)
  15255. }
  15256. }
  15257. });
  15258. me.addListener('keydown', function(type, evt) {
  15259. var keyCode = evt.keyCode || evt.which;
  15260. if (keyCode == 13) {//回车
  15261. if(me.fireEvent('beforeenterkeydown')){
  15262. domUtils.preventDefault(evt);
  15263. return;
  15264. }
  15265. me.fireEvent('saveScene',true,true);
  15266. hTag = '';
  15267. var range = me.selection.getRange();
  15268. if (!range.collapsed) {
  15269. //跨td不能删
  15270. var start = range.startContainer,
  15271. end = range.endContainer,
  15272. startTd = domUtils.findParentByTagName(start, 'td', true),
  15273. endTd = domUtils.findParentByTagName(end, 'td', true);
  15274. if (startTd && endTd && startTd !== endTd || !startTd && endTd || startTd && !endTd) {
  15275. evt.preventDefault ? evt.preventDefault() : ( evt.returnValue = false);
  15276. return;
  15277. }
  15278. }
  15279. if (tag == 'p') {
  15280. if (!browser.ie) {
  15281. start = domUtils.findParentByTagName(range.startContainer, ['ol','ul','p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6','blockquote','caption'], true);
  15282. //opera下执行formatblock会在table的场景下有问题,回车在opera原生支持很好,所以暂时在opera去掉调用这个原生的command
  15283. //trace:2431
  15284. if (!start && !browser.opera) {
  15285. me.document.execCommand('formatBlock', false, '<p>');
  15286. if (browser.gecko) {
  15287. range = me.selection.getRange();
  15288. start = domUtils.findParentByTagName(range.startContainer, 'p', true);
  15289. start && domUtils.removeDirtyAttr(start);
  15290. }
  15291. } else {
  15292. hTag = start.tagName;
  15293. start.tagName.toLowerCase() == 'p' && browser.gecko && domUtils.removeDirtyAttr(start);
  15294. }
  15295. }
  15296. } else {
  15297. evt.preventDefault ? evt.preventDefault() : ( evt.returnValue = false);
  15298. if (!range.collapsed) {
  15299. range.deleteContents();
  15300. start = range.startContainer;
  15301. if (start.nodeType == 1 && (start = start.childNodes[range.startOffset])) {
  15302. while (start.nodeType == 1) {
  15303. if (dtd.$empty[start.tagName]) {
  15304. range.setStartBefore(start).setCursor();
  15305. if (me.undoManger) {
  15306. me.undoManger.save();
  15307. }
  15308. return false;
  15309. }
  15310. if (!start.firstChild) {
  15311. var br = range.document.createElement('br');
  15312. start.appendChild(br);
  15313. range.setStart(start, 0).setCursor();
  15314. if (me.undoManger) {
  15315. me.undoManger.save();
  15316. }
  15317. return false;
  15318. }
  15319. start = start.firstChild;
  15320. }
  15321. if (start === range.startContainer.childNodes[range.startOffset]) {
  15322. br = range.document.createElement('br');
  15323. range.insertNode(br).setCursor();
  15324. } else {
  15325. range.setStart(start, 0).setCursor();
  15326. }
  15327. } else {
  15328. br = range.document.createElement('br');
  15329. range.insertNode(br).setStartAfter(br).setCursor();
  15330. }
  15331. } else {
  15332. br = range.document.createElement('br');
  15333. range.insertNode(br);
  15334. var parent = br.parentNode;
  15335. if (parent.lastChild === br) {
  15336. br.parentNode.insertBefore(br.cloneNode(true), br);
  15337. range.setStartBefore(br);
  15338. } else {
  15339. range.setStartAfter(br);
  15340. }
  15341. range.setCursor();
  15342. }
  15343. }
  15344. }
  15345. });
  15346. };
  15347. // plugins/keystrokes.js
  15348. /* 处理特殊键的兼容性问题 */
  15349. UE.plugins['keystrokes'] = function() {
  15350. var me = this;
  15351. var collapsed = true;
  15352. me.addListener('keydown', function(type, evt) {
  15353. var keyCode = evt.keyCode || evt.which,
  15354. rng = me.selection.getRange();
  15355. //处理全选的情况
  15356. if(!rng.collapsed && !(evt.ctrlKey || evt.shiftKey || evt.altKey || evt.metaKey) && (keyCode >= 65 && keyCode <=90
  15357. || keyCode >= 48 && keyCode <= 57 ||
  15358. keyCode >= 96 && keyCode <= 111 || {
  15359. 13:1,
  15360. 8:1,
  15361. 46:1
  15362. }[keyCode])
  15363. ){
  15364. var tmpNode = rng.startContainer;
  15365. if(domUtils.isFillChar(tmpNode)){
  15366. rng.setStartBefore(tmpNode)
  15367. }
  15368. tmpNode = rng.endContainer;
  15369. if(domUtils.isFillChar(tmpNode)){
  15370. rng.setEndAfter(tmpNode)
  15371. }
  15372. rng.txtToElmBoundary();
  15373. //结束边界可能放到了br的前边,要把br包含进来
  15374. // x[xxx]<br/>
  15375. if(rng.endContainer && rng.endContainer.nodeType == 1){
  15376. tmpNode = rng.endContainer.childNodes[rng.endOffset];
  15377. if(tmpNode && domUtils.isBr(tmpNode)){
  15378. rng.setEndAfter(tmpNode);
  15379. }
  15380. }
  15381. if(rng.startOffset == 0){
  15382. tmpNode = rng.startContainer;
  15383. if(domUtils.isBoundaryNode(tmpNode,'firstChild') ){
  15384. tmpNode = rng.endContainer;
  15385. if(rng.endOffset == (tmpNode.nodeType == 3 ? tmpNode.nodeValue.length : tmpNode.childNodes.length) && domUtils.isBoundaryNode(tmpNode,'lastChild')){
  15386. me.fireEvent('saveScene');
  15387. me.body.innerHTML = '<p>'+(browser.ie ? '' : '<br/>')+'</p>';
  15388. rng.setStart(me.body.firstChild,0).setCursor(false,true);
  15389. me._selectionChange();
  15390. return;
  15391. }
  15392. }
  15393. }
  15394. }
  15395. //处理backspace
  15396. if (keyCode == keymap.Backspace) {
  15397. rng = me.selection.getRange();
  15398. collapsed = rng.collapsed;
  15399. if(me.fireEvent('delkeydown',evt)){
  15400. return;
  15401. }
  15402. var start,end;
  15403. //避免按两次删除才能生效的问题
  15404. if(rng.collapsed && rng.inFillChar()){
  15405. start = rng.startContainer;
  15406. if(domUtils.isFillChar(start)){
  15407. rng.setStartBefore(start).shrinkBoundary(true).collapse(true);
  15408. domUtils.remove(start)
  15409. }else{
  15410. start.nodeValue = start.nodeValue.replace(new RegExp('^' + domUtils.fillChar ),'');
  15411. rng.startOffset--;
  15412. rng.collapse(true).select(true)
  15413. }
  15414. }
  15415. //解决选中control元素不能删除的问题
  15416. if (start = rng.getClosedNode()) {
  15417. me.fireEvent('saveScene');
  15418. rng.setStartBefore(start);
  15419. domUtils.remove(start);
  15420. rng.setCursor();
  15421. me.fireEvent('saveScene');
  15422. domUtils.preventDefault(evt);
  15423. return;
  15424. }
  15425. //阻止在table上的删除
  15426. if (!browser.ie) {
  15427. start = domUtils.findParentByTagName(rng.startContainer, 'table', true);
  15428. end = domUtils.findParentByTagName(rng.endContainer, 'table', true);
  15429. if (start && !end || !start && end || start !== end) {
  15430. evt.preventDefault();
  15431. return;
  15432. }
  15433. }
  15434. }
  15435. //处理tab键的逻辑
  15436. if (keyCode == keymap.Tab) {
  15437. //不处理以下标签
  15438. var excludeTagNameForTabKey = {
  15439. 'ol' : 1,
  15440. 'ul' : 1,
  15441. 'table':1
  15442. };
  15443. //处理组件里的tab按下事件
  15444. if(me.fireEvent('tabkeydown',evt)){
  15445. domUtils.preventDefault(evt);
  15446. return;
  15447. }
  15448. var range = me.selection.getRange();
  15449. me.fireEvent('saveScene');
  15450. for (var i = 0,txt = '',tabSize = me.options.tabSize|| 4,tabNode = me.options.tabNode || '&nbsp;'; i < tabSize; i++) {
  15451. txt += tabNode;
  15452. }
  15453. var span = me.document.createElement('span');
  15454. span.innerHTML = txt + domUtils.fillChar;
  15455. if (range.collapsed) {
  15456. range.insertNode(span.cloneNode(true).firstChild).setCursor(true);
  15457. } else {
  15458. var filterFn = function(node) {
  15459. return domUtils.isBlockElm(node) && !excludeTagNameForTabKey[node.tagName.toLowerCase()]
  15460. };
  15461. //普通的情况
  15462. start = domUtils.findParent(range.startContainer, filterFn,true);
  15463. end = domUtils.findParent(range.endContainer, filterFn,true);
  15464. if (start && end && start === end) {
  15465. range.deleteContents();
  15466. range.insertNode(span.cloneNode(true).firstChild).setCursor(true);
  15467. } else {
  15468. var bookmark = range.createBookmark();
  15469. range.enlarge(true);
  15470. var bookmark2 = range.createBookmark(),
  15471. current = domUtils.getNextDomNode(bookmark2.start, false, filterFn);
  15472. while (current && !(domUtils.getPosition(current, bookmark2.end) & domUtils.POSITION_FOLLOWING)) {
  15473. current.insertBefore(span.cloneNode(true).firstChild, current.firstChild);
  15474. current = domUtils.getNextDomNode(current, false, filterFn);
  15475. }
  15476. range.moveToBookmark(bookmark2).moveToBookmark(bookmark).select();
  15477. }
  15478. }
  15479. domUtils.preventDefault(evt)
  15480. }
  15481. //trace:1634
  15482. //ff的del键在容器空的时候,也会删除
  15483. if(browser.gecko && keyCode == 46){
  15484. range = me.selection.getRange();
  15485. if(range.collapsed){
  15486. start = range.startContainer;
  15487. if(domUtils.isEmptyBlock(start)){
  15488. var parent = start.parentNode;
  15489. while(domUtils.getChildCount(parent) == 1 && !domUtils.isBody(parent)){
  15490. start = parent;
  15491. parent = parent.parentNode;
  15492. }
  15493. if(start === parent.lastChild)
  15494. evt.preventDefault();
  15495. return;
  15496. }
  15497. }
  15498. }
  15499. });
  15500. me.addListener('keyup', function(type, evt) {
  15501. var keyCode = evt.keyCode || evt.which,
  15502. rng,me = this;
  15503. if(keyCode == keymap.Backspace){
  15504. if(me.fireEvent('delkeyup')){
  15505. return;
  15506. }
  15507. rng = me.selection.getRange();
  15508. if(rng.collapsed){
  15509. var tmpNode,
  15510. autoClearTagName = ['h1','h2','h3','h4','h5','h6'];
  15511. if(tmpNode = domUtils.findParentByTagName(rng.startContainer,autoClearTagName,true)){
  15512. if(domUtils.isEmptyBlock(tmpNode)){
  15513. var pre = tmpNode.previousSibling;
  15514. if(pre && pre.nodeName != 'TABLE'){
  15515. domUtils.remove(tmpNode);
  15516. rng.setStartAtLast(pre).setCursor(false,true);
  15517. return;
  15518. }else{
  15519. var next = tmpNode.nextSibling;
  15520. if(next && next.nodeName != 'TABLE'){
  15521. domUtils.remove(tmpNode);
  15522. rng.setStartAtFirst(next).setCursor(false,true);
  15523. return;
  15524. }
  15525. }
  15526. }
  15527. }
  15528. //处理当删除到body时,要重新给p标签展位
  15529. if(domUtils.isBody(rng.startContainer)){
  15530. var tmpNode = domUtils.createElement(me.document,'p',{
  15531. 'innerHTML' : browser.ie ? domUtils.fillChar : '<br/>'
  15532. });
  15533. rng.insertNode(tmpNode).setStart(tmpNode,0).setCursor(false,true);
  15534. }
  15535. }
  15536. //chrome下如果删除了inline标签,浏览器会有记忆,在输入文字还是会套上刚才删除的标签,所以这里再选一次就不会了
  15537. if( !collapsed && (rng.startContainer.nodeType == 3 || rng.startContainer.nodeType == 1 && domUtils.isEmptyBlock(rng.startContainer))){
  15538. if(browser.ie){
  15539. var span = rng.document.createElement('span');
  15540. rng.insertNode(span).setStartBefore(span).collapse(true);
  15541. rng.select();
  15542. domUtils.remove(span)
  15543. }else{
  15544. rng.select()
  15545. }
  15546. }
  15547. }
  15548. })
  15549. };
  15550. // plugins/fiximgclick.js
  15551. ///import core
  15552. ///commands 修复chrome下图片不能点击的问题,出现八个角可改变大小
  15553. ///commandsName FixImgClick
  15554. ///commandsTitle 修复chrome下图片不能点击的问题,出现八个角可改变大小
  15555. //修复chrome下图片不能点击的问题,出现八个角可改变大小
  15556. UE.plugins['fiximgclick'] = (function () {
  15557. var elementUpdated = false;
  15558. function Scale() {
  15559. this.editor = null;
  15560. this.resizer = null;
  15561. this.cover = null;
  15562. this.doc = document;
  15563. this.prePos = {x: 0, y: 0};
  15564. this.startPos = {x: 0, y: 0};
  15565. }
  15566. (function () {
  15567. var rect = [
  15568. //[left, top, width, height]
  15569. [0, 0, -1, -1],
  15570. [0, 0, 0, -1],
  15571. [0, 0, 1, -1],
  15572. [0, 0, -1, 0],
  15573. [0, 0, 1, 0],
  15574. [0, 0, -1, 1],
  15575. [0, 0, 0, 1],
  15576. [0, 0, 1, 1]
  15577. ];
  15578. Scale.prototype = {
  15579. init: function (editor) {
  15580. var me = this;
  15581. me.editor = editor;
  15582. me.startPos = this.prePos = {x: 0, y: 0};
  15583. me.dragId = -1;
  15584. var hands = [],
  15585. cover = me.cover = document.createElement('div'),
  15586. resizer = me.resizer = document.createElement('div');
  15587. cover.id = me.editor.ui.id + '_imagescale_cover';
  15588. cover.style.cssText = 'position:absolute;display:none;z-index:' + (me.editor.options.zIndex) + ';filter:alpha(opacity=0); opacity:0;background:#CCC;';
  15589. domUtils.on(cover, 'mousedown click', function () {
  15590. me.hide();
  15591. });
  15592. for (i = 0; i < 8; i++) {
  15593. hands.push('<span class="edui-editor-imagescale-hand' + i + '"></span>');
  15594. }
  15595. resizer.id = me.editor.ui.id + '_imagescale';
  15596. resizer.className = 'edui-editor-imagescale';
  15597. resizer.innerHTML = hands.join('');
  15598. resizer.style.cssText += ';display:none;border:1px solid #3b77ff;z-index:' + (me.editor.options.zIndex) + ';';
  15599. me.editor.ui.getDom().appendChild(cover);
  15600. me.editor.ui.getDom().appendChild(resizer);
  15601. me.initStyle();
  15602. me.initEvents();
  15603. },
  15604. initStyle: function () {
  15605. 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;}' +
  15606. '.edui-editor-imagescale span{position:absolute;width:6px;height:6px;overflow:hidden;font-size:0px;display:block;background-color:#3C9DD0;}'
  15607. + '.edui-editor-imagescale .edui-editor-imagescale-hand0{cursor:nw-resize;top:0;margin-top:-4px;left:0;margin-left:-4px;}'
  15608. + '.edui-editor-imagescale .edui-editor-imagescale-hand1{cursor:n-resize;top:0;margin-top:-4px;left:50%;margin-left:-4px;}'
  15609. + '.edui-editor-imagescale .edui-editor-imagescale-hand2{cursor:ne-resize;top:0;margin-top:-4px;left:100%;margin-left:-3px;}'
  15610. + '.edui-editor-imagescale .edui-editor-imagescale-hand3{cursor:w-resize;top:50%;margin-top:-4px;left:0;margin-left:-4px;}'
  15611. + '.edui-editor-imagescale .edui-editor-imagescale-hand4{cursor:e-resize;top:50%;margin-top:-4px;left:100%;margin-left:-3px;}'
  15612. + '.edui-editor-imagescale .edui-editor-imagescale-hand5{cursor:sw-resize;top:100%;margin-top:-3px;left:0;margin-left:-4px;}'
  15613. + '.edui-editor-imagescale .edui-editor-imagescale-hand6{cursor:s-resize;top:100%;margin-top:-3px;left:50%;margin-left:-4px;}'
  15614. + '.edui-editor-imagescale .edui-editor-imagescale-hand7{cursor:se-resize;top:100%;margin-top:-3px;left:100%;margin-left:-3px;}');
  15615. },
  15616. initEvents: function () {
  15617. var me = this;
  15618. me.startPos.x = me.startPos.y = 0;
  15619. me.isDraging = false;
  15620. },
  15621. _eventHandler: function (e) {
  15622. var me = this;
  15623. switch (e.type) {
  15624. case 'mousedown':
  15625. var hand = e.target || e.srcElement, hand;
  15626. if (hand.className.indexOf('edui-editor-imagescale-hand') != -1 && me.dragId == -1) {
  15627. me.dragId = hand.className.slice(-1);
  15628. me.startPos.x = me.prePos.x = e.clientX;
  15629. me.startPos.y = me.prePos.y = e.clientY;
  15630. domUtils.on(me.doc,'mousemove', me.proxy(me._eventHandler, me));
  15631. }
  15632. break;
  15633. case 'mousemove':
  15634. if (me.dragId != -1) {
  15635. me.updateContainerStyle(me.dragId, {x: e.clientX - me.prePos.x, y: e.clientY - me.prePos.y});
  15636. me.prePos.x = e.clientX;
  15637. me.prePos.y = e.clientY;
  15638. elementUpdated = true;
  15639. me.updateTargetElement();
  15640. }
  15641. break;
  15642. case 'mouseup':
  15643. if (me.dragId != -1) {
  15644. me.updateContainerStyle(me.dragId, {x: e.clientX - me.prePos.x, y: e.clientY - me.prePos.y});
  15645. me.updateTargetElement();
  15646. if (me.target.parentNode) me.attachTo(me.target);
  15647. me.dragId = -1;
  15648. }
  15649. domUtils.un(me.doc,'mousemove', me.proxy(me._eventHandler, me));
  15650. //修复只是点击挪动点,但没有改变大小,不应该触发contentchange
  15651. if(elementUpdated){
  15652. elementUpdated = false;
  15653. me.editor.fireEvent('contentchange');
  15654. }
  15655. break;
  15656. default:
  15657. break;
  15658. }
  15659. },
  15660. updateTargetElement: function () {
  15661. var me = this;
  15662. domUtils.setStyles(me.target, {
  15663. 'width': me.resizer.style.width,
  15664. 'height': me.resizer.style.height
  15665. });
  15666. me.target.width = parseInt(me.resizer.style.width);
  15667. me.target.height = parseInt(me.resizer.style.height);
  15668. me.attachTo(me.target);
  15669. },
  15670. updateContainerStyle: function (dir, offset) {
  15671. var me = this,
  15672. dom = me.resizer, tmp;
  15673. if (rect[dir][0] != 0) {
  15674. tmp = parseInt(dom.style.left) + offset.x;
  15675. dom.style.left = me._validScaledProp('left', tmp) + 'px';
  15676. }
  15677. if (rect[dir][1] != 0) {
  15678. tmp = parseInt(dom.style.top) + offset.y;
  15679. dom.style.top = me._validScaledProp('top', tmp) + 'px';
  15680. }
  15681. if (rect[dir][2] != 0) {
  15682. tmp = dom.clientWidth + rect[dir][2] * offset.x;
  15683. dom.style.width = me._validScaledProp('width', tmp) + 'px';
  15684. }
  15685. if (rect[dir][3] != 0) {
  15686. tmp = dom.clientHeight + rect[dir][3] * offset.y;
  15687. dom.style.height = me._validScaledProp('height', tmp) + 'px';
  15688. }
  15689. },
  15690. _validScaledProp: function (prop, value) {
  15691. var ele = this.resizer,
  15692. wrap = document;
  15693. value = isNaN(value) ? 0 : value;
  15694. switch (prop) {
  15695. case 'left':
  15696. return value < 0 ? 0 : (value + ele.clientWidth) > wrap.clientWidth ? wrap.clientWidth - ele.clientWidth : value;
  15697. case 'top':
  15698. return value < 0 ? 0 : (value + ele.clientHeight) > wrap.clientHeight ? wrap.clientHeight - ele.clientHeight : value;
  15699. case 'width':
  15700. return value <= 0 ? 1 : (value + ele.offsetLeft) > wrap.clientWidth ? wrap.clientWidth - ele.offsetLeft : value;
  15701. case 'height':
  15702. return value <= 0 ? 1 : (value + ele.offsetTop) > wrap.clientHeight ? wrap.clientHeight - ele.offsetTop : value;
  15703. }
  15704. },
  15705. hideCover: function () {
  15706. this.cover.style.display = 'none';
  15707. },
  15708. showCover: function () {
  15709. var me = this,
  15710. editorPos = domUtils.getXY(me.editor.ui.getDom()),
  15711. iframePos = domUtils.getXY(me.editor.iframe);
  15712. domUtils.setStyles(me.cover, {
  15713. 'width': me.editor.iframe.offsetWidth + 'px',
  15714. 'height': me.editor.iframe.offsetHeight + 'px',
  15715. 'top': iframePos.y - editorPos.y + 'px',
  15716. 'left': iframePos.x - editorPos.x + 'px',
  15717. 'position': 'absolute',
  15718. 'display': ''
  15719. })
  15720. },
  15721. show: function (targetObj) {
  15722. var me = this;
  15723. me.resizer.style.display = 'block';
  15724. if(targetObj) me.attachTo(targetObj);
  15725. domUtils.on(this.resizer, 'mousedown', me.proxy(me._eventHandler, me));
  15726. domUtils.on(me.doc, 'mouseup', me.proxy(me._eventHandler, me));
  15727. me.showCover();
  15728. me.editor.fireEvent('afterscaleshow', me);
  15729. me.editor.fireEvent('saveScene');
  15730. },
  15731. hide: function () {
  15732. var me = this;
  15733. me.hideCover();
  15734. me.resizer.style.display = 'none';
  15735. domUtils.un(me.resizer, 'mousedown', me.proxy(me._eventHandler, me));
  15736. domUtils.un(me.doc, 'mouseup', me.proxy(me._eventHandler, me));
  15737. me.editor.fireEvent('afterscalehide', me);
  15738. },
  15739. proxy: function( fn, context ) {
  15740. return function(e) {
  15741. return fn.apply( context || this, arguments);
  15742. };
  15743. },
  15744. attachTo: function (targetObj) {
  15745. var me = this,
  15746. target = me.target = targetObj,
  15747. resizer = this.resizer,
  15748. imgPos = domUtils.getXY(target),
  15749. iframePos = domUtils.getXY(me.editor.iframe),
  15750. editorPos = domUtils.getXY(resizer.parentNode);
  15751. domUtils.setStyles(resizer, {
  15752. 'width': target.width + 'px',
  15753. 'height': target.height + 'px',
  15754. 'left': iframePos.x + imgPos.x - me.editor.document.body.scrollLeft - editorPos.x - parseInt(resizer.style.borderLeftWidth) + 'px',
  15755. 'top': iframePos.y + imgPos.y - me.editor.document.body.scrollTop - editorPos.y - parseInt(resizer.style.borderTopWidth) + 'px'
  15756. });
  15757. }
  15758. }
  15759. })();
  15760. return function () {
  15761. var me = this,
  15762. imageScale;
  15763. me.setOpt('imageScaleEnabled', true);
  15764. if ( !browser.ie && me.options.imageScaleEnabled) {
  15765. me.addListener('click', function (type, e) {
  15766. var range = me.selection.getRange(),
  15767. img = range.getClosedNode();
  15768. if (img && img.tagName == 'IMG' && me.body.contentEditable!="false") {
  15769. if (img.className.indexOf("edui-faked-music") != -1 ||
  15770. img.getAttribute("anchorname") ||
  15771. domUtils.hasClass(img, 'loadingclass') ||
  15772. domUtils.hasClass(img, 'loaderrorclass')) { return }
  15773. if (!imageScale) {
  15774. imageScale = new Scale();
  15775. imageScale.init(me);
  15776. me.ui.getDom().appendChild(imageScale.resizer);
  15777. var _keyDownHandler = function (e) {
  15778. imageScale.hide();
  15779. if(imageScale.target) me.selection.getRange().selectNode(imageScale.target).select();
  15780. }, _mouseDownHandler = function (e) {
  15781. var ele = e.target || e.srcElement;
  15782. if (ele && (ele.className===undefined || ele.className.indexOf('edui-editor-imagescale') == -1)) {
  15783. _keyDownHandler(e);
  15784. }
  15785. }, timer;
  15786. me.addListener('afterscaleshow', function (e) {
  15787. me.addListener('beforekeydown', _keyDownHandler);
  15788. me.addListener('beforemousedown', _mouseDownHandler);
  15789. domUtils.on(document, 'keydown', _keyDownHandler);
  15790. domUtils.on(document,'mousedown', _mouseDownHandler);
  15791. me.selection.getNative().removeAllRanges();
  15792. });
  15793. me.addListener('afterscalehide', function (e) {
  15794. me.removeListener('beforekeydown', _keyDownHandler);
  15795. me.removeListener('beforemousedown', _mouseDownHandler);
  15796. domUtils.un(document, 'keydown', _keyDownHandler);
  15797. domUtils.un(document,'mousedown', _mouseDownHandler);
  15798. var target = imageScale.target;
  15799. if (target.parentNode) {
  15800. me.selection.getRange().selectNode(target).select();
  15801. }
  15802. });
  15803. //TODO 有iframe的情况,mousedown不能往下传。。
  15804. domUtils.on(imageScale.resizer, 'mousedown', function (e) {
  15805. me.selection.getNative().removeAllRanges();
  15806. var ele = e.target || e.srcElement;
  15807. if (ele && ele.className.indexOf('edui-editor-imagescale-hand') == -1) {
  15808. timer = setTimeout(function () {
  15809. imageScale.hide();
  15810. if(imageScale.target) me.selection.getRange().selectNode(ele).select();
  15811. }, 200);
  15812. }
  15813. });
  15814. domUtils.on(imageScale.resizer, 'mouseup', function (e) {
  15815. var ele = e.target || e.srcElement;
  15816. if (ele && ele.className.indexOf('edui-editor-imagescale-hand') == -1) {
  15817. clearTimeout(timer);
  15818. }
  15819. });
  15820. }
  15821. imageScale.show(img);
  15822. } else {
  15823. if (imageScale && imageScale.resizer.style.display != 'none') imageScale.hide();
  15824. }
  15825. });
  15826. }
  15827. if (browser.webkit) {
  15828. me.addListener('click', function (type, e) {
  15829. if (e.target.tagName == 'IMG' && me.body.contentEditable!="false") {
  15830. var range = new dom.Range(me.document);
  15831. range.selectNode(e.target).select();
  15832. }
  15833. });
  15834. }
  15835. }
  15836. })();
  15837. // plugins/autolink.js
  15838. ///import core
  15839. ///commands 为非ie浏览器自动添加a标签
  15840. ///commandsName AutoLink
  15841. ///commandsTitle 自动增加链接
  15842. /**
  15843. * @description 为非ie浏览器自动添加a标签
  15844. * @author zhanyi
  15845. */
  15846. UE.plugin.register('autolink',function(){
  15847. var cont = 0;
  15848. return !browser.ie ? {
  15849. bindEvents:{
  15850. 'reset' : function(){
  15851. cont = 0;
  15852. },
  15853. 'keydown':function(type, evt) {
  15854. var me = this;
  15855. var keyCode = evt.keyCode || evt.which;
  15856. if (keyCode == 32 || keyCode == 13) {
  15857. var sel = me.selection.getNative(),
  15858. range = sel.getRangeAt(0).cloneRange(),
  15859. offset,
  15860. charCode;
  15861. var start = range.startContainer;
  15862. while (start.nodeType == 1 && range.startOffset > 0) {
  15863. start = range.startContainer.childNodes[range.startOffset - 1];
  15864. if (!start){
  15865. break;
  15866. }
  15867. range.setStart(start, start.nodeType == 1 ? start.childNodes.length : start.nodeValue.length);
  15868. range.collapse(true);
  15869. start = range.startContainer;
  15870. }
  15871. do{
  15872. if (range.startOffset == 0) {
  15873. start = range.startContainer.previousSibling;
  15874. while (start && start.nodeType == 1) {
  15875. start = start.lastChild;
  15876. }
  15877. if (!start || domUtils.isFillChar(start)){
  15878. break;
  15879. }
  15880. offset = start.nodeValue.length;
  15881. } else {
  15882. start = range.startContainer;
  15883. offset = range.startOffset;
  15884. }
  15885. range.setStart(start, offset - 1);
  15886. charCode = range.toString().charCodeAt(0);
  15887. } while (charCode != 160 && charCode != 32);
  15888. if (range.toString().replace(new RegExp(domUtils.fillChar, 'g'), '').match(/(?:https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.)/i)) {
  15889. while(range.toString().length){
  15890. if(/^(?:https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.)/i.test(range.toString())){
  15891. break;
  15892. }
  15893. try{
  15894. range.setStart(range.startContainer,range.startOffset+1);
  15895. }catch(e){
  15896. //trace:2121
  15897. var start = range.startContainer;
  15898. while(!(next = start.nextSibling)){
  15899. if(domUtils.isBody(start)){
  15900. return;
  15901. }
  15902. start = start.parentNode;
  15903. }
  15904. range.setStart(next,0);
  15905. }
  15906. }
  15907. //range的开始边界已经在a标签里的不再处理
  15908. if(domUtils.findParentByTagName(range.startContainer,'a',true)){
  15909. return;
  15910. }
  15911. var a = me.document.createElement('a'),text = me.document.createTextNode(' '),href;
  15912. me.undoManger && me.undoManger.save();
  15913. a.appendChild(range.extractContents());
  15914. a.href = a.innerHTML = a.innerHTML.replace(/<[^>]+>/g,'');
  15915. href = a.getAttribute("href").replace(new RegExp(domUtils.fillChar,'g'),'');
  15916. href = /^(?:https?:\/\/)/ig.test(href) ? href : "http://"+ href;
  15917. a.setAttribute('_src',utils.html(href));
  15918. a.href = utils.html(href);
  15919. range.insertNode(a);
  15920. a.parentNode.insertBefore(text, a.nextSibling);
  15921. range.setStart(text, 0);
  15922. range.collapse(true);
  15923. sel.removeAllRanges();
  15924. sel.addRange(range);
  15925. me.undoManger && me.undoManger.save();
  15926. }
  15927. }
  15928. }
  15929. }
  15930. }:{}
  15931. },function(){
  15932. var keyCodes = {
  15933. 37:1, 38:1, 39:1, 40:1,
  15934. 13:1,32:1
  15935. };
  15936. function checkIsCludeLink(node){
  15937. if(node.nodeType == 3){
  15938. return null
  15939. }
  15940. if(node.nodeName == 'A'){
  15941. return node;
  15942. }
  15943. var lastChild = node.lastChild;
  15944. while(lastChild){
  15945. if(lastChild.nodeName == 'A'){
  15946. return lastChild;
  15947. }
  15948. if(lastChild.nodeType == 3){
  15949. if(domUtils.isWhitespace(lastChild)){
  15950. lastChild = lastChild.previousSibling;
  15951. continue;
  15952. }
  15953. return null
  15954. }
  15955. lastChild = lastChild.lastChild;
  15956. }
  15957. }
  15958. browser.ie && this.addListener('keyup',function(cmd,evt){
  15959. var me = this,keyCode = evt.keyCode;
  15960. if(keyCodes[keyCode]){
  15961. var rng = me.selection.getRange();
  15962. var start = rng.startContainer;
  15963. if(keyCode == 13){
  15964. while(start && !domUtils.isBody(start) && !domUtils.isBlockElm(start)){
  15965. start = start.parentNode;
  15966. }
  15967. if(start && !domUtils.isBody(start) && start.nodeName == 'P'){
  15968. var pre = start.previousSibling;
  15969. if(pre && pre.nodeType == 1){
  15970. var pre = checkIsCludeLink(pre);
  15971. if(pre && !pre.getAttribute('_href')){
  15972. domUtils.remove(pre,true);
  15973. }
  15974. }
  15975. }
  15976. }else if(keyCode == 32 ){
  15977. if(start.nodeType == 3 && /^\s$/.test(start.nodeValue)){
  15978. start = start.previousSibling;
  15979. if(start && start.nodeName == 'A' && !start.getAttribute('_href')){
  15980. domUtils.remove(start,true);
  15981. }
  15982. }
  15983. }else {
  15984. start = domUtils.findParentByTagName(start,'a',true);
  15985. if(start && !start.getAttribute('_href')){
  15986. var bk = rng.createBookmark();
  15987. domUtils.remove(start,true);
  15988. rng.moveToBookmark(bk).select(true)
  15989. }
  15990. }
  15991. }
  15992. });
  15993. }
  15994. );
  15995. // plugins/autoheight.js
  15996. ///import core
  15997. ///commands 当输入内容超过编辑器高度时,编辑器自动增高
  15998. ///commandsName AutoHeight,autoHeightEnabled
  15999. ///commandsTitle 自动增高
  16000. /**
  16001. * @description 自动伸展
  16002. * @author zhanyi
  16003. */
  16004. UE.plugins['autoheight'] = function () {
  16005. var me = this;
  16006. //提供开关,就算加载也可以关闭
  16007. me.autoHeightEnabled = me.options.autoHeightEnabled !== false;
  16008. if (!me.autoHeightEnabled) {
  16009. return;
  16010. }
  16011. var bakOverflow,
  16012. lastHeight = 0,
  16013. options = me.options,
  16014. currentHeight,
  16015. timer;
  16016. function adjustHeight() {
  16017. var me = this;
  16018. clearTimeout(timer);
  16019. if(isFullscreen)return;
  16020. if (!me.queryCommandState || me.queryCommandState && me.queryCommandState('source') != 1) {
  16021. timer = setTimeout(function(){
  16022. var node = me.body.lastChild;
  16023. while(node && node.nodeType != 1){
  16024. node = node.previousSibling;
  16025. }
  16026. if(node && node.nodeType == 1){
  16027. node.style.clear = 'both';
  16028. currentHeight = Math.max(domUtils.getXY(node).y + node.offsetHeight + 25 ,Math.max(options.minFrameHeight, options.initialFrameHeight)) ;
  16029. if (currentHeight != lastHeight) {
  16030. if (currentHeight !== parseInt(me.iframe.parentNode.style.height)) {
  16031. me.iframe.parentNode.style.height = currentHeight + 'px';
  16032. }
  16033. me.body.style.height = currentHeight + 'px';
  16034. lastHeight = currentHeight;
  16035. }
  16036. domUtils.removeStyle(node,'clear');
  16037. }
  16038. },50)
  16039. }
  16040. }
  16041. var isFullscreen;
  16042. me.addListener('fullscreenchanged',function(cmd,f){
  16043. isFullscreen = f
  16044. });
  16045. me.addListener('destroy', function () {
  16046. me.removeListener('contentchange afterinserthtml keyup mouseup',adjustHeight)
  16047. });
  16048. me.enableAutoHeight = function () {
  16049. var me = this;
  16050. if (!me.autoHeightEnabled) {
  16051. return;
  16052. }
  16053. var doc = me.document;
  16054. me.autoHeightEnabled = true;
  16055. bakOverflow = doc.body.style.overflowY;
  16056. doc.body.style.overflowY = 'hidden';
  16057. me.addListener('contentchange afterinserthtml keyup mouseup',adjustHeight);
  16058. //ff不给事件算得不对
  16059. setTimeout(function () {
  16060. adjustHeight.call(me);
  16061. }, browser.gecko ? 100 : 0);
  16062. me.fireEvent('autoheightchanged', me.autoHeightEnabled);
  16063. };
  16064. me.disableAutoHeight = function () {
  16065. me.body.style.overflowY = bakOverflow || '';
  16066. me.removeListener('contentchange', adjustHeight);
  16067. me.removeListener('keyup', adjustHeight);
  16068. me.removeListener('mouseup', adjustHeight);
  16069. me.autoHeightEnabled = false;
  16070. me.fireEvent('autoheightchanged', me.autoHeightEnabled);
  16071. };
  16072. me.on('setHeight',function(){
  16073. me.disableAutoHeight()
  16074. });
  16075. me.addListener('ready', function () {
  16076. me.enableAutoHeight();
  16077. //trace:1764
  16078. var timer;
  16079. domUtils.on(browser.ie ? me.body : me.document, browser.webkit ? 'dragover' : 'drop', function () {
  16080. clearTimeout(timer);
  16081. timer = setTimeout(function () {
  16082. //trace:3681
  16083. adjustHeight.call(me);
  16084. }, 100);
  16085. });
  16086. //修复内容过多时,回到顶部,顶部内容被工具栏遮挡问题
  16087. var lastScrollY;
  16088. window.onscroll = function(){
  16089. if(lastScrollY === null){
  16090. lastScrollY = this.scrollY
  16091. }else if(this.scrollY == 0 && lastScrollY != 0){
  16092. me.window.scrollTo(0,0);
  16093. lastScrollY = null;
  16094. }
  16095. }
  16096. });
  16097. };
  16098. // plugins/autofloat.js
  16099. ///import core
  16100. ///commands 悬浮工具栏
  16101. ///commandsName AutoFloat,autoFloatEnabled
  16102. ///commandsTitle 悬浮工具栏
  16103. /**
  16104. * modified by chengchao01
  16105. * 注意: 引入此功能后,在IE6下会将body的背景图片覆盖掉!
  16106. */
  16107. UE.plugins['autofloat'] = function() {
  16108. var me = this,
  16109. lang = me.getLang();
  16110. me.setOpt({
  16111. topOffset:0
  16112. });
  16113. var optsAutoFloatEnabled = me.options.autoFloatEnabled !== false,
  16114. topOffset = me.options.topOffset;
  16115. //如果不固定toolbar的位置,则直接退出
  16116. if(!optsAutoFloatEnabled){
  16117. return;
  16118. }
  16119. var uiUtils = UE.ui.uiUtils,
  16120. LteIE6 = browser.ie && browser.version <= 6,
  16121. quirks = browser.quirks;
  16122. function checkHasUI(){
  16123. if(!UE.ui){
  16124. alert(lang.autofloatMsg);
  16125. return 0;
  16126. }
  16127. return 1;
  16128. }
  16129. function fixIE6FixedPos(){
  16130. var docStyle = document.body.style;
  16131. docStyle.backgroundImage = 'url("about:blank")';
  16132. docStyle.backgroundAttachment = 'fixed';
  16133. }
  16134. var bakCssText,
  16135. placeHolder = document.createElement('div'),
  16136. toolbarBox,orgTop,
  16137. getPosition,
  16138. flag =true; //ie7模式下需要偏移
  16139. function setFloating(){
  16140. var toobarBoxPos = domUtils.getXY(toolbarBox),
  16141. origalFloat = domUtils.getComputedStyle(toolbarBox,'position'),
  16142. origalLeft = domUtils.getComputedStyle(toolbarBox,'left');
  16143. toolbarBox.style.width = toolbarBox.offsetWidth + 'px';
  16144. toolbarBox.style.zIndex = me.options.zIndex * 1 + 1;
  16145. toolbarBox.parentNode.insertBefore(placeHolder, toolbarBox);
  16146. if (LteIE6 || (quirks && browser.ie)) {
  16147. if(toolbarBox.style.position != 'absolute'){
  16148. toolbarBox.style.position = 'absolute';
  16149. }
  16150. toolbarBox.style.top = (document.body.scrollTop||document.documentElement.scrollTop) - orgTop + topOffset + 'px';
  16151. } else {
  16152. if (browser.ie7Compat && flag) {
  16153. flag = false;
  16154. toolbarBox.style.left = domUtils.getXY(toolbarBox).x - document.documentElement.getBoundingClientRect().left+2 + 'px';
  16155. }
  16156. if(toolbarBox.style.position != 'fixed'){
  16157. toolbarBox.style.position = 'fixed';
  16158. toolbarBox.style.top = topOffset +"px";
  16159. ((origalFloat == 'absolute' || origalFloat == 'relative') && parseFloat(origalLeft)) && (toolbarBox.style.left = toobarBoxPos.x + 'px');
  16160. }
  16161. }
  16162. }
  16163. function unsetFloating(){
  16164. flag = true;
  16165. if(placeHolder.parentNode){
  16166. placeHolder.parentNode.removeChild(placeHolder);
  16167. }
  16168. toolbarBox.style.cssText = bakCssText;
  16169. }
  16170. function updateFloating(){
  16171. var rect3 = getPosition(me.container);
  16172. var offset=me.options.toolbarTopOffset||0;
  16173. if (rect3.top < 0 && rect3.bottom - toolbarBox.offsetHeight > offset) {
  16174. setFloating();
  16175. }else{
  16176. unsetFloating();
  16177. }
  16178. }
  16179. var defer_updateFloating = utils.defer(function(){
  16180. updateFloating();
  16181. },browser.ie ? 200 : 100,true);
  16182. me.addListener('destroy',function(){
  16183. domUtils.un(window, ['scroll','resize'], updateFloating);
  16184. me.removeListener('keydown', defer_updateFloating);
  16185. });
  16186. me.addListener('ready', function(){
  16187. if(checkHasUI(me)){
  16188. //加载了ui组件,但在new时,没有加载ui,导致编辑器实例上没有ui类,所以这里做判断
  16189. if(!me.ui){
  16190. return;
  16191. }
  16192. getPosition = uiUtils.getClientRect;
  16193. toolbarBox = me.ui.getDom('toolbarbox');
  16194. orgTop = getPosition(toolbarBox).top;
  16195. bakCssText = toolbarBox.style.cssText;
  16196. placeHolder.style.height = toolbarBox.offsetHeight + 'px';
  16197. if(LteIE6){
  16198. fixIE6FixedPos();
  16199. }
  16200. domUtils.on(window, ['scroll','resize'], updateFloating);
  16201. me.addListener('keydown', defer_updateFloating);
  16202. me.addListener('beforefullscreenchange', function (t, enabled){
  16203. if (enabled) {
  16204. unsetFloating();
  16205. }
  16206. });
  16207. me.addListener('fullscreenchanged', function (t, enabled){
  16208. if (!enabled) {
  16209. updateFloating();
  16210. }
  16211. });
  16212. me.addListener('sourcemodechanged', function (t, enabled){
  16213. setTimeout(function (){
  16214. updateFloating();
  16215. },0);
  16216. });
  16217. me.addListener("clearDoc",function(){
  16218. setTimeout(function(){
  16219. updateFloating();
  16220. },0);
  16221. })
  16222. }
  16223. });
  16224. };
  16225. // plugins/video.js
  16226. /**
  16227. * video插件, 为UEditor提供视频插入支持
  16228. * @file
  16229. * @since 1.2.6.1
  16230. */
  16231. UE.plugins['video'] = function (){
  16232. var me =this;
  16233. /**
  16234. * 创建插入视频字符窜
  16235. * @param url 视频地址
  16236. * @param width 视频宽度
  16237. * @param height 视频高度
  16238. * @param align 视频对齐
  16239. * @param toEmbed 是否以flash代替显示
  16240. * @param addParagraph 是否需要添加P 标签
  16241. */
  16242. function creatInsertStr(url,width,height,id,align,classname,type){
  16243. url = utils.unhtmlForUrl(url);
  16244. align = utils.unhtml(align);
  16245. classname = utils.unhtml(classname);
  16246. width = parseInt(width, 10) || 0;
  16247. height = parseInt(height, 10) || 0;
  16248. var str;
  16249. switch (type){
  16250. case 'image':
  16251. str = '<img ' + (id ? 'id="' + id+'"' : '') + ' width="'+ width +'" height="' + height + '" _url="'+url+'" class="' + classname.replace(/\bvideo-js\b/, '') + '"' +
  16252. ' 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 + ';': '')+'" />'
  16253. break;
  16254. case 'embed':
  16255. str = '<embed type="application/x-shockwave-flash" class="' + classname + '" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
  16256. ' src="' + utils.html(url) + '" width="' + width + '" height="' + height + '"' + (align ? ' style="float:' + align + '"': '') +
  16257. ' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >';
  16258. break;
  16259. case 'video':
  16260. var ext = url.substr(url.lastIndexOf('.') + 1);
  16261. if(ext == 'ogv') ext = 'ogg';
  16262. str = '<video' + (id ? ' id="' + id + '"' : '') + ' class="' + classname + ' video-js" ' + (align ? ' style="float:' + align + '"': '') +
  16263. ' controls preload="none" width="' + width + '" height="' + height + '" src="' + url + '" data-setup="{}">' +
  16264. '<source src="' + url + '" type="video/' + ext + '" /></video>';
  16265. break;
  16266. }
  16267. return str;
  16268. }
  16269. function switchImgAndVideo(root,img2video){
  16270. utils.each(root.getNodesByTagName(img2video ? 'img' : 'embed video'),function(node){
  16271. var className = node.getAttr('class');
  16272. if(className && className.indexOf('edui-faked-video') != -1){
  16273. var html = creatInsertStr( img2video ? node.getAttr('_url') : node.getAttr('src'),node.getAttr('width'),node.getAttr('height'),null,node.getStyle('float') || '',className,img2video ? 'embed':'image');
  16274. node.parentNode.replaceChild(UE.uNode.createElement(html),node);
  16275. }
  16276. if(className && className.indexOf('edui-upload-video') != -1){
  16277. var html = creatInsertStr( img2video ? node.getAttr('_url') : node.getAttr('src'),node.getAttr('width'),node.getAttr('height'),null,node.getStyle('float') || '',className,img2video ? 'video':'image');
  16278. node.parentNode.replaceChild(UE.uNode.createElement(html),node);
  16279. }
  16280. })
  16281. }
  16282. me.addOutputRule(function(root){
  16283. switchImgAndVideo(root,true)
  16284. });
  16285. me.addInputRule(function(root){
  16286. switchImgAndVideo(root)
  16287. });
  16288. /**
  16289. * 插入视频
  16290. * @command insertvideo
  16291. * @method execCommand
  16292. * @param { String } cmd 命令字符串
  16293. * @param { Object } videoAttr 键值对对象, 描述一个视频的所有属性
  16294. * @example
  16295. * ```javascript
  16296. *
  16297. * var videoAttr = {
  16298. * //视频地址
  16299. * url: 'http://www.youku.com/xxx',
  16300. * //视频宽高值, 单位px
  16301. * width: 200,
  16302. * height: 100
  16303. * };
  16304. *
  16305. * //editor 是编辑器实例
  16306. * //向编辑器插入单个视频
  16307. * editor.execCommand( 'insertvideo', videoAttr );
  16308. * ```
  16309. */
  16310. /**
  16311. * 插入视频
  16312. * @command insertvideo
  16313. * @method execCommand
  16314. * @param { String } cmd 命令字符串
  16315. * @param { Array } videoArr 需要插入的视频的数组, 其中的每一个元素都是一个键值对对象, 描述了一个视频的所有属性
  16316. * @example
  16317. * ```javascript
  16318. *
  16319. * var videoAttr1 = {
  16320. * //视频地址
  16321. * url: 'http://www.youku.com/xxx',
  16322. * //视频宽高值, 单位px
  16323. * width: 200,
  16324. * height: 100
  16325. * },
  16326. * videoAttr2 = {
  16327. * //视频地址
  16328. * url: 'http://www.youku.com/xxx',
  16329. * //视频宽高值, 单位px
  16330. * width: 200,
  16331. * height: 100
  16332. * }
  16333. *
  16334. * //editor 是编辑器实例
  16335. * //该方法将会向编辑器内插入两个视频
  16336. * editor.execCommand( 'insertvideo', [ videoAttr1, videoAttr2 ] );
  16337. * ```
  16338. */
  16339. /**
  16340. * 查询当前光标所在处是否是一个视频
  16341. * @command insertvideo
  16342. * @method queryCommandState
  16343. * @param { String } cmd 需要查询的命令字符串
  16344. * @return { int } 如果当前光标所在处的元素是一个视频对象, 则返回1,否则返回0
  16345. * @example
  16346. * ```javascript
  16347. *
  16348. * //editor 是编辑器实例
  16349. * editor.queryCommandState( 'insertvideo' );
  16350. * ```
  16351. */
  16352. me.commands["insertvideo"] = {
  16353. execCommand: function (cmd, videoObjs, type){
  16354. videoObjs = utils.isArray(videoObjs)?videoObjs:[videoObjs];
  16355. var html = [],id = 'tmpVedio', cl;
  16356. for(var i=0,vi,len = videoObjs.length;i<len;i++){
  16357. vi = videoObjs[i];
  16358. cl = (type == 'upload' ? 'video-js vjs-default-skin':'edui-faked-video');
  16359. html.push(creatInsertStr( vi.url, vi.width || 420, vi.height || 280, id + i, null, cl, 'video'));
  16360. }
  16361. me.execCommand("inserthtml",html.join(""),true);
  16362. var rng = this.selection.getRange();
  16363. for(var i= 0,len=videoObjs.length;i<len;i++){
  16364. var img = this.document.getElementById('tmpVedio'+i);
  16365. domUtils.removeAttributes(img,'id');
  16366. rng.selectNode(img).select();
  16367. me.execCommand('imagefloat',videoObjs[i].align)
  16368. }
  16369. },
  16370. queryCommandState : function(){
  16371. var img = me.selection.getRange().getClosedNode(),
  16372. flag = img && (img.className == "edui-faked-video" || img.className.indexOf("edui-upload-video")!=-1);
  16373. return flag ? 1 : 0;
  16374. }
  16375. };
  16376. };
  16377. // plugins/table.core.js
  16378. /**
  16379. * Created with JetBrains WebStorm.
  16380. * User: taoqili
  16381. * Date: 13-1-18
  16382. * Time: 上午11:09
  16383. * To change this template use File | Settings | File Templates.
  16384. */
  16385. /**
  16386. * UE表格操作类
  16387. * @param table
  16388. * @constructor
  16389. */
  16390. (function () {
  16391. var UETable = UE.UETable = function (table) {
  16392. this.table = table;
  16393. this.indexTable = [];
  16394. this.selectedTds = [];
  16395. this.cellsRange = {};
  16396. this.update(table);
  16397. };
  16398. //===以下为静态工具方法===
  16399. UETable.removeSelectedClass = function (cells) {
  16400. utils.each(cells, function (cell) {
  16401. domUtils.removeClasses(cell, "selectTdClass");
  16402. })
  16403. };
  16404. UETable.addSelectedClass = function (cells) {
  16405. utils.each(cells, function (cell) {
  16406. domUtils.addClass(cell, "selectTdClass");
  16407. })
  16408. };
  16409. UETable.isEmptyBlock = function (node) {
  16410. var reg = new RegExp(domUtils.fillChar, 'g');
  16411. if (node[browser.ie ? 'innerText' : 'textContent'].replace(/^\s*$/, '').replace(reg, '').length > 0) {
  16412. return 0;
  16413. }
  16414. for (var i in dtd.$isNotEmpty) if (dtd.$isNotEmpty.hasOwnProperty(i)) {
  16415. if (node.getElementsByTagName(i).length) {
  16416. return 0;
  16417. }
  16418. }
  16419. return 1;
  16420. };
  16421. UETable.getWidth = function (cell) {
  16422. if (!cell)return 0;
  16423. return parseInt(domUtils.getComputedStyle(cell, "width"), 10);
  16424. };
  16425. /**
  16426. * 获取单元格或者单元格组的“对齐”状态。 如果当前的检测对象是一个单元格组, 只有在满足所有单元格的 水平和竖直 对齐属性都相同的
  16427. * 条件时才会返回其状态值,否则将返回null; 如果当前只检测了一个单元格, 则直接返回当前单元格的对齐状态;
  16428. * @param table cell or table cells , 支持单个单元格dom对象 或者 单元格dom对象数组
  16429. * @return { align: 'left' || 'right' || 'center', valign: 'top' || 'middle' || 'bottom' } 或者 null
  16430. */
  16431. UETable.getTableCellAlignState = function ( cells ) {
  16432. !utils.isArray( cells ) && ( cells = [cells] );
  16433. var result = {},
  16434. status = ['align', 'valign'],
  16435. tempStatus = null,
  16436. isSame = true;//状态是否相同
  16437. utils.each( cells, function( cellNode ){
  16438. utils.each( status, function( currentState ){
  16439. tempStatus = cellNode.getAttribute( currentState );
  16440. if( !result[ currentState ] && tempStatus ) {
  16441. result[ currentState ] = tempStatus;
  16442. } else if( !result[ currentState ] || ( tempStatus !== result[ currentState ] ) ) {
  16443. isSame = false;
  16444. return false;
  16445. }
  16446. } );
  16447. return isSame;
  16448. });
  16449. return isSame ? result : null;
  16450. };
  16451. /**
  16452. * 根据当前选区获取相关的table信息
  16453. * @return {Object}
  16454. */
  16455. UETable.getTableItemsByRange = function (editor) {
  16456. var start = editor.selection.getStart();
  16457. //ff下会选中bookmark
  16458. if( start && start.id && start.id.indexOf('_baidu_bookmark_start_') === 0 && start.nextSibling) {
  16459. start = start.nextSibling;
  16460. }
  16461. //在table或者td边缘有可能存在选中tr的情况
  16462. var cell = start && domUtils.findParentByTagName(start, ["td", "th"], true),
  16463. tr = cell && cell.parentNode,
  16464. caption = start && domUtils.findParentByTagName(start, 'caption', true),
  16465. table = caption ? caption.parentNode : tr && tr.parentNode.parentNode;
  16466. return {
  16467. cell:cell,
  16468. tr:tr,
  16469. table:table,
  16470. caption:caption
  16471. }
  16472. };
  16473. UETable.getUETableBySelected = function (editor) {
  16474. var table = UETable.getTableItemsByRange(editor).table;
  16475. if (table && table.ueTable && table.ueTable.selectedTds.length) {
  16476. return table.ueTable;
  16477. }
  16478. return null;
  16479. };
  16480. UETable.getDefaultValue = function (editor, table) {
  16481. var borderMap = {
  16482. thin:'0px',
  16483. medium:'1px',
  16484. thick:'2px'
  16485. },
  16486. tableBorder, tdPadding, tdBorder, tmpValue;
  16487. if (!table) {
  16488. table = editor.document.createElement('table');
  16489. table.insertRow(0).insertCell(0).innerHTML = 'xxx';
  16490. editor.body.appendChild(table);
  16491. var td = table.getElementsByTagName('td')[0];
  16492. tmpValue = domUtils.getComputedStyle(table, 'border-left-width');
  16493. tableBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16494. tmpValue = domUtils.getComputedStyle(td, 'padding-left');
  16495. tdPadding = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16496. tmpValue = domUtils.getComputedStyle(td, 'border-left-width');
  16497. tdBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16498. domUtils.remove(table);
  16499. return {
  16500. tableBorder:tableBorder,
  16501. tdPadding:tdPadding,
  16502. tdBorder:tdBorder
  16503. };
  16504. } else {
  16505. td = table.getElementsByTagName('td')[0];
  16506. tmpValue = domUtils.getComputedStyle(table, 'border-left-width');
  16507. tableBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16508. tmpValue = domUtils.getComputedStyle(td, 'padding-left');
  16509. tdPadding = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16510. tmpValue = domUtils.getComputedStyle(td, 'border-left-width');
  16511. tdBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16512. return {
  16513. tableBorder:tableBorder,
  16514. tdPadding:tdPadding,
  16515. tdBorder:tdBorder
  16516. };
  16517. }
  16518. };
  16519. /**
  16520. * 根据当前点击的td或者table获取索引对象
  16521. * @param tdOrTable
  16522. */
  16523. UETable.getUETable = function (tdOrTable) {
  16524. var tag = tdOrTable.tagName.toLowerCase();
  16525. tdOrTable = (tag == "td" || tag == "th" || tag == 'caption') ? domUtils.findParentByTagName(tdOrTable, "table", true) : tdOrTable;
  16526. if (!tdOrTable.ueTable) {
  16527. tdOrTable.ueTable = new UETable(tdOrTable);
  16528. }
  16529. return tdOrTable.ueTable;
  16530. };
  16531. UETable.cloneCell = function(cell,ignoreMerge,keepPro){
  16532. if (!cell || utils.isString(cell)) {
  16533. return this.table.ownerDocument.createElement(cell || 'td');
  16534. }
  16535. var flag = domUtils.hasClass(cell, "selectTdClass");
  16536. flag && domUtils.removeClasses(cell, "selectTdClass");
  16537. var tmpCell = cell.cloneNode(true);
  16538. if (ignoreMerge) {
  16539. tmpCell.rowSpan = tmpCell.colSpan = 1;
  16540. }
  16541. //去掉宽高
  16542. !keepPro && domUtils.removeAttributes(tmpCell,'width height');
  16543. !keepPro && domUtils.removeAttributes(tmpCell,'style');
  16544. tmpCell.style.borderLeftStyle = "";
  16545. tmpCell.style.borderTopStyle = "";
  16546. tmpCell.style.borderLeftColor = cell.style.borderRightColor;
  16547. tmpCell.style.borderLeftWidth = cell.style.borderRightWidth;
  16548. tmpCell.style.borderTopColor = cell.style.borderBottomColor;
  16549. tmpCell.style.borderTopWidth = cell.style.borderBottomWidth;
  16550. flag && domUtils.addClass(cell, "selectTdClass");
  16551. return tmpCell;
  16552. }
  16553. UETable.prototype = {
  16554. getMaxRows:function () {
  16555. var rows = this.table.rows, maxLen = 1;
  16556. for (var i = 0, row; row = rows[i]; i++) {
  16557. var currentMax = 1;
  16558. for (var j = 0, cj; cj = row.cells[j++];) {
  16559. currentMax = Math.max(cj.rowSpan || 1, currentMax);
  16560. }
  16561. maxLen = Math.max(currentMax + i, maxLen);
  16562. }
  16563. return maxLen;
  16564. },
  16565. /**
  16566. * 获取当前表格的最大列数
  16567. */
  16568. getMaxCols:function () {
  16569. var rows = this.table.rows, maxLen = 0, cellRows = {};
  16570. for (var i = 0, row; row = rows[i]; i++) {
  16571. var cellsNum = 0;
  16572. for (var j = 0, cj; cj = row.cells[j++];) {
  16573. cellsNum += (cj.colSpan || 1);
  16574. if (cj.rowSpan && cj.rowSpan > 1) {
  16575. for (var k = 1; k < cj.rowSpan; k++) {
  16576. if (!cellRows['row_' + (i + k)]) {
  16577. cellRows['row_' + (i + k)] = (cj.colSpan || 1);
  16578. } else {
  16579. cellRows['row_' + (i + k)]++
  16580. }
  16581. }
  16582. }
  16583. }
  16584. cellsNum += cellRows['row_' + i] || 0;
  16585. maxLen = Math.max(cellsNum, maxLen);
  16586. }
  16587. return maxLen;
  16588. },
  16589. getCellColIndex:function (cell) {
  16590. },
  16591. /**
  16592. * 获取当前cell旁边的单元格,
  16593. * @param cell
  16594. * @param right
  16595. */
  16596. getHSideCell:function (cell, right) {
  16597. try {
  16598. var cellInfo = this.getCellInfo(cell),
  16599. previewRowIndex, previewColIndex;
  16600. var len = this.selectedTds.length,
  16601. range = this.cellsRange;
  16602. //首行或者首列没有前置单元格
  16603. if ((!right && (!len ? !cellInfo.colIndex : !range.beginColIndex)) || (right && (!len ? (cellInfo.colIndex == (this.colsNum - 1)) : (range.endColIndex == this.colsNum - 1)))) return null;
  16604. previewRowIndex = !len ? cellInfo.rowIndex : range.beginRowIndex;
  16605. previewColIndex = !right ? ( !len ? (cellInfo.colIndex < 1 ? 0 : (cellInfo.colIndex - 1)) : range.beginColIndex - 1)
  16606. : ( !len ? cellInfo.colIndex + 1 : range.endColIndex + 1);
  16607. return this.getCell(this.indexTable[previewRowIndex][previewColIndex].rowIndex, this.indexTable[previewRowIndex][previewColIndex].cellIndex);
  16608. } catch (e) {
  16609. showError(e);
  16610. }
  16611. },
  16612. getTabNextCell:function (cell, preRowIndex) {
  16613. var cellInfo = this.getCellInfo(cell),
  16614. rowIndex = preRowIndex || cellInfo.rowIndex,
  16615. colIndex = cellInfo.colIndex + 1 + (cellInfo.colSpan - 1),
  16616. nextCell;
  16617. try {
  16618. nextCell = this.getCell(this.indexTable[rowIndex][colIndex].rowIndex, this.indexTable[rowIndex][colIndex].cellIndex);
  16619. } catch (e) {
  16620. try {
  16621. rowIndex = rowIndex * 1 + 1;
  16622. colIndex = 0;
  16623. nextCell = this.getCell(this.indexTable[rowIndex][colIndex].rowIndex, this.indexTable[rowIndex][colIndex].cellIndex);
  16624. } catch (e) {
  16625. }
  16626. }
  16627. return nextCell;
  16628. },
  16629. /**
  16630. * 获取视觉上的后置单元格
  16631. * @param cell
  16632. * @param bottom
  16633. */
  16634. getVSideCell:function (cell, bottom, ignoreRange) {
  16635. try {
  16636. var cellInfo = this.getCellInfo(cell),
  16637. nextRowIndex, nextColIndex;
  16638. var len = this.selectedTds.length && !ignoreRange,
  16639. range = this.cellsRange;
  16640. //末行或者末列没有后置单元格
  16641. if ((!bottom && (cellInfo.rowIndex == 0)) || (bottom && (!len ? (cellInfo.rowIndex + cellInfo.rowSpan > this.rowsNum - 1) : (range.endRowIndex == this.rowsNum - 1)))) return null;
  16642. nextRowIndex = !bottom ? ( !len ? cellInfo.rowIndex - 1 : range.beginRowIndex - 1)
  16643. : ( !len ? (cellInfo.rowIndex + cellInfo.rowSpan) : range.endRowIndex + 1);
  16644. nextColIndex = !len ? cellInfo.colIndex : range.beginColIndex;
  16645. return this.getCell(this.indexTable[nextRowIndex][nextColIndex].rowIndex, this.indexTable[nextRowIndex][nextColIndex].cellIndex);
  16646. } catch (e) {
  16647. showError(e);
  16648. }
  16649. },
  16650. /**
  16651. * 获取相同结束位置的单元格,xOrY指代了是获取x轴相同还是y轴相同
  16652. */
  16653. getSameEndPosCells:function (cell, xOrY) {
  16654. try {
  16655. var flag = (xOrY.toLowerCase() === "x"),
  16656. end = domUtils.getXY(cell)[flag ? 'x' : 'y'] + cell["offset" + (flag ? 'Width' : 'Height')],
  16657. rows = this.table.rows,
  16658. cells = null, 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 tmpEnd = domUtils.getXY(tmpCell)[flag ? 'x' : 'y'] + tmpCell["offset" + (flag ? 'Width' : 'Height')];
  16663. //对应行的td已经被上面行rowSpan了
  16664. if (tmpEnd > end && flag) break;
  16665. if (cell == tmpCell || end == tmpEnd) {
  16666. //只获取单一的单元格
  16667. //todo 仅获取单一单元格在特定情况下会造成returns为空,从而影响后续的拖拽实现,修正这个。需考虑性能
  16668. if (tmpCell[flag ? "colSpan" : "rowSpan"] == 1) {
  16669. returns.push(tmpCell);
  16670. }
  16671. if (flag) break;
  16672. }
  16673. }
  16674. }
  16675. return returns;
  16676. } catch (e) {
  16677. showError(e);
  16678. }
  16679. },
  16680. setCellContent:function (cell, content) {
  16681. cell.innerHTML = content || (browser.ie ? domUtils.fillChar : "<br />");
  16682. },
  16683. cloneCell:UETable.cloneCell,
  16684. /**
  16685. * 获取跟当前单元格的右边竖线为左边的所有未合并单元格
  16686. */
  16687. getSameStartPosXCells:function (cell) {
  16688. try {
  16689. var start = domUtils.getXY(cell).x + cell.offsetWidth,
  16690. rows = this.table.rows, cells , returns = [];
  16691. for (var i = 0; i < this.rowsNum; i++) {
  16692. cells = rows[i].cells;
  16693. for (var j = 0, tmpCell; tmpCell = cells[j++];) {
  16694. var tmpStart = domUtils.getXY(tmpCell).x;
  16695. if (tmpStart > start) break;
  16696. if (tmpStart == start && tmpCell.colSpan == 1) {
  16697. returns.push(tmpCell);
  16698. break;
  16699. }
  16700. }
  16701. }
  16702. return returns;
  16703. } catch (e) {
  16704. showError(e);
  16705. }
  16706. },
  16707. /**
  16708. * 更新table对应的索引表
  16709. */
  16710. update:function (table) {
  16711. this.table = table || this.table;
  16712. this.selectedTds = [];
  16713. this.cellsRange = {};
  16714. this.indexTable = [];
  16715. var rows = this.table.rows,
  16716. rowsNum = this.getMaxRows(),
  16717. dNum = rowsNum - rows.length,
  16718. colsNum = this.getMaxCols();
  16719. while (dNum--) {
  16720. this.table.insertRow(rows.length);
  16721. }
  16722. this.rowsNum = rowsNum;
  16723. this.colsNum = colsNum;
  16724. for (var i = 0, len = rows.length; i < len; i++) {
  16725. this.indexTable[i] = new Array(colsNum);
  16726. }
  16727. //填充索引表
  16728. for (var rowIndex = 0, row; row = rows[rowIndex]; rowIndex++) {
  16729. for (var cellIndex = 0, cell, cells = row.cells; cell = cells[cellIndex]; cellIndex++) {
  16730. //修正整行被rowSpan时导致的行数计算错误
  16731. if (cell.rowSpan > rowsNum) {
  16732. cell.rowSpan = rowsNum;
  16733. }
  16734. var colIndex = cellIndex,
  16735. rowSpan = cell.rowSpan || 1,
  16736. colSpan = cell.colSpan || 1;
  16737. //当已经被上一行rowSpan或者被前一列colSpan了,则跳到下一个单元格进行
  16738. while (this.indexTable[rowIndex][colIndex]) colIndex++;
  16739. for (var j = 0; j < rowSpan; j++) {
  16740. for (var k = 0; k < colSpan; k++) {
  16741. this.indexTable[rowIndex + j][colIndex + k] = {
  16742. rowIndex:rowIndex,
  16743. cellIndex:cellIndex,
  16744. colIndex:colIndex,
  16745. rowSpan:rowSpan,
  16746. colSpan:colSpan
  16747. }
  16748. }
  16749. }
  16750. }
  16751. }
  16752. //修复残缺td
  16753. for (j = 0; j < rowsNum; j++) {
  16754. for (k = 0; k < colsNum; k++) {
  16755. if (this.indexTable[j][k] === undefined) {
  16756. row = rows[j];
  16757. cell = row.cells[row.cells.length - 1];
  16758. cell = cell ? cell.cloneNode(true) : this.table.ownerDocument.createElement("td");
  16759. this.setCellContent(cell);
  16760. if (cell.colSpan !== 1)cell.colSpan = 1;
  16761. if (cell.rowSpan !== 1)cell.rowSpan = 1;
  16762. row.appendChild(cell);
  16763. this.indexTable[j][k] = {
  16764. rowIndex:j,
  16765. cellIndex:cell.cellIndex,
  16766. colIndex:k,
  16767. rowSpan:1,
  16768. colSpan:1
  16769. }
  16770. }
  16771. }
  16772. }
  16773. //当框选后删除行或者列后撤销,需要重建选区。
  16774. var tds = domUtils.getElementsByTagName(this.table, "td"),
  16775. selectTds = [];
  16776. utils.each(tds, function (td) {
  16777. if (domUtils.hasClass(td, "selectTdClass")) {
  16778. selectTds.push(td);
  16779. }
  16780. });
  16781. if (selectTds.length) {
  16782. var start = selectTds[0],
  16783. end = selectTds[selectTds.length - 1],
  16784. startInfo = this.getCellInfo(start),
  16785. endInfo = this.getCellInfo(end);
  16786. this.selectedTds = selectTds;
  16787. this.cellsRange = {
  16788. beginRowIndex:startInfo.rowIndex,
  16789. beginColIndex:startInfo.colIndex,
  16790. endRowIndex:endInfo.rowIndex + endInfo.rowSpan - 1,
  16791. endColIndex:endInfo.colIndex + endInfo.colSpan - 1
  16792. };
  16793. }
  16794. //给第一行设置firstRow的样式名称,在排序图标的样式上使用到
  16795. if(!domUtils.hasClass(this.table.rows[0], "firstRow")) {
  16796. domUtils.addClass(this.table.rows[0], "firstRow");
  16797. for(var i = 1; i< this.table.rows.length; i++) {
  16798. domUtils.removeClasses(this.table.rows[i], "firstRow");
  16799. }
  16800. }
  16801. },
  16802. /**
  16803. * 获取单元格的索引信息
  16804. */
  16805. getCellInfo:function (cell) {
  16806. if (!cell) return;
  16807. var cellIndex = cell.cellIndex,
  16808. rowIndex = cell.parentNode.rowIndex,
  16809. rowInfo = this.indexTable[rowIndex],
  16810. numCols = this.colsNum;
  16811. for (var colIndex = cellIndex; colIndex < numCols; colIndex++) {
  16812. var cellInfo = rowInfo[colIndex];
  16813. if (cellInfo.rowIndex === rowIndex && cellInfo.cellIndex === cellIndex) {
  16814. return cellInfo;
  16815. }
  16816. }
  16817. },
  16818. /**
  16819. * 根据行列号获取单元格
  16820. */
  16821. getCell:function (rowIndex, cellIndex) {
  16822. return rowIndex < this.rowsNum && this.table.rows[rowIndex].cells[cellIndex] || null;
  16823. },
  16824. /**
  16825. * 删除单元格
  16826. */
  16827. deleteCell:function (cell, rowIndex) {
  16828. rowIndex = typeof rowIndex == 'number' ? rowIndex : cell.parentNode.rowIndex;
  16829. var row = this.table.rows[rowIndex];
  16830. row.deleteCell(cell.cellIndex);
  16831. },
  16832. /**
  16833. * 根据始末两个单元格获取被框选的所有单元格范围
  16834. */
  16835. getCellsRange:function (cellA, cellB) {
  16836. function checkRange(beginRowIndex, beginColIndex, endRowIndex, endColIndex) {
  16837. var tmpBeginRowIndex = beginRowIndex,
  16838. tmpBeginColIndex = beginColIndex,
  16839. tmpEndRowIndex = endRowIndex,
  16840. tmpEndColIndex = endColIndex,
  16841. cellInfo, colIndex, rowIndex;
  16842. // 通过indexTable检查是否存在超出TableRange上边界的情况
  16843. if (beginRowIndex > 0) {
  16844. for (colIndex = beginColIndex; colIndex < endColIndex; colIndex++) {
  16845. cellInfo = me.indexTable[beginRowIndex][colIndex];
  16846. rowIndex = cellInfo.rowIndex;
  16847. if (rowIndex < beginRowIndex) {
  16848. tmpBeginRowIndex = Math.min(rowIndex, tmpBeginRowIndex);
  16849. }
  16850. }
  16851. }
  16852. // 通过indexTable检查是否存在超出TableRange右边界的情况
  16853. if (endColIndex < me.colsNum) {
  16854. for (rowIndex = beginRowIndex; rowIndex < endRowIndex; rowIndex++) {
  16855. cellInfo = me.indexTable[rowIndex][endColIndex];
  16856. colIndex = cellInfo.colIndex + cellInfo.colSpan - 1;
  16857. if (colIndex > endColIndex) {
  16858. tmpEndColIndex = Math.max(colIndex, tmpEndColIndex);
  16859. }
  16860. }
  16861. }
  16862. // 检查是否有超出TableRange下边界的情况
  16863. if (endRowIndex < me.rowsNum) {
  16864. for (colIndex = beginColIndex; colIndex < endColIndex; colIndex++) {
  16865. cellInfo = me.indexTable[endRowIndex][colIndex];
  16866. rowIndex = cellInfo.rowIndex + cellInfo.rowSpan - 1;
  16867. if (rowIndex > endRowIndex) {
  16868. tmpEndRowIndex = Math.max(rowIndex, tmpEndRowIndex);
  16869. }
  16870. }
  16871. }
  16872. // 检查是否有超出TableRange左边界的情况
  16873. if (beginColIndex > 0) {
  16874. for (rowIndex = beginRowIndex; rowIndex < endRowIndex; rowIndex++) {
  16875. cellInfo = me.indexTable[rowIndex][beginColIndex];
  16876. colIndex = cellInfo.colIndex;
  16877. if (colIndex < beginColIndex) {
  16878. tmpBeginColIndex = Math.min(cellInfo.colIndex, tmpBeginColIndex);
  16879. }
  16880. }
  16881. }
  16882. //递归调用直至所有完成所有框选单元格的扩展
  16883. if (tmpBeginRowIndex != beginRowIndex || tmpBeginColIndex != beginColIndex || tmpEndRowIndex != endRowIndex || tmpEndColIndex != endColIndex) {
  16884. return checkRange(tmpBeginRowIndex, tmpBeginColIndex, tmpEndRowIndex, tmpEndColIndex);
  16885. } else {
  16886. // 不需要扩展TableRange的情况
  16887. return {
  16888. beginRowIndex:beginRowIndex,
  16889. beginColIndex:beginColIndex,
  16890. endRowIndex:endRowIndex,
  16891. endColIndex:endColIndex
  16892. };
  16893. }
  16894. }
  16895. try {
  16896. var me = this,
  16897. cellAInfo = me.getCellInfo(cellA);
  16898. if (cellA === cellB) {
  16899. return {
  16900. beginRowIndex:cellAInfo.rowIndex,
  16901. beginColIndex:cellAInfo.colIndex,
  16902. endRowIndex:cellAInfo.rowIndex + cellAInfo.rowSpan - 1,
  16903. endColIndex:cellAInfo.colIndex + cellAInfo.colSpan - 1
  16904. };
  16905. }
  16906. var cellBInfo = me.getCellInfo(cellB);
  16907. // 计算TableRange的四个边
  16908. var beginRowIndex = Math.min(cellAInfo.rowIndex, cellBInfo.rowIndex),
  16909. beginColIndex = Math.min(cellAInfo.colIndex, cellBInfo.colIndex),
  16910. endRowIndex = Math.max(cellAInfo.rowIndex + cellAInfo.rowSpan - 1, cellBInfo.rowIndex + cellBInfo.rowSpan - 1),
  16911. endColIndex = Math.max(cellAInfo.colIndex + cellAInfo.colSpan - 1, cellBInfo.colIndex + cellBInfo.colSpan - 1);
  16912. return checkRange(beginRowIndex, beginColIndex, endRowIndex, endColIndex);
  16913. } catch (e) {
  16914. //throw e;
  16915. }
  16916. },
  16917. /**
  16918. * 依据cellsRange获取对应的单元格集合
  16919. */
  16920. getCells:function (range) {
  16921. //每次获取cells之前必须先清除上次的选择,否则会对后续获取操作造成影响
  16922. this.clearSelected();
  16923. var beginRowIndex = range.beginRowIndex,
  16924. beginColIndex = range.beginColIndex,
  16925. endRowIndex = range.endRowIndex,
  16926. endColIndex = range.endColIndex,
  16927. cellInfo, rowIndex, colIndex, tdHash = {}, returnTds = [];
  16928. for (var i = beginRowIndex; i <= endRowIndex; i++) {
  16929. for (var j = beginColIndex; j <= endColIndex; j++) {
  16930. cellInfo = this.indexTable[i][j];
  16931. rowIndex = cellInfo.rowIndex;
  16932. colIndex = cellInfo.colIndex;
  16933. // 如果Cells里已经包含了此Cell则跳过
  16934. var key = rowIndex + '|' + colIndex;
  16935. if (tdHash[key]) continue;
  16936. tdHash[key] = 1;
  16937. if (rowIndex < i || colIndex < j || rowIndex + cellInfo.rowSpan - 1 > endRowIndex || colIndex + cellInfo.colSpan - 1 > endColIndex) {
  16938. return null;
  16939. }
  16940. returnTds.push(this.getCell(rowIndex, cellInfo.cellIndex));
  16941. }
  16942. }
  16943. return returnTds;
  16944. },
  16945. /**
  16946. * 清理已经选中的单元格
  16947. */
  16948. clearSelected:function () {
  16949. UETable.removeSelectedClass(this.selectedTds);
  16950. this.selectedTds = [];
  16951. this.cellsRange = {};
  16952. },
  16953. /**
  16954. * 根据range设置已经选中的单元格
  16955. */
  16956. setSelected:function (range) {
  16957. var cells = this.getCells(range);
  16958. UETable.addSelectedClass(cells);
  16959. this.selectedTds = cells;
  16960. this.cellsRange = range;
  16961. },
  16962. isFullRow:function () {
  16963. var range = this.cellsRange;
  16964. return (range.endColIndex - range.beginColIndex + 1) == this.colsNum;
  16965. },
  16966. isFullCol:function () {
  16967. var range = this.cellsRange,
  16968. table = this.table,
  16969. ths = table.getElementsByTagName("th"),
  16970. rows = range.endRowIndex - range.beginRowIndex + 1;
  16971. return !ths.length ? rows == this.rowsNum : rows == this.rowsNum || (rows == this.rowsNum - 1);
  16972. },
  16973. /**
  16974. * 获取视觉上的前置单元格,默认是左边,top传入时
  16975. * @param cell
  16976. * @param top
  16977. */
  16978. getNextCell:function (cell, bottom, ignoreRange) {
  16979. try {
  16980. var cellInfo = this.getCellInfo(cell),
  16981. nextRowIndex, nextColIndex;
  16982. var len = this.selectedTds.length && !ignoreRange,
  16983. range = this.cellsRange;
  16984. //末行或者末列没有后置单元格
  16985. if ((!bottom && (cellInfo.rowIndex == 0)) || (bottom && (!len ? (cellInfo.rowIndex + cellInfo.rowSpan > this.rowsNum - 1) : (range.endRowIndex == this.rowsNum - 1)))) return null;
  16986. nextRowIndex = !bottom ? ( !len ? cellInfo.rowIndex - 1 : range.beginRowIndex - 1)
  16987. : ( !len ? (cellInfo.rowIndex + cellInfo.rowSpan) : range.endRowIndex + 1);
  16988. nextColIndex = !len ? cellInfo.colIndex : range.beginColIndex;
  16989. return this.getCell(this.indexTable[nextRowIndex][nextColIndex].rowIndex, this.indexTable[nextRowIndex][nextColIndex].cellIndex);
  16990. } catch (e) {
  16991. showError(e);
  16992. }
  16993. },
  16994. getPreviewCell:function (cell, top) {
  16995. try {
  16996. var cellInfo = this.getCellInfo(cell),
  16997. previewRowIndex, previewColIndex;
  16998. var len = this.selectedTds.length,
  16999. range = this.cellsRange;
  17000. //首行或者首列没有前置单元格
  17001. if ((!top && (!len ? !cellInfo.colIndex : !range.beginColIndex)) || (top && (!len ? (cellInfo.rowIndex > (this.colsNum - 1)) : (range.endColIndex == this.colsNum - 1)))) return null;
  17002. previewRowIndex = !top ? ( !len ? cellInfo.rowIndex : range.beginRowIndex )
  17003. : ( !len ? (cellInfo.rowIndex < 1 ? 0 : (cellInfo.rowIndex - 1)) : range.beginRowIndex);
  17004. previewColIndex = !top ? ( !len ? (cellInfo.colIndex < 1 ? 0 : (cellInfo.colIndex - 1)) : range.beginColIndex - 1)
  17005. : ( !len ? cellInfo.colIndex : range.endColIndex + 1);
  17006. return this.getCell(this.indexTable[previewRowIndex][previewColIndex].rowIndex, this.indexTable[previewRowIndex][previewColIndex].cellIndex);
  17007. } catch (e) {
  17008. showError(e);
  17009. }
  17010. },
  17011. /**
  17012. * 移动单元格中的内容
  17013. */
  17014. moveContent:function (cellTo, cellFrom) {
  17015. if (UETable.isEmptyBlock(cellFrom)) return;
  17016. if (UETable.isEmptyBlock(cellTo)) {
  17017. cellTo.innerHTML = cellFrom.innerHTML;
  17018. return;
  17019. }
  17020. var child = cellTo.lastChild;
  17021. if (child.nodeType == 3 || !dtd.$block[child.tagName]) {
  17022. cellTo.appendChild(cellTo.ownerDocument.createElement('br'))
  17023. }
  17024. while (child = cellFrom.firstChild) {
  17025. cellTo.appendChild(child);
  17026. }
  17027. },
  17028. /**
  17029. * 向右合并单元格
  17030. */
  17031. mergeRight:function (cell) {
  17032. var cellInfo = this.getCellInfo(cell),
  17033. rightColIndex = cellInfo.colIndex + cellInfo.colSpan,
  17034. rightCellInfo = this.indexTable[cellInfo.rowIndex][rightColIndex],
  17035. rightCell = this.getCell(rightCellInfo.rowIndex, rightCellInfo.cellIndex);
  17036. //合并
  17037. cell.colSpan = cellInfo.colSpan + rightCellInfo.colSpan;
  17038. //被合并的单元格不应存在宽度属性
  17039. cell.removeAttribute("width");
  17040. //移动内容
  17041. this.moveContent(cell, rightCell);
  17042. //删掉被合并的Cell
  17043. this.deleteCell(rightCell, rightCellInfo.rowIndex);
  17044. this.update();
  17045. },
  17046. /**
  17047. * 向下合并单元格
  17048. */
  17049. mergeDown:function (cell) {
  17050. var cellInfo = this.getCellInfo(cell),
  17051. downRowIndex = cellInfo.rowIndex + cellInfo.rowSpan,
  17052. downCellInfo = this.indexTable[downRowIndex][cellInfo.colIndex],
  17053. downCell = this.getCell(downCellInfo.rowIndex, downCellInfo.cellIndex);
  17054. cell.rowSpan = cellInfo.rowSpan + downCellInfo.rowSpan;
  17055. cell.removeAttribute("height");
  17056. this.moveContent(cell, downCell);
  17057. this.deleteCell(downCell, downCellInfo.rowIndex);
  17058. this.update();
  17059. },
  17060. /**
  17061. * 合并整个range中的内容
  17062. */
  17063. mergeRange:function () {
  17064. //由于合并操作可以在任意时刻进行,所以无法通过鼠标位置等信息实时生成range,只能通过缓存实例中的cellsRange对象来访问
  17065. var range = this.cellsRange,
  17066. leftTopCell = this.getCell(range.beginRowIndex, this.indexTable[range.beginRowIndex][range.beginColIndex].cellIndex);
  17067. if (leftTopCell.tagName == "TH" && range.endRowIndex !== range.beginRowIndex) {
  17068. var index = this.indexTable,
  17069. info = this.getCellInfo(leftTopCell);
  17070. leftTopCell = this.getCell(1, index[1][info.colIndex].cellIndex);
  17071. range = this.getCellsRange(leftTopCell, this.getCell(index[this.rowsNum - 1][info.colIndex].rowIndex, index[this.rowsNum - 1][info.colIndex].cellIndex));
  17072. }
  17073. // 删除剩余的Cells
  17074. var cells = this.getCells(range);
  17075. for(var i= 0,ci;ci=cells[i++];){
  17076. if (ci !== leftTopCell) {
  17077. this.moveContent(leftTopCell, ci);
  17078. this.deleteCell(ci);
  17079. }
  17080. }
  17081. // 修改左上角Cell的rowSpan和colSpan,并调整宽度属性设置
  17082. leftTopCell.rowSpan = range.endRowIndex - range.beginRowIndex + 1;
  17083. leftTopCell.rowSpan > 1 && leftTopCell.removeAttribute("height");
  17084. leftTopCell.colSpan = range.endColIndex - range.beginColIndex + 1;
  17085. leftTopCell.colSpan > 1 && leftTopCell.removeAttribute("width");
  17086. if (leftTopCell.rowSpan == this.rowsNum && leftTopCell.colSpan != 1) {
  17087. leftTopCell.colSpan = 1;
  17088. }
  17089. if (leftTopCell.colSpan == this.colsNum && leftTopCell.rowSpan != 1) {
  17090. var rowIndex = leftTopCell.parentNode.rowIndex;
  17091. //解决IE下的表格操作问题
  17092. if( this.table.deleteRow ) {
  17093. for (var i = rowIndex+ 1, curIndex=rowIndex+ 1, len=leftTopCell.rowSpan; i < len; i++) {
  17094. this.table.deleteRow(curIndex);
  17095. }
  17096. } else {
  17097. for (var i = 0, len=leftTopCell.rowSpan - 1; i < len; i++) {
  17098. var row = this.table.rows[rowIndex + 1];
  17099. row.parentNode.removeChild(row);
  17100. }
  17101. }
  17102. leftTopCell.rowSpan = 1;
  17103. }
  17104. this.update();
  17105. },
  17106. /**
  17107. * 插入一行单元格
  17108. */
  17109. insertRow:function (rowIndex, sourceCell) {
  17110. var numCols = this.colsNum,
  17111. table = this.table,
  17112. row = table.insertRow(rowIndex), cell,
  17113. isInsertTitle = typeof sourceCell == 'string' && sourceCell.toUpperCase() == 'TH';
  17114. function replaceTdToTh(colIndex, cell, tableRow) {
  17115. if (colIndex == 0) {
  17116. var tr = tableRow.nextSibling || tableRow.previousSibling,
  17117. th = tr.cells[colIndex];
  17118. if (th.tagName == 'TH') {
  17119. th = cell.ownerDocument.createElement("th");
  17120. th.appendChild(cell.firstChild);
  17121. tableRow.insertBefore(th, cell);
  17122. domUtils.remove(cell)
  17123. }
  17124. }else{
  17125. if (cell.tagName == 'TH') {
  17126. var td = cell.ownerDocument.createElement("td");
  17127. td.appendChild(cell.firstChild);
  17128. tableRow.insertBefore(td, cell);
  17129. domUtils.remove(cell)
  17130. }
  17131. }
  17132. }
  17133. //首行直接插入,无需考虑部分单元格被rowspan的情况
  17134. if (rowIndex == 0 || rowIndex == this.rowsNum) {
  17135. for (var colIndex = 0; colIndex < numCols; colIndex++) {
  17136. cell = this.cloneCell(sourceCell, true);
  17137. this.setCellContent(cell);
  17138. cell.getAttribute('vAlign') && cell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17139. row.appendChild(cell);
  17140. if(!isInsertTitle) replaceTdToTh(colIndex, cell, row);
  17141. }
  17142. } else {
  17143. var infoRow = this.indexTable[rowIndex],
  17144. cellIndex = 0;
  17145. for (colIndex = 0; colIndex < numCols; colIndex++) {
  17146. var cellInfo = infoRow[colIndex];
  17147. //如果存在某个单元格的rowspan穿过待插入行的位置,则修改该单元格的rowspan即可,无需插入单元格
  17148. if (cellInfo.rowIndex < rowIndex) {
  17149. cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
  17150. cell.rowSpan = cellInfo.rowSpan + 1;
  17151. } else {
  17152. cell = this.cloneCell(sourceCell, true);
  17153. this.setCellContent(cell);
  17154. row.appendChild(cell);
  17155. }
  17156. if(!isInsertTitle) replaceTdToTh(colIndex, cell, row);
  17157. }
  17158. }
  17159. //框选时插入不触发contentchange,需要手动更新索引。
  17160. this.update();
  17161. return row;
  17162. },
  17163. /**
  17164. * 删除一行单元格
  17165. * @param rowIndex
  17166. */
  17167. deleteRow:function (rowIndex) {
  17168. var row = this.table.rows[rowIndex],
  17169. infoRow = this.indexTable[rowIndex],
  17170. colsNum = this.colsNum,
  17171. count = 0; //处理计数
  17172. for (var colIndex = 0; colIndex < colsNum;) {
  17173. var cellInfo = infoRow[colIndex],
  17174. cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
  17175. if (cell.rowSpan > 1) {
  17176. if (cellInfo.rowIndex == rowIndex) {
  17177. var clone = cell.cloneNode(true);
  17178. clone.rowSpan = cell.rowSpan - 1;
  17179. clone.innerHTML = "";
  17180. cell.rowSpan = 1;
  17181. var nextRowIndex = rowIndex + 1,
  17182. nextRow = this.table.rows[nextRowIndex],
  17183. insertCellIndex,
  17184. preMerged = this.getPreviewMergedCellsNum(nextRowIndex, colIndex) - count;
  17185. if (preMerged < colIndex) {
  17186. insertCellIndex = colIndex - preMerged - 1;
  17187. //nextRow.insertCell(insertCellIndex);
  17188. domUtils.insertAfter(nextRow.cells[insertCellIndex], clone);
  17189. } else {
  17190. if (nextRow.cells.length) nextRow.insertBefore(clone, nextRow.cells[0])
  17191. }
  17192. count += 1;
  17193. //cell.parentNode.removeChild(cell);
  17194. }
  17195. }
  17196. colIndex += cell.colSpan || 1;
  17197. }
  17198. var deleteTds = [], cacheMap = {};
  17199. for (colIndex = 0; colIndex < colsNum; colIndex++) {
  17200. var tmpRowIndex = infoRow[colIndex].rowIndex,
  17201. tmpCellIndex = infoRow[colIndex].cellIndex,
  17202. key = tmpRowIndex + "_" + tmpCellIndex;
  17203. if (cacheMap[key])continue;
  17204. cacheMap[key] = 1;
  17205. cell = this.getCell(tmpRowIndex, tmpCellIndex);
  17206. deleteTds.push(cell);
  17207. }
  17208. var mergeTds = [];
  17209. utils.each(deleteTds, function (td) {
  17210. if (td.rowSpan == 1) {
  17211. td.parentNode.removeChild(td);
  17212. } else {
  17213. mergeTds.push(td);
  17214. }
  17215. });
  17216. utils.each(mergeTds, function (td) {
  17217. td.rowSpan--;
  17218. });
  17219. row.parentNode.removeChild(row);
  17220. //浏览器方法本身存在bug,采用自定义方法删除
  17221. //this.table.deleteRow(rowIndex);
  17222. this.update();
  17223. },
  17224. insertCol:function (colIndex, sourceCell, defaultValue) {
  17225. var rowsNum = this.rowsNum,
  17226. rowIndex = 0,
  17227. tableRow, cell,
  17228. backWidth = parseInt((this.table.offsetWidth - (this.colsNum + 1) * 20 - (this.colsNum + 1)) / (this.colsNum + 1), 10),
  17229. isInsertTitleCol = typeof sourceCell == 'string' && sourceCell.toUpperCase() == 'TH';
  17230. function replaceTdToTh(rowIndex, cell, tableRow) {
  17231. if (rowIndex == 0) {
  17232. var th = cell.nextSibling || cell.previousSibling;
  17233. if (th.tagName == 'TH') {
  17234. th = cell.ownerDocument.createElement("th");
  17235. th.appendChild(cell.firstChild);
  17236. tableRow.insertBefore(th, cell);
  17237. domUtils.remove(cell)
  17238. }
  17239. }else{
  17240. if (cell.tagName == 'TH') {
  17241. var td = cell.ownerDocument.createElement("td");
  17242. td.appendChild(cell.firstChild);
  17243. tableRow.insertBefore(td, cell);
  17244. domUtils.remove(cell)
  17245. }
  17246. }
  17247. }
  17248. var preCell;
  17249. if (colIndex == 0 || colIndex == this.colsNum) {
  17250. for (; rowIndex < rowsNum; rowIndex++) {
  17251. tableRow = this.table.rows[rowIndex];
  17252. preCell = tableRow.cells[colIndex == 0 ? colIndex : tableRow.cells.length];
  17253. cell = this.cloneCell(sourceCell, true); //tableRow.insertCell(colIndex == 0 ? colIndex : tableRow.cells.length);
  17254. this.setCellContent(cell);
  17255. cell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17256. preCell && cell.setAttribute('width', preCell.getAttribute('width'));
  17257. if (!colIndex) {
  17258. tableRow.insertBefore(cell, tableRow.cells[0]);
  17259. } else {
  17260. domUtils.insertAfter(tableRow.cells[tableRow.cells.length - 1], cell);
  17261. }
  17262. if(!isInsertTitleCol) replaceTdToTh(rowIndex, cell, tableRow)
  17263. }
  17264. } else {
  17265. for (; rowIndex < rowsNum; rowIndex++) {
  17266. var cellInfo = this.indexTable[rowIndex][colIndex];
  17267. if (cellInfo.colIndex < colIndex) {
  17268. cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
  17269. cell.colSpan = cellInfo.colSpan + 1;
  17270. } else {
  17271. tableRow = this.table.rows[rowIndex];
  17272. preCell = tableRow.cells[cellInfo.cellIndex];
  17273. cell = this.cloneCell(sourceCell, true);//tableRow.insertCell(cellInfo.cellIndex);
  17274. this.setCellContent(cell);
  17275. cell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17276. preCell && cell.setAttribute('width', preCell.getAttribute('width'));
  17277. //防止IE下报错
  17278. preCell ? tableRow.insertBefore(cell, preCell) : tableRow.appendChild(cell);
  17279. }
  17280. if(!isInsertTitleCol) replaceTdToTh(rowIndex, cell, tableRow);
  17281. }
  17282. }
  17283. //框选时插入不触发contentchange,需要手动更新索引
  17284. this.update();
  17285. this.updateWidth(backWidth, defaultValue || {tdPadding:10, tdBorder:1});
  17286. },
  17287. updateWidth:function (width, defaultValue) {
  17288. var table = this.table,
  17289. tmpWidth = UETable.getWidth(table) - defaultValue.tdPadding * 2 - defaultValue.tdBorder + width;
  17290. if (tmpWidth < table.ownerDocument.body.offsetWidth) {
  17291. table.setAttribute("width", tmpWidth);
  17292. return;
  17293. }
  17294. var tds = domUtils.getElementsByTagName(this.table, "td th");
  17295. utils.each(tds, function (td) {
  17296. td.setAttribute("width", width);
  17297. })
  17298. },
  17299. deleteCol:function (colIndex) {
  17300. var indexTable = this.indexTable,
  17301. tableRows = this.table.rows,
  17302. backTableWidth = this.table.getAttribute("width"),
  17303. backTdWidth = 0,
  17304. rowsNum = this.rowsNum,
  17305. cacheMap = {};
  17306. for (var rowIndex = 0; rowIndex < rowsNum;) {
  17307. var infoRow = indexTable[rowIndex],
  17308. cellInfo = infoRow[colIndex],
  17309. key = cellInfo.rowIndex + '_' + cellInfo.colIndex;
  17310. // 跳过已经处理过的Cell
  17311. if (cacheMap[key])continue;
  17312. cacheMap[key] = 1;
  17313. var cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
  17314. if (!backTdWidth) backTdWidth = cell && parseInt(cell.offsetWidth / cell.colSpan, 10).toFixed(0);
  17315. // 如果Cell的colSpan大于1, 就修改colSpan, 否则就删掉这个Cell
  17316. if (cell.colSpan > 1) {
  17317. cell.colSpan--;
  17318. } else {
  17319. tableRows[rowIndex].deleteCell(cellInfo.cellIndex);
  17320. }
  17321. rowIndex += cellInfo.rowSpan || 1;
  17322. }
  17323. this.table.setAttribute("width", backTableWidth - backTdWidth);
  17324. this.update();
  17325. },
  17326. splitToCells:function (cell) {
  17327. var me = this,
  17328. cells = this.splitToRows(cell);
  17329. utils.each(cells, function (cell) {
  17330. me.splitToCols(cell);
  17331. })
  17332. },
  17333. splitToRows:function (cell) {
  17334. var cellInfo = this.getCellInfo(cell),
  17335. rowIndex = cellInfo.rowIndex,
  17336. colIndex = cellInfo.colIndex,
  17337. results = [];
  17338. // 修改Cell的rowSpan
  17339. cell.rowSpan = 1;
  17340. results.push(cell);
  17341. // 补齐单元格
  17342. for (var i = rowIndex, endRow = rowIndex + cellInfo.rowSpan; i < endRow; i++) {
  17343. if (i == rowIndex)continue;
  17344. var tableRow = this.table.rows[i],
  17345. tmpCell = tableRow.insertCell(colIndex - this.getPreviewMergedCellsNum(i, colIndex));
  17346. tmpCell.colSpan = cellInfo.colSpan;
  17347. this.setCellContent(tmpCell);
  17348. tmpCell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17349. tmpCell.setAttribute('align', cell.getAttribute('align'));
  17350. if (cell.style.cssText) {
  17351. tmpCell.style.cssText = cell.style.cssText;
  17352. }
  17353. results.push(tmpCell);
  17354. }
  17355. this.update();
  17356. return results;
  17357. },
  17358. getPreviewMergedCellsNum:function (rowIndex, colIndex) {
  17359. var indexRow = this.indexTable[rowIndex],
  17360. num = 0;
  17361. for (var i = 0; i < colIndex;) {
  17362. var colSpan = indexRow[i].colSpan,
  17363. tmpRowIndex = indexRow[i].rowIndex;
  17364. num += (colSpan - (tmpRowIndex == rowIndex ? 1 : 0));
  17365. i += colSpan;
  17366. }
  17367. return num;
  17368. },
  17369. splitToCols:function (cell) {
  17370. var backWidth = (cell.offsetWidth / cell.colSpan - 22).toFixed(0),
  17371. cellInfo = this.getCellInfo(cell),
  17372. rowIndex = cellInfo.rowIndex,
  17373. colIndex = cellInfo.colIndex,
  17374. results = [];
  17375. // 修改Cell的rowSpan
  17376. cell.colSpan = 1;
  17377. cell.setAttribute("width", backWidth);
  17378. results.push(cell);
  17379. // 补齐单元格
  17380. for (var j = colIndex, endCol = colIndex + cellInfo.colSpan; j < endCol; j++) {
  17381. if (j == colIndex)continue;
  17382. var tableRow = this.table.rows[rowIndex],
  17383. tmpCell = tableRow.insertCell(this.indexTable[rowIndex][j].cellIndex + 1);
  17384. tmpCell.rowSpan = cellInfo.rowSpan;
  17385. this.setCellContent(tmpCell);
  17386. tmpCell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17387. tmpCell.setAttribute('align', cell.getAttribute('align'));
  17388. tmpCell.setAttribute('width', backWidth);
  17389. if (cell.style.cssText) {
  17390. tmpCell.style.cssText = cell.style.cssText;
  17391. }
  17392. //处理th的情况
  17393. if (cell.tagName == 'TH') {
  17394. var th = cell.ownerDocument.createElement('th');
  17395. th.appendChild(tmpCell.firstChild);
  17396. th.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17397. th.rowSpan = tmpCell.rowSpan;
  17398. tableRow.insertBefore(th, tmpCell);
  17399. domUtils.remove(tmpCell);
  17400. }
  17401. results.push(tmpCell);
  17402. }
  17403. this.update();
  17404. return results;
  17405. },
  17406. isLastCell:function (cell, rowsNum, colsNum) {
  17407. rowsNum = rowsNum || this.rowsNum;
  17408. colsNum = colsNum || this.colsNum;
  17409. var cellInfo = this.getCellInfo(cell);
  17410. return ((cellInfo.rowIndex + cellInfo.rowSpan) == rowsNum) &&
  17411. ((cellInfo.colIndex + cellInfo.colSpan) == colsNum);
  17412. },
  17413. getLastCell:function (cells) {
  17414. cells = cells || this.table.getElementsByTagName("td");
  17415. var firstInfo = this.getCellInfo(cells[0]);
  17416. var me = this, last = cells[0],
  17417. tr = last.parentNode,
  17418. cellsNum = 0, cols = 0, rows;
  17419. utils.each(cells, function (cell) {
  17420. if (cell.parentNode == tr)cols += cell.colSpan || 1;
  17421. cellsNum += cell.rowSpan * cell.colSpan || 1;
  17422. });
  17423. rows = cellsNum / cols;
  17424. utils.each(cells, function (cell) {
  17425. if (me.isLastCell(cell, rows, cols)) {
  17426. last = cell;
  17427. return false;
  17428. }
  17429. });
  17430. return last;
  17431. },
  17432. selectRow:function (rowIndex) {
  17433. var indexRow = this.indexTable[rowIndex],
  17434. start = this.getCell(indexRow[0].rowIndex, indexRow[0].cellIndex),
  17435. end = this.getCell(indexRow[this.colsNum - 1].rowIndex, indexRow[this.colsNum - 1].cellIndex),
  17436. range = this.getCellsRange(start, end);
  17437. this.setSelected(range);
  17438. },
  17439. selectTable:function () {
  17440. var tds = this.table.getElementsByTagName("td"),
  17441. range = this.getCellsRange(tds[0], tds[tds.length - 1]);
  17442. this.setSelected(range);
  17443. },
  17444. setBackground:function (cells, value) {
  17445. if (typeof value === "string") {
  17446. utils.each(cells, function (cell) {
  17447. cell.style.backgroundColor = value;
  17448. })
  17449. } else if (typeof value === "object") {
  17450. value = utils.extend({
  17451. repeat:true,
  17452. colorList:["#ddd", "#fff"]
  17453. }, value);
  17454. var rowIndex = this.getCellInfo(cells[0]).rowIndex,
  17455. count = 0,
  17456. colors = value.colorList,
  17457. getColor = function (list, index, repeat) {
  17458. return list[index] ? list[index] : repeat ? list[index % list.length] : "";
  17459. };
  17460. for (var i = 0, cell; cell = cells[i++];) {
  17461. var cellInfo = this.getCellInfo(cell);
  17462. cell.style.backgroundColor = getColor(colors, ((rowIndex + count) == cellInfo.rowIndex) ? count : ++count, value.repeat);
  17463. }
  17464. }
  17465. },
  17466. removeBackground:function (cells) {
  17467. utils.each(cells, function (cell) {
  17468. cell.style.backgroundColor = "";
  17469. })
  17470. }
  17471. };
  17472. function showError(e) {
  17473. }
  17474. })();
  17475. // plugins/table.cmds.js
  17476. /**
  17477. * Created with JetBrains PhpStorm.
  17478. * User: taoqili
  17479. * Date: 13-2-20
  17480. * Time: 下午6:25
  17481. * To change this template use File | Settings | File Templates.
  17482. */
  17483. ;
  17484. (function () {
  17485. var UT = UE.UETable,
  17486. getTableItemsByRange = function (editor) {
  17487. return UT.getTableItemsByRange(editor);
  17488. },
  17489. getUETableBySelected = function (editor) {
  17490. return UT.getUETableBySelected(editor)
  17491. },
  17492. getDefaultValue = function (editor, table) {
  17493. return UT.getDefaultValue(editor, table);
  17494. },
  17495. getUETable = function (tdOrTable) {
  17496. return UT.getUETable(tdOrTable);
  17497. };
  17498. UE.commands['inserttable'] = {
  17499. queryCommandState: function () {
  17500. return getTableItemsByRange(this).table ? -1 : 0;
  17501. },
  17502. execCommand: function (cmd, opt) {
  17503. function createTable(opt, tdWidth) {
  17504. var html = [],
  17505. rowsNum = opt.numRows,
  17506. colsNum = opt.numCols;
  17507. for (var r = 0; r < rowsNum; r++) {
  17508. html.push('<tr' + (r == 0 ? ' class="firstRow"':'') + '>');
  17509. for (var c = 0; c < colsNum; c++) {
  17510. html.push('<td width="' + tdWidth + '" vAlign="' + opt.tdvalign + '" >' + (browser.ie && browser.version < 11 ? domUtils.fillChar : '<br/>') + '</td>')
  17511. }
  17512. html.push('</tr>')
  17513. }
  17514. //禁止指定table-width
  17515. return '<table><tbody>' + html.join('') + '</tbody></table>'
  17516. }
  17517. if (!opt) {
  17518. opt = utils.extend({}, {
  17519. numCols: this.options.defaultCols,
  17520. numRows: this.options.defaultRows,
  17521. tdvalign: this.options.tdvalign
  17522. })
  17523. }
  17524. var me = this;
  17525. var range = this.selection.getRange(),
  17526. start = range.startContainer,
  17527. firstParentBlock = domUtils.findParent(start, function (node) {
  17528. return domUtils.isBlockElm(node);
  17529. }, true) || me.body;
  17530. var defaultValue = getDefaultValue(me),
  17531. tableWidth = firstParentBlock.offsetWidth,
  17532. tdWidth = Math.floor(tableWidth / opt.numCols - defaultValue.tdPadding * 2 - defaultValue.tdBorder);
  17533. //todo其他属性
  17534. !opt.tdvalign && (opt.tdvalign = me.options.tdvalign);
  17535. me.execCommand("inserthtml", createTable(opt, tdWidth));
  17536. }
  17537. };
  17538. UE.commands['insertparagraphbeforetable'] = {
  17539. queryCommandState: function () {
  17540. return getTableItemsByRange(this).cell ? 0 : -1;
  17541. },
  17542. execCommand: function () {
  17543. var table = getTableItemsByRange(this).table;
  17544. if (table) {
  17545. var p = this.document.createElement("p");
  17546. p.innerHTML = browser.ie ? '&nbsp;' : '<br />';
  17547. table.parentNode.insertBefore(p, table);
  17548. this.selection.getRange().setStart(p, 0).setCursor();
  17549. }
  17550. }
  17551. };
  17552. UE.commands['deletetable'] = {
  17553. queryCommandState: function () {
  17554. var rng = this.selection.getRange();
  17555. return domUtils.findParentByTagName(rng.startContainer, 'table', true) ? 0 : -1;
  17556. },
  17557. execCommand: function (cmd, table) {
  17558. var rng = this.selection.getRange();
  17559. table = table || domUtils.findParentByTagName(rng.startContainer, 'table', true);
  17560. if (table) {
  17561. var next = table.nextSibling;
  17562. if (!next) {
  17563. next = domUtils.createElement(this.document, 'p', {
  17564. 'innerHTML': browser.ie ? domUtils.fillChar : '<br/>'
  17565. });
  17566. table.parentNode.insertBefore(next, table);
  17567. }
  17568. domUtils.remove(table);
  17569. rng = this.selection.getRange();
  17570. if (next.nodeType == 3) {
  17571. rng.setStartBefore(next)
  17572. } else {
  17573. rng.setStart(next, 0)
  17574. }
  17575. rng.setCursor(false, true)
  17576. this.fireEvent("tablehasdeleted")
  17577. }
  17578. }
  17579. };
  17580. UE.commands['cellalign'] = {
  17581. queryCommandState: function () {
  17582. return getSelectedArr(this).length ? 0 : -1
  17583. },
  17584. execCommand: function (cmd, align) {
  17585. var selectedTds = getSelectedArr(this);
  17586. if (selectedTds.length) {
  17587. for (var i = 0, ci; ci = selectedTds[i++];) {
  17588. ci.setAttribute('align', align);
  17589. }
  17590. }
  17591. }
  17592. };
  17593. UE.commands['cellvalign'] = {
  17594. queryCommandState: function () {
  17595. return getSelectedArr(this).length ? 0 : -1;
  17596. },
  17597. execCommand: function (cmd, valign) {
  17598. var selectedTds = getSelectedArr(this);
  17599. if (selectedTds.length) {
  17600. for (var i = 0, ci; ci = selectedTds[i++];) {
  17601. ci.setAttribute('vAlign', valign);
  17602. }
  17603. }
  17604. }
  17605. };
  17606. UE.commands['insertcaption'] = {
  17607. queryCommandState: function () {
  17608. var table = getTableItemsByRange(this).table;
  17609. if (table) {
  17610. return table.getElementsByTagName('caption').length == 0 ? 1 : -1;
  17611. }
  17612. return -1;
  17613. },
  17614. execCommand: function () {
  17615. var table = getTableItemsByRange(this).table;
  17616. if (table) {
  17617. var caption = this.document.createElement('caption');
  17618. caption.innerHTML = browser.ie ? domUtils.fillChar : '<br/>';
  17619. table.insertBefore(caption, table.firstChild);
  17620. var range = this.selection.getRange();
  17621. range.setStart(caption, 0).setCursor();
  17622. }
  17623. }
  17624. };
  17625. UE.commands['deletecaption'] = {
  17626. queryCommandState: function () {
  17627. var rng = this.selection.getRange(),
  17628. table = domUtils.findParentByTagName(rng.startContainer, 'table');
  17629. if (table) {
  17630. return table.getElementsByTagName('caption').length == 0 ? -1 : 1;
  17631. }
  17632. return -1;
  17633. },
  17634. execCommand: function () {
  17635. var rng = this.selection.getRange(),
  17636. table = domUtils.findParentByTagName(rng.startContainer, 'table');
  17637. if (table) {
  17638. domUtils.remove(table.getElementsByTagName('caption')[0]);
  17639. var range = this.selection.getRange();
  17640. range.setStart(table.rows[0].cells[0], 0).setCursor();
  17641. }
  17642. }
  17643. };
  17644. UE.commands['inserttitle'] = {
  17645. queryCommandState: function () {
  17646. var table = getTableItemsByRange(this).table;
  17647. if (table) {
  17648. var firstRow = table.rows[0];
  17649. return firstRow.cells[firstRow.cells.length-1].tagName.toLowerCase() != 'th' ? 0 : -1
  17650. }
  17651. return -1;
  17652. },
  17653. execCommand: function () {
  17654. var table = getTableItemsByRange(this).table;
  17655. if (table) {
  17656. getUETable(table).insertRow(0, 'th');
  17657. }
  17658. var th = table.getElementsByTagName('th')[0];
  17659. this.selection.getRange().setStart(th, 0).setCursor(false, true);
  17660. }
  17661. };
  17662. UE.commands['deletetitle'] = {
  17663. queryCommandState: function () {
  17664. var table = getTableItemsByRange(this).table;
  17665. if (table) {
  17666. var firstRow = table.rows[0];
  17667. return firstRow.cells[firstRow.cells.length-1].tagName.toLowerCase() == 'th' ? 0 : -1
  17668. }
  17669. return -1;
  17670. },
  17671. execCommand: function () {
  17672. var table = getTableItemsByRange(this).table;
  17673. if (table) {
  17674. domUtils.remove(table.rows[0])
  17675. }
  17676. var td = table.getElementsByTagName('td')[0];
  17677. this.selection.getRange().setStart(td, 0).setCursor(false, true);
  17678. }
  17679. };
  17680. UE.commands['inserttitlecol'] = {
  17681. queryCommandState: function () {
  17682. var table = getTableItemsByRange(this).table;
  17683. if (table) {
  17684. var lastRow = table.rows[table.rows.length-1];
  17685. return lastRow.getElementsByTagName('th').length ? -1 : 0;
  17686. }
  17687. return -1;
  17688. },
  17689. execCommand: function (cmd) {
  17690. var table = getTableItemsByRange(this).table;
  17691. if (table) {
  17692. getUETable(table).insertCol(0, 'th');
  17693. }
  17694. resetTdWidth(table, this);
  17695. var th = table.getElementsByTagName('th')[0];
  17696. this.selection.getRange().setStart(th, 0).setCursor(false, true);
  17697. }
  17698. };
  17699. UE.commands['deletetitlecol'] = {
  17700. queryCommandState: function () {
  17701. var table = getTableItemsByRange(this).table;
  17702. if (table) {
  17703. var lastRow = table.rows[table.rows.length-1];
  17704. return lastRow.getElementsByTagName('th').length ? 0 : -1;
  17705. }
  17706. return -1;
  17707. },
  17708. execCommand: function () {
  17709. var table = getTableItemsByRange(this).table;
  17710. if (table) {
  17711. for(var i = 0; i< table.rows.length; i++ ){
  17712. domUtils.remove(table.rows[i].children[0])
  17713. }
  17714. }
  17715. resetTdWidth(table, this);
  17716. var td = table.getElementsByTagName('td')[0];
  17717. this.selection.getRange().setStart(td, 0).setCursor(false, true);
  17718. }
  17719. };
  17720. UE.commands["mergeright"] = {
  17721. queryCommandState: function (cmd) {
  17722. var tableItems = getTableItemsByRange(this),
  17723. table = tableItems.table,
  17724. cell = tableItems.cell;
  17725. if (!table || !cell) return -1;
  17726. var ut = getUETable(table);
  17727. if (ut.selectedTds.length) return -1;
  17728. var cellInfo = ut.getCellInfo(cell),
  17729. rightColIndex = cellInfo.colIndex + cellInfo.colSpan;
  17730. if (rightColIndex >= ut.colsNum) return -1; // 如果处于最右边则不能向右合并
  17731. var rightCellInfo = ut.indexTable[cellInfo.rowIndex][rightColIndex],
  17732. rightCell = table.rows[rightCellInfo.rowIndex].cells[rightCellInfo.cellIndex];
  17733. if (!rightCell || cell.tagName != rightCell.tagName) return -1; // TH和TD不能相互合并
  17734. // 当且仅当两个Cell的开始列号和结束列号一致时能进行合并
  17735. return (rightCellInfo.rowIndex == cellInfo.rowIndex && rightCellInfo.rowSpan == cellInfo.rowSpan) ? 0 : -1;
  17736. },
  17737. execCommand: function (cmd) {
  17738. var rng = this.selection.getRange(),
  17739. bk = rng.createBookmark(true);
  17740. var cell = getTableItemsByRange(this).cell,
  17741. ut = getUETable(cell);
  17742. ut.mergeRight(cell);
  17743. rng.moveToBookmark(bk).select();
  17744. }
  17745. };
  17746. UE.commands["mergedown"] = {
  17747. queryCommandState: function (cmd) {
  17748. var tableItems = getTableItemsByRange(this),
  17749. table = tableItems.table,
  17750. cell = tableItems.cell;
  17751. if (!table || !cell) return -1;
  17752. var ut = getUETable(table);
  17753. if (ut.selectedTds.length)return -1;
  17754. var cellInfo = ut.getCellInfo(cell),
  17755. downRowIndex = cellInfo.rowIndex + cellInfo.rowSpan;
  17756. if (downRowIndex >= ut.rowsNum) return -1; // 如果处于最下边则不能向下合并
  17757. var downCellInfo = ut.indexTable[downRowIndex][cellInfo.colIndex],
  17758. downCell = table.rows[downCellInfo.rowIndex].cells[downCellInfo.cellIndex];
  17759. if (!downCell || cell.tagName != downCell.tagName) return -1; // TH和TD不能相互合并
  17760. // 当且仅当两个Cell的开始列号和结束列号一致时能进行合并
  17761. return (downCellInfo.colIndex == cellInfo.colIndex && downCellInfo.colSpan == cellInfo.colSpan) ? 0 : -1;
  17762. },
  17763. execCommand: function () {
  17764. var rng = this.selection.getRange(),
  17765. bk = rng.createBookmark(true);
  17766. var cell = getTableItemsByRange(this).cell,
  17767. ut = getUETable(cell);
  17768. ut.mergeDown(cell);
  17769. rng.moveToBookmark(bk).select();
  17770. }
  17771. };
  17772. UE.commands["mergecells"] = {
  17773. queryCommandState: function () {
  17774. return getUETableBySelected(this) ? 0 : -1;
  17775. },
  17776. execCommand: function () {
  17777. var ut = getUETableBySelected(this);
  17778. if (ut && ut.selectedTds.length) {
  17779. var cell = ut.selectedTds[0];
  17780. ut.mergeRange();
  17781. var rng = this.selection.getRange();
  17782. if (domUtils.isEmptyBlock(cell)) {
  17783. rng.setStart(cell, 0).collapse(true)
  17784. } else {
  17785. rng.selectNodeContents(cell)
  17786. }
  17787. rng.select();
  17788. }
  17789. }
  17790. };
  17791. UE.commands["insertrow"] = {
  17792. queryCommandState: function () {
  17793. var tableItems = getTableItemsByRange(this),
  17794. cell = tableItems.cell;
  17795. return cell && (cell.tagName == "TD" || (cell.tagName == 'TH' && tableItems.tr !== tableItems.table.rows[0])) &&
  17796. getUETable(tableItems.table).rowsNum < this.options.maxRowNum ? 0 : -1;
  17797. },
  17798. execCommand: function () {
  17799. var rng = this.selection.getRange(),
  17800. bk = rng.createBookmark(true);
  17801. var tableItems = getTableItemsByRange(this),
  17802. cell = tableItems.cell,
  17803. table = tableItems.table,
  17804. ut = getUETable(table),
  17805. cellInfo = ut.getCellInfo(cell);
  17806. //ut.insertRow(!ut.selectedTds.length ? cellInfo.rowIndex:ut.cellsRange.beginRowIndex,'');
  17807. if (!ut.selectedTds.length) {
  17808. ut.insertRow(cellInfo.rowIndex, cell);
  17809. } else {
  17810. var range = ut.cellsRange;
  17811. for (var i = 0, len = range.endRowIndex - range.beginRowIndex + 1; i < len; i++) {
  17812. ut.insertRow(range.beginRowIndex, cell);
  17813. }
  17814. }
  17815. rng.moveToBookmark(bk).select();
  17816. if (table.getAttribute("interlaced") === "enabled")this.fireEvent("interlacetable", table);
  17817. }
  17818. };
  17819. //后插入行
  17820. UE.commands["insertrownext"] = {
  17821. queryCommandState: function () {
  17822. var tableItems = getTableItemsByRange(this),
  17823. cell = tableItems.cell;
  17824. return cell && (cell.tagName == "TD") && getUETable(tableItems.table).rowsNum < this.options.maxRowNum ? 0 : -1;
  17825. },
  17826. execCommand: function () {
  17827. var rng = this.selection.getRange(),
  17828. bk = rng.createBookmark(true);
  17829. var tableItems = getTableItemsByRange(this),
  17830. cell = tableItems.cell,
  17831. table = tableItems.table,
  17832. ut = getUETable(table),
  17833. cellInfo = ut.getCellInfo(cell);
  17834. //ut.insertRow(!ut.selectedTds.length? cellInfo.rowIndex + cellInfo.rowSpan : ut.cellsRange.endRowIndex + 1,'');
  17835. if (!ut.selectedTds.length) {
  17836. ut.insertRow(cellInfo.rowIndex + cellInfo.rowSpan, cell);
  17837. } else {
  17838. var range = ut.cellsRange;
  17839. for (var i = 0, len = range.endRowIndex - range.beginRowIndex + 1; i < len; i++) {
  17840. ut.insertRow(range.endRowIndex + 1, cell);
  17841. }
  17842. }
  17843. rng.moveToBookmark(bk).select();
  17844. if (table.getAttribute("interlaced") === "enabled")this.fireEvent("interlacetable", table);
  17845. }
  17846. };
  17847. UE.commands["deleterow"] = {
  17848. queryCommandState: function () {
  17849. var tableItems = getTableItemsByRange(this);
  17850. return tableItems.cell ? 0 : -1;
  17851. },
  17852. execCommand: function () {
  17853. var cell = getTableItemsByRange(this).cell,
  17854. ut = getUETable(cell),
  17855. cellsRange = ut.cellsRange,
  17856. cellInfo = ut.getCellInfo(cell),
  17857. preCell = ut.getVSideCell(cell),
  17858. nextCell = ut.getVSideCell(cell, true),
  17859. rng = this.selection.getRange();
  17860. if (utils.isEmptyObject(cellsRange)) {
  17861. ut.deleteRow(cellInfo.rowIndex);
  17862. } else {
  17863. for (var i = cellsRange.beginRowIndex; i < cellsRange.endRowIndex + 1; i++) {
  17864. ut.deleteRow(cellsRange.beginRowIndex);
  17865. }
  17866. }
  17867. var table = ut.table;
  17868. if (!table.getElementsByTagName('td').length) {
  17869. var nextSibling = table.nextSibling;
  17870. domUtils.remove(table);
  17871. if (nextSibling) {
  17872. rng.setStart(nextSibling, 0).setCursor(false, true);
  17873. }
  17874. } else {
  17875. if (cellInfo.rowSpan == 1 || cellInfo.rowSpan == cellsRange.endRowIndex - cellsRange.beginRowIndex + 1) {
  17876. if (nextCell || preCell) rng.selectNodeContents(nextCell || preCell).setCursor(false, true);
  17877. } else {
  17878. var newCell = ut.getCell(cellInfo.rowIndex, ut.indexTable[cellInfo.rowIndex][cellInfo.colIndex].cellIndex);
  17879. if (newCell) rng.selectNodeContents(newCell).setCursor(false, true);
  17880. }
  17881. }
  17882. if (table.getAttribute("interlaced") === "enabled")this.fireEvent("interlacetable", table);
  17883. }
  17884. };
  17885. UE.commands["insertcol"] = {
  17886. queryCommandState: function (cmd) {
  17887. var tableItems = getTableItemsByRange(this),
  17888. cell = tableItems.cell;
  17889. return cell && (cell.tagName == "TD" || (cell.tagName == 'TH' && cell !== tableItems.tr.cells[0])) &&
  17890. getUETable(tableItems.table).colsNum < this.options.maxColNum ? 0 : -1;
  17891. },
  17892. execCommand: function (cmd) {
  17893. var rng = this.selection.getRange(),
  17894. bk = rng.createBookmark(true);
  17895. if (this.queryCommandState(cmd) == -1)return;
  17896. var cell = getTableItemsByRange(this).cell,
  17897. ut = getUETable(cell),
  17898. cellInfo = ut.getCellInfo(cell);
  17899. //ut.insertCol(!ut.selectedTds.length ? cellInfo.colIndex:ut.cellsRange.beginColIndex);
  17900. if (!ut.selectedTds.length) {
  17901. ut.insertCol(cellInfo.colIndex, cell);
  17902. } else {
  17903. var range = ut.cellsRange;
  17904. for (var i = 0, len = range.endColIndex - range.beginColIndex + 1; i < len; i++) {
  17905. ut.insertCol(range.beginColIndex, cell);
  17906. }
  17907. }
  17908. rng.moveToBookmark(bk).select(true);
  17909. }
  17910. };
  17911. UE.commands["insertcolnext"] = {
  17912. queryCommandState: function () {
  17913. var tableItems = getTableItemsByRange(this),
  17914. cell = tableItems.cell;
  17915. return cell && getUETable(tableItems.table).colsNum < this.options.maxColNum ? 0 : -1;
  17916. },
  17917. execCommand: function () {
  17918. var rng = this.selection.getRange(),
  17919. bk = rng.createBookmark(true);
  17920. var cell = getTableItemsByRange(this).cell,
  17921. ut = getUETable(cell),
  17922. cellInfo = ut.getCellInfo(cell);
  17923. //ut.insertCol(!ut.selectedTds.length ? cellInfo.colIndex + cellInfo.colSpan:ut.cellsRange.endColIndex +1);
  17924. if (!ut.selectedTds.length) {
  17925. ut.insertCol(cellInfo.colIndex + cellInfo.colSpan, cell);
  17926. } else {
  17927. var range = ut.cellsRange;
  17928. for (var i = 0, len = range.endColIndex - range.beginColIndex + 1; i < len; i++) {
  17929. ut.insertCol(range.endColIndex + 1, cell);
  17930. }
  17931. }
  17932. rng.moveToBookmark(bk).select();
  17933. }
  17934. };
  17935. UE.commands["deletecol"] = {
  17936. queryCommandState: function () {
  17937. var tableItems = getTableItemsByRange(this);
  17938. return tableItems.cell ? 0 : -1;
  17939. },
  17940. execCommand: function () {
  17941. var cell = getTableItemsByRange(this).cell,
  17942. ut = getUETable(cell),
  17943. range = ut.cellsRange,
  17944. cellInfo = ut.getCellInfo(cell),
  17945. preCell = ut.getHSideCell(cell),
  17946. nextCell = ut.getHSideCell(cell, true);
  17947. if (utils.isEmptyObject(range)) {
  17948. ut.deleteCol(cellInfo.colIndex);
  17949. } else {
  17950. for (var i = range.beginColIndex; i < range.endColIndex + 1; i++) {
  17951. ut.deleteCol(range.beginColIndex);
  17952. }
  17953. }
  17954. var table = ut.table,
  17955. rng = this.selection.getRange();
  17956. if (!table.getElementsByTagName('td').length) {
  17957. var nextSibling = table.nextSibling;
  17958. domUtils.remove(table);
  17959. if (nextSibling) {
  17960. rng.setStart(nextSibling, 0).setCursor(false, true);
  17961. }
  17962. } else {
  17963. if (domUtils.inDoc(cell, this.document)) {
  17964. rng.setStart(cell, 0).setCursor(false, true);
  17965. } else {
  17966. if (nextCell && domUtils.inDoc(nextCell, this.document)) {
  17967. rng.selectNodeContents(nextCell).setCursor(false, true);
  17968. } else {
  17969. if (preCell && domUtils.inDoc(preCell, this.document)) {
  17970. rng.selectNodeContents(preCell).setCursor(true, true);
  17971. }
  17972. }
  17973. }
  17974. }
  17975. }
  17976. };
  17977. UE.commands["splittocells"] = {
  17978. queryCommandState: function () {
  17979. var tableItems = getTableItemsByRange(this),
  17980. cell = tableItems.cell;
  17981. if (!cell) return -1;
  17982. var ut = getUETable(tableItems.table);
  17983. if (ut.selectedTds.length > 0) return -1;
  17984. return cell && (cell.colSpan > 1 || cell.rowSpan > 1) ? 0 : -1;
  17985. },
  17986. execCommand: function () {
  17987. var rng = this.selection.getRange(),
  17988. bk = rng.createBookmark(true);
  17989. var cell = getTableItemsByRange(this).cell,
  17990. ut = getUETable(cell);
  17991. ut.splitToCells(cell);
  17992. rng.moveToBookmark(bk).select();
  17993. }
  17994. };
  17995. UE.commands["splittorows"] = {
  17996. queryCommandState: function () {
  17997. var tableItems = getTableItemsByRange(this),
  17998. cell = tableItems.cell;
  17999. if (!cell) return -1;
  18000. var ut = getUETable(tableItems.table);
  18001. if (ut.selectedTds.length > 0) return -1;
  18002. return cell && cell.rowSpan > 1 ? 0 : -1;
  18003. },
  18004. execCommand: function () {
  18005. var rng = this.selection.getRange(),
  18006. bk = rng.createBookmark(true);
  18007. var cell = getTableItemsByRange(this).cell,
  18008. ut = getUETable(cell);
  18009. ut.splitToRows(cell);
  18010. rng.moveToBookmark(bk).select();
  18011. }
  18012. };
  18013. UE.commands["splittocols"] = {
  18014. queryCommandState: function () {
  18015. var tableItems = getTableItemsByRange(this),
  18016. cell = tableItems.cell;
  18017. if (!cell) return -1;
  18018. var ut = getUETable(tableItems.table);
  18019. if (ut.selectedTds.length > 0) return -1;
  18020. return cell && cell.colSpan > 1 ? 0 : -1;
  18021. },
  18022. execCommand: function () {
  18023. var rng = this.selection.getRange(),
  18024. bk = rng.createBookmark(true);
  18025. var cell = getTableItemsByRange(this).cell,
  18026. ut = getUETable(cell);
  18027. ut.splitToCols(cell);
  18028. rng.moveToBookmark(bk).select();
  18029. }
  18030. };
  18031. UE.commands["adaptbytext"] =
  18032. UE.commands["adaptbywindow"] = {
  18033. queryCommandState: function () {
  18034. return getTableItemsByRange(this).table ? 0 : -1
  18035. },
  18036. execCommand: function (cmd) {
  18037. var tableItems = getTableItemsByRange(this),
  18038. table = tableItems.table;
  18039. if (table) {
  18040. if (cmd == 'adaptbywindow') {
  18041. resetTdWidth(table, this);
  18042. } else {
  18043. var cells = domUtils.getElementsByTagName(table, "td th");
  18044. utils.each(cells, function (cell) {
  18045. cell.removeAttribute("width");
  18046. });
  18047. table.removeAttribute("width");
  18048. }
  18049. }
  18050. }
  18051. };
  18052. //平均分配各列
  18053. UE.commands['averagedistributecol'] = {
  18054. queryCommandState: function () {
  18055. var ut = getUETableBySelected(this);
  18056. if (!ut) return -1;
  18057. return ut.isFullRow() || ut.isFullCol() ? 0 : -1;
  18058. },
  18059. execCommand: function (cmd) {
  18060. var me = this,
  18061. ut = getUETableBySelected(me);
  18062. function getAverageWidth() {
  18063. var tb = ut.table,
  18064. averageWidth, sumWidth = 0, colsNum = 0,
  18065. tbAttr = getDefaultValue(me, tb);
  18066. if (ut.isFullRow()) {
  18067. sumWidth = tb.offsetWidth;
  18068. colsNum = ut.colsNum;
  18069. } else {
  18070. var begin = ut.cellsRange.beginColIndex,
  18071. end = ut.cellsRange.endColIndex,
  18072. node;
  18073. for (var i = begin; i <= end;) {
  18074. node = ut.selectedTds[i];
  18075. sumWidth += node.offsetWidth;
  18076. i += node.colSpan;
  18077. colsNum += 1;
  18078. }
  18079. }
  18080. averageWidth = Math.ceil(sumWidth / colsNum) - tbAttr.tdBorder * 2 - tbAttr.tdPadding * 2;
  18081. return averageWidth;
  18082. }
  18083. function setAverageWidth(averageWidth) {
  18084. utils.each(domUtils.getElementsByTagName(ut.table, "th"), function (node) {
  18085. node.setAttribute("width", "");
  18086. });
  18087. var cells = ut.isFullRow() ? domUtils.getElementsByTagName(ut.table, "td") : ut.selectedTds;
  18088. utils.each(cells, function (node) {
  18089. if (node.colSpan == 1) {
  18090. node.setAttribute("width", averageWidth);
  18091. }
  18092. });
  18093. }
  18094. if (ut && ut.selectedTds.length) {
  18095. setAverageWidth(getAverageWidth());
  18096. }
  18097. }
  18098. };
  18099. //平均分配各行
  18100. UE.commands['averagedistributerow'] = {
  18101. queryCommandState: function () {
  18102. var ut = getUETableBySelected(this);
  18103. if (!ut) return -1;
  18104. if (ut.selectedTds && /th/ig.test(ut.selectedTds[0].tagName)) return -1;
  18105. return ut.isFullRow() || ut.isFullCol() ? 0 : -1;
  18106. },
  18107. execCommand: function (cmd) {
  18108. var me = this,
  18109. ut = getUETableBySelected(me);
  18110. function getAverageHeight() {
  18111. var averageHeight, rowNum, sumHeight = 0,
  18112. tb = ut.table,
  18113. tbAttr = getDefaultValue(me, tb),
  18114. tdpadding = parseInt(domUtils.getComputedStyle(tb.getElementsByTagName('td')[0], "padding-top"));
  18115. if (ut.isFullCol()) {
  18116. var captionArr = domUtils.getElementsByTagName(tb, "caption"),
  18117. thArr = domUtils.getElementsByTagName(tb, "th"),
  18118. captionHeight, thHeight;
  18119. if (captionArr.length > 0) {
  18120. captionHeight = captionArr[0].offsetHeight;
  18121. }
  18122. if (thArr.length > 0) {
  18123. thHeight = thArr[0].offsetHeight;
  18124. }
  18125. sumHeight = tb.offsetHeight - (captionHeight || 0) - (thHeight || 0);
  18126. rowNum = thArr.length == 0 ? ut.rowsNum : (ut.rowsNum - 1);
  18127. } else {
  18128. var begin = ut.cellsRange.beginRowIndex,
  18129. end = ut.cellsRange.endRowIndex,
  18130. count = 0,
  18131. trs = domUtils.getElementsByTagName(tb, "tr");
  18132. for (var i = begin; i <= end; i++) {
  18133. sumHeight += trs[i].offsetHeight;
  18134. count += 1;
  18135. }
  18136. rowNum = count;
  18137. }
  18138. //ie8下是混杂模式
  18139. if (browser.ie && browser.version < 9) {
  18140. averageHeight = Math.ceil(sumHeight / rowNum);
  18141. } else {
  18142. averageHeight = Math.ceil(sumHeight / rowNum) - tbAttr.tdBorder * 2 - tdpadding * 2;
  18143. }
  18144. return averageHeight;
  18145. }
  18146. function setAverageHeight(averageHeight) {
  18147. var cells = ut.isFullCol() ? domUtils.getElementsByTagName(ut.table, "td") : ut.selectedTds;
  18148. utils.each(cells, function (node) {
  18149. if (node.rowSpan == 1) {
  18150. node.setAttribute("height", averageHeight);
  18151. }
  18152. });
  18153. }
  18154. if (ut && ut.selectedTds.length) {
  18155. setAverageHeight(getAverageHeight());
  18156. }
  18157. }
  18158. };
  18159. //单元格对齐方式
  18160. UE.commands['cellalignment'] = {
  18161. queryCommandState: function () {
  18162. return getTableItemsByRange(this).table ? 0 : -1
  18163. },
  18164. execCommand: function (cmd, data) {
  18165. var me = this,
  18166. ut = getUETableBySelected(me);
  18167. if (!ut) {
  18168. var start = me.selection.getStart(),
  18169. cell = start && domUtils.findParentByTagName(start, ["td", "th", "caption"], true);
  18170. if (!/caption/ig.test(cell.tagName)) {
  18171. domUtils.setAttributes(cell, data);
  18172. } else {
  18173. cell.style.textAlign = data.align;
  18174. cell.style.verticalAlign = data.vAlign;
  18175. }
  18176. me.selection.getRange().setCursor(true);
  18177. } else {
  18178. utils.each(ut.selectedTds, function (cell) {
  18179. domUtils.setAttributes(cell, data);
  18180. });
  18181. }
  18182. },
  18183. /**
  18184. * 查询当前点击的单元格的对齐状态, 如果当前已经选择了多个单元格, 则会返回所有单元格经过统一协调过后的状态
  18185. * @see UE.UETable.getTableCellAlignState
  18186. */
  18187. queryCommandValue: function (cmd) {
  18188. var activeMenuCell = getTableItemsByRange( this).cell;
  18189. if( !activeMenuCell ) {
  18190. activeMenuCell = getSelectedArr(this)[0];
  18191. }
  18192. if (!activeMenuCell) {
  18193. return null;
  18194. } else {
  18195. //获取同时选中的其他单元格
  18196. var cells = UE.UETable.getUETable(activeMenuCell).selectedTds;
  18197. !cells.length && ( cells = activeMenuCell );
  18198. return UE.UETable.getTableCellAlignState(cells);
  18199. }
  18200. }
  18201. };
  18202. //表格对齐方式
  18203. UE.commands['tablealignment'] = {
  18204. queryCommandState: function () {
  18205. if (browser.ie && browser.version < 8) {
  18206. return -1;
  18207. }
  18208. return getTableItemsByRange(this).table ? 0 : -1
  18209. },
  18210. execCommand: function (cmd, value) {
  18211. var me = this,
  18212. start = me.selection.getStart(),
  18213. table = start && domUtils.findParentByTagName(start, ["table"], true);
  18214. if (table) {
  18215. table.setAttribute("align",value);
  18216. }
  18217. }
  18218. };
  18219. //表格属性
  18220. UE.commands['edittable'] = {
  18221. queryCommandState: function () {
  18222. return getTableItemsByRange(this).table ? 0 : -1
  18223. },
  18224. execCommand: function (cmd, color) {
  18225. var rng = this.selection.getRange(),
  18226. table = domUtils.findParentByTagName(rng.startContainer, 'table');
  18227. if (table) {
  18228. var arr = domUtils.getElementsByTagName(table, "td").concat(
  18229. domUtils.getElementsByTagName(table, "th"),
  18230. domUtils.getElementsByTagName(table, "caption")
  18231. );
  18232. utils.each(arr, function (node) {
  18233. node.style.borderColor = color;
  18234. });
  18235. }
  18236. }
  18237. };
  18238. //单元格属性
  18239. UE.commands['edittd'] = {
  18240. queryCommandState: function () {
  18241. return getTableItemsByRange(this).table ? 0 : -1
  18242. },
  18243. execCommand: function (cmd, bkColor) {
  18244. var me = this,
  18245. ut = getUETableBySelected(me);
  18246. if (!ut) {
  18247. var start = me.selection.getStart(),
  18248. cell = start && domUtils.findParentByTagName(start, ["td", "th", "caption"], true);
  18249. if (cell) {
  18250. cell.style.backgroundColor = bkColor;
  18251. }
  18252. } else {
  18253. utils.each(ut.selectedTds, function (cell) {
  18254. cell.style.backgroundColor = bkColor;
  18255. });
  18256. }
  18257. }
  18258. };
  18259. UE.commands["settablebackground"] = {
  18260. queryCommandState: function () {
  18261. return getSelectedArr(this).length > 1 ? 0 : -1;
  18262. },
  18263. execCommand: function (cmd, value) {
  18264. var cells, ut;
  18265. cells = getSelectedArr(this);
  18266. ut = getUETable(cells[0]);
  18267. ut.setBackground(cells, value);
  18268. }
  18269. };
  18270. UE.commands["cleartablebackground"] = {
  18271. queryCommandState: function () {
  18272. var cells = getSelectedArr(this);
  18273. if (!cells.length)return -1;
  18274. for (var i = 0, cell; cell = cells[i++];) {
  18275. if (cell.style.backgroundColor !== "") return 0;
  18276. }
  18277. return -1;
  18278. },
  18279. execCommand: function () {
  18280. var cells = getSelectedArr(this),
  18281. ut = getUETable(cells[0]);
  18282. ut.removeBackground(cells);
  18283. }
  18284. };
  18285. UE.commands["interlacetable"] = UE.commands["uninterlacetable"] = {
  18286. queryCommandState: function (cmd) {
  18287. var table = getTableItemsByRange(this).table;
  18288. if (!table) return -1;
  18289. var interlaced = table.getAttribute("interlaced");
  18290. if (cmd == "interlacetable") {
  18291. //TODO 待定
  18292. //是否需要待定,如果设置,则命令只能单次执行成功,但反射具备toggle效果;否则可以覆盖前次命令,但反射将不存在toggle效果
  18293. return (interlaced === "enabled") ? -1 : 0;
  18294. } else {
  18295. return (!interlaced || interlaced === "disabled") ? -1 : 0;
  18296. }
  18297. },
  18298. execCommand: function (cmd, classList) {
  18299. var table = getTableItemsByRange(this).table;
  18300. if (cmd == "interlacetable") {
  18301. table.setAttribute("interlaced", "enabled");
  18302. this.fireEvent("interlacetable", table, classList);
  18303. } else {
  18304. table.setAttribute("interlaced", "disabled");
  18305. this.fireEvent("uninterlacetable", table);
  18306. }
  18307. }
  18308. };
  18309. UE.commands["setbordervisible"] = {
  18310. queryCommandState: function (cmd) {
  18311. var table = getTableItemsByRange(this).table;
  18312. if (!table) return -1;
  18313. return 0;
  18314. },
  18315. execCommand: function () {
  18316. var table = getTableItemsByRange(this).table;
  18317. utils.each(domUtils.getElementsByTagName(table,'td'),function(td){
  18318. td.style.borderWidth = '1px';
  18319. td.style.borderStyle = 'solid';
  18320. })
  18321. }
  18322. };
  18323. function resetTdWidth(table, editor) {
  18324. var tds = domUtils.getElementsByTagName(table,'td th');
  18325. utils.each(tds, function (td) {
  18326. td.removeAttribute("width");
  18327. });
  18328. table.setAttribute('width', getTableWidth(editor, true, getDefaultValue(editor, table)));
  18329. var tdsWidths = [];
  18330. setTimeout(function () {
  18331. utils.each(tds, function (td) {
  18332. (td.colSpan == 1) && tdsWidths.push(td.offsetWidth)
  18333. })
  18334. utils.each(tds, function (td,i) {
  18335. (td.colSpan == 1) && td.setAttribute("width", tdsWidths[i] + "");
  18336. })
  18337. }, 0);
  18338. }
  18339. function getTableWidth(editor, needIEHack, defaultValue) {
  18340. var body = editor.body;
  18341. return body.offsetWidth - (needIEHack ? parseInt(domUtils.getComputedStyle(body, 'margin-left'), 10) * 2 : 0) - defaultValue.tableBorder * 2 - (editor.options.offsetWidth || 0);
  18342. }
  18343. function getSelectedArr(editor) {
  18344. var cell = getTableItemsByRange(editor).cell;
  18345. if (cell) {
  18346. var ut = getUETable(cell);
  18347. return ut.selectedTds.length ? ut.selectedTds : [cell];
  18348. } else {
  18349. return [];
  18350. }
  18351. }
  18352. })();
  18353. // plugins/table.action.js
  18354. /**
  18355. * Created with JetBrains PhpStorm.
  18356. * User: taoqili
  18357. * Date: 12-10-12
  18358. * Time: 上午10:05
  18359. * To change this template use File | Settings | File Templates.
  18360. */
  18361. UE.plugins['table'] = function () {
  18362. var me = this,
  18363. tabTimer = null,
  18364. //拖动计时器
  18365. tableDragTimer = null,
  18366. //双击计时器
  18367. tableResizeTimer = null,
  18368. //单元格最小宽度
  18369. cellMinWidth = 5,
  18370. isInResizeBuffer = false,
  18371. //单元格边框大小
  18372. cellBorderWidth = 5,
  18373. //鼠标偏移距离
  18374. offsetOfTableCell = 10,
  18375. //记录在有限时间内的点击状态, 共有3个取值, 0, 1, 2。 0代表未初始化, 1代表单击了1次,2代表2次
  18376. singleClickState = 0,
  18377. userActionStatus = null,
  18378. //双击允许的时间范围
  18379. dblclickTime = 360,
  18380. UT = UE.UETable,
  18381. getUETable = function (tdOrTable) {
  18382. return UT.getUETable(tdOrTable);
  18383. },
  18384. getUETableBySelected = function (editor) {
  18385. return UT.getUETableBySelected(editor);
  18386. },
  18387. getDefaultValue = function (editor, table) {
  18388. return UT.getDefaultValue(editor, table);
  18389. },
  18390. removeSelectedClass = function (cells) {
  18391. return UT.removeSelectedClass(cells);
  18392. };
  18393. function showError(e) {
  18394. // throw e;
  18395. }
  18396. me.ready(function(){
  18397. var me = this;
  18398. var orgGetText = me.selection.getText;
  18399. me.selection.getText = function(){
  18400. var table = getUETableBySelected(me);
  18401. if(table){
  18402. var str = '';
  18403. utils.each(table.selectedTds,function(td){
  18404. str += td[browser.ie?'innerText':'textContent'];
  18405. })
  18406. return str;
  18407. }else{
  18408. return orgGetText.call(me.selection)
  18409. }
  18410. }
  18411. })
  18412. //处理拖动及框选相关方法
  18413. var startTd = null, //鼠标按下时的锚点td
  18414. currentTd = null, //当前鼠标经过时的td
  18415. onDrag = "", //指示当前拖动状态,其值可为"","h","v" ,分别表示未拖动状态,横向拖动状态,纵向拖动状态,用于鼠标移动过程中的判断
  18416. onBorder = false, //检测鼠标按下时是否处在单元格边缘位置
  18417. dragButton = null,
  18418. dragOver = false,
  18419. dragLine = null, //模拟的拖动线
  18420. dragTd = null; //发生拖动的目标td
  18421. var mousedown = false,
  18422. //todo 判断混乱模式
  18423. needIEHack = true;
  18424. me.setOpt({
  18425. 'maxColNum':20,
  18426. 'maxRowNum':100,
  18427. 'defaultCols':5,
  18428. 'defaultRows':5,
  18429. 'tdvalign':'top',
  18430. 'cursorpath':me.options.UEDITOR_HOME_URL + "themes/default/images/cursor_",
  18431. 'tableDragable':false,
  18432. 'classList':["ue-table-interlace-color-single","ue-table-interlace-color-double"]
  18433. });
  18434. me.getUETable = getUETable;
  18435. var commands = {
  18436. 'deletetable':1,
  18437. 'inserttable':1,
  18438. 'cellvalign':1,
  18439. 'insertcaption':1,
  18440. 'deletecaption':1,
  18441. 'inserttitle':1,
  18442. 'deletetitle':1,
  18443. "mergeright":1,
  18444. "mergedown":1,
  18445. "mergecells":1,
  18446. "insertrow":1,
  18447. "insertrownext":1,
  18448. "deleterow":1,
  18449. "insertcol":1,
  18450. "insertcolnext":1,
  18451. "deletecol":1,
  18452. "splittocells":1,
  18453. "splittorows":1,
  18454. "splittocols":1,
  18455. "adaptbytext":1,
  18456. "adaptbywindow":1,
  18457. "adaptbycustomer":1,
  18458. "insertparagraph":1,
  18459. "insertparagraphbeforetable":1,
  18460. "averagedistributecol":1,
  18461. "averagedistributerow":1
  18462. };
  18463. me.ready(function () {
  18464. utils.cssRule('table',
  18465. //选中的td上的样式
  18466. '.selectTdClass{background-color:#edf5fa !important}' +
  18467. 'table.noBorderTable td,table.noBorderTable th,table.noBorderTable caption{border:1px dashed #ddd !important}' +
  18468. //插入的表格的默认样式
  18469. 'table{margin-bottom:10px;border-collapse:collapse;display:table;}' +
  18470. 'td,th{padding: 5px 10px;border: 1px solid #DDD;}' +
  18471. 'caption{border:1px dashed #DDD;border-bottom:0;padding:3px;text-align:center;}' +
  18472. 'th{border-top:1px solid #BBB;background-color:#F7F7F7;}' +
  18473. 'table tr.firstRow th{border-top-width:2px;}' +
  18474. '.ue-table-interlace-color-single{ background-color: #fcfcfc; } .ue-table-interlace-color-double{ background-color: #f7faff; }' +
  18475. 'td p{margin:0;padding:0;}', me.document);
  18476. var tableCopyList, isFullCol, isFullRow;
  18477. //注册del/backspace事件
  18478. me.addListener('keydown', function (cmd, evt) {
  18479. var me = this;
  18480. var keyCode = evt.keyCode || evt.which;
  18481. if (keyCode == 8) {
  18482. var ut = getUETableBySelected(me);
  18483. if (ut && ut.selectedTds.length) {
  18484. if (ut.isFullCol()) {
  18485. me.execCommand('deletecol')
  18486. } else if (ut.isFullRow()) {
  18487. me.execCommand('deleterow')
  18488. } else {
  18489. me.fireEvent('delcells');
  18490. }
  18491. domUtils.preventDefault(evt);
  18492. }
  18493. var caption = domUtils.findParentByTagName(me.selection.getStart(), 'caption', true),
  18494. range = me.selection.getRange();
  18495. if (range.collapsed && caption && isEmptyBlock(caption)) {
  18496. me.fireEvent('saveScene');
  18497. var table = caption.parentNode;
  18498. domUtils.remove(caption);
  18499. if (table) {
  18500. range.setStart(table.rows[0].cells[0], 0).setCursor(false, true);
  18501. }
  18502. me.fireEvent('saveScene');
  18503. }
  18504. }
  18505. if (keyCode == 46) {
  18506. ut = getUETableBySelected(me);
  18507. if (ut) {
  18508. me.fireEvent('saveScene');
  18509. for (var i = 0, ci; ci = ut.selectedTds[i++];) {
  18510. domUtils.fillNode(me.document, ci)
  18511. }
  18512. me.fireEvent('saveScene');
  18513. domUtils.preventDefault(evt);
  18514. }
  18515. }
  18516. if (keyCode == 13) {
  18517. var rng = me.selection.getRange(),
  18518. caption = domUtils.findParentByTagName(rng.startContainer, 'caption', true);
  18519. if (caption) {
  18520. var table = domUtils.findParentByTagName(caption, 'table');
  18521. if (!rng.collapsed) {
  18522. rng.deleteContents();
  18523. me.fireEvent('saveScene');
  18524. } else {
  18525. if (caption) {
  18526. rng.setStart(table.rows[0].cells[0], 0).setCursor(false, true);
  18527. }
  18528. }
  18529. domUtils.preventDefault(evt);
  18530. return;
  18531. }
  18532. if (rng.collapsed) {
  18533. var table = domUtils.findParentByTagName(rng.startContainer, 'table');
  18534. if (table) {
  18535. var cell = table.rows[0].cells[0],
  18536. start = domUtils.findParentByTagName(me.selection.getStart(), ['td', 'th'], true),
  18537. preNode = table.previousSibling;
  18538. if (cell === start && (!preNode || preNode.nodeType == 1 && preNode.tagName == 'TABLE' ) && domUtils.isStartInblock(rng)) {
  18539. var first = domUtils.findParent(me.selection.getStart(), function(n){return domUtils.isBlockElm(n)}, true);
  18540. if(first && ( /t(h|d)/i.test(first.tagName) || first === start.firstChild )){
  18541. me.execCommand('insertparagraphbeforetable');
  18542. domUtils.preventDefault(evt);
  18543. }
  18544. }
  18545. }
  18546. }
  18547. }
  18548. if ((evt.ctrlKey || evt.metaKey) && evt.keyCode == '67') {
  18549. tableCopyList = null;
  18550. var ut = getUETableBySelected(me);
  18551. if (ut) {
  18552. var tds = ut.selectedTds;
  18553. isFullCol = ut.isFullCol();
  18554. isFullRow = ut.isFullRow();
  18555. tableCopyList = [
  18556. [ut.cloneCell(tds[0],null,true)]
  18557. ];
  18558. for (var i = 1, ci; ci = tds[i]; i++) {
  18559. if (ci.parentNode !== tds[i - 1].parentNode) {
  18560. tableCopyList.push([ut.cloneCell(ci,null,true)]);
  18561. } else {
  18562. tableCopyList[tableCopyList.length - 1].push(ut.cloneCell(ci,null,true));
  18563. }
  18564. }
  18565. }
  18566. }
  18567. });
  18568. me.addListener("tablehasdeleted",function(){
  18569. toggleDraggableState(this, false, "", null);
  18570. if (dragButton)domUtils.remove(dragButton);
  18571. });
  18572. me.addListener('beforepaste', function (cmd, html) {
  18573. var me = this;
  18574. var rng = me.selection.getRange();
  18575. if (domUtils.findParentByTagName(rng.startContainer, 'caption', true)) {
  18576. var div = me.document.createElement("div");
  18577. div.innerHTML = html.html;
  18578. //trace:3729
  18579. html.html = div[browser.ie9below ? 'innerText' : 'textContent'];
  18580. return;
  18581. }
  18582. var table = getUETableBySelected(me);
  18583. if (tableCopyList) {
  18584. me.fireEvent('saveScene');
  18585. var rng = me.selection.getRange();
  18586. var td = domUtils.findParentByTagName(rng.startContainer, ['td', 'th'], true), tmpNode, preNode;
  18587. if (td) {
  18588. var ut = getUETable(td);
  18589. if (isFullRow) {
  18590. var rowIndex = ut.getCellInfo(td).rowIndex;
  18591. if (td.tagName == 'TH') {
  18592. rowIndex++;
  18593. }
  18594. for (var i = 0, ci; ci = tableCopyList[i++];) {
  18595. var tr = ut.insertRow(rowIndex++, "td");
  18596. for (var j = 0, cj; cj = ci[j]; j++) {
  18597. var cell = tr.cells[j];
  18598. if (!cell) {
  18599. cell = tr.insertCell(j)
  18600. }
  18601. cell.innerHTML = cj.innerHTML;
  18602. cj.getAttribute('width') && cell.setAttribute('width', cj.getAttribute('width'));
  18603. cj.getAttribute('vAlign') && cell.setAttribute('vAlign', cj.getAttribute('vAlign'));
  18604. cj.getAttribute('align') && cell.setAttribute('align', cj.getAttribute('align'));
  18605. cj.style.cssText && (cell.style.cssText = cj.style.cssText)
  18606. }
  18607. for (var j = 0, cj; cj = tr.cells[j]; j++) {
  18608. if (!ci[j])
  18609. break;
  18610. cj.innerHTML = ci[j].innerHTML;
  18611. ci[j].getAttribute('width') && cj.setAttribute('width', ci[j].getAttribute('width'));
  18612. ci[j].getAttribute('vAlign') && cj.setAttribute('vAlign', ci[j].getAttribute('vAlign'));
  18613. ci[j].getAttribute('align') && cj.setAttribute('align', ci[j].getAttribute('align'));
  18614. ci[j].style.cssText && (cj.style.cssText = ci[j].style.cssText)
  18615. }
  18616. }
  18617. } else {
  18618. if (isFullCol) {
  18619. cellInfo = ut.getCellInfo(td);
  18620. var maxColNum = 0;
  18621. for (var j = 0, ci = tableCopyList[0], cj; cj = ci[j++];) {
  18622. maxColNum += cj.colSpan || 1;
  18623. }
  18624. me.__hasEnterExecCommand = true;
  18625. for (i = 0; i < maxColNum; i++) {
  18626. me.execCommand('insertcol');
  18627. }
  18628. me.__hasEnterExecCommand = false;
  18629. td = ut.table.rows[0].cells[cellInfo.cellIndex];
  18630. if (td.tagName == 'TH') {
  18631. td = ut.table.rows[1].cells[cellInfo.cellIndex];
  18632. }
  18633. }
  18634. for (var i = 0, ci; ci = tableCopyList[i++];) {
  18635. tmpNode = td;
  18636. for (var j = 0, cj; cj = ci[j++];) {
  18637. if (td) {
  18638. td.innerHTML = cj.innerHTML;
  18639. //todo 定制处理
  18640. cj.getAttribute('width') && td.setAttribute('width', cj.getAttribute('width'));
  18641. cj.getAttribute('vAlign') && td.setAttribute('vAlign', cj.getAttribute('vAlign'));
  18642. cj.getAttribute('align') && td.setAttribute('align', cj.getAttribute('align'));
  18643. cj.style.cssText && (td.style.cssText = cj.style.cssText);
  18644. preNode = td;
  18645. td = td.nextSibling;
  18646. } else {
  18647. var cloneTd = cj.cloneNode(true);
  18648. domUtils.removeAttributes(cloneTd, ['class', 'rowSpan', 'colSpan']);
  18649. preNode.parentNode.appendChild(cloneTd)
  18650. }
  18651. }
  18652. td = ut.getNextCell(tmpNode, true, true);
  18653. if (!tableCopyList[i])
  18654. break;
  18655. if (!td) {
  18656. var cellInfo = ut.getCellInfo(tmpNode);
  18657. ut.table.insertRow(ut.table.rows.length);
  18658. ut.update();
  18659. td = ut.getVSideCell(tmpNode, true);
  18660. }
  18661. }
  18662. }
  18663. ut.update();
  18664. } else {
  18665. table = me.document.createElement('table');
  18666. for (var i = 0, ci; ci = tableCopyList[i++];) {
  18667. var tr = table.insertRow(table.rows.length);
  18668. for (var j = 0, cj; cj = ci[j++];) {
  18669. cloneTd = UT.cloneCell(cj,null,true);
  18670. domUtils.removeAttributes(cloneTd, ['class']);
  18671. tr.appendChild(cloneTd)
  18672. }
  18673. if (j == 2 && cloneTd.rowSpan > 1) {
  18674. cloneTd.rowSpan = 1;
  18675. }
  18676. }
  18677. var defaultValue = getDefaultValue(me),
  18678. width = me.body.offsetWidth -
  18679. (needIEHack ? parseInt(domUtils.getComputedStyle(me.body, 'margin-left'), 10) * 2 : 0) - defaultValue.tableBorder * 2 - (me.options.offsetWidth || 0);
  18680. me.execCommand('insertHTML', '<table ' +
  18681. ( isFullCol && isFullRow ? 'width="' + width + '"' : '') +
  18682. '>' + table.innerHTML.replace(/>\s*</g, '><').replace(/\bth\b/gi, "td") + '</table>')
  18683. }
  18684. me.fireEvent('contentchange');
  18685. me.fireEvent('saveScene');
  18686. html.html = '';
  18687. return true;
  18688. } else {
  18689. var div = me.document.createElement("div"), tables;
  18690. div.innerHTML = html.html;
  18691. tables = div.getElementsByTagName("table");
  18692. if (domUtils.findParentByTagName(me.selection.getStart(), 'table')) {
  18693. utils.each(tables, function (t) {
  18694. domUtils.remove(t)
  18695. });
  18696. if (domUtils.findParentByTagName(me.selection.getStart(), 'caption', true)) {
  18697. div.innerHTML = div[browser.ie ? 'innerText' : 'textContent'];
  18698. }
  18699. } else {
  18700. utils.each(tables, function (table) {
  18701. removeStyleSize(table, true);
  18702. domUtils.removeAttributes(table, ['style', 'border']);
  18703. utils.each(domUtils.getElementsByTagName(table, "td"), function (td) {
  18704. if (isEmptyBlock(td)) {
  18705. domUtils.fillNode(me.document, td);
  18706. }
  18707. removeStyleSize(td, true);
  18708. // domUtils.removeAttributes(td, ['style'])
  18709. });
  18710. });
  18711. }
  18712. html.html = div.innerHTML;
  18713. }
  18714. });
  18715. me.addListener('afterpaste', function () {
  18716. utils.each(domUtils.getElementsByTagName(me.body, "table"), function (table) {
  18717. if (table.offsetWidth > me.body.offsetWidth) {
  18718. var defaultValue = getDefaultValue(me, table);
  18719. 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'
  18720. }
  18721. })
  18722. });
  18723. me.addListener('blur', function () {
  18724. tableCopyList = null;
  18725. });
  18726. var timer;
  18727. me.addListener('keydown', function () {
  18728. clearTimeout(timer);
  18729. timer = setTimeout(function () {
  18730. var rng = me.selection.getRange(),
  18731. cell = domUtils.findParentByTagName(rng.startContainer, ['th', 'td'], true);
  18732. if (cell) {
  18733. var table = cell.parentNode.parentNode.parentNode;
  18734. if (table.offsetWidth > table.getAttribute("width")) {
  18735. cell.style.wordBreak = "break-all";
  18736. }
  18737. }
  18738. }, 100);
  18739. });
  18740. me.addListener("selectionchange", function () {
  18741. toggleDraggableState(me, false, "", null);
  18742. });
  18743. //内容变化时触发索引更新
  18744. //todo 可否考虑标记检测,如果不涉及表格的变化就不进行索引重建和更新
  18745. me.addListener("contentchange", function () {
  18746. var me = this;
  18747. //尽可能排除一些不需要更新的状况
  18748. hideDragLine(me);
  18749. if (getUETableBySelected(me))return;
  18750. var rng = me.selection.getRange();
  18751. var start = rng.startContainer;
  18752. start = domUtils.findParentByTagName(start, ['td', 'th'], true);
  18753. utils.each(domUtils.getElementsByTagName(me.document, 'table'), function (table) {
  18754. if (me.fireEvent("excludetable", table) === true) return;
  18755. table.ueTable = new UT(table);
  18756. //trace:3742
  18757. // utils.each(domUtils.getElementsByTagName(me.document, 'td'), function (td) {
  18758. //
  18759. // if (domUtils.isEmptyBlock(td) && td !== start) {
  18760. // domUtils.fillNode(me.document, td);
  18761. // if (browser.ie && browser.version == 6) {
  18762. // td.innerHTML = '&nbsp;'
  18763. // }
  18764. // }
  18765. // });
  18766. // utils.each(domUtils.getElementsByTagName(me.document, 'th'), function (th) {
  18767. // if (domUtils.isEmptyBlock(th) && th !== start) {
  18768. // domUtils.fillNode(me.document, th);
  18769. // if (browser.ie && browser.version == 6) {
  18770. // th.innerHTML = '&nbsp;'
  18771. // }
  18772. // }
  18773. // });
  18774. table.onmouseover = function () {
  18775. me.fireEvent('tablemouseover', table);
  18776. };
  18777. table.onmousemove = function () {
  18778. me.fireEvent('tablemousemove', table);
  18779. me.options.tableDragable && toggleDragButton(true, this, me);
  18780. utils.defer(function(){
  18781. me.fireEvent('contentchange',50)
  18782. },true)
  18783. };
  18784. table.onmouseout = function () {
  18785. me.fireEvent('tablemouseout', table);
  18786. toggleDraggableState(me, false, "", null);
  18787. hideDragLine(me);
  18788. };
  18789. table.onclick = function (evt) {
  18790. evt = me.window.event || evt;
  18791. var target = getParentTdOrTh(evt.target || evt.srcElement);
  18792. if (!target)return;
  18793. var ut = getUETable(target),
  18794. table = ut.table,
  18795. cellInfo = ut.getCellInfo(target),
  18796. cellsRange,
  18797. rng = me.selection.getRange();
  18798. // if ("topLeft" == inPosition(table, mouseCoords(evt))) {
  18799. // cellsRange = ut.getCellsRange(ut.table.rows[0].cells[0], ut.getLastCell());
  18800. // ut.setSelected(cellsRange);
  18801. // return;
  18802. // }
  18803. // if ("bottomRight" == inPosition(table, mouseCoords(evt))) {
  18804. //
  18805. // return;
  18806. // }
  18807. if (inTableSide(table, target, evt, true)) {
  18808. var endTdCol = ut.getCell(ut.indexTable[ut.rowsNum - 1][cellInfo.colIndex].rowIndex, ut.indexTable[ut.rowsNum - 1][cellInfo.colIndex].cellIndex);
  18809. if (evt.shiftKey && ut.selectedTds.length) {
  18810. if (ut.selectedTds[0] !== endTdCol) {
  18811. cellsRange = ut.getCellsRange(ut.selectedTds[0], endTdCol);
  18812. ut.setSelected(cellsRange);
  18813. } else {
  18814. rng && rng.selectNodeContents(endTdCol).select();
  18815. }
  18816. } else {
  18817. if (target !== endTdCol) {
  18818. cellsRange = ut.getCellsRange(target, endTdCol);
  18819. ut.setSelected(cellsRange);
  18820. } else {
  18821. rng && rng.selectNodeContents(endTdCol).select();
  18822. }
  18823. }
  18824. return;
  18825. }
  18826. if (inTableSide(table, target, evt)) {
  18827. var endTdRow = ut.getCell(ut.indexTable[cellInfo.rowIndex][ut.colsNum - 1].rowIndex, ut.indexTable[cellInfo.rowIndex][ut.colsNum - 1].cellIndex);
  18828. if (evt.shiftKey && ut.selectedTds.length) {
  18829. if (ut.selectedTds[0] !== endTdRow) {
  18830. cellsRange = ut.getCellsRange(ut.selectedTds[0], endTdRow);
  18831. ut.setSelected(cellsRange);
  18832. } else {
  18833. rng && rng.selectNodeContents(endTdRow).select();
  18834. }
  18835. } else {
  18836. if (target !== endTdRow) {
  18837. cellsRange = ut.getCellsRange(target, endTdRow);
  18838. ut.setSelected(cellsRange);
  18839. } else {
  18840. rng && rng.selectNodeContents(endTdRow).select();
  18841. }
  18842. }
  18843. }
  18844. };
  18845. });
  18846. switchBorderColor(me, true);
  18847. });
  18848. domUtils.on(me.document, "mousemove", mouseMoveEvent);
  18849. domUtils.on(me.document, "mouseout", function (evt) {
  18850. var target = evt.target || evt.srcElement;
  18851. if (target.tagName == "TABLE") {
  18852. toggleDraggableState(me, false, "", null);
  18853. }
  18854. });
  18855. /**
  18856. * 表格隔行变色
  18857. */
  18858. me.addListener("interlacetable",function(type,table,classList){
  18859. if(!table) return;
  18860. var me = this,
  18861. rows = table.rows,
  18862. len = rows.length,
  18863. getClass = function(list,index,repeat){
  18864. return list[index] ? list[index] : repeat ? list[index % list.length]: "";
  18865. };
  18866. for(var i = 0;i<len;i++){
  18867. rows[i].className = getClass( classList|| me.options.classList,i,true);
  18868. }
  18869. });
  18870. me.addListener("uninterlacetable",function(type,table){
  18871. if(!table) return;
  18872. var me = this,
  18873. rows = table.rows,
  18874. classList = me.options.classList,
  18875. len = rows.length;
  18876. for(var i = 0;i<len;i++){
  18877. domUtils.removeClasses( rows[i], classList );
  18878. }
  18879. });
  18880. me.addListener("mousedown", mouseDownEvent);
  18881. me.addListener("mouseup", mouseUpEvent);
  18882. //拖动的时候触发mouseup
  18883. domUtils.on( me.body, 'dragstart', function( evt ){
  18884. mouseUpEvent.call( me, 'dragstart', evt );
  18885. });
  18886. me.addOutputRule(function(root){
  18887. utils.each(root.getNodesByTagName('div'),function(n){
  18888. if (n.getAttr('id') == 'ue_tableDragLine') {
  18889. n.parentNode.removeChild(n);
  18890. }
  18891. });
  18892. });
  18893. var currentRowIndex = 0;
  18894. me.addListener("mousedown", function () {
  18895. currentRowIndex = 0;
  18896. });
  18897. me.addListener('tabkeydown', function () {
  18898. var range = this.selection.getRange(),
  18899. common = range.getCommonAncestor(true, true),
  18900. table = domUtils.findParentByTagName(common, 'table');
  18901. if (table) {
  18902. if (domUtils.findParentByTagName(common, 'caption', true)) {
  18903. var cell = domUtils.getElementsByTagName(table, 'th td');
  18904. if (cell && cell.length) {
  18905. range.setStart(cell[0], 0).setCursor(false, true)
  18906. }
  18907. } else {
  18908. var cell = domUtils.findParentByTagName(common, ['td', 'th'], true),
  18909. ua = getUETable(cell);
  18910. currentRowIndex = cell.rowSpan > 1 ? currentRowIndex : ua.getCellInfo(cell).rowIndex;
  18911. var nextCell = ua.getTabNextCell(cell, currentRowIndex);
  18912. if (nextCell) {
  18913. if (isEmptyBlock(nextCell)) {
  18914. range.setStart(nextCell, 0).setCursor(false, true)
  18915. } else {
  18916. range.selectNodeContents(nextCell).select()
  18917. }
  18918. } else {
  18919. me.fireEvent('saveScene');
  18920. me.__hasEnterExecCommand = true;
  18921. this.execCommand('insertrownext');
  18922. me.__hasEnterExecCommand = false;
  18923. range = this.selection.getRange();
  18924. range.setStart(table.rows[table.rows.length - 1].cells[0], 0).setCursor();
  18925. me.fireEvent('saveScene');
  18926. }
  18927. }
  18928. return true;
  18929. }
  18930. });
  18931. browser.ie && me.addListener('selectionchange', function () {
  18932. toggleDraggableState(this, false, "", null);
  18933. });
  18934. me.addListener("keydown", function (type, evt) {
  18935. var me = this;
  18936. //处理在表格的最后一个输入tab产生新的表格
  18937. var keyCode = evt.keyCode || evt.which;
  18938. if (keyCode == 8 || keyCode == 46) {
  18939. return;
  18940. }
  18941. var notCtrlKey = !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey;
  18942. notCtrlKey && removeSelectedClass(domUtils.getElementsByTagName(me.body, "td"));
  18943. var ut = getUETableBySelected(me);
  18944. if (!ut) return;
  18945. notCtrlKey && ut.clearSelected();
  18946. });
  18947. me.addListener("beforegetcontent", function () {
  18948. switchBorderColor(this, false);
  18949. browser.ie && utils.each(this.document.getElementsByTagName('caption'), function (ci) {
  18950. if (domUtils.isEmptyNode(ci)) {
  18951. ci.innerHTML = '&nbsp;'
  18952. }
  18953. });
  18954. });
  18955. me.addListener("aftergetcontent", function () {
  18956. switchBorderColor(this, true);
  18957. });
  18958. me.addListener("getAllHtml", function () {
  18959. removeSelectedClass(me.document.getElementsByTagName("td"));
  18960. });
  18961. //修正全屏状态下插入的表格宽度在非全屏状态下撑开编辑器的情况
  18962. me.addListener("fullscreenchanged", function (type, fullscreen) {
  18963. if (!fullscreen) {
  18964. var ratio = this.body.offsetWidth / document.body.offsetWidth,
  18965. tables = domUtils.getElementsByTagName(this.body, "table");
  18966. utils.each(tables, function (table) {
  18967. if (table.offsetWidth < me.body.offsetWidth) return false;
  18968. var tds = domUtils.getElementsByTagName(table, "td"),
  18969. backWidths = [];
  18970. utils.each(tds, function (td) {
  18971. backWidths.push(td.offsetWidth);
  18972. });
  18973. for (var i = 0, td; td = tds[i]; i++) {
  18974. td.setAttribute("width", Math.floor(backWidths[i] * ratio));
  18975. }
  18976. table.setAttribute("width", Math.floor(getTableWidth(me, needIEHack, getDefaultValue(me))))
  18977. });
  18978. }
  18979. });
  18980. //重写execCommand命令,用于处理框选时的处理
  18981. var oldExecCommand = me.execCommand;
  18982. me.execCommand = function (cmd, datatat) {
  18983. var me = this,
  18984. args = arguments;
  18985. cmd = cmd.toLowerCase();
  18986. var ut = getUETableBySelected(me), tds,
  18987. range = new dom.Range(me.document),
  18988. cmdFun = me.commands[cmd] || UE.commands[cmd],
  18989. result;
  18990. if (!cmdFun) return;
  18991. if (ut && !commands[cmd] && !cmdFun.notNeedUndo && !me.__hasEnterExecCommand) {
  18992. me.__hasEnterExecCommand = true;
  18993. me.fireEvent("beforeexeccommand", cmd);
  18994. tds = ut.selectedTds;
  18995. var lastState = -2, lastValue = -2, value, state;
  18996. for (var i = 0, td; td = tds[i]; i++) {
  18997. if (isEmptyBlock(td)) {
  18998. range.setStart(td, 0).setCursor(false, true)
  18999. } else {
  19000. range.selectNode(td).select(true);
  19001. }
  19002. state = me.queryCommandState(cmd);
  19003. value = me.queryCommandValue(cmd);
  19004. if (state != -1) {
  19005. if (lastState !== state || lastValue !== value) {
  19006. me._ignoreContentChange = true;
  19007. result = oldExecCommand.apply(me, arguments);
  19008. me._ignoreContentChange = false;
  19009. }
  19010. lastState = me.queryCommandState(cmd);
  19011. lastValue = me.queryCommandValue(cmd);
  19012. if (domUtils.isEmptyBlock(td)) {
  19013. domUtils.fillNode(me.document, td)
  19014. }
  19015. }
  19016. }
  19017. range.setStart(tds[0], 0).shrinkBoundary(true).setCursor(false, true);
  19018. me.fireEvent('contentchange');
  19019. me.fireEvent("afterexeccommand", cmd);
  19020. me.__hasEnterExecCommand = false;
  19021. me._selectionChange();
  19022. } else {
  19023. result = oldExecCommand.apply(me, arguments);
  19024. }
  19025. return result;
  19026. };
  19027. });
  19028. /**
  19029. * 删除obj的宽高style,改成属性宽高
  19030. * @param obj
  19031. * @param replaceToProperty
  19032. */
  19033. function removeStyleSize(obj, replaceToProperty) {
  19034. removeStyle(obj, "width", true);
  19035. removeStyle(obj, "height", true);
  19036. }
  19037. function removeStyle(obj, styleName, replaceToProperty) {
  19038. if (obj.style[styleName]) {
  19039. replaceToProperty && obj.setAttribute(styleName, parseInt(obj.style[styleName], 10));
  19040. obj.style[styleName] = "";
  19041. }
  19042. }
  19043. function getParentTdOrTh(ele) {
  19044. if (ele.tagName == "TD" || ele.tagName == "TH") return ele;
  19045. var td;
  19046. if (td = domUtils.findParentByTagName(ele, "td", true) || domUtils.findParentByTagName(ele, "th", true)) return td;
  19047. return null;
  19048. }
  19049. function isEmptyBlock(node) {
  19050. var reg = new RegExp(domUtils.fillChar, 'g');
  19051. if (node[browser.ie ? 'innerText' : 'textContent'].replace(/^\s*$/, '').replace(reg, '').length > 0) {
  19052. return 0;
  19053. }
  19054. for (var n in dtd.$isNotEmpty) {
  19055. if (node.getElementsByTagName(n).length) {
  19056. return 0;
  19057. }
  19058. }
  19059. return 1;
  19060. }
  19061. function mouseCoords(evt) {
  19062. if (evt.pageX || evt.pageY) {
  19063. return { x:evt.pageX, y:evt.pageY };
  19064. }
  19065. return {
  19066. x:evt.clientX + me.document.body.scrollLeft - me.document.body.clientLeft,
  19067. y:evt.clientY + me.document.body.scrollTop - me.document.body.clientTop
  19068. };
  19069. }
  19070. function mouseMoveEvent(evt) {
  19071. if( isEditorDisabled() ) {
  19072. return;
  19073. }
  19074. try {
  19075. //普通状态下鼠标移动
  19076. var target = getParentTdOrTh(evt.target || evt.srcElement),
  19077. pos;
  19078. //区分用户的行为是拖动还是双击
  19079. if( isInResizeBuffer ) {
  19080. me.body.style.webkitUserSelect = 'none';
  19081. if( Math.abs( userActionStatus.x - evt.clientX ) > offsetOfTableCell || Math.abs( userActionStatus.y - evt.clientY ) > offsetOfTableCell ) {
  19082. clearTableDragTimer();
  19083. isInResizeBuffer = false;
  19084. singleClickState = 0;
  19085. //drag action
  19086. tableBorderDrag(evt);
  19087. }
  19088. }
  19089. //修改单元格大小时的鼠标移动
  19090. if (onDrag && dragTd) {
  19091. singleClickState = 0;
  19092. me.body.style.webkitUserSelect = 'none';
  19093. me.selection.getNative()[browser.ie9below ? 'empty' : 'removeAllRanges']();
  19094. pos = mouseCoords(evt);
  19095. toggleDraggableState(me, true, onDrag, pos, target);
  19096. if (onDrag == "h") {
  19097. dragLine.style.left = getPermissionX(dragTd, evt) + "px";
  19098. } else if (onDrag == "v") {
  19099. dragLine.style.top = getPermissionY(dragTd, evt) + "px";
  19100. }
  19101. return;
  19102. }
  19103. //当鼠标处于table上时,修改移动过程中的光标状态
  19104. if (target) {
  19105. //针对使用table作为容器的组件不触发拖拽效果
  19106. if (me.fireEvent('excludetable', target) === true)
  19107. return;
  19108. pos = mouseCoords(evt);
  19109. var state = getRelation(target, pos),
  19110. table = domUtils.findParentByTagName(target, "table", true);
  19111. if (inTableSide(table, target, evt, true)) {
  19112. if (me.fireEvent("excludetable", table) === true) return;
  19113. me.body.style.cursor = "url(" + me.options.cursorpath + "h.png),pointer";
  19114. } else if (inTableSide(table, target, evt)) {
  19115. if (me.fireEvent("excludetable", table) === true) return;
  19116. me.body.style.cursor = "url(" + me.options.cursorpath + "v.png),pointer";
  19117. } else {
  19118. me.body.style.cursor = "text";
  19119. var curCell = target;
  19120. if (/\d/.test(state)) {
  19121. state = state.replace(/\d/, '');
  19122. target = getUETable(target).getPreviewCell(target, state == "v");
  19123. }
  19124. //位于第一行的顶部或者第一列的左边时不可拖动
  19125. toggleDraggableState(me, target ? !!state : false, target ? state : '', pos, target);
  19126. }
  19127. } else {
  19128. toggleDragButton(false, table, me);
  19129. }
  19130. } catch (e) {
  19131. showError(e);
  19132. }
  19133. }
  19134. var dragButtonTimer;
  19135. function toggleDragButton(show, table, editor) {
  19136. if (!show) {
  19137. if (dragOver)return;
  19138. dragButtonTimer = setTimeout(function () {
  19139. !dragOver && dragButton && dragButton.parentNode && dragButton.parentNode.removeChild(dragButton);
  19140. }, 2000);
  19141. } else {
  19142. createDragButton(table, editor);
  19143. }
  19144. }
  19145. function createDragButton(table, editor) {
  19146. var pos = domUtils.getXY(table),
  19147. doc = table.ownerDocument;
  19148. if (dragButton && dragButton.parentNode)return dragButton;
  19149. dragButton = doc.createElement("div");
  19150. dragButton.contentEditable = false;
  19151. dragButton.innerHTML = "";
  19152. 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;";
  19153. domUtils.unSelectable(dragButton);
  19154. dragButton.onmouseover = function (evt) {
  19155. dragOver = true;
  19156. };
  19157. dragButton.onmouseout = function (evt) {
  19158. dragOver = false;
  19159. };
  19160. domUtils.on(dragButton, 'click', function (type, evt) {
  19161. doClick(evt, this);
  19162. });
  19163. domUtils.on(dragButton, 'dblclick', function (type, evt) {
  19164. doDblClick(evt);
  19165. });
  19166. domUtils.on(dragButton, 'dragstart', function (type, evt) {
  19167. domUtils.preventDefault(evt);
  19168. });
  19169. var timer;
  19170. function doClick(evt, button) {
  19171. // 部分浏览器下需要清理
  19172. clearTimeout(timer);
  19173. timer = setTimeout(function () {
  19174. editor.fireEvent("tableClicked", table, button);
  19175. }, 300);
  19176. }
  19177. function doDblClick(evt) {
  19178. clearTimeout(timer);
  19179. var ut = getUETable(table),
  19180. start = table.rows[0].cells[0],
  19181. end = ut.getLastCell(),
  19182. range = ut.getCellsRange(start, end);
  19183. editor.selection.getRange().setStart(start, 0).setCursor(false, true);
  19184. ut.setSelected(range);
  19185. }
  19186. doc.body.appendChild(dragButton);
  19187. }
  19188. // function inPosition(table, pos) {
  19189. // var tablePos = domUtils.getXY(table),
  19190. // width = table.offsetWidth,
  19191. // height = table.offsetHeight;
  19192. // if (pos.x - tablePos.x < 5 && pos.y - tablePos.y < 5) {
  19193. // return "topLeft";
  19194. // } else if (tablePos.x + width - pos.x < 5 && tablePos.y + height - pos.y < 5) {
  19195. // return "bottomRight";
  19196. // }
  19197. // }
  19198. function inTableSide(table, cell, evt, top) {
  19199. var pos = mouseCoords(evt),
  19200. state = getRelation(cell, pos);
  19201. if (top) {
  19202. var caption = table.getElementsByTagName("caption")[0],
  19203. capHeight = caption ? caption.offsetHeight : 0;
  19204. return (state == "v1") && ((pos.y - domUtils.getXY(table).y - capHeight) < 8);
  19205. } else {
  19206. return (state == "h1") && ((pos.x - domUtils.getXY(table).x) < 8);
  19207. }
  19208. }
  19209. /**
  19210. * 获取拖动时允许的X轴坐标
  19211. * @param dragTd
  19212. * @param evt
  19213. */
  19214. function getPermissionX(dragTd, evt) {
  19215. var ut = getUETable(dragTd);
  19216. if (ut) {
  19217. var preTd = ut.getSameEndPosCells(dragTd, "x")[0],
  19218. nextTd = ut.getSameStartPosXCells(dragTd)[0],
  19219. mouseX = mouseCoords(evt).x,
  19220. left = (preTd ? domUtils.getXY(preTd).x : domUtils.getXY(ut.table).x) + 20 ,
  19221. right = nextTd ? domUtils.getXY(nextTd).x + nextTd.offsetWidth - 20 : (me.body.offsetWidth + 5 || parseInt(domUtils.getComputedStyle(me.body, "width"), 10));
  19222. left += cellMinWidth;
  19223. right -= cellMinWidth;
  19224. return mouseX < left ? left : mouseX > right ? right : mouseX;
  19225. }
  19226. }
  19227. /**
  19228. * 获取拖动时允许的Y轴坐标
  19229. */
  19230. function getPermissionY(dragTd, evt) {
  19231. try {
  19232. var top = domUtils.getXY(dragTd).y,
  19233. mousePosY = mouseCoords(evt).y;
  19234. return mousePosY < top ? top : mousePosY;
  19235. } catch (e) {
  19236. showError(e);
  19237. }
  19238. }
  19239. /**
  19240. * 移动状态切换
  19241. */
  19242. function toggleDraggableState(editor, draggable, dir, mousePos, cell) {
  19243. try {
  19244. editor.body.style.cursor = dir == "h" ? "col-resize" : dir == "v" ? "row-resize" : "text";
  19245. if (browser.ie) {
  19246. if (dir && !mousedown && !getUETableBySelected(editor)) {
  19247. getDragLine(editor, editor.document);
  19248. showDragLineAt(dir, cell);
  19249. } else {
  19250. hideDragLine(editor)
  19251. }
  19252. }
  19253. onBorder = draggable;
  19254. } catch (e) {
  19255. showError(e);
  19256. }
  19257. }
  19258. /**
  19259. * 获取与UETable相关的resize line
  19260. * @param uetable UETable对象
  19261. */
  19262. function getResizeLineByUETable() {
  19263. var lineId = '_UETableResizeLine',
  19264. line = this.document.getElementById( lineId );
  19265. if( !line ) {
  19266. line = this.document.createElement("div");
  19267. line.id = lineId;
  19268. line.contnetEditable = false;
  19269. line.setAttribute("unselectable", "on");
  19270. var styles = {
  19271. width: 2*cellBorderWidth + 1 + 'px',
  19272. position: 'absolute',
  19273. 'z-index': 100000,
  19274. cursor: 'col-resize',
  19275. background: 'red',
  19276. display: 'none'
  19277. };
  19278. //切换状态
  19279. line.onmouseout = function(){
  19280. this.style.display = 'none';
  19281. };
  19282. utils.extend( line.style, styles );
  19283. this.document.body.appendChild( line );
  19284. }
  19285. return line;
  19286. }
  19287. /**
  19288. * 更新resize-line
  19289. */
  19290. function updateResizeLine( cell, uetable ) {
  19291. var line = getResizeLineByUETable.call( this ),
  19292. table = uetable.table,
  19293. styles = {
  19294. top: domUtils.getXY( table ).y + 'px',
  19295. left: domUtils.getXY( cell).x + cell.offsetWidth - cellBorderWidth + 'px',
  19296. display: 'block',
  19297. height: table.offsetHeight + 'px'
  19298. };
  19299. utils.extend( line.style, styles );
  19300. }
  19301. /**
  19302. * 显示resize-line
  19303. */
  19304. function showResizeLine( cell ) {
  19305. var uetable = getUETable( cell );
  19306. updateResizeLine.call( this, cell, uetable );
  19307. }
  19308. /**
  19309. * 获取鼠标与当前单元格的相对位置
  19310. * @param ele
  19311. * @param mousePos
  19312. */
  19313. function getRelation(ele, mousePos) {
  19314. var elePos = domUtils.getXY(ele);
  19315. if( !elePos ) {
  19316. return '';
  19317. }
  19318. if (elePos.x + ele.offsetWidth - mousePos.x < cellBorderWidth) {
  19319. return "h";
  19320. }
  19321. if (mousePos.x - elePos.x < cellBorderWidth) {
  19322. return 'h1'
  19323. }
  19324. if (elePos.y + ele.offsetHeight - mousePos.y < cellBorderWidth) {
  19325. return "v";
  19326. }
  19327. if (mousePos.y - elePos.y < cellBorderWidth) {
  19328. return 'v1'
  19329. }
  19330. return '';
  19331. }
  19332. function mouseDownEvent(type, evt) {
  19333. if( isEditorDisabled() ) {
  19334. return ;
  19335. }
  19336. userActionStatus = {
  19337. x: evt.clientX,
  19338. y: evt.clientY
  19339. };
  19340. //右键菜单单独处理
  19341. if (evt.button == 2) {
  19342. var ut = getUETableBySelected(me),
  19343. flag = false;
  19344. if (ut) {
  19345. var td = getTargetTd(me, evt);
  19346. utils.each(ut.selectedTds, function (ti) {
  19347. if (ti === td) {
  19348. flag = true;
  19349. }
  19350. });
  19351. if (!flag) {
  19352. removeSelectedClass(domUtils.getElementsByTagName(me.body, "th td"));
  19353. ut.clearSelected()
  19354. } else {
  19355. td = ut.selectedTds[0];
  19356. setTimeout(function () {
  19357. me.selection.getRange().setStart(td, 0).setCursor(false, true);
  19358. }, 0);
  19359. }
  19360. }
  19361. } else {
  19362. tableClickHander( evt );
  19363. }
  19364. }
  19365. //清除表格的计时器
  19366. function clearTableTimer() {
  19367. tabTimer && clearTimeout( tabTimer );
  19368. tabTimer = null;
  19369. }
  19370. //双击收缩
  19371. function tableDbclickHandler(evt) {
  19372. singleClickState = 0;
  19373. evt = evt || me.window.event;
  19374. var target = getParentTdOrTh(evt.target || evt.srcElement);
  19375. if (target) {
  19376. var h;
  19377. if (h = getRelation(target, mouseCoords(evt))) {
  19378. hideDragLine( me );
  19379. if (h == 'h1') {
  19380. h = 'h';
  19381. if (inTableSide(domUtils.findParentByTagName(target, "table"), target, evt)) {
  19382. me.execCommand('adaptbywindow');
  19383. } else {
  19384. target = getUETable(target).getPreviewCell(target);
  19385. if (target) {
  19386. var rng = me.selection.getRange();
  19387. rng.selectNodeContents(target).setCursor(true, true)
  19388. }
  19389. }
  19390. }
  19391. if (h == 'h') {
  19392. var ut = getUETable(target),
  19393. table = ut.table,
  19394. cells = getCellsByMoveBorder( target, table, true );
  19395. cells = extractArray( cells, 'left' );
  19396. ut.width = ut.offsetWidth;
  19397. var oldWidth = [],
  19398. newWidth = [];
  19399. utils.each( cells, function( cell ){
  19400. oldWidth.push( cell.offsetWidth );
  19401. } );
  19402. utils.each( cells, function( cell ){
  19403. cell.removeAttribute("width");
  19404. } );
  19405. window.setTimeout( function(){
  19406. //是否允许改变
  19407. var changeable = true;
  19408. utils.each( cells, function( cell, index ){
  19409. var width = cell.offsetWidth;
  19410. if( width > oldWidth[index] ) {
  19411. changeable = false;
  19412. return false;
  19413. }
  19414. newWidth.push( width );
  19415. } );
  19416. var change = changeable ? newWidth : oldWidth;
  19417. utils.each( cells, function( cell, index ){
  19418. cell.width = change[index] - getTabcellSpace();
  19419. } );
  19420. }, 0 );
  19421. // minWidth -= cellMinWidth;
  19422. //
  19423. // table.removeAttribute("width");
  19424. // utils.each(cells, function (cell) {
  19425. // cell.style.width = "";
  19426. // cell.width -= minWidth;
  19427. // });
  19428. }
  19429. }
  19430. }
  19431. }
  19432. function tableClickHander( evt ) {
  19433. removeSelectedClass(domUtils.getElementsByTagName(me.body, "td th"));
  19434. //trace:3113
  19435. //选中单元格,点击table外部,不会清掉table上挂的ueTable,会引起getUETableBySelected方法返回值
  19436. utils.each(me.document.getElementsByTagName('table'), function (t) {
  19437. t.ueTable = null;
  19438. });
  19439. startTd = getTargetTd(me, evt);
  19440. if( !startTd ) return;
  19441. var table = domUtils.findParentByTagName(startTd, "table", true);
  19442. ut = getUETable(table);
  19443. ut && ut.clearSelected();
  19444. //判断当前鼠标状态
  19445. if (!onBorder) {
  19446. me.document.body.style.webkitUserSelect = '';
  19447. mousedown = true;
  19448. me.addListener('mouseover', mouseOverEvent);
  19449. } else {
  19450. //边框上的动作处理
  19451. borderActionHandler( evt );
  19452. }
  19453. }
  19454. //处理表格边框上的动作, 这里做延时处理,避免两种动作互相影响
  19455. function borderActionHandler( evt ) {
  19456. if ( browser.ie ) {
  19457. evt = reconstruct(evt );
  19458. }
  19459. clearTableDragTimer();
  19460. //是否正在等待resize的缓冲中
  19461. isInResizeBuffer = true;
  19462. tableDragTimer = setTimeout(function(){
  19463. tableBorderDrag( evt );
  19464. }, dblclickTime);
  19465. }
  19466. function extractArray( originArr, key ) {
  19467. var result = [],
  19468. tmp = null;
  19469. for( var i = 0, len = originArr.length; i<len; i++ ) {
  19470. tmp = originArr[ i ][ key ];
  19471. if( tmp ) {
  19472. result.push( tmp );
  19473. }
  19474. }
  19475. return result;
  19476. }
  19477. function clearTableDragTimer() {
  19478. tableDragTimer && clearTimeout(tableDragTimer);
  19479. tableDragTimer = null;
  19480. }
  19481. function reconstruct( obj ) {
  19482. var attrs = ['pageX', 'pageY', 'clientX', 'clientY', 'srcElement', 'target'],
  19483. newObj = {};
  19484. if( obj ) {
  19485. for( var i = 0, key, val; key = attrs[i]; i++ ) {
  19486. val=obj[ key ];
  19487. val && (newObj[ key ] = val);
  19488. }
  19489. }
  19490. return newObj;
  19491. }
  19492. //边框拖动
  19493. function tableBorderDrag( evt ) {
  19494. isInResizeBuffer = false;
  19495. startTd = evt.target || evt.srcElement;
  19496. if( !startTd ) return;
  19497. var state = getRelation(startTd, mouseCoords(evt));
  19498. if (/\d/.test(state)) {
  19499. state = state.replace(/\d/, '');
  19500. startTd = getUETable(startTd).getPreviewCell(startTd, state == 'v');
  19501. }
  19502. hideDragLine(me);
  19503. getDragLine(me, me.document);
  19504. me.fireEvent('saveScene');
  19505. showDragLineAt(state, startTd);
  19506. mousedown = true;
  19507. //拖动开始
  19508. onDrag = state;
  19509. dragTd = startTd;
  19510. }
  19511. function mouseUpEvent(type, evt) {
  19512. if( isEditorDisabled() ) {
  19513. return ;
  19514. }
  19515. clearTableDragTimer();
  19516. isInResizeBuffer = false;
  19517. if( onBorder ) {
  19518. singleClickState = ++singleClickState % 3;
  19519. userActionStatus = {
  19520. x: evt.clientX,
  19521. y: evt.clientY
  19522. };
  19523. tableResizeTimer = setTimeout(function(){
  19524. singleClickState > 0 && singleClickState--;
  19525. }, dblclickTime );
  19526. if( singleClickState === 2 ) {
  19527. singleClickState = 0;
  19528. tableDbclickHandler(evt);
  19529. return;
  19530. }
  19531. }
  19532. if (evt.button == 2)return;
  19533. var me = this;
  19534. //清除表格上原生跨选问题
  19535. var range = me.selection.getRange(),
  19536. start = domUtils.findParentByTagName(range.startContainer, 'table', true),
  19537. end = domUtils.findParentByTagName(range.endContainer, 'table', true);
  19538. if (start || end) {
  19539. if (start === end) {
  19540. start = domUtils.findParentByTagName(range.startContainer, ['td', 'th', 'caption'], true);
  19541. end = domUtils.findParentByTagName(range.endContainer, ['td', 'th', 'caption'], true);
  19542. if (start !== end) {
  19543. me.selection.clearRange()
  19544. }
  19545. } else {
  19546. me.selection.clearRange()
  19547. }
  19548. }
  19549. mousedown = false;
  19550. me.document.body.style.webkitUserSelect = '';
  19551. //拖拽状态下的mouseUP
  19552. if ( onDrag && dragTd ) {
  19553. me.selection.getNative()[browser.ie9below ? 'empty' : 'removeAllRanges']();
  19554. singleClickState = 0;
  19555. dragLine = me.document.getElementById('ue_tableDragLine');
  19556. // trace 3973
  19557. if (dragLine) {
  19558. var dragTdPos = domUtils.getXY(dragTd),
  19559. dragLinePos = domUtils.getXY(dragLine);
  19560. switch (onDrag) {
  19561. case "h":
  19562. changeColWidth(dragTd, dragLinePos.x - dragTdPos.x);
  19563. break;
  19564. case "v":
  19565. changeRowHeight(dragTd, dragLinePos.y - dragTdPos.y - dragTd.offsetHeight);
  19566. break;
  19567. default:
  19568. }
  19569. onDrag = "";
  19570. dragTd = null;
  19571. hideDragLine(me);
  19572. me.fireEvent('saveScene');
  19573. return;
  19574. }
  19575. }
  19576. //正常状态下的mouseup
  19577. if (!startTd) {
  19578. var target = domUtils.findParentByTagName(evt.target || evt.srcElement, "td", true);
  19579. if (!target) target = domUtils.findParentByTagName(evt.target || evt.srcElement, "th", true);
  19580. if (target && (target.tagName == "TD" || target.tagName == "TH")) {
  19581. if (me.fireEvent("excludetable", target) === true) return;
  19582. range = new dom.Range(me.document);
  19583. range.setStart(target, 0).setCursor(false, true);
  19584. }
  19585. } else {
  19586. var ut = getUETable(startTd),
  19587. cell = ut ? ut.selectedTds[0] : null;
  19588. if (cell) {
  19589. range = new dom.Range(me.document);
  19590. if (domUtils.isEmptyBlock(cell)) {
  19591. range.setStart(cell, 0).setCursor(false, true);
  19592. } else {
  19593. range.selectNodeContents(cell).shrinkBoundary().setCursor(false, true);
  19594. }
  19595. } else {
  19596. range = me.selection.getRange().shrinkBoundary();
  19597. if (!range.collapsed) {
  19598. var start = domUtils.findParentByTagName(range.startContainer, ['td', 'th'], true),
  19599. end = domUtils.findParentByTagName(range.endContainer, ['td', 'th'], true);
  19600. //在table里边的不能清除
  19601. if (start && !end || !start && end || start && end && start !== end) {
  19602. range.setCursor(false, true);
  19603. }
  19604. }
  19605. }
  19606. startTd = null;
  19607. me.removeListener('mouseover', mouseOverEvent);
  19608. }
  19609. me._selectionChange(250, evt);
  19610. }
  19611. function mouseOverEvent(type, evt) {
  19612. if( isEditorDisabled() ) {
  19613. return;
  19614. }
  19615. var me = this,
  19616. tar = evt.target || evt.srcElement;
  19617. currentTd = domUtils.findParentByTagName(tar, "td", true) || domUtils.findParentByTagName(tar, "th", true);
  19618. //需要判断两个TD是否位于同一个表格内
  19619. if (startTd && currentTd &&
  19620. ((startTd.tagName == "TD" && currentTd.tagName == "TD") || (startTd.tagName == "TH" && currentTd.tagName == "TH")) &&
  19621. domUtils.findParentByTagName(startTd, 'table') == domUtils.findParentByTagName(currentTd, 'table')) {
  19622. var ut = getUETable(currentTd);
  19623. if (startTd != currentTd) {
  19624. me.document.body.style.webkitUserSelect = 'none';
  19625. me.selection.getNative()[browser.ie9below ? 'empty' : 'removeAllRanges']();
  19626. var range = ut.getCellsRange(startTd, currentTd);
  19627. ut.setSelected(range);
  19628. } else {
  19629. me.document.body.style.webkitUserSelect = '';
  19630. ut.clearSelected();
  19631. }
  19632. }
  19633. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  19634. }
  19635. function setCellHeight(cell, height, backHeight) {
  19636. var lineHight = parseInt(domUtils.getComputedStyle(cell, "line-height"), 10),
  19637. tmpHeight = backHeight + height;
  19638. height = tmpHeight < lineHight ? lineHight : tmpHeight;
  19639. if (cell.style.height) cell.style.height = "";
  19640. cell.rowSpan == 1 ? cell.setAttribute("height", height) : (cell.removeAttribute && cell.removeAttribute("height"));
  19641. }
  19642. function getWidth(cell) {
  19643. if (!cell)return 0;
  19644. return parseInt(domUtils.getComputedStyle(cell, "width"), 10);
  19645. }
  19646. function changeColWidth(cell, changeValue) {
  19647. var ut = getUETable(cell);
  19648. if (ut) {
  19649. //根据当前移动的边框获取相关的单元格
  19650. var table = ut.table,
  19651. cells = getCellsByMoveBorder( cell, table );
  19652. table.style.width = "";
  19653. table.removeAttribute("width");
  19654. //修正改变量
  19655. changeValue = correctChangeValue( changeValue, cell, cells );
  19656. if (cell.nextSibling) {
  19657. var i=0;
  19658. utils.each( cells, function( cellGroup ){
  19659. cellGroup.left.width = (+cellGroup.left.width)+changeValue;
  19660. cellGroup.right && ( cellGroup.right.width = (+cellGroup.right.width)-changeValue );
  19661. } );
  19662. } else {
  19663. utils.each( cells, function( cellGroup ){
  19664. cellGroup.left.width -= -changeValue;
  19665. } );
  19666. }
  19667. }
  19668. }
  19669. function isEditorDisabled() {
  19670. return me.body.contentEditable === "false";
  19671. }
  19672. function changeRowHeight(td, changeValue) {
  19673. if (Math.abs(changeValue) < 10) return;
  19674. var ut = getUETable(td);
  19675. if (ut) {
  19676. var cells = ut.getSameEndPosCells(td, "y"),
  19677. //备份需要连带变化的td的原始高度,否则后期无法获取正确的值
  19678. backHeight = cells[0] ? cells[0].offsetHeight : 0;
  19679. for (var i = 0, cell; cell = cells[i++];) {
  19680. setCellHeight(cell, changeValue, backHeight);
  19681. }
  19682. }
  19683. }
  19684. /**
  19685. * 获取调整单元格大小的相关单元格
  19686. * @isContainMergeCell 返回的结果中是否包含发生合并后的单元格
  19687. */
  19688. function getCellsByMoveBorder( cell, table, isContainMergeCell ) {
  19689. if( !table ) {
  19690. table = domUtils.findParentByTagName( cell, 'table' );
  19691. }
  19692. if( !table ) {
  19693. return null;
  19694. }
  19695. //获取到该单元格所在行的序列号
  19696. var index = domUtils.getNodeIndex( cell ),
  19697. temp = cell,
  19698. rows = table.rows,
  19699. colIndex = 0;
  19700. while( temp ) {
  19701. //获取到当前单元格在未发生单元格合并时的序列
  19702. if( temp.nodeType === 1 ) {
  19703. colIndex += (temp.colSpan || 1);
  19704. }
  19705. temp = temp.previousSibling;
  19706. }
  19707. temp = null;
  19708. //记录想关的单元格
  19709. var borderCells = [];
  19710. utils.each(rows, function( tabRow ){
  19711. var cells = tabRow.cells,
  19712. currIndex = 0;
  19713. utils.each( cells, function( tabCell ){
  19714. currIndex += (tabCell.colSpan || 1);
  19715. if( currIndex === colIndex ) {
  19716. borderCells.push({
  19717. left: tabCell,
  19718. right: tabCell.nextSibling || null
  19719. });
  19720. return false;
  19721. } else if( currIndex > colIndex ) {
  19722. if( isContainMergeCell ) {
  19723. borderCells.push({
  19724. left: tabCell
  19725. });
  19726. }
  19727. return false;
  19728. }
  19729. } );
  19730. });
  19731. return borderCells;
  19732. }
  19733. /**
  19734. * 通过给定的单元格集合获取最小的单元格width
  19735. */
  19736. function getMinWidthByTableCells( cells ) {
  19737. var minWidth = Number.MAX_VALUE;
  19738. for( var i = 0, curCell; curCell = cells[ i ] ; i++ ) {
  19739. minWidth = Math.min( minWidth, curCell.width || getTableCellWidth( curCell ) );
  19740. }
  19741. return minWidth;
  19742. }
  19743. function correctChangeValue( changeValue, relatedCell, cells ) {
  19744. //为单元格的paading预留空间
  19745. changeValue -= getTabcellSpace();
  19746. if( changeValue < 0 ) {
  19747. return 0;
  19748. }
  19749. changeValue -= getTableCellWidth( relatedCell );
  19750. //确定方向
  19751. var direction = changeValue < 0 ? 'left':'right';
  19752. changeValue = Math.abs(changeValue);
  19753. //只关心非最后一个单元格就可以
  19754. utils.each( cells, function( cellGroup ){
  19755. var curCell = cellGroup[direction];
  19756. //为单元格保留最小空间
  19757. if( curCell ) {
  19758. changeValue = Math.min( changeValue, getTableCellWidth( curCell )-cellMinWidth );
  19759. }
  19760. } );
  19761. //修正越界
  19762. changeValue = changeValue < 0 ? 0 : changeValue;
  19763. return direction === 'left' ? -changeValue : changeValue;
  19764. }
  19765. function getTableCellWidth( cell ) {
  19766. var width = 0,
  19767. //偏移纠正量
  19768. offset = 0,
  19769. width = cell.offsetWidth - getTabcellSpace();
  19770. //最后一个节点纠正一下
  19771. if( !cell.nextSibling ) {
  19772. width -= getTableCellOffset( cell );
  19773. }
  19774. width = width < 0 ? 0 : width;
  19775. try {
  19776. cell.width = width;
  19777. } catch(e) {
  19778. }
  19779. return width;
  19780. }
  19781. /**
  19782. * 获取单元格所在表格的最末单元格的偏移量
  19783. */
  19784. function getTableCellOffset( cell ) {
  19785. tab = domUtils.findParentByTagName( cell, "table", false);
  19786. if( tab.offsetVal === undefined ) {
  19787. var prev = cell.previousSibling;
  19788. if( prev ) {
  19789. //最后一个单元格和前一个单元格的width diff结果 如果恰好为一个border width, 则条件成立
  19790. tab.offsetVal = cell.offsetWidth - prev.offsetWidth === UT.borderWidth ? UT.borderWidth : 0;
  19791. } else {
  19792. tab.offsetVal = 0;
  19793. }
  19794. }
  19795. return tab.offsetVal;
  19796. }
  19797. function getTabcellSpace() {
  19798. if( UT.tabcellSpace === undefined ) {
  19799. var cell = null,
  19800. tab = me.document.createElement("table"),
  19801. tbody = me.document.createElement("tbody"),
  19802. trow = me.document.createElement("tr"),
  19803. tabcell = me.document.createElement("td"),
  19804. mirror = null;
  19805. tabcell.style.cssText = 'border: 0;';
  19806. tabcell.width = 1;
  19807. trow.appendChild( tabcell );
  19808. trow.appendChild( mirror = tabcell.cloneNode( false ) );
  19809. tbody.appendChild( trow );
  19810. tab.appendChild( tbody );
  19811. tab.style.cssText = "visibility: hidden;";
  19812. me.body.appendChild( tab );
  19813. UT.paddingSpace = tabcell.offsetWidth - 1;
  19814. var tmpTabWidth = tab.offsetWidth;
  19815. tabcell.style.cssText = '';
  19816. mirror.style.cssText = '';
  19817. UT.borderWidth = ( tab.offsetWidth - tmpTabWidth ) / 3;
  19818. UT.tabcellSpace = UT.paddingSpace + UT.borderWidth;
  19819. me.body.removeChild( tab );
  19820. }
  19821. getTabcellSpace = function(){ return UT.tabcellSpace; };
  19822. return UT.tabcellSpace;
  19823. }
  19824. function getDragLine(editor, doc) {
  19825. if (mousedown)return;
  19826. dragLine = editor.document.createElement("div");
  19827. domUtils.setAttributes(dragLine, {
  19828. id:"ue_tableDragLine",
  19829. unselectable:'on',
  19830. contenteditable:false,
  19831. 'onresizestart':'return false',
  19832. 'ondragstart':'return false',
  19833. 'onselectstart':'return false',
  19834. style:"background-color:blue;position:absolute;padding:0;margin:0;background-image:none;border:0px none;opacity:0;filter:alpha(opacity=0)"
  19835. });
  19836. editor.body.appendChild(dragLine);
  19837. }
  19838. function hideDragLine(editor) {
  19839. if (mousedown)return;
  19840. var line;
  19841. while (line = editor.document.getElementById('ue_tableDragLine')) {
  19842. domUtils.remove(line)
  19843. }
  19844. }
  19845. /**
  19846. * 依据state(v|h)在cell位置显示横线
  19847. * @param state
  19848. * @param cell
  19849. */
  19850. function showDragLineAt(state, cell) {
  19851. if (!cell) return;
  19852. var table = domUtils.findParentByTagName(cell, "table"),
  19853. caption = table.getElementsByTagName('caption'),
  19854. width = table.offsetWidth,
  19855. height = table.offsetHeight - (caption.length > 0 ? caption[0].offsetHeight : 0),
  19856. tablePos = domUtils.getXY(table),
  19857. cellPos = domUtils.getXY(cell), css;
  19858. switch (state) {
  19859. case "h":
  19860. css = 'height:' + height + 'px;top:' + (tablePos.y + (caption.length > 0 ? caption[0].offsetHeight : 0)) + 'px;left:' + (cellPos.x + cell.offsetWidth);
  19861. dragLine.style.cssText = css + 'px;position: absolute;display:block;background-color:blue;width:1px;border:0; color:blue;opacity:.3;filter:alpha(opacity=30)';
  19862. break;
  19863. case "v":
  19864. css = 'width:' + width + 'px;left:' + tablePos.x + 'px;top:' + (cellPos.y + cell.offsetHeight );
  19865. //必须加上border:0和color:blue,否则低版ie不支持背景色显示
  19866. 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)';
  19867. break;
  19868. default:
  19869. }
  19870. }
  19871. /**
  19872. * 当表格边框颜色为白色时设置为虚线,true为添加虚线
  19873. * @param editor
  19874. * @param flag
  19875. */
  19876. function switchBorderColor(editor, flag) {
  19877. var tableArr = domUtils.getElementsByTagName(editor.body, "table"), color;
  19878. for (var i = 0, node; node = tableArr[i++];) {
  19879. var td = domUtils.getElementsByTagName(node, "td");
  19880. if (td[0]) {
  19881. if (flag) {
  19882. color = (td[0].style.borderColor).replace(/\s/g, "");
  19883. if (/(#ffffff)|(rgb\(255,255,255\))/ig.test(color))
  19884. domUtils.addClass(node, "noBorderTable")
  19885. } else {
  19886. domUtils.removeClasses(node, "noBorderTable")
  19887. }
  19888. }
  19889. }
  19890. }
  19891. function getTableWidth(editor, needIEHack, defaultValue) {
  19892. var body = editor.body;
  19893. return body.offsetWidth - (needIEHack ? parseInt(domUtils.getComputedStyle(body, 'margin-left'), 10) * 2 : 0) - defaultValue.tableBorder * 2 - (editor.options.offsetWidth || 0);
  19894. }
  19895. /**
  19896. * 获取当前拖动的单元格
  19897. */
  19898. function getTargetTd(editor, evt) {
  19899. var target = domUtils.findParentByTagName(evt.target || evt.srcElement, ["td", "th"], true),
  19900. dir = null;
  19901. if( !target ) {
  19902. return null;
  19903. }
  19904. dir = getRelation( target, mouseCoords( evt ) );
  19905. //如果有前一个节点, 需要做一个修正, 否则可能会得到一个错误的td
  19906. if( !target ) {
  19907. return null;
  19908. }
  19909. if( dir === 'h1' && target.previousSibling ) {
  19910. var position = domUtils.getXY( target),
  19911. cellWidth = target.offsetWidth;
  19912. if( Math.abs( position.x + cellWidth - evt.clientX ) > cellWidth / 3 ) {
  19913. target = target.previousSibling;
  19914. }
  19915. } else if( dir === 'v1' && target.parentNode.previousSibling ) {
  19916. var position = domUtils.getXY( target),
  19917. cellHeight = target.offsetHeight;
  19918. if( Math.abs( position.y + cellHeight - evt.clientY ) > cellHeight / 3 ) {
  19919. target = target.parentNode.previousSibling.firstChild;
  19920. }
  19921. }
  19922. //排除了非td内部以及用于代码高亮部分的td
  19923. return target && !(editor.fireEvent("excludetable", target) === true) ? target : null;
  19924. }
  19925. };
  19926. // plugins/table.sort.js
  19927. /**
  19928. * Created with JetBrains PhpStorm.
  19929. * User: Jinqn
  19930. * Date: 13-10-12
  19931. * Time: 上午10:20
  19932. * To change this template use File | Settings | File Templates.
  19933. */
  19934. UE.UETable.prototype.sortTable = function (sortByCellIndex, compareFn) {
  19935. var table = this.table,
  19936. rows = table.rows,
  19937. trArray = [],
  19938. flag = rows[0].cells[0].tagName === "TH",
  19939. lastRowIndex = 0;
  19940. if(this.selectedTds.length){
  19941. var range = this.cellsRange,
  19942. len = range.endRowIndex + 1;
  19943. for (var i = range.beginRowIndex; i < len; i++) {
  19944. trArray[i] = rows[i];
  19945. }
  19946. trArray.splice(0,range.beginRowIndex);
  19947. lastRowIndex = (range.endRowIndex +1) === this.rowsNum ? 0 : range.endRowIndex +1;
  19948. }else{
  19949. for (var i = 0,len = rows.length; i < len; i++) {
  19950. trArray[i] = rows[i];
  19951. }
  19952. }
  19953. var Fn = {
  19954. 'reversecurrent': function(td1,td2){
  19955. return 1;
  19956. },
  19957. 'orderbyasc': function(td1,td2){
  19958. var value1 = td1.innerText||td1.textContent,
  19959. value2 = td2.innerText||td2.textContent;
  19960. return value1.localeCompare(value2);
  19961. },
  19962. 'reversebyasc': function(td1,td2){
  19963. var value1 = td1.innerHTML,
  19964. value2 = td2.innerHTML;
  19965. return value2.localeCompare(value1);
  19966. },
  19967. 'orderbynum': function(td1,td2){
  19968. var value1 = td1[browser.ie ? 'innerText':'textContent'].match(/\d+/),
  19969. value2 = td2[browser.ie ? 'innerText':'textContent'].match(/\d+/);
  19970. if(value1) value1 = +value1[0];
  19971. if(value2) value2 = +value2[0];
  19972. return (value1||0) - (value2||0);
  19973. },
  19974. 'reversebynum': function(td1,td2){
  19975. var value1 = td1[browser.ie ? 'innerText':'textContent'].match(/\d+/),
  19976. value2 = td2[browser.ie ? 'innerText':'textContent'].match(/\d+/);
  19977. if(value1) value1 = +value1[0];
  19978. if(value2) value2 = +value2[0];
  19979. return (value2||0) - (value1||0);
  19980. }
  19981. };
  19982. //对表格设置排序的标记data-sort-type
  19983. table.setAttribute('data-sort-type', compareFn && typeof compareFn === "string" && Fn[compareFn] ? compareFn:'');
  19984. //th不参与排序
  19985. flag && trArray.splice(0, 1);
  19986. trArray = utils.sort(trArray,function (tr1, tr2) {
  19987. var result;
  19988. if (compareFn && typeof compareFn === "function") {
  19989. result = compareFn.call(this, tr1.cells[sortByCellIndex], tr2.cells[sortByCellIndex]);
  19990. } else if (compareFn && typeof compareFn === "number") {
  19991. result = 1;
  19992. } else if (compareFn && typeof compareFn === "string" && Fn[compareFn]) {
  19993. result = Fn[compareFn].call(this, tr1.cells[sortByCellIndex], tr2.cells[sortByCellIndex]);
  19994. } else {
  19995. result = Fn['orderbyasc'].call(this, tr1.cells[sortByCellIndex], tr2.cells[sortByCellIndex]);
  19996. }
  19997. return result;
  19998. });
  19999. var fragment = table.ownerDocument.createDocumentFragment();
  20000. for (var j = 0, len = trArray.length; j < len; j++) {
  20001. fragment.appendChild(trArray[j]);
  20002. }
  20003. var tbody = table.getElementsByTagName("tbody")[0];
  20004. if(!lastRowIndex){
  20005. tbody.appendChild(fragment);
  20006. }else{
  20007. tbody.insertBefore(fragment,rows[lastRowIndex- range.endRowIndex + range.beginRowIndex - 1])
  20008. }
  20009. };
  20010. UE.plugins['tablesort'] = function () {
  20011. var me = this,
  20012. UT = UE.UETable,
  20013. getUETable = function (tdOrTable) {
  20014. return UT.getUETable(tdOrTable);
  20015. },
  20016. getTableItemsByRange = function (editor) {
  20017. return UT.getTableItemsByRange(editor);
  20018. };
  20019. me.ready(function () {
  20020. //添加表格可排序的样式
  20021. utils.cssRule('tablesort',
  20022. 'table.sortEnabled tr.firstRow th,table.sortEnabled tr.firstRow td{padding-right:20px;background-repeat: no-repeat;background-position: center right;' +
  20023. ' background-image:url(' + me.options.themePath + me.options.theme + '/images/sortable.png);}',
  20024. me.document);
  20025. //做单元格合并操作时,清除可排序标识
  20026. me.addListener("afterexeccommand", function (type, cmd) {
  20027. if( cmd == 'mergeright' || cmd == 'mergedown' || cmd == 'mergecells') {
  20028. this.execCommand('disablesort');
  20029. }
  20030. });
  20031. });
  20032. //表格排序
  20033. UE.commands['sorttable'] = {
  20034. queryCommandState: function () {
  20035. var me = this,
  20036. tableItems = getTableItemsByRange(me);
  20037. if (!tableItems.cell) return -1;
  20038. var table = tableItems.table,
  20039. cells = table.getElementsByTagName("td");
  20040. for (var i = 0, cell; cell = cells[i++];) {
  20041. if (cell.rowSpan != 1 || cell.colSpan != 1) return -1;
  20042. }
  20043. return 0;
  20044. },
  20045. execCommand: function (cmd, fn) {
  20046. var me = this,
  20047. range = me.selection.getRange(),
  20048. bk = range.createBookmark(true),
  20049. tableItems = getTableItemsByRange(me),
  20050. cell = tableItems.cell,
  20051. ut = getUETable(tableItems.table),
  20052. cellInfo = ut.getCellInfo(cell);
  20053. ut.sortTable(cellInfo.cellIndex, fn);
  20054. range.moveToBookmark(bk);
  20055. try{
  20056. range.select();
  20057. }catch(e){}
  20058. }
  20059. };
  20060. //设置表格可排序,清除表格可排序
  20061. UE.commands["enablesort"] = UE.commands["disablesort"] = {
  20062. queryCommandState: function (cmd) {
  20063. var table = getTableItemsByRange(this).table;
  20064. if(table && cmd=='enablesort') {
  20065. var cells = domUtils.getElementsByTagName(table, 'th td');
  20066. for(var i = 0; i<cells.length; i++) {
  20067. if(cells[i].getAttribute('colspan')>1 || cells[i].getAttribute('rowspan')>1) return -1;
  20068. }
  20069. }
  20070. return !table ? -1: cmd=='enablesort' ^ table.getAttribute('data-sort')!='sortEnabled' ? -1:0;
  20071. },
  20072. execCommand: function (cmd) {
  20073. var table = getTableItemsByRange(this).table;
  20074. table.setAttribute("data-sort", cmd == "enablesort" ? "sortEnabled" : "sortDisabled");
  20075. cmd == "enablesort" ? domUtils.addClass(table,"sortEnabled"):domUtils.removeClasses(table,"sortEnabled");
  20076. }
  20077. };
  20078. };
  20079. // plugins/contextmenu.js
  20080. ///import core
  20081. ///commands 右键菜单
  20082. ///commandsName ContextMenu
  20083. ///commandsTitle 右键菜单
  20084. /**
  20085. * 右键菜单
  20086. * @function
  20087. * @name baidu.editor.plugins.contextmenu
  20088. * @author zhanyi
  20089. */
  20090. UE.plugins['contextmenu'] = function () {
  20091. var me = this;
  20092. me.setOpt('enableContextMenu',true);
  20093. if(me.getOpt('enableContextMenu') === false){
  20094. return;
  20095. }
  20096. var lang = me.getLang( "contextMenu" ),
  20097. menu,
  20098. items = me.options.contextMenu || [
  20099. {label:lang['selectall'], cmdName:'selectall'},
  20100. {
  20101. label:lang.cleardoc,
  20102. cmdName:'cleardoc',
  20103. exec:function () {
  20104. if ( confirm( lang.confirmclear ) ) {
  20105. this.execCommand( 'cleardoc' );
  20106. }
  20107. }
  20108. },
  20109. '-',
  20110. {
  20111. label:lang.unlink,
  20112. cmdName:'unlink'
  20113. },
  20114. '-',
  20115. {
  20116. group:lang.paragraph,
  20117. icon:'justifyjustify',
  20118. subMenu:[
  20119. {
  20120. label:lang.justifyleft,
  20121. cmdName:'justify',
  20122. value:'left'
  20123. },
  20124. {
  20125. label:lang.justifyright,
  20126. cmdName:'justify',
  20127. value:'right'
  20128. },
  20129. {
  20130. label:lang.justifycenter,
  20131. cmdName:'justify',
  20132. value:'center'
  20133. },
  20134. {
  20135. label:lang.justifyjustify,
  20136. cmdName:'justify',
  20137. value:'justify'
  20138. }
  20139. ]
  20140. },
  20141. '-',
  20142. {
  20143. group:lang.table,
  20144. icon:'table',
  20145. subMenu:[
  20146. {
  20147. label:lang.inserttable,
  20148. cmdName:'inserttable'
  20149. },
  20150. {
  20151. label:lang.deletetable,
  20152. cmdName:'deletetable'
  20153. },
  20154. '-',
  20155. {
  20156. label:lang.deleterow,
  20157. cmdName:'deleterow'
  20158. },
  20159. {
  20160. label:lang.deletecol,
  20161. cmdName:'deletecol'
  20162. },
  20163. {
  20164. label:lang.insertcol,
  20165. cmdName:'insertcol'
  20166. },
  20167. {
  20168. label:lang.insertcolnext,
  20169. cmdName:'insertcolnext'
  20170. },
  20171. {
  20172. label:lang.insertrow,
  20173. cmdName:'insertrow'
  20174. },
  20175. {
  20176. label:lang.insertrownext,
  20177. cmdName:'insertrownext'
  20178. },
  20179. '-',
  20180. {
  20181. label:lang.insertcaption,
  20182. cmdName:'insertcaption'
  20183. },
  20184. {
  20185. label:lang.deletecaption,
  20186. cmdName:'deletecaption'
  20187. },
  20188. {
  20189. label:lang.inserttitle,
  20190. cmdName:'inserttitle'
  20191. },
  20192. {
  20193. label:lang.deletetitle,
  20194. cmdName:'deletetitle'
  20195. },
  20196. {
  20197. label:lang.inserttitlecol,
  20198. cmdName:'inserttitlecol'
  20199. },
  20200. {
  20201. label:lang.deletetitlecol,
  20202. cmdName:'deletetitlecol'
  20203. },
  20204. '-',
  20205. {
  20206. label:lang.mergecells,
  20207. cmdName:'mergecells'
  20208. },
  20209. {
  20210. label:lang.mergeright,
  20211. cmdName:'mergeright'
  20212. },
  20213. {
  20214. label:lang.mergedown,
  20215. cmdName:'mergedown'
  20216. },
  20217. '-',
  20218. {
  20219. label:lang.splittorows,
  20220. cmdName:'splittorows'
  20221. },
  20222. {
  20223. label:lang.splittocols,
  20224. cmdName:'splittocols'
  20225. },
  20226. {
  20227. label:lang.splittocells,
  20228. cmdName:'splittocells'
  20229. },
  20230. '-',
  20231. {
  20232. label:lang.averageDiseRow,
  20233. cmdName:'averagedistributerow'
  20234. },
  20235. {
  20236. label:lang.averageDisCol,
  20237. cmdName:'averagedistributecol'
  20238. },
  20239. '-',
  20240. {
  20241. label:lang.edittd,
  20242. cmdName:'edittd',
  20243. exec:function () {
  20244. if ( UE.ui['edittd'] ) {
  20245. new UE.ui['edittd']( this );
  20246. }
  20247. this.getDialog('edittd').open();
  20248. }
  20249. },
  20250. {
  20251. label:lang.edittable,
  20252. cmdName:'edittable',
  20253. exec:function () {
  20254. if ( UE.ui['edittable'] ) {
  20255. new UE.ui['edittable']( this );
  20256. }
  20257. this.getDialog('edittable').open();
  20258. }
  20259. },
  20260. {
  20261. label:lang.setbordervisible,
  20262. cmdName:'setbordervisible'
  20263. }
  20264. ]
  20265. },
  20266. {
  20267. group:lang.tablesort,
  20268. icon:'tablesort',
  20269. subMenu:[
  20270. {
  20271. label:lang.enablesort,
  20272. cmdName:'enablesort'
  20273. },
  20274. {
  20275. label:lang.disablesort,
  20276. cmdName:'disablesort'
  20277. },
  20278. '-',
  20279. {
  20280. label:lang.reversecurrent,
  20281. cmdName:'sorttable',
  20282. value:'reversecurrent'
  20283. },
  20284. {
  20285. label:lang.orderbyasc,
  20286. cmdName:'sorttable',
  20287. value:'orderbyasc'
  20288. },
  20289. {
  20290. label:lang.reversebyasc,
  20291. cmdName:'sorttable',
  20292. value:'reversebyasc'
  20293. },
  20294. {
  20295. label:lang.orderbynum,
  20296. cmdName:'sorttable',
  20297. value:'orderbynum'
  20298. },
  20299. {
  20300. label:lang.reversebynum,
  20301. cmdName:'sorttable',
  20302. value:'reversebynum'
  20303. }
  20304. ]
  20305. },
  20306. {
  20307. group:lang.borderbk,
  20308. icon:'borderBack',
  20309. subMenu:[
  20310. {
  20311. label:lang.setcolor,
  20312. cmdName:"interlacetable",
  20313. exec:function(){
  20314. this.execCommand("interlacetable");
  20315. }
  20316. },
  20317. {
  20318. label:lang.unsetcolor,
  20319. cmdName:"uninterlacetable",
  20320. exec:function(){
  20321. this.execCommand("uninterlacetable");
  20322. }
  20323. },
  20324. {
  20325. label:lang.setbackground,
  20326. cmdName:"settablebackground",
  20327. exec:function(){
  20328. this.execCommand("settablebackground",{repeat:true,colorList:["#bbb","#ccc"]});
  20329. }
  20330. },
  20331. {
  20332. label:lang.unsetbackground,
  20333. cmdName:"cleartablebackground",
  20334. exec:function(){
  20335. this.execCommand("cleartablebackground");
  20336. }
  20337. },
  20338. {
  20339. label:lang.redandblue,
  20340. cmdName:"settablebackground",
  20341. exec:function(){
  20342. this.execCommand("settablebackground",{repeat:true,colorList:["red","blue"]});
  20343. }
  20344. },
  20345. {
  20346. label:lang.threecolorgradient,
  20347. cmdName:"settablebackground",
  20348. exec:function(){
  20349. this.execCommand("settablebackground",{repeat:true,colorList:["#aaa","#bbb","#ccc"]});
  20350. }
  20351. }
  20352. ]
  20353. },
  20354. {
  20355. group:lang.aligntd,
  20356. icon:'aligntd',
  20357. subMenu:[
  20358. {
  20359. cmdName:'cellalignment',
  20360. value:{align:'left',vAlign:'top'}
  20361. },
  20362. {
  20363. cmdName:'cellalignment',
  20364. value:{align:'center',vAlign:'top'}
  20365. },
  20366. {
  20367. cmdName:'cellalignment',
  20368. value:{align:'right',vAlign:'top'}
  20369. },
  20370. {
  20371. cmdName:'cellalignment',
  20372. value:{align:'left',vAlign:'middle'}
  20373. },
  20374. {
  20375. cmdName:'cellalignment',
  20376. value:{align:'center',vAlign:'middle'}
  20377. },
  20378. {
  20379. cmdName:'cellalignment',
  20380. value:{align:'right',vAlign:'middle'}
  20381. },
  20382. {
  20383. cmdName:'cellalignment',
  20384. value:{align:'left',vAlign:'bottom'}
  20385. },
  20386. {
  20387. cmdName:'cellalignment',
  20388. value:{align:'center',vAlign:'bottom'}
  20389. },
  20390. {
  20391. cmdName:'cellalignment',
  20392. value:{align:'right',vAlign:'bottom'}
  20393. }
  20394. ]
  20395. },
  20396. {
  20397. group:lang.aligntable,
  20398. icon:'aligntable',
  20399. subMenu:[
  20400. {
  20401. cmdName:'tablealignment',
  20402. className: 'left',
  20403. label:lang.tableleft,
  20404. value:"left"
  20405. },
  20406. {
  20407. cmdName:'tablealignment',
  20408. className: 'center',
  20409. label:lang.tablecenter,
  20410. value:"center"
  20411. },
  20412. {
  20413. cmdName:'tablealignment',
  20414. className: 'right',
  20415. label:lang.tableright,
  20416. value:"right"
  20417. }
  20418. ]
  20419. },
  20420. '-',
  20421. {
  20422. label:lang.insertparagraphbefore,
  20423. cmdName:'insertparagraph',
  20424. value:true
  20425. },
  20426. {
  20427. label:lang.insertparagraphafter,
  20428. cmdName:'insertparagraph'
  20429. },
  20430. {
  20431. label:lang['copy'],
  20432. cmdName:'copy'
  20433. },
  20434. {
  20435. label:lang['paste'],
  20436. cmdName:'paste'
  20437. }
  20438. ];
  20439. if ( !items.length ) {
  20440. return;
  20441. }
  20442. var uiUtils = UE.ui.uiUtils;
  20443. me.addListener( 'contextmenu', function ( type, evt ) {
  20444. var offset = uiUtils.getViewportOffsetByEvent( evt );
  20445. me.fireEvent( 'beforeselectionchange' );
  20446. if ( menu ) {
  20447. menu.destroy();
  20448. }
  20449. for ( var i = 0, ti, contextItems = []; ti = items[i]; i++ ) {
  20450. var last;
  20451. (function ( item ) {
  20452. if ( item == '-' ) {
  20453. if ( (last = contextItems[contextItems.length - 1 ] ) && last !== '-' ) {
  20454. contextItems.push( '-' );
  20455. }
  20456. } else if ( item.hasOwnProperty( "group" ) ) {
  20457. for ( var j = 0, cj, subMenu = []; cj = item.subMenu[j]; j++ ) {
  20458. (function ( subItem ) {
  20459. if ( subItem == '-' ) {
  20460. if ( (last = subMenu[subMenu.length - 1 ] ) && last !== '-' ) {
  20461. subMenu.push( '-' );
  20462. }else{
  20463. subMenu.splice(subMenu.length-1);
  20464. }
  20465. } else {
  20466. if ( (me.commands[subItem.cmdName] || UE.commands[subItem.cmdName] || subItem.query) &&
  20467. (subItem.query ? subItem.query() : me.queryCommandState( subItem.cmdName )) > -1 ) {
  20468. subMenu.push( {
  20469. 'label':subItem.label || me.getLang( "contextMenu." + subItem.cmdName + (subItem.value || '') )||"",
  20470. 'className':'edui-for-' +subItem.cmdName + ( subItem.className ? ( ' edui-for-' + subItem.cmdName + '-' + subItem.className ) : '' ),
  20471. onclick:subItem.exec ? function () {
  20472. subItem.exec.call( me );
  20473. } : function () {
  20474. me.execCommand( subItem.cmdName, subItem.value );
  20475. }
  20476. } );
  20477. }
  20478. }
  20479. })( cj );
  20480. }
  20481. if ( subMenu.length ) {
  20482. function getLabel(){
  20483. switch (item.icon){
  20484. case "table":
  20485. return me.getLang( "contextMenu.table" );
  20486. case "justifyjustify":
  20487. return me.getLang( "contextMenu.paragraph" );
  20488. case "aligntd":
  20489. return me.getLang("contextMenu.aligntd");
  20490. case "aligntable":
  20491. return me.getLang("contextMenu.aligntable");
  20492. case "tablesort":
  20493. return lang.tablesort;
  20494. case "borderBack":
  20495. return lang.borderbk;
  20496. default :
  20497. return '';
  20498. }
  20499. }
  20500. contextItems.push( {
  20501. //todo 修正成自动获取方式
  20502. 'label':getLabel(),
  20503. className:'edui-for-' + item.icon,
  20504. 'subMenu':{
  20505. items:subMenu,
  20506. editor:me
  20507. }
  20508. } );
  20509. }
  20510. } else {
  20511. //有可能commmand没有加载右键不能出来,或者没有command也想能展示出来添加query方法
  20512. if ( (me.commands[item.cmdName] || UE.commands[item.cmdName] || item.query) &&
  20513. (item.query ? item.query.call(me) : me.queryCommandState( item.cmdName )) > -1 ) {
  20514. contextItems.push( {
  20515. 'label':item.label || me.getLang( "contextMenu." + item.cmdName ),
  20516. className:'edui-for-' + (item.icon ? item.icon : item.cmdName + (item.value || '')),
  20517. onclick:item.exec ? function () {
  20518. item.exec.call( me );
  20519. } : function () {
  20520. me.execCommand( item.cmdName, item.value );
  20521. }
  20522. } );
  20523. }
  20524. }
  20525. })( ti );
  20526. }
  20527. if ( contextItems[contextItems.length - 1] == '-' ) {
  20528. contextItems.pop();
  20529. }
  20530. menu = new UE.ui.Menu( {
  20531. items:contextItems,
  20532. className:"edui-contextmenu",
  20533. editor:me
  20534. } );
  20535. menu.render();
  20536. menu.showAt( offset );
  20537. me.fireEvent("aftershowcontextmenu",menu);
  20538. domUtils.preventDefault( evt );
  20539. if ( browser.ie ) {
  20540. var ieRange;
  20541. try {
  20542. ieRange = me.selection.getNative().createRange();
  20543. } catch ( e ) {
  20544. return;
  20545. }
  20546. if ( ieRange.item ) {
  20547. var range = new dom.Range( me.document );
  20548. range.selectNode( ieRange.item( 0 ) ).select( true, true );
  20549. }
  20550. }
  20551. });
  20552. // 添加复制的flash按钮
  20553. me.addListener('aftershowcontextmenu', function(type, menu) {
  20554. if (me.zeroclipboard) {
  20555. var items = menu.items;
  20556. for (var key in items) {
  20557. if (items[key].className == 'edui-for-copy') {
  20558. me.zeroclipboard.clip(items[key].getDom());
  20559. }
  20560. }
  20561. }
  20562. });
  20563. };
  20564. // plugins/shortcutmenu.js
  20565. ///import core
  20566. ///commands 弹出菜单
  20567. // commandsName popupmenu
  20568. ///commandsTitle 弹出菜单
  20569. /**
  20570. * 弹出菜单
  20571. * @function
  20572. * @name baidu.editor.plugins.popupmenu
  20573. * @author xuheng
  20574. */
  20575. UE.plugins['shortcutmenu'] = function () {
  20576. var me = this,
  20577. menu,
  20578. items = me.options.shortcutMenu || [];
  20579. if (!items.length) {
  20580. return;
  20581. }
  20582. me.addListener ('contextmenu mouseup' , function (type , e) {
  20583. var me = this,
  20584. customEvt = {
  20585. type : type ,
  20586. target : e.target || e.srcElement ,
  20587. screenX : e.screenX ,
  20588. screenY : e.screenY ,
  20589. clientX : e.clientX ,
  20590. clientY : e.clientY
  20591. };
  20592. setTimeout (function () {
  20593. var rng = me.selection.getRange ();
  20594. if (rng.collapsed === false || type == "contextmenu") {
  20595. if (!menu) {
  20596. menu = new baidu.editor.ui.ShortCutMenu ({
  20597. editor : me ,
  20598. items : items ,
  20599. theme : me.options.theme ,
  20600. className : 'edui-shortcutmenu'
  20601. });
  20602. menu.render ();
  20603. me.fireEvent ("afterrendershortcutmenu" , menu);
  20604. }
  20605. menu.show (customEvt , !!UE.plugins['contextmenu']);
  20606. }
  20607. });
  20608. if (type == 'contextmenu') {
  20609. domUtils.preventDefault (e);
  20610. if (browser.ie9below) {
  20611. var ieRange;
  20612. try {
  20613. ieRange = me.selection.getNative().createRange();
  20614. } catch (e) {
  20615. return;
  20616. }
  20617. if (ieRange.item) {
  20618. var range = new dom.Range (me.document);
  20619. range.selectNode (ieRange.item (0)).select (true , true);
  20620. }
  20621. }
  20622. }
  20623. });
  20624. me.addListener ('keydown' , function (type) {
  20625. if (type == "keydown") {
  20626. menu && !menu.isHidden && menu.hide ();
  20627. }
  20628. });
  20629. };
  20630. // plugins/basestyle.js
  20631. /**
  20632. * B、I、sub、super命令支持
  20633. * @file
  20634. * @since 1.2.6.1
  20635. */
  20636. UE.plugins['basestyle'] = function(){
  20637. /**
  20638. * 字体加粗
  20639. * @command bold
  20640. * @param { String } cmd 命令字符串
  20641. * @remind 对已加粗的文本内容执行该命令, 将取消加粗
  20642. * @method execCommand
  20643. * @example
  20644. * ```javascript
  20645. * //editor是编辑器实例
  20646. * //对当前选中的文本内容执行加粗操作
  20647. * //第一次执行, 文本内容加粗
  20648. * editor.execCommand( 'bold' );
  20649. *
  20650. * //第二次执行, 文本内容取消加粗
  20651. * editor.execCommand( 'bold' );
  20652. * ```
  20653. */
  20654. /**
  20655. * 字体倾斜
  20656. * @command italic
  20657. * @method execCommand
  20658. * @param { String } cmd 命令字符串
  20659. * @remind 对已倾斜的文本内容执行该命令, 将取消倾斜
  20660. * @example
  20661. * ```javascript
  20662. * //editor是编辑器实例
  20663. * //对当前选中的文本内容执行斜体操作
  20664. * //第一次操作, 文本内容将变成斜体
  20665. * editor.execCommand( 'italic' );
  20666. *
  20667. * //再次对同一文本内容执行, 则文本内容将恢复正常
  20668. * editor.execCommand( 'italic' );
  20669. * ```
  20670. */
  20671. /**
  20672. * 下标文本,与“superscript”命令互斥
  20673. * @command subscript
  20674. * @method execCommand
  20675. * @remind 把选中的文本内容切换成下标文本, 如果当前选中的文本已经是下标, 则该操作会把文本内容还原成正常文本
  20676. * @param { String } cmd 命令字符串
  20677. * @example
  20678. * ```javascript
  20679. * //editor是编辑器实例
  20680. * //对当前选中的文本内容执行下标操作
  20681. * //第一次操作, 文本内容将变成下标文本
  20682. * editor.execCommand( 'subscript' );
  20683. *
  20684. * //再次对同一文本内容执行, 则文本内容将恢复正常
  20685. * editor.execCommand( 'subscript' );
  20686. * ```
  20687. */
  20688. /**
  20689. * 上标文本,与“subscript”命令互斥
  20690. * @command superscript
  20691. * @method execCommand
  20692. * @remind 把选中的文本内容切换成上标文本, 如果当前选中的文本已经是上标, 则该操作会把文本内容还原成正常文本
  20693. * @param { String } cmd 命令字符串
  20694. * @example
  20695. * ```javascript
  20696. * //editor是编辑器实例
  20697. * //对当前选中的文本内容执行上标操作
  20698. * //第一次操作, 文本内容将变成上标文本
  20699. * editor.execCommand( 'superscript' );
  20700. *
  20701. * //再次对同一文本内容执行, 则文本内容将恢复正常
  20702. * editor.execCommand( 'superscript' );
  20703. * ```
  20704. */
  20705. var basestyles = {
  20706. 'bold':['strong','b'],
  20707. 'italic':['em','i'],
  20708. 'subscript':['sub'],
  20709. 'superscript':['sup']
  20710. },
  20711. getObj = function(editor,tagNames){
  20712. return domUtils.filterNodeList(editor.selection.getStartElementPath(),tagNames);
  20713. },
  20714. me = this;
  20715. //添加快捷键
  20716. me.addshortcutkey({
  20717. "Bold" : "ctrl+66",//^B
  20718. "Italic" : "ctrl+73", //^I
  20719. "Underline" : "ctrl+85"//^U
  20720. });
  20721. me.addInputRule(function(root){
  20722. utils.each(root.getNodesByTagName('b i'),function(node){
  20723. switch (node.tagName){
  20724. case 'b':
  20725. node.tagName = 'strong';
  20726. break;
  20727. case 'i':
  20728. node.tagName = 'em';
  20729. }
  20730. });
  20731. });
  20732. for ( var style in basestyles ) {
  20733. (function( cmd, tagNames ) {
  20734. me.commands[cmd] = {
  20735. execCommand : function( cmdName ) {
  20736. var range = me.selection.getRange(),obj = getObj(this,tagNames);
  20737. if ( range.collapsed ) {
  20738. if ( obj ) {
  20739. var tmpText = me.document.createTextNode('');
  20740. range.insertNode( tmpText ).removeInlineStyle( tagNames );
  20741. range.setStartBefore(tmpText);
  20742. domUtils.remove(tmpText);
  20743. } else {
  20744. var tmpNode = range.document.createElement( tagNames[0] );
  20745. if(cmdName == 'superscript' || cmdName == 'subscript'){
  20746. tmpText = me.document.createTextNode('');
  20747. range.insertNode(tmpText)
  20748. .removeInlineStyle(['sub','sup'])
  20749. .setStartBefore(tmpText)
  20750. .collapse(true);
  20751. }
  20752. range.insertNode( tmpNode ).setStart( tmpNode, 0 );
  20753. }
  20754. range.collapse( true );
  20755. } else {
  20756. if(cmdName == 'superscript' || cmdName == 'subscript'){
  20757. if(!obj || obj.tagName.toLowerCase() != cmdName){
  20758. range.removeInlineStyle(['sub','sup']);
  20759. }
  20760. }
  20761. obj ? range.removeInlineStyle( tagNames ) : range.applyInlineStyle( tagNames[0] );
  20762. }
  20763. range.select();
  20764. },
  20765. queryCommandState : function() {
  20766. return getObj(this,tagNames) ? 1 : 0;
  20767. }
  20768. };
  20769. })( style, basestyles[style] );
  20770. }
  20771. };
  20772. // plugins/elementpath.js
  20773. /**
  20774. * 选取路径命令
  20775. * @file
  20776. */
  20777. UE.plugins['elementpath'] = function(){
  20778. var currentLevel,
  20779. tagNames,
  20780. me = this;
  20781. me.setOpt('elementPathEnabled',true);
  20782. if(!me.options.elementPathEnabled){
  20783. return;
  20784. }
  20785. me.commands['elementpath'] = {
  20786. execCommand : function( cmdName, level ) {
  20787. var start = tagNames[level],
  20788. range = me.selection.getRange();
  20789. currentLevel = level*1;
  20790. range.selectNode(start).select();
  20791. },
  20792. queryCommandValue : function() {
  20793. //产生一个副本,不能修改原来的startElementPath;
  20794. var parents = [].concat(this.selection.getStartElementPath()).reverse(),
  20795. names = [];
  20796. tagNames = parents;
  20797. for(var i=0,ci;ci=parents[i];i++){
  20798. if(ci.nodeType == 3) {
  20799. continue;
  20800. }
  20801. var name = ci.tagName.toLowerCase();
  20802. if(name == 'img' && ci.getAttribute('anchorname')){
  20803. name = 'anchor';
  20804. }
  20805. names[i] = name;
  20806. if(currentLevel == i){
  20807. currentLevel = -1;
  20808. break;
  20809. }
  20810. }
  20811. return names;
  20812. }
  20813. };
  20814. };
  20815. // plugins/formatmatch.js
  20816. /**
  20817. * 格式刷,只格式inline的
  20818. * @file
  20819. * @since 1.2.6.1
  20820. */
  20821. /**
  20822. * 格式刷
  20823. * @command formatmatch
  20824. * @method execCommand
  20825. * @remind 该操作不能复制段落格式
  20826. * @param { String } cmd 命令字符串
  20827. * @example
  20828. * ```javascript
  20829. * //editor是编辑器实例
  20830. * //获取格式刷
  20831. * editor.execCommand( 'formatmatch' );
  20832. * ```
  20833. */
  20834. UE.plugins['formatmatch'] = function(){
  20835. var me = this,
  20836. list = [],img,
  20837. flag = 0;
  20838. me.addListener('reset',function(){
  20839. list = [];
  20840. flag = 0;
  20841. });
  20842. function addList(type,evt){
  20843. if(browser.webkit){
  20844. var target = evt.target.tagName == 'IMG' ? evt.target : null;
  20845. }
  20846. function addFormat(range){
  20847. if(text){
  20848. range.selectNode(text);
  20849. }
  20850. return range.applyInlineStyle(list[list.length-1].tagName,null,list);
  20851. }
  20852. me.undoManger && me.undoManger.save();
  20853. var range = me.selection.getRange(),
  20854. imgT = target || range.getClosedNode();
  20855. if(img && imgT && imgT.tagName == 'IMG'){
  20856. //trace:964
  20857. imgT.style.cssText += ';float:' + (img.style.cssFloat || img.style.styleFloat ||'none') + ';display:' + (img.style.display||'inline');
  20858. img = null;
  20859. }else{
  20860. if(!img){
  20861. var collapsed = range.collapsed;
  20862. if(collapsed){
  20863. var text = me.document.createTextNode('match');
  20864. range.insertNode(text).select();
  20865. }
  20866. me.__hasEnterExecCommand = true;
  20867. //不能把block上的属性干掉
  20868. //trace:1553
  20869. var removeFormatAttributes = me.options.removeFormatAttributes;
  20870. me.options.removeFormatAttributes = '';
  20871. me.execCommand('removeformat');
  20872. me.options.removeFormatAttributes = removeFormatAttributes;
  20873. me.__hasEnterExecCommand = false;
  20874. //trace:969
  20875. range = me.selection.getRange();
  20876. if(list.length){
  20877. addFormat(range);
  20878. }
  20879. if(text){
  20880. range.setStartBefore(text).collapse(true);
  20881. }
  20882. range.select();
  20883. text && domUtils.remove(text);
  20884. }
  20885. }
  20886. me.undoManger && me.undoManger.save();
  20887. me.removeListener('mouseup',addList);
  20888. flag = 0;
  20889. }
  20890. me.commands['formatmatch'] = {
  20891. execCommand : function( cmdName ) {
  20892. if(flag){
  20893. flag = 0;
  20894. list = [];
  20895. me.removeListener('mouseup',addList);
  20896. return;
  20897. }
  20898. var range = me.selection.getRange();
  20899. img = range.getClosedNode();
  20900. if(!img || img.tagName != 'IMG'){
  20901. range.collapse(true).shrinkBoundary();
  20902. var start = range.startContainer;
  20903. list = domUtils.findParents(start,true,function(node){
  20904. return !domUtils.isBlockElm(node) && node.nodeType == 1;
  20905. });
  20906. //a不能加入格式刷, 并且克隆节点
  20907. for(var i=0,ci;ci=list[i];i++){
  20908. if(ci.tagName == 'A'){
  20909. list.splice(i,1);
  20910. break;
  20911. }
  20912. }
  20913. }
  20914. me.addListener('mouseup',addList);
  20915. flag = 1;
  20916. },
  20917. queryCommandState : function() {
  20918. return flag;
  20919. },
  20920. notNeedUndo : 1
  20921. };
  20922. };
  20923. // plugins/searchreplace.js
  20924. ///import core
  20925. ///commands 查找替换
  20926. ///commandsName SearchReplace
  20927. ///commandsTitle 查询替换
  20928. ///commandsDialog dialogs\searchreplace
  20929. /**
  20930. * @description 查找替换
  20931. * @author zhanyi
  20932. */
  20933. UE.plugin.register('searchreplace',function(){
  20934. var me = this;
  20935. var _blockElm = {'table':1,'tbody':1,'tr':1,'ol':1,'ul':1};
  20936. function findTextInString(textContent,opt,currentIndex){
  20937. var str = opt.searchStr;
  20938. if(opt.dir == -1){
  20939. textContent = textContent.split('').reverse().join('');
  20940. str = str.split('').reverse().join('');
  20941. currentIndex = textContent.length - currentIndex;
  20942. }
  20943. var reg = new RegExp(str,'g' + (opt.casesensitive ? '' : 'i')),match;
  20944. while(match = reg.exec(textContent)){
  20945. if(match.index >= currentIndex){
  20946. return opt.dir == -1 ? textContent.length - match.index - opt.searchStr.length : match.index;
  20947. }
  20948. }
  20949. return -1
  20950. }
  20951. function findTextBlockElm(node,currentIndex,opt){
  20952. var textContent,index,methodName = opt.all || opt.dir == 1 ? 'getNextDomNode' : 'getPreDomNode';
  20953. if(domUtils.isBody(node)){
  20954. node = node.firstChild;
  20955. }
  20956. var first = 1;
  20957. while(node){
  20958. textContent = node.nodeType == 3 ? node.nodeValue : node[browser.ie ? 'innerText' : 'textContent'];
  20959. index = findTextInString(textContent,opt,currentIndex );
  20960. first = 0;
  20961. if(index!=-1){
  20962. return {
  20963. 'node':node,
  20964. 'index':index
  20965. }
  20966. }
  20967. node = domUtils[methodName](node);
  20968. while(node && _blockElm[node.nodeName.toLowerCase()]){
  20969. node = domUtils[methodName](node,true);
  20970. }
  20971. if(node){
  20972. currentIndex = opt.dir == -1 ? (node.nodeType == 3 ? node.nodeValue : node[browser.ie ? 'innerText' : 'textContent']).length : 0;
  20973. }
  20974. }
  20975. }
  20976. function findNTextInBlockElm(node,index,str){
  20977. var currentIndex = 0,
  20978. currentNode = node.firstChild,
  20979. currentNodeLength = 0,
  20980. result;
  20981. while(currentNode){
  20982. if(currentNode.nodeType == 3){
  20983. currentNodeLength = currentNode.nodeValue.replace(/(^[\t\r\n]+)|([\t\r\n]+$)/,'').length;
  20984. currentIndex += currentNodeLength;
  20985. if(currentIndex >= index){
  20986. return {
  20987. 'node':currentNode,
  20988. 'index': currentNodeLength - (currentIndex - index)
  20989. }
  20990. }
  20991. }else if(!dtd.$empty[currentNode.tagName]){
  20992. currentNodeLength = currentNode[browser.ie ? 'innerText' : 'textContent'].replace(/(^[\t\r\n]+)|([\t\r\n]+$)/,'').length
  20993. currentIndex += currentNodeLength;
  20994. if(currentIndex >= index){
  20995. result = findNTextInBlockElm(currentNode,currentNodeLength - (currentIndex - index),str);
  20996. if(result){
  20997. return result;
  20998. }
  20999. }
  21000. }
  21001. currentNode = domUtils.getNextDomNode(currentNode);
  21002. }
  21003. }
  21004. function searchReplace(me,opt){
  21005. var rng = me.selection.getRange(),
  21006. startBlockNode,
  21007. searchStr = opt.searchStr,
  21008. span = me.document.createElement('span');
  21009. span.innerHTML = '$$ueditor_searchreplace_key$$';
  21010. rng.shrinkBoundary(true);
  21011. //判断是不是第一次选中
  21012. if(!rng.collapsed){
  21013. rng.select();
  21014. var rngText = me.selection.getText();
  21015. if(new RegExp('^' + opt.searchStr + '$',(opt.casesensitive ? '' : 'i')).test(rngText)){
  21016. if(opt.replaceStr != undefined){
  21017. replaceText(rng,opt.replaceStr);
  21018. rng.select();
  21019. return true;
  21020. }else{
  21021. rng.collapse(opt.dir == -1)
  21022. }
  21023. }
  21024. }
  21025. rng.insertNode(span);
  21026. rng.enlargeToBlockElm(true);
  21027. startBlockNode = rng.startContainer;
  21028. var currentIndex = startBlockNode[browser.ie ? 'innerText' : 'textContent'].indexOf('$$ueditor_searchreplace_key$$');
  21029. rng.setStartBefore(span);
  21030. domUtils.remove(span);
  21031. var result = findTextBlockElm(startBlockNode,currentIndex,opt);
  21032. if(result){
  21033. var rngStart = findNTextInBlockElm(result.node,result.index,searchStr);
  21034. var rngEnd = findNTextInBlockElm(result.node,result.index + searchStr.length,searchStr);
  21035. rng.setStart(rngStart.node,rngStart.index).setEnd(rngEnd.node,rngEnd.index);
  21036. if(opt.replaceStr !== undefined){
  21037. replaceText(rng,opt.replaceStr)
  21038. }
  21039. rng.select();
  21040. return true;
  21041. }else{
  21042. rng.setCursor()
  21043. }
  21044. }
  21045. function replaceText(rng,str){
  21046. str = me.document.createTextNode(str);
  21047. rng.deleteContents().insertNode(str);
  21048. }
  21049. return {
  21050. commands:{
  21051. 'searchreplace':{
  21052. execCommand:function(cmdName,opt){
  21053. utils.extend(opt,{
  21054. all : false,
  21055. casesensitive : false,
  21056. dir : 1
  21057. },true);
  21058. var num = 0;
  21059. if(opt.all){
  21060. var rng = me.selection.getRange(),
  21061. first = me.body.firstChild;
  21062. if(first && first.nodeType == 1){
  21063. rng.setStart(first,0);
  21064. rng.shrinkBoundary(true);
  21065. }else if(first.nodeType == 3){
  21066. rng.setStartBefore(first)
  21067. }
  21068. rng.collapse(true).select(true);
  21069. if(opt.replaceStr !== undefined){
  21070. me.fireEvent('saveScene');
  21071. }
  21072. while(searchReplace(this,opt)){
  21073. num++;
  21074. }
  21075. if(num){
  21076. me.fireEvent('saveScene');
  21077. }
  21078. }else{
  21079. if(opt.replaceStr !== undefined){
  21080. me.fireEvent('saveScene');
  21081. }
  21082. if(searchReplace(this,opt)){
  21083. num++
  21084. }
  21085. if(num){
  21086. me.fireEvent('saveScene');
  21087. }
  21088. }
  21089. return num;
  21090. },
  21091. notNeedUndo:1
  21092. }
  21093. }
  21094. }
  21095. });
  21096. // plugins/customstyle.js
  21097. /**
  21098. * 自定义样式
  21099. * @file
  21100. * @since 1.2.6.1
  21101. */
  21102. /**
  21103. * 根据config配置文件里“customstyle”选项的值对匹配的标签执行样式替换。
  21104. * @command customstyle
  21105. * @method execCommand
  21106. * @param { String } cmd 命令字符串
  21107. * @example
  21108. * ```javascript
  21109. * editor.execCommand( 'customstyle' );
  21110. * ```
  21111. */
  21112. UE.plugins['customstyle'] = function() {
  21113. var me = this;
  21114. me.setOpt({ 'customstyle':[
  21115. {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;'},
  21116. {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;'},
  21117. {tag:'span',name:'im', style:'font-size:16px;font-style:italic;font-weight:bold;line-height:18px;'},
  21118. {tag:'span',name:'hi', style:'font-size:16px;font-style:italic;font-weight:bold;color:rgb(51, 153, 204);line-height:18px;'}
  21119. ]});
  21120. me.commands['customstyle'] = {
  21121. execCommand : function(cmdName, obj) {
  21122. var me = this,
  21123. tagName = obj.tag,
  21124. node = domUtils.findParent(me.selection.getStart(), function(node) {
  21125. return node.getAttribute('label');
  21126. }, true),
  21127. range,bk,tmpObj = {};
  21128. for (var p in obj) {
  21129. if(obj[p]!==undefined)
  21130. tmpObj[p] = obj[p];
  21131. }
  21132. delete tmpObj.tag;
  21133. if (node && node.getAttribute('label') == obj.label) {
  21134. range = this.selection.getRange();
  21135. bk = range.createBookmark();
  21136. if (range.collapsed) {
  21137. //trace:1732 删掉自定义标签,要有p来回填站位
  21138. if(dtd.$block[node.tagName]){
  21139. var fillNode = me.document.createElement('p');
  21140. domUtils.moveChild(node, fillNode);
  21141. node.parentNode.insertBefore(fillNode, node);
  21142. domUtils.remove(node);
  21143. }else{
  21144. domUtils.remove(node,true);
  21145. }
  21146. } else {
  21147. var common = domUtils.getCommonAncestor(bk.start, bk.end),
  21148. nodes = domUtils.getElementsByTagName(common, tagName);
  21149. if(new RegExp(tagName,'i').test(common.tagName)){
  21150. nodes.push(common);
  21151. }
  21152. for (var i = 0,ni; ni = nodes[i++];) {
  21153. if (ni.getAttribute('label') == obj.label) {
  21154. var ps = domUtils.getPosition(ni, bk.start),pe = domUtils.getPosition(ni, bk.end);
  21155. if ((ps & domUtils.POSITION_FOLLOWING || ps & domUtils.POSITION_CONTAINS)
  21156. &&
  21157. (pe & domUtils.POSITION_PRECEDING || pe & domUtils.POSITION_CONTAINS)
  21158. )
  21159. if (dtd.$block[tagName]) {
  21160. var fillNode = me.document.createElement('p');
  21161. domUtils.moveChild(ni, fillNode);
  21162. ni.parentNode.insertBefore(fillNode, ni);
  21163. }
  21164. domUtils.remove(ni, true);
  21165. }
  21166. }
  21167. node = domUtils.findParent(common, function(node) {
  21168. return node.getAttribute('label') == obj.label;
  21169. }, true);
  21170. if (node) {
  21171. domUtils.remove(node, true);
  21172. }
  21173. }
  21174. range.moveToBookmark(bk).select();
  21175. } else {
  21176. if (dtd.$block[tagName]) {
  21177. this.execCommand('paragraph', tagName, tmpObj,'customstyle');
  21178. range = me.selection.getRange();
  21179. if (!range.collapsed) {
  21180. range.collapse();
  21181. node = domUtils.findParent(me.selection.getStart(), function(node) {
  21182. return node.getAttribute('label') == obj.label;
  21183. }, true);
  21184. var pNode = me.document.createElement('p');
  21185. domUtils.insertAfter(node, pNode);
  21186. domUtils.fillNode(me.document, pNode);
  21187. range.setStart(pNode, 0).setCursor();
  21188. }
  21189. } else {
  21190. range = me.selection.getRange();
  21191. if (range.collapsed) {
  21192. node = me.document.createElement(tagName);
  21193. domUtils.setAttributes(node, tmpObj);
  21194. range.insertNode(node).setStart(node, 0).setCursor();
  21195. return;
  21196. }
  21197. bk = range.createBookmark();
  21198. range.applyInlineStyle(tagName, tmpObj).moveToBookmark(bk).select();
  21199. }
  21200. }
  21201. },
  21202. queryCommandValue : function() {
  21203. var parent = domUtils.filterNodeList(
  21204. this.selection.getStartElementPath(),
  21205. function(node){return node.getAttribute('label')}
  21206. );
  21207. return parent ? parent.getAttribute('label') : '';
  21208. }
  21209. };
  21210. //当去掉customstyle是,如果是块元素,用p代替
  21211. me.addListener('keyup', function(type, evt) {
  21212. var keyCode = evt.keyCode || evt.which;
  21213. if (keyCode == 32 || keyCode == 13) {
  21214. var range = me.selection.getRange();
  21215. if (range.collapsed) {
  21216. var node = domUtils.findParent(me.selection.getStart(), function(node) {
  21217. return node.getAttribute('label');
  21218. }, true);
  21219. if (node && dtd.$block[node.tagName] && domUtils.isEmptyNode(node)) {
  21220. var p = me.document.createElement('p');
  21221. domUtils.insertAfter(node, p);
  21222. domUtils.fillNode(me.document, p);
  21223. domUtils.remove(node);
  21224. range.setStart(p, 0).setCursor();
  21225. }
  21226. }
  21227. }
  21228. });
  21229. };
  21230. // plugins/catchremoteimage.js
  21231. ///import core
  21232. ///commands 远程图片抓取
  21233. ///commandsName catchRemoteImage,catchremoteimageenable
  21234. ///commandsTitle 远程图片抓取
  21235. /**
  21236. * 远程图片抓取,当开启本插件时所有不符合本地域名的图片都将被抓取成为本地服务器上的图片
  21237. */
  21238. UE.plugins['catchremoteimage'] = function () {
  21239. var me = this,
  21240. ajax = UE.ajax;
  21241. /* 设置默认值 */
  21242. if (me.options.catchRemoteImageEnable === undefined) return;
  21243. me.setOpt({
  21244. catchRemoteImageEnable: false
  21245. });
  21246. me.addListener("afterpaste", function () {
  21247. me.fireEvent("catchRemoteImage");
  21248. });
  21249. me.addListener("catchRemoteImage", function () {
  21250. var catcherLocalDomain = me.getOpt('catcherLocalDomain'),
  21251. catcherActionUrl = me.getActionUrl(me.getOpt('catcherActionName')),
  21252. catcherUrlPrefix = me.getOpt('catcherUrlPrefix'),
  21253. catcherFieldName = me.getOpt('catcherFieldName');
  21254. var remoteImages = [],
  21255. imgs = domUtils.getElementsByTagName(me.document, "img"),
  21256. test = function (src, urls) {
  21257. if (src.indexOf(location.host) != -1 || /(^\.)|(^\/)/.test(src)) {
  21258. return true;
  21259. }
  21260. if (urls) {
  21261. for (var j = 0, url; url = urls[j++];) {
  21262. if (src.indexOf(url) !== -1) {
  21263. return true;
  21264. }
  21265. }
  21266. }
  21267. return false;
  21268. };
  21269. for (var i = 0, ci; ci = imgs[i++];) {
  21270. if (ci.getAttribute("word_img")) {
  21271. continue;
  21272. }
  21273. var src = ci.getAttribute("_src") || ci.src || "";
  21274. if (/^(https?|ftp):/i.test(src) && !test(src, catcherLocalDomain)) {
  21275. remoteImages.push(src);
  21276. }
  21277. }
  21278. if (remoteImages.length) {
  21279. catchremoteimage(remoteImages, {
  21280. //成功抓取
  21281. success: function (r) {
  21282. try {
  21283. var info = r.state !== undefined ? r:eval("(" + r.responseText + ")");
  21284. } catch (e) {
  21285. return;
  21286. }
  21287. /* 获取源路径和新路径 */
  21288. var i, j, ci, cj, oldSrc, newSrc, list = info.list;
  21289. for (i = 0; ci = imgs[i++];) {
  21290. oldSrc = ci.getAttribute("_src") || ci.src || "";
  21291. for (j = 0; cj = list[j++];) {
  21292. if (oldSrc == cj.source && cj.state == "SUCCESS") { //抓取失败时不做替换处理
  21293. newSrc = catcherUrlPrefix + cj.url;
  21294. domUtils.setAttributes(ci, {
  21295. "src": newSrc,
  21296. "_src": newSrc
  21297. });
  21298. break;
  21299. }
  21300. }
  21301. }
  21302. me.fireEvent('catchremotesuccess')
  21303. },
  21304. //回调失败,本次请求超时
  21305. error: function () {
  21306. me.fireEvent("catchremoteerror");
  21307. }
  21308. });
  21309. }
  21310. function catchremoteimage(imgs, callbacks) {
  21311. var params = utils.serializeParam(me.queryCommandValue('serverparam')) || '',
  21312. url = utils.formatUrl(catcherActionUrl + (catcherActionUrl.indexOf('?') == -1 ? '?':'&') + params),
  21313. isJsonp = utils.isCrossDomainUrl(url),
  21314. opt = {
  21315. 'method': 'POST',
  21316. 'dataType': isJsonp ? 'jsonp':'',
  21317. 'timeout': 60000, //单位:毫秒,回调请求超时设置。目标用户如果网速不是很快的话此处建议设置一个较大的数值
  21318. 'onsuccess': callbacks["success"],
  21319. 'onerror': callbacks["error"]
  21320. };
  21321. opt[catcherFieldName] = imgs;
  21322. ajax.request(url, opt);
  21323. }
  21324. });
  21325. };
  21326. // plugins/snapscreen.js
  21327. /**
  21328. * 截屏插件,为UEditor提供插入支持
  21329. * @file
  21330. * @since 1.4.2
  21331. */
  21332. UE.plugin.register('snapscreen', function (){
  21333. var me = this;
  21334. var snapplugin;
  21335. function getLocation(url){
  21336. var search,
  21337. a = document.createElement('a'),
  21338. params = utils.serializeParam(me.queryCommandValue('serverparam')) || '';
  21339. a.href = url;
  21340. if (browser.ie) {
  21341. a.href = a.href;
  21342. }
  21343. search = a.search;
  21344. if (params) {
  21345. search = search + (search.indexOf('?') == -1 ? '?':'&')+ params;
  21346. search = search.replace(/[&]+/ig, '&');
  21347. }
  21348. return {
  21349. 'port': a.port,
  21350. 'hostname': a.hostname,
  21351. 'path': a.pathname + search || + a.hash
  21352. }
  21353. }
  21354. return {
  21355. commands:{
  21356. /**
  21357. * 字体背景颜色
  21358. * @command snapscreen
  21359. * @method execCommand
  21360. * @param { String } cmd 命令字符串
  21361. * @example
  21362. * ```javascript
  21363. * editor.execCommand('snapscreen');
  21364. * ```
  21365. */
  21366. 'snapscreen':{
  21367. execCommand:function (cmd) {
  21368. var url, local, res;
  21369. var lang = me.getLang("snapScreen_plugin");
  21370. if(!snapplugin){
  21371. var container = me.container;
  21372. var doc = me.container.ownerDocument || me.container.document;
  21373. snapplugin = doc.createElement("object");
  21374. try{snapplugin.type = "application/x-pluginbaidusnap";}catch(e){
  21375. return;
  21376. }
  21377. snapplugin.style.cssText = "position:absolute;left:-9999px;width:0;height:0;";
  21378. snapplugin.setAttribute("width","0");
  21379. snapplugin.setAttribute("height","0");
  21380. container.appendChild(snapplugin);
  21381. }
  21382. function onSuccess(rs){
  21383. try{
  21384. rs = eval("("+ rs +")");
  21385. if(rs.state == 'SUCCESS'){
  21386. var opt = me.options;
  21387. me.execCommand('insertimage', {
  21388. src: opt.snapscreenUrlPrefix + rs.url,
  21389. _src: opt.snapscreenUrlPrefix + rs.url,
  21390. alt: rs.title || '',
  21391. floatStyle: opt.snapscreenImgAlign
  21392. });
  21393. } else {
  21394. alert(rs.state);
  21395. }
  21396. }catch(e){
  21397. alert(lang.callBackErrorMsg);
  21398. }
  21399. }
  21400. url = me.getActionUrl(me.getOpt('snapscreenActionName'));
  21401. local = getLocation(url);
  21402. setTimeout(function () {
  21403. try{
  21404. res =snapplugin.saveSnapshot(local.hostname, local.path, local.port);
  21405. }catch(e){
  21406. me.ui._dialogs['snapscreenDialog'].open();
  21407. return;
  21408. }
  21409. onSuccess(res);
  21410. }, 50);
  21411. },
  21412. queryCommandState: function(){
  21413. return (navigator.userAgent.indexOf("Windows",0) != -1) ? 0:-1;
  21414. }
  21415. }
  21416. }
  21417. }
  21418. });
  21419. // plugins/insertparagraph.js
  21420. /**
  21421. * 插入段落
  21422. * @file
  21423. * @since 1.2.6.1
  21424. */
  21425. /**
  21426. * 插入段落
  21427. * @command insertparagraph
  21428. * @method execCommand
  21429. * @param { String } cmd 命令字符串
  21430. * @example
  21431. * ```javascript
  21432. * //editor是编辑器实例
  21433. * editor.execCommand( 'insertparagraph' );
  21434. * ```
  21435. */
  21436. UE.commands['insertparagraph'] = {
  21437. execCommand : function( cmdName,front) {
  21438. var me = this,
  21439. range = me.selection.getRange(),
  21440. start = range.startContainer,tmpNode;
  21441. while(start ){
  21442. if(domUtils.isBody(start)){
  21443. break;
  21444. }
  21445. tmpNode = start;
  21446. start = start.parentNode;
  21447. }
  21448. if(tmpNode){
  21449. var p = me.document.createElement('p');
  21450. if(front){
  21451. tmpNode.parentNode.insertBefore(p,tmpNode)
  21452. }else{
  21453. tmpNode.parentNode.insertBefore(p,tmpNode.nextSibling)
  21454. }
  21455. domUtils.fillNode(me.document,p);
  21456. range.setStart(p,0).setCursor(false,true);
  21457. }
  21458. }
  21459. };
  21460. // plugins/webapp.js
  21461. /**
  21462. * 百度应用
  21463. * @file
  21464. * @since 1.2.6.1
  21465. */
  21466. /**
  21467. * 插入百度应用
  21468. * @command webapp
  21469. * @method execCommand
  21470. * @remind 需要百度APPKey
  21471. * @remind 百度应用主页: <a href="http://app.baidu.com/" target="_blank">http://app.baidu.com/</a>
  21472. * @param { Object } appOptions 应用所需的参数项, 支持的key有: title=>应用标题, width=>应用容器宽度,
  21473. * height=>应用容器高度,logo=>应用logo,url=>应用地址
  21474. * @example
  21475. * ```javascript
  21476. * //editor是编辑器实例
  21477. * //在编辑器里插入一个“植物大战僵尸”的APP
  21478. * editor.execCommand( 'webapp' , {
  21479. * title: '植物大战僵尸',
  21480. * width: 560,
  21481. * height: 465,
  21482. * logo: '应用展示的图片',
  21483. * url: '百度应用的地址'
  21484. * } );
  21485. * ```
  21486. */
  21487. //UE.plugins['webapp'] = function () {
  21488. // var me = this;
  21489. // function createInsertStr( obj, toIframe, addParagraph ) {
  21490. // return !toIframe ?
  21491. // (addParagraph ? '<p>' : '') + '<img title="'+obj.title+'" width="' + obj.width + '" height="' + obj.height + '"' +
  21492. // ' 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 + '" />' +
  21493. // (addParagraph ? '</p>' : '')
  21494. // :
  21495. // '<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>';
  21496. // }
  21497. //
  21498. // function switchImgAndIframe( img2frame ) {
  21499. // var tmpdiv,
  21500. // nodes = domUtils.getElementsByTagName( me.document, !img2frame ? "iframe" : "img" );
  21501. // for ( var i = 0, node; node = nodes[i++]; ) {
  21502. // if ( node.className != "edui-faked-webapp" ){
  21503. // continue;
  21504. // }
  21505. // tmpdiv = me.document.createElement( "div" );
  21506. // 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 );
  21507. // node.parentNode.replaceChild( tmpdiv.firstChild, node );
  21508. // }
  21509. // }
  21510. //
  21511. // me.addListener( "beforegetcontent", function () {
  21512. // switchImgAndIframe( true );
  21513. // } );
  21514. // me.addListener( 'aftersetcontent', function () {
  21515. // switchImgAndIframe( false );
  21516. // } );
  21517. // me.addListener( 'aftergetcontent', function ( cmdName ) {
  21518. // if ( cmdName == 'aftergetcontent' && me.queryCommandState( 'source' ) ){
  21519. // return;
  21520. // }
  21521. // switchImgAndIframe( false );
  21522. // } );
  21523. //
  21524. // me.commands['webapp'] = {
  21525. // execCommand:function ( cmd, obj ) {
  21526. // me.execCommand( "inserthtml", createInsertStr( obj, false,true ) );
  21527. // }
  21528. // };
  21529. //};
  21530. UE.plugin.register('webapp', function (){
  21531. var me = this;
  21532. function createInsertStr(obj,toEmbed){
  21533. return !toEmbed ?
  21534. '<img title="'+obj.title+'" width="' + obj.width + '" height="' + obj.height + '"' +
  21535. ' src="' + me.options.UEDITOR_HOME_URL + 'themes/default/images/spacer.gif" _logo_url="'+obj.logo+'" style="background:url(' + obj.logo
  21536. +') no-repeat center center; border:1px solid gray;" class="edui-faked-webapp" _url="' + obj.url + '" ' +
  21537. (obj.align && !obj.cssfloat? 'align="' + obj.align + '"' : '') +
  21538. (obj.cssfloat ? 'style="float:' + obj.cssfloat + '"' : '') +
  21539. '/>'
  21540. :
  21541. '<iframe class="edui-faked-webapp" title="'+obj.title+'" ' +
  21542. (obj.align && !obj.cssfloat? 'align="' + obj.align + '"' : '') +
  21543. (obj.cssfloat ? 'style="float:' + obj.cssfloat + '"' : '') +
  21544. 'width="' + obj.width + '" height="' + obj.height + '" scrolling="no" frameborder="0" src="' + obj.url + '" logo_url = "'+obj.logo+'"></iframe>'
  21545. }
  21546. return {
  21547. outputRule: function(root){
  21548. utils.each(root.getNodesByTagName('img'),function(node){
  21549. var html;
  21550. if(node.getAttr('class') == 'edui-faked-webapp'){
  21551. html = createInsertStr({
  21552. title:node.getAttr('title'),
  21553. 'width':node.getAttr('width'),
  21554. 'height':node.getAttr('height'),
  21555. 'align':node.getAttr('align'),
  21556. 'cssfloat':node.getStyle('float'),
  21557. 'url':node.getAttr("_url"),
  21558. 'logo':node.getAttr('_logo_url')
  21559. },true);
  21560. var embed = UE.uNode.createElement(html);
  21561. node.parentNode.replaceChild(embed,node);
  21562. }
  21563. })
  21564. },
  21565. inputRule:function(root){
  21566. utils.each(root.getNodesByTagName('iframe'),function(node){
  21567. if(node.getAttr('class') == 'edui-faked-webapp'){
  21568. var img = UE.uNode.createElement(createInsertStr({
  21569. title:node.getAttr('title'),
  21570. 'width':node.getAttr('width'),
  21571. 'height':node.getAttr('height'),
  21572. 'align':node.getAttr('align'),
  21573. 'cssfloat':node.getStyle('float'),
  21574. 'url':node.getAttr("src"),
  21575. 'logo':node.getAttr('logo_url')
  21576. }));
  21577. node.parentNode.replaceChild(img,node);
  21578. }
  21579. })
  21580. },
  21581. commands:{
  21582. /**
  21583. * 插入百度应用
  21584. * @command webapp
  21585. * @method execCommand
  21586. * @remind 需要百度APPKey
  21587. * @remind 百度应用主页: <a href="http://app.baidu.com/" target="_blank">http://app.baidu.com/</a>
  21588. * @param { Object } appOptions 应用所需的参数项, 支持的key有: title=>应用标题, width=>应用容器宽度,
  21589. * height=>应用容器高度,logo=>应用logo,url=>应用地址
  21590. * @example
  21591. * ```javascript
  21592. * //editor是编辑器实例
  21593. * //在编辑器里插入一个“植物大战僵尸”的APP
  21594. * editor.execCommand( 'webapp' , {
  21595. * title: '植物大战僵尸',
  21596. * width: 560,
  21597. * height: 465,
  21598. * logo: '应用展示的图片',
  21599. * url: '百度应用的地址'
  21600. * } );
  21601. * ```
  21602. */
  21603. 'webapp':{
  21604. execCommand:function (cmd, obj) {
  21605. var me = this,
  21606. str = createInsertStr(utils.extend(obj,{
  21607. align:'none'
  21608. }), false);
  21609. me.execCommand("inserthtml",str);
  21610. },
  21611. queryCommandState:function () {
  21612. var me = this,
  21613. img = me.selection.getRange().getClosedNode(),
  21614. flag = img && (img.className == "edui-faked-webapp");
  21615. return flag ? 1 : 0;
  21616. }
  21617. }
  21618. }
  21619. }
  21620. });
  21621. // plugins/template.js
  21622. ///import core
  21623. ///import plugins\inserthtml.js
  21624. ///import plugins\cleardoc.js
  21625. ///commands 模板
  21626. ///commandsName template
  21627. ///commandsTitle 模板
  21628. ///commandsDialog dialogs\template
  21629. UE.plugins['template'] = function () {
  21630. UE.commands['template'] = {
  21631. execCommand:function (cmd, obj) {
  21632. obj.html && this.execCommand("inserthtml", obj.html);
  21633. }
  21634. };
  21635. this.addListener("click", function (type, evt) {
  21636. var el = evt.target || evt.srcElement,
  21637. range = this.selection.getRange();
  21638. var tnode = domUtils.findParent(el, function (node) {
  21639. if (node.className && domUtils.hasClass(node, "ue_t")) {
  21640. return node;
  21641. }
  21642. }, true);
  21643. tnode && range.selectNode(tnode).shrinkBoundary().select();
  21644. });
  21645. this.addListener("keydown", function (type, evt) {
  21646. var range = this.selection.getRange();
  21647. if (!range.collapsed) {
  21648. if (!evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey) {
  21649. var tnode = domUtils.findParent(range.startContainer, function (node) {
  21650. if (node.className && domUtils.hasClass(node, "ue_t")) {
  21651. return node;
  21652. }
  21653. }, true);
  21654. if (tnode) {
  21655. domUtils.removeClasses(tnode, ["ue_t"]);
  21656. }
  21657. }
  21658. }
  21659. });
  21660. };
  21661. // plugins/music.js
  21662. /**
  21663. * 插入音乐命令
  21664. * @file
  21665. */
  21666. UE.plugin.register('music', function (){
  21667. var me = this;
  21668. function creatInsertStr(url,width,height,align,cssfloat,toEmbed){
  21669. return !toEmbed ?
  21670. '<img ' +
  21671. (align && !cssfloat? 'align="' + align + '"' : '') +
  21672. (cssfloat ? 'style="float:' + cssfloat + '"' : '') +
  21673. ' width="'+ width +'" height="' + height + '" _url="'+url+'" class="edui-faked-music"' +
  21674. ' src="'+me.options.langPath+me.options.lang+'/images/music.png" />'
  21675. :
  21676. '<embed type="application/x-shockwave-flash" class="edui-faked-music" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
  21677. ' src="' + url + '" width="' + width + '" height="' + height + '" '+ (align && !cssfloat? 'align="' + align + '"' : '') +
  21678. (cssfloat ? 'style="float:' + cssfloat + '"' : '') +
  21679. ' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >';
  21680. }
  21681. return {
  21682. outputRule: function(root){
  21683. utils.each(root.getNodesByTagName('img'),function(node){
  21684. var html;
  21685. if(node.getAttr('class') == 'edui-faked-music'){
  21686. var cssfloat = node.getStyle('float');
  21687. var align = node.getAttr('align');
  21688. html = creatInsertStr(node.getAttr("_url"), node.getAttr('width'), node.getAttr('height'), align, cssfloat, true);
  21689. var embed = UE.uNode.createElement(html);
  21690. node.parentNode.replaceChild(embed,node);
  21691. }
  21692. })
  21693. },
  21694. inputRule:function(root){
  21695. utils.each(root.getNodesByTagName('embed'),function(node){
  21696. if(node.getAttr('class') == 'edui-faked-music'){
  21697. var cssfloat = node.getStyle('float');
  21698. var align = node.getAttr('align');
  21699. html = creatInsertStr(node.getAttr("src"), node.getAttr('width'), node.getAttr('height'), align, cssfloat,false);
  21700. var img = UE.uNode.createElement(html);
  21701. node.parentNode.replaceChild(img,node);
  21702. }
  21703. })
  21704. },
  21705. commands:{
  21706. /**
  21707. * 插入音乐
  21708. * @command music
  21709. * @method execCommand
  21710. * @param { Object } musicOptions 插入音乐的参数项, 支持的key有: url=>音乐地址;
  21711. * width=>音乐容器宽度;height=>音乐容器高度;align=>音乐文件的对齐方式, 可选值有: left, center, right, none
  21712. * @example
  21713. * ```javascript
  21714. * //editor是编辑器实例
  21715. * //在编辑器里插入一个“植物大战僵尸”的APP
  21716. * editor.execCommand( 'music' , {
  21717. * width: 400,
  21718. * height: 95,
  21719. * align: "center",
  21720. * url: "音乐地址"
  21721. * } );
  21722. * ```
  21723. */
  21724. 'music':{
  21725. execCommand:function (cmd, musicObj) {
  21726. var me = this,
  21727. str = creatInsertStr(musicObj.url, musicObj.width || 400, musicObj.height || 95, "none", false);
  21728. me.execCommand("inserthtml",str);
  21729. },
  21730. queryCommandState:function () {
  21731. var me = this,
  21732. img = me.selection.getRange().getClosedNode(),
  21733. flag = img && (img.className == "edui-faked-music");
  21734. return flag ? 1 : 0;
  21735. }
  21736. }
  21737. }
  21738. }
  21739. });
  21740. // plugins/autoupload.js
  21741. /**
  21742. * @description
  21743. * 1.拖放文件到编辑区域,自动上传并插入到选区
  21744. * 2.插入粘贴板的图片,自动上传并插入到选区
  21745. * @author Jinqn
  21746. * @date 2013-10-14
  21747. */
  21748. UE.plugin.register('autoupload', function (){
  21749. function sendAndInsertFile(file, editor) {
  21750. var me = editor;
  21751. //模拟数据
  21752. var fieldName, urlPrefix, maxSize, allowFiles, actionUrl,
  21753. loadingHtml, errorHandler, successHandler,
  21754. filetype = /image\/\w+/i.test(file.type) ? 'image':'file',
  21755. loadingId = 'loading_' + (+new Date()).toString(36);
  21756. fieldName = me.getOpt(filetype + 'FieldName');
  21757. urlPrefix = me.getOpt(filetype + 'UrlPrefix');
  21758. maxSize = me.getOpt(filetype + 'MaxSize');
  21759. allowFiles = me.getOpt(filetype + 'AllowFiles');
  21760. actionUrl = me.getActionUrl(me.getOpt(filetype + 'ActionName'));
  21761. errorHandler = function(title) {
  21762. var loader = me.document.getElementById(loadingId);
  21763. loader && domUtils.remove(loader);
  21764. me.fireEvent('showmessage', {
  21765. 'id': loadingId,
  21766. 'content': title,
  21767. 'type': 'error',
  21768. 'timeout': 4000
  21769. });
  21770. };
  21771. if (filetype == 'image') {
  21772. loadingHtml = '<img class="loadingclass" id="' + loadingId + '" src="' +
  21773. me.options.themePath + me.options.theme +
  21774. '/images/spacer.gif" title="' + (me.getLang('autoupload.loading') || '') + '" >';
  21775. successHandler = function(data) {
  21776. var link = urlPrefix + data.url,
  21777. loader = me.document.getElementById(loadingId);
  21778. if (loader) {
  21779. loader.setAttribute('src', link);
  21780. loader.setAttribute('_src', link);
  21781. loader.setAttribute('title', data.title || '');
  21782. loader.setAttribute('alt', data.original || '');
  21783. loader.removeAttribute('id');
  21784. domUtils.removeClasses(loader, 'loadingclass');
  21785. }
  21786. };
  21787. } else {
  21788. loadingHtml = '<p>' +
  21789. '<img class="loadingclass" id="' + loadingId + '" src="' +
  21790. me.options.themePath + me.options.theme +
  21791. '/images/spacer.gif" title="' + (me.getLang('autoupload.loading') || '') + '" >' +
  21792. '</p>';
  21793. successHandler = function(data) {
  21794. var link = urlPrefix + data.url,
  21795. loader = me.document.getElementById(loadingId);
  21796. var rng = me.selection.getRange(),
  21797. bk = rng.createBookmark();
  21798. rng.selectNode(loader).select();
  21799. me.execCommand('insertfile', {'url': link});
  21800. rng.moveToBookmark(bk).select();
  21801. };
  21802. }
  21803. /* 插入loading的占位符 */
  21804. me.execCommand('inserthtml', loadingHtml);
  21805. /* 判断后端配置是否没有加载成功 */
  21806. if (!me.getOpt(filetype + 'ActionName')) {
  21807. errorHandler(me.getLang('autoupload.errorLoadConfig'));
  21808. return;
  21809. }
  21810. /* 判断文件大小是否超出限制 */
  21811. if(file.size > maxSize) {
  21812. errorHandler(me.getLang('autoupload.exceedSizeError'));
  21813. return;
  21814. }
  21815. /* 判断文件格式是否超出允许 */
  21816. var fileext = file.name ? file.name.substr(file.name.lastIndexOf('.')):'';
  21817. if ((fileext && filetype != 'image') || (allowFiles && (allowFiles.join('') + '.').indexOf(fileext.toLowerCase() + '.') == -1)) {
  21818. errorHandler(me.getLang('autoupload.exceedTypeError'));
  21819. return;
  21820. }
  21821. /* 创建Ajax并提交 */
  21822. var xhr = new XMLHttpRequest(),
  21823. fd = new FormData(),
  21824. params = utils.serializeParam(me.queryCommandValue('serverparam')) || '',
  21825. url = utils.formatUrl(actionUrl + (actionUrl.indexOf('?') == -1 ? '?':'&') + params);
  21826. fd.append(fieldName, file, file.name || ('blob.' + file.type.substr('image/'.length)));
  21827. fd.append('type', 'ajax');
  21828. xhr.open("post", url, true);
  21829. xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
  21830. xhr.addEventListener('load', function (e) {
  21831. try{
  21832. var json = (new Function("return " + utils.trim(e.target.response)))();
  21833. if (json.state == 'SUCCESS' && json.url) {
  21834. successHandler(json);
  21835. } else {
  21836. errorHandler(json.state);
  21837. }
  21838. }catch(er){
  21839. errorHandler(me.getLang('autoupload.loadError'));
  21840. }
  21841. });
  21842. xhr.send(fd);
  21843. }
  21844. function getPasteImage(e){
  21845. return e.clipboardData && e.clipboardData.items && e.clipboardData.items.length == 1 && /^image\//.test(e.clipboardData.items[0].type) ? e.clipboardData.items:null;
  21846. }
  21847. function getDropImage(e){
  21848. return e.dataTransfer && e.dataTransfer.files ? e.dataTransfer.files:null;
  21849. }
  21850. return {
  21851. outputRule: function(root){
  21852. utils.each(root.getNodesByTagName('img'),function(n){
  21853. if (/\b(loaderrorclass)|(bloaderrorclass)\b/.test(n.getAttr('class'))) {
  21854. n.parentNode.removeChild(n);
  21855. }
  21856. });
  21857. utils.each(root.getNodesByTagName('p'),function(n){
  21858. if (/\bloadpara\b/.test(n.getAttr('class'))) {
  21859. n.parentNode.removeChild(n);
  21860. }
  21861. });
  21862. },
  21863. bindEvents:{
  21864. //插入粘贴板的图片,拖放插入图片
  21865. 'ready':function(e){
  21866. var me = this;
  21867. if(window.FormData && window.FileReader) {
  21868. domUtils.on(me.body, 'paste drop', function(e){
  21869. var hasImg = false,
  21870. items;
  21871. //获取粘贴板文件列表或者拖放文件列表
  21872. items = e.type == 'paste' ? getPasteImage(e):getDropImage(e);
  21873. if(items){
  21874. var len = items.length,
  21875. file;
  21876. while (len--){
  21877. file = items[len];
  21878. if(file.getAsFile) file = file.getAsFile();
  21879. if(file && file.size > 0) {
  21880. sendAndInsertFile(file, me);
  21881. hasImg = true;
  21882. }
  21883. }
  21884. hasImg && e.preventDefault();
  21885. }
  21886. });
  21887. //取消拖放图片时出现的文字光标位置提示
  21888. domUtils.on(me.body, 'dragover', function (e) {
  21889. if(e.dataTransfer.types[0] == 'Files') {
  21890. e.preventDefault();
  21891. }
  21892. });
  21893. //设置loading的样式
  21894. utils.cssRule('loading',
  21895. '.loadingclass{display:inline-block;cursor:default;background: url(\''
  21896. + this.options.themePath
  21897. + this.options.theme +'/images/loading.gif\') no-repeat center center transparent;border:1px solid #cccccc;margin-left:1px;height: 22px;width: 22px;}\n' +
  21898. '.loaderrorclass{display:inline-block;cursor:default;background: url(\''
  21899. + this.options.themePath
  21900. + this.options.theme +'/images/loaderror.png\') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;' +
  21901. '}',
  21902. this.document);
  21903. }
  21904. }
  21905. }
  21906. }
  21907. });
  21908. // plugins/autosave.js
  21909. UE.plugin.register('autosave', function (){
  21910. var me = this,
  21911. //无限循环保护
  21912. lastSaveTime = new Date(),
  21913. //最小保存间隔时间
  21914. MIN_TIME = 20,
  21915. //auto save key
  21916. saveKey = null;
  21917. function save ( editor ) {
  21918. var saveData;
  21919. if ( new Date() - lastSaveTime < MIN_TIME ) {
  21920. return;
  21921. }
  21922. if ( !editor.hasContents() ) {
  21923. //这里不能调用命令来删除, 会造成事件死循环
  21924. saveKey && me.removePreferences( saveKey );
  21925. return;
  21926. }
  21927. lastSaveTime = new Date();
  21928. editor._saveFlag = null;
  21929. saveData = me.body.innerHTML;
  21930. if ( editor.fireEvent( "beforeautosave", {
  21931. content: saveData
  21932. } ) === false ) {
  21933. return;
  21934. }
  21935. me.setPreferences( saveKey, saveData );
  21936. editor.fireEvent( "afterautosave", {
  21937. content: saveData
  21938. } );
  21939. }
  21940. return {
  21941. defaultOptions: {
  21942. //默认间隔时间
  21943. saveInterval: 500
  21944. },
  21945. bindEvents:{
  21946. 'ready':function(){
  21947. var _suffix = "-drafts-data",
  21948. key = null;
  21949. if ( me.key ) {
  21950. key = me.key + _suffix;
  21951. } else {
  21952. key = ( me.container.parentNode.id || 'ue-common' ) + _suffix;
  21953. }
  21954. //页面地址+编辑器ID 保持唯一
  21955. saveKey = ( location.protocol + location.host + location.pathname ).replace( /[.:\/]/g, '_' ) + key;
  21956. },
  21957. 'contentchange': function () {
  21958. if ( !saveKey ) {
  21959. return;
  21960. }
  21961. if ( me._saveFlag ) {
  21962. window.clearTimeout( me._saveFlag );
  21963. }
  21964. if ( me.options.saveInterval > 0 ) {
  21965. me._saveFlag = window.setTimeout( function () {
  21966. save( me );
  21967. }, me.options.saveInterval );
  21968. } else {
  21969. save(me);
  21970. }
  21971. }
  21972. },
  21973. commands:{
  21974. 'clearlocaldata':{
  21975. execCommand:function (cmd, name) {
  21976. if ( saveKey && me.getPreferences( saveKey ) ) {
  21977. me.removePreferences( saveKey )
  21978. }
  21979. },
  21980. notNeedUndo: true,
  21981. ignoreContentChange:true
  21982. },
  21983. 'getlocaldata':{
  21984. execCommand:function (cmd, name) {
  21985. return saveKey ? me.getPreferences( saveKey ) || '' : '';
  21986. },
  21987. notNeedUndo: true,
  21988. ignoreContentChange:true
  21989. },
  21990. 'drafts':{
  21991. execCommand:function (cmd, name) {
  21992. if ( saveKey ) {
  21993. me.body.innerHTML = me.getPreferences( saveKey ) || '<p>'+domUtils.fillHtml+'</p>';
  21994. me.focus(true);
  21995. }
  21996. },
  21997. queryCommandState: function () {
  21998. return saveKey ? ( me.getPreferences( saveKey ) === null ? -1 : 0 ) : -1;
  21999. },
  22000. notNeedUndo: true,
  22001. ignoreContentChange:true
  22002. }
  22003. }
  22004. }
  22005. });
  22006. // plugins/charts.js
  22007. UE.plugin.register('charts', function (){
  22008. var me = this;
  22009. return {
  22010. bindEvents: {
  22011. 'chartserror': function () {
  22012. }
  22013. },
  22014. commands:{
  22015. 'charts': {
  22016. execCommand: function ( cmd, data ) {
  22017. var tableNode = domUtils.findParentByTagName(this.selection.getRange().startContainer, 'table', true),
  22018. flagText = [],
  22019. config = {};
  22020. if ( !tableNode ) {
  22021. return false;
  22022. }
  22023. if ( !validData( tableNode ) ) {
  22024. me.fireEvent( "chartserror" );
  22025. return false;
  22026. }
  22027. config.title = data.title || '';
  22028. config.subTitle = data.subTitle || '';
  22029. config.xTitle = data.xTitle || '';
  22030. config.yTitle = data.yTitle || '';
  22031. config.suffix = data.suffix || '';
  22032. config.tip = data.tip || '';
  22033. //数据对齐方式
  22034. config.dataFormat = data.tableDataFormat || '';
  22035. //图表类型
  22036. config.chartType = data.chartType || 0;
  22037. for ( var key in config ) {
  22038. if ( !config.hasOwnProperty( key ) ) {
  22039. continue;
  22040. }
  22041. flagText.push( key+":"+config[ key ] );
  22042. }
  22043. tableNode.setAttribute( "data-chart", flagText.join( ";" ) );
  22044. domUtils.addClass( tableNode, "edui-charts-table" );
  22045. },
  22046. queryCommandState: function ( cmd, name ) {
  22047. var tableNode = domUtils.findParentByTagName(this.selection.getRange().startContainer, 'table', true);
  22048. return tableNode && validData( tableNode ) ? 0 : -1;
  22049. }
  22050. }
  22051. },
  22052. inputRule:function(root){
  22053. utils.each(root.getNodesByTagName('table'),function( tableNode ){
  22054. if ( tableNode.getAttr("data-chart") !== undefined ) {
  22055. tableNode.setAttr("style");
  22056. }
  22057. })
  22058. },
  22059. outputRule:function(root){
  22060. utils.each(root.getNodesByTagName('table'),function( tableNode ){
  22061. if ( tableNode.getAttr("data-chart") !== undefined ) {
  22062. tableNode.setAttr("style", "display: none;");
  22063. }
  22064. })
  22065. }
  22066. }
  22067. function validData ( table ) {
  22068. var firstRows = null,
  22069. cellCount = 0;
  22070. //行数不够
  22071. if ( table.rows.length < 2 ) {
  22072. return false;
  22073. }
  22074. //列数不够
  22075. if ( table.rows[0].cells.length < 2 ) {
  22076. return false;
  22077. }
  22078. //第一行所有cell必须是th
  22079. firstRows = table.rows[ 0 ].cells;
  22080. cellCount = firstRows.length;
  22081. for ( var i = 0, cell; cell = firstRows[ i ]; i++ ) {
  22082. if ( cell.tagName.toLowerCase() !== 'th' ) {
  22083. return false;
  22084. }
  22085. }
  22086. for ( var i = 1, row; row = table.rows[ i ]; i++ ) {
  22087. //每行单元格数不匹配, 返回false
  22088. if ( row.cells.length != cellCount ) {
  22089. return false;
  22090. }
  22091. //第一列不是th也返回false
  22092. if ( row.cells[0].tagName.toLowerCase() !== 'th' ) {
  22093. return false;
  22094. }
  22095. for ( var j = 1, cell; cell = row.cells[ j ]; j++ ) {
  22096. var value = utils.trim( ( cell.innerText || cell.textContent || '' ) );
  22097. value = value.replace( new RegExp( UE.dom.domUtils.fillChar, 'g' ), '' ).replace( /^\s+|\s+$/g, '' );
  22098. //必须是数字
  22099. if ( !/^\d*\.?\d+$/.test( value ) ) {
  22100. return false;
  22101. }
  22102. }
  22103. }
  22104. return true;
  22105. }
  22106. });
  22107. // plugins/section.js
  22108. /**
  22109. * 目录大纲支持插件
  22110. * @file
  22111. * @since 1.3.0
  22112. */
  22113. UE.plugin.register('section', function (){
  22114. /* 目录节点对象 */
  22115. function Section(option){
  22116. this.tag = '';
  22117. this.level = -1,
  22118. this.dom = null;
  22119. this.nextSection = null;
  22120. this.previousSection = null;
  22121. this.parentSection = null;
  22122. this.startAddress = [];
  22123. this.endAddress = [];
  22124. this.children = [];
  22125. }
  22126. function getSection(option) {
  22127. var section = new Section();
  22128. return utils.extend(section, option);
  22129. }
  22130. function getNodeFromAddress(startAddress, root) {
  22131. var current = root;
  22132. for(var i = 0;i < startAddress.length; i++) {
  22133. if(!current.childNodes) return null;
  22134. current = current.childNodes[startAddress[i]];
  22135. }
  22136. return current;
  22137. }
  22138. var me = this;
  22139. return {
  22140. bindMultiEvents:{
  22141. type: 'aftersetcontent afterscencerestore',
  22142. handler: function(){
  22143. me.fireEvent('updateSections');
  22144. }
  22145. },
  22146. bindEvents:{
  22147. /* 初始化、拖拽、粘贴、执行setcontent之后 */
  22148. 'ready': function (){
  22149. me.fireEvent('updateSections');
  22150. domUtils.on(me.body, 'drop paste', function(){
  22151. me.fireEvent('updateSections');
  22152. });
  22153. },
  22154. /* 执行paragraph命令之后 */
  22155. 'afterexeccommand': function (type, cmd) {
  22156. if(cmd == 'paragraph') {
  22157. me.fireEvent('updateSections');
  22158. }
  22159. },
  22160. /* 部分键盘操作,触发updateSections事件 */
  22161. 'keyup': function (type, e) {
  22162. var me = this,
  22163. range = me.selection.getRange();
  22164. if(range.collapsed != true) {
  22165. me.fireEvent('updateSections');
  22166. } else {
  22167. var keyCode = e.keyCode || e.which;
  22168. if(keyCode == 13 || keyCode == 8 || keyCode == 46) {
  22169. me.fireEvent('updateSections');
  22170. }
  22171. }
  22172. }
  22173. },
  22174. commands:{
  22175. 'getsections': {
  22176. execCommand: function (cmd, levels) {
  22177. var levelFn = levels || ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
  22178. for (var i = 0; i < levelFn.length; i++) {
  22179. if (typeof levelFn[i] == 'string') {
  22180. levelFn[i] = function(fn){
  22181. return function(node){
  22182. return node.tagName == fn.toUpperCase()
  22183. };
  22184. }(levelFn[i]);
  22185. } else if (typeof levelFn[i] != 'function') {
  22186. levelFn[i] = function (node) {
  22187. return null;
  22188. }
  22189. }
  22190. }
  22191. function getSectionLevel(node) {
  22192. for (var i = 0; i < levelFn.length; i++) {
  22193. if (levelFn[i](node)) return i;
  22194. }
  22195. return -1;
  22196. }
  22197. var me = this,
  22198. Directory = getSection({'level':-1, 'title':'root'}),
  22199. previous = Directory;
  22200. function traversal(node, Directory) {
  22201. var level,
  22202. tmpSection = null,
  22203. parent,
  22204. child,
  22205. children = node.childNodes;
  22206. for (var i = 0, len = children.length; i < len; i++) {
  22207. child = children[i];
  22208. level = getSectionLevel(child);
  22209. if (level >= 0) {
  22210. var address = me.selection.getRange().selectNode(child).createAddress(true).startAddress,
  22211. current = getSection({
  22212. 'tag': child.tagName,
  22213. 'title': child.innerText || child.textContent || '',
  22214. 'level': level,
  22215. 'dom': child,
  22216. 'startAddress': utils.clone(address, []),
  22217. 'endAddress': utils.clone(address, []),
  22218. 'children': []
  22219. });
  22220. previous.nextSection = current;
  22221. current.previousSection = previous;
  22222. parent = previous;
  22223. while(level <= parent.level){
  22224. parent = parent.parentSection;
  22225. }
  22226. current.parentSection = parent;
  22227. parent.children.push(current);
  22228. tmpSection = previous = current;
  22229. } else {
  22230. child.nodeType === 1 && traversal(child, Directory);
  22231. tmpSection && tmpSection.endAddress[tmpSection.endAddress.length - 1] ++;
  22232. }
  22233. }
  22234. }
  22235. traversal(me.body, Directory);
  22236. return Directory;
  22237. },
  22238. notNeedUndo: true
  22239. },
  22240. 'movesection': {
  22241. execCommand: function (cmd, sourceSection, targetSection, isAfter) {
  22242. var me = this,
  22243. targetAddress,
  22244. target;
  22245. if(!sourceSection || !targetSection || targetSection.level == -1) return;
  22246. targetAddress = isAfter ? targetSection.endAddress:targetSection.startAddress;
  22247. target = getNodeFromAddress(targetAddress, me.body);
  22248. /* 判断目标地址是否被源章节包含 */
  22249. if(!targetAddress || !target || isContainsAddress(sourceSection.startAddress, sourceSection.endAddress, targetAddress)) return;
  22250. var startNode = getNodeFromAddress(sourceSection.startAddress, me.body),
  22251. endNode = getNodeFromAddress(sourceSection.endAddress, me.body),
  22252. current,
  22253. nextNode;
  22254. if(isAfter) {
  22255. current = endNode;
  22256. while ( current && !(domUtils.getPosition( startNode, current ) & domUtils.POSITION_FOLLOWING) ) {
  22257. nextNode = current.previousSibling;
  22258. domUtils.insertAfter(target, current);
  22259. if(current == startNode) break;
  22260. current = nextNode;
  22261. }
  22262. } else {
  22263. current = startNode;
  22264. while ( current && !(domUtils.getPosition( current, endNode ) & domUtils.POSITION_FOLLOWING) ) {
  22265. nextNode = current.nextSibling;
  22266. target.parentNode.insertBefore(current, target);
  22267. if(current == endNode) break;
  22268. current = nextNode;
  22269. }
  22270. }
  22271. me.fireEvent('updateSections');
  22272. /* 获取地址的包含关系 */
  22273. function isContainsAddress(startAddress, endAddress, addressTarget){
  22274. var isAfterStartAddress = false,
  22275. isBeforeEndAddress = false;
  22276. for(var i = 0; i< startAddress.length; i++){
  22277. if(i >= addressTarget.length) break;
  22278. if(addressTarget[i] > startAddress[i]) {
  22279. isAfterStartAddress = true;
  22280. break;
  22281. } else if(addressTarget[i] < startAddress[i]) {
  22282. break;
  22283. }
  22284. }
  22285. for(var i = 0; i< endAddress.length; i++){
  22286. if(i >= addressTarget.length) break;
  22287. if(addressTarget[i] < startAddress[i]) {
  22288. isBeforeEndAddress = true;
  22289. break;
  22290. } else if(addressTarget[i] > startAddress[i]) {
  22291. break;
  22292. }
  22293. }
  22294. return isAfterStartAddress && isBeforeEndAddress;
  22295. }
  22296. }
  22297. },
  22298. 'deletesection': {
  22299. execCommand: function (cmd, section, keepChildren) {
  22300. var me = this;
  22301. if(!section) return;
  22302. function getNodeFromAddress(startAddress) {
  22303. var current = me.body;
  22304. for(var i = 0;i < startAddress.length; i++) {
  22305. if(!current.childNodes) return null;
  22306. current = current.childNodes[startAddress[i]];
  22307. }
  22308. return current;
  22309. }
  22310. var startNode = getNodeFromAddress(section.startAddress),
  22311. endNode = getNodeFromAddress(section.endAddress),
  22312. current = startNode,
  22313. nextNode;
  22314. if(!keepChildren) {
  22315. while ( current && domUtils.inDoc(endNode, me.document) && !(domUtils.getPosition( current, endNode ) & domUtils.POSITION_FOLLOWING) ) {
  22316. nextNode = current.nextSibling;
  22317. domUtils.remove(current);
  22318. current = nextNode;
  22319. }
  22320. } else {
  22321. domUtils.remove(current);
  22322. }
  22323. me.fireEvent('updateSections');
  22324. }
  22325. },
  22326. 'selectsection': {
  22327. execCommand: function (cmd, section) {
  22328. if(!section && !section.dom) return false;
  22329. var me = this,
  22330. range = me.selection.getRange(),
  22331. address = {
  22332. 'startAddress':utils.clone(section.startAddress, []),
  22333. 'endAddress':utils.clone(section.endAddress, [])
  22334. };
  22335. address.endAddress[address.endAddress.length - 1]++;
  22336. range.moveToAddress(address).select().scrollToView();
  22337. return true;
  22338. },
  22339. notNeedUndo: true
  22340. },
  22341. 'scrolltosection': {
  22342. execCommand: function (cmd, section) {
  22343. if(!section && !section.dom) return false;
  22344. var me = this,
  22345. range = me.selection.getRange(),
  22346. address = {
  22347. 'startAddress':section.startAddress,
  22348. 'endAddress':section.endAddress
  22349. };
  22350. address.endAddress[address.endAddress.length - 1]++;
  22351. range.moveToAddress(address).scrollToView();
  22352. return true;
  22353. },
  22354. notNeedUndo: true
  22355. }
  22356. }
  22357. }
  22358. });
  22359. // plugins/simpleupload.js
  22360. /**
  22361. * @description
  22362. * 简单上传:点击按钮,直接选择文件上传
  22363. * @author Jinqn
  22364. * @date 2014-03-31
  22365. */
  22366. UE.plugin.register('simpleupload', function (){
  22367. var me = this,
  22368. isLoaded = false,
  22369. containerBtn;
  22370. function initUploadBtn(){
  22371. var w = containerBtn.offsetWidth || 20,
  22372. h = containerBtn.offsetHeight || 20,
  22373. btnIframe = document.createElement('iframe'),
  22374. 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;';
  22375. domUtils.on(btnIframe, 'load', function(){
  22376. var timestrap = (+new Date()).toString(36),
  22377. wrapper,
  22378. btnIframeDoc,
  22379. btnIframeBody;
  22380. btnIframeDoc = (btnIframe.contentDocument || btnIframe.contentWindow.document);
  22381. btnIframeBody = btnIframeDoc.body;
  22382. wrapper = btnIframeDoc.createElement('div');
  22383. wrapper.innerHTML = '<form id="edui_form_' + timestrap + '" target="edui_iframe_' + timestrap + '" method="POST" enctype="multipart/form-data" action="' + me.getOpt('serverUrl') + '" ' +
  22384. 'style="' + btnStyle + '">' +
  22385. '<input id="edui_input_' + timestrap + '" type="file" accept="image/*" name="' + me.options.imageFieldName + '" ' +
  22386. 'style="' + btnStyle + '">' +
  22387. '</form>' +
  22388. '<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>';
  22389. wrapper.className = 'edui-' + me.options.theme;
  22390. wrapper.id = me.ui.id + '_iframeupload';
  22391. btnIframeBody.style.cssText = btnStyle;
  22392. btnIframeBody.style.width = w + 'px';
  22393. btnIframeBody.style.height = h + 'px';
  22394. btnIframeBody.appendChild(wrapper);
  22395. if (btnIframeBody.parentNode) {
  22396. btnIframeBody.parentNode.style.width = w + 'px';
  22397. btnIframeBody.parentNode.style.height = w + 'px';
  22398. }
  22399. var form = btnIframeDoc.getElementById('edui_form_' + timestrap);
  22400. var input = btnIframeDoc.getElementById('edui_input_' + timestrap);
  22401. var iframe = btnIframeDoc.getElementById('edui_iframe_' + timestrap);
  22402. /**
  22403. * 2017-09-07 改掉了ueditor源码,将本身的单文件上传的方法改为ajax上传,主要目的是为了解决跨域的问题
  22404. * @author Guoqing
  22405. */
  22406. domUtils.on(input, 'change', function() {
  22407. if(!input.value) return;
  22408. var loadingId = 'loading_' + (+new Date()).toString(36);
  22409. var imageActionUrl = me.getActionUrl(me.getOpt('imageActionName'));
  22410. var allowFiles = me.getOpt('imageAllowFiles');
  22411. me.focus();
  22412. me.execCommand('inserthtml', '<img class="loadingclass" id="' + loadingId + '" src="' + me.options.themePath + me.options.theme +'/images/spacer.gif" title="' + (me.getLang('simpleupload.loading') || '') + '" >');
  22413. /!* 判断后端配置是否没有加载成功 *!/
  22414. if (!me.getOpt('imageActionName')) {
  22415. errorHandler(me.getLang('autoupload.errorLoadConfig'));
  22416. return;
  22417. }
  22418. // 判断文件格式是否错误
  22419. var filename = input.value,
  22420. fileext = filename ? filename.substr(filename.lastIndexOf('.')):'';
  22421. if (!fileext || (allowFiles && (allowFiles.join('') + '.').indexOf(fileext.toLowerCase() + '.') == -1)) {
  22422. showErrorLoader(me.getLang('simpleupload.exceedTypeError'));
  22423. return;
  22424. }
  22425. var params = utils.serializeParam(me.queryCommandValue('serverparam')) || '';
  22426. var action = utils.formatUrl(imageActionUrl + (imageActionUrl.indexOf('?') == -1 ? '?' : '&') + params);
  22427. var formData = new FormData();
  22428. formData.append("upfile", form[0].files[0] );
  22429. $.ajax({
  22430. url: action,
  22431. type: 'POST',
  22432. cache: false,
  22433. data: formData,
  22434. processData: false,
  22435. contentType: false,
  22436. success: function (data) {
  22437. data = JSON.parse(data);
  22438. var link, loader,
  22439. body = (iframe.contentDocument || iframe.contentWindow.document).body,
  22440. result = body.innerText || body.textContent || '';
  22441. link = me.options.imageUrlPrefix + data.url;
  22442. if(data.state == 'SUCCESS' && data.url) {
  22443. loader = me.document.getElementById(loadingId);
  22444. loader.setAttribute('src', link);
  22445. loader.setAttribute('_src', link);
  22446. loader.setAttribute('title', data.title || '');
  22447. loader.setAttribute('alt', data.original || '');
  22448. loader.removeAttribute('id');
  22449. domUtils.removeClasses(loader, 'loadingclass');
  22450. } else {
  22451. showErrorLoader && showErrorLoader(data.state);
  22452. }
  22453. form.reset();
  22454. }
  22455. });
  22456. function showErrorLoader(title){
  22457. if(loadingId) {
  22458. var loader = me.document.getElementById(loadingId);
  22459. loader && domUtils.remove(loader);
  22460. me.fireEvent('showmessage', {
  22461. 'id': loadingId,
  22462. 'content': title,
  22463. 'type': 'error',
  22464. 'timeout': 4000
  22465. });
  22466. }
  22467. }
  22468. });
  22469. /*domUtils.on(input, 'change', function(){
  22470. if(!input.value) return;
  22471. var loadingId = 'loading_' + (+new Date()).toString(36);
  22472. var params = utils.serializeParam(me.queryCommandValue('serverparam')) || '';
  22473. var imageActionUrl = me.getActionUrl(me.getOpt('imageActionName'));
  22474. var allowFiles = me.getOpt('imageAllowFiles');
  22475. me.focus();
  22476. me.execCommand('inserthtml', '<img class="loadingclass" id="' + loadingId + '" src="' + me.options.themePath + me.options.theme +'/images/spacer.gif" title="' + (me.getLang('simpleupload.loading') || '') + '" >');
  22477. function callback(){
  22478. try{
  22479. var link, json, loader,
  22480. body = (iframe.contentDocument || iframe.contentWindow.document).body,
  22481. result = body.innerText || body.textContent || '';
  22482. json = (new Function("return " + result))();
  22483. link = me.options.imageUrlPrefix + json.url;
  22484. if(json.state == 'SUCCESS' && json.url) {
  22485. loader = me.document.getElementById(loadingId);
  22486. loader.setAttribute('src', link);
  22487. loader.setAttribute('_src', link);
  22488. loader.setAttribute('title', json.title || '');
  22489. loader.setAttribute('alt', json.original || '');
  22490. loader.removeAttribute('id');
  22491. domUtils.removeClasses(loader, 'loadingclass');
  22492. } else {
  22493. showErrorLoader && showErrorLoader(json.state);
  22494. }
  22495. }catch(er){
  22496. showErrorLoader && showErrorLoader(me.getLang('simpleupload.loadError'));
  22497. }
  22498. form.reset();
  22499. domUtils.un(iframe, 'load', callback);
  22500. }
  22501. function showErrorLoader(title){
  22502. if(loadingId) {
  22503. var loader = me.document.getElementById(loadingId);
  22504. loader && domUtils.remove(loader);
  22505. me.fireEvent('showmessage', {
  22506. 'id': loadingId,
  22507. 'content': title,
  22508. 'type': 'error',
  22509. 'timeout': 4000
  22510. });
  22511. }
  22512. }
  22513. /!* 判断后端配置是否没有加载成功 *!/
  22514. if (!me.getOpt('imageActionName')) {
  22515. errorHandler(me.getLang('autoupload.errorLoadConfig'));
  22516. return;
  22517. }
  22518. // 判断文件格式是否错误
  22519. var filename = input.value,
  22520. fileext = filename ? filename.substr(filename.lastIndexOf('.')):'';
  22521. if (!fileext || (allowFiles && (allowFiles.join('') + '.').indexOf(fileext.toLowerCase() + '.') == -1)) {
  22522. showErrorLoader(me.getLang('simpleupload.exceedTypeError'));
  22523. return;
  22524. }
  22525. domUtils.on(iframe, 'load', callback);
  22526. form.action = utils.formatUrl(imageActionUrl + (imageActionUrl.indexOf('?') == -1 ? '?':'&') + params);
  22527. form.submit();
  22528. });*/
  22529. var stateTimer;
  22530. me.addListener('selectionchange', function () {
  22531. clearTimeout(stateTimer);
  22532. stateTimer = setTimeout(function() {
  22533. var state = me.queryCommandState('simpleupload');
  22534. if (state == -1) {
  22535. input.disabled = 'disabled';
  22536. } else {
  22537. input.disabled = false;
  22538. }
  22539. }, 400);
  22540. });
  22541. isLoaded = true;
  22542. });
  22543. btnIframe.style.cssText = btnStyle;
  22544. containerBtn.appendChild(btnIframe);
  22545. }
  22546. return {
  22547. bindEvents:{
  22548. 'ready': function() {
  22549. //设置loading的样式
  22550. utils.cssRule('loading',
  22551. '.loadingclass{display:inline-block;cursor:default;background: url(\''
  22552. + this.options.themePath
  22553. + this.options.theme +'/images/loading.gif\') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;}\n' +
  22554. '.loaderrorclass{display:inline-block;cursor:default;background: url(\''
  22555. + this.options.themePath
  22556. + this.options.theme +'/images/loaderror.png\') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;' +
  22557. '}',
  22558. this.document);
  22559. },
  22560. /* 初始化简单上传按钮 */
  22561. 'simpleuploadbtnready': function(type, container) {
  22562. containerBtn = container;
  22563. me.afterConfigReady(initUploadBtn);
  22564. }
  22565. },
  22566. outputRule: function(root){
  22567. utils.each(root.getNodesByTagName('img'),function(n){
  22568. if (/\b(loaderrorclass)|(bloaderrorclass)\b/.test(n.getAttr('class'))) {
  22569. n.parentNode.removeChild(n);
  22570. }
  22571. });
  22572. },
  22573. commands: {
  22574. 'simpleupload': {
  22575. queryCommandState: function () {
  22576. return isLoaded ? 0:-1;
  22577. }
  22578. }
  22579. }
  22580. }
  22581. });
  22582. // plugins/serverparam.js
  22583. /**
  22584. * 服务器提交的额外参数列表设置插件
  22585. * @file
  22586. * @since 1.2.6.1
  22587. */
  22588. UE.plugin.register('serverparam', function (){
  22589. var me = this,
  22590. serverParam = {};
  22591. return {
  22592. commands:{
  22593. /**
  22594. * 修改服务器提交的额外参数列表,清除所有项
  22595. * @command serverparam
  22596. * @method execCommand
  22597. * @param { String } cmd 命令字符串
  22598. * @example
  22599. * ```javascript
  22600. * editor.execCommand('serverparam');
  22601. * editor.queryCommandValue('serverparam'); //返回空
  22602. * ```
  22603. */
  22604. /**
  22605. * 修改服务器提交的额外参数列表,删除指定项
  22606. * @command serverparam
  22607. * @method execCommand
  22608. * @param { String } cmd 命令字符串
  22609. * @param { String } key 要清除的属性
  22610. * @example
  22611. * ```javascript
  22612. * editor.execCommand('serverparam', 'name'); //删除属性name
  22613. * ```
  22614. */
  22615. /**
  22616. * 修改服务器提交的额外参数列表,使用键值添加项
  22617. * @command serverparam
  22618. * @method execCommand
  22619. * @param { String } cmd 命令字符串
  22620. * @param { String } key 要添加的属性
  22621. * @param { String } value 要添加属性的值
  22622. * @example
  22623. * ```javascript
  22624. * editor.execCommand('serverparam', 'name', 'hello');
  22625. * editor.queryCommandValue('serverparam'); //返回对象 {'name': 'hello'}
  22626. * ```
  22627. */
  22628. /**
  22629. * 修改服务器提交的额外参数列表,传入键值对对象添加多项
  22630. * @command serverparam
  22631. * @method execCommand
  22632. * @param { String } cmd 命令字符串
  22633. * @param { Object } key 传入的键值对对象
  22634. * @example
  22635. * ```javascript
  22636. * editor.execCommand('serverparam', {'name': 'hello'});
  22637. * editor.queryCommandValue('serverparam'); //返回对象 {'name': 'hello'}
  22638. * ```
  22639. */
  22640. /**
  22641. * 修改服务器提交的额外参数列表,使用自定义函数添加多项
  22642. * @command serverparam
  22643. * @method execCommand
  22644. * @param { String } cmd 命令字符串
  22645. * @param { Function } key 自定义获取参数的函数
  22646. * @example
  22647. * ```javascript
  22648. * editor.execCommand('serverparam', function(editor){
  22649. * return {'key': 'value'};
  22650. * });
  22651. * editor.queryCommandValue('serverparam'); //返回对象 {'key': 'value'}
  22652. * ```
  22653. */
  22654. /**
  22655. * 获取服务器提交的额外参数列表
  22656. * @command serverparam
  22657. * @method queryCommandValue
  22658. * @param { String } cmd 命令字符串
  22659. * @example
  22660. * ```javascript
  22661. * editor.queryCommandValue( 'serverparam' ); //返回对象 {'key': 'value'}
  22662. * ```
  22663. */
  22664. 'serverparam':{
  22665. execCommand:function (cmd, key, value) {
  22666. if (key === undefined || key === null) { //不传参数,清空列表
  22667. serverParam = {};
  22668. } else if (utils.isString(key)) { //传入键值
  22669. if(value === undefined || value === null) {
  22670. delete serverParam[key];
  22671. } else {
  22672. serverParam[key] = value;
  22673. }
  22674. } else if (utils.isObject(key)) { //传入对象,覆盖列表项
  22675. utils.extend(serverParam, key, true);
  22676. } else if (utils.isFunction(key)){ //传入函数,添加列表项
  22677. utils.extend(serverParam, key(), true);
  22678. }
  22679. },
  22680. queryCommandValue: function(){
  22681. return serverParam || {};
  22682. }
  22683. }
  22684. }
  22685. }
  22686. });
  22687. // plugins/insertfile.js
  22688. /**
  22689. * 插入附件
  22690. */
  22691. UE.plugin.register('insertfile', function (){
  22692. var me = this;
  22693. function getFileIcon(url){
  22694. var ext = url.substr(url.lastIndexOf('.') + 1).toLowerCase(),
  22695. maps = {
  22696. "rar":"icon_rar.gif",
  22697. "zip":"icon_rar.gif",
  22698. "tar":"icon_rar.gif",
  22699. "gz":"icon_rar.gif",
  22700. "bz2":"icon_rar.gif",
  22701. "doc":"icon_doc.gif",
  22702. "docx":"icon_doc.gif",
  22703. "pdf":"icon_pdf.gif",
  22704. "mp3":"icon_mp3.gif",
  22705. "xls":"icon_xls.gif",
  22706. "chm":"icon_chm.gif",
  22707. "ppt":"icon_ppt.gif",
  22708. "pptx":"icon_ppt.gif",
  22709. "avi":"icon_mv.gif",
  22710. "rmvb":"icon_mv.gif",
  22711. "wmv":"icon_mv.gif",
  22712. "flv":"icon_mv.gif",
  22713. "swf":"icon_mv.gif",
  22714. "rm":"icon_mv.gif",
  22715. "exe":"icon_exe.gif",
  22716. "psd":"icon_psd.gif",
  22717. "txt":"icon_txt.gif",
  22718. "jpg":"icon_jpg.gif",
  22719. "png":"icon_jpg.gif",
  22720. "jpeg":"icon_jpg.gif",
  22721. "gif":"icon_jpg.gif",
  22722. "ico":"icon_jpg.gif",
  22723. "bmp":"icon_jpg.gif"
  22724. };
  22725. return maps[ext] ? maps[ext]:maps['txt'];
  22726. }
  22727. return {
  22728. commands:{
  22729. 'insertfile': {
  22730. execCommand: function (command, filelist){
  22731. filelist = utils.isArray(filelist) ? filelist : [filelist];
  22732. var i, item, icon, title,
  22733. html = '',
  22734. URL = me.getOpt('UEDITOR_HOME_URL'),
  22735. iconDir = URL + (URL.substr(URL.length - 1) == '/' ? '':'/') + 'dialogs/attachment/fileTypeImages/';
  22736. for (i = 0; i < filelist.length; i++) {
  22737. item = filelist[i];
  22738. icon = iconDir + getFileIcon(item.url);
  22739. title = item.title || item.url.substr(item.url.lastIndexOf('/') + 1);
  22740. html += '<p style="line-height: 16px;">' +
  22741. '<img style="vertical-align: middle; margin-right: 2px;" src="'+ icon + '" _src="' + icon + '" />' +
  22742. '<a style="font-size:12px; color:#0066cc;" href="' + item.url +'" title="' + title + '">' + title + '</a>' +
  22743. '</p>';
  22744. }
  22745. me.execCommand('insertHtml', html);
  22746. }
  22747. }
  22748. }
  22749. }
  22750. });
  22751. // plugins/xssFilter.js
  22752. /**
  22753. * @file xssFilter.js
  22754. * @desc xss过滤器
  22755. * @author robbenmu
  22756. */
  22757. UE.plugins.xssFilter = function() {
  22758. var config = UEDITOR_CONFIG;
  22759. var whitList = config.whitList;
  22760. function filter(node) {
  22761. var tagName = node.tagName;
  22762. var attrs = node.attrs;
  22763. if (!whitList.hasOwnProperty(tagName)) {
  22764. node.parentNode.removeChild(node);
  22765. return false;
  22766. }
  22767. UE.utils.each(attrs, function (val, key) {
  22768. if (whitList[tagName].indexOf(key) === -1) {
  22769. node.setAttr(key);
  22770. }
  22771. });
  22772. }
  22773. // 添加inserthtml\paste等操作用的过滤规则
  22774. if (whitList && config.xssFilterRules) {
  22775. this.options.filterRules = function () {
  22776. var result = {};
  22777. UE.utils.each(whitList, function(val, key) {
  22778. result[key] = function (node) {
  22779. return filter(node);
  22780. };
  22781. });
  22782. return result;
  22783. }();
  22784. }
  22785. var tagList = [];
  22786. UE.utils.each(whitList, function (val, key) {
  22787. tagList.push(key);
  22788. });
  22789. // 添加input过滤规则
  22790. //
  22791. if (whitList && config.inputXssFilter) {
  22792. this.addInputRule(function (root) {
  22793. root.traversal(function(node) {
  22794. if (node.type !== 'element') {
  22795. return false;
  22796. }
  22797. filter(node);
  22798. });
  22799. });
  22800. }
  22801. // 添加output过滤规则
  22802. //
  22803. if (whitList && config.outputXssFilter) {
  22804. this.addOutputRule(function (root) {
  22805. root.traversal(function(node) {
  22806. if (node.type !== 'element') {
  22807. return false;
  22808. }
  22809. filter(node);
  22810. });
  22811. });
  22812. }
  22813. };
  22814. // ui/ui.js
  22815. var baidu = baidu || {};
  22816. baidu.editor = baidu.editor || {};
  22817. UE.ui = baidu.editor.ui = {};
  22818. // ui/uiutils.js
  22819. (function (){
  22820. var browser = baidu.editor.browser,
  22821. domUtils = baidu.editor.dom.domUtils;
  22822. var magic = '$EDITORUI';
  22823. var root = window[magic] = {};
  22824. var uidMagic = 'ID' + magic;
  22825. var uidCount = 0;
  22826. var uiUtils = baidu.editor.ui.uiUtils = {
  22827. uid: function (obj){
  22828. return (obj ? obj[uidMagic] || (obj[uidMagic] = ++ uidCount) : ++ uidCount);
  22829. },
  22830. hook: function ( fn, callback ) {
  22831. var dg;
  22832. if (fn && fn._callbacks) {
  22833. dg = fn;
  22834. } else {
  22835. dg = function (){
  22836. var q;
  22837. if (fn) {
  22838. q = fn.apply(this, arguments);
  22839. }
  22840. var callbacks = dg._callbacks;
  22841. var k = callbacks.length;
  22842. while (k --) {
  22843. var r = callbacks[k].apply(this, arguments);
  22844. if (q === undefined) {
  22845. q = r;
  22846. }
  22847. }
  22848. return q;
  22849. };
  22850. dg._callbacks = [];
  22851. }
  22852. dg._callbacks.push(callback);
  22853. return dg;
  22854. },
  22855. createElementByHtml: function (html){
  22856. var el = document.createElement('div');
  22857. el.innerHTML = html;
  22858. el = el.firstChild;
  22859. el.parentNode.removeChild(el);
  22860. return el;
  22861. },
  22862. getViewportElement: function (){
  22863. return (browser.ie && browser.quirks) ?
  22864. document.body : document.documentElement;
  22865. },
  22866. getClientRect: function (element){
  22867. var bcr;
  22868. //trace IE6下在控制编辑器显隐时可能会报错,catch一下
  22869. try{
  22870. bcr = element.getBoundingClientRect();
  22871. }catch(e){
  22872. bcr={left:0,top:0,height:0,width:0}
  22873. }
  22874. var rect = {
  22875. left: Math.round(bcr.left),
  22876. top: Math.round(bcr.top),
  22877. height: Math.round(bcr.bottom - bcr.top),
  22878. width: Math.round(bcr.right - bcr.left)
  22879. };
  22880. var doc;
  22881. while ((doc = element.ownerDocument) !== document &&
  22882. (element = domUtils.getWindow(doc).frameElement)) {
  22883. bcr = element.getBoundingClientRect();
  22884. rect.left += bcr.left;
  22885. rect.top += bcr.top;
  22886. }
  22887. rect.bottom = rect.top + rect.height;
  22888. rect.right = rect.left + rect.width;
  22889. return rect;
  22890. },
  22891. getViewportRect: function (){
  22892. var viewportEl = uiUtils.getViewportElement();
  22893. var width = (window.innerWidth || viewportEl.clientWidth) | 0;
  22894. var height = (window.innerHeight ||viewportEl.clientHeight) | 0;
  22895. return {
  22896. left: 0,
  22897. top: 0,
  22898. height: height,
  22899. width: width,
  22900. bottom: height,
  22901. right: width
  22902. };
  22903. },
  22904. setViewportOffset: function (element, offset){
  22905. var rect;
  22906. var fixedLayer = uiUtils.getFixedLayer();
  22907. if (element.parentNode === fixedLayer) {
  22908. element.style.left = offset.left + 'px';
  22909. element.style.top = offset.top + 'px';
  22910. } else {
  22911. domUtils.setViewportOffset(element, offset);
  22912. }
  22913. },
  22914. getEventOffset: function (evt){
  22915. var el = evt.target || evt.srcElement;
  22916. var rect = uiUtils.getClientRect(el);
  22917. var offset = uiUtils.getViewportOffsetByEvent(evt);
  22918. return {
  22919. left: offset.left - rect.left,
  22920. top: offset.top - rect.top
  22921. };
  22922. },
  22923. getViewportOffsetByEvent: function (evt){
  22924. var el = evt.target || evt.srcElement;
  22925. var frameEl = domUtils.getWindow(el).frameElement;
  22926. var offset = {
  22927. left: evt.clientX,
  22928. top: evt.clientY
  22929. };
  22930. if (frameEl && el.ownerDocument !== document) {
  22931. var rect = uiUtils.getClientRect(frameEl);
  22932. offset.left += rect.left;
  22933. offset.top += rect.top;
  22934. }
  22935. return offset;
  22936. },
  22937. setGlobal: function (id, obj){
  22938. root[id] = obj;
  22939. return magic + '["' + id + '"]';
  22940. },
  22941. unsetGlobal: function (id){
  22942. delete root[id];
  22943. },
  22944. copyAttributes: function (tgt, src){
  22945. var attributes = src.attributes;
  22946. var k = attributes.length;
  22947. while (k --) {
  22948. var attrNode = attributes[k];
  22949. if ( attrNode.nodeName != 'style' && attrNode.nodeName != 'class' && (!browser.ie || attrNode.specified) ) {
  22950. tgt.setAttribute(attrNode.nodeName, attrNode.nodeValue);
  22951. }
  22952. }
  22953. if (src.className) {
  22954. domUtils.addClass(tgt,src.className);
  22955. }
  22956. if (src.style.cssText) {
  22957. tgt.style.cssText += ';' + src.style.cssText;
  22958. }
  22959. },
  22960. removeStyle: function (el, styleName){
  22961. if (el.style.removeProperty) {
  22962. el.style.removeProperty(styleName);
  22963. } else if (el.style.removeAttribute) {
  22964. el.style.removeAttribute(styleName);
  22965. } else throw '';
  22966. },
  22967. contains: function (elA, elB){
  22968. return elA && elB && (elA === elB ? false : (
  22969. elA.contains ? elA.contains(elB) :
  22970. elA.compareDocumentPosition(elB) & 16
  22971. ));
  22972. },
  22973. startDrag: function (evt, callbacks,doc){
  22974. var doc = doc || document;
  22975. var startX = evt.clientX;
  22976. var startY = evt.clientY;
  22977. function handleMouseMove(evt){
  22978. var x = evt.clientX - startX;
  22979. var y = evt.clientY - startY;
  22980. callbacks.ondragmove(x, y,evt);
  22981. if (evt.stopPropagation) {
  22982. evt.stopPropagation();
  22983. } else {
  22984. evt.cancelBubble = true;
  22985. }
  22986. }
  22987. if (doc.addEventListener) {
  22988. function handleMouseUp(evt){
  22989. doc.removeEventListener('mousemove', handleMouseMove, true);
  22990. doc.removeEventListener('mouseup', handleMouseUp, true);
  22991. window.removeEventListener('mouseup', handleMouseUp, true);
  22992. callbacks.ondragstop();
  22993. }
  22994. doc.addEventListener('mousemove', handleMouseMove, true);
  22995. doc.addEventListener('mouseup', handleMouseUp, true);
  22996. window.addEventListener('mouseup', handleMouseUp, true);
  22997. evt.preventDefault();
  22998. } else {
  22999. var elm = evt.srcElement;
  23000. elm.setCapture();
  23001. function releaseCaptrue(){
  23002. elm.releaseCapture();
  23003. elm.detachEvent('onmousemove', handleMouseMove);
  23004. elm.detachEvent('onmouseup', releaseCaptrue);
  23005. elm.detachEvent('onlosecaptrue', releaseCaptrue);
  23006. callbacks.ondragstop();
  23007. }
  23008. elm.attachEvent('onmousemove', handleMouseMove);
  23009. elm.attachEvent('onmouseup', releaseCaptrue);
  23010. elm.attachEvent('onlosecaptrue', releaseCaptrue);
  23011. evt.returnValue = false;
  23012. }
  23013. callbacks.ondragstart();
  23014. },
  23015. getFixedLayer: function (){
  23016. var layer = document.getElementById('edui_fixedlayer');
  23017. if (layer == null) {
  23018. layer = document.createElement('div');
  23019. layer.id = 'edui_fixedlayer';
  23020. document.body.appendChild(layer);
  23021. if (browser.ie && browser.version <= 8) {
  23022. layer.style.position = 'absolute';
  23023. bindFixedLayer();
  23024. setTimeout(updateFixedOffset);
  23025. } else {
  23026. layer.style.position = 'fixed';
  23027. }
  23028. layer.style.left = '0';
  23029. layer.style.top = '0';
  23030. layer.style.width = '0';
  23031. layer.style.height = '0';
  23032. }
  23033. return layer;
  23034. },
  23035. makeUnselectable: function (element){
  23036. if (browser.opera || (browser.ie && browser.version < 9)) {
  23037. element.unselectable = 'on';
  23038. if (element.hasChildNodes()) {
  23039. for (var i=0; i<element.childNodes.length; i++) {
  23040. if (element.childNodes[i].nodeType == 1) {
  23041. uiUtils.makeUnselectable(element.childNodes[i]);
  23042. }
  23043. }
  23044. }
  23045. } else {
  23046. if (element.style.MozUserSelect !== undefined) {
  23047. element.style.MozUserSelect = 'none';
  23048. } else if (element.style.WebkitUserSelect !== undefined) {
  23049. element.style.WebkitUserSelect = 'none';
  23050. } else if (element.style.KhtmlUserSelect !== undefined) {
  23051. element.style.KhtmlUserSelect = 'none';
  23052. }
  23053. }
  23054. }
  23055. };
  23056. function updateFixedOffset(){
  23057. var layer = document.getElementById('edui_fixedlayer');
  23058. uiUtils.setViewportOffset(layer, {
  23059. left: 0,
  23060. top: 0
  23061. });
  23062. // layer.style.display = 'none';
  23063. // layer.style.display = 'block';
  23064. //#trace: 1354
  23065. // setTimeout(updateFixedOffset);
  23066. }
  23067. function bindFixedLayer(adjOffset){
  23068. domUtils.on(window, 'scroll', updateFixedOffset);
  23069. domUtils.on(window, 'resize', baidu.editor.utils.defer(updateFixedOffset, 0, true));
  23070. }
  23071. })();
  23072. // ui/uibase.js
  23073. (function () {
  23074. var utils = baidu.editor.utils,
  23075. uiUtils = baidu.editor.ui.uiUtils,
  23076. EventBase = baidu.editor.EventBase,
  23077. UIBase = baidu.editor.ui.UIBase = function () {
  23078. };
  23079. UIBase.prototype = {
  23080. className:'',
  23081. uiName:'',
  23082. initOptions:function (options) {
  23083. var me = this;
  23084. for (var k in options) {
  23085. me[k] = options[k];
  23086. }
  23087. this.id = this.id || 'edui' + uiUtils.uid();
  23088. },
  23089. initUIBase:function () {
  23090. this._globalKey = utils.unhtml(uiUtils.setGlobal(this.id, this));
  23091. },
  23092. render:function (holder) {
  23093. var html = this.renderHtml();
  23094. var el = uiUtils.createElementByHtml(html);
  23095. //by xuheng 给每个node添加class
  23096. var list = domUtils.getElementsByTagName(el, "*");
  23097. var theme = "edui-" + (this.theme || this.editor.options.theme);
  23098. var layer = document.getElementById('edui_fixedlayer');
  23099. for (var i = 0, node; node = list[i++];) {
  23100. domUtils.addClass(node, theme);
  23101. }
  23102. domUtils.addClass(el, theme);
  23103. if(layer){
  23104. layer.className="";
  23105. domUtils.addClass(layer,theme);
  23106. }
  23107. var seatEl = this.getDom();
  23108. if (seatEl != null) {
  23109. seatEl.parentNode.replaceChild(el, seatEl);
  23110. uiUtils.copyAttributes(el, seatEl);
  23111. } else {
  23112. if (typeof holder == 'string') {
  23113. holder = document.getElementById(holder);
  23114. }
  23115. holder = holder || uiUtils.getFixedLayer();
  23116. domUtils.addClass(holder, theme);
  23117. holder.appendChild(el);
  23118. }
  23119. this.postRender();
  23120. },
  23121. getDom:function (name) {
  23122. if (!name) {
  23123. return document.getElementById(this.id);
  23124. } else {
  23125. return document.getElementById(this.id + '_' + name);
  23126. }
  23127. },
  23128. postRender:function () {
  23129. this.fireEvent('postrender');
  23130. },
  23131. getHtmlTpl:function () {
  23132. return '';
  23133. },
  23134. formatHtml:function (tpl) {
  23135. var prefix = 'edui-' + this.uiName;
  23136. return (tpl
  23137. .replace(/##/g, this.id)
  23138. .replace(/%%-/g, this.uiName ? prefix + '-' : '')
  23139. .replace(/%%/g, (this.uiName ? prefix : '') + ' ' + this.className)
  23140. .replace(/\$\$/g, this._globalKey));
  23141. },
  23142. renderHtml:function () {
  23143. return this.formatHtml(this.getHtmlTpl());
  23144. },
  23145. dispose:function () {
  23146. var box = this.getDom();
  23147. if (box) baidu.editor.dom.domUtils.remove(box);
  23148. uiUtils.unsetGlobal(this.id);
  23149. }
  23150. };
  23151. utils.inherits(UIBase, EventBase);
  23152. })();
  23153. // ui/separator.js
  23154. (function (){
  23155. var utils = baidu.editor.utils,
  23156. UIBase = baidu.editor.ui.UIBase,
  23157. Separator = baidu.editor.ui.Separator = function (options){
  23158. this.initOptions(options);
  23159. this.initSeparator();
  23160. };
  23161. Separator.prototype = {
  23162. uiName: 'separator',
  23163. initSeparator: function (){
  23164. this.initUIBase();
  23165. },
  23166. getHtmlTpl: function (){
  23167. return '<div id="##" class="edui-box %%"></div>';
  23168. }
  23169. };
  23170. utils.inherits(Separator, UIBase);
  23171. })();
  23172. // ui/mask.js
  23173. ///import core
  23174. ///import uicore
  23175. (function (){
  23176. var utils = baidu.editor.utils,
  23177. domUtils = baidu.editor.dom.domUtils,
  23178. UIBase = baidu.editor.ui.UIBase,
  23179. uiUtils = baidu.editor.ui.uiUtils;
  23180. var Mask = baidu.editor.ui.Mask = function (options){
  23181. this.initOptions(options);
  23182. this.initUIBase();
  23183. };
  23184. Mask.prototype = {
  23185. getHtmlTpl: function (){
  23186. return '<div id="##" class="edui-mask %%" onclick="return $$._onClick(event, this);" onmousedown="return $$._onMouseDown(event, this);"></div>';
  23187. },
  23188. postRender: function (){
  23189. var me = this;
  23190. domUtils.on(window, 'resize', function (){
  23191. setTimeout(function (){
  23192. if (!me.isHidden()) {
  23193. me._fill();
  23194. }
  23195. });
  23196. });
  23197. },
  23198. show: function (zIndex){
  23199. this._fill();
  23200. this.getDom().style.display = '';
  23201. this.getDom().style.zIndex = zIndex;
  23202. },
  23203. hide: function (){
  23204. this.getDom().style.display = 'none';
  23205. this.getDom().style.zIndex = '';
  23206. },
  23207. isHidden: function (){
  23208. return this.getDom().style.display == 'none';
  23209. },
  23210. _onMouseDown: function (){
  23211. return false;
  23212. },
  23213. _onClick: function (e, target){
  23214. this.fireEvent('click', e, target);
  23215. },
  23216. _fill: function (){
  23217. var el = this.getDom();
  23218. var vpRect = uiUtils.getViewportRect();
  23219. el.style.width = vpRect.width + 'px';
  23220. el.style.height = vpRect.height + 'px';
  23221. }
  23222. };
  23223. utils.inherits(Mask, UIBase);
  23224. })();
  23225. // ui/popup.js
  23226. ///import core
  23227. ///import uicore
  23228. (function () {
  23229. var utils = baidu.editor.utils,
  23230. uiUtils = baidu.editor.ui.uiUtils,
  23231. domUtils = baidu.editor.dom.domUtils,
  23232. UIBase = baidu.editor.ui.UIBase,
  23233. Popup = baidu.editor.ui.Popup = function (options){
  23234. this.initOptions(options);
  23235. this.initPopup();
  23236. };
  23237. var allPopups = [];
  23238. function closeAllPopup( evt,el ){
  23239. for ( var i = 0; i < allPopups.length; i++ ) {
  23240. var pop = allPopups[i];
  23241. if (!pop.isHidden()) {
  23242. if (pop.queryAutoHide(el) !== false) {
  23243. if(evt&&/scroll/ig.test(evt.type)&&pop.className=="edui-wordpastepop") return;
  23244. pop.hide();
  23245. }
  23246. }
  23247. }
  23248. if(allPopups.length)
  23249. pop.editor.fireEvent("afterhidepop");
  23250. }
  23251. Popup.postHide = closeAllPopup;
  23252. var ANCHOR_CLASSES = ['edui-anchor-topleft','edui-anchor-topright',
  23253. 'edui-anchor-bottomleft','edui-anchor-bottomright'];
  23254. Popup.prototype = {
  23255. SHADOW_RADIUS: 5,
  23256. content: null,
  23257. _hidden: false,
  23258. autoRender: true,
  23259. canSideLeft: true,
  23260. canSideUp: true,
  23261. initPopup: function (){
  23262. this.initUIBase();
  23263. allPopups.push( this );
  23264. },
  23265. getHtmlTpl: function (){
  23266. return '<div id="##" class="edui-popup %%" onmousedown="return false;">' +
  23267. ' <div id="##_body" class="edui-popup-body">' +
  23268. ' <iframe style="position:absolute;z-index:-1;left:0;top:0;background-color: transparent;" frameborder="0" width="100%" height="100%" src="about:blank"></iframe>' +
  23269. ' <div class="edui-shadow"></div>' +
  23270. ' <div id="##_content" class="edui-popup-content">' +
  23271. this.getContentHtmlTpl() +
  23272. ' </div>' +
  23273. ' </div>' +
  23274. '</div>';
  23275. },
  23276. getContentHtmlTpl: function (){
  23277. if(this.content){
  23278. if (typeof this.content == 'string') {
  23279. return this.content;
  23280. }
  23281. return this.content.renderHtml();
  23282. }else{
  23283. return ''
  23284. }
  23285. },
  23286. _UIBase_postRender: UIBase.prototype.postRender,
  23287. postRender: function (){
  23288. if (this.content instanceof UIBase) {
  23289. this.content.postRender();
  23290. }
  23291. //捕获鼠标滚轮
  23292. if( this.captureWheel && !this.captured ) {
  23293. this.captured = true;
  23294. var winHeight = ( document.documentElement.clientHeight || document.body.clientHeight ) - 80,
  23295. _height = this.getDom().offsetHeight,
  23296. _top = uiUtils.getClientRect( this.combox.getDom() ).top,
  23297. content = this.getDom('content'),
  23298. ifr = this.getDom('body').getElementsByTagName('iframe'),
  23299. me = this;
  23300. ifr.length && ( ifr = ifr[0] );
  23301. while( _top + _height > winHeight ) {
  23302. _height -= 30;
  23303. }
  23304. content.style.height = _height + 'px';
  23305. //同步更改iframe高度
  23306. ifr && ( ifr.style.height = _height + 'px' );
  23307. //阻止在combox上的鼠标滚轮事件, 防止用户的正常操作被误解
  23308. if( window.XMLHttpRequest ) {
  23309. domUtils.on( content, ( 'onmousewheel' in document.body ) ? 'mousewheel' :'DOMMouseScroll' , function(e){
  23310. if(e.preventDefault) {
  23311. e.preventDefault();
  23312. } else {
  23313. e.returnValue = false;
  23314. }
  23315. if( e.wheelDelta ) {
  23316. content.scrollTop -= ( e.wheelDelta / 120 )*60;
  23317. } else {
  23318. content.scrollTop -= ( e.detail / -3 )*60;
  23319. }
  23320. });
  23321. } else {
  23322. //ie6
  23323. domUtils.on( this.getDom(), 'mousewheel' , function(e){
  23324. e.returnValue = false;
  23325. me.getDom('content').scrollTop -= ( e.wheelDelta / 120 )*60;
  23326. });
  23327. }
  23328. }
  23329. this.fireEvent('postRenderAfter');
  23330. this.hide(true);
  23331. this._UIBase_postRender();
  23332. },
  23333. _doAutoRender: function (){
  23334. if (!this.getDom() && this.autoRender) {
  23335. this.render();
  23336. }
  23337. },
  23338. mesureSize: function (){
  23339. var box = this.getDom('content');
  23340. return uiUtils.getClientRect(box);
  23341. },
  23342. fitSize: function (){
  23343. if( this.captureWheel && this.sized ) {
  23344. return this.__size;
  23345. }
  23346. this.sized = true;
  23347. var popBodyEl = this.getDom('body');
  23348. popBodyEl.style.width = '';
  23349. popBodyEl.style.height = '';
  23350. var size = this.mesureSize();
  23351. if( this.captureWheel ) {
  23352. popBodyEl.style.width = -(-20 -size.width) + 'px';
  23353. var height = parseInt( this.getDom('content').style.height, 10 );
  23354. !window.isNaN( height ) && ( size.height = height );
  23355. } else {
  23356. popBodyEl.style.width = size.width + 'px';
  23357. }
  23358. popBodyEl.style.height = size.height + 'px';
  23359. this.__size = size;
  23360. this.captureWheel && (this.getDom('content').style.overflow = 'auto');
  23361. return size;
  23362. },
  23363. showAnchor: function ( element, hoz ){
  23364. this.showAnchorRect( uiUtils.getClientRect( element ), hoz );
  23365. },
  23366. showAnchorRect: function ( rect, hoz, adj ){
  23367. this._doAutoRender();
  23368. var vpRect = uiUtils.getViewportRect();
  23369. this.getDom().style.visibility = 'hidden';
  23370. this._show();
  23371. var popSize = this.fitSize();
  23372. var sideLeft, sideUp, left, top;
  23373. if (hoz) {
  23374. sideLeft = this.canSideLeft && (rect.right + popSize.width > vpRect.right && rect.left > popSize.width);
  23375. sideUp = this.canSideUp && (rect.top + popSize.height > vpRect.bottom && rect.bottom > popSize.height);
  23376. left = (sideLeft ? rect.left - popSize.width : rect.right);
  23377. top = (sideUp ? rect.bottom - popSize.height : rect.top);
  23378. } else {
  23379. sideLeft = this.canSideLeft && (rect.right + popSize.width > vpRect.right && rect.left > popSize.width);
  23380. sideUp = this.canSideUp && (rect.top + popSize.height > vpRect.bottom && rect.bottom > popSize.height);
  23381. left = (sideLeft ? rect.right - popSize.width : rect.left);
  23382. top = (sideUp ? rect.top - popSize.height : rect.bottom);
  23383. }
  23384. var popEl = this.getDom();
  23385. uiUtils.setViewportOffset(popEl, {
  23386. left: left,
  23387. top: top
  23388. });
  23389. domUtils.removeClasses(popEl, ANCHOR_CLASSES);
  23390. popEl.className += ' ' + ANCHOR_CLASSES[(sideUp ? 1 : 0) * 2 + (sideLeft ? 1 : 0)];
  23391. if(this.editor){
  23392. popEl.style.zIndex = this.editor.container.style.zIndex * 1 + 10;
  23393. baidu.editor.ui.uiUtils.getFixedLayer().style.zIndex = popEl.style.zIndex - 1;
  23394. }
  23395. this.getDom().style.visibility = 'visible';
  23396. },
  23397. showAt: function (offset) {
  23398. var left = offset.left;
  23399. var top = offset.top;
  23400. var rect = {
  23401. left: left,
  23402. top: top,
  23403. right: left,
  23404. bottom: top,
  23405. height: 0,
  23406. width: 0
  23407. };
  23408. this.showAnchorRect(rect, false, true);
  23409. },
  23410. _show: function (){
  23411. if (this._hidden) {
  23412. var box = this.getDom();
  23413. box.style.display = '';
  23414. this._hidden = false;
  23415. // if (box.setActive) {
  23416. // box.setActive();
  23417. // }
  23418. this.fireEvent('show');
  23419. }
  23420. },
  23421. isHidden: function (){
  23422. return this._hidden;
  23423. },
  23424. show: function (){
  23425. this._doAutoRender();
  23426. this._show();
  23427. },
  23428. hide: function (notNofity){
  23429. if (!this._hidden && this.getDom()) {
  23430. this.getDom().style.display = 'none';
  23431. this._hidden = true;
  23432. if (!notNofity) {
  23433. this.fireEvent('hide');
  23434. }
  23435. }
  23436. },
  23437. queryAutoHide: function (el){
  23438. return !el || !uiUtils.contains(this.getDom(), el);
  23439. }
  23440. };
  23441. utils.inherits(Popup, UIBase);
  23442. domUtils.on( document, 'mousedown', function ( evt ) {
  23443. var el = evt.target || evt.srcElement;
  23444. closeAllPopup( evt,el );
  23445. } );
  23446. domUtils.on( window, 'scroll', function (evt,el) {
  23447. closeAllPopup( evt,el );
  23448. } );
  23449. })();
  23450. // ui/colorpicker.js
  23451. ///import core
  23452. ///import uicore
  23453. (function (){
  23454. var utils = baidu.editor.utils,
  23455. UIBase = baidu.editor.ui.UIBase,
  23456. ColorPicker = baidu.editor.ui.ColorPicker = function (options){
  23457. this.initOptions(options);
  23458. this.noColorText = this.noColorText || this.editor.getLang("clearColor");
  23459. this.initUIBase();
  23460. };
  23461. ColorPicker.prototype = {
  23462. getHtmlTpl: function (){
  23463. return genColorPicker(this.noColorText,this.editor);
  23464. },
  23465. _onTableClick: function (evt){
  23466. var tgt = evt.target || evt.srcElement;
  23467. var color = tgt.getAttribute('data-color');
  23468. if (color) {
  23469. this.fireEvent('pickcolor', color);
  23470. }
  23471. },
  23472. _onTableOver: function (evt){
  23473. var tgt = evt.target || evt.srcElement;
  23474. var color = tgt.getAttribute('data-color');
  23475. if (color) {
  23476. this.getDom('preview').style.backgroundColor = color;
  23477. }
  23478. },
  23479. _onTableOut: function (){
  23480. this.getDom('preview').style.backgroundColor = '';
  23481. },
  23482. _onPickNoColor: function (){
  23483. this.fireEvent('picknocolor');
  23484. }
  23485. };
  23486. utils.inherits(ColorPicker, UIBase);
  23487. var COLORS = (
  23488. 'ffffff,000000,eeece1,1f497d,4f81bd,c0504d,9bbb59,8064a2,4bacc6,f79646,' +
  23489. 'f2f2f2,7f7f7f,ddd9c3,c6d9f0,dbe5f1,f2dcdb,ebf1dd,e5e0ec,dbeef3,fdeada,' +
  23490. 'd8d8d8,595959,c4bd97,8db3e2,b8cce4,e5b9b7,d7e3bc,ccc1d9,b7dde8,fbd5b5,' +
  23491. 'bfbfbf,3f3f3f,938953,548dd4,95b3d7,d99694,c3d69b,b2a2c7,92cddc,fac08f,' +
  23492. 'a5a5a5,262626,494429,17365d,366092,953734,76923c,5f497a,31859b,e36c09,' +
  23493. '7f7f7f,0c0c0c,1d1b10,0f243e,244061,632423,4f6128,3f3151,205867,974806,' +
  23494. 'c00000,ff0000,ffc000,ffff00,92d050,00b050,00b0f0,0070c0,002060,7030a0,').split(',');
  23495. function genColorPicker(noColorText,editor){
  23496. var html = '<div id="##" class="edui-colorpicker %%">' +
  23497. '<div class="edui-colorpicker-topbar edui-clearfix">' +
  23498. '<div unselectable="on" id="##_preview" class="edui-colorpicker-preview"></div>' +
  23499. '<div unselectable="on" class="edui-colorpicker-nocolor" onclick="$$._onPickNoColor(event, this);">'+ noColorText +'</div>' +
  23500. '</div>' +
  23501. '<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">' +
  23502. '<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>'+
  23503. '<tr class="edui-colorpicker-tablefirstrow" >';
  23504. for (var i=0; i<COLORS.length; i++) {
  23505. if (i && i%10 === 0) {
  23506. 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"':'')+'>';
  23507. }
  23508. 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"' +
  23509. ' data-color="#'+ COLORS[i] +'"'+
  23510. ' style="background-color:#'+ COLORS[i] +';border:solid #ccc;'+
  23511. (i<10 || i>=60?'border-width:1px;':
  23512. i>=10&&i<20?'border-width:1px 1px 0 1px;':
  23513. 'border-width:0 1px 0 1px;')+
  23514. '"' +
  23515. '></a></td>':'';
  23516. }
  23517. html += '</tr></table></div>';
  23518. return html;
  23519. }
  23520. })();
  23521. // ui/tablepicker.js
  23522. ///import core
  23523. ///import uicore
  23524. (function (){
  23525. var utils = baidu.editor.utils,
  23526. uiUtils = baidu.editor.ui.uiUtils,
  23527. UIBase = baidu.editor.ui.UIBase;
  23528. var TablePicker = baidu.editor.ui.TablePicker = function (options){
  23529. this.initOptions(options);
  23530. this.initTablePicker();
  23531. };
  23532. TablePicker.prototype = {
  23533. defaultNumRows: 10,
  23534. defaultNumCols: 10,
  23535. maxNumRows: 20,
  23536. maxNumCols: 20,
  23537. numRows: 10,
  23538. numCols: 10,
  23539. lengthOfCellSide: 22,
  23540. initTablePicker: function (){
  23541. this.initUIBase();
  23542. },
  23543. getHtmlTpl: function (){
  23544. var me = this;
  23545. return '<div id="##" class="edui-tablepicker %%">' +
  23546. '<div class="edui-tablepicker-body">' +
  23547. '<div class="edui-infoarea">' +
  23548. '<span id="##_label" class="edui-label"></span>' +
  23549. '</div>' +
  23550. '<div class="edui-pickarea"' +
  23551. ' onmousemove="$$._onMouseMove(event, this);"' +
  23552. ' onmouseover="$$._onMouseOver(event, this);"' +
  23553. ' onmouseout="$$._onMouseOut(event, this);"' +
  23554. ' onclick="$$._onClick(event, this);"' +
  23555. '>' +
  23556. '<div id="##_overlay" class="edui-overlay"></div>' +
  23557. '</div>' +
  23558. '</div>' +
  23559. '</div>';
  23560. },
  23561. _UIBase_render: UIBase.prototype.render,
  23562. render: function (holder){
  23563. this._UIBase_render(holder);
  23564. this.getDom('label').innerHTML = '0'+this.editor.getLang("t_row")+' x 0'+this.editor.getLang("t_col");
  23565. },
  23566. _track: function (numCols, numRows){
  23567. var style = this.getDom('overlay').style;
  23568. var sideLen = this.lengthOfCellSide;
  23569. style.width = numCols * sideLen + 'px';
  23570. style.height = numRows * sideLen + 'px';
  23571. var label = this.getDom('label');
  23572. label.innerHTML = numCols +this.editor.getLang("t_col")+' x ' + numRows + this.editor.getLang("t_row");
  23573. this.numCols = numCols;
  23574. this.numRows = numRows;
  23575. },
  23576. _onMouseOver: function (evt, el){
  23577. var rel = evt.relatedTarget || evt.fromElement;
  23578. if (!uiUtils.contains(el, rel) && el !== rel) {
  23579. this.getDom('label').innerHTML = '0'+this.editor.getLang("t_col")+' x 0'+this.editor.getLang("t_row");
  23580. this.getDom('overlay').style.visibility = '';
  23581. }
  23582. },
  23583. _onMouseOut: function (evt, el){
  23584. var rel = evt.relatedTarget || evt.toElement;
  23585. if (!uiUtils.contains(el, rel) && el !== rel) {
  23586. this.getDom('label').innerHTML = '0'+this.editor.getLang("t_col")+' x 0'+this.editor.getLang("t_row");
  23587. this.getDom('overlay').style.visibility = 'hidden';
  23588. }
  23589. },
  23590. _onMouseMove: function (evt, el){
  23591. var style = this.getDom('overlay').style;
  23592. var offset = uiUtils.getEventOffset(evt);
  23593. var sideLen = this.lengthOfCellSide;
  23594. var numCols = Math.ceil(offset.left / sideLen);
  23595. var numRows = Math.ceil(offset.top / sideLen);
  23596. this._track(numCols, numRows);
  23597. },
  23598. _onClick: function (){
  23599. this.fireEvent('picktable', this.numCols, this.numRows);
  23600. }
  23601. };
  23602. utils.inherits(TablePicker, UIBase);
  23603. })();
  23604. // ui/stateful.js
  23605. (function (){
  23606. var browser = baidu.editor.browser,
  23607. domUtils = baidu.editor.dom.domUtils,
  23608. uiUtils = baidu.editor.ui.uiUtils;
  23609. var TPL_STATEFUL = 'onmousedown="$$.Stateful_onMouseDown(event, this);"' +
  23610. ' onmouseup="$$.Stateful_onMouseUp(event, this);"' +
  23611. ( browser.ie ? (
  23612. ' onmouseenter="$$.Stateful_onMouseEnter(event, this);"' +
  23613. ' onmouseleave="$$.Stateful_onMouseLeave(event, this);"' )
  23614. : (
  23615. ' onmouseover="$$.Stateful_onMouseOver(event, this);"' +
  23616. ' onmouseout="$$.Stateful_onMouseOut(event, this);"' ));
  23617. baidu.editor.ui.Stateful = {
  23618. alwalysHoverable: false,
  23619. target:null,//目标元素和this指向dom不一样
  23620. Stateful_init: function (){
  23621. this._Stateful_dGetHtmlTpl = this.getHtmlTpl;
  23622. this.getHtmlTpl = this.Stateful_getHtmlTpl;
  23623. },
  23624. Stateful_getHtmlTpl: function (){
  23625. var tpl = this._Stateful_dGetHtmlTpl();
  23626. // 使用function避免$转义
  23627. return tpl.replace(/stateful/g, function (){ return TPL_STATEFUL; });
  23628. },
  23629. Stateful_onMouseEnter: function (evt, el){
  23630. this.target=el;
  23631. if (!this.isDisabled() || this.alwalysHoverable) {
  23632. this.addState('hover');
  23633. this.fireEvent('over');
  23634. }
  23635. },
  23636. Stateful_onMouseLeave: function (evt, el){
  23637. if (!this.isDisabled() || this.alwalysHoverable) {
  23638. this.removeState('hover');
  23639. this.removeState('active');
  23640. this.fireEvent('out');
  23641. }
  23642. },
  23643. Stateful_onMouseOver: function (evt, el){
  23644. var rel = evt.relatedTarget;
  23645. if (!uiUtils.contains(el, rel) && el !== rel) {
  23646. this.Stateful_onMouseEnter(evt, el);
  23647. }
  23648. },
  23649. Stateful_onMouseOut: function (evt, el){
  23650. var rel = evt.relatedTarget;
  23651. if (!uiUtils.contains(el, rel) && el !== rel) {
  23652. this.Stateful_onMouseLeave(evt, el);
  23653. }
  23654. },
  23655. Stateful_onMouseDown: function (evt, el){
  23656. if (!this.isDisabled()) {
  23657. this.addState('active');
  23658. }
  23659. },
  23660. Stateful_onMouseUp: function (evt, el){
  23661. if (!this.isDisabled()) {
  23662. this.removeState('active');
  23663. }
  23664. },
  23665. Stateful_postRender: function (){
  23666. if (this.disabled && !this.hasState('disabled')) {
  23667. this.addState('disabled');
  23668. }
  23669. },
  23670. hasState: function (state){
  23671. return domUtils.hasClass(this.getStateDom(), 'edui-state-' + state);
  23672. },
  23673. addState: function (state){
  23674. if (!this.hasState(state)) {
  23675. this.getStateDom().className += ' edui-state-' + state;
  23676. }
  23677. },
  23678. removeState: function (state){
  23679. if (this.hasState(state)) {
  23680. domUtils.removeClasses(this.getStateDom(), ['edui-state-' + state]);
  23681. }
  23682. },
  23683. getStateDom: function (){
  23684. return this.getDom('state');
  23685. },
  23686. isChecked: function (){
  23687. return this.hasState('checked');
  23688. },
  23689. setChecked: function (checked){
  23690. if (!this.isDisabled() && checked) {
  23691. this.addState('checked');
  23692. } else {
  23693. this.removeState('checked');
  23694. }
  23695. },
  23696. isDisabled: function (){
  23697. return this.hasState('disabled');
  23698. },
  23699. setDisabled: function (disabled){
  23700. if (disabled) {
  23701. this.removeState('hover');
  23702. this.removeState('checked');
  23703. this.removeState('active');
  23704. this.addState('disabled');
  23705. } else {
  23706. this.removeState('disabled');
  23707. }
  23708. }
  23709. };
  23710. })();
  23711. // ui/button.js
  23712. ///import core
  23713. ///import uicore
  23714. ///import ui/stateful.js
  23715. (function (){
  23716. var utils = baidu.editor.utils,
  23717. UIBase = baidu.editor.ui.UIBase,
  23718. Stateful = baidu.editor.ui.Stateful,
  23719. Button = baidu.editor.ui.Button = function (options){
  23720. if(options.name){
  23721. var btnName = options.name;
  23722. var cssRules = options.cssRules;
  23723. if(!options.className){
  23724. options.className = 'edui-for-' + btnName;
  23725. }
  23726. options.cssRules = '.edui-default .edui-for-'+ btnName +' .edui-icon {'+ cssRules +'}'
  23727. }
  23728. this.initOptions(options);
  23729. this.initButton();
  23730. };
  23731. Button.prototype = {
  23732. uiName: 'button',
  23733. label: '',
  23734. title: '',
  23735. showIcon: true,
  23736. showText: true,
  23737. cssRules:'',
  23738. initButton: function (){
  23739. this.initUIBase();
  23740. this.Stateful_init();
  23741. if(this.cssRules){
  23742. utils.cssRule('edui-customize-'+this.name+'-style',this.cssRules);
  23743. }
  23744. },
  23745. getHtmlTpl: function (){
  23746. return '<div id="##" class="edui-box %%">' +
  23747. '<div id="##_state" stateful>' +
  23748. '<div class="%%-wrap"><div id="##_body" unselectable="on" ' + (this.title ? 'title="' + this.title + '"' : '') +
  23749. ' class="%%-body" onmousedown="return $$._onMouseDown(event, this);" onclick="return $$._onClick(event, this);">' +
  23750. (this.showIcon ? '<div class="edui-box edui-icon"></div>' : '') +
  23751. (this.showText ? '<div class="edui-box edui-label">' + this.label + '</div>' : '') +
  23752. '</div>' +
  23753. '</div>' +
  23754. '</div></div>';
  23755. },
  23756. postRender: function (){
  23757. this.Stateful_postRender();
  23758. this.setDisabled(this.disabled)
  23759. },
  23760. _onMouseDown: function (e){
  23761. var target = e.target || e.srcElement,
  23762. tagName = target && target.tagName && target.tagName.toLowerCase();
  23763. if (tagName == 'input' || tagName == 'object' || tagName == 'object') {
  23764. return false;
  23765. }
  23766. },
  23767. _onClick: function (){
  23768. if (!this.isDisabled()) {
  23769. this.fireEvent('click');
  23770. }
  23771. },
  23772. setTitle: function(text){
  23773. var label = this.getDom('label');
  23774. label.innerHTML = text;
  23775. }
  23776. };
  23777. utils.inherits(Button, UIBase);
  23778. utils.extend(Button.prototype, Stateful);
  23779. })();
  23780. // ui/splitbutton.js
  23781. ///import core
  23782. ///import uicore
  23783. ///import ui/stateful.js
  23784. (function (){
  23785. var utils = baidu.editor.utils,
  23786. uiUtils = baidu.editor.ui.uiUtils,
  23787. domUtils = baidu.editor.dom.domUtils,
  23788. UIBase = baidu.editor.ui.UIBase,
  23789. Stateful = baidu.editor.ui.Stateful,
  23790. SplitButton = baidu.editor.ui.SplitButton = function (options){
  23791. this.initOptions(options);
  23792. this.initSplitButton();
  23793. };
  23794. SplitButton.prototype = {
  23795. popup: null,
  23796. uiName: 'splitbutton',
  23797. title: '',
  23798. initSplitButton: function (){
  23799. this.initUIBase();
  23800. this.Stateful_init();
  23801. var me = this;
  23802. if (this.popup != null) {
  23803. var popup = this.popup;
  23804. this.popup = null;
  23805. this.setPopup(popup);
  23806. }
  23807. },
  23808. _UIBase_postRender: UIBase.prototype.postRender,
  23809. postRender: function (){
  23810. this.Stateful_postRender();
  23811. this._UIBase_postRender();
  23812. },
  23813. setPopup: function (popup){
  23814. if (this.popup === popup) return;
  23815. if (this.popup != null) {
  23816. this.popup.dispose();
  23817. }
  23818. popup.addListener('show', utils.bind(this._onPopupShow, this));
  23819. popup.addListener('hide', utils.bind(this._onPopupHide, this));
  23820. popup.addListener('postrender', utils.bind(function (){
  23821. popup.getDom('body').appendChild(
  23822. uiUtils.createElementByHtml('<div id="' +
  23823. this.popup.id + '_bordereraser" class="edui-bordereraser edui-background" style="width:' +
  23824. (uiUtils.getClientRect(this.getDom()).width + 20) + 'px"></div>')
  23825. );
  23826. popup.getDom().className += ' ' + this.className;
  23827. }, this));
  23828. this.popup = popup;
  23829. },
  23830. _onPopupShow: function (){
  23831. this.addState('opened');
  23832. },
  23833. _onPopupHide: function (){
  23834. this.removeState('opened');
  23835. },
  23836. getHtmlTpl: function (){
  23837. return '<div id="##" class="edui-box %%">' +
  23838. '<div '+ (this.title ? 'title="' + this.title + '"' : '') +' id="##_state" stateful><div class="%%-body">' +
  23839. '<div id="##_button_body" class="edui-box edui-button-body" onclick="$$._onButtonClick(event, this);">' +
  23840. '<div class="edui-box edui-icon"></div>' +
  23841. '</div>' +
  23842. '<div class="edui-box edui-splitborder"></div>' +
  23843. '<div class="edui-box edui-arrow" onclick="$$._onArrowClick();"></div>' +
  23844. '</div></div></div>';
  23845. },
  23846. showPopup: function (){
  23847. // 当popup往上弹出的时候,做特殊处理
  23848. var rect = uiUtils.getClientRect(this.getDom());
  23849. rect.top -= this.popup.SHADOW_RADIUS;
  23850. rect.height += this.popup.SHADOW_RADIUS;
  23851. this.popup.showAnchorRect(rect);
  23852. },
  23853. _onArrowClick: function (event, el){
  23854. if (!this.isDisabled()) {
  23855. this.showPopup();
  23856. }
  23857. },
  23858. _onButtonClick: function (){
  23859. if (!this.isDisabled()) {
  23860. this.fireEvent('buttonclick');
  23861. }
  23862. }
  23863. };
  23864. utils.inherits(SplitButton, UIBase);
  23865. utils.extend(SplitButton.prototype, Stateful, true);
  23866. })();
  23867. // ui/colorbutton.js
  23868. ///import core
  23869. ///import uicore
  23870. ///import ui/colorpicker.js
  23871. ///import ui/popup.js
  23872. ///import ui/splitbutton.js
  23873. (function (){
  23874. var utils = baidu.editor.utils,
  23875. uiUtils = baidu.editor.ui.uiUtils,
  23876. ColorPicker = baidu.editor.ui.ColorPicker,
  23877. Popup = baidu.editor.ui.Popup,
  23878. SplitButton = baidu.editor.ui.SplitButton,
  23879. ColorButton = baidu.editor.ui.ColorButton = function (options){
  23880. this.initOptions(options);
  23881. this.initColorButton();
  23882. };
  23883. ColorButton.prototype = {
  23884. initColorButton: function (){
  23885. var me = this;
  23886. this.popup = new Popup({
  23887. content: new ColorPicker({
  23888. noColorText: me.editor.getLang("clearColor"),
  23889. editor:me.editor,
  23890. onpickcolor: function (t, color){
  23891. me._onPickColor(color);
  23892. },
  23893. onpicknocolor: function (t, color){
  23894. me._onPickNoColor(color);
  23895. }
  23896. }),
  23897. editor:me.editor
  23898. });
  23899. this.initSplitButton();
  23900. },
  23901. _SplitButton_postRender: SplitButton.prototype.postRender,
  23902. postRender: function (){
  23903. this._SplitButton_postRender();
  23904. this.getDom('button_body').appendChild(
  23905. uiUtils.createElementByHtml('<div id="' + this.id + '_colorlump" class="edui-colorlump"></div>')
  23906. );
  23907. this.getDom().className += ' edui-colorbutton';
  23908. },
  23909. setColor: function (color){
  23910. this.getDom('colorlump').style.backgroundColor = color;
  23911. this.color = color;
  23912. },
  23913. _onPickColor: function (color){
  23914. if (this.fireEvent('pickcolor', color) !== false) {
  23915. this.setColor(color);
  23916. this.popup.hide();
  23917. }
  23918. },
  23919. _onPickNoColor: function (color){
  23920. if (this.fireEvent('picknocolor') !== false) {
  23921. this.popup.hide();
  23922. }
  23923. }
  23924. };
  23925. utils.inherits(ColorButton, SplitButton);
  23926. })();
  23927. // ui/tablebutton.js
  23928. ///import core
  23929. ///import uicore
  23930. ///import ui/popup.js
  23931. ///import ui/tablepicker.js
  23932. ///import ui/splitbutton.js
  23933. (function (){
  23934. var utils = baidu.editor.utils,
  23935. Popup = baidu.editor.ui.Popup,
  23936. TablePicker = baidu.editor.ui.TablePicker,
  23937. SplitButton = baidu.editor.ui.SplitButton,
  23938. TableButton = baidu.editor.ui.TableButton = function (options){
  23939. this.initOptions(options);
  23940. this.initTableButton();
  23941. };
  23942. TableButton.prototype = {
  23943. initTableButton: function (){
  23944. var me = this;
  23945. this.popup = new Popup({
  23946. content: new TablePicker({
  23947. editor:me.editor,
  23948. onpicktable: function (t, numCols, numRows){
  23949. me._onPickTable(numCols, numRows);
  23950. }
  23951. }),
  23952. 'editor':me.editor
  23953. });
  23954. this.initSplitButton();
  23955. },
  23956. _onPickTable: function (numCols, numRows){
  23957. if (this.fireEvent('picktable', numCols, numRows) !== false) {
  23958. this.popup.hide();
  23959. }
  23960. }
  23961. };
  23962. utils.inherits(TableButton, SplitButton);
  23963. })();
  23964. // ui/autotypesetpicker.js
  23965. ///import core
  23966. ///import uicore
  23967. (function () {
  23968. var utils = baidu.editor.utils,
  23969. UIBase = baidu.editor.ui.UIBase;
  23970. var AutoTypeSetPicker = baidu.editor.ui.AutoTypeSetPicker = function (options) {
  23971. this.initOptions(options);
  23972. this.initAutoTypeSetPicker();
  23973. };
  23974. AutoTypeSetPicker.prototype = {
  23975. initAutoTypeSetPicker:function () {
  23976. this.initUIBase();
  23977. },
  23978. getHtmlTpl:function () {
  23979. var me = this.editor,
  23980. opt = me.options.autotypeset,
  23981. lang = me.getLang("autoTypeSet");
  23982. var textAlignInputName = 'textAlignValue' + me.uid,
  23983. imageBlockInputName = 'imageBlockLineValue' + me.uid,
  23984. symbolConverInputName = 'symbolConverValue' + me.uid;
  23985. return '<div id="##" class="edui-autotypesetpicker %%">' +
  23986. '<div class="edui-autotypesetpicker-body">' +
  23987. '<table >' +
  23988. '<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>' +
  23989. '<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>' +
  23990. '<tr>' +
  23991. '<td nowrap><input type="checkbox" name="textAlign" ' + (opt["textAlign"] ? "checked" : "" ) + '>' + lang.alignment + '</td>' +
  23992. '<td colspan="2" id="' + textAlignInputName + '">' +
  23993. '<input type="radio" name="'+ textAlignInputName +'" value="left" ' + ((opt["textAlign"] && opt["textAlign"] == "left") ? "checked" : "") + '>' + me.getLang("justifyleft") +
  23994. '<input type="radio" name="'+ textAlignInputName +'" value="center" ' + ((opt["textAlign"] && opt["textAlign"] == "center") ? "checked" : "") + '>' + me.getLang("justifycenter") +
  23995. '<input type="radio" name="'+ textAlignInputName +'" value="right" ' + ((opt["textAlign"] && opt["textAlign"] == "right") ? "checked" : "") + '>' + me.getLang("justifyright") +
  23996. '</td>' +
  23997. '</tr>' +
  23998. '<tr>' +
  23999. '<td nowrap><input type="checkbox" name="imageBlockLine" ' + (opt["imageBlockLine"] ? "checked" : "" ) + '>' + lang.imageFloat + '</td>' +
  24000. '<td nowrap id="'+ imageBlockInputName +'">' +
  24001. '<input type="radio" name="'+ imageBlockInputName +'" value="none" ' + ((opt["imageBlockLine"] && opt["imageBlockLine"] == "none") ? "checked" : "") + '>' + me.getLang("default") +
  24002. '<input type="radio" name="'+ imageBlockInputName +'" value="left" ' + ((opt["imageBlockLine"] && opt["imageBlockLine"] == "left") ? "checked" : "") + '>' + me.getLang("justifyleft") +
  24003. '<input type="radio" name="'+ imageBlockInputName +'" value="center" ' + ((opt["imageBlockLine"] && opt["imageBlockLine"] == "center") ? "checked" : "") + '>' + me.getLang("justifycenter") +
  24004. '<input type="radio" name="'+ imageBlockInputName +'" value="right" ' + ((opt["imageBlockLine"] && opt["imageBlockLine"] == "right") ? "checked" : "") + '>' + me.getLang("justifyright") +
  24005. '</td>' +
  24006. '</tr>' +
  24007. '<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>' +
  24008. '<tr><td nowrap colspan="3"><input type="checkbox" name="removeEmptyNode" ' + (opt["removeEmptyNode"] ? "checked" : "" ) + '>' + lang.removeHtml + '</td></tr>' +
  24009. '<tr><td nowrap colspan="3"><input type="checkbox" name="pasteFilter" ' + (opt["pasteFilter"] ? "checked" : "" ) + '>' + lang.pasteFilter + '</td></tr>' +
  24010. '<tr>' +
  24011. '<td nowrap><input type="checkbox" name="symbolConver" ' + (opt["bdc2sb"] || opt["tobdc"] ? "checked" : "" ) + '>' + lang.symbol + '</td>' +
  24012. '<td id="' + symbolConverInputName + '">' +
  24013. '<input type="radio" name="bdc" value="bdc2sb" ' + (opt["bdc2sb"] ? "checked" : "" ) + '>' + lang.bdc2sb +
  24014. '<input type="radio" name="bdc" value="tobdc" ' + (opt["tobdc"] ? "checked" : "" ) + '>' + lang.tobdc + '' +
  24015. '</td>' +
  24016. '<td nowrap align="right"><button >' + lang.run + '</button></td>' +
  24017. '</tr>' +
  24018. '</table>' +
  24019. '</div>' +
  24020. '</div>';
  24021. },
  24022. _UIBase_render:UIBase.prototype.render
  24023. };
  24024. utils.inherits(AutoTypeSetPicker, UIBase);
  24025. })();
  24026. // ui/autotypesetbutton.js
  24027. ///import core
  24028. ///import uicore
  24029. ///import ui/popup.js
  24030. ///import ui/autotypesetpicker.js
  24031. ///import ui/splitbutton.js
  24032. (function (){
  24033. var utils = baidu.editor.utils,
  24034. Popup = baidu.editor.ui.Popup,
  24035. AutoTypeSetPicker = baidu.editor.ui.AutoTypeSetPicker,
  24036. SplitButton = baidu.editor.ui.SplitButton,
  24037. AutoTypeSetButton = baidu.editor.ui.AutoTypeSetButton = function (options){
  24038. this.initOptions(options);
  24039. this.initAutoTypeSetButton();
  24040. };
  24041. function getPara(me){
  24042. var opt = {},
  24043. cont = me.getDom(),
  24044. editorId = me.editor.uid,
  24045. inputType = null,
  24046. attrName = null,
  24047. ipts = domUtils.getElementsByTagName(cont,"input");
  24048. for(var i=ipts.length-1,ipt;ipt=ipts[i--];){
  24049. inputType = ipt.getAttribute("type");
  24050. if(inputType=="checkbox"){
  24051. attrName = ipt.getAttribute("name");
  24052. opt[attrName] && delete opt[attrName];
  24053. if(ipt.checked){
  24054. var attrValue = document.getElementById( attrName + "Value" + editorId );
  24055. if(attrValue){
  24056. if(/input/ig.test(attrValue.tagName)){
  24057. opt[attrName] = attrValue.value;
  24058. } else {
  24059. var iptChilds = attrValue.getElementsByTagName("input");
  24060. for(var j=iptChilds.length-1,iptchild;iptchild=iptChilds[j--];){
  24061. if(iptchild.checked){
  24062. opt[attrName] = iptchild.value;
  24063. break;
  24064. }
  24065. }
  24066. }
  24067. } else {
  24068. opt[attrName] = true;
  24069. }
  24070. } else {
  24071. opt[attrName] = false;
  24072. }
  24073. } else {
  24074. opt[ipt.getAttribute("value")] = ipt.checked;
  24075. }
  24076. }
  24077. var selects = domUtils.getElementsByTagName(cont,"select");
  24078. for(var i=0,si;si=selects[i++];){
  24079. var attr = si.getAttribute('name');
  24080. opt[attr] = opt[attr] ? si.value : '';
  24081. }
  24082. utils.extend(me.editor.options.autotypeset,opt);
  24083. me.editor.setPreferences('autotypeset', opt);
  24084. }
  24085. AutoTypeSetButton.prototype = {
  24086. initAutoTypeSetButton: function (){
  24087. var me = this;
  24088. this.popup = new Popup({
  24089. //传入配置参数
  24090. content: new AutoTypeSetPicker({editor:me.editor}),
  24091. 'editor':me.editor,
  24092. hide : function(){
  24093. if (!this._hidden && this.getDom()) {
  24094. getPara(this);
  24095. this.getDom().style.display = 'none';
  24096. this._hidden = true;
  24097. this.fireEvent('hide');
  24098. }
  24099. }
  24100. });
  24101. var flag = 0;
  24102. this.popup.addListener('postRenderAfter',function(){
  24103. var popupUI = this;
  24104. if(flag)return;
  24105. var cont = this.getDom(),
  24106. btn = cont.getElementsByTagName('button')[0];
  24107. btn.onclick = function(){
  24108. getPara(popupUI);
  24109. me.editor.execCommand('autotypeset');
  24110. popupUI.hide()
  24111. };
  24112. domUtils.on(cont, 'click', function(e) {
  24113. var target = e.target || e.srcElement,
  24114. editorId = me.editor.uid;
  24115. if (target && target.tagName == 'INPUT') {
  24116. // 点击图片浮动的checkbox,去除对应的radio
  24117. if (target.name == 'imageBlockLine' || target.name == 'textAlign' || target.name == 'symbolConver') {
  24118. var checked = target.checked,
  24119. radioTd = document.getElementById( target.name + 'Value' + editorId),
  24120. radios = radioTd.getElementsByTagName('input'),
  24121. defalutSelect = {
  24122. 'imageBlockLine': 'none',
  24123. 'textAlign': 'left',
  24124. 'symbolConver': 'tobdc'
  24125. };
  24126. for (var i = 0; i < radios.length; i++) {
  24127. if (checked) {
  24128. if (radios[i].value == defalutSelect[target.name]) {
  24129. radios[i].checked = 'checked';
  24130. }
  24131. } else {
  24132. radios[i].checked = false;
  24133. }
  24134. }
  24135. }
  24136. // 点击radio,选中对应的checkbox
  24137. if (target.name == ('imageBlockLineValue' + editorId) || target.name == ('textAlignValue' + editorId) || target.name == 'bdc') {
  24138. var checkboxs = target.parentNode.previousSibling.getElementsByTagName('input');
  24139. checkboxs && (checkboxs[0].checked = true);
  24140. }
  24141. getPara(popupUI);
  24142. }
  24143. });
  24144. flag = 1;
  24145. });
  24146. this.initSplitButton();
  24147. }
  24148. };
  24149. utils.inherits(AutoTypeSetButton, SplitButton);
  24150. })();
  24151. // ui/cellalignpicker.js
  24152. ///import core
  24153. ///import uicore
  24154. (function () {
  24155. var utils = baidu.editor.utils,
  24156. Popup = baidu.editor.ui.Popup,
  24157. Stateful = baidu.editor.ui.Stateful,
  24158. UIBase = baidu.editor.ui.UIBase;
  24159. /**
  24160. * 该参数将新增一个参数: selected, 参数类型为一个Object, 形如{ 'align': 'center', 'valign': 'top' }, 表示单元格的初始
  24161. * 对齐状态为: 竖直居上,水平居中; 其中 align的取值为:'center', 'left', 'right'; valign的取值为: 'top', 'middle', 'bottom'
  24162. * @update 2013/4/2 hancong03@baidu.com
  24163. */
  24164. var CellAlignPicker = baidu.editor.ui.CellAlignPicker = function (options) {
  24165. this.initOptions(options);
  24166. this.initSelected();
  24167. this.initCellAlignPicker();
  24168. };
  24169. CellAlignPicker.prototype = {
  24170. //初始化选中状态, 该方法将根据传递进来的参数获取到应该选中的对齐方式图标的索引
  24171. initSelected: function(){
  24172. var status = {
  24173. valign: {
  24174. top: 0,
  24175. middle: 1,
  24176. bottom: 2
  24177. },
  24178. align: {
  24179. left: 0,
  24180. center: 1,
  24181. right: 2
  24182. },
  24183. count: 3
  24184. },
  24185. result = -1;
  24186. if( this.selected ) {
  24187. this.selectedIndex = status.valign[ this.selected.valign ] * status.count + status.align[ this.selected.align ];
  24188. }
  24189. },
  24190. initCellAlignPicker:function () {
  24191. this.initUIBase();
  24192. this.Stateful_init();
  24193. },
  24194. getHtmlTpl:function () {
  24195. var alignType = [ 'left', 'center', 'right' ],
  24196. COUNT = 9,
  24197. tempClassName = null,
  24198. tempIndex = -1,
  24199. tmpl = [];
  24200. for( var i= 0; i<COUNT; i++ ) {
  24201. tempClassName = this.selectedIndex === i ? ' class="edui-cellalign-selected" ' : '';
  24202. tempIndex = i % 3;
  24203. tempIndex === 0 && tmpl.push('<tr>');
  24204. tmpl.push( '<td index="'+ i +'" ' + tempClassName + ' stateful><div class="edui-icon edui-'+ alignType[ tempIndex ] +'"></div></td>' );
  24205. tempIndex === 2 && tmpl.push('</tr>');
  24206. }
  24207. return '<div id="##" class="edui-cellalignpicker %%">' +
  24208. '<div class="edui-cellalignpicker-body">' +
  24209. '<table onclick="$$._onClick(event);">' +
  24210. tmpl.join('') +
  24211. '</table>' +
  24212. '</div>' +
  24213. '</div>';
  24214. },
  24215. getStateDom: function (){
  24216. return this.target;
  24217. },
  24218. _onClick: function (evt){
  24219. var target= evt.target || evt.srcElement;
  24220. if(/icon/.test(target.className)){
  24221. this.items[target.parentNode.getAttribute("index")].onclick();
  24222. Popup.postHide(evt);
  24223. }
  24224. },
  24225. _UIBase_render:UIBase.prototype.render
  24226. };
  24227. utils.inherits(CellAlignPicker, UIBase);
  24228. utils.extend(CellAlignPicker.prototype, Stateful,true);
  24229. })();
  24230. // ui/pastepicker.js
  24231. ///import core
  24232. ///import uicore
  24233. (function () {
  24234. var utils = baidu.editor.utils,
  24235. Stateful = baidu.editor.ui.Stateful,
  24236. uiUtils = baidu.editor.ui.uiUtils,
  24237. UIBase = baidu.editor.ui.UIBase;
  24238. var PastePicker = baidu.editor.ui.PastePicker = function (options) {
  24239. this.initOptions(options);
  24240. this.initPastePicker();
  24241. };
  24242. PastePicker.prototype = {
  24243. initPastePicker:function () {
  24244. this.initUIBase();
  24245. this.Stateful_init();
  24246. },
  24247. getHtmlTpl:function () {
  24248. return '<div class="edui-pasteicon" onclick="$$._onClick(this)"></div>' +
  24249. '<div class="edui-pastecontainer">' +
  24250. '<div class="edui-title">' + this.editor.getLang("pasteOpt") + '</div>' +
  24251. '<div class="edui-button">' +
  24252. '<div title="' + this.editor.getLang("pasteSourceFormat") + '" onclick="$$.format(false)" stateful>' +
  24253. '<div class="edui-richtxticon"></div></div>' +
  24254. '<div title="' + this.editor.getLang("tagFormat") + '" onclick="$$.format(2)" stateful>' +
  24255. '<div class="edui-tagicon"></div></div>' +
  24256. '<div title="' + this.editor.getLang("pasteTextFormat") + '" onclick="$$.format(true)" stateful>' +
  24257. '<div class="edui-plaintxticon"></div></div>' +
  24258. '</div>' +
  24259. '</div>' +
  24260. '</div>'
  24261. },
  24262. getStateDom:function () {
  24263. return this.target;
  24264. },
  24265. format:function (param) {
  24266. this.editor.ui._isTransfer = true;
  24267. this.editor.fireEvent('pasteTransfer', param);
  24268. },
  24269. _onClick:function (cur) {
  24270. var node = domUtils.getNextDomNode(cur),
  24271. screenHt = uiUtils.getViewportRect().height,
  24272. subPop = uiUtils.getClientRect(node);
  24273. if ((subPop.top + subPop.height) > screenHt)
  24274. node.style.top = (-subPop.height - cur.offsetHeight) + "px";
  24275. else
  24276. node.style.top = "";
  24277. if (/hidden/ig.test(domUtils.getComputedStyle(node, "visibility"))) {
  24278. node.style.visibility = "visible";
  24279. domUtils.addClass(cur, "edui-state-opened");
  24280. } else {
  24281. node.style.visibility = "hidden";
  24282. domUtils.removeClasses(cur, "edui-state-opened")
  24283. }
  24284. },
  24285. _UIBase_render:UIBase.prototype.render
  24286. };
  24287. utils.inherits(PastePicker, UIBase);
  24288. utils.extend(PastePicker.prototype, Stateful, true);
  24289. })();
  24290. // ui/toolbar.js
  24291. (function (){
  24292. var utils = baidu.editor.utils,
  24293. uiUtils = baidu.editor.ui.uiUtils,
  24294. UIBase = baidu.editor.ui.UIBase,
  24295. Toolbar = baidu.editor.ui.Toolbar = function (options){
  24296. this.initOptions(options);
  24297. this.initToolbar();
  24298. };
  24299. Toolbar.prototype = {
  24300. items: null,
  24301. initToolbar: function (){
  24302. this.items = this.items || [];
  24303. this.initUIBase();
  24304. },
  24305. add: function (item,index){
  24306. if(index === undefined){
  24307. this.items.push(item);
  24308. }else{
  24309. this.items.splice(index,0,item)
  24310. }
  24311. },
  24312. getHtmlTpl: function (){
  24313. var buff = [];
  24314. for (var i=0; i<this.items.length; i++) {
  24315. buff[i] = this.items[i].renderHtml();
  24316. }
  24317. return '<div id="##" class="edui-toolbar %%" onselectstart="return false;" onmousedown="return $$._onMouseDown(event, this);">' +
  24318. buff.join('') +
  24319. '</div>'
  24320. },
  24321. postRender: function (){
  24322. var box = this.getDom();
  24323. for (var i=0; i<this.items.length; i++) {
  24324. this.items[i].postRender();
  24325. }
  24326. uiUtils.makeUnselectable(box);
  24327. },
  24328. _onMouseDown: function (e){
  24329. var target = e.target || e.srcElement,
  24330. tagName = target && target.tagName && target.tagName.toLowerCase();
  24331. if (tagName == 'input' || tagName == 'object' || tagName == 'object') {
  24332. return false;
  24333. }
  24334. }
  24335. };
  24336. utils.inherits(Toolbar, UIBase);
  24337. })();
  24338. // ui/menu.js
  24339. ///import core
  24340. ///import uicore
  24341. ///import ui\popup.js
  24342. ///import ui\stateful.js
  24343. (function () {
  24344. var utils = baidu.editor.utils,
  24345. domUtils = baidu.editor.dom.domUtils,
  24346. uiUtils = baidu.editor.ui.uiUtils,
  24347. UIBase = baidu.editor.ui.UIBase,
  24348. Popup = baidu.editor.ui.Popup,
  24349. Stateful = baidu.editor.ui.Stateful,
  24350. CellAlignPicker = baidu.editor.ui.CellAlignPicker,
  24351. Menu = baidu.editor.ui.Menu = function (options) {
  24352. this.initOptions(options);
  24353. this.initMenu();
  24354. };
  24355. var menuSeparator = {
  24356. renderHtml:function () {
  24357. return '<div class="edui-menuitem edui-menuseparator"><div class="edui-menuseparator-inner"></div></div>';
  24358. },
  24359. postRender:function () {
  24360. },
  24361. queryAutoHide:function () {
  24362. return true;
  24363. }
  24364. };
  24365. Menu.prototype = {
  24366. items:null,
  24367. uiName:'menu',
  24368. initMenu:function () {
  24369. this.items = this.items || [];
  24370. this.initPopup();
  24371. this.initItems();
  24372. },
  24373. initItems:function () {
  24374. for (var i = 0; i < this.items.length; i++) {
  24375. var item = this.items[i];
  24376. if (item == '-') {
  24377. this.items[i] = this.getSeparator();
  24378. } else if (!(item instanceof MenuItem)) {
  24379. item.editor = this.editor;
  24380. item.theme = this.editor.options.theme;
  24381. this.items[i] = this.createItem(item);
  24382. }
  24383. }
  24384. },
  24385. getSeparator:function () {
  24386. return menuSeparator;
  24387. },
  24388. createItem:function (item) {
  24389. //新增一个参数menu, 该参数存储了menuItem所对应的menu引用
  24390. item.menu = this;
  24391. return new MenuItem(item);
  24392. },
  24393. _Popup_getContentHtmlTpl:Popup.prototype.getContentHtmlTpl,
  24394. getContentHtmlTpl:function () {
  24395. if (this.items.length == 0) {
  24396. return this._Popup_getContentHtmlTpl();
  24397. }
  24398. var buff = [];
  24399. for (var i = 0; i < this.items.length; i++) {
  24400. var item = this.items[i];
  24401. buff[i] = item.renderHtml();
  24402. }
  24403. return ('<div class="%%-body">' + buff.join('') + '</div>');
  24404. },
  24405. _Popup_postRender:Popup.prototype.postRender,
  24406. postRender:function () {
  24407. var me = this;
  24408. for (var i = 0; i < this.items.length; i++) {
  24409. var item = this.items[i];
  24410. item.ownerMenu = this;
  24411. item.postRender();
  24412. }
  24413. domUtils.on(this.getDom(), 'mouseover', function (evt) {
  24414. evt = evt || event;
  24415. var rel = evt.relatedTarget || evt.fromElement;
  24416. var el = me.getDom();
  24417. if (!uiUtils.contains(el, rel) && el !== rel) {
  24418. me.fireEvent('over');
  24419. }
  24420. });
  24421. this._Popup_postRender();
  24422. },
  24423. queryAutoHide:function (el) {
  24424. if (el) {
  24425. if (uiUtils.contains(this.getDom(), el)) {
  24426. return false;
  24427. }
  24428. for (var i = 0; i < this.items.length; i++) {
  24429. var item = this.items[i];
  24430. if (item.queryAutoHide(el) === false) {
  24431. return false;
  24432. }
  24433. }
  24434. }
  24435. },
  24436. clearItems:function () {
  24437. for (var i = 0; i < this.items.length; i++) {
  24438. var item = this.items[i];
  24439. clearTimeout(item._showingTimer);
  24440. clearTimeout(item._closingTimer);
  24441. if (item.subMenu) {
  24442. item.subMenu.destroy();
  24443. }
  24444. }
  24445. this.items = [];
  24446. },
  24447. destroy:function () {
  24448. if (this.getDom()) {
  24449. domUtils.remove(this.getDom());
  24450. }
  24451. this.clearItems();
  24452. },
  24453. dispose:function () {
  24454. this.destroy();
  24455. }
  24456. };
  24457. utils.inherits(Menu, Popup);
  24458. /**
  24459. * @update 2013/04/03 hancong03 新增一个参数menu, 该参数存储了menuItem所对应的menu引用
  24460. * @type {Function}
  24461. */
  24462. var MenuItem = baidu.editor.ui.MenuItem = function (options) {
  24463. this.initOptions(options);
  24464. this.initUIBase();
  24465. this.Stateful_init();
  24466. if (this.subMenu && !(this.subMenu instanceof Menu)) {
  24467. if (options.className && options.className.indexOf("aligntd") != -1) {
  24468. var me = this;
  24469. //获取单元格对齐初始状态
  24470. this.subMenu.selected = this.editor.queryCommandValue( 'cellalignment' );
  24471. this.subMenu = new Popup({
  24472. content:new CellAlignPicker(this.subMenu),
  24473. parentMenu:me,
  24474. editor:me.editor,
  24475. destroy:function () {
  24476. if (this.getDom()) {
  24477. domUtils.remove(this.getDom());
  24478. }
  24479. }
  24480. });
  24481. this.subMenu.addListener("postRenderAfter", function () {
  24482. domUtils.on(this.getDom(), "mouseover", function () {
  24483. me.addState('opened');
  24484. });
  24485. });
  24486. } else {
  24487. this.subMenu = new Menu(this.subMenu);
  24488. }
  24489. }
  24490. };
  24491. MenuItem.prototype = {
  24492. label:'',
  24493. subMenu:null,
  24494. ownerMenu:null,
  24495. uiName:'menuitem',
  24496. alwalysHoverable:true,
  24497. getHtmlTpl:function () {
  24498. return '<div id="##" class="%%" stateful onclick="$$._onClick(event, this);">' +
  24499. '<div class="%%-body">' +
  24500. this.renderLabelHtml() +
  24501. '</div>' +
  24502. '</div>';
  24503. },
  24504. postRender:function () {
  24505. var me = this;
  24506. this.addListener('over', function () {
  24507. me.ownerMenu.fireEvent('submenuover', me);
  24508. if (me.subMenu) {
  24509. me.delayShowSubMenu();
  24510. }
  24511. });
  24512. if (this.subMenu) {
  24513. this.getDom().className += ' edui-hassubmenu';
  24514. this.subMenu.render();
  24515. this.addListener('out', function () {
  24516. me.delayHideSubMenu();
  24517. });
  24518. this.subMenu.addListener('over', function () {
  24519. clearTimeout(me._closingTimer);
  24520. me._closingTimer = null;
  24521. me.addState('opened');
  24522. });
  24523. this.ownerMenu.addListener('hide', function () {
  24524. me.hideSubMenu();
  24525. });
  24526. this.ownerMenu.addListener('submenuover', function (t, subMenu) {
  24527. if (subMenu !== me) {
  24528. me.delayHideSubMenu();
  24529. }
  24530. });
  24531. this.subMenu._bakQueryAutoHide = this.subMenu.queryAutoHide;
  24532. this.subMenu.queryAutoHide = function (el) {
  24533. if (el && uiUtils.contains(me.getDom(), el)) {
  24534. return false;
  24535. }
  24536. return this._bakQueryAutoHide(el);
  24537. };
  24538. }
  24539. this.getDom().style.tabIndex = '-1';
  24540. uiUtils.makeUnselectable(this.getDom());
  24541. this.Stateful_postRender();
  24542. },
  24543. delayShowSubMenu:function () {
  24544. var me = this;
  24545. if (!me.isDisabled()) {
  24546. me.addState('opened');
  24547. clearTimeout(me._showingTimer);
  24548. clearTimeout(me._closingTimer);
  24549. me._closingTimer = null;
  24550. me._showingTimer = setTimeout(function () {
  24551. me.showSubMenu();
  24552. }, 250);
  24553. }
  24554. },
  24555. delayHideSubMenu:function () {
  24556. var me = this;
  24557. if (!me.isDisabled()) {
  24558. me.removeState('opened');
  24559. clearTimeout(me._showingTimer);
  24560. if (!me._closingTimer) {
  24561. me._closingTimer = setTimeout(function () {
  24562. if (!me.hasState('opened')) {
  24563. me.hideSubMenu();
  24564. }
  24565. me._closingTimer = null;
  24566. }, 400);
  24567. }
  24568. }
  24569. },
  24570. renderLabelHtml:function () {
  24571. return '<div class="edui-arrow"></div>' +
  24572. '<div class="edui-box edui-icon"></div>' +
  24573. '<div class="edui-box edui-label %%-label">' + (this.label || '') + '</div>';
  24574. },
  24575. getStateDom:function () {
  24576. return this.getDom();
  24577. },
  24578. queryAutoHide:function (el) {
  24579. if (this.subMenu && this.hasState('opened')) {
  24580. return this.subMenu.queryAutoHide(el);
  24581. }
  24582. },
  24583. _onClick:function (event, this_) {
  24584. if (this.hasState('disabled')) return;
  24585. if (this.fireEvent('click', event, this_) !== false) {
  24586. if (this.subMenu) {
  24587. this.showSubMenu();
  24588. } else {
  24589. Popup.postHide(event);
  24590. }
  24591. }
  24592. },
  24593. showSubMenu:function () {
  24594. var rect = uiUtils.getClientRect(this.getDom());
  24595. rect.right -= 5;
  24596. rect.left += 2;
  24597. rect.width -= 7;
  24598. rect.top -= 4;
  24599. rect.bottom += 4;
  24600. rect.height += 8;
  24601. this.subMenu.showAnchorRect(rect, true, true);
  24602. },
  24603. hideSubMenu:function () {
  24604. this.subMenu.hide();
  24605. }
  24606. };
  24607. utils.inherits(MenuItem, UIBase);
  24608. utils.extend(MenuItem.prototype, Stateful, true);
  24609. })();
  24610. // ui/combox.js
  24611. ///import core
  24612. ///import uicore
  24613. ///import ui/menu.js
  24614. ///import ui/splitbutton.js
  24615. (function (){
  24616. // todo: menu和item提成通用list
  24617. var utils = baidu.editor.utils,
  24618. uiUtils = baidu.editor.ui.uiUtils,
  24619. Menu = baidu.editor.ui.Menu,
  24620. SplitButton = baidu.editor.ui.SplitButton,
  24621. Combox = baidu.editor.ui.Combox = function (options){
  24622. this.initOptions(options);
  24623. this.initCombox();
  24624. };
  24625. Combox.prototype = {
  24626. uiName: 'combox',
  24627. onbuttonclick:function () {
  24628. this.showPopup();
  24629. },
  24630. initCombox: function (){
  24631. var me = this;
  24632. this.items = this.items || [];
  24633. for (var i=0; i<this.items.length; i++) {
  24634. var item = this.items[i];
  24635. item.uiName = 'listitem';
  24636. item.index = i;
  24637. item.onclick = function (){
  24638. me.selectByIndex(this.index);
  24639. };
  24640. }
  24641. this.popup = new Menu({
  24642. items: this.items,
  24643. uiName: 'list',
  24644. editor:this.editor,
  24645. captureWheel: true,
  24646. combox: this
  24647. });
  24648. this.initSplitButton();
  24649. },
  24650. _SplitButton_postRender: SplitButton.prototype.postRender,
  24651. postRender: function (){
  24652. this._SplitButton_postRender();
  24653. this.setLabel(this.label || '');
  24654. this.setValue(this.initValue || '');
  24655. },
  24656. showPopup: function (){
  24657. var rect = uiUtils.getClientRect(this.getDom());
  24658. rect.top += 1;
  24659. rect.bottom -= 1;
  24660. rect.height -= 2;
  24661. this.popup.showAnchorRect(rect);
  24662. },
  24663. getValue: function (){
  24664. return this.value;
  24665. },
  24666. setValue: function (value){
  24667. var index = this.indexByValue(value);
  24668. if (index != -1) {
  24669. this.selectedIndex = index;
  24670. this.setLabel(this.items[index].label);
  24671. this.value = this.items[index].value;
  24672. } else {
  24673. this.selectedIndex = -1;
  24674. this.setLabel(this.getLabelForUnknowValue(value));
  24675. this.value = value;
  24676. }
  24677. },
  24678. setLabel: function (label){
  24679. this.getDom('button_body').innerHTML = label;
  24680. this.label = label;
  24681. },
  24682. getLabelForUnknowValue: function (value){
  24683. return value;
  24684. },
  24685. indexByValue: function (value){
  24686. for (var i=0; i<this.items.length; i++) {
  24687. if (value == this.items[i].value) {
  24688. return i;
  24689. }
  24690. }
  24691. return -1;
  24692. },
  24693. getItem: function (index){
  24694. return this.items[index];
  24695. },
  24696. selectByIndex: function (index){
  24697. if (index < this.items.length && this.fireEvent('select', index) !== false) {
  24698. this.selectedIndex = index;
  24699. this.value = this.items[index].value;
  24700. this.setLabel(this.items[index].label);
  24701. }
  24702. }
  24703. };
  24704. utils.inherits(Combox, SplitButton);
  24705. })();
  24706. // ui/dialog.js
  24707. ///import core
  24708. ///import uicore
  24709. ///import ui/mask.js
  24710. ///import ui/button.js
  24711. (function (){
  24712. var utils = baidu.editor.utils,
  24713. domUtils = baidu.editor.dom.domUtils,
  24714. uiUtils = baidu.editor.ui.uiUtils,
  24715. Mask = baidu.editor.ui.Mask,
  24716. UIBase = baidu.editor.ui.UIBase,
  24717. Button = baidu.editor.ui.Button,
  24718. Dialog = baidu.editor.ui.Dialog = function (options){
  24719. if(options.name){
  24720. var name = options.name;
  24721. var cssRules = options.cssRules;
  24722. if(!options.className){
  24723. options.className = 'edui-for-' + name;
  24724. }
  24725. if(cssRules){
  24726. options.cssRules = '.edui-default .edui-for-'+ name +' .edui-dialog-content {'+ cssRules +'}'
  24727. }
  24728. }
  24729. this.initOptions(utils.extend({
  24730. autoReset: true,
  24731. draggable: true,
  24732. onok: function (){},
  24733. oncancel: function (){},
  24734. onclose: function (t, ok){
  24735. return ok ? this.onok() : this.oncancel();
  24736. },
  24737. //是否控制dialog中的scroll事件, 默认为不阻止
  24738. holdScroll: false
  24739. },options));
  24740. this.initDialog();
  24741. };
  24742. var modalMask;
  24743. var dragMask;
  24744. var activeDialog;
  24745. Dialog.prototype = {
  24746. draggable: false,
  24747. uiName: 'dialog',
  24748. initDialog: function (){
  24749. var me = this,
  24750. theme=this.editor.options.theme;
  24751. if(this.cssRules){
  24752. utils.cssRule('edui-customize-'+this.name+'-style',this.cssRules);
  24753. }
  24754. this.initUIBase();
  24755. this.modalMask = (modalMask || (modalMask = new Mask({
  24756. className: 'edui-dialog-modalmask',
  24757. theme:theme,
  24758. onclick: function (){
  24759. activeDialog && activeDialog.close(false);
  24760. }
  24761. })));
  24762. this.dragMask = (dragMask || (dragMask = new Mask({
  24763. className: 'edui-dialog-dragmask',
  24764. theme:theme
  24765. })));
  24766. this.closeButton = new Button({
  24767. className: 'edui-dialog-closebutton',
  24768. title: me.closeDialog,
  24769. theme:theme,
  24770. onclick: function (){
  24771. me.close(false);
  24772. }
  24773. });
  24774. this.fullscreen && this.initResizeEvent();
  24775. if (this.buttons) {
  24776. for (var i=0; i<this.buttons.length; i++) {
  24777. if (!(this.buttons[i] instanceof Button)) {
  24778. this.buttons[i] = new Button(utils.extend(this.buttons[i],{
  24779. editor : this.editor
  24780. },true));
  24781. }
  24782. }
  24783. }
  24784. },
  24785. initResizeEvent: function () {
  24786. var me = this;
  24787. domUtils.on( window, "resize", function () {
  24788. if ( me._hidden || me._hidden === undefined ) {
  24789. return;
  24790. }
  24791. if ( me.__resizeTimer ) {
  24792. window.clearTimeout( me.__resizeTimer );
  24793. }
  24794. me.__resizeTimer = window.setTimeout( function () {
  24795. me.__resizeTimer = null;
  24796. var dialogWrapNode = me.getDom(),
  24797. contentNode = me.getDom('content'),
  24798. wrapRect = UE.ui.uiUtils.getClientRect( dialogWrapNode ),
  24799. contentRect = UE.ui.uiUtils.getClientRect( contentNode ),
  24800. vpRect = uiUtils.getViewportRect();
  24801. contentNode.style.width = ( vpRect.width - wrapRect.width + contentRect.width ) + "px";
  24802. contentNode.style.height = ( vpRect.height - wrapRect.height + contentRect.height ) + "px";
  24803. dialogWrapNode.style.width = vpRect.width + "px";
  24804. dialogWrapNode.style.height = vpRect.height + "px";
  24805. me.fireEvent( "resize" );
  24806. }, 100 );
  24807. } );
  24808. },
  24809. fitSize: function (){
  24810. var popBodyEl = this.getDom('body');
  24811. // if (!(baidu.editor.browser.ie && baidu.editor.browser.version == 7)) {
  24812. // uiUtils.removeStyle(popBodyEl, 'width');
  24813. // uiUtils.removeStyle(popBodyEl, 'height');
  24814. // }
  24815. var size = this.mesureSize();
  24816. popBodyEl.style.width = size.width + 'px';
  24817. popBodyEl.style.height = size.height + 'px';
  24818. return size;
  24819. },
  24820. safeSetOffset: function (offset){
  24821. var me = this;
  24822. var el = me.getDom();
  24823. var vpRect = uiUtils.getViewportRect();
  24824. var rect = uiUtils.getClientRect(el);
  24825. var left = offset.left;
  24826. if (left + rect.width > vpRect.right) {
  24827. left = vpRect.right - rect.width;
  24828. }
  24829. var top = offset.top;
  24830. if (top + rect.height > vpRect.bottom) {
  24831. top = vpRect.bottom - rect.height;
  24832. }
  24833. el.style.left = Math.max(left, 0) + 'px';
  24834. el.style.top = Math.max(top, 0) + 'px';
  24835. },
  24836. showAtCenter: function (){
  24837. var vpRect = uiUtils.getViewportRect();
  24838. if ( !this.fullscreen ) {
  24839. this.getDom().style.display = '';
  24840. var popSize = this.fitSize();
  24841. var titleHeight = this.getDom('titlebar').offsetHeight | 0;
  24842. var left = vpRect.width / 2 - popSize.width / 2;
  24843. var top = vpRect.height / 2 - (popSize.height - titleHeight) / 2 - titleHeight;
  24844. var popEl = this.getDom();
  24845. this.safeSetOffset({
  24846. left: Math.max(left | 0, 0),
  24847. top: Math.max(top | 0, 0)
  24848. });
  24849. if (!domUtils.hasClass(popEl, 'edui-state-centered')) {
  24850. popEl.className += ' edui-state-centered';
  24851. }
  24852. } else {
  24853. var dialogWrapNode = this.getDom(),
  24854. contentNode = this.getDom('content');
  24855. dialogWrapNode.style.display = "block";
  24856. var wrapRect = UE.ui.uiUtils.getClientRect( dialogWrapNode ),
  24857. contentRect = UE.ui.uiUtils.getClientRect( contentNode );
  24858. dialogWrapNode.style.left = "-100000px";
  24859. contentNode.style.width = ( vpRect.width - wrapRect.width + contentRect.width ) + "px";
  24860. contentNode.style.height = ( vpRect.height - wrapRect.height + contentRect.height ) + "px";
  24861. dialogWrapNode.style.width = vpRect.width + "px";
  24862. dialogWrapNode.style.height = vpRect.height + "px";
  24863. dialogWrapNode.style.left = 0;
  24864. //保存环境的overflow值
  24865. this._originalContext = {
  24866. html: {
  24867. overflowX: document.documentElement.style.overflowX,
  24868. overflowY: document.documentElement.style.overflowY
  24869. },
  24870. body: {
  24871. overflowX: document.body.style.overflowX,
  24872. overflowY: document.body.style.overflowY
  24873. }
  24874. };
  24875. document.documentElement.style.overflowX = 'hidden';
  24876. document.documentElement.style.overflowY = 'hidden';
  24877. document.body.style.overflowX = 'hidden';
  24878. document.body.style.overflowY = 'hidden';
  24879. }
  24880. this._show();
  24881. },
  24882. getContentHtml: function (){
  24883. var contentHtml = '';
  24884. if (typeof this.content == 'string') {
  24885. contentHtml = this.content;
  24886. } else if (this.iframeUrl) {
  24887. contentHtml = '<span id="'+ this.id +'_contmask" class="dialogcontmask"></span><iframe id="'+ this.id +
  24888. '_iframe" class="%%-iframe" height="100%" width="100%" frameborder="0" src="'+ this.iframeUrl +'"></iframe>';
  24889. }
  24890. return contentHtml;
  24891. },
  24892. getHtmlTpl: function (){
  24893. var footHtml = '';
  24894. if (this.buttons) {
  24895. var buff = [];
  24896. for (var i=0; i<this.buttons.length; i++) {
  24897. buff[i] = this.buttons[i].renderHtml();
  24898. }
  24899. footHtml = '<div class="%%-foot">' +
  24900. '<div id="##_buttons" class="%%-buttons">' + buff.join('') + '</div>' +
  24901. '</div>';
  24902. }
  24903. return '<div id="##" class="%%"><div '+ ( !this.fullscreen ? 'class="%%"' : 'class="%%-wrap edui-dialog-fullscreen-flag"' ) +'><div id="##_body" class="%%-body">' +
  24904. '<div class="%%-shadow"></div>' +
  24905. '<div id="##_titlebar" class="%%-titlebar">' +
  24906. '<div class="%%-draghandle" onmousedown="$$._onTitlebarMouseDown(event, this);">' +
  24907. '<span class="%%-caption">' + (this.title || '') + '</span>' +
  24908. '</div>' +
  24909. this.closeButton.renderHtml() +
  24910. '</div>' +
  24911. '<div id="##_content" class="%%-content">'+ ( this.autoReset ? '' : this.getContentHtml()) +'</div>' +
  24912. footHtml +
  24913. '</div></div></div>';
  24914. },
  24915. postRender: function (){
  24916. // todo: 保持居中/记住上次关闭位置选项
  24917. if (!this.modalMask.getDom()) {
  24918. this.modalMask.render();
  24919. this.modalMask.hide();
  24920. }
  24921. if (!this.dragMask.getDom()) {
  24922. this.dragMask.render();
  24923. this.dragMask.hide();
  24924. }
  24925. var me = this;
  24926. this.addListener('show', function (){
  24927. me.modalMask.show(this.getDom().style.zIndex - 2);
  24928. });
  24929. this.addListener('hide', function (){
  24930. me.modalMask.hide();
  24931. });
  24932. if (this.buttons) {
  24933. for (var i=0; i<this.buttons.length; i++) {
  24934. this.buttons[i].postRender();
  24935. }
  24936. }
  24937. domUtils.on(window, 'resize', function (){
  24938. setTimeout(function (){
  24939. if (!me.isHidden()) {
  24940. me.safeSetOffset(uiUtils.getClientRect(me.getDom()));
  24941. }
  24942. });
  24943. });
  24944. //hold住scroll事件,防止dialog的滚动影响页面
  24945. // if( this.holdScroll ) {
  24946. //
  24947. // if( !me.iframeUrl ) {
  24948. // domUtils.on( document.getElementById( me.id + "_iframe"), !browser.gecko ? "mousewheel" : "DOMMouseScroll", function(e){
  24949. // domUtils.preventDefault(e);
  24950. // } );
  24951. // } else {
  24952. // me.addListener('dialogafterreset', function(){
  24953. // window.setTimeout(function(){
  24954. // var iframeWindow = document.getElementById( me.id + "_iframe").contentWindow;
  24955. //
  24956. // if( browser.ie ) {
  24957. //
  24958. // var timer = window.setInterval(function(){
  24959. //
  24960. // if( iframeWindow.document && iframeWindow.document.body ) {
  24961. // window.clearInterval( timer );
  24962. // timer = null;
  24963. // domUtils.on( iframeWindow.document.body, !browser.gecko ? "mousewheel" : "DOMMouseScroll", function(e){
  24964. // domUtils.preventDefault(e);
  24965. // } );
  24966. // }
  24967. //
  24968. // }, 100);
  24969. //
  24970. // } else {
  24971. // domUtils.on( iframeWindow, !browser.gecko ? "mousewheel" : "DOMMouseScroll", function(e){
  24972. // domUtils.preventDefault(e);
  24973. // } );
  24974. // }
  24975. //
  24976. // }, 1);
  24977. // });
  24978. // }
  24979. //
  24980. // }
  24981. this._hide();
  24982. },
  24983. mesureSize: function (){
  24984. var body = this.getDom('body');
  24985. var width = uiUtils.getClientRect(this.getDom('content')).width;
  24986. var dialogBodyStyle = body.style;
  24987. dialogBodyStyle.width = width;
  24988. return uiUtils.getClientRect(body);
  24989. },
  24990. _onTitlebarMouseDown: function (evt, el){
  24991. if (this.draggable) {
  24992. var rect;
  24993. var vpRect = uiUtils.getViewportRect();
  24994. var me = this;
  24995. uiUtils.startDrag(evt, {
  24996. ondragstart: function (){
  24997. rect = uiUtils.getClientRect(me.getDom());
  24998. me.getDom('contmask').style.visibility = 'visible';
  24999. me.dragMask.show(me.getDom().style.zIndex - 1);
  25000. },
  25001. ondragmove: function (x, y){
  25002. var left = rect.left + x;
  25003. var top = rect.top + y;
  25004. me.safeSetOffset({
  25005. left: left,
  25006. top: top
  25007. });
  25008. },
  25009. ondragstop: function (){
  25010. me.getDom('contmask').style.visibility = 'hidden';
  25011. domUtils.removeClasses(me.getDom(), ['edui-state-centered']);
  25012. me.dragMask.hide();
  25013. }
  25014. });
  25015. }
  25016. },
  25017. reset: function (){
  25018. this.getDom('content').innerHTML = this.getContentHtml();
  25019. this.fireEvent('dialogafterreset');
  25020. },
  25021. _show: function (){
  25022. if (this._hidden) {
  25023. this.getDom().style.display = '';
  25024. //要高过编辑器的zindxe
  25025. this.editor.container.style.zIndex && (this.getDom().style.zIndex = this.editor.container.style.zIndex * 1 + 10);
  25026. this._hidden = false;
  25027. this.fireEvent('show');
  25028. baidu.editor.ui.uiUtils.getFixedLayer().style.zIndex = this.getDom().style.zIndex - 4;
  25029. }
  25030. },
  25031. isHidden: function (){
  25032. return this._hidden;
  25033. },
  25034. _hide: function (){
  25035. if (!this._hidden) {
  25036. var wrapNode = this.getDom();
  25037. wrapNode.style.display = 'none';
  25038. wrapNode.style.zIndex = '';
  25039. wrapNode.style.width = '';
  25040. wrapNode.style.height = '';
  25041. this._hidden = true;
  25042. this.fireEvent('hide');
  25043. }
  25044. },
  25045. open: function (){
  25046. if (this.autoReset) {
  25047. //有可能还没有渲染
  25048. try{
  25049. this.reset();
  25050. }catch(e){
  25051. this.render();
  25052. this.open()
  25053. }
  25054. }
  25055. this.showAtCenter();
  25056. if (this.iframeUrl) {
  25057. try {
  25058. this.getDom('iframe').focus();
  25059. } catch(ex){}
  25060. }
  25061. activeDialog = this;
  25062. },
  25063. _onCloseButtonClick: function (evt, el){
  25064. this.close(false);
  25065. },
  25066. close: function (ok){
  25067. if (this.fireEvent('close', ok) !== false) {
  25068. //还原环境
  25069. if ( this.fullscreen ) {
  25070. document.documentElement.style.overflowX = this._originalContext.html.overflowX;
  25071. document.documentElement.style.overflowY = this._originalContext.html.overflowY;
  25072. document.body.style.overflowX = this._originalContext.body.overflowX;
  25073. document.body.style.overflowY = this._originalContext.body.overflowY;
  25074. delete this._originalContext;
  25075. }
  25076. this._hide();
  25077. //销毁content
  25078. var content = this.getDom('content');
  25079. var iframe = this.getDom('iframe');
  25080. if (content && iframe) {
  25081. var doc = iframe.contentDocument || iframe.contentWindow.document;
  25082. doc && (doc.body.innerHTML = '');
  25083. domUtils.remove(content);
  25084. }
  25085. }
  25086. }
  25087. };
  25088. utils.inherits(Dialog, UIBase);
  25089. })();
  25090. // ui/menubutton.js
  25091. ///import core
  25092. ///import uicore
  25093. ///import ui/menu.js
  25094. ///import ui/splitbutton.js
  25095. (function (){
  25096. var utils = baidu.editor.utils,
  25097. Menu = baidu.editor.ui.Menu,
  25098. SplitButton = baidu.editor.ui.SplitButton,
  25099. MenuButton = baidu.editor.ui.MenuButton = function (options){
  25100. this.initOptions(options);
  25101. this.initMenuButton();
  25102. };
  25103. MenuButton.prototype = {
  25104. initMenuButton: function (){
  25105. var me = this;
  25106. this.uiName = "menubutton";
  25107. this.popup = new Menu({
  25108. items: me.items,
  25109. className: me.className,
  25110. editor:me.editor
  25111. });
  25112. this.popup.addListener('show', function (){
  25113. var list = this;
  25114. for (var i=0; i<list.items.length; i++) {
  25115. list.items[i].removeState('checked');
  25116. if (list.items[i].value == me._value) {
  25117. list.items[i].addState('checked');
  25118. this.value = me._value;
  25119. }
  25120. }
  25121. });
  25122. this.initSplitButton();
  25123. },
  25124. setValue : function(value){
  25125. this._value = value;
  25126. }
  25127. };
  25128. utils.inherits(MenuButton, SplitButton);
  25129. })();
  25130. // ui/multiMenu.js
  25131. ///import core
  25132. ///import uicore
  25133. ///commands 表情
  25134. (function(){
  25135. var utils = baidu.editor.utils,
  25136. Popup = baidu.editor.ui.Popup,
  25137. SplitButton = baidu.editor.ui.SplitButton,
  25138. MultiMenuPop = baidu.editor.ui.MultiMenuPop = function(options){
  25139. this.initOptions(options);
  25140. this.initMultiMenu();
  25141. };
  25142. MultiMenuPop.prototype = {
  25143. initMultiMenu: function (){
  25144. var me = this;
  25145. this.popup = new Popup({
  25146. content: '',
  25147. editor : me.editor,
  25148. iframe_rendered: false,
  25149. onshow: function (){
  25150. if (!this.iframe_rendered) {
  25151. this.iframe_rendered = true;
  25152. this.getDom('content').innerHTML = '<iframe id="'+me.id+'_iframe" src="'+ me.iframeUrl +'" frameborder="0"></iframe>';
  25153. me.editor.container.style.zIndex && (this.getDom().style.zIndex = me.editor.container.style.zIndex * 1 + 1);
  25154. }
  25155. }
  25156. // canSideUp:false,
  25157. // canSideLeft:false
  25158. });
  25159. this.onbuttonclick = function(){
  25160. this.showPopup();
  25161. };
  25162. this.initSplitButton();
  25163. }
  25164. };
  25165. utils.inherits(MultiMenuPop, SplitButton);
  25166. })();
  25167. // ui/shortcutmenu.js
  25168. (function () {
  25169. var UI = baidu.editor.ui,
  25170. UIBase = UI.UIBase,
  25171. uiUtils = UI.uiUtils,
  25172. utils = baidu.editor.utils,
  25173. domUtils = baidu.editor.dom.domUtils;
  25174. var allMenus = [],//存储所有快捷菜单
  25175. timeID,
  25176. isSubMenuShow = false;//是否有子pop显示
  25177. var ShortCutMenu = UI.ShortCutMenu = function (options) {
  25178. this.initOptions (options);
  25179. this.initShortCutMenu ();
  25180. };
  25181. ShortCutMenu.postHide = hideAllMenu;
  25182. ShortCutMenu.prototype = {
  25183. isHidden : true ,
  25184. SPACE : 5 ,
  25185. initShortCutMenu : function () {
  25186. this.items = this.items || [];
  25187. this.initUIBase ();
  25188. this.initItems ();
  25189. this.initEvent ();
  25190. allMenus.push (this);
  25191. } ,
  25192. initEvent : function () {
  25193. var me = this,
  25194. doc = me.editor.document;
  25195. domUtils.on (doc , "mousemove" , function (e) {
  25196. if (me.isHidden === false) {
  25197. //有pop显示就不隐藏快捷菜单
  25198. if (me.getSubMenuMark () || me.eventType == "contextmenu") return;
  25199. var flag = true,
  25200. el = me.getDom (),
  25201. wt = el.offsetWidth,
  25202. ht = el.offsetHeight,
  25203. distanceX = wt / 2 + me.SPACE,//距离中心X标准
  25204. distanceY = ht / 2,//距离中心Y标准
  25205. x = Math.abs (e.screenX - me.left),//离中心距离横坐标
  25206. y = Math.abs (e.screenY - me.top);//离中心距离纵坐标
  25207. clearTimeout (timeID);
  25208. timeID = setTimeout (function () {
  25209. if (y > 0 && y < distanceY) {
  25210. me.setOpacity (el , "1");
  25211. } else if (y > distanceY && y < distanceY + 70) {
  25212. me.setOpacity (el , "0.5");
  25213. flag = false;
  25214. } else if (y > distanceY + 70 && y < distanceY + 140) {
  25215. me.hide ();
  25216. }
  25217. if (flag && x > 0 && x < distanceX) {
  25218. me.setOpacity (el , "1")
  25219. } else if (x > distanceX && x < distanceX + 70) {
  25220. me.setOpacity (el , "0.5")
  25221. } else if (x > distanceX + 70 && x < distanceX + 140) {
  25222. me.hide ();
  25223. }
  25224. });
  25225. }
  25226. });
  25227. //ie\ff下 mouseout不准
  25228. if (browser.chrome) {
  25229. domUtils.on (doc , "mouseout" , function (e) {
  25230. var relatedTgt = e.relatedTarget || e.toElement;
  25231. if (relatedTgt == null || relatedTgt.tagName == "HTML") {
  25232. me.hide ();
  25233. }
  25234. });
  25235. }
  25236. me.editor.addListener ("afterhidepop" , function () {
  25237. if (!me.isHidden) {
  25238. isSubMenuShow = true;
  25239. }
  25240. });
  25241. } ,
  25242. initItems : function () {
  25243. if (utils.isArray (this.items)) {
  25244. for (var i = 0, len = this.items.length ; i < len ; i++) {
  25245. var item = this.items[i].toLowerCase ();
  25246. if (UI[item]) {
  25247. this.items[i] = new UI[item] (this.editor);
  25248. this.items[i].className += " edui-shortcutsubmenu ";
  25249. }
  25250. }
  25251. }
  25252. } ,
  25253. setOpacity : function (el , value) {
  25254. if (browser.ie && browser.version < 9) {
  25255. el.style.filter = "alpha(opacity = " + parseFloat (value) * 100 + ");"
  25256. } else {
  25257. el.style.opacity = value;
  25258. }
  25259. } ,
  25260. getSubMenuMark : function () {
  25261. isSubMenuShow = false;
  25262. var layerEle = uiUtils.getFixedLayer ();
  25263. var list = domUtils.getElementsByTagName (layerEle , "div" , function (node) {
  25264. return domUtils.hasClass (node , "edui-shortcutsubmenu edui-popup")
  25265. });
  25266. for (var i = 0, node ; node = list[i++] ;) {
  25267. if (node.style.display != "none") {
  25268. isSubMenuShow = true;
  25269. }
  25270. }
  25271. return isSubMenuShow;
  25272. } ,
  25273. show : function (e , hasContextmenu) {
  25274. var me = this,
  25275. offset = {},
  25276. el = this.getDom (),
  25277. fixedlayer = uiUtils.getFixedLayer ();
  25278. function setPos (offset) {
  25279. if (offset.left < 0) {
  25280. offset.left = 0;
  25281. }
  25282. if (offset.top < 0) {
  25283. offset.top = 0;
  25284. }
  25285. el.style.cssText = "position:absolute;left:" + offset.left + "px;top:" + offset.top + "px;";
  25286. }
  25287. function setPosByCxtMenu (menu) {
  25288. if (!menu.tagName) {
  25289. menu = menu.getDom ();
  25290. }
  25291. offset.left = parseInt (menu.style.left);
  25292. offset.top = parseInt (menu.style.top);
  25293. offset.top -= el.offsetHeight + 15;
  25294. setPos (offset);
  25295. }
  25296. me.eventType = e.type;
  25297. el.style.cssText = "display:block;left:-9999px";
  25298. if (e.type == "contextmenu" && hasContextmenu) {
  25299. var menu = domUtils.getElementsByTagName (fixedlayer , "div" , "edui-contextmenu")[0];
  25300. if (menu) {
  25301. setPosByCxtMenu (menu)
  25302. } else {
  25303. me.editor.addListener ("aftershowcontextmenu" , function (type , menu) {
  25304. setPosByCxtMenu (menu);
  25305. });
  25306. }
  25307. } else {
  25308. offset = uiUtils.getViewportOffsetByEvent (e);
  25309. offset.top -= el.offsetHeight + me.SPACE;
  25310. offset.left += me.SPACE + 20;
  25311. setPos (offset);
  25312. me.setOpacity (el , 0.2);
  25313. }
  25314. me.isHidden = false;
  25315. me.left = e.screenX + el.offsetWidth / 2 - me.SPACE;
  25316. me.top = e.screenY - (el.offsetHeight / 2) - me.SPACE;
  25317. if (me.editor) {
  25318. el.style.zIndex = me.editor.container.style.zIndex * 1 + 10;
  25319. fixedlayer.style.zIndex = el.style.zIndex - 1;
  25320. }
  25321. } ,
  25322. hide : function () {
  25323. if (this.getDom ()) {
  25324. this.getDom ().style.display = "none";
  25325. }
  25326. this.isHidden = true;
  25327. } ,
  25328. postRender : function () {
  25329. if (utils.isArray (this.items)) {
  25330. for (var i = 0, item ; item = this.items[i++] ;) {
  25331. item.postRender ();
  25332. }
  25333. }
  25334. } ,
  25335. getHtmlTpl : function () {
  25336. var buff;
  25337. if (utils.isArray (this.items)) {
  25338. buff = [];
  25339. for (var i = 0 ; i < this.items.length ; i++) {
  25340. buff[i] = this.items[i].renderHtml ();
  25341. }
  25342. buff = buff.join ("");
  25343. } else {
  25344. buff = this.items;
  25345. }
  25346. return '<div id="##" class="%% edui-toolbar" data-src="shortcutmenu" onmousedown="return false;" onselectstart="return false;" >' +
  25347. buff +
  25348. '</div>';
  25349. }
  25350. };
  25351. utils.inherits (ShortCutMenu , UIBase);
  25352. function hideAllMenu (e) {
  25353. var tgt = e.target || e.srcElement,
  25354. cur = domUtils.findParent (tgt , function (node) {
  25355. return domUtils.hasClass (node , "edui-shortcutmenu") || domUtils.hasClass (node , "edui-popup");
  25356. } , true);
  25357. if (!cur) {
  25358. for (var i = 0, menu ; menu = allMenus[i++] ;) {
  25359. menu.hide ()
  25360. }
  25361. }
  25362. }
  25363. domUtils.on (document , 'mousedown' , function (e) {
  25364. hideAllMenu (e);
  25365. });
  25366. domUtils.on (window , 'scroll' , function (e) {
  25367. hideAllMenu (e);
  25368. });
  25369. }) ();
  25370. // ui/breakline.js
  25371. (function (){
  25372. var utils = baidu.editor.utils,
  25373. UIBase = baidu.editor.ui.UIBase,
  25374. Breakline = baidu.editor.ui.Breakline = function (options){
  25375. this.initOptions(options);
  25376. this.initSeparator();
  25377. };
  25378. Breakline.prototype = {
  25379. uiName: 'Breakline',
  25380. initSeparator: function (){
  25381. this.initUIBase();
  25382. },
  25383. getHtmlTpl: function (){
  25384. return '<br/>';
  25385. }
  25386. };
  25387. utils.inherits(Breakline, UIBase);
  25388. })();
  25389. // ui/message.js
  25390. ///import core
  25391. ///import uicore
  25392. (function () {
  25393. var utils = baidu.editor.utils,
  25394. domUtils = baidu.editor.dom.domUtils,
  25395. UIBase = baidu.editor.ui.UIBase,
  25396. Message = baidu.editor.ui.Message = function (options){
  25397. this.initOptions(options);
  25398. this.initMessage();
  25399. };
  25400. Message.prototype = {
  25401. initMessage: function (){
  25402. this.initUIBase();
  25403. },
  25404. getHtmlTpl: function (){
  25405. return '<div id="##" class="edui-message %%">' +
  25406. ' <div id="##_closer" class="edui-message-closer">×</div>' +
  25407. ' <div id="##_body" class="edui-message-body edui-message-type-info">' +
  25408. ' <iframe style="position:absolute;z-index:-1;left:0;top:0;background-color: transparent;" frameborder="0" width="100%" height="100%" src="about:blank"></iframe>' +
  25409. ' <div class="edui-shadow"></div>' +
  25410. ' <div id="##_content" class="edui-message-content">' +
  25411. ' </div>' +
  25412. ' </div>' +
  25413. '</div>';
  25414. },
  25415. reset: function(opt){
  25416. var me = this;
  25417. if (!opt.keepshow) {
  25418. clearTimeout(this.timer);
  25419. me.timer = setTimeout(function(){
  25420. me.hide();
  25421. }, opt.timeout || 4000);
  25422. }
  25423. opt.content !== undefined && me.setContent(opt.content);
  25424. opt.type !== undefined && me.setType(opt.type);
  25425. me.show();
  25426. },
  25427. postRender: function(){
  25428. var me = this,
  25429. closer = this.getDom('closer');
  25430. closer && domUtils.on(closer, 'click', function(){
  25431. me.hide();
  25432. });
  25433. },
  25434. setContent: function(content){
  25435. this.getDom('content').innerHTML = content;
  25436. },
  25437. setType: function(type){
  25438. type = type || 'info';
  25439. var body = this.getDom('body');
  25440. body.className = body.className.replace(/edui-message-type-[\w-]+/, 'edui-message-type-' + type);
  25441. },
  25442. getContent: function(){
  25443. return this.getDom('content').innerHTML;
  25444. },
  25445. getType: function(){
  25446. var arr = this.getDom('body').match(/edui-message-type-([\w-]+)/);
  25447. return arr ? arr[1]:'';
  25448. },
  25449. show: function (){
  25450. this.getDom().style.display = 'block';
  25451. },
  25452. hide: function (){
  25453. var dom = this.getDom();
  25454. if (dom) {
  25455. dom.style.display = 'none';
  25456. dom.parentNode && dom.parentNode.removeChild(dom);
  25457. }
  25458. }
  25459. };
  25460. utils.inherits(Message, UIBase);
  25461. })();
  25462. // adapter/editorui.js
  25463. //ui跟编辑器的适配層
  25464. //那个按钮弹出是dialog,是下拉筐等都是在这个js中配置
  25465. //自己写的ui也要在这里配置,放到baidu.editor.ui下边,当编辑器实例化的时候会根据ueditor.config中的toolbars找到相应的进行实例化
  25466. (function () {
  25467. var utils = baidu.editor.utils;
  25468. var editorui = baidu.editor.ui;
  25469. var _Dialog = editorui.Dialog;
  25470. editorui.buttons = {};
  25471. editorui.Dialog = function (options) {
  25472. var dialog = new _Dialog(options);
  25473. dialog.addListener('hide', function () {
  25474. if (dialog.editor) {
  25475. var editor = dialog.editor;
  25476. try {
  25477. if (browser.gecko) {
  25478. var y = editor.window.scrollY,
  25479. x = editor.window.scrollX;
  25480. editor.body.focus();
  25481. editor.window.scrollTo(x, y);
  25482. } else {
  25483. editor.focus();
  25484. }
  25485. } catch (ex) {
  25486. }
  25487. }
  25488. });
  25489. return dialog;
  25490. };
  25491. var iframeUrlMap = {
  25492. 'anchor':'~/dialogs/anchor/anchor.html',
  25493. 'insertimage':'~/dialogs/image/image.html',
  25494. 'link':'~/dialogs/link/link.html',
  25495. 'spechars':'~/dialogs/spechars/spechars.html',
  25496. 'searchreplace':'~/dialogs/searchreplace/searchreplace.html',
  25497. 'map':'~/dialogs/map/map.html',
  25498. 'gmap':'~/dialogs/gmap/gmap.html',
  25499. 'insertvideo':'~/dialogs/video/video.html',
  25500. 'help':'~/dialogs/help/help.html',
  25501. 'preview':'~/dialogs/preview/preview.html',
  25502. 'emotion':'~/dialogs/emotion/emotion.html',
  25503. 'wordimage':'~/dialogs/wordimage/wordimage.html',
  25504. 'attachment':'~/dialogs/attachment/attachment.html',
  25505. 'insertframe':'~/dialogs/insertframe/insertframe.html',
  25506. 'edittip':'~/dialogs/table/edittip.html',
  25507. 'edittable':'~/dialogs/table/edittable.html',
  25508. 'edittd':'~/dialogs/table/edittd.html',
  25509. 'webapp':'~/dialogs/webapp/webapp.html',
  25510. 'snapscreen':'~/dialogs/snapscreen/snapscreen.html',
  25511. 'scrawl':'~/dialogs/scrawl/scrawl.html',
  25512. 'music':'~/dialogs/music/music.html',
  25513. 'template':'~/dialogs/template/template.html',
  25514. 'background':'~/dialogs/background/background.html',
  25515. 'charts': '~/dialogs/charts/charts.html'
  25516. };
  25517. //为工具栏添加按钮,以下都是统一的按钮触发命令,所以写在一起
  25518. var btnCmds = ['undo', 'redo', 'formatmatch',
  25519. 'bold', 'italic', 'underline', 'fontborder', 'touppercase', 'tolowercase',
  25520. 'strikethrough', 'subscript', 'superscript', 'source', 'indent', 'outdent',
  25521. 'blockquote', 'pasteplain', 'pagebreak',
  25522. 'selectall', 'print','horizontal', 'removeformat', 'time', 'date', 'unlink',
  25523. 'insertparagraphbeforetable', 'insertrow', 'insertcol', 'mergeright', 'mergedown', 'deleterow',
  25524. 'deletecol', 'splittorows', 'splittocols', 'splittocells', 'mergecells', 'deletetable', 'drafts'];
  25525. for (var i = 0, ci; ci = btnCmds[i++];) {
  25526. ci = ci.toLowerCase();
  25527. editorui[ci] = function (cmd) {
  25528. return function (editor) {
  25529. var ui = new editorui.Button({
  25530. className:'edui-for-' + cmd,
  25531. title:editor.options.labelMap[cmd] || editor.getLang("labelMap." + cmd) || '',
  25532. onclick:function () {
  25533. editor.execCommand(cmd);
  25534. },
  25535. theme:editor.options.theme,
  25536. showText:false
  25537. });
  25538. editorui.buttons[cmd] = ui;
  25539. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25540. var state = editor.queryCommandState(cmd);
  25541. if (state == -1) {
  25542. ui.setDisabled(true);
  25543. ui.setChecked(false);
  25544. } else {
  25545. if (!uiReady) {
  25546. ui.setDisabled(false);
  25547. ui.setChecked(state);
  25548. }
  25549. }
  25550. });
  25551. return ui;
  25552. };
  25553. }(ci);
  25554. }
  25555. //清除文档
  25556. editorui.cleardoc = function (editor) {
  25557. var ui = new editorui.Button({
  25558. className:'edui-for-cleardoc',
  25559. title:editor.options.labelMap.cleardoc || editor.getLang("labelMap.cleardoc") || '',
  25560. theme:editor.options.theme,
  25561. onclick:function () {
  25562. if (confirm(editor.getLang("confirmClear"))) {
  25563. editor.execCommand('cleardoc');
  25564. }
  25565. }
  25566. });
  25567. editorui.buttons["cleardoc"] = ui;
  25568. editor.addListener('selectionchange', function () {
  25569. ui.setDisabled(editor.queryCommandState('cleardoc') == -1);
  25570. });
  25571. return ui;
  25572. };
  25573. //排版,图片排版,文字方向
  25574. var typeset = {
  25575. 'justify':['left', 'right', 'center', 'justify'],
  25576. 'imagefloat':['none', 'left', 'center', 'right'],
  25577. 'directionality':['ltr', 'rtl']
  25578. };
  25579. for (var p in typeset) {
  25580. (function (cmd, val) {
  25581. for (var i = 0, ci; ci = val[i++];) {
  25582. (function (cmd2) {
  25583. editorui[cmd.replace('float', '') + cmd2] = function (editor) {
  25584. var ui = new editorui.Button({
  25585. className:'edui-for-' + cmd.replace('float', '') + cmd2,
  25586. title:editor.options.labelMap[cmd.replace('float', '') + cmd2] || editor.getLang("labelMap." + cmd.replace('float', '') + cmd2) || '',
  25587. theme:editor.options.theme,
  25588. onclick:function () {
  25589. editor.execCommand(cmd, cmd2);
  25590. }
  25591. });
  25592. editorui.buttons[cmd] = ui;
  25593. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25594. ui.setDisabled(editor.queryCommandState(cmd) == -1);
  25595. ui.setChecked(editor.queryCommandValue(cmd) == cmd2 && !uiReady);
  25596. });
  25597. return ui;
  25598. };
  25599. })(ci)
  25600. }
  25601. })(p, typeset[p])
  25602. }
  25603. //字体颜色和背景颜色
  25604. for (var i = 0, ci; ci = ['backcolor', 'forecolor'][i++];) {
  25605. editorui[ci] = function (cmd) {
  25606. return function (editor) {
  25607. var ui = new editorui.ColorButton({
  25608. className:'edui-for-' + cmd,
  25609. color:'default',
  25610. title:editor.options.labelMap[cmd] || editor.getLang("labelMap." + cmd) || '',
  25611. editor:editor,
  25612. onpickcolor:function (t, color) {
  25613. editor.execCommand(cmd, color);
  25614. },
  25615. onpicknocolor:function () {
  25616. editor.execCommand(cmd, 'default');
  25617. this.setColor('transparent');
  25618. this.color = 'default';
  25619. },
  25620. onbuttonclick:function () {
  25621. editor.execCommand(cmd, this.color);
  25622. }
  25623. });
  25624. editorui.buttons[cmd] = ui;
  25625. editor.addListener('selectionchange', function () {
  25626. ui.setDisabled(editor.queryCommandState(cmd) == -1);
  25627. });
  25628. return ui;
  25629. };
  25630. }(ci);
  25631. }
  25632. var dialogBtns = {
  25633. noOk:['searchreplace', 'help', 'spechars', 'webapp','preview'],
  25634. ok:['attachment', 'anchor', 'link', 'insertimage', 'map', 'gmap', 'insertframe', 'wordimage',
  25635. 'insertvideo', 'insertframe', 'edittip', 'edittable', 'edittd', 'scrawl', 'template', 'music', 'background', 'charts']
  25636. };
  25637. for (var p in dialogBtns) {
  25638. (function (type, vals) {
  25639. for (var i = 0, ci; ci = vals[i++];) {
  25640. //todo opera下存在问题
  25641. if (browser.opera && ci === "searchreplace") {
  25642. continue;
  25643. }
  25644. (function (cmd) {
  25645. editorui[cmd] = function (editor, iframeUrl, title) {
  25646. iframeUrl = iframeUrl || (editor.options.iframeUrlMap || {})[cmd] || iframeUrlMap[cmd];
  25647. title = editor.options.labelMap[cmd] || editor.getLang("labelMap." + cmd) || '';
  25648. var dialog;
  25649. //没有iframeUrl不创建dialog
  25650. if (iframeUrl) {
  25651. dialog = new editorui.Dialog(utils.extend({
  25652. iframeUrl:editor.ui.mapUrl(iframeUrl),
  25653. editor:editor,
  25654. className:'edui-for-' + cmd,
  25655. title:title,
  25656. holdScroll: cmd === 'insertimage',
  25657. fullscreen: /charts|preview/.test(cmd),
  25658. closeDialog:editor.getLang("closeDialog")
  25659. }, type == 'ok' ? {
  25660. buttons:[
  25661. {
  25662. className:'edui-okbutton',
  25663. label:editor.getLang("ok"),
  25664. editor:editor,
  25665. onclick:function () {
  25666. dialog.close(true);
  25667. }
  25668. },
  25669. {
  25670. className:'edui-cancelbutton',
  25671. label:editor.getLang("cancel"),
  25672. editor:editor,
  25673. onclick:function () {
  25674. dialog.close(false);
  25675. }
  25676. }
  25677. ]
  25678. } : {}));
  25679. editor.ui._dialogs[cmd + "Dialog"] = dialog;
  25680. }
  25681. var ui = new editorui.Button({
  25682. className:'edui-for-' + cmd,
  25683. title:title,
  25684. onclick:function () {
  25685. if (dialog) {
  25686. switch (cmd) {
  25687. case "wordimage":
  25688. var images = editor.execCommand("wordimage");
  25689. if (images && images.length) {
  25690. dialog.render();
  25691. dialog.open();
  25692. }
  25693. break;
  25694. case "scrawl":
  25695. if (editor.queryCommandState("scrawl") != -1) {
  25696. dialog.render();
  25697. dialog.open();
  25698. }
  25699. break;
  25700. default:
  25701. dialog.render();
  25702. dialog.open();
  25703. }
  25704. }
  25705. },
  25706. theme:editor.options.theme,
  25707. disabled:(cmd == 'scrawl' && editor.queryCommandState("scrawl") == -1) || ( cmd == 'charts' )
  25708. });
  25709. editorui.buttons[cmd] = ui;
  25710. editor.addListener('selectionchange', function () {
  25711. //只存在于右键菜单而无工具栏按钮的ui不需要检测状态
  25712. var unNeedCheckState = {'edittable':1};
  25713. if (cmd in unNeedCheckState)return;
  25714. var state = editor.queryCommandState(cmd);
  25715. if (ui.getDom()) {
  25716. ui.setDisabled(state == -1);
  25717. ui.setChecked(state);
  25718. }
  25719. });
  25720. return ui;
  25721. };
  25722. })(ci.toLowerCase())
  25723. }
  25724. })(p, dialogBtns[p]);
  25725. }
  25726. editorui.snapscreen = function (editor, iframeUrl, title) {
  25727. title = editor.options.labelMap['snapscreen'] || editor.getLang("labelMap.snapscreen") || '';
  25728. var ui = new editorui.Button({
  25729. className:'edui-for-snapscreen',
  25730. title:title,
  25731. onclick:function () {
  25732. editor.execCommand("snapscreen");
  25733. },
  25734. theme:editor.options.theme
  25735. });
  25736. editorui.buttons['snapscreen'] = ui;
  25737. iframeUrl = iframeUrl || (editor.options.iframeUrlMap || {})["snapscreen"] || iframeUrlMap["snapscreen"];
  25738. if (iframeUrl) {
  25739. var dialog = new editorui.Dialog({
  25740. iframeUrl:editor.ui.mapUrl(iframeUrl),
  25741. editor:editor,
  25742. className:'edui-for-snapscreen',
  25743. title:title,
  25744. buttons:[
  25745. {
  25746. className:'edui-okbutton',
  25747. label:editor.getLang("ok"),
  25748. editor:editor,
  25749. onclick:function () {
  25750. dialog.close(true);
  25751. }
  25752. },
  25753. {
  25754. className:'edui-cancelbutton',
  25755. label:editor.getLang("cancel"),
  25756. editor:editor,
  25757. onclick:function () {
  25758. dialog.close(false);
  25759. }
  25760. }
  25761. ]
  25762. });
  25763. dialog.render();
  25764. editor.ui._dialogs["snapscreenDialog"] = dialog;
  25765. }
  25766. editor.addListener('selectionchange', function () {
  25767. ui.setDisabled(editor.queryCommandState('snapscreen') == -1);
  25768. });
  25769. return ui;
  25770. };
  25771. editorui.insertcode = function (editor, list, title) {
  25772. list = editor.options['insertcode'] || [];
  25773. title = editor.options.labelMap['insertcode'] || editor.getLang("labelMap.insertcode") || '';
  25774. // if (!list.length) return;
  25775. var items = [];
  25776. utils.each(list,function(key,val){
  25777. items.push({
  25778. label:key,
  25779. value:val,
  25780. theme:editor.options.theme,
  25781. renderLabelHtml:function () {
  25782. return '<div class="edui-label %%-label" >' + (this.label || '') + '</div>';
  25783. }
  25784. });
  25785. });
  25786. var ui = new editorui.Combox({
  25787. editor:editor,
  25788. items:items,
  25789. onselect:function (t, index) {
  25790. editor.execCommand('insertcode', this.items[index].value);
  25791. },
  25792. onbuttonclick:function () {
  25793. this.showPopup();
  25794. },
  25795. title:title,
  25796. initValue:title,
  25797. className:'edui-for-insertcode',
  25798. indexByValue:function (value) {
  25799. if (value) {
  25800. for (var i = 0, ci; ci = this.items[i]; i++) {
  25801. if (ci.value.indexOf(value) != -1)
  25802. return i;
  25803. }
  25804. }
  25805. return -1;
  25806. }
  25807. });
  25808. editorui.buttons['insertcode'] = ui;
  25809. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25810. if (!uiReady) {
  25811. var state = editor.queryCommandState('insertcode');
  25812. if (state == -1) {
  25813. ui.setDisabled(true);
  25814. } else {
  25815. ui.setDisabled(false);
  25816. var value = editor.queryCommandValue('insertcode');
  25817. if(!value){
  25818. ui.setValue(title);
  25819. return;
  25820. }
  25821. //trace:1871 ie下从源码模式切换回来时,字体会带单引号,而且会有逗号
  25822. value && (value = value.replace(/['"]/g, '').split(',')[0]);
  25823. ui.setValue(value);
  25824. }
  25825. }
  25826. });
  25827. return ui;
  25828. };
  25829. editorui.fontfamily = function (editor, list, title) {
  25830. list = editor.options['fontfamily'] || [];
  25831. title = editor.options.labelMap['fontfamily'] || editor.getLang("labelMap.fontfamily") || '';
  25832. if (!list.length) return;
  25833. for (var i = 0, ci, items = []; ci = list[i]; i++) {
  25834. var langLabel = editor.getLang('fontfamily')[ci.name] || "";
  25835. (function (key, val) {
  25836. items.push({
  25837. label:key,
  25838. value:val,
  25839. theme:editor.options.theme,
  25840. renderLabelHtml:function () {
  25841. return '<div class="edui-label %%-label" style="font-family:' +
  25842. utils.unhtml(this.value) + '">' + (this.label || '') + '</div>';
  25843. }
  25844. });
  25845. })(ci.label || langLabel, ci.val)
  25846. }
  25847. var ui = new editorui.Combox({
  25848. editor:editor,
  25849. items:items,
  25850. onselect:function (t, index) {
  25851. editor.execCommand('FontFamily', this.items[index].value);
  25852. },
  25853. onbuttonclick:function () {
  25854. this.showPopup();
  25855. },
  25856. title:title,
  25857. initValue:title,
  25858. className:'edui-for-fontfamily',
  25859. indexByValue:function (value) {
  25860. if (value) {
  25861. for (var i = 0, ci; ci = this.items[i]; i++) {
  25862. if (ci.value.indexOf(value) != -1)
  25863. return i;
  25864. }
  25865. }
  25866. return -1;
  25867. }
  25868. });
  25869. editorui.buttons['fontfamily'] = ui;
  25870. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25871. if (!uiReady) {
  25872. var state = editor.queryCommandState('FontFamily');
  25873. if (state == -1) {
  25874. ui.setDisabled(true);
  25875. } else {
  25876. ui.setDisabled(false);
  25877. var value = editor.queryCommandValue('FontFamily');
  25878. //trace:1871 ie下从源码模式切换回来时,字体会带单引号,而且会有逗号
  25879. value && (value = value.replace(/['"]/g, '').split(',')[0]);
  25880. ui.setValue(value);
  25881. }
  25882. }
  25883. });
  25884. return ui;
  25885. };
  25886. editorui.fontsize = function (editor, list, title) {
  25887. title = editor.options.labelMap['fontsize'] || editor.getLang("labelMap.fontsize") || '';
  25888. list = list || editor.options['fontsize'] || [];
  25889. if (!list.length) return;
  25890. var items = [];
  25891. for (var i = 0; i < list.length; i++) {
  25892. var size = list[i] + 'px';
  25893. items.push({
  25894. label:size,
  25895. value:size,
  25896. theme:editor.options.theme,
  25897. renderLabelHtml:function () {
  25898. return '<div class="edui-label %%-label" style="line-height:1;font-size:' +
  25899. this.value + '">' + (this.label || '') + '</div>';
  25900. }
  25901. });
  25902. }
  25903. var ui = new editorui.Combox({
  25904. editor:editor,
  25905. items:items,
  25906. title:title,
  25907. initValue:title,
  25908. onselect:function (t, index) {
  25909. editor.execCommand('FontSize', this.items[index].value);
  25910. },
  25911. onbuttonclick:function () {
  25912. this.showPopup();
  25913. },
  25914. className:'edui-for-fontsize'
  25915. });
  25916. editorui.buttons['fontsize'] = ui;
  25917. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25918. if (!uiReady) {
  25919. var state = editor.queryCommandState('FontSize');
  25920. if (state == -1) {
  25921. ui.setDisabled(true);
  25922. } else {
  25923. ui.setDisabled(false);
  25924. ui.setValue(editor.queryCommandValue('FontSize'));
  25925. }
  25926. }
  25927. });
  25928. return ui;
  25929. };
  25930. editorui.paragraph = function (editor, list, title) {
  25931. title = editor.options.labelMap['paragraph'] || editor.getLang("labelMap.paragraph") || '';
  25932. list = editor.options['paragraph'] || [];
  25933. if (utils.isEmptyObject(list)) return;
  25934. var items = [];
  25935. for (var i in list) {
  25936. items.push({
  25937. value:i,
  25938. label:list[i] || editor.getLang("paragraph")[i],
  25939. theme:editor.options.theme,
  25940. renderLabelHtml:function () {
  25941. return '<div class="edui-label %%-label"><span class="edui-for-' + this.value + '">' + (this.label || '') + '</span></div>';
  25942. }
  25943. })
  25944. }
  25945. var ui = new editorui.Combox({
  25946. editor:editor,
  25947. items:items,
  25948. title:title,
  25949. initValue:title,
  25950. className:'edui-for-paragraph',
  25951. onselect:function (t, index) {
  25952. editor.execCommand('Paragraph', this.items[index].value);
  25953. },
  25954. onbuttonclick:function () {
  25955. this.showPopup();
  25956. }
  25957. });
  25958. editorui.buttons['paragraph'] = ui;
  25959. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25960. if (!uiReady) {
  25961. var state = editor.queryCommandState('Paragraph');
  25962. if (state == -1) {
  25963. ui.setDisabled(true);
  25964. } else {
  25965. ui.setDisabled(false);
  25966. var value = editor.queryCommandValue('Paragraph');
  25967. var index = ui.indexByValue(value);
  25968. if (index != -1) {
  25969. ui.setValue(value);
  25970. } else {
  25971. ui.setValue(ui.initValue);
  25972. }
  25973. }
  25974. }
  25975. });
  25976. return ui;
  25977. };
  25978. //自定义标题
  25979. editorui.customstyle = function (editor) {
  25980. var list = editor.options['customstyle'] || [],
  25981. title = editor.options.labelMap['customstyle'] || editor.getLang("labelMap.customstyle") || '';
  25982. if (!list.length)return;
  25983. var langCs = editor.getLang('customstyle');
  25984. for (var i = 0, items = [], t; t = list[i++];) {
  25985. (function (t) {
  25986. var ck = {};
  25987. ck.label = t.label ? t.label : langCs[t.name];
  25988. ck.style = t.style;
  25989. ck.className = t.className;
  25990. ck.tag = t.tag;
  25991. items.push({
  25992. label:ck.label,
  25993. value:ck,
  25994. theme:editor.options.theme,
  25995. renderLabelHtml:function () {
  25996. return '<div class="edui-label %%-label">' + '<' + ck.tag + ' ' + (ck.className ? ' class="' + ck.className + '"' : "")
  25997. + (ck.style ? ' style="' + ck.style + '"' : "") + '>' + ck.label + "<\/" + ck.tag + ">"
  25998. + '</div>';
  25999. }
  26000. });
  26001. })(t);
  26002. }
  26003. var ui = new editorui.Combox({
  26004. editor:editor,
  26005. items:items,
  26006. title:title,
  26007. initValue:title,
  26008. className:'edui-for-customstyle',
  26009. onselect:function (t, index) {
  26010. editor.execCommand('customstyle', this.items[index].value);
  26011. },
  26012. onbuttonclick:function () {
  26013. this.showPopup();
  26014. },
  26015. indexByValue:function (value) {
  26016. for (var i = 0, ti; ti = this.items[i++];) {
  26017. if (ti.label == value) {
  26018. return i - 1
  26019. }
  26020. }
  26021. return -1;
  26022. }
  26023. });
  26024. editorui.buttons['customstyle'] = ui;
  26025. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  26026. if (!uiReady) {
  26027. var state = editor.queryCommandState('customstyle');
  26028. if (state == -1) {
  26029. ui.setDisabled(true);
  26030. } else {
  26031. ui.setDisabled(false);
  26032. var value = editor.queryCommandValue('customstyle');
  26033. var index = ui.indexByValue(value);
  26034. if (index != -1) {
  26035. ui.setValue(value);
  26036. } else {
  26037. ui.setValue(ui.initValue);
  26038. }
  26039. }
  26040. }
  26041. });
  26042. return ui;
  26043. };
  26044. editorui.inserttable = function (editor, iframeUrl, title) {
  26045. title = editor.options.labelMap['inserttable'] || editor.getLang("labelMap.inserttable") || '';
  26046. var ui = new editorui.TableButton({
  26047. editor:editor,
  26048. title:title,
  26049. className:'edui-for-inserttable',
  26050. onpicktable:function (t, numCols, numRows) {
  26051. editor.execCommand('InsertTable', {numRows:numRows, numCols:numCols, border:1});
  26052. },
  26053. onbuttonclick:function () {
  26054. this.showPopup();
  26055. }
  26056. });
  26057. editorui.buttons['inserttable'] = ui;
  26058. editor.addListener('selectionchange', function () {
  26059. ui.setDisabled(editor.queryCommandState('inserttable') == -1);
  26060. });
  26061. return ui;
  26062. };
  26063. editorui.lineheight = function (editor) {
  26064. var val = editor.options.lineheight || [];
  26065. if (!val.length)return;
  26066. for (var i = 0, ci, items = []; ci = val[i++];) {
  26067. items.push({
  26068. //todo:写死了
  26069. label:ci,
  26070. value:ci,
  26071. theme:editor.options.theme,
  26072. onclick:function () {
  26073. editor.execCommand("lineheight", this.value);
  26074. }
  26075. })
  26076. }
  26077. var ui = new editorui.MenuButton({
  26078. editor:editor,
  26079. className:'edui-for-lineheight',
  26080. title:editor.options.labelMap['lineheight'] || editor.getLang("labelMap.lineheight") || '',
  26081. items:items,
  26082. onbuttonclick:function () {
  26083. var value = editor.queryCommandValue('LineHeight') || this.value;
  26084. editor.execCommand("LineHeight", value);
  26085. }
  26086. });
  26087. editorui.buttons['lineheight'] = ui;
  26088. editor.addListener('selectionchange', function () {
  26089. var state = editor.queryCommandState('LineHeight');
  26090. if (state == -1) {
  26091. ui.setDisabled(true);
  26092. } else {
  26093. ui.setDisabled(false);
  26094. var value = editor.queryCommandValue('LineHeight');
  26095. value && ui.setValue((value + '').replace(/cm/, ''));
  26096. ui.setChecked(state)
  26097. }
  26098. });
  26099. return ui;
  26100. };
  26101. var rowspacings = ['top', 'bottom'];
  26102. for (var r = 0, ri; ri = rowspacings[r++];) {
  26103. (function (cmd) {
  26104. editorui['rowspacing' + cmd] = function (editor) {
  26105. var val = editor.options['rowspacing' + cmd] || [];
  26106. if (!val.length) return null;
  26107. for (var i = 0, ci, items = []; ci = val[i++];) {
  26108. items.push({
  26109. label:ci,
  26110. value:ci,
  26111. theme:editor.options.theme,
  26112. onclick:function () {
  26113. editor.execCommand("rowspacing", this.value, cmd);
  26114. }
  26115. })
  26116. }
  26117. var ui = new editorui.MenuButton({
  26118. editor:editor,
  26119. className:'edui-for-rowspacing' + cmd,
  26120. title:editor.options.labelMap['rowspacing' + cmd] || editor.getLang("labelMap.rowspacing" + cmd) || '',
  26121. items:items,
  26122. onbuttonclick:function () {
  26123. var value = editor.queryCommandValue('rowspacing', cmd) || this.value;
  26124. editor.execCommand("rowspacing", value, cmd);
  26125. }
  26126. });
  26127. editorui.buttons[cmd] = ui;
  26128. editor.addListener('selectionchange', function () {
  26129. var state = editor.queryCommandState('rowspacing', cmd);
  26130. if (state == -1) {
  26131. ui.setDisabled(true);
  26132. } else {
  26133. ui.setDisabled(false);
  26134. var value = editor.queryCommandValue('rowspacing', cmd);
  26135. value && ui.setValue((value + '').replace(/%/, ''));
  26136. ui.setChecked(state)
  26137. }
  26138. });
  26139. return ui;
  26140. }
  26141. })(ri)
  26142. }
  26143. //有序,无序列表
  26144. var lists = ['insertorderedlist', 'insertunorderedlist'];
  26145. for (var l = 0, cl; cl = lists[l++];) {
  26146. (function (cmd) {
  26147. editorui[cmd] = function (editor) {
  26148. var vals = editor.options[cmd],
  26149. _onMenuClick = function () {
  26150. editor.execCommand(cmd, this.value);
  26151. }, items = [];
  26152. for (var i in vals) {
  26153. items.push({
  26154. label:vals[i] || editor.getLang()[cmd][i] || "",
  26155. value:i,
  26156. theme:editor.options.theme,
  26157. onclick:_onMenuClick
  26158. })
  26159. }
  26160. var ui = new editorui.MenuButton({
  26161. editor:editor,
  26162. className:'edui-for-' + cmd,
  26163. title:editor.getLang("labelMap." + cmd) || '',
  26164. 'items':items,
  26165. onbuttonclick:function () {
  26166. var value = editor.queryCommandValue(cmd) || this.value;
  26167. editor.execCommand(cmd, value);
  26168. }
  26169. });
  26170. editorui.buttons[cmd] = ui;
  26171. editor.addListener('selectionchange', function () {
  26172. var state = editor.queryCommandState(cmd);
  26173. if (state == -1) {
  26174. ui.setDisabled(true);
  26175. } else {
  26176. ui.setDisabled(false);
  26177. var value = editor.queryCommandValue(cmd);
  26178. ui.setValue(value);
  26179. ui.setChecked(state)
  26180. }
  26181. });
  26182. return ui;
  26183. };
  26184. })(cl)
  26185. }
  26186. editorui.fullscreen = function (editor, title) {
  26187. title = editor.options.labelMap['fullscreen'] || editor.getLang("labelMap.fullscreen") || '';
  26188. var ui = new editorui.Button({
  26189. className:'edui-for-fullscreen',
  26190. title:title,
  26191. theme:editor.options.theme,
  26192. onclick:function () {
  26193. if (editor.ui) {
  26194. editor.ui.setFullScreen(!editor.ui.isFullScreen());
  26195. }
  26196. this.setChecked(editor.ui.isFullScreen());
  26197. }
  26198. });
  26199. editorui.buttons['fullscreen'] = ui;
  26200. editor.addListener('selectionchange', function () {
  26201. var state = editor.queryCommandState('fullscreen');
  26202. ui.setDisabled(state == -1);
  26203. ui.setChecked(editor.ui.isFullScreen());
  26204. });
  26205. return ui;
  26206. };
  26207. // 表情
  26208. editorui["emotion"] = function (editor, iframeUrl) {
  26209. var cmd = "emotion";
  26210. var ui = new editorui.MultiMenuPop({
  26211. title:editor.options.labelMap[cmd] || editor.getLang("labelMap." + cmd + "") || '',
  26212. editor:editor,
  26213. className:'edui-for-' + cmd,
  26214. iframeUrl:editor.ui.mapUrl(iframeUrl || (editor.options.iframeUrlMap || {})[cmd] || iframeUrlMap[cmd])
  26215. });
  26216. editorui.buttons[cmd] = ui;
  26217. editor.addListener('selectionchange', function () {
  26218. ui.setDisabled(editor.queryCommandState(cmd) == -1)
  26219. });
  26220. return ui;
  26221. };
  26222. editorui.autotypeset = function (editor) {
  26223. var ui = new editorui.AutoTypeSetButton({
  26224. editor:editor,
  26225. title:editor.options.labelMap['autotypeset'] || editor.getLang("labelMap.autotypeset") || '',
  26226. className:'edui-for-autotypeset',
  26227. onbuttonclick:function () {
  26228. editor.execCommand('autotypeset')
  26229. }
  26230. });
  26231. editorui.buttons['autotypeset'] = ui;
  26232. editor.addListener('selectionchange', function () {
  26233. ui.setDisabled(editor.queryCommandState('autotypeset') == -1);
  26234. });
  26235. return ui;
  26236. };
  26237. /* 简单上传插件 */
  26238. editorui["simpleupload"] = function (editor) {
  26239. var name = 'simpleupload',
  26240. ui = new editorui.Button({
  26241. className:'edui-for-' + name,
  26242. title:editor.options.labelMap[name] || editor.getLang("labelMap." + name) || '',
  26243. onclick:function () {},
  26244. theme:editor.options.theme,
  26245. showText:false
  26246. });
  26247. editorui.buttons[name] = ui;
  26248. editor.addListener('ready', function() {
  26249. var b = ui.getDom('body'),
  26250. iconSpan = b.children[0];
  26251. editor.fireEvent('simpleuploadbtnready', iconSpan);
  26252. });
  26253. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  26254. var state = editor.queryCommandState(name);
  26255. if (state == -1) {
  26256. ui.setDisabled(true);
  26257. ui.setChecked(false);
  26258. } else {
  26259. if (!uiReady) {
  26260. ui.setDisabled(false);
  26261. ui.setChecked(state);
  26262. }
  26263. }
  26264. });
  26265. return ui;
  26266. };
  26267. })();
  26268. // adapter/editor.js
  26269. ///import core
  26270. ///commands 全屏
  26271. ///commandsName FullScreen
  26272. ///commandsTitle 全屏
  26273. (function () {
  26274. var utils = baidu.editor.utils,
  26275. uiUtils = baidu.editor.ui.uiUtils,
  26276. UIBase = baidu.editor.ui.UIBase,
  26277. domUtils = baidu.editor.dom.domUtils;
  26278. var nodeStack = [];
  26279. function EditorUI(options) {
  26280. this.initOptions(options);
  26281. this.initEditorUI();
  26282. }
  26283. EditorUI.prototype = {
  26284. uiName:'editor',
  26285. initEditorUI:function () {
  26286. this.editor.ui = this;
  26287. this._dialogs = {};
  26288. this.initUIBase();
  26289. this._initToolbars();
  26290. var editor = this.editor,
  26291. me = this;
  26292. editor.addListener('ready', function () {
  26293. //提供getDialog方法
  26294. editor.getDialog = function (name) {
  26295. return editor.ui._dialogs[name + "Dialog"];
  26296. };
  26297. domUtils.on(editor.window, 'scroll', function (evt) {
  26298. baidu.editor.ui.Popup.postHide(evt);
  26299. });
  26300. //提供编辑器实时宽高(全屏时宽高不变化)
  26301. editor.ui._actualFrameWidth = editor.options.initialFrameWidth;
  26302. UE.browser.ie && UE.browser.version === 6 && editor.container.ownerDocument.execCommand("BackgroundImageCache", false, true);
  26303. //display bottom-bar label based on config
  26304. if (editor.options.elementPathEnabled) {
  26305. editor.ui.getDom('elementpath').innerHTML = '<div class="edui-editor-breadcrumb">' + editor.getLang("elementPathTip") + ':</div>';
  26306. }
  26307. if (editor.options.wordCount) {
  26308. function countFn() {
  26309. setCount(editor,me);
  26310. domUtils.un(editor.document, "click", arguments.callee);
  26311. }
  26312. domUtils.on(editor.document, "click", countFn);
  26313. editor.ui.getDom('wordcount').innerHTML = editor.getLang("wordCountTip");
  26314. }
  26315. editor.ui._scale();
  26316. if (editor.options.scaleEnabled) {
  26317. if (editor.autoHeightEnabled) {
  26318. editor.disableAutoHeight();
  26319. }
  26320. me.enableScale();
  26321. } else {
  26322. me.disableScale();
  26323. }
  26324. if (!editor.options.elementPathEnabled && !editor.options.wordCount && !editor.options.scaleEnabled) {
  26325. editor.ui.getDom('elementpath').style.display = "none";
  26326. editor.ui.getDom('wordcount').style.display = "none";
  26327. editor.ui.getDom('scale').style.display = "none";
  26328. }
  26329. if (!editor.selection.isFocus())return;
  26330. editor.fireEvent('selectionchange', false, true);
  26331. });
  26332. editor.addListener('mousedown', function (t, evt) {
  26333. var el = evt.target || evt.srcElement;
  26334. baidu.editor.ui.Popup.postHide(evt, el);
  26335. baidu.editor.ui.ShortCutMenu.postHide(evt);
  26336. });
  26337. editor.addListener("delcells", function () {
  26338. if (UE.ui['edittip']) {
  26339. new UE.ui['edittip'](editor);
  26340. }
  26341. editor.getDialog('edittip').open();
  26342. });
  26343. var pastePop, isPaste = false, timer;
  26344. editor.addListener("afterpaste", function () {
  26345. if(editor.queryCommandState('pasteplain'))
  26346. return;
  26347. if(baidu.editor.ui.PastePicker){
  26348. pastePop = new baidu.editor.ui.Popup({
  26349. content:new baidu.editor.ui.PastePicker({editor:editor}),
  26350. editor:editor,
  26351. className:'edui-wordpastepop'
  26352. });
  26353. pastePop.render();
  26354. }
  26355. isPaste = true;
  26356. });
  26357. editor.addListener("afterinserthtml", function () {
  26358. clearTimeout(timer);
  26359. timer = setTimeout(function () {
  26360. if (pastePop && (isPaste || editor.ui._isTransfer)) {
  26361. if(pastePop.isHidden()){
  26362. var span = domUtils.createElement(editor.document, 'span', {
  26363. 'style':"line-height:0px;",
  26364. 'innerHTML':'\ufeff'
  26365. }),
  26366. range = editor.selection.getRange();
  26367. range.insertNode(span);
  26368. var tmp= getDomNode(span, 'firstChild', 'previousSibling');
  26369. tmp && pastePop.showAnchor(tmp.nodeType == 3 ? tmp.parentNode : tmp);
  26370. domUtils.remove(span);
  26371. }else{
  26372. pastePop.show();
  26373. }
  26374. delete editor.ui._isTransfer;
  26375. isPaste = false;
  26376. }
  26377. }, 200)
  26378. });
  26379. editor.addListener('contextmenu', function (t, evt) {
  26380. baidu.editor.ui.Popup.postHide(evt);
  26381. });
  26382. editor.addListener('keydown', function (t, evt) {
  26383. if (pastePop) pastePop.dispose(evt);
  26384. var keyCode = evt.keyCode || evt.which;
  26385. if(evt.altKey&&keyCode==90){
  26386. UE.ui.buttons['fullscreen'].onclick();
  26387. }
  26388. });
  26389. editor.addListener('wordcount', function (type) {
  26390. setCount(this,me);
  26391. });
  26392. function setCount(editor,ui) {
  26393. editor.setOpt({
  26394. wordCount:true,
  26395. maximumWords:10000,
  26396. wordCountMsg:editor.options.wordCountMsg || editor.getLang("wordCountMsg"),
  26397. wordOverFlowMsg:editor.options.wordOverFlowMsg || editor.getLang("wordOverFlowMsg")
  26398. });
  26399. var opt = editor.options,
  26400. max = opt.maximumWords,
  26401. msg = opt.wordCountMsg ,
  26402. errMsg = opt.wordOverFlowMsg,
  26403. countDom = ui.getDom('wordcount');
  26404. if (!opt.wordCount) {
  26405. return;
  26406. }
  26407. var count = editor.getContentLength(true);
  26408. if (count > max) {
  26409. countDom.innerHTML = errMsg;
  26410. editor.fireEvent("wordcountoverflow");
  26411. } else {
  26412. countDom.innerHTML = msg.replace("{#leave}", max - count).replace("{#count}", count);
  26413. }
  26414. }
  26415. editor.addListener('selectionchange', function () {
  26416. if (editor.options.elementPathEnabled) {
  26417. me[(editor.queryCommandState('elementpath') == -1 ? 'dis' : 'en') + 'ableElementPath']()
  26418. }
  26419. if (editor.options.scaleEnabled) {
  26420. me[(editor.queryCommandState('scale') == -1 ? 'dis' : 'en') + 'ableScale']();
  26421. }
  26422. });
  26423. var popup = new baidu.editor.ui.Popup({
  26424. editor:editor,
  26425. content:'',
  26426. className:'edui-bubble',
  26427. _onEditButtonClick:function () {
  26428. this.hide();
  26429. editor.ui._dialogs.linkDialog.open();
  26430. },
  26431. _onImgEditButtonClick:function (name) {
  26432. this.hide();
  26433. editor.ui._dialogs[name] && editor.ui._dialogs[name].open();
  26434. },
  26435. _onImgSetFloat:function (value) {
  26436. this.hide();
  26437. editor.execCommand("imagefloat", value);
  26438. },
  26439. _setIframeAlign:function (value) {
  26440. var frame = popup.anchorEl;
  26441. var newFrame = frame.cloneNode(true);
  26442. switch (value) {
  26443. case -2:
  26444. newFrame.setAttribute("align", "");
  26445. break;
  26446. case -1:
  26447. newFrame.setAttribute("align", "left");
  26448. break;
  26449. case 1:
  26450. newFrame.setAttribute("align", "right");
  26451. break;
  26452. }
  26453. frame.parentNode.insertBefore(newFrame, frame);
  26454. domUtils.remove(frame);
  26455. popup.anchorEl = newFrame;
  26456. popup.showAnchor(popup.anchorEl);
  26457. },
  26458. _updateIframe:function () {
  26459. var frame = editor._iframe = popup.anchorEl;
  26460. if(domUtils.hasClass(frame, 'ueditor_baidumap')) {
  26461. editor.selection.getRange().selectNode(frame).select();
  26462. editor.ui._dialogs.mapDialog.open();
  26463. popup.hide();
  26464. } else {
  26465. editor.ui._dialogs.insertframeDialog.open();
  26466. popup.hide();
  26467. }
  26468. },
  26469. _onRemoveButtonClick:function (cmdName) {
  26470. editor.execCommand(cmdName);
  26471. this.hide();
  26472. },
  26473. queryAutoHide:function (el) {
  26474. if (el && el.ownerDocument == editor.document) {
  26475. if (el.tagName.toLowerCase() == 'img' || domUtils.findParentByTagName(el, 'a', true)) {
  26476. return el !== popup.anchorEl;
  26477. }
  26478. }
  26479. return baidu.editor.ui.Popup.prototype.queryAutoHide.call(this, el);
  26480. }
  26481. });
  26482. popup.render();
  26483. if (editor.options.imagePopup) {
  26484. editor.addListener('mouseover', function (t, evt) {
  26485. evt = evt || window.event;
  26486. var el = evt.target || evt.srcElement;
  26487. if (editor.ui._dialogs.insertframeDialog && /iframe/ig.test(el.tagName)) {
  26488. var html = popup.formatHtml(
  26489. '<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;' +
  26490. ' <span onclick="$$._updateIframe( this);" class="edui-clickable">' + editor.getLang("modify") + '</span></nobr>');
  26491. if (html) {
  26492. popup.getDom('content').innerHTML = html;
  26493. popup.anchorEl = el;
  26494. popup.showAnchor(popup.anchorEl);
  26495. } else {
  26496. popup.hide();
  26497. }
  26498. }
  26499. });
  26500. editor.addListener('selectionchange', function (t, causeByUi) {
  26501. if (!causeByUi) return;
  26502. var html = '', str = "",
  26503. img = editor.selection.getRange().getClosedNode(),
  26504. dialogs = editor.ui._dialogs;
  26505. if (img && img.tagName == 'IMG') {
  26506. var dialogName = 'insertimageDialog';
  26507. if (img.className.indexOf("edui-faked-video") != -1 || img.className.indexOf("edui-upload-video") != -1) {
  26508. dialogName = "insertvideoDialog"
  26509. }
  26510. if (img.className.indexOf("edui-faked-webapp") != -1) {
  26511. dialogName = "webappDialog"
  26512. }
  26513. if (img.src.indexOf("http://api.map.baidu.com") != -1) {
  26514. dialogName = "mapDialog"
  26515. }
  26516. if (img.className.indexOf("edui-faked-music") != -1) {
  26517. dialogName = "musicDialog"
  26518. }
  26519. if (img.src.indexOf("http://maps.google.com/maps/api/staticmap") != -1) {
  26520. dialogName = "gmapDialog"
  26521. }
  26522. if (img.getAttribute("anchorname")) {
  26523. dialogName = "anchorDialog";
  26524. html = popup.formatHtml(
  26525. '<nobr>' + editor.getLang("property") + ': <span onclick=$$._onImgEditButtonClick("anchorDialog") class="edui-clickable">' + editor.getLang("modify") + '</span>&nbsp;&nbsp;' +
  26526. '<span onclick=$$._onRemoveButtonClick(\'anchor\') class="edui-clickable">' + editor.getLang("delete") + '</span></nobr>');
  26527. }
  26528. if (img.getAttribute("word_img")) {
  26529. //todo 放到dialog去做查询
  26530. editor.word_img = [img.getAttribute("word_img")];
  26531. dialogName = "wordimageDialog"
  26532. }
  26533. if(domUtils.hasClass(img, 'loadingclass') || domUtils.hasClass(img, 'loaderrorclass')) {
  26534. dialogName = "";
  26535. }
  26536. if (!dialogs[dialogName]) {
  26537. return;
  26538. }
  26539. str = '<nobr>' + editor.getLang("property") + ': '+
  26540. '<span onclick=$$._onImgSetFloat("none") class="edui-clickable">' + editor.getLang("default") + '</span>&nbsp;&nbsp;' +
  26541. '<span onclick=$$._onImgSetFloat("left") class="edui-clickable">' + editor.getLang("justifyleft") + '</span>&nbsp;&nbsp;' +
  26542. '<span onclick=$$._onImgSetFloat("right") class="edui-clickable">' + editor.getLang("justifyright") + '</span>&nbsp;&nbsp;' +
  26543. '<span onclick=$$._onImgSetFloat("center") class="edui-clickable">' + editor.getLang("justifycenter") + '</span>&nbsp;&nbsp;'+
  26544. '<span onclick="$$._onImgEditButtonClick(\'' + dialogName + '\');" class="edui-clickable">' + editor.getLang("modify") + '</span></nobr>';
  26545. !html && (html = popup.formatHtml(str))
  26546. }
  26547. if (editor.ui._dialogs.linkDialog) {
  26548. var link = editor.queryCommandValue('link');
  26549. var url;
  26550. if (link && (url = (link.getAttribute('_href') || link.getAttribute('href', 2)))) {
  26551. var txt = url;
  26552. if (url.length > 30) {
  26553. txt = url.substring(0, 20) + "...";
  26554. }
  26555. if (html) {
  26556. html += '<div style="height:5px;"></div>'
  26557. }
  26558. html += popup.formatHtml(
  26559. '<nobr>' + editor.getLang("anthorMsg") + ': <a target="_blank" href="' + url + '" title="' + url + '" >' + txt + '</a>' +
  26560. ' <span class="edui-clickable" onclick="$$._onEditButtonClick();">' + editor.getLang("modify") + '</span>' +
  26561. ' <span class="edui-clickable" onclick="$$._onRemoveButtonClick(\'unlink\');"> ' + editor.getLang("clear") + '</span></nobr>');
  26562. popup.showAnchor(link);
  26563. }
  26564. }
  26565. if (html) {
  26566. popup.getDom('content').innerHTML = html;
  26567. popup.anchorEl = img || link;
  26568. popup.showAnchor(popup.anchorEl);
  26569. } else {
  26570. popup.hide();
  26571. }
  26572. });
  26573. }
  26574. },
  26575. _initToolbars:function () {
  26576. var editor = this.editor;
  26577. var toolbars = this.toolbars || [];
  26578. var toolbarUis = [];
  26579. for (var i = 0; i < toolbars.length; i++) {
  26580. var toolbar = toolbars[i];
  26581. var toolbarUi = new baidu.editor.ui.Toolbar({theme:editor.options.theme});
  26582. for (var j = 0; j < toolbar.length; j++) {
  26583. var toolbarItem = toolbar[j];
  26584. var toolbarItemUi = null;
  26585. if (typeof toolbarItem == 'string') {
  26586. toolbarItem = toolbarItem.toLowerCase();
  26587. if (toolbarItem == '|') {
  26588. toolbarItem = 'Separator';
  26589. }
  26590. if(toolbarItem == '||'){
  26591. toolbarItem = 'Breakline';
  26592. }
  26593. if (baidu.editor.ui[toolbarItem]) {
  26594. toolbarItemUi = new baidu.editor.ui[toolbarItem](editor);
  26595. }
  26596. //fullscreen这里单独处理一下,放到首行去
  26597. if (toolbarItem == 'fullscreen') {
  26598. if (toolbarUis && toolbarUis[0]) {
  26599. toolbarUis[0].items.splice(0, 0, toolbarItemUi);
  26600. } else {
  26601. toolbarItemUi && toolbarUi.items.splice(0, 0, toolbarItemUi);
  26602. }
  26603. continue;
  26604. }
  26605. } else {
  26606. toolbarItemUi = toolbarItem;
  26607. }
  26608. if (toolbarItemUi && toolbarItemUi.id) {
  26609. toolbarUi.add(toolbarItemUi);
  26610. }
  26611. }
  26612. toolbarUis[i] = toolbarUi;
  26613. }
  26614. //接受外部定制的UI
  26615. utils.each(UE._customizeUI,function(obj,key){
  26616. var itemUI,index;
  26617. if(obj.id && obj.id != editor.key){
  26618. return false;
  26619. }
  26620. itemUI = obj.execFn.call(editor,editor,key);
  26621. if(itemUI){
  26622. index = obj.index;
  26623. if(index === undefined){
  26624. index = toolbarUi.items.length;
  26625. }
  26626. toolbarUi.add(itemUI,index)
  26627. }
  26628. });
  26629. this.toolbars = toolbarUis;
  26630. },
  26631. getHtmlTpl:function () {
  26632. return '<div id="##" class="%%">' +
  26633. '<div id="##_toolbarbox" class="%%-toolbarbox">' +
  26634. (this.toolbars.length ?
  26635. '<div id="##_toolbarboxouter" class="%%-toolbarboxouter"><div class="%%-toolbarboxinner">' +
  26636. this.renderToolbarBoxHtml() +
  26637. '</div></div>' : '') +
  26638. '<div id="##_toolbarmsg" class="%%-toolbarmsg" style="display:none;">' +
  26639. '<div id = "##_upload_dialog" class="%%-toolbarmsg-upload" onclick="$$.showWordImageDialog();">' + this.editor.getLang("clickToUpload") + '</div>' +
  26640. '<div class="%%-toolbarmsg-close" onclick="$$.hideToolbarMsg();">x</div>' +
  26641. '<div id="##_toolbarmsg_label" class="%%-toolbarmsg-label"></div>' +
  26642. '<div style="height:0;overflow:hidden;clear:both;"></div>' +
  26643. '</div>' +
  26644. '<div id="##_message_holder" class="%%-messageholder"></div>' +
  26645. '</div>' +
  26646. '<div id="##_iframeholder" class="%%-iframeholder">' +
  26647. '</div>' +
  26648. //modify wdcount by matao
  26649. '<div id="##_bottombar" class="%%-bottomContainer"><table><tr>' +
  26650. '<td id="##_elementpath" class="%%-bottombar"></td>' +
  26651. '<td id="##_wordcount" class="%%-wordcount"></td>' +
  26652. '<td id="##_scale" class="%%-scale"><div class="%%-icon"></div></td>' +
  26653. '</tr></table></div>' +
  26654. '<div id="##_scalelayer"></div>' +
  26655. '</div>';
  26656. },
  26657. showWordImageDialog:function () {
  26658. this._dialogs['wordimageDialog'].open();
  26659. },
  26660. renderToolbarBoxHtml:function () {
  26661. var buff = [];
  26662. for (var i = 0; i < this.toolbars.length; i++) {
  26663. buff.push(this.toolbars[i].renderHtml());
  26664. }
  26665. return buff.join('');
  26666. },
  26667. setFullScreen:function (fullscreen) {
  26668. var editor = this.editor,
  26669. container = editor.container.parentNode.parentNode;
  26670. if (this._fullscreen != fullscreen) {
  26671. this._fullscreen = fullscreen;
  26672. this.editor.fireEvent('beforefullscreenchange', fullscreen);
  26673. if (baidu.editor.browser.gecko) {
  26674. var bk = editor.selection.getRange().createBookmark();
  26675. }
  26676. if (fullscreen) {
  26677. while (container.tagName != "BODY") {
  26678. var position = baidu.editor.dom.domUtils.getComputedStyle(container, "position");
  26679. nodeStack.push(position);
  26680. container.style.position = "static";
  26681. container = container.parentNode;
  26682. }
  26683. this._bakHtmlOverflow = document.documentElement.style.overflow;
  26684. this._bakBodyOverflow = document.body.style.overflow;
  26685. this._bakAutoHeight = this.editor.autoHeightEnabled;
  26686. this._bakScrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
  26687. this._bakEditorContaninerWidth = editor.iframe.parentNode.offsetWidth;
  26688. if (this._bakAutoHeight) {
  26689. //当全屏时不能执行自动长高
  26690. editor.autoHeightEnabled = false;
  26691. this.editor.disableAutoHeight();
  26692. }
  26693. document.documentElement.style.overflow = 'hidden';
  26694. //修复,滚动条不收起的问题
  26695. window.scrollTo(0,window.scrollY);
  26696. this._bakCssText = this.getDom().style.cssText;
  26697. this._bakCssText1 = this.getDom('iframeholder').style.cssText;
  26698. editor.iframe.parentNode.style.width = '';
  26699. this._updateFullScreen();
  26700. } else {
  26701. while (container.tagName != "BODY") {
  26702. container.style.position = nodeStack.shift();
  26703. container = container.parentNode;
  26704. }
  26705. this.getDom().style.cssText = this._bakCssText;
  26706. this.getDom('iframeholder').style.cssText = this._bakCssText1;
  26707. if (this._bakAutoHeight) {
  26708. editor.autoHeightEnabled = true;
  26709. this.editor.enableAutoHeight();
  26710. }
  26711. document.documentElement.style.overflow = this._bakHtmlOverflow;
  26712. document.body.style.overflow = this._bakBodyOverflow;
  26713. editor.iframe.parentNode.style.width = this._bakEditorContaninerWidth + 'px';
  26714. window.scrollTo(0, this._bakScrollTop);
  26715. }
  26716. if (browser.gecko && editor.body.contentEditable === 'true') {
  26717. var input = document.createElement('input');
  26718. document.body.appendChild(input);
  26719. editor.body.contentEditable = false;
  26720. setTimeout(function () {
  26721. input.focus();
  26722. setTimeout(function () {
  26723. editor.body.contentEditable = true;
  26724. editor.fireEvent('fullscreenchanged', fullscreen);
  26725. editor.selection.getRange().moveToBookmark(bk).select(true);
  26726. baidu.editor.dom.domUtils.remove(input);
  26727. fullscreen && window.scroll(0, 0);
  26728. }, 0)
  26729. }, 0)
  26730. }
  26731. if(editor.body.contentEditable === 'true'){
  26732. this.editor.fireEvent('fullscreenchanged', fullscreen);
  26733. this.triggerLayout();
  26734. }
  26735. }
  26736. },
  26737. _updateFullScreen:function () {
  26738. if (this._fullscreen) {
  26739. var vpRect = uiUtils.getViewportRect();
  26740. 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);
  26741. uiUtils.setViewportOffset(this.getDom(), { left:0, top:this.editor.options.topOffset || 0 });
  26742. this.editor.setHeight(vpRect.height - this.getDom('toolbarbox').offsetHeight - this.getDom('bottombar').offsetHeight - (this.editor.options.topOffset || 0),true);
  26743. //不手动调一下,会导致全屏失效
  26744. if(browser.gecko){
  26745. try{
  26746. window.onresize();
  26747. }catch(e){
  26748. }
  26749. }
  26750. }
  26751. },
  26752. _updateElementPath:function () {
  26753. var bottom = this.getDom('elementpath'), list;
  26754. if (this.elementPathEnabled && (list = this.editor.queryCommandValue('elementpath'))) {
  26755. var buff = [];
  26756. for (var i = 0, ci; ci = list[i]; i++) {
  26757. buff[i] = this.formatHtml('<span unselectable="on" onclick="$$.editor.execCommand(&quot;elementpath&quot;, &quot;' + i + '&quot;);">' + ci + '</span>');
  26758. }
  26759. bottom.innerHTML = '<div class="edui-editor-breadcrumb" onmousedown="return false;">' + this.editor.getLang("elementPathTip") + ': ' + buff.join(' &gt; ') + '</div>';
  26760. } else {
  26761. bottom.style.display = 'none'
  26762. }
  26763. },
  26764. disableElementPath:function () {
  26765. var bottom = this.getDom('elementpath');
  26766. bottom.innerHTML = '';
  26767. bottom.style.display = 'none';
  26768. this.elementPathEnabled = false;
  26769. },
  26770. enableElementPath:function () {
  26771. var bottom = this.getDom('elementpath');
  26772. bottom.style.display = '';
  26773. this.elementPathEnabled = true;
  26774. this._updateElementPath();
  26775. },
  26776. _scale:function () {
  26777. var doc = document,
  26778. editor = this.editor,
  26779. editorHolder = editor.container,
  26780. editorDocument = editor.document,
  26781. toolbarBox = this.getDom("toolbarbox"),
  26782. bottombar = this.getDom("bottombar"),
  26783. scale = this.getDom("scale"),
  26784. scalelayer = this.getDom("scalelayer");
  26785. var isMouseMove = false,
  26786. position = null,
  26787. minEditorHeight = 0,
  26788. minEditorWidth = editor.options.minFrameWidth,
  26789. pageX = 0,
  26790. pageY = 0,
  26791. scaleWidth = 0,
  26792. scaleHeight = 0;
  26793. function down() {
  26794. position = domUtils.getXY(editorHolder);
  26795. if (!minEditorHeight) {
  26796. minEditorHeight = editor.options.minFrameHeight + toolbarBox.offsetHeight + bottombar.offsetHeight;
  26797. }
  26798. 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:"
  26799. + editorHolder.offsetHeight + "px;z-index:" + (editor.options.zIndex + 1);
  26800. domUtils.on(doc, "mousemove", move);
  26801. domUtils.on(editorDocument, "mouseup", up);
  26802. domUtils.on(doc, "mouseup", up);
  26803. }
  26804. var me = this;
  26805. //by xuheng 全屏时关掉缩放
  26806. this.editor.addListener('fullscreenchanged', function (e, fullScreen) {
  26807. if (fullScreen) {
  26808. me.disableScale();
  26809. } else {
  26810. if (me.editor.options.scaleEnabled) {
  26811. me.enableScale();
  26812. var tmpNode = me.editor.document.createElement('span');
  26813. me.editor.body.appendChild(tmpNode);
  26814. me.editor.body.style.height = Math.max(domUtils.getXY(tmpNode).y, me.editor.iframe.offsetHeight - 20) + 'px';
  26815. domUtils.remove(tmpNode)
  26816. }
  26817. }
  26818. });
  26819. function move(event) {
  26820. clearSelection();
  26821. var e = event || window.event;
  26822. pageX = e.pageX || (doc.documentElement.scrollLeft + e.clientX);
  26823. pageY = e.pageY || (doc.documentElement.scrollTop + e.clientY);
  26824. scaleWidth = pageX - position.x;
  26825. scaleHeight = pageY - position.y;
  26826. if (scaleWidth >= minEditorWidth) {
  26827. isMouseMove = true;
  26828. scalelayer.style.width = scaleWidth + 'px';
  26829. }
  26830. if (scaleHeight >= minEditorHeight) {
  26831. isMouseMove = true;
  26832. scalelayer.style.height = scaleHeight + "px";
  26833. }
  26834. }
  26835. function up() {
  26836. if (isMouseMove) {
  26837. isMouseMove = false;
  26838. editor.ui._actualFrameWidth = scalelayer.offsetWidth - 2;
  26839. editorHolder.style.width = editor.ui._actualFrameWidth + 'px';
  26840. editor.setHeight(scalelayer.offsetHeight - bottombar.offsetHeight - toolbarBox.offsetHeight - 2,true);
  26841. }
  26842. if (scalelayer) {
  26843. scalelayer.style.display = "none";
  26844. }
  26845. clearSelection();
  26846. domUtils.un(doc, "mousemove", move);
  26847. domUtils.un(editorDocument, "mouseup", up);
  26848. domUtils.un(doc, "mouseup", up);
  26849. }
  26850. function clearSelection() {
  26851. if (browser.ie)
  26852. doc.selection.clear();
  26853. else
  26854. window.getSelection().removeAllRanges();
  26855. }
  26856. this.enableScale = function () {
  26857. //trace:2868
  26858. if (editor.queryCommandState("source") == 1) return;
  26859. scale.style.display = "";
  26860. this.scaleEnabled = true;
  26861. domUtils.on(scale, "mousedown", down);
  26862. };
  26863. this.disableScale = function () {
  26864. scale.style.display = "none";
  26865. this.scaleEnabled = false;
  26866. domUtils.un(scale, "mousedown", down);
  26867. };
  26868. },
  26869. isFullScreen:function () {
  26870. return this._fullscreen;
  26871. },
  26872. postRender:function () {
  26873. UIBase.prototype.postRender.call(this);
  26874. for (var i = 0; i < this.toolbars.length; i++) {
  26875. this.toolbars[i].postRender();
  26876. }
  26877. var me = this;
  26878. var timerId,
  26879. domUtils = baidu.editor.dom.domUtils,
  26880. updateFullScreenTime = function () {
  26881. clearTimeout(timerId);
  26882. timerId = setTimeout(function () {
  26883. me._updateFullScreen();
  26884. });
  26885. };
  26886. domUtils.on(window, 'resize', updateFullScreenTime);
  26887. me.addListener('destroy', function () {
  26888. domUtils.un(window, 'resize', updateFullScreenTime);
  26889. clearTimeout(timerId);
  26890. })
  26891. },
  26892. showToolbarMsg:function (msg, flag) {
  26893. this.getDom('toolbarmsg_label').innerHTML = msg;
  26894. this.getDom('toolbarmsg').style.display = '';
  26895. //
  26896. if (!flag) {
  26897. var w = this.getDom('upload_dialog');
  26898. w.style.display = 'none';
  26899. }
  26900. },
  26901. hideToolbarMsg:function () {
  26902. this.getDom('toolbarmsg').style.display = 'none';
  26903. },
  26904. mapUrl:function (url) {
  26905. return url ? url.replace('~/', this.editor.options.UEDITOR_HOME_URL || '') : ''
  26906. },
  26907. triggerLayout:function () {
  26908. var dom = this.getDom();
  26909. if (dom.style.zoom == '1') {
  26910. dom.style.zoom = '100%';
  26911. } else {
  26912. dom.style.zoom = '1';
  26913. }
  26914. }
  26915. };
  26916. utils.inherits(EditorUI, baidu.editor.ui.UIBase);
  26917. var instances = {};
  26918. UE.ui.Editor = function (options) {
  26919. var editor = new UE.Editor(options);
  26920. editor.options.editor = editor;
  26921. utils.loadFile(document, {
  26922. href:editor.options.themePath + editor.options.theme + "/css/ueditor.css",
  26923. tag:"link",
  26924. type:"text/css",
  26925. rel:"stylesheet"
  26926. });
  26927. var oldRender = editor.render;
  26928. editor.render = function (holder) {
  26929. if (holder.constructor === String) {
  26930. editor.key = holder;
  26931. instances[holder] = editor;
  26932. }
  26933. utils.domReady(function () {
  26934. editor.langIsReady ? renderUI() : editor.addListener("langReady", renderUI);
  26935. function renderUI() {
  26936. editor.setOpt({
  26937. labelMap:editor.options.labelMap || editor.getLang('labelMap')
  26938. });
  26939. new EditorUI(editor.options);
  26940. if (holder) {
  26941. if (holder.constructor === String) {
  26942. holder = document.getElementById(holder);
  26943. }
  26944. holder && holder.getAttribute('name') && ( editor.options.textarea = holder.getAttribute('name'));
  26945. if (holder && /script|textarea/ig.test(holder.tagName)) {
  26946. var newDiv = document.createElement('div');
  26947. holder.parentNode.insertBefore(newDiv, holder);
  26948. var cont = holder.value || holder.innerHTML;
  26949. editor.options.initialContent = /^[\t\r\n ]*$/.test(cont) ? editor.options.initialContent :
  26950. cont.replace(/>[\n\r\t]+([ ]{4})+/g, '>')
  26951. .replace(/[\n\r\t]+([ ]{4})+</g, '<')
  26952. .replace(/>[\n\r\t]+</g, '><');
  26953. holder.className && (newDiv.className = holder.className);
  26954. holder.style.cssText && (newDiv.style.cssText = holder.style.cssText);
  26955. if (/textarea/i.test(holder.tagName)) {
  26956. editor.textarea = holder;
  26957. editor.textarea.style.display = 'none';
  26958. } else {
  26959. holder.parentNode.removeChild(holder);
  26960. }
  26961. if(holder.id){
  26962. newDiv.id = holder.id;
  26963. domUtils.removeAttributes(holder,'id');
  26964. }
  26965. holder = newDiv;
  26966. holder.innerHTML = '';
  26967. }
  26968. }
  26969. domUtils.addClass(holder, "edui-" + editor.options.theme);
  26970. editor.ui.render(holder);
  26971. var opt = editor.options;
  26972. //给实例添加一个编辑器的容器引用
  26973. editor.container = editor.ui.getDom();
  26974. var parents = domUtils.findParents(holder,true);
  26975. var displays = [];
  26976. for(var i = 0 ,ci;ci=parents[i];i++){
  26977. displays[i] = ci.style.display;
  26978. ci.style.display = 'block'
  26979. }
  26980. if (opt.initialFrameWidth) {
  26981. opt.minFrameWidth = opt.initialFrameWidth;
  26982. } else {
  26983. opt.minFrameWidth = opt.initialFrameWidth = holder.offsetWidth;
  26984. var styleWidth = holder.style.width;
  26985. if(/%$/.test(styleWidth)) {
  26986. opt.initialFrameWidth = styleWidth;
  26987. }
  26988. }
  26989. if (opt.initialFrameHeight) {
  26990. opt.minFrameHeight = opt.initialFrameHeight;
  26991. } else {
  26992. opt.initialFrameHeight = opt.minFrameHeight = holder.offsetHeight;
  26993. }
  26994. for(var i = 0 ,ci;ci=parents[i];i++){
  26995. ci.style.display = displays[i]
  26996. }
  26997. //编辑器最外容器设置了高度,会导致,编辑器不占位
  26998. //todo 先去掉,没有找到原因
  26999. if(holder.style.height){
  27000. holder.style.height = ''
  27001. }
  27002. editor.container.style.width = opt.initialFrameWidth + (/%$/.test(opt.initialFrameWidth) ? '' : 'px');
  27003. editor.container.style.zIndex = opt.zIndex;
  27004. oldRender.call(editor, editor.ui.getDom('iframeholder'));
  27005. editor.fireEvent("afteruiready");
  27006. }
  27007. })
  27008. };
  27009. return editor;
  27010. };
  27011. /**
  27012. * @file
  27013. * @name UE
  27014. * @short UE
  27015. * @desc UEditor的顶部命名空间
  27016. */
  27017. /**
  27018. * @name getEditor
  27019. * @since 1.2.4+
  27020. * @grammar UE.getEditor(id,[opt]) => Editor实例
  27021. * @desc 提供一个全局的方法得到编辑器实例
  27022. *
  27023. * * ''id'' 放置编辑器的容器id, 如果容器下的编辑器已经存在,就直接返回
  27024. * * ''opt'' 编辑器的可选参数
  27025. * @example
  27026. * UE.getEditor('containerId',{onready:function(){//创建一个编辑器实例
  27027. * this.setContent('hello')
  27028. * }});
  27029. * UE.getEditor('containerId'); //返回刚创建的实例
  27030. *
  27031. */
  27032. UE.getEditor = function (id, opt) {
  27033. var editor = instances[id];
  27034. if (!editor) {
  27035. editor = instances[id] = new UE.ui.Editor(opt);
  27036. editor.render(id);
  27037. }
  27038. return editor;
  27039. };
  27040. UE.delEditor = function (id) {
  27041. var editor;
  27042. if (editor = instances[id]) {
  27043. editor.key && editor.destroy();
  27044. delete instances[id]
  27045. }
  27046. };
  27047. UE.registerUI = function(uiName,fn,index,editorId){
  27048. utils.each(uiName.split(/\s+/), function (name) {
  27049. UE._customizeUI[name] = {
  27050. id : editorId,
  27051. execFn:fn,
  27052. index:index
  27053. };
  27054. })
  27055. }
  27056. })();
  27057. // adapter/message.js
  27058. UE.registerUI('message', function(editor) {
  27059. var editorui = baidu.editor.ui;
  27060. var Message = editorui.Message;
  27061. var holder;
  27062. var _messageItems = [];
  27063. var me = editor;
  27064. me.addListener('ready', function(){
  27065. holder = document.getElementById(me.ui.id + '_message_holder');
  27066. updateHolderPos();
  27067. setTimeout(function(){
  27068. updateHolderPos();
  27069. }, 500);
  27070. });
  27071. me.addListener('showmessage', function(type, opt){
  27072. opt = utils.isString(opt) ? {
  27073. 'content': opt
  27074. } : opt;
  27075. var message = new Message({
  27076. 'timeout': opt.timeout,
  27077. 'type': opt.type,
  27078. 'content': opt.content,
  27079. 'keepshow': opt.keepshow,
  27080. 'editor': me
  27081. }),
  27082. mid = opt.id || ('msg_' + (+new Date()).toString(36));
  27083. message.render(holder);
  27084. _messageItems[mid] = message;
  27085. message.reset(opt);
  27086. updateHolderPos();
  27087. return mid;
  27088. });
  27089. me.addListener('updatemessage',function(type, id, opt){
  27090. opt = utils.isString(opt) ? {
  27091. 'content': opt
  27092. } : opt;
  27093. var message = _messageItems[id];
  27094. message.render(holder);
  27095. message && message.reset(opt);
  27096. });
  27097. me.addListener('hidemessage',function(type, id){
  27098. var message = _messageItems[id];
  27099. message && message.hide();
  27100. });
  27101. function updateHolderPos(){
  27102. var toolbarbox = me.ui.getDom('toolbarbox');
  27103. if (toolbarbox) {
  27104. holder.style.top = toolbarbox.offsetHeight + 3 + 'px';
  27105. }
  27106. holder.style.zIndex = Math.max(me.options.zIndex, me.iframe.style.zIndex) + 1;
  27107. }
  27108. });
  27109. // adapter/autosave.js
  27110. UE.registerUI('autosave', function(editor) {
  27111. var timer = null,uid = null;
  27112. editor.on('afterautosave',function(){
  27113. clearTimeout(timer);
  27114. timer = setTimeout(function(){
  27115. if(uid){
  27116. editor.trigger('hidemessage',uid);
  27117. }
  27118. uid = editor.trigger('showmessage',{
  27119. content : editor.getLang('autosave.success'),
  27120. timeout : 2000
  27121. });
  27122. },2000)
  27123. })
  27124. });
  27125. })();