ueditor.all.min.js 1.1 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615
  1. /*!
  2. * UEditor
  3. * version: ueditor
  4. * build: Wed Aug 10 2016 11:06:02 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. '<meta name=\'referrer\' content=\'never\'>' +
  6588. '<style type=\'text/css\'>' +
  6589. //设置四周的留边
  6590. // '.view{padding:0;word-wrap:break-word;cursor:text;height:90%;}\n' +
  6591. '.view{padding:0;word-wrap:break-word;cursor:text;height:90% !important;}\n' +
  6592. //设置默认字体和字号
  6593. //font-family不能呢随便改,在safari下fillchar会有解析问题
  6594. // 'body{margin:8px;font-family:sans-serif;font-size:16px;}' +
  6595. 'body{margin:0 18px;font-family:sans-serif;font-size:16px;}' +
  6596. //设置段落间距
  6597. // 'p{margin:5px 0;}</style>' +
  6598. 'p{margin:5px 0;} img{max-width:100%} </style>' +
  6599. ( options.iframeCssUrl ? '<link rel=\'stylesheet\' type=\'text/css\' href=\'' + utils.unhtml(options.iframeCssUrl) + '\'/>' : '' ) +
  6600. (options.initialStyle ? '<style>' + options.initialStyle + '</style>' : '') +
  6601. '</head><body class=\'view\' ></body>' +
  6602. '<script type=\'text/javascript\' ' + (ie ? 'defer=\'defer\'' : '' ) +' id=\'_initialScript\'>' +
  6603. 'setTimeout(function(){editor = window.parent.UE.instants[\'ueditorInstant' + me.uid + '\'];editor._setup(document);},0);' +
  6604. 'var _tmpScript = document.getElementById(\'_initialScript\');_tmpScript.parentNode.removeChild(_tmpScript);</script></html>';
  6605. container.appendChild(domUtils.createElement(document, 'iframe', {
  6606. id: 'ueditor_' + me.uid,
  6607. width: "100%",
  6608. height: "100%",
  6609. frameborder: "0",
  6610. //先注释掉了,加的原因忘记了,但开启会直接导致全屏模式下内容多时不会出现滚动条
  6611. // scrolling :'no',
  6612. src: 'javascript:void(function(){document.open();' + (options.customDomain && document.domain != location.hostname ? 'document.domain="' + document.domain + '";' : '') +
  6613. 'document.write("' + html + '");document.close();}())'
  6614. }));
  6615. container.style.overflow = 'hidden';
  6616. //解决如果是给定的百分比,会导致高度算不对的问题
  6617. setTimeout(function(){
  6618. if( /%$/.test(options.initialFrameWidth)){
  6619. options.minFrameWidth = options.initialFrameWidth = container.offsetWidth;
  6620. //如果这里给定宽度,会导致ie在拖动窗口大小时,编辑区域不随着变化
  6621. // container.style.width = options.initialFrameWidth + 'px';
  6622. }
  6623. if(/%$/.test(options.initialFrameHeight)){
  6624. options.minFrameHeight = options.initialFrameHeight = container.offsetHeight;
  6625. container.style.height = options.initialFrameHeight + 'px';
  6626. }
  6627. })
  6628. }
  6629. },
  6630. /**
  6631. * 编辑器初始化
  6632. * @method _setup
  6633. * @private
  6634. * @param { Element } doc 编辑器Iframe中的文档对象
  6635. */
  6636. _setup: function (doc) {
  6637. var me = this,
  6638. options = me.options;
  6639. if (ie) {
  6640. doc.body.disabled = true;
  6641. doc.body.contentEditable = true;
  6642. doc.body.disabled = false;
  6643. } else {
  6644. doc.body.contentEditable = true;
  6645. }
  6646. doc.body.spellcheck = false;
  6647. me.document = doc;
  6648. me.window = doc.defaultView || doc.parentWindow;
  6649. me.iframe = me.window.frameElement;
  6650. me.body = doc.body;
  6651. me.selection = new dom.Selection(doc);
  6652. //gecko初始化就能得到range,无法判断isFocus了
  6653. var geckoSel;
  6654. if (browser.gecko && (geckoSel = this.selection.getNative())) {
  6655. geckoSel.removeAllRanges();
  6656. }
  6657. this._initEvents();
  6658. //为form提交提供一个隐藏的textarea
  6659. for (var form = this.iframe.parentNode; !domUtils.isBody(form); form = form.parentNode) {
  6660. if (form.tagName == 'FORM') {
  6661. me.form = form;
  6662. if(me.options.autoSyncData){
  6663. domUtils.on(me.window,'blur',function(){
  6664. setValue(form,me);
  6665. });
  6666. }else{
  6667. domUtils.on(form, 'submit', function () {
  6668. setValue(this, me);
  6669. });
  6670. }
  6671. break;
  6672. }
  6673. }
  6674. if (options.initialContent) {
  6675. if (options.autoClearinitialContent) {
  6676. var oldExecCommand = me.execCommand;
  6677. me.execCommand = function () {
  6678. me.fireEvent('firstBeforeExecCommand');
  6679. return oldExecCommand.apply(me, arguments);
  6680. };
  6681. this._setDefaultContent(options.initialContent);
  6682. } else
  6683. this.setContent(options.initialContent, false, true);
  6684. }
  6685. //编辑器不能为空内容
  6686. if (domUtils.isEmptyNode(me.body)) {
  6687. me.body.innerHTML = '<p>' + (browser.ie ? '' : '<br/>') + '</p>';
  6688. }
  6689. //如果要求focus, 就把光标定位到内容开始
  6690. if (options.focus) {
  6691. setTimeout(function () {
  6692. me.focus(me.options.focusInEnd);
  6693. //如果自动清除开着,就不需要做selectionchange;
  6694. !me.options.autoClearinitialContent && me._selectionChange();
  6695. }, 0);
  6696. }
  6697. if (!me.container) {
  6698. me.container = this.iframe.parentNode;
  6699. }
  6700. if (options.fullscreen && me.ui) {
  6701. me.ui.setFullScreen(true);
  6702. }
  6703. try {
  6704. me.document.execCommand('2D-position', false, false);
  6705. } catch (e) {
  6706. }
  6707. try {
  6708. me.document.execCommand('enableInlineTableEditing', false, false);
  6709. } catch (e) {
  6710. }
  6711. try {
  6712. me.document.execCommand('enableObjectResizing', false, false);
  6713. } catch (e) {
  6714. }
  6715. //挂接快捷键
  6716. me._bindshortcutKeys();
  6717. me.isReady = 1;
  6718. me.fireEvent('ready');
  6719. options.onready && options.onready.call(me);
  6720. if (!browser.ie9below) {
  6721. domUtils.on(me.window, ['blur', 'focus'], function (e) {
  6722. //chrome下会出现alt+tab切换时,导致选区位置不对
  6723. if (e.type == 'blur') {
  6724. me._bakRange = me.selection.getRange();
  6725. try {
  6726. me._bakNativeRange = me.selection.getNative().getRangeAt(0);
  6727. me.selection.getNative().removeAllRanges();
  6728. } catch (e) {
  6729. me._bakNativeRange = null;
  6730. }
  6731. } else {
  6732. try {
  6733. me._bakRange && me._bakRange.select();
  6734. } catch (e) {
  6735. }
  6736. }
  6737. });
  6738. }
  6739. //trace:1518 ff3.6body不够寛,会导致点击空白处无法获得焦点
  6740. if (browser.gecko && browser.version <= 10902) {
  6741. //修复ff3.6初始化进来,不能点击获得焦点
  6742. me.body.contentEditable = false;
  6743. setTimeout(function () {
  6744. me.body.contentEditable = true;
  6745. }, 100);
  6746. setInterval(function () {
  6747. me.body.style.height = me.iframe.offsetHeight - 20 + 'px'
  6748. }, 100)
  6749. }
  6750. !options.isShow && me.setHide();
  6751. options.readonly && me.setDisabled();
  6752. },
  6753. /**
  6754. * 同步数据到编辑器所在的form
  6755. * 从编辑器的容器节点向上查找form元素,若找到,就同步编辑内容到找到的form里,为提交数据做准备,主要用于是手动提交的情况
  6756. * 后台取得数据的键值,使用你容器上的name属性,如果没有就使用参数里的textarea项
  6757. * @method sync
  6758. * @example
  6759. * ```javascript
  6760. * editor.sync();
  6761. * form.sumbit(); //form变量已经指向了form元素
  6762. * ```
  6763. */
  6764. /**
  6765. * 根据传入的formId,在页面上查找要同步数据的表单,若找到,就同步编辑内容到找到的form里,为提交数据做准备
  6766. * 后台取得数据的键值,该键值默认使用给定的编辑器容器的name属性,如果没有name属性则使用参数项里给定的“textarea”项
  6767. * @method sync
  6768. * @param { String } formID 指定一个要同步数据的form的id,编辑器的数据会同步到你指定form下
  6769. */
  6770. sync: function (formId) {
  6771. var me = this,
  6772. form = formId ? document.getElementById(formId) :
  6773. domUtils.findParent(me.iframe.parentNode, function (node) {
  6774. return node.tagName == 'FORM'
  6775. }, true);
  6776. form && setValue(form, me);
  6777. },
  6778. /**
  6779. * 设置编辑器高度
  6780. * @method setHeight
  6781. * @remind 当配置项autoHeightEnabled为真时,该方法无效
  6782. * @param { Number } number 设置的高度值,纯数值,不带单位
  6783. * @example
  6784. * ```javascript
  6785. * editor.setHeight(number);
  6786. * ```
  6787. */
  6788. setHeight: function (height,notSetHeight) {
  6789. if (height !== parseInt(this.iframe.parentNode.style.height)) {
  6790. this.iframe.parentNode.style.height = height + 'px';
  6791. }
  6792. !notSetHeight && (this.options.minFrameHeight = this.options.initialFrameHeight = height);
  6793. this.body.style.height = height + 'px';
  6794. !notSetHeight && this.trigger('setHeight')
  6795. },
  6796. /**
  6797. * 为编辑器的编辑命令提供快捷键
  6798. * 这个接口是为插件扩展提供的接口,主要是为新添加的插件,如果需要添加快捷键,所提供的接口
  6799. * @method addshortcutkey
  6800. * @param { Object } keyset 命令名和快捷键键值对对象,多个按钮的快捷键用“+”分隔
  6801. * @example
  6802. * ```javascript
  6803. * editor.addshortcutkey({
  6804. * "Bold" : "ctrl+66",//^B
  6805. * "Italic" : "ctrl+73", //^I
  6806. * });
  6807. * ```
  6808. */
  6809. /**
  6810. * 这个接口是为插件扩展提供的接口,主要是为新添加的插件,如果需要添加快捷键,所提供的接口
  6811. * @method addshortcutkey
  6812. * @param { String } cmd 触发快捷键时,响应的命令
  6813. * @param { String } keys 快捷键的字符串,多个按钮用“+”分隔
  6814. * @example
  6815. * ```javascript
  6816. * editor.addshortcutkey("Underline", "ctrl+85"); //^U
  6817. * ```
  6818. */
  6819. addshortcutkey: function (cmd, keys) {
  6820. var obj = {};
  6821. if (keys) {
  6822. obj[cmd] = keys
  6823. } else {
  6824. obj = cmd;
  6825. }
  6826. utils.extend(this.shortcutkeys, obj)
  6827. },
  6828. /**
  6829. * 对编辑器设置keydown事件监听,绑定快捷键和命令,当快捷键组合触发成功,会响应对应的命令
  6830. * @method _bindshortcutKeys
  6831. * @private
  6832. */
  6833. _bindshortcutKeys: function () {
  6834. var me = this, shortcutkeys = this.shortcutkeys;
  6835. me.addListener('keydown', function (type, e) {
  6836. var keyCode = e.keyCode || e.which;
  6837. for (var i in shortcutkeys) {
  6838. var tmp = shortcutkeys[i].split(',');
  6839. for (var t = 0, ti; ti = tmp[t++];) {
  6840. ti = ti.split(':');
  6841. var key = ti[0], param = ti[1];
  6842. if (/^(ctrl)(\+shift)?\+(\d+)$/.test(key.toLowerCase()) || /^(\d+)$/.test(key)) {
  6843. if (( (RegExp.$1 == 'ctrl' ? (e.ctrlKey || e.metaKey) : 0)
  6844. && (RegExp.$2 != "" ? e[RegExp.$2.slice(1) + "Key"] : 1)
  6845. && keyCode == RegExp.$3
  6846. ) ||
  6847. keyCode == RegExp.$1
  6848. ) {
  6849. if (me.queryCommandState(i,param) != -1)
  6850. me.execCommand(i, param);
  6851. domUtils.preventDefault(e);
  6852. }
  6853. }
  6854. }
  6855. }
  6856. });
  6857. },
  6858. /**
  6859. * 获取编辑器的内容
  6860. * @method getContent
  6861. * @warning 该方法获取到的是经过编辑器内置的过滤规则进行过滤后得到的内容
  6862. * @return { String } 编辑器的内容字符串, 如果编辑器的内容为空,或者是空的标签内容(如:”&lt;p&gt;&lt;br/&gt;&lt;/p&gt;“), 则返回空字符串
  6863. * @example
  6864. * ```javascript
  6865. * //编辑器html内容:<p>1<strong>2<em>34</em>5</strong>6</p>
  6866. * var content = editor.getContent(); //返回值:<p>1<strong>2<em>34</em>5</strong>6</p>
  6867. * ```
  6868. */
  6869. /**
  6870. * 获取编辑器的内容。 可以通过参数定义编辑器内置的判空规则
  6871. * @method getContent
  6872. * @param { Function } fn 自定的判空规则, 要求该方法返回一个boolean类型的值,
  6873. * 代表当前编辑器的内容是否空,
  6874. * 如果返回true, 则该方法将直接返回空字符串;如果返回false,则编辑器将返回
  6875. * 经过内置过滤规则处理后的内容。
  6876. * @remind 该方法在处理包含有初始化内容的时候能起到很好的作用。
  6877. * @warning 该方法获取到的是经过编辑器内置的过滤规则进行过滤后得到的内容
  6878. * @return { String } 编辑器的内容字符串
  6879. * @example
  6880. * ```javascript
  6881. * // editor 是一个编辑器的实例
  6882. * var content = editor.getContent( function ( editor ) {
  6883. * return editor.body.innerHTML === '欢迎使用UEditor'; //返回空字符串
  6884. * } );
  6885. * ```
  6886. */
  6887. getContent: function (cmd, fn,notSetCursor,ignoreBlank,formatter) {
  6888. var me = this;
  6889. if (cmd && utils.isFunction(cmd)) {
  6890. fn = cmd;
  6891. cmd = '';
  6892. }
  6893. if (fn ? !fn() : !this.hasContents()) {
  6894. return '';
  6895. }
  6896. me.fireEvent('beforegetcontent');
  6897. var root = UE.htmlparser(me.body.innerHTML,ignoreBlank);
  6898. me.filterOutputRule(root);
  6899. me.fireEvent('aftergetcontent', cmd,root);
  6900. return root.toHtml(formatter);
  6901. },
  6902. /**
  6903. * 取得完整的html代码,可以直接显示成完整的html文档
  6904. * @method getAllHtml
  6905. * @return { String } 编辑器的内容html文档字符串
  6906. * @eaxmple
  6907. * ```javascript
  6908. * editor.getAllHtml(); //返回格式大致是: <html><head>...</head><body>...</body></html>
  6909. * ```
  6910. */
  6911. getAllHtml: function () {
  6912. var me = this,
  6913. headHtml = [],
  6914. html = '';
  6915. me.fireEvent('getAllHtml', headHtml);
  6916. if (browser.ie && browser.version > 8) {
  6917. var headHtmlForIE9 = '';
  6918. utils.each(me.document.styleSheets, function (si) {
  6919. headHtmlForIE9 += ( si.href ? '<link rel="stylesheet" type="text/css" href="' + si.href + '" />' : '<style>' + si.cssText + '</style>');
  6920. });
  6921. utils.each(me.document.getElementsByTagName('script'), function (si) {
  6922. headHtmlForIE9 += si.outerHTML;
  6923. });
  6924. }
  6925. return '<html><head>' + (me.options.charset ? '<meta http-equiv="Content-Type" content="text/html; charset=' + me.options.charset + '"/>' : '')
  6926. + (headHtmlForIE9 || me.document.getElementsByTagName('head')[0].innerHTML) + headHtml.join('\n') + '</head>'
  6927. + '<body ' + (ie && browser.version < 9 ? 'class="view"' : '') + '>' + me.getContent(null, null, true) + '</body></html>';
  6928. },
  6929. /**
  6930. * 得到编辑器的纯文本内容,但会保留段落格式
  6931. * @method getPlainTxt
  6932. * @return { String } 编辑器带段落格式的纯文本内容字符串
  6933. * @example
  6934. * ```javascript
  6935. * //编辑器html内容:<p><strong>1</strong></p><p><strong>2</strong></p>
  6936. * //console.log(editor.getPlainTxt()); //输出:"1\n2\n
  6937. * ```
  6938. */
  6939. getPlainTxt: function () {
  6940. var reg = new RegExp(domUtils.fillChar, 'g'),
  6941. html = this.body.innerHTML.replace(/[\n\r]/g, '');//ie要先去了\n在处理
  6942. html = html.replace(/<(p|div)[^>]*>(<br\/?>|&nbsp;)<\/\1>/gi, '\n')
  6943. .replace(/<br\/?>/gi, '\n')
  6944. .replace(/<[^>/]+>/g, '')
  6945. .replace(/(\n)?<\/([^>]+)>/g, function (a, b, c) {
  6946. return dtd.$block[c] ? '\n' : b ? b : '';
  6947. });
  6948. //取出来的空格会有c2a0会变成乱码,处理这种情况\u00a0
  6949. return html.replace(reg, '').replace(/\u00a0/g, ' ').replace(/&nbsp;/g, ' ');
  6950. },
  6951. /**
  6952. * 获取编辑器中的纯文本内容,没有段落格式
  6953. * @method getContentTxt
  6954. * @return { String } 编辑器不带段落格式的纯文本内容字符串
  6955. * @example
  6956. * ```javascript
  6957. * //编辑器html内容:<p><strong>1</strong></p><p><strong>2</strong></p>
  6958. * //console.log(editor.getPlainTxt()); //输出:"12
  6959. * ```
  6960. */
  6961. getContentTxt: function () {
  6962. var reg = new RegExp(domUtils.fillChar, 'g');
  6963. //取出来的空格会有c2a0会变成乱码,处理这种情况\u00a0
  6964. return this.body[browser.ie ? 'innerText' : 'textContent'].replace(reg, '').replace(/\u00a0/g, ' ');
  6965. },
  6966. /**
  6967. * 设置编辑器的内容,可修改编辑器当前的html内容
  6968. * @method setContent
  6969. * @warning 通过该方法插入的内容,是经过编辑器内置的过滤规则进行过滤后得到的内容
  6970. * @warning 该方法会触发selectionchange事件
  6971. * @param { String } html 要插入的html内容
  6972. * @example
  6973. * ```javascript
  6974. * editor.getContent('<p>test</p>');
  6975. * ```
  6976. */
  6977. /**
  6978. * 设置编辑器的内容,可修改编辑器当前的html内容
  6979. * @method setContent
  6980. * @warning 通过该方法插入的内容,是经过编辑器内置的过滤规则进行过滤后得到的内容
  6981. * @warning 该方法会触发selectionchange事件
  6982. * @param { String } html 要插入的html内容
  6983. * @param { Boolean } isAppendTo 若传入true,不清空原来的内容,在最后插入内容,否则,清空内容再插入
  6984. * @example
  6985. * ```javascript
  6986. * //假设设置前的编辑器内容是 <p>old text</p>
  6987. * editor.setContent('<p>new text</p>', true); //插入的结果是<p>old text</p><p>new text</p>
  6988. * ```
  6989. */
  6990. setContent: function (html, isAppendTo, notFireSelectionchange) {
  6991. var me = this;
  6992. me.fireEvent('beforesetcontent', html);
  6993. var root = UE.htmlparser(html);
  6994. me.filterInputRule(root);
  6995. html = root.toHtml();
  6996. me.body.innerHTML = (isAppendTo ? me.body.innerHTML : '') + html;
  6997. function isCdataDiv(node){
  6998. return node.tagName == 'DIV' && node.getAttribute('cdata_tag');
  6999. }
  7000. //给文本或者inline节点套p标签
  7001. if (me.options.enterTag == 'p') {
  7002. var child = this.body.firstChild, tmpNode;
  7003. if (!child || child.nodeType == 1 &&
  7004. (dtd.$cdata[child.tagName] || isCdataDiv(child) ||
  7005. domUtils.isCustomeNode(child)
  7006. )
  7007. && child === this.body.lastChild) {
  7008. this.body.innerHTML = '<p>' + (browser.ie ? '&nbsp;' : '<br/>') + '</p>' + this.body.innerHTML;
  7009. } else {
  7010. var p = me.document.createElement('p');
  7011. while (child) {
  7012. while (child && (child.nodeType == 3 || child.nodeType == 1 && dtd.p[child.tagName] && !dtd.$cdata[child.tagName])) {
  7013. tmpNode = child.nextSibling;
  7014. p.appendChild(child);
  7015. child = tmpNode;
  7016. }
  7017. if (p.firstChild) {
  7018. if (!child) {
  7019. me.body.appendChild(p);
  7020. break;
  7021. } else {
  7022. child.parentNode.insertBefore(p, child);
  7023. p = me.document.createElement('p');
  7024. }
  7025. }
  7026. child = child.nextSibling;
  7027. }
  7028. }
  7029. }
  7030. me.fireEvent('aftersetcontent');
  7031. me.fireEvent('contentchange');
  7032. !notFireSelectionchange && me._selectionChange();
  7033. //清除保存的选区
  7034. me._bakRange = me._bakIERange = me._bakNativeRange = null;
  7035. //trace:1742 setContent后gecko能得到焦点问题
  7036. var geckoSel;
  7037. if (browser.gecko && (geckoSel = this.selection.getNative())) {
  7038. geckoSel.removeAllRanges();
  7039. }
  7040. if(me.options.autoSyncData){
  7041. me.form && setValue(me.form,me);
  7042. }
  7043. },
  7044. /**
  7045. * 让编辑器获得焦点,默认focus到编辑器头部
  7046. * @method focus
  7047. * @example
  7048. * ```javascript
  7049. * editor.focus()
  7050. * ```
  7051. */
  7052. /**
  7053. * 让编辑器获得焦点,toEnd确定focus位置
  7054. * @method focus
  7055. * @param { Boolean } toEnd 默认focus到编辑器头部,toEnd为true时focus到内容尾部
  7056. * @example
  7057. * ```javascript
  7058. * editor.focus(true)
  7059. * ```
  7060. */
  7061. focus: function (toEnd) {
  7062. try {
  7063. var me = this,
  7064. rng = me.selection.getRange();
  7065. if (toEnd) {
  7066. var node = me.body.lastChild;
  7067. if(node && node.nodeType == 1 && !dtd.$empty[node.tagName]){
  7068. if(domUtils.isEmptyBlock(node)){
  7069. rng.setStartAtFirst(node)
  7070. }else{
  7071. rng.setStartAtLast(node)
  7072. }
  7073. rng.collapse(true);
  7074. }
  7075. rng.setCursor(true);
  7076. } else {
  7077. if(!rng.collapsed && domUtils.isBody(rng.startContainer) && rng.startOffset == 0){
  7078. var node = me.body.firstChild;
  7079. if(node && node.nodeType == 1 && !dtd.$empty[node.tagName]){
  7080. rng.setStartAtFirst(node).collapse(true);
  7081. }
  7082. }
  7083. rng.select(true);
  7084. }
  7085. this.fireEvent('focus selectionchange');
  7086. } catch (e) {
  7087. }
  7088. },
  7089. isFocus:function(){
  7090. return this.selection.isFocus();
  7091. },
  7092. blur:function(){
  7093. var sel = this.selection.getNative();
  7094. if(sel.empty && browser.ie){
  7095. var nativeRng = document.body.createTextRange();
  7096. nativeRng.moveToElementText(document.body);
  7097. nativeRng.collapse(true);
  7098. nativeRng.select();
  7099. sel.empty()
  7100. }else{
  7101. sel.removeAllRanges()
  7102. }
  7103. //this.fireEvent('blur selectionchange');
  7104. },
  7105. /**
  7106. * 初始化UE事件及部分事件代理
  7107. * @method _initEvents
  7108. * @private
  7109. */
  7110. _initEvents: function () {
  7111. var me = this,
  7112. doc = me.document,
  7113. win = me.window;
  7114. me._proxyDomEvent = utils.bind(me._proxyDomEvent, me);
  7115. domUtils.on(doc, ['click', 'contextmenu', 'mousedown', 'keydown', 'keyup', 'keypress', 'mouseup', 'mouseover', 'mouseout', 'selectstart'], me._proxyDomEvent);
  7116. domUtils.on(win, ['focus', 'blur'], me._proxyDomEvent);
  7117. domUtils.on(me.body,'drop',function(e){
  7118. //阻止ff下默认的弹出新页面打开图片
  7119. if(browser.gecko && e.stopPropagation) { e.stopPropagation(); }
  7120. me.fireEvent('contentchange')
  7121. });
  7122. domUtils.on(doc, ['mouseup', 'keydown'], function (evt) {
  7123. //特殊键不触发selectionchange
  7124. if (evt.type == 'keydown' && (evt.ctrlKey || evt.metaKey || evt.shiftKey || evt.altKey)) {
  7125. return;
  7126. }
  7127. if (evt.button == 2)return;
  7128. me._selectionChange(250, evt);
  7129. });
  7130. },
  7131. /**
  7132. * 触发事件代理
  7133. * @method _proxyDomEvent
  7134. * @private
  7135. * @return { * } fireEvent的返回值
  7136. * @see UE.EventBase:fireEvent(String)
  7137. */
  7138. _proxyDomEvent: function (evt) {
  7139. if(this.fireEvent('before' + evt.type.replace(/^on/, '').toLowerCase()) === false){
  7140. return false;
  7141. }
  7142. if(this.fireEvent(evt.type.replace(/^on/, ''), evt) === false){
  7143. return false;
  7144. }
  7145. return this.fireEvent('after' + evt.type.replace(/^on/, '').toLowerCase())
  7146. },
  7147. /**
  7148. * 变化选区
  7149. * @method _selectionChange
  7150. * @private
  7151. */
  7152. _selectionChange: function (delay, evt) {
  7153. var me = this;
  7154. //有光标才做selectionchange 为了解决未focus时点击source不能触发更改工具栏状态的问题(source命令notNeedUndo=1)
  7155. // if ( !me.selection.isFocus() ){
  7156. // return;
  7157. // }
  7158. var hackForMouseUp = false;
  7159. var mouseX, mouseY;
  7160. if (browser.ie && browser.version < 9 && evt && evt.type == 'mouseup') {
  7161. var range = this.selection.getRange();
  7162. if (!range.collapsed) {
  7163. hackForMouseUp = true;
  7164. mouseX = evt.clientX;
  7165. mouseY = evt.clientY;
  7166. }
  7167. }
  7168. clearTimeout(_selectionChangeTimer);
  7169. _selectionChangeTimer = setTimeout(function () {
  7170. if (!me.selection || !me.selection.getNative()) {
  7171. return;
  7172. }
  7173. //修复一个IE下的bug: 鼠标点击一段已选择的文本中间时,可能在mouseup后的一段时间内取到的range是在selection的type为None下的错误值.
  7174. //IE下如果用户是拖拽一段已选择文本,则不会触发mouseup事件,所以这里的特殊处理不会对其有影响
  7175. var ieRange;
  7176. if (hackForMouseUp && me.selection.getNative().type == 'None') {
  7177. ieRange = me.document.body.createTextRange();
  7178. try {
  7179. ieRange.moveToPoint(mouseX, mouseY);
  7180. } catch (ex) {
  7181. ieRange = null;
  7182. }
  7183. }
  7184. var bakGetIERange;
  7185. if (ieRange) {
  7186. bakGetIERange = me.selection.getIERange;
  7187. me.selection.getIERange = function () {
  7188. return ieRange;
  7189. };
  7190. }
  7191. me.selection.cache();
  7192. if (bakGetIERange) {
  7193. me.selection.getIERange = bakGetIERange;
  7194. }
  7195. if (me.selection._cachedRange && me.selection._cachedStartElement) {
  7196. me.fireEvent('beforeselectionchange');
  7197. // 第二个参数causeByUi为true代表由用户交互造成的selectionchange.
  7198. me.fireEvent('selectionchange', !!evt);
  7199. me.fireEvent('afterselectionchange');
  7200. me.selection.clear();
  7201. }
  7202. }, delay || 50);
  7203. },
  7204. /**
  7205. * 执行编辑命令
  7206. * @method _callCmdFn
  7207. * @private
  7208. * @param { String } fnName 函数名称
  7209. * @param { * } args 传给命令函数的参数
  7210. * @return { * } 返回命令函数运行的返回值
  7211. */
  7212. _callCmdFn: function (fnName, args) {
  7213. var cmdName = args[0].toLowerCase(),
  7214. cmd, cmdFn;
  7215. cmd = this.commands[cmdName] || UE.commands[cmdName];
  7216. cmdFn = cmd && cmd[fnName];
  7217. //没有querycommandstate或者没有command的都默认返回0
  7218. if ((!cmd || !cmdFn) && fnName == 'queryCommandState') {
  7219. return 0;
  7220. } else if (cmdFn) {
  7221. return cmdFn.apply(this, args);
  7222. }
  7223. },
  7224. /**
  7225. * 执行编辑命令cmdName,完成富文本编辑效果
  7226. * @method execCommand
  7227. * @param { String } cmdName 需要执行的命令
  7228. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  7229. * @return { * } 返回命令函数运行的返回值
  7230. * @example
  7231. * ```javascript
  7232. * editor.execCommand(cmdName);
  7233. * ```
  7234. */
  7235. execCommand: function (cmdName) {
  7236. cmdName = cmdName.toLowerCase();
  7237. var me = this,
  7238. result,
  7239. cmd = me.commands[cmdName] || UE.commands[cmdName];
  7240. if (!cmd || !cmd.execCommand) {
  7241. return null;
  7242. }
  7243. if (!cmd.notNeedUndo && !me.__hasEnterExecCommand) {
  7244. me.__hasEnterExecCommand = true;
  7245. if (me.queryCommandState.apply(me,arguments) != -1) {
  7246. me.fireEvent('saveScene');
  7247. me.fireEvent.apply(me, ['beforeexeccommand', cmdName].concat(arguments));
  7248. result = this._callCmdFn('execCommand', arguments);
  7249. //保存场景时,做了内容对比,再看是否进行contentchange触发,这里多触发了一次,去掉
  7250. // (!cmd.ignoreContentChange && !me._ignoreContentChange) && me.fireEvent('contentchange');
  7251. me.fireEvent.apply(me, ['afterexeccommand', cmdName].concat(arguments));
  7252. me.fireEvent('saveScene');
  7253. }
  7254. me.__hasEnterExecCommand = false;
  7255. } else {
  7256. result = this._callCmdFn('execCommand', arguments);
  7257. (!me.__hasEnterExecCommand && !cmd.ignoreContentChange && !me._ignoreContentChange) && me.fireEvent('contentchange')
  7258. }
  7259. (!me.__hasEnterExecCommand && !cmd.ignoreContentChange && !me._ignoreContentChange) && me._selectionChange();
  7260. return result;
  7261. },
  7262. /**
  7263. * 根据传入的command命令,查选编辑器当前的选区,返回命令的状态
  7264. * @method queryCommandState
  7265. * @param { String } cmdName 需要查询的命令名称
  7266. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  7267. * @return { Number } number 返回放前命令的状态,返回值三种情况:(-1|0|1)
  7268. * @example
  7269. * ```javascript
  7270. * editor.queryCommandState(cmdName) => (-1|0|1)
  7271. * ```
  7272. * @see COMMAND.LIST
  7273. */
  7274. queryCommandState: function (cmdName) {
  7275. return this._callCmdFn('queryCommandState', arguments);
  7276. },
  7277. /**
  7278. * 根据传入的command命令,查选编辑器当前的选区,根据命令返回相关的值
  7279. * @method queryCommandValue
  7280. * @param { String } cmdName 需要查询的命令名称
  7281. * @remind 具体命令的使用请参考<a href="#COMMAND.LIST">命令列表</a>
  7282. * @remind 只有部分插件有此方法
  7283. * @return { * } 返回每个命令特定的当前状态值
  7284. * @grammar editor.queryCommandValue(cmdName) => {*}
  7285. * @see COMMAND.LIST
  7286. */
  7287. queryCommandValue: function (cmdName) {
  7288. return this._callCmdFn('queryCommandValue', arguments);
  7289. },
  7290. /**
  7291. * 检查编辑区域中是否有内容
  7292. * @method hasContents
  7293. * @remind 默认有文本内容,或者有以下节点都不认为是空
  7294. * table,ul,ol,dl,iframe,area,base,col,hr,img,embed,input,link,meta,param
  7295. * @return { Boolean } 检查有内容返回true,否则返回false
  7296. * @example
  7297. * ```javascript
  7298. * editor.hasContents()
  7299. * ```
  7300. */
  7301. /**
  7302. * 检查编辑区域中是否有内容,若包含参数tags中的节点类型,直接返回true
  7303. * @method hasContents
  7304. * @param { Array } tags 传入数组判断时用到的节点类型
  7305. * @return { Boolean } 若文档中包含tags数组里对应的tag,返回true,否则返回false
  7306. * @example
  7307. * ```javascript
  7308. * editor.hasContents(['span']);
  7309. * ```
  7310. */
  7311. hasContents: function (tags) {
  7312. if (tags) {
  7313. for (var i = 0, ci; ci = tags[i++];) {
  7314. if (this.document.getElementsByTagName(ci).length > 0) {
  7315. return true;
  7316. }
  7317. }
  7318. }
  7319. if (!domUtils.isEmptyBlock(this.body)) {
  7320. return true
  7321. }
  7322. //随时添加,定义的特殊标签如果存在,不能认为是空
  7323. tags = ['div'];
  7324. for (i = 0; ci = tags[i++];) {
  7325. var nodes = domUtils.getElementsByTagName(this.document, ci);
  7326. for (var n = 0, cn; cn = nodes[n++];) {
  7327. if (domUtils.isCustomeNode(cn)) {
  7328. return true;
  7329. }
  7330. }
  7331. }
  7332. return false;
  7333. },
  7334. /**
  7335. * 重置编辑器,可用来做多个tab使用同一个编辑器实例
  7336. * @method reset
  7337. * @remind 此方法会清空编辑器内容,清空回退列表,会触发reset事件
  7338. * @example
  7339. * ```javascript
  7340. * editor.reset()
  7341. * ```
  7342. */
  7343. reset: function () {
  7344. this.fireEvent('reset');
  7345. },
  7346. /**
  7347. * 设置当前编辑区域可以编辑
  7348. * @method setEnabled
  7349. * @example
  7350. * ```javascript
  7351. * editor.setEnabled()
  7352. * ```
  7353. */
  7354. setEnabled: function () {
  7355. var me = this, range;
  7356. if (me.body.contentEditable == 'false') {
  7357. me.body.contentEditable = true;
  7358. range = me.selection.getRange();
  7359. //有可能内容丢失了
  7360. try {
  7361. range.moveToBookmark(me.lastBk);
  7362. delete me.lastBk
  7363. } catch (e) {
  7364. range.setStartAtFirst(me.body).collapse(true)
  7365. }
  7366. range.select(true);
  7367. if (me.bkqueryCommandState) {
  7368. me.queryCommandState = me.bkqueryCommandState;
  7369. delete me.bkqueryCommandState;
  7370. }
  7371. if (me.bkqueryCommandValue) {
  7372. me.queryCommandValue = me.bkqueryCommandValue;
  7373. delete me.bkqueryCommandValue;
  7374. }
  7375. me.fireEvent('selectionchange');
  7376. }
  7377. },
  7378. enable: function () {
  7379. return this.setEnabled();
  7380. },
  7381. /** 设置当前编辑区域不可编辑
  7382. * @method setDisabled
  7383. */
  7384. /** 设置当前编辑区域不可编辑,except中的命令除外
  7385. * @method setDisabled
  7386. * @param { String } except 例外命令的字符串
  7387. * @remind 即使设置了disable,此处配置的例外命令仍然可以执行
  7388. * @example
  7389. * ```javascript
  7390. * editor.setDisabled('bold'); //禁用工具栏中除加粗之外的所有功能
  7391. * ```
  7392. */
  7393. /** 设置当前编辑区域不可编辑,except中的命令除外
  7394. * @method setDisabled
  7395. * @param { Array } except 例外命令的字符串数组,数组中的命令仍然可以执行
  7396. * @remind 即使设置了disable,此处配置的例外命令仍然可以执行
  7397. * @example
  7398. * ```javascript
  7399. * editor.setDisabled(['bold','insertimage']); //禁用工具栏中除加粗和插入图片之外的所有功能
  7400. * ```
  7401. */
  7402. setDisabled: function (except) {
  7403. var me = this;
  7404. except = except ? utils.isArray(except) ? except : [except] : [];
  7405. if (me.body.contentEditable == 'true') {
  7406. if (!me.lastBk) {
  7407. me.lastBk = me.selection.getRange().createBookmark(true);
  7408. }
  7409. me.body.contentEditable = false;
  7410. me.bkqueryCommandState = me.queryCommandState;
  7411. me.bkqueryCommandValue = me.queryCommandValue;
  7412. me.queryCommandState = function (type) {
  7413. if (utils.indexOf(except, type) != -1) {
  7414. return me.bkqueryCommandState.apply(me, arguments);
  7415. }
  7416. return -1;
  7417. };
  7418. me.queryCommandValue = function (type) {
  7419. if (utils.indexOf(except, type) != -1) {
  7420. return me.bkqueryCommandValue.apply(me, arguments);
  7421. }
  7422. return null;
  7423. };
  7424. me.fireEvent('selectionchange');
  7425. }
  7426. },
  7427. disable: function (except) {
  7428. return this.setDisabled(except);
  7429. },
  7430. /**
  7431. * 设置默认内容
  7432. * @method _setDefaultContent
  7433. * @private
  7434. * @param { String } cont 要存入的内容
  7435. */
  7436. _setDefaultContent: function () {
  7437. function clear() {
  7438. var me = this;
  7439. if (me.document.getElementById('initContent')) {
  7440. me.body.innerHTML = '<p>' + (ie ? '' : '<br/>') + '</p>';
  7441. me.removeListener('firstBeforeExecCommand focus', clear);
  7442. setTimeout(function () {
  7443. me.focus();
  7444. me._selectionChange();
  7445. }, 0)
  7446. }
  7447. }
  7448. return function (cont) {
  7449. var me = this;
  7450. me.body.innerHTML = '<p id="initContent">' + cont + '</p>';
  7451. me.addListener('firstBeforeExecCommand focus', clear);
  7452. }
  7453. }(),
  7454. /**
  7455. * 显示编辑器
  7456. * @method setShow
  7457. * @example
  7458. * ```javascript
  7459. * editor.setShow()
  7460. * ```
  7461. */
  7462. setShow: function () {
  7463. var me = this, range = me.selection.getRange();
  7464. if (me.container.style.display == 'none') {
  7465. //有可能内容丢失了
  7466. try {
  7467. range.moveToBookmark(me.lastBk);
  7468. delete me.lastBk
  7469. } catch (e) {
  7470. range.setStartAtFirst(me.body).collapse(true)
  7471. }
  7472. //ie下focus实效,所以做了个延迟
  7473. setTimeout(function () {
  7474. range.select(true);
  7475. }, 100);
  7476. me.container.style.display = '';
  7477. }
  7478. },
  7479. show: function () {
  7480. return this.setShow();
  7481. },
  7482. /**
  7483. * 隐藏编辑器
  7484. * @method setHide
  7485. * @example
  7486. * ```javascript
  7487. * editor.setHide()
  7488. * ```
  7489. */
  7490. setHide: function () {
  7491. var me = this;
  7492. if (!me.lastBk) {
  7493. me.lastBk = me.selection.getRange().createBookmark(true);
  7494. }
  7495. me.container.style.display = 'none'
  7496. },
  7497. hide: function () {
  7498. return this.setHide();
  7499. },
  7500. /**
  7501. * 根据指定的路径,获取对应的语言资源
  7502. * @method getLang
  7503. * @param { String } path 路径根据的是lang目录下的语言文件的路径结构
  7504. * @return { Object | String } 根据路径返回语言资源的Json格式对象或者语言字符串
  7505. * @example
  7506. * ```javascript
  7507. * editor.getLang('contextMenu.delete'); //如果当前是中文,那返回是的是'删除'
  7508. * ```
  7509. */
  7510. getLang: function (path) {
  7511. var lang = UE.I18N[this.options.lang];
  7512. if (!lang) {
  7513. throw Error("not import language file");
  7514. }
  7515. path = (path || "").split(".");
  7516. for (var i = 0, ci; ci = path[i++];) {
  7517. lang = lang[ci];
  7518. if (!lang)break;
  7519. }
  7520. return lang;
  7521. },
  7522. /**
  7523. * 计算编辑器html内容字符串的长度
  7524. * @method getContentLength
  7525. * @return { Number } 返回计算的长度
  7526. * @example
  7527. * ```javascript
  7528. * //编辑器html内容<p><strong>132</strong></p>
  7529. * editor.getContentLength() //返回27
  7530. * ```
  7531. */
  7532. /**
  7533. * 计算编辑器当前纯文本内容的长度
  7534. * @method getContentLength
  7535. * @param { Boolean } ingoneHtml 传入true时,只按照纯文本来计算
  7536. * @return { Number } 返回计算的长度,内容中有hr/img/iframe标签,长度加1
  7537. * @example
  7538. * ```javascript
  7539. * //编辑器html内容<p><strong>132</strong></p>
  7540. * editor.getContentLength() //返回3
  7541. * ```
  7542. */
  7543. getContentLength: function (ingoneHtml, tagNames) {
  7544. var count = this.getContent(false,false,true).length;
  7545. if (ingoneHtml) {
  7546. tagNames = (tagNames || []).concat([ 'hr', 'img', 'iframe']);
  7547. count = this.getContentTxt().replace(/[\t\r\n]+/g, '').length;
  7548. for (var i = 0, ci; ci = tagNames[i++];) {
  7549. count += this.document.getElementsByTagName(ci).length;
  7550. }
  7551. }
  7552. return count;
  7553. },
  7554. /**
  7555. * 注册输入过滤规则
  7556. * @method addInputRule
  7557. * @param { Function } rule 要添加的过滤规则
  7558. * @example
  7559. * ```javascript
  7560. * editor.addInputRule(function(root){
  7561. * $.each(root.getNodesByTagName('div'),function(i,node){
  7562. * node.tagName="p";
  7563. * });
  7564. * });
  7565. * ```
  7566. */
  7567. addInputRule: function (rule) {
  7568. this.inputRules.push(rule);
  7569. },
  7570. /**
  7571. * 执行注册的过滤规则
  7572. * @method filterInputRule
  7573. * @param { UE.uNode } root 要过滤的uNode节点
  7574. * @remind 执行editor.setContent方法和执行'inserthtml'命令后,会运行该过滤函数
  7575. * @example
  7576. * ```javascript
  7577. * editor.filterInputRule(editor.body);
  7578. * ```
  7579. * @see UE.Editor:addInputRule
  7580. */
  7581. filterInputRule: function (root) {
  7582. for (var i = 0, ci; ci = this.inputRules[i++];) {
  7583. ci.call(this, root)
  7584. }
  7585. },
  7586. /**
  7587. * 注册输出过滤规则
  7588. * @method addOutputRule
  7589. * @param { Function } rule 要添加的过滤规则
  7590. * @example
  7591. * ```javascript
  7592. * editor.addOutputRule(function(root){
  7593. * $.each(root.getNodesByTagName('p'),function(i,node){
  7594. * node.tagName="div";
  7595. * });
  7596. * });
  7597. * ```
  7598. */
  7599. addOutputRule: function (rule) {
  7600. this.outputRules.push(rule)
  7601. },
  7602. /**
  7603. * 根据输出过滤规则,过滤编辑器内容
  7604. * @method filterOutputRule
  7605. * @remind 执行editor.getContent方法的时候,会先运行该过滤函数
  7606. * @param { UE.uNode } root 要过滤的uNode节点
  7607. * @example
  7608. * ```javascript
  7609. * editor.filterOutputRule(editor.body);
  7610. * ```
  7611. * @see UE.Editor:addOutputRule
  7612. */
  7613. filterOutputRule: function (root) {
  7614. for (var i = 0, ci; ci = this.outputRules[i++];) {
  7615. ci.call(this, root)
  7616. }
  7617. },
  7618. /**
  7619. * 根据action名称获取请求的路径
  7620. * @method getActionUrl
  7621. * @remind 假如没有设置serverUrl,会根据imageUrl设置默认的controller路径
  7622. * @param { String } action action名称
  7623. * @example
  7624. * ```javascript
  7625. * editor.getActionUrl('config'); //返回 "/ueditor/php/controller.php?action=config"
  7626. * editor.getActionUrl('image'); //返回 "/ueditor/php/controller.php?action=uplaodimage"
  7627. * editor.getActionUrl('scrawl'); //返回 "/ueditor/php/controller.php?action=uplaodscrawl"
  7628. * editor.getActionUrl('imageManager'); //返回 "/ueditor/php/controller.php?action=listimage"
  7629. * ```
  7630. */
  7631. getActionUrl: function(action){
  7632. var actionName = this.getOpt(action) || action,
  7633. imageUrl = this.getOpt('imageUrl'),
  7634. serverUrl = this.getOpt('serverUrl');
  7635. if(!serverUrl && imageUrl) {
  7636. serverUrl = imageUrl.replace(/^(.*[\/]).+([\.].+)$/, '$1controller$2');
  7637. }
  7638. if(serverUrl) {
  7639. serverUrl = serverUrl + (serverUrl.indexOf('?') == -1 ? '?':'&') + 'action=' + (actionName || '');
  7640. return utils.formatUrl(serverUrl);
  7641. } else {
  7642. return '';
  7643. }
  7644. }
  7645. };
  7646. utils.inherits(Editor, EventBase);
  7647. })();
  7648. // core/Editor.defaultoptions.js
  7649. //维护编辑器一下默认的不在插件中的配置项
  7650. UE.Editor.defaultOptions = function(editor){
  7651. var _url = editor.options.UEDITOR_HOME_URL;
  7652. return {
  7653. isShow: true,
  7654. initialContent: '',
  7655. initialStyle:'',
  7656. autoClearinitialContent: false,
  7657. iframeCssUrl: _url + 'themes/iframe.css',
  7658. textarea: 'editorValue',
  7659. focus: false,
  7660. focusInEnd: true,
  7661. autoClearEmptyNode: true,
  7662. fullscreen: false,
  7663. readonly: false,
  7664. zIndex: 999,
  7665. imagePopup: true,
  7666. enterTag: 'p',
  7667. customDomain: false,
  7668. lang: 'zh-cn',
  7669. langPath: _url + 'lang/',
  7670. theme: 'default',
  7671. themePath: _url + 'themes/',
  7672. allHtmlEnabled: false,
  7673. scaleEnabled: false,
  7674. tableNativeEditInFF: false,
  7675. autoSyncData : true,
  7676. fileNameFormat: '{time}{rand:6}'
  7677. }
  7678. };
  7679. // core/loadconfig.js
  7680. (function(){
  7681. UE.Editor.prototype.loadServerConfig = function(){
  7682. var me = this;
  7683. me.fireEvent('serverConfigLoaded');
  7684. me._serverConfigLoaded = true;
  7685. // setTimeout(function(){
  7686. // try{
  7687. // me.options.imageUrl && me.setOpt('serverUrl', me.options.imageUrl.replace(/^(.*[\/]).+([\.].+)$/, '$1controller$2'));
  7688. // var configUrl = me.getActionUrl('config'),
  7689. // isJsonp = utils.isCrossDomainUrl(configUrl);
  7690. // /* 发出ajax请求 */
  7691. // me._serverConfigLoaded = false;
  7692. // configUrl && UE.ajax.request(configUrl,{
  7693. // 'method': 'GET',
  7694. // 'dataType': isJsonp ? 'jsonp':'',
  7695. // 'onsuccess':function(r){
  7696. // try {
  7697. // var config = isJsonp ? r:eval("("+r.responseText+")");
  7698. // utils.extend(me.options, config);
  7699. // me.fireEvent('serverConfigLoaded');
  7700. // me._serverConfigLoaded = true;
  7701. // } catch (e) {
  7702. // showErrorMsg(me.getLang('loadconfigFormatError'));
  7703. // }
  7704. // },
  7705. // 'onerror':function(){
  7706. // showErrorMsg(me.getLang('loadconfigHttpError'));
  7707. // }
  7708. // });
  7709. // } catch(e){
  7710. // showErrorMsg(me.getLang('loadconfigError'));
  7711. // }
  7712. // });
  7713. function showErrorMsg(msg) {
  7714. console && console.error(msg);
  7715. //me.fireEvent('showMessage', {
  7716. // 'title': msg,
  7717. // 'type': 'error'
  7718. //});
  7719. }
  7720. };
  7721. UE.Editor.prototype.isServerConfigLoaded = function(){
  7722. var me = this;
  7723. return me._serverConfigLoaded || false;
  7724. };
  7725. UE.Editor.prototype.afterConfigReady = function(handler){
  7726. if (!handler || !utils.isFunction(handler)) return;
  7727. var me = this;
  7728. var readyHandler = function(){
  7729. handler.apply(me, arguments);
  7730. me.removeListener('serverConfigLoaded', readyHandler);
  7731. };
  7732. if (me.isServerConfigLoaded()) {
  7733. handler.call(me, 'serverConfigLoaded');
  7734. } else {
  7735. me.addListener('serverConfigLoaded', readyHandler);
  7736. }
  7737. };
  7738. })();
  7739. // core/ajax.js
  7740. /**
  7741. * @file
  7742. * @module UE.ajax
  7743. * @since 1.2.6.1
  7744. */
  7745. /**
  7746. * 提供对ajax请求的支持
  7747. * @module UE.ajax
  7748. */
  7749. UE.ajax = function() {
  7750. //创建一个ajaxRequest对象
  7751. var fnStr = 'XMLHttpRequest()';
  7752. try {
  7753. new ActiveXObject("Msxml2.XMLHTTP");
  7754. fnStr = 'ActiveXObject(\'Msxml2.XMLHTTP\')';
  7755. } catch (e) {
  7756. try {
  7757. new ActiveXObject("Microsoft.XMLHTTP");
  7758. fnStr = 'ActiveXObject(\'Microsoft.XMLHTTP\')'
  7759. } catch (e) {
  7760. }
  7761. }
  7762. var creatAjaxRequest = new Function('return new ' + fnStr);
  7763. /**
  7764. * 将json参数转化成适合ajax提交的参数列表
  7765. * @param json
  7766. */
  7767. function json2str(json) {
  7768. var strArr = [];
  7769. for (var i in json) {
  7770. //忽略默认的几个参数
  7771. if(i=="method" || i=="timeout" || i=="async" || i=="dataType" || i=="callback") continue;
  7772. //忽略控制
  7773. if(json[i] == undefined || json[i] == null) continue;
  7774. //传递过来的对象和函数不在提交之列
  7775. if (!((typeof json[i]).toLowerCase() == "function" || (typeof json[i]).toLowerCase() == "object")) {
  7776. strArr.push( encodeURIComponent(i) + "="+encodeURIComponent(json[i]) );
  7777. } else if (utils.isArray(json[i])) {
  7778. //支持传数组内容
  7779. for(var j = 0; j < json[i].length; j++) {
  7780. strArr.push( encodeURIComponent(i) + "[]="+encodeURIComponent(json[i][j]) );
  7781. }
  7782. }
  7783. }
  7784. return strArr.join("&");
  7785. }
  7786. function doAjax(url, ajaxOptions) {
  7787. var xhr = creatAjaxRequest(),
  7788. //是否超时
  7789. timeIsOut = false,
  7790. //默认参数
  7791. defaultAjaxOptions = {
  7792. method:"POST",
  7793. timeout:5000,
  7794. async:true,
  7795. data:{},//需要传递对象的话只能覆盖
  7796. onsuccess:function() {
  7797. },
  7798. onerror:function() {
  7799. }
  7800. };
  7801. if (typeof url === "object") {
  7802. ajaxOptions = url;
  7803. url = ajaxOptions.url;
  7804. }
  7805. if (!xhr || !url) return;
  7806. var ajaxOpts = ajaxOptions ? utils.extend(defaultAjaxOptions,ajaxOptions) : defaultAjaxOptions;
  7807. var submitStr = json2str(ajaxOpts); // { name:"Jim",city:"Beijing" } --> "name=Jim&city=Beijing"
  7808. //如果用户直接通过data参数传递json对象过来,则也要将此json对象转化为字符串
  7809. if (!utils.isEmptyObject(ajaxOpts.data)){
  7810. submitStr += (submitStr? "&":"") + json2str(ajaxOpts.data);
  7811. }
  7812. //超时检测
  7813. var timerID = setTimeout(function() {
  7814. if (xhr.readyState != 4) {
  7815. timeIsOut = true;
  7816. xhr.abort();
  7817. clearTimeout(timerID);
  7818. }
  7819. }, ajaxOpts.timeout);
  7820. var method = ajaxOpts.method.toUpperCase();
  7821. var str = url + (url.indexOf("?")==-1?"?":"&") + (method=="POST"?"":submitStr+ "&noCache=" + +new Date);
  7822. xhr.open(method, str, ajaxOpts.async);
  7823. xhr.onreadystatechange = function() {
  7824. if (xhr.readyState == 4) {
  7825. if (!timeIsOut && xhr.status == 200) {
  7826. ajaxOpts.onsuccess(xhr);
  7827. } else {
  7828. ajaxOpts.onerror(xhr);
  7829. }
  7830. }
  7831. };
  7832. if (method == "POST") {
  7833. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  7834. xhr.send(submitStr);
  7835. } else {
  7836. xhr.send(null);
  7837. }
  7838. }
  7839. function doJsonp(url, opts) {
  7840. var successhandler = opts.onsuccess || function(){},
  7841. scr = document.createElement('SCRIPT'),
  7842. options = opts || {},
  7843. charset = options['charset'],
  7844. callbackField = options['jsonp'] || 'callback',
  7845. callbackFnName,
  7846. timeOut = options['timeOut'] || 0,
  7847. timer,
  7848. reg = new RegExp('(\\?|&)' + callbackField + '=([^&]*)'),
  7849. matches;
  7850. if (utils.isFunction(successhandler)) {
  7851. callbackFnName = 'bd__editor__' + Math.floor(Math.random() * 2147483648).toString(36);
  7852. window[callbackFnName] = getCallBack(0);
  7853. } else if(utils.isString(successhandler)){
  7854. callbackFnName = successhandler;
  7855. } else {
  7856. if (matches = reg.exec(url)) {
  7857. callbackFnName = matches[2];
  7858. }
  7859. }
  7860. url = url.replace(reg, '\x241' + callbackField + '=' + callbackFnName);
  7861. if (url.search(reg) < 0) {
  7862. url += (url.indexOf('?') < 0 ? '?' : '&') + callbackField + '=' + callbackFnName;
  7863. }
  7864. var queryStr = json2str(opts); // { name:"Jim",city:"Beijing" } --> "name=Jim&city=Beijing"
  7865. //如果用户直接通过data参数传递json对象过来,则也要将此json对象转化为字符串
  7866. if (!utils.isEmptyObject(opts.data)){
  7867. queryStr += (queryStr? "&":"") + json2str(opts.data);
  7868. }
  7869. if (queryStr) {
  7870. url = url.replace(/\?/, '?' + queryStr + '&');
  7871. }
  7872. scr.onerror = getCallBack(1);
  7873. if( timeOut ){
  7874. timer = setTimeout(getCallBack(1), timeOut);
  7875. }
  7876. createScriptTag(scr, url, charset);
  7877. function createScriptTag(scr, url, charset) {
  7878. scr.setAttribute('type', 'text/javascript');
  7879. scr.setAttribute('defer', 'defer');
  7880. charset && scr.setAttribute('charset', charset);
  7881. scr.setAttribute('src', url);
  7882. document.getElementsByTagName('head')[0].appendChild(scr);
  7883. }
  7884. function getCallBack(onTimeOut){
  7885. return function(){
  7886. try {
  7887. if(onTimeOut){
  7888. options.onerror && options.onerror();
  7889. }else{
  7890. try{
  7891. clearTimeout(timer);
  7892. successhandler.apply(window, arguments);
  7893. } catch (e){}
  7894. }
  7895. } catch (exception) {
  7896. options.onerror && options.onerror.call(window, exception);
  7897. } finally {
  7898. options.oncomplete && options.oncomplete.apply(window, arguments);
  7899. scr.parentNode && scr.parentNode.removeChild(scr);
  7900. window[callbackFnName] = null;
  7901. try {
  7902. delete window[callbackFnName];
  7903. }catch(e){}
  7904. }
  7905. }
  7906. }
  7907. }
  7908. return {
  7909. /**
  7910. * 根据给定的参数项,向指定的url发起一个ajax请求。 ajax请求完成后,会根据请求结果调用相应回调: 如果请求
  7911. * 成功, 则调用onsuccess回调, 失败则调用 onerror 回调
  7912. * @method request
  7913. * @param { URLString } url ajax请求的url地址
  7914. * @param { Object } ajaxOptions ajax请求选项的键值对,支持的选项如下:
  7915. * @example
  7916. * ```javascript
  7917. * //向sayhello.php发起一个异步的Ajax GET请求, 请求超时时间为10s, 请求完成后执行相应的回调。
  7918. * UE.ajax.requeset( 'sayhello.php', {
  7919. *
  7920. * //请求方法。可选值: 'GET', 'POST',默认值是'POST'
  7921. * method: 'GET',
  7922. *
  7923. * //超时时间。 默认为5000, 单位是ms
  7924. * timeout: 10000,
  7925. *
  7926. * //是否是异步请求。 true为异步请求, false为同步请求
  7927. * async: true,
  7928. *
  7929. * //请求携带的数据。如果请求为GET请求, data会经过stringify后附加到请求url之后。
  7930. * data: {
  7931. * name: 'ueditor'
  7932. * },
  7933. *
  7934. * //请求成功后的回调, 该回调接受当前的XMLHttpRequest对象作为参数。
  7935. * onsuccess: function ( xhr ) {
  7936. * //console.log( xhr.responseText );
  7937. * },
  7938. *
  7939. * //请求失败或者超时后的回调。
  7940. * onerror: function ( xhr ) {
  7941. * alert( 'Ajax请求失败' );
  7942. * }
  7943. *
  7944. * } );
  7945. * ```
  7946. */
  7947. /**
  7948. * 根据给定的参数项发起一个ajax请求, 参数项里必须包含一个url地址。 ajax请求完成后,会根据请求结果调用相应回调: 如果请求
  7949. * 成功, 则调用onsuccess回调, 失败则调用 onerror 回调。
  7950. * @method request
  7951. * @warning 如果在参数项里未提供一个key为“url”的地址值,则该请求将直接退出。
  7952. * @param { Object } ajaxOptions ajax请求选项的键值对,支持的选项如下:
  7953. * @example
  7954. * ```javascript
  7955. *
  7956. * //向sayhello.php发起一个异步的Ajax POST请求, 请求超时时间为5s, 请求完成后不执行任何回调。
  7957. * UE.ajax.requeset( 'sayhello.php', {
  7958. *
  7959. * //请求的地址, 该项是必须的。
  7960. * url: 'sayhello.php'
  7961. *
  7962. * } );
  7963. * ```
  7964. */
  7965. request:function(url, opts) {
  7966. if (opts && opts.dataType == 'jsonp') {
  7967. doJsonp(url, opts);
  7968. } else {
  7969. doAjax(url, opts);
  7970. }
  7971. },
  7972. getJSONP:function(url, data, fn) {
  7973. var opts = {
  7974. 'data': data,
  7975. 'oncomplete': fn
  7976. };
  7977. doJsonp(url, opts);
  7978. }
  7979. };
  7980. }();
  7981. // core/filterword.js
  7982. /**
  7983. * UE过滤word的静态方法
  7984. * @file
  7985. */
  7986. /**
  7987. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  7988. * @module UE
  7989. */
  7990. /**
  7991. * 根据传入html字符串过滤word
  7992. * @module UE
  7993. * @since 1.2.6.1
  7994. * @method filterWord
  7995. * @param { String } html html字符串
  7996. * @return { String } 已过滤后的结果字符串
  7997. * @example
  7998. * ```javascript
  7999. * UE.filterWord(html);
  8000. * ```
  8001. */
  8002. var filterWord = UE.filterWord = function () {
  8003. //是否是word过来的内容
  8004. function isWordDocument( str ) {
  8005. return /(class="?Mso|style="[^"]*\bmso\-|w:WordDocument|<(v|o):|lang=)/ig.test( str );
  8006. }
  8007. //去掉小数
  8008. function transUnit( v ) {
  8009. v = v.replace( /[\d.]+\w+/g, function ( m ) {
  8010. return utils.transUnitToPx(m);
  8011. } );
  8012. return v;
  8013. }
  8014. function filterPasteWord( str ) {
  8015. return str.replace(/[\t\r\n]+/g,' ')
  8016. .replace( /<!--[\s\S]*?-->/ig, "" )
  8017. //转换图片
  8018. .replace(/<v:shape [^>]*>[\s\S]*?.<\/v:shape>/gi,function(str){
  8019. //opera能自己解析出image所这里直接返回空
  8020. if(browser.opera){
  8021. return '';
  8022. }
  8023. try{
  8024. //有可能是bitmap占为图,无用,直接过滤掉,主要体现在粘贴excel表格中
  8025. if(/Bitmap/i.test(str)){
  8026. return '';
  8027. }
  8028. var width = str.match(/width:([ \d.]*p[tx])/i)[1],
  8029. height = str.match(/height:([ \d.]*p[tx])/i)[1],
  8030. src = str.match(/src=\s*"([^"]*)"/i)[1];
  8031. return '<img width="'+ transUnit(width) +'" height="'+transUnit(height) +'" src="' + src + '" />';
  8032. } catch(e){
  8033. return '';
  8034. }
  8035. })
  8036. //针对wps添加的多余标签处理
  8037. .replace(/<\/?div[^>]*>/g,'')
  8038. //去掉多余的属性
  8039. .replace( /v:\w+=(["']?)[^'"]+\1/g, '' )
  8040. .replace( /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|xml|meta|link|style|\w+:\w+)(?=[\s\/>]))[^>]*>/gi, "" )
  8041. .replace( /<p [^>]*class="?MsoHeading"?[^>]*>(.*?)<\/p>/gi, "<p><strong>$1</strong></p>" )
  8042. //去掉多余的属性
  8043. .replace( /\s+(class|lang|align)\s*=\s*(['"]?)([\w-]+)\2/ig, function(str,name,marks,val){
  8044. //保留list的标示
  8045. return name == 'class' && val == 'MsoListParagraph' ? str : ''
  8046. })
  8047. //清除多余的font/span不能匹配&nbsp;有可能是空格
  8048. .replace( /<(font|span)[^>]*>(\s*)<\/\1>/gi, function(a,b,c){
  8049. return c.replace(/[\t\r\n ]+/g,' ')
  8050. })
  8051. //处理style的问题
  8052. .replace( /(<[a-z][^>]*)\sstyle=(["'])([^\2]*?)\2/gi, function( str, tag, tmp, style ) {
  8053. var n = [],
  8054. s = style.replace( /^\s+|\s+$/, '' )
  8055. .replace(/&#39;/g,'\'')
  8056. .replace( /&quot;/gi, "'" )
  8057. .replace(/[\d.]+(cm|pt)/g,function(str){
  8058. return utils.transUnitToPx(str)
  8059. })
  8060. .split( /;\s*/g );
  8061. for ( var i = 0,v; v = s[i];i++ ) {
  8062. var name, value,
  8063. parts = v.split( ":" );
  8064. if ( parts.length == 2 ) {
  8065. name = parts[0].toLowerCase();
  8066. value = parts[1].toLowerCase();
  8067. if(/^(background)\w*/.test(name) && value.replace(/(initial|\s)/g,'').length == 0
  8068. ||
  8069. /^(margin)\w*/.test(name) && /^0\w+$/.test(value)
  8070. ){
  8071. continue;
  8072. }
  8073. switch ( name ) {
  8074. case "mso-padding-alt":
  8075. case "mso-padding-top-alt":
  8076. case "mso-padding-right-alt":
  8077. case "mso-padding-bottom-alt":
  8078. case "mso-padding-left-alt":
  8079. case "mso-margin-alt":
  8080. case "mso-margin-top-alt":
  8081. case "mso-margin-right-alt":
  8082. case "mso-margin-bottom-alt":
  8083. case "mso-margin-left-alt":
  8084. //ie下会出现挤到一起的情况
  8085. //case "mso-table-layout-alt":
  8086. case "mso-height":
  8087. case "mso-width":
  8088. case "mso-vertical-align-alt":
  8089. //trace:1819 ff下会解析出padding在table上
  8090. if(!/<table/.test(tag))
  8091. n[i] = name.replace( /^mso-|-alt$/g, "" ) + ":" + transUnit( value );
  8092. continue;
  8093. case "horiz-align":
  8094. n[i] = "text-align:" + value;
  8095. continue;
  8096. case "vert-align":
  8097. n[i] = "vertical-align:" + value;
  8098. continue;
  8099. case "font-color":
  8100. case "mso-foreground":
  8101. n[i] = "color:" + value;
  8102. continue;
  8103. case "mso-background":
  8104. case "mso-highlight":
  8105. n[i] = "background:" + value;
  8106. continue;
  8107. case "mso-default-height":
  8108. n[i] = "min-height:" + transUnit( value );
  8109. continue;
  8110. case "mso-default-width":
  8111. n[i] = "min-width:" + transUnit( value );
  8112. continue;
  8113. case "mso-padding-between-alt":
  8114. n[i] = "border-collapse:separate;border-spacing:" + transUnit( value );
  8115. continue;
  8116. case "text-line-through":
  8117. if ( (value == "single") || (value == "double") ) {
  8118. n[i] = "text-decoration:line-through";
  8119. }
  8120. continue;
  8121. case "mso-zero-height":
  8122. if ( value == "yes" ) {
  8123. n[i] = "display:none";
  8124. }
  8125. continue;
  8126. // case 'background':
  8127. // break;
  8128. case 'margin':
  8129. if ( !/[1-9]/.test( value ) ) {
  8130. continue;
  8131. }
  8132. }
  8133. 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 )
  8134. ||
  8135. /text\-indent|padding|margin/.test(name) && /\-[\d.]+/.test(value)
  8136. ) {
  8137. continue;
  8138. }
  8139. n[i] = name + ":" + parts[1];
  8140. }
  8141. }
  8142. return tag + (n.length ? ' style="' + n.join( ';').replace(/;{2,}/g,';') + '"' : '');
  8143. })
  8144. }
  8145. return function ( html ) {
  8146. return (isWordDocument( html ) ? filterPasteWord( html ) : html);
  8147. };
  8148. }();
  8149. // core/node.js
  8150. /**
  8151. * 编辑器模拟的节点类
  8152. * @file
  8153. * @module UE
  8154. * @class uNode
  8155. * @since 1.2.6.1
  8156. */
  8157. /**
  8158. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  8159. * @unfile
  8160. * @module UE
  8161. */
  8162. (function () {
  8163. /**
  8164. * 编辑器模拟的节点类
  8165. * @unfile
  8166. * @module UE
  8167. * @class uNode
  8168. */
  8169. /**
  8170. * 通过一个键值对,创建一个uNode对象
  8171. * @constructor
  8172. * @param { Object } attr 传入要创建的uNode的初始属性
  8173. * @example
  8174. * ```javascript
  8175. * var node = new uNode({
  8176. * type:'element',
  8177. * tagName:'span',
  8178. * attrs:{style:'font-size:14px;'}
  8179. * }
  8180. * ```
  8181. */
  8182. var uNode = UE.uNode = function (obj) {
  8183. this.type = obj.type;
  8184. this.data = obj.data;
  8185. this.tagName = obj.tagName;
  8186. this.parentNode = obj.parentNode;
  8187. this.attrs = obj.attrs || {};
  8188. this.children = obj.children;
  8189. };
  8190. var notTransAttrs = {
  8191. 'href':1,
  8192. 'src':1,
  8193. '_src':1,
  8194. '_href':1,
  8195. 'cdata_data':1
  8196. };
  8197. var notTransTagName = {
  8198. style:1,
  8199. script:1
  8200. };
  8201. var indentChar = ' ',
  8202. breakChar = '\n';
  8203. function insertLine(arr, current, begin) {
  8204. arr.push(breakChar);
  8205. return current + (begin ? 1 : -1);
  8206. }
  8207. function insertIndent(arr, current) {
  8208. //插入缩进
  8209. for (var i = 0; i < current; i++) {
  8210. arr.push(indentChar);
  8211. }
  8212. }
  8213. //创建uNode的静态方法
  8214. //支持标签和html
  8215. uNode.createElement = function (html) {
  8216. if (/[<>]/.test(html)) {
  8217. return UE.htmlparser(html).children[0]
  8218. } else {
  8219. return new uNode({
  8220. type:'element',
  8221. children:[],
  8222. tagName:html
  8223. })
  8224. }
  8225. };
  8226. uNode.createText = function (data,noTrans) {
  8227. return new UE.uNode({
  8228. type:'text',
  8229. 'data':noTrans ? data : utils.unhtml(data || '')
  8230. })
  8231. };
  8232. function nodeToHtml(node, arr, formatter, current) {
  8233. switch (node.type) {
  8234. case 'root':
  8235. for (var i = 0, ci; ci = node.children[i++];) {
  8236. //插入新行
  8237. if (formatter && ci.type == 'element' && !dtd.$inlineWithA[ci.tagName] && i > 1) {
  8238. insertLine(arr, current, true);
  8239. insertIndent(arr, current)
  8240. }
  8241. nodeToHtml(ci, arr, formatter, current)
  8242. }
  8243. break;
  8244. case 'text':
  8245. isText(node, arr);
  8246. break;
  8247. case 'element':
  8248. isElement(node, arr, formatter, current);
  8249. break;
  8250. case 'comment':
  8251. isComment(node, arr, formatter);
  8252. }
  8253. return arr;
  8254. }
  8255. function isText(node, arr) {
  8256. if(node.parentNode.tagName == 'pre'){
  8257. //源码模式下输入html标签,不能做转换处理,直接输出
  8258. arr.push(node.data)
  8259. }else{
  8260. arr.push(notTransTagName[node.parentNode.tagName] ? utils.html(node.data) : node.data.replace(/[ ]{2}/g,' &nbsp;'))
  8261. }
  8262. }
  8263. function isElement(node, arr, formatter, current) {
  8264. var attrhtml = '';
  8265. if (node.attrs) {
  8266. attrhtml = [];
  8267. var attrs = node.attrs;
  8268. for (var a in attrs) {
  8269. //这里就针对
  8270. //<p>'<img src='http://nsclick.baidu.com/u.gif?&asdf=\"sdf&asdfasdfs;asdf'></p>
  8271. //这里边的\"做转换,要不用innerHTML直接被截断了,属性src
  8272. //有可能做的不够
  8273. attrhtml.push(a + (attrs[a] !== undefined ? '="' + (notTransAttrs[a] ? utils.html(attrs[a]).replace(/["]/g, function (a) {
  8274. return '&quot;'
  8275. }) : utils.unhtml(attrs[a])) + '"' : ''))
  8276. }
  8277. attrhtml = attrhtml.join(' ');
  8278. }
  8279. arr.push('<' + node.tagName +
  8280. (attrhtml ? ' ' + attrhtml : '') +
  8281. (dtd.$empty[node.tagName] ? '\/' : '' ) + '>'
  8282. );
  8283. //插入新行
  8284. if (formatter && !dtd.$inlineWithA[node.tagName] && node.tagName != 'pre') {
  8285. if(node.children && node.children.length){
  8286. current = insertLine(arr, current, true);
  8287. insertIndent(arr, current)
  8288. }
  8289. }
  8290. if (node.children && node.children.length) {
  8291. for (var i = 0, ci; ci = node.children[i++];) {
  8292. if (formatter && ci.type == 'element' && !dtd.$inlineWithA[ci.tagName] && i > 1) {
  8293. insertLine(arr, current);
  8294. insertIndent(arr, current)
  8295. }
  8296. nodeToHtml(ci, arr, formatter, current)
  8297. }
  8298. }
  8299. if (!dtd.$empty[node.tagName]) {
  8300. if (formatter && !dtd.$inlineWithA[node.tagName] && node.tagName != 'pre') {
  8301. if(node.children && node.children.length){
  8302. current = insertLine(arr, current);
  8303. insertIndent(arr, current)
  8304. }
  8305. }
  8306. arr.push('<\/' + node.tagName + '>');
  8307. }
  8308. }
  8309. function isComment(node, arr) {
  8310. arr.push('<!--' + node.data + '-->');
  8311. }
  8312. function getNodeById(root, id) {
  8313. var node;
  8314. if (root.type == 'element' && root.getAttr('id') == id) {
  8315. return root;
  8316. }
  8317. if (root.children && root.children.length) {
  8318. for (var i = 0, ci; ci = root.children[i++];) {
  8319. if (node = getNodeById(ci, id)) {
  8320. return node;
  8321. }
  8322. }
  8323. }
  8324. }
  8325. function getNodesByTagName(node, tagName, arr) {
  8326. if (node.type == 'element' && node.tagName == tagName) {
  8327. arr.push(node);
  8328. }
  8329. if (node.children && node.children.length) {
  8330. for (var i = 0, ci; ci = node.children[i++];) {
  8331. getNodesByTagName(ci, tagName, arr)
  8332. }
  8333. }
  8334. }
  8335. function nodeTraversal(root,fn){
  8336. if(root.children && root.children.length){
  8337. for(var i= 0,ci;ci=root.children[i];){
  8338. nodeTraversal(ci,fn);
  8339. //ci被替换的情况,这里就不再走 fn了
  8340. if(ci.parentNode ){
  8341. if(ci.children && ci.children.length){
  8342. fn(ci)
  8343. }
  8344. if(ci.parentNode) i++
  8345. }
  8346. }
  8347. }else{
  8348. fn(root)
  8349. }
  8350. }
  8351. uNode.prototype = {
  8352. /**
  8353. * 当前节点对象,转换成html文本
  8354. * @method toHtml
  8355. * @return { String } 返回转换后的html字符串
  8356. * @example
  8357. * ```javascript
  8358. * node.toHtml();
  8359. * ```
  8360. */
  8361. /**
  8362. * 当前节点对象,转换成html文本
  8363. * @method toHtml
  8364. * @param { Boolean } formatter 是否格式化返回值
  8365. * @return { String } 返回转换后的html字符串
  8366. * @example
  8367. * ```javascript
  8368. * node.toHtml( true );
  8369. * ```
  8370. */
  8371. toHtml:function (formatter) {
  8372. var arr = [];
  8373. nodeToHtml(this, arr, formatter, 0);
  8374. return arr.join('')
  8375. },
  8376. /**
  8377. * 获取节点的html内容
  8378. * @method innerHTML
  8379. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  8380. * @return { String } 返回节点的html内容
  8381. * @example
  8382. * ```javascript
  8383. * var htmlstr = node.innerHTML();
  8384. * ```
  8385. */
  8386. /**
  8387. * 设置节点的html内容
  8388. * @method innerHTML
  8389. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  8390. * @param { String } htmlstr 传入要设置的html内容
  8391. * @return { UE.uNode } 返回节点本身
  8392. * @example
  8393. * ```javascript
  8394. * node.innerHTML('<span>text</span>');
  8395. * ```
  8396. */
  8397. innerHTML:function (htmlstr) {
  8398. if (this.type != 'element' || dtd.$empty[this.tagName]) {
  8399. return this;
  8400. }
  8401. if (utils.isString(htmlstr)) {
  8402. if(this.children){
  8403. for (var i = 0, ci; ci = this.children[i++];) {
  8404. ci.parentNode = null;
  8405. }
  8406. }
  8407. this.children = [];
  8408. var tmpRoot = UE.htmlparser(htmlstr);
  8409. for (var i = 0, ci; ci = tmpRoot.children[i++];) {
  8410. this.children.push(ci);
  8411. ci.parentNode = this;
  8412. }
  8413. return this;
  8414. } else {
  8415. var tmpRoot = new UE.uNode({
  8416. type:'root',
  8417. children:this.children
  8418. });
  8419. return tmpRoot.toHtml();
  8420. }
  8421. },
  8422. /**
  8423. * 获取节点的纯文本内容
  8424. * @method innerText
  8425. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  8426. * @return { String } 返回节点的存文本内容
  8427. * @example
  8428. * ```javascript
  8429. * var textStr = node.innerText();
  8430. * ```
  8431. */
  8432. /**
  8433. * 设置节点的纯文本内容
  8434. * @method innerText
  8435. * @warning 假如节点的type不是'element',或节点的标签名称不在dtd列表里,直接返回当前节点
  8436. * @param { String } textStr 传入要设置的文本内容
  8437. * @return { UE.uNode } 返回节点本身
  8438. * @example
  8439. * ```javascript
  8440. * node.innerText('<span>text</span>');
  8441. * ```
  8442. */
  8443. innerText:function (textStr,noTrans) {
  8444. if (this.type != 'element' || dtd.$empty[this.tagName]) {
  8445. return this;
  8446. }
  8447. if (textStr) {
  8448. if(this.children){
  8449. for (var i = 0, ci; ci = this.children[i++];) {
  8450. ci.parentNode = null;
  8451. }
  8452. }
  8453. this.children = [];
  8454. this.appendChild(uNode.createText(textStr,noTrans));
  8455. return this;
  8456. } else {
  8457. return this.toHtml().replace(/<[^>]+>/g, '');
  8458. }
  8459. },
  8460. /**
  8461. * 获取当前对象的data属性
  8462. * @method getData
  8463. * @return { Object } 若节点的type值是elemenet,返回空字符串,否则返回节点的data属性
  8464. * @example
  8465. * ```javascript
  8466. * node.getData();
  8467. * ```
  8468. */
  8469. getData:function () {
  8470. if (this.type == 'element')
  8471. return '';
  8472. return this.data
  8473. },
  8474. /**
  8475. * 获取当前节点下的第一个子节点
  8476. * @method firstChild
  8477. * @return { UE.uNode } 返回第一个子节点
  8478. * @example
  8479. * ```javascript
  8480. * node.firstChild(); //返回第一个子节点
  8481. * ```
  8482. */
  8483. firstChild:function () {
  8484. // if (this.type != 'element' || dtd.$empty[this.tagName]) {
  8485. // return this;
  8486. // }
  8487. return this.children ? this.children[0] : null;
  8488. },
  8489. /**
  8490. * 获取当前节点下的最后一个子节点
  8491. * @method lastChild
  8492. * @return { UE.uNode } 返回最后一个子节点
  8493. * @example
  8494. * ```javascript
  8495. * node.lastChild(); //返回最后一个子节点
  8496. * ```
  8497. */
  8498. lastChild:function () {
  8499. // if (this.type != 'element' || dtd.$empty[this.tagName] ) {
  8500. // return this;
  8501. // }
  8502. return this.children ? this.children[this.children.length - 1] : null;
  8503. },
  8504. /**
  8505. * 获取和当前节点有相同父亲节点的前一个节点
  8506. * @method previousSibling
  8507. * @return { UE.uNode } 返回前一个节点
  8508. * @example
  8509. * ```javascript
  8510. * node.children[2].previousSibling(); //返回子节点node.children[1]
  8511. * ```
  8512. */
  8513. previousSibling : function(){
  8514. var parent = this.parentNode;
  8515. for (var i = 0, ci; ci = parent.children[i]; i++) {
  8516. if (ci === this) {
  8517. return i == 0 ? null : parent.children[i-1];
  8518. }
  8519. }
  8520. },
  8521. /**
  8522. * 获取和当前节点有相同父亲节点的后一个节点
  8523. * @method nextSibling
  8524. * @return { UE.uNode } 返回后一个节点,找不到返回null
  8525. * @example
  8526. * ```javascript
  8527. * node.children[2].nextSibling(); //如果有,返回子节点node.children[3]
  8528. * ```
  8529. */
  8530. nextSibling : function(){
  8531. var parent = this.parentNode;
  8532. for (var i = 0, ci; ci = parent.children[i++];) {
  8533. if (ci === this) {
  8534. return parent.children[i];
  8535. }
  8536. }
  8537. },
  8538. /**
  8539. * 用新的节点替换当前节点
  8540. * @method replaceChild
  8541. * @param { UE.uNode } target 要替换成该节点参数
  8542. * @param { UE.uNode } source 要被替换掉的节点
  8543. * @return { UE.uNode } 返回替换之后的节点对象
  8544. * @example
  8545. * ```javascript
  8546. * node.replaceChild(newNode, childNode); //用newNode替换childNode,childNode是node的子节点
  8547. * ```
  8548. */
  8549. replaceChild:function (target, source) {
  8550. if (this.children) {
  8551. if(target.parentNode){
  8552. target.parentNode.removeChild(target);
  8553. }
  8554. for (var i = 0, ci; ci = this.children[i]; i++) {
  8555. if (ci === source) {
  8556. this.children.splice(i, 1, target);
  8557. source.parentNode = null;
  8558. target.parentNode = this;
  8559. return target;
  8560. }
  8561. }
  8562. }
  8563. },
  8564. /**
  8565. * 在节点的子节点列表最后位置插入一个节点
  8566. * @method appendChild
  8567. * @param { UE.uNode } node 要插入的节点
  8568. * @return { UE.uNode } 返回刚插入的子节点
  8569. * @example
  8570. * ```javascript
  8571. * node.appendChild( newNode ); //在node内插入子节点newNode
  8572. * ```
  8573. */
  8574. appendChild:function (node) {
  8575. if (this.type == 'root' || (this.type == 'element' && !dtd.$empty[this.tagName])) {
  8576. if (!this.children) {
  8577. this.children = []
  8578. }
  8579. if(node.parentNode){
  8580. node.parentNode.removeChild(node);
  8581. }
  8582. for (var i = 0, ci; ci = this.children[i]; i++) {
  8583. if (ci === node) {
  8584. this.children.splice(i, 1);
  8585. break;
  8586. }
  8587. }
  8588. this.children.push(node);
  8589. node.parentNode = this;
  8590. return node;
  8591. }
  8592. },
  8593. /**
  8594. * 在传入节点的前面插入一个节点
  8595. * @method insertBefore
  8596. * @param { UE.uNode } target 要插入的节点
  8597. * @param { UE.uNode } source 在该参数节点前面插入
  8598. * @return { UE.uNode } 返回刚插入的子节点
  8599. * @example
  8600. * ```javascript
  8601. * node.parentNode.insertBefore(newNode, node); //在node节点后面插入newNode
  8602. * ```
  8603. */
  8604. insertBefore:function (target, source) {
  8605. if (this.children) {
  8606. if(target.parentNode){
  8607. target.parentNode.removeChild(target);
  8608. }
  8609. for (var i = 0, ci; ci = this.children[i]; i++) {
  8610. if (ci === source) {
  8611. this.children.splice(i, 0, target);
  8612. target.parentNode = this;
  8613. return target;
  8614. }
  8615. }
  8616. }
  8617. },
  8618. /**
  8619. * 在传入节点的后面插入一个节点
  8620. * @method insertAfter
  8621. * @param { UE.uNode } target 要插入的节点
  8622. * @param { UE.uNode } source 在该参数节点后面插入
  8623. * @return { UE.uNode } 返回刚插入的子节点
  8624. * @example
  8625. * ```javascript
  8626. * node.parentNode.insertAfter(newNode, node); //在node节点后面插入newNode
  8627. * ```
  8628. */
  8629. insertAfter:function (target, source) {
  8630. if (this.children) {
  8631. if(target.parentNode){
  8632. target.parentNode.removeChild(target);
  8633. }
  8634. for (var i = 0, ci; ci = this.children[i]; i++) {
  8635. if (ci === source) {
  8636. this.children.splice(i + 1, 0, target);
  8637. target.parentNode = this;
  8638. return target;
  8639. }
  8640. }
  8641. }
  8642. },
  8643. /**
  8644. * 从当前节点的子节点列表中,移除节点
  8645. * @method removeChild
  8646. * @param { UE.uNode } node 要移除的节点引用
  8647. * @param { Boolean } keepChildren 是否保留移除节点的子节点,若传入true,自动把移除节点的子节点插入到移除的位置
  8648. * @return { * } 返回刚移除的子节点
  8649. * @example
  8650. * ```javascript
  8651. * node.removeChild(childNode,true); //在node的子节点列表中移除child节点,并且吧child的子节点插入到移除的位置
  8652. * ```
  8653. */
  8654. removeChild:function (node,keepChildren) {
  8655. if (this.children) {
  8656. for (var i = 0, ci; ci = this.children[i]; i++) {
  8657. if (ci === node) {
  8658. this.children.splice(i, 1);
  8659. ci.parentNode = null;
  8660. if(keepChildren && ci.children && ci.children.length){
  8661. for(var j= 0,cj;cj=ci.children[j];j++){
  8662. this.children.splice(i+j,0,cj);
  8663. cj.parentNode = this;
  8664. }
  8665. }
  8666. return ci;
  8667. }
  8668. }
  8669. }
  8670. },
  8671. /**
  8672. * 获取当前节点所代表的元素属性,即获取attrs对象下的属性值
  8673. * @method getAttr
  8674. * @param { String } attrName 要获取的属性名称
  8675. * @return { * } 返回attrs对象下的属性值
  8676. * @example
  8677. * ```javascript
  8678. * node.getAttr('title');
  8679. * ```
  8680. */
  8681. getAttr:function (attrName) {
  8682. return this.attrs && this.attrs[attrName.toLowerCase()]
  8683. },
  8684. /**
  8685. * 设置当前节点所代表的元素属性,即设置attrs对象下的属性值
  8686. * @method setAttr
  8687. * @param { String } attrName 要设置的属性名称
  8688. * @param { * } attrVal 要设置的属性值,类型视设置的属性而定
  8689. * @return { * } 返回attrs对象下的属性值
  8690. * @example
  8691. * ```javascript
  8692. * node.setAttr('title','标题');
  8693. * ```
  8694. */
  8695. setAttr:function (attrName, attrVal) {
  8696. if (!attrName) {
  8697. delete this.attrs;
  8698. return;
  8699. }
  8700. if(!this.attrs){
  8701. this.attrs = {};
  8702. }
  8703. if (utils.isObject(attrName)) {
  8704. for (var a in attrName) {
  8705. if (!attrName[a]) {
  8706. delete this.attrs[a]
  8707. } else {
  8708. this.attrs[a.toLowerCase()] = attrName[a];
  8709. }
  8710. }
  8711. } else {
  8712. if (!attrVal) {
  8713. delete this.attrs[attrName]
  8714. } else {
  8715. this.attrs[attrName.toLowerCase()] = attrVal;
  8716. }
  8717. }
  8718. },
  8719. /**
  8720. * 获取当前节点在父节点下的位置索引
  8721. * @method getIndex
  8722. * @return { Number } 返回索引数值,如果没有父节点,返回-1
  8723. * @example
  8724. * ```javascript
  8725. * node.getIndex();
  8726. * ```
  8727. */
  8728. getIndex:function(){
  8729. var parent = this.parentNode;
  8730. for(var i= 0,ci;ci=parent.children[i];i++){
  8731. if(ci === this){
  8732. return i;
  8733. }
  8734. }
  8735. return -1;
  8736. },
  8737. /**
  8738. * 在当前节点下,根据id查找节点
  8739. * @method getNodeById
  8740. * @param { String } id 要查找的id
  8741. * @return { UE.uNode } 返回找到的节点
  8742. * @example
  8743. * ```javascript
  8744. * node.getNodeById('textId');
  8745. * ```
  8746. */
  8747. getNodeById:function (id) {
  8748. var node;
  8749. if (this.children && this.children.length) {
  8750. for (var i = 0, ci; ci = this.children[i++];) {
  8751. if (node = getNodeById(ci, id)) {
  8752. return node;
  8753. }
  8754. }
  8755. }
  8756. },
  8757. /**
  8758. * 在当前节点下,根据元素名称查找节点列表
  8759. * @method getNodesByTagName
  8760. * @param { String } tagNames 要查找的元素名称
  8761. * @return { Array } 返回找到的节点列表
  8762. * @example
  8763. * ```javascript
  8764. * node.getNodesByTagName('span');
  8765. * ```
  8766. */
  8767. getNodesByTagName:function (tagNames) {
  8768. tagNames = utils.trim(tagNames).replace(/[ ]{2,}/g, ' ').split(' ');
  8769. var arr = [], me = this;
  8770. utils.each(tagNames, function (tagName) {
  8771. if (me.children && me.children.length) {
  8772. for (var i = 0, ci; ci = me.children[i++];) {
  8773. getNodesByTagName(ci, tagName, arr)
  8774. }
  8775. }
  8776. });
  8777. return arr;
  8778. },
  8779. /**
  8780. * 根据样式名称,获取节点的样式值
  8781. * @method getStyle
  8782. * @param { String } name 要获取的样式名称
  8783. * @return { String } 返回样式值
  8784. * @example
  8785. * ```javascript
  8786. * node.getStyle('font-size');
  8787. * ```
  8788. */
  8789. getStyle:function (name) {
  8790. var cssStyle = this.getAttr('style');
  8791. if (!cssStyle) {
  8792. return ''
  8793. }
  8794. var reg = new RegExp('(^|;)\\s*' + name + ':([^;]+)','i');
  8795. var match = cssStyle.match(reg);
  8796. if (match && match[0]) {
  8797. return match[2]
  8798. }
  8799. return '';
  8800. },
  8801. /**
  8802. * 给节点设置样式
  8803. * @method setStyle
  8804. * @param { String } name 要设置的的样式名称
  8805. * @param { String } val 要设置的的样值
  8806. * @example
  8807. * ```javascript
  8808. * node.setStyle('font-size', '12px');
  8809. * ```
  8810. */
  8811. setStyle:function (name, val) {
  8812. function exec(name, val) {
  8813. var reg = new RegExp('(^|;)\\s*' + name + ':([^;]+;?)', 'gi');
  8814. cssStyle = cssStyle.replace(reg, '$1');
  8815. if (val) {
  8816. cssStyle = name + ':' + utils.unhtml(val) + ';' + cssStyle
  8817. }
  8818. }
  8819. var cssStyle = this.getAttr('style');
  8820. if (!cssStyle) {
  8821. cssStyle = '';
  8822. }
  8823. if (utils.isObject(name)) {
  8824. for (var a in name) {
  8825. exec(a, name[a])
  8826. }
  8827. } else {
  8828. exec(name, val)
  8829. }
  8830. this.setAttr('style', utils.trim(cssStyle))
  8831. },
  8832. /**
  8833. * 传入一个函数,递归遍历当前节点下的所有节点
  8834. * @method traversal
  8835. * @param { Function } fn 遍历到节点的时,传入节点作为参数,运行此函数
  8836. * @example
  8837. * ```javascript
  8838. * traversal(node, function(){
  8839. * //console.log(node.type);
  8840. * });
  8841. * ```
  8842. */
  8843. traversal:function(fn){
  8844. if(this.children && this.children.length){
  8845. nodeTraversal(this,fn);
  8846. }
  8847. return this;
  8848. }
  8849. }
  8850. })();
  8851. // core/htmlparser.js
  8852. /**
  8853. * html字符串转换成uNode节点
  8854. * @file
  8855. * @module UE
  8856. * @since 1.2.6.1
  8857. */
  8858. /**
  8859. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  8860. * @unfile
  8861. * @module UE
  8862. */
  8863. /**
  8864. * html字符串转换成uNode节点的静态方法
  8865. * @method htmlparser
  8866. * @param { String } htmlstr 要转换的html代码
  8867. * @param { Boolean } ignoreBlank 若设置为true,转换的时候忽略\n\r\t等空白字符
  8868. * @return { uNode } 给定的html片段转换形成的uNode对象
  8869. * @example
  8870. * ```javascript
  8871. * var root = UE.htmlparser('<p><b>htmlparser</b></p>', true);
  8872. * ```
  8873. */
  8874. var htmlparser = UE.htmlparser = function (htmlstr,ignoreBlank) {
  8875. //todo 原来的方式 [^"'<>\/] 有\/就不能配对上 <TD vAlign=top background=../AAA.JPG> 这样的标签了
  8876. //先去掉了,加上的原因忘了,这里先记录
  8877. var re_tag = /<(?:(?:\/([^>]+)>)|(?:!--([\S|\s]*?)-->)|(?:([^\s\/<>]+)\s*((?:(?:"[^"]*")|(?:'[^']*')|[^"'<>])*)\/?>))/g,
  8878. re_attr = /([\w\-:.]+)(?:(?:\s*=\s*(?:(?:"([^"]*)")|(?:'([^']*)')|([^\s>]+)))|(?=\s|$))/g;
  8879. //ie下取得的html可能会有\n存在,要去掉,在处理replace(/[\t\r\n]*/g,'');代码高量的\n不能去除
  8880. var allowEmptyTags = {
  8881. b:1,code:1,i:1,u:1,strike:1,s:1,tt:1,strong:1,q:1,samp:1,em:1,span:1,
  8882. sub:1,img:1,sup:1,font:1,big:1,small:1,iframe:1,a:1,br:1,pre:1
  8883. };
  8884. htmlstr = htmlstr.replace(new RegExp(domUtils.fillChar, 'g'), '');
  8885. if(!ignoreBlank){
  8886. htmlstr = htmlstr.replace(new RegExp('[\\r\\t\\n'+(ignoreBlank?'':' ')+']*<\/?(\\w+)\\s*(?:[^>]*)>[\\r\\t\\n'+(ignoreBlank?'':' ')+']*','g'), function(a,b){
  8887. //br暂时单独处理
  8888. if(b && allowEmptyTags[b.toLowerCase()]){
  8889. return a.replace(/(^[\n\r]+)|([\n\r]+$)/g,'');
  8890. }
  8891. return a.replace(new RegExp('^[\\r\\n'+(ignoreBlank?'':' ')+']+'),'').replace(new RegExp('[\\r\\n'+(ignoreBlank?'':' ')+']+$'),'');
  8892. });
  8893. }
  8894. var notTransAttrs = {
  8895. 'href':1,
  8896. 'src':1
  8897. };
  8898. var uNode = UE.uNode,
  8899. needParentNode = {
  8900. 'td':'tr',
  8901. 'tr':['tbody','thead','tfoot'],
  8902. 'tbody':'table',
  8903. 'th':'tr',
  8904. 'thead':'table',
  8905. 'tfoot':'table',
  8906. 'caption':'table',
  8907. 'li':['ul', 'ol'],
  8908. 'dt':'dl',
  8909. 'dd':'dl',
  8910. 'option':'select'
  8911. },
  8912. needChild = {
  8913. 'ol':'li',
  8914. 'ul':'li'
  8915. };
  8916. function text(parent, data) {
  8917. if(needChild[parent.tagName]){
  8918. var tmpNode = uNode.createElement(needChild[parent.tagName]);
  8919. parent.appendChild(tmpNode);
  8920. tmpNode.appendChild(uNode.createText(data));
  8921. parent = tmpNode;
  8922. }else{
  8923. parent.appendChild(uNode.createText(data));
  8924. }
  8925. }
  8926. function element(parent, tagName, htmlattr) {
  8927. var needParentTag;
  8928. if (needParentTag = needParentNode[tagName]) {
  8929. var tmpParent = parent,hasParent;
  8930. while(tmpParent.type != 'root'){
  8931. if(utils.isArray(needParentTag) ? utils.indexOf(needParentTag, tmpParent.tagName) != -1 : needParentTag == tmpParent.tagName){
  8932. parent = tmpParent;
  8933. hasParent = true;
  8934. break;
  8935. }
  8936. tmpParent = tmpParent.parentNode;
  8937. }
  8938. if(!hasParent){
  8939. parent = element(parent, utils.isArray(needParentTag) ? needParentTag[0] : needParentTag)
  8940. }
  8941. }
  8942. //按dtd处理嵌套
  8943. // if(parent.type != 'root' && !dtd[parent.tagName][tagName])
  8944. // parent = parent.parentNode;
  8945. var elm = new uNode({
  8946. parentNode:parent,
  8947. type:'element',
  8948. tagName:tagName.toLowerCase(),
  8949. //是自闭合的处理一下
  8950. children:dtd.$empty[tagName] ? null : []
  8951. });
  8952. //如果属性存在,处理属性
  8953. if (htmlattr) {
  8954. var attrs = {}, match;
  8955. while (match = re_attr.exec(htmlattr)) {
  8956. attrs[match[1].toLowerCase()] = notTransAttrs[match[1].toLowerCase()] ? (match[2] || match[3] || match[4]) : utils.unhtml(match[2] || match[3] || match[4])
  8957. }
  8958. elm.attrs = attrs;
  8959. }
  8960. //trace:3970
  8961. // //如果parent下不能放elm
  8962. // if(dtd.$inline[parent.tagName] && dtd.$block[elm.tagName] && !dtd[parent.tagName][elm.tagName]){
  8963. // parent = parent.parentNode;
  8964. // elm.parentNode = parent;
  8965. // }
  8966. parent.children.push(elm);
  8967. //如果是自闭合节点返回父亲节点
  8968. return dtd.$empty[tagName] ? parent : elm
  8969. }
  8970. function comment(parent, data) {
  8971. parent.children.push(new uNode({
  8972. type:'comment',
  8973. data:data,
  8974. parentNode:parent
  8975. }));
  8976. }
  8977. var match, currentIndex = 0, nextIndex = 0;
  8978. //设置根节点
  8979. var root = new uNode({
  8980. type:'root',
  8981. children:[]
  8982. });
  8983. var currentParent = root;
  8984. while (match = re_tag.exec(htmlstr)) {
  8985. currentIndex = match.index;
  8986. try{
  8987. if (currentIndex > nextIndex) {
  8988. //text node
  8989. text(currentParent, htmlstr.slice(nextIndex, currentIndex));
  8990. }
  8991. if (match[3]) {
  8992. if(dtd.$cdata[currentParent.tagName]){
  8993. text(currentParent, match[0]);
  8994. }else{
  8995. //start tag
  8996. currentParent = element(currentParent, match[3].toLowerCase(), match[4]);
  8997. }
  8998. } else if (match[1]) {
  8999. if(currentParent.type != 'root'){
  9000. if(dtd.$cdata[currentParent.tagName] && !dtd.$cdata[match[1]]){
  9001. text(currentParent, match[0]);
  9002. }else{
  9003. var tmpParent = currentParent;
  9004. while(currentParent.type == 'element' && currentParent.tagName != match[1].toLowerCase()){
  9005. currentParent = currentParent.parentNode;
  9006. if(currentParent.type == 'root'){
  9007. currentParent = tmpParent;
  9008. throw 'break'
  9009. }
  9010. }
  9011. //end tag
  9012. currentParent = currentParent.parentNode;
  9013. }
  9014. }
  9015. } else if (match[2]) {
  9016. //comment
  9017. comment(currentParent, match[2])
  9018. }
  9019. }catch(e){}
  9020. nextIndex = re_tag.lastIndex;
  9021. }
  9022. //如果结束是文本,就有可能丢掉,所以这里手动判断一下
  9023. //例如 <li>sdfsdfsdf<li>sdfsdfsdfsdf
  9024. if (nextIndex < htmlstr.length) {
  9025. text(currentParent, htmlstr.slice(nextIndex));
  9026. }
  9027. return root;
  9028. };
  9029. // core/filternode.js
  9030. /**
  9031. * UE过滤节点的静态方法
  9032. * @file
  9033. */
  9034. /**
  9035. * UEditor公用空间,UEditor所有的功能都挂载在该空间下
  9036. * @module UE
  9037. */
  9038. /**
  9039. * 根据传入节点和过滤规则过滤相应节点
  9040. * @module UE
  9041. * @since 1.2.6.1
  9042. * @method filterNode
  9043. * @param { Object } root 指定root节点
  9044. * @param { Object } rules 过滤规则json对象
  9045. * @example
  9046. * ```javascript
  9047. * UE.filterNode(root,editor.options.filterRules);
  9048. * ```
  9049. */
  9050. var filterNode = UE.filterNode = function () {
  9051. function filterNode(node,rules){
  9052. switch (node.type) {
  9053. case 'text':
  9054. break;
  9055. case 'element':
  9056. var val;
  9057. if(val = rules[node.tagName]){
  9058. if(val === '-'){
  9059. node.parentNode.removeChild(node)
  9060. }else if(utils.isFunction(val)){
  9061. var parentNode = node.parentNode,
  9062. index = node.getIndex();
  9063. val(node);
  9064. if(node.parentNode){
  9065. if(node.children){
  9066. for(var i = 0,ci;ci=node.children[i];){
  9067. filterNode(ci,rules);
  9068. if(ci.parentNode){
  9069. i++;
  9070. }
  9071. }
  9072. }
  9073. }else{
  9074. for(var i = index,ci;ci=parentNode.children[i];){
  9075. filterNode(ci,rules);
  9076. if(ci.parentNode){
  9077. i++;
  9078. }
  9079. }
  9080. }
  9081. }else{
  9082. var attrs = val['$'];
  9083. if(attrs && node.attrs){
  9084. var tmpAttrs = {},tmpVal;
  9085. for(var a in attrs){
  9086. tmpVal = node.getAttr(a);
  9087. //todo 只先对style单独处理
  9088. if(a == 'style' && utils.isArray(attrs[a])){
  9089. var tmpCssStyle = [];
  9090. utils.each(attrs[a],function(v){
  9091. var tmp;
  9092. if(tmp = node.getStyle(v)){
  9093. tmpCssStyle.push(v + ':' + tmp);
  9094. }
  9095. });
  9096. tmpVal = tmpCssStyle.join(';')
  9097. }
  9098. if(tmpVal){
  9099. tmpAttrs[a] = tmpVal;
  9100. }
  9101. }
  9102. node.attrs = tmpAttrs;
  9103. }
  9104. if(node.children){
  9105. for(var i = 0,ci;ci=node.children[i];){
  9106. filterNode(ci,rules);
  9107. if(ci.parentNode){
  9108. i++;
  9109. }
  9110. }
  9111. }
  9112. }
  9113. }else{
  9114. //如果不在名单里扣出子节点并删除该节点,cdata除外
  9115. if(dtd.$cdata[node.tagName]){
  9116. node.parentNode.removeChild(node)
  9117. }else{
  9118. var parentNode = node.parentNode,
  9119. index = node.getIndex();
  9120. node.parentNode.removeChild(node,true);
  9121. for(var i = index,ci;ci=parentNode.children[i];){
  9122. filterNode(ci,rules);
  9123. if(ci.parentNode){
  9124. i++;
  9125. }
  9126. }
  9127. }
  9128. }
  9129. break;
  9130. case 'comment':
  9131. node.parentNode.removeChild(node)
  9132. }
  9133. }
  9134. return function(root,rules){
  9135. if(utils.isEmptyObject(rules)){
  9136. return root;
  9137. }
  9138. var val;
  9139. if(val = rules['-']){
  9140. utils.each(val.split(' '),function(k){
  9141. rules[k] = '-'
  9142. })
  9143. }
  9144. for(var i= 0,ci;ci=root.children[i];){
  9145. filterNode(ci,rules);
  9146. if(ci.parentNode){
  9147. i++;
  9148. }
  9149. }
  9150. return root;
  9151. }
  9152. }();
  9153. // core/plugin.js
  9154. /**
  9155. * Created with JetBrains PhpStorm.
  9156. * User: campaign
  9157. * Date: 10/8/13
  9158. * Time: 6:15 PM
  9159. * To change this template use File | Settings | File Templates.
  9160. */
  9161. UE.plugin = function(){
  9162. var _plugins = {};
  9163. return {
  9164. register : function(pluginName,fn,oldOptionName,afterDisabled){
  9165. if(oldOptionName && utils.isFunction(oldOptionName)){
  9166. afterDisabled = oldOptionName;
  9167. oldOptionName = null
  9168. }
  9169. _plugins[pluginName] = {
  9170. optionName : oldOptionName || pluginName,
  9171. execFn : fn,
  9172. //当插件被禁用时执行
  9173. afterDisabled : afterDisabled
  9174. }
  9175. },
  9176. load : function(editor){
  9177. utils.each(_plugins,function(plugin){
  9178. var _export = plugin.execFn.call(editor);
  9179. if(editor.options[plugin.optionName] !== false){
  9180. if(_export){
  9181. //后边需要再做扩展
  9182. utils.each(_export,function(v,k){
  9183. switch(k.toLowerCase()){
  9184. case 'shortcutkey':
  9185. editor.addshortcutkey(v);
  9186. break;
  9187. case 'bindevents':
  9188. utils.each(v,function(fn,eventName){
  9189. editor.addListener(eventName,fn);
  9190. });
  9191. break;
  9192. case 'bindmultievents':
  9193. utils.each(utils.isArray(v) ? v:[v],function(event){
  9194. var types = utils.trim(event.type).split(/\s+/);
  9195. utils.each(types,function(eventName){
  9196. editor.addListener(eventName, event.handler);
  9197. });
  9198. });
  9199. break;
  9200. case 'commands':
  9201. utils.each(v,function(execFn,execName){
  9202. editor.commands[execName] = execFn
  9203. });
  9204. break;
  9205. case 'outputrule':
  9206. editor.addOutputRule(v);
  9207. break;
  9208. case 'inputrule':
  9209. editor.addInputRule(v);
  9210. break;
  9211. case 'defaultoptions':
  9212. editor.setOpt(v)
  9213. }
  9214. })
  9215. }
  9216. }else if(plugin.afterDisabled){
  9217. plugin.afterDisabled.call(editor)
  9218. }
  9219. });
  9220. //向下兼容
  9221. utils.each(UE.plugins,function(plugin){
  9222. plugin.call(editor);
  9223. });
  9224. },
  9225. run : function(pluginName,editor){
  9226. var plugin = _plugins[pluginName];
  9227. if(plugin){
  9228. plugin.exeFn.call(editor)
  9229. }
  9230. }
  9231. }
  9232. }();
  9233. // core/keymap.js
  9234. var keymap = UE.keymap = {
  9235. 'Backspace' : 8,
  9236. 'Tab' : 9,
  9237. 'Enter' : 13,
  9238. 'Shift':16,
  9239. 'Control':17,
  9240. 'Alt':18,
  9241. 'CapsLock':20,
  9242. 'Esc':27,
  9243. 'Spacebar':32,
  9244. 'PageUp':33,
  9245. 'PageDown':34,
  9246. 'End':35,
  9247. 'Home':36,
  9248. 'Left':37,
  9249. 'Up':38,
  9250. 'Right':39,
  9251. 'Down':40,
  9252. 'Insert':45,
  9253. 'Del':46,
  9254. 'NumLock':144,
  9255. 'Cmd':91,
  9256. '=':187,
  9257. '-':189,
  9258. "b":66,
  9259. 'i':73,
  9260. //回退
  9261. 'z':90,
  9262. 'y':89,
  9263. //粘贴
  9264. 'v' : 86,
  9265. 'x' : 88,
  9266. 's' : 83,
  9267. 'n' : 78
  9268. };
  9269. // core/localstorage.js
  9270. //存储媒介封装
  9271. var LocalStorage = UE.LocalStorage = (function () {
  9272. var storage = window.localStorage || getUserData() || null,
  9273. LOCAL_FILE = 'localStorage';
  9274. return {
  9275. saveLocalData: function (key, data) {
  9276. if (storage && data) {
  9277. storage.setItem(key, data);
  9278. return true;
  9279. }
  9280. return false;
  9281. },
  9282. getLocalData: function (key) {
  9283. if (storage) {
  9284. return storage.getItem(key);
  9285. }
  9286. return null;
  9287. },
  9288. removeItem: function (key) {
  9289. storage && storage.removeItem(key);
  9290. }
  9291. };
  9292. function getUserData() {
  9293. var container = document.createElement("div");
  9294. container.style.display = "none";
  9295. if (!container.addBehavior) {
  9296. return null;
  9297. }
  9298. container.addBehavior("#default#userdata");
  9299. return {
  9300. getItem: function (key) {
  9301. var result = null;
  9302. try {
  9303. document.body.appendChild(container);
  9304. container.load(LOCAL_FILE);
  9305. result = container.getAttribute(key);
  9306. document.body.removeChild(container);
  9307. } catch (e) {
  9308. }
  9309. return result;
  9310. },
  9311. setItem: function (key, value) {
  9312. document.body.appendChild(container);
  9313. container.setAttribute(key, value);
  9314. container.save(LOCAL_FILE);
  9315. document.body.removeChild(container);
  9316. },
  9317. //// 暂时没有用到
  9318. //clear: function () {
  9319. //
  9320. // var expiresTime = new Date();
  9321. // expiresTime.setFullYear(expiresTime.getFullYear() - 1);
  9322. // document.body.appendChild(container);
  9323. // container.expires = expiresTime.toUTCString();
  9324. // container.save(LOCAL_FILE);
  9325. // document.body.removeChild(container);
  9326. //
  9327. //},
  9328. removeItem: function (key) {
  9329. document.body.appendChild(container);
  9330. container.removeAttribute(key);
  9331. container.save(LOCAL_FILE);
  9332. document.body.removeChild(container);
  9333. }
  9334. };
  9335. }
  9336. })();
  9337. (function () {
  9338. var ROOTKEY = 'ueditor_preference';
  9339. UE.Editor.prototype.setPreferences = function(key,value){
  9340. var obj = {};
  9341. if (utils.isString(key)) {
  9342. obj[ key ] = value;
  9343. } else {
  9344. obj = key;
  9345. }
  9346. var data = LocalStorage.getLocalData(ROOTKEY);
  9347. if (data && (data = utils.str2json(data))) {
  9348. utils.extend(data, obj);
  9349. } else {
  9350. data = obj;
  9351. }
  9352. data && LocalStorage.saveLocalData(ROOTKEY, utils.json2str(data));
  9353. };
  9354. UE.Editor.prototype.getPreferences = function(key){
  9355. var data = LocalStorage.getLocalData(ROOTKEY);
  9356. if (data && (data = utils.str2json(data))) {
  9357. return key ? data[key] : data
  9358. }
  9359. return null;
  9360. };
  9361. UE.Editor.prototype.removePreferences = function (key) {
  9362. var data = LocalStorage.getLocalData(ROOTKEY);
  9363. if (data && (data = utils.str2json(data))) {
  9364. data[key] = undefined;
  9365. delete data[key]
  9366. }
  9367. data && LocalStorage.saveLocalData(ROOTKEY, utils.json2str(data));
  9368. };
  9369. })();
  9370. // plugins/defaultfilter.js
  9371. ///import core
  9372. ///plugin 编辑器默认的过滤转换机制
  9373. UE.plugins['defaultfilter'] = function () {
  9374. var me = this;
  9375. me.setOpt({
  9376. 'allowDivTransToP':true,
  9377. 'disabledTableInTable':true
  9378. });
  9379. //默认的过滤处理
  9380. //进入编辑器的内容处理
  9381. me.addInputRule(function (root) {
  9382. var allowDivTransToP = this.options.allowDivTransToP;
  9383. var val;
  9384. function tdParent(node){
  9385. while(node && node.type == 'element'){
  9386. if(node.tagName == 'td'){
  9387. return true;
  9388. }
  9389. node = node.parentNode;
  9390. }
  9391. return false;
  9392. }
  9393. //进行默认的处理
  9394. root.traversal(function (node) {
  9395. if (node.type == 'element') {
  9396. if (!dtd.$cdata[node.tagName] && me.options.autoClearEmptyNode && dtd.$inline[node.tagName] && !dtd.$empty[node.tagName] && (!node.attrs || utils.isEmptyObject(node.attrs))) {
  9397. if (!node.firstChild()) node.parentNode.removeChild(node);
  9398. else if (node.tagName == 'span' && (!node.attrs || utils.isEmptyObject(node.attrs))) {
  9399. node.parentNode.removeChild(node, true)
  9400. }
  9401. return;
  9402. }
  9403. switch (node.tagName) {
  9404. case 'style':
  9405. case 'script':
  9406. node.setAttr({
  9407. cdata_tag: node.tagName,
  9408. cdata_data: (node.innerHTML() || ''),
  9409. '_ue_custom_node_':'true'
  9410. });
  9411. node.tagName = 'div';
  9412. node.innerHTML('');
  9413. break;
  9414. case 'a':
  9415. if (val = node.getAttr('href')) {
  9416. node.setAttr('_href', val)
  9417. }
  9418. break;
  9419. case 'img':
  9420. //todo base64暂时去掉,后边做远程图片上传后,干掉这个
  9421. if (val = node.getAttr('src')) {
  9422. if (/^data:/.test(val)) {
  9423. node.parentNode.removeChild(node);
  9424. break;
  9425. }
  9426. }
  9427. node.setAttr('_src', node.getAttr('src'));
  9428. break;
  9429. case 'span':
  9430. if (browser.webkit && (val = node.getStyle('white-space'))) {
  9431. if (/nowrap|normal/.test(val)) {
  9432. node.setStyle('white-space', '');
  9433. if (me.options.autoClearEmptyNode && utils.isEmptyObject(node.attrs)) {
  9434. node.parentNode.removeChild(node, true)
  9435. }
  9436. }
  9437. }
  9438. val = node.getAttr('id');
  9439. if(val && /^_baidu_bookmark_/i.test(val)){
  9440. node.parentNode.removeChild(node)
  9441. }
  9442. break;
  9443. case 'p':
  9444. if (val = node.getAttr('align')) {
  9445. node.setAttr('align');
  9446. node.setStyle('text-align', val)
  9447. }
  9448. //trace:3431
  9449. // var cssStyle = node.getAttr('style');
  9450. // if (cssStyle) {
  9451. // cssStyle = cssStyle.replace(/(margin|padding)[^;]+/g, '');
  9452. // node.setAttr('style', cssStyle)
  9453. //
  9454. // }
  9455. //p标签不允许嵌套
  9456. utils.each(node.children,function(n){
  9457. if(n.type == 'element' && n.tagName == 'p'){
  9458. var next = n.nextSibling();
  9459. node.parentNode.insertAfter(n,node);
  9460. var last = n;
  9461. while(next){
  9462. var tmp = next.nextSibling();
  9463. node.parentNode.insertAfter(next,last);
  9464. last = next;
  9465. next = tmp;
  9466. }
  9467. return false;
  9468. }
  9469. });
  9470. if (!node.firstChild()) {
  9471. node.innerHTML(browser.ie ? '&nbsp;' : '<br/>')
  9472. }
  9473. break;
  9474. case 'div':
  9475. if(node.getAttr('cdata_tag')){
  9476. break;
  9477. }
  9478. //针对代码这里不处理插入代码的div
  9479. val = node.getAttr('class');
  9480. if(val && /^line number\d+/.test(val)){
  9481. break;
  9482. }
  9483. if(!allowDivTransToP){
  9484. break;
  9485. }
  9486. var tmpNode, p = UE.uNode.createElement('p');
  9487. while (tmpNode = node.firstChild()) {
  9488. if (tmpNode.type == 'text' || !UE.dom.dtd.$block[tmpNode.tagName]) {
  9489. p.appendChild(tmpNode);
  9490. } else {
  9491. if (p.firstChild()) {
  9492. node.parentNode.insertBefore(p, node);
  9493. p = UE.uNode.createElement('p');
  9494. } else {
  9495. node.parentNode.insertBefore(tmpNode, node);
  9496. }
  9497. }
  9498. }
  9499. if (p.firstChild()) {
  9500. node.parentNode.insertBefore(p, node);
  9501. }
  9502. node.parentNode.removeChild(node);
  9503. break;
  9504. case 'dl':
  9505. node.tagName = 'ul';
  9506. break;
  9507. case 'dt':
  9508. case 'dd':
  9509. node.tagName = 'li';
  9510. break;
  9511. case 'li':
  9512. var className = node.getAttr('class');
  9513. if (!className || !/list\-/.test(className)) {
  9514. node.setAttr()
  9515. }
  9516. var tmpNodes = node.getNodesByTagName('ol ul');
  9517. UE.utils.each(tmpNodes, function (n) {
  9518. node.parentNode.insertAfter(n, node);
  9519. });
  9520. break;
  9521. case 'td':
  9522. case 'th':
  9523. case 'caption':
  9524. if(!node.children || !node.children.length){
  9525. node.appendChild(browser.ie11below ? UE.uNode.createText(' ') : UE.uNode.createElement('br'))
  9526. }
  9527. break;
  9528. case 'table':
  9529. if(me.options.disabledTableInTable && tdParent(node)){
  9530. node.parentNode.insertBefore(UE.uNode.createText(node.innerText()),node);
  9531. node.parentNode.removeChild(node)
  9532. }
  9533. }
  9534. }
  9535. // if(node.type == 'comment'){
  9536. // node.parentNode.removeChild(node);
  9537. // }
  9538. })
  9539. });
  9540. //从编辑器出去的内容处理
  9541. me.addOutputRule(function (root) {
  9542. var val;
  9543. root.traversal(function (node) {
  9544. if (node.type == 'element') {
  9545. if (me.options.autoClearEmptyNode && dtd.$inline[node.tagName] && !dtd.$empty[node.tagName] && (!node.attrs || utils.isEmptyObject(node.attrs))) {
  9546. if (!node.firstChild()) node.parentNode.removeChild(node);
  9547. else if (node.tagName == 'span' && (!node.attrs || utils.isEmptyObject(node.attrs))) {
  9548. node.parentNode.removeChild(node, true)
  9549. }
  9550. return;
  9551. }
  9552. switch (node.tagName) {
  9553. case 'div':
  9554. if (val = node.getAttr('cdata_tag')) {
  9555. node.tagName = val;
  9556. node.appendChild(UE.uNode.createText(node.getAttr('cdata_data')));
  9557. node.setAttr({cdata_tag: '', cdata_data: '','_ue_custom_node_':''});
  9558. }
  9559. break;
  9560. case 'a':
  9561. if (val = node.getAttr('_href')) {
  9562. node.setAttr({
  9563. 'href': utils.html(val),
  9564. '_href': ''
  9565. })
  9566. }
  9567. break;
  9568. break;
  9569. case 'span':
  9570. val = node.getAttr('id');
  9571. if(val && /^_baidu_bookmark_/i.test(val)){
  9572. node.parentNode.removeChild(node)
  9573. }
  9574. break;
  9575. case 'img':
  9576. if (val = node.getAttr('_src')) {
  9577. node.setAttr({
  9578. 'src': node.getAttr('_src'),
  9579. '_src': ''
  9580. })
  9581. }
  9582. }
  9583. }
  9584. })
  9585. });
  9586. };
  9587. // plugins/inserthtml.js
  9588. /**
  9589. * 插入html字符串插件
  9590. * @file
  9591. * @since 1.2.6.1
  9592. */
  9593. /**
  9594. * 插入html代码
  9595. * @command inserthtml
  9596. * @method execCommand
  9597. * @param { String } cmd 命令字符串
  9598. * @param { String } html 插入的html字符串
  9599. * @remaind 插入的标签内容是在当前的选区位置上插入,如果当前是闭合状态,那直接插入内容, 如果当前是选中状态,将先清除当前选中内容后,再做插入
  9600. * @warning 注意:该命令会对当前选区的位置,对插入的内容进行过滤转换处理。 过滤的规则遵循html语意化的原则。
  9601. * @example
  9602. * ```javascript
  9603. * //xxx[BB]xxx 当前选区为非闭合选区,选中BB这两个文本
  9604. * //执行命令,插入<b>CC</b>
  9605. * //插入后的效果 xxx<b>CC</b>xxx
  9606. * //<p>xx|xxx</p> 当前选区为闭合状态
  9607. * //插入<p>CC</p>
  9608. * //结果 <p>xx</p><p>CC</p><p>xxx</p>
  9609. * //<p>xxxx</p>|</p>xxx</p> 当前选区在两个p标签之间
  9610. * //插入 xxxx
  9611. * //结果 <p>xxxx</p><p>xxxx</p></p>xxx</p>
  9612. * ```
  9613. */
  9614. UE.commands['inserthtml'] = {
  9615. execCommand: function (command,html,notNeedFilter){
  9616. var me = this,
  9617. range,
  9618. div;
  9619. if(!html){
  9620. return;
  9621. }
  9622. if(me.fireEvent('beforeinserthtml',html) === true){
  9623. return;
  9624. }
  9625. range = me.selection.getRange();
  9626. div = range.document.createElement( 'div' );
  9627. div.style.display = 'inline';
  9628. if (!notNeedFilter) {
  9629. var root = UE.htmlparser(html);
  9630. //如果给了过滤规则就先进行过滤
  9631. if(me.options.filterRules){
  9632. UE.filterNode(root,me.options.filterRules);
  9633. }
  9634. //执行默认的处理
  9635. me.filterInputRule(root);
  9636. html = root.toHtml()
  9637. }
  9638. div.innerHTML = utils.trim( html );
  9639. if ( !range.collapsed ) {
  9640. var tmpNode = range.startContainer;
  9641. if(domUtils.isFillChar(tmpNode)){
  9642. range.setStartBefore(tmpNode)
  9643. }
  9644. tmpNode = range.endContainer;
  9645. if(domUtils.isFillChar(tmpNode)){
  9646. range.setEndAfter(tmpNode)
  9647. }
  9648. range.txtToElmBoundary();
  9649. //结束边界可能放到了br的前边,要把br包含进来
  9650. // x[xxx]<br/>
  9651. if(range.endContainer && range.endContainer.nodeType == 1){
  9652. tmpNode = range.endContainer.childNodes[range.endOffset];
  9653. if(tmpNode && domUtils.isBr(tmpNode)){
  9654. range.setEndAfter(tmpNode);
  9655. }
  9656. }
  9657. if(range.startOffset == 0){
  9658. tmpNode = range.startContainer;
  9659. if(domUtils.isBoundaryNode(tmpNode,'firstChild') ){
  9660. tmpNode = range.endContainer;
  9661. if(range.endOffset == (tmpNode.nodeType == 3 ? tmpNode.nodeValue.length : tmpNode.childNodes.length) && domUtils.isBoundaryNode(tmpNode,'lastChild')){
  9662. me.body.innerHTML = '<p>'+(browser.ie ? '' : '<br/>')+'</p>';
  9663. range.setStart(me.body.firstChild,0).collapse(true)
  9664. }
  9665. }
  9666. }
  9667. !range.collapsed && range.deleteContents();
  9668. if(range.startContainer.nodeType == 1){
  9669. var child = range.startContainer.childNodes[range.startOffset],pre;
  9670. if(child && domUtils.isBlockElm(child) && (pre = child.previousSibling) && domUtils.isBlockElm(pre)){
  9671. range.setEnd(pre,pre.childNodes.length).collapse();
  9672. while(child.firstChild){
  9673. pre.appendChild(child.firstChild);
  9674. }
  9675. domUtils.remove(child);
  9676. }
  9677. }
  9678. }
  9679. var child,parent,pre,tmp,hadBreak = 0, nextNode;
  9680. //如果当前位置选中了fillchar要干掉,要不会产生空行
  9681. if(range.inFillChar()){
  9682. child = range.startContainer;
  9683. if(domUtils.isFillChar(child)){
  9684. range.setStartBefore(child).collapse(true);
  9685. domUtils.remove(child);
  9686. }else if(domUtils.isFillChar(child,true)){
  9687. child.nodeValue = child.nodeValue.replace(fillCharReg,'');
  9688. range.startOffset--;
  9689. range.collapsed && range.collapse(true)
  9690. }
  9691. }
  9692. //列表单独处理
  9693. var li = domUtils.findParentByTagName(range.startContainer,'li',true);
  9694. if(li){
  9695. var next,last;
  9696. while(child = div.firstChild){
  9697. //针对hr单独处理一下先
  9698. while(child && (child.nodeType == 3 || !domUtils.isBlockElm(child) || child.tagName=='HR' )){
  9699. next = child.nextSibling;
  9700. range.insertNode( child).collapse();
  9701. last = child;
  9702. child = next;
  9703. }
  9704. if(child){
  9705. if(/^(ol|ul)$/i.test(child.tagName)){
  9706. while(child.firstChild){
  9707. last = child.firstChild;
  9708. domUtils.insertAfter(li,child.firstChild);
  9709. li = li.nextSibling;
  9710. }
  9711. domUtils.remove(child)
  9712. }else{
  9713. var tmpLi;
  9714. next = child.nextSibling;
  9715. tmpLi = me.document.createElement('li');
  9716. domUtils.insertAfter(li,tmpLi);
  9717. tmpLi.appendChild(child);
  9718. last = child;
  9719. child = next;
  9720. li = tmpLi;
  9721. }
  9722. }
  9723. }
  9724. li = domUtils.findParentByTagName(range.startContainer,'li',true);
  9725. if(domUtils.isEmptyBlock(li)){
  9726. domUtils.remove(li)
  9727. }
  9728. if(last){
  9729. range.setStartAfter(last).collapse(true).select(true)
  9730. }
  9731. }else{
  9732. while ( child = div.firstChild ) {
  9733. if(hadBreak){
  9734. var p = me.document.createElement('p');
  9735. while(child && (child.nodeType == 3 || !dtd.$block[child.tagName])){
  9736. nextNode = child.nextSibling;
  9737. p.appendChild(child);
  9738. child = nextNode;
  9739. }
  9740. if(p.firstChild){
  9741. child = p
  9742. }
  9743. }
  9744. range.insertNode( child );
  9745. nextNode = child.nextSibling;
  9746. if ( !hadBreak && child.nodeType == domUtils.NODE_ELEMENT && domUtils.isBlockElm( child ) ){
  9747. parent = domUtils.findParent( child,function ( node ){ return domUtils.isBlockElm( node ); } );
  9748. if ( parent && parent.tagName.toLowerCase() != 'body' && !(dtd[parent.tagName] && dtd[parent.tagName][child.nodeName] && child.parentNode === parent)){
  9749. if(!dtd[parent.tagName] || !dtd[parent.tagName][child.nodeName]){
  9750. pre = parent;
  9751. }else{
  9752. tmp = child.parentNode;
  9753. while (tmp !== parent){
  9754. pre = tmp;
  9755. tmp = tmp.parentNode;
  9756. }
  9757. }
  9758. domUtils.breakParent( child, pre || tmp );
  9759. //去掉break后前一个多余的节点 <p>|<[p> ==> <p></p><div></div><p>|</p>
  9760. var pre = child.previousSibling;
  9761. domUtils.trimWhiteTextNode(pre);
  9762. if(!pre.childNodes.length){
  9763. domUtils.remove(pre);
  9764. }
  9765. //trace:2012,在非ie的情况,切开后剩下的节点有可能不能点入光标添加br占位
  9766. if(!browser.ie &&
  9767. (next = child.nextSibling) &&
  9768. domUtils.isBlockElm(next) &&
  9769. next.lastChild &&
  9770. !domUtils.isBr(next.lastChild)){
  9771. next.appendChild(me.document.createElement('br'));
  9772. }
  9773. hadBreak = 1;
  9774. }
  9775. }
  9776. var next = child.nextSibling;
  9777. if(!div.firstChild && next && domUtils.isBlockElm(next)){
  9778. range.setStart(next,0).collapse(true);
  9779. break;
  9780. }
  9781. range.setEndAfter( child ).collapse();
  9782. }
  9783. child = range.startContainer;
  9784. if(nextNode && domUtils.isBr(nextNode)){
  9785. domUtils.remove(nextNode)
  9786. }
  9787. //用chrome可能有空白展位符
  9788. if(domUtils.isBlockElm(child) && domUtils.isEmptyNode(child)){
  9789. if(nextNode = child.nextSibling){
  9790. domUtils.remove(child);
  9791. if(nextNode.nodeType == 1 && dtd.$block[nextNode.tagName]){
  9792. range.setStart(nextNode,0).collapse(true).shrinkBoundary()
  9793. }
  9794. }else{
  9795. try{
  9796. child.innerHTML = browser.ie ? domUtils.fillChar : '<br/>';
  9797. }catch(e){
  9798. range.setStartBefore(child);
  9799. domUtils.remove(child)
  9800. }
  9801. }
  9802. }
  9803. //加上true因为在删除表情等时会删两次,第一次是删的fillData
  9804. try{
  9805. range.select(true);
  9806. }catch(e){}
  9807. }
  9808. setTimeout(function(){
  9809. range = me.selection.getRange();
  9810. range.scrollToView(me.autoHeightEnabled,me.autoHeightEnabled ? domUtils.getXY(me.iframe).y:0);
  9811. me.fireEvent('afterinserthtml', html);
  9812. },200);
  9813. }
  9814. };
  9815. // plugins/autotypeset.js
  9816. /**
  9817. * 自动排版
  9818. * @file
  9819. * @since 1.2.6.1
  9820. */
  9821. /**
  9822. * 对当前编辑器的内容执行自动排版, 排版的行为根据config配置文件里的“autotypeset”选项进行控制。
  9823. * @command autotypeset
  9824. * @method execCommand
  9825. * @param { String } cmd 命令字符串
  9826. * @example
  9827. * ```javascript
  9828. * editor.execCommand( 'autotypeset' );
  9829. * ```
  9830. */
  9831. UE.plugins['autotypeset'] = function(){
  9832. this.setOpt({'autotypeset': {
  9833. mergeEmptyline: true, //合并空行
  9834. removeClass: true, //去掉冗余的class
  9835. removeEmptyline: false, //去掉空行
  9836. textAlign:"left", //段落的排版方式,可以是 left,right,center,justify 去掉这个属性表示不执行排版
  9837. imageBlockLine: 'center', //图片的浮动方式,独占一行剧中,左右浮动,默认: center,left,right,none 去掉这个属性表示不执行排版
  9838. pasteFilter: false, //根据规则过滤没事粘贴进来的内容
  9839. clearFontSize: false, //去掉所有的内嵌字号,使用编辑器默认的字号
  9840. clearFontFamily: false, //去掉所有的内嵌字体,使用编辑器默认的字体
  9841. removeEmptyNode: false, // 去掉空节点
  9842. //可以去掉的标签
  9843. removeTagNames: utils.extend({div:1},dtd.$removeEmpty),
  9844. indent: false, // 行首缩进
  9845. indentValue : '2em', //行首缩进的大小
  9846. bdc2sb: false,
  9847. tobdc: false
  9848. }});
  9849. var me = this,
  9850. opt = me.options.autotypeset,
  9851. remainClass = {
  9852. 'selectTdClass':1,
  9853. 'pagebreak':1,
  9854. 'anchorclass':1
  9855. },
  9856. remainTag = {
  9857. 'li':1
  9858. },
  9859. tags = {
  9860. div:1,
  9861. p:1,
  9862. //trace:2183 这些也认为是行
  9863. blockquote:1,center:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,
  9864. span:1
  9865. },
  9866. highlightCont;
  9867. //升级了版本,但配置项目里没有autotypeset
  9868. if(!opt){
  9869. return;
  9870. }
  9871. readLocalOpts();
  9872. function isLine(node,notEmpty){
  9873. if(!node || node.nodeType == 3)
  9874. return 0;
  9875. if(domUtils.isBr(node))
  9876. return 1;
  9877. if(node && node.parentNode && tags[node.tagName.toLowerCase()]){
  9878. if(highlightCont && highlightCont.contains(node)
  9879. ||
  9880. node.getAttribute('pagebreak')
  9881. ){
  9882. return 0;
  9883. }
  9884. return notEmpty ? !domUtils.isEmptyBlock(node) : domUtils.isEmptyBlock(node,new RegExp('[\\s'+domUtils.fillChar
  9885. +']','g'));
  9886. }
  9887. }
  9888. function removeNotAttributeSpan(node){
  9889. if(!node.style.cssText){
  9890. domUtils.removeAttributes(node,['style']);
  9891. if(node.tagName.toLowerCase() == 'span' && domUtils.hasNoAttributes(node)){
  9892. domUtils.remove(node,true);
  9893. }
  9894. }
  9895. }
  9896. function autotype(type,html){
  9897. console.error('autotype start');
  9898. var me = this,cont;
  9899. if(html){
  9900. if(!opt.pasteFilter){
  9901. return;
  9902. }
  9903. cont = me.document.createElement('div');
  9904. cont.innerHTML = html.html;
  9905. }else{
  9906. cont = me.document.body;
  9907. }
  9908. var nodes = domUtils.getElementsByTagName(cont,'*');
  9909. // 行首缩进,段落方向,段间距,段内间距
  9910. for(var i=0,ci;ci=nodes[i++];){
  9911. if(me.fireEvent('excludeNodeinautotype',ci) === true){
  9912. continue;
  9913. }
  9914. //font-size
  9915. if(opt.clearFontSize && ci.style.fontSize){
  9916. domUtils.removeStyle(ci,'font-size');
  9917. removeNotAttributeSpan(ci);
  9918. }
  9919. //font-family
  9920. if(opt.clearFontFamily && ci.style.fontFamily){
  9921. domUtils.removeStyle(ci,'font-family');
  9922. removeNotAttributeSpan(ci);
  9923. }
  9924. if(isLine(ci)){
  9925. //合并空行
  9926. if(opt.mergeEmptyline ){
  9927. var next = ci.nextSibling,tmpNode,isBr = domUtils.isBr(ci);
  9928. while(isLine(next)){
  9929. tmpNode = next;
  9930. next = tmpNode.nextSibling;
  9931. if(isBr && (!next || next && !domUtils.isBr(next))){
  9932. break;
  9933. }
  9934. domUtils.remove(tmpNode);
  9935. }
  9936. }
  9937. //去掉空行,保留占位的空行
  9938. if(opt.removeEmptyline && domUtils.inDoc(ci,cont) && !remainTag[ci.parentNode.tagName.toLowerCase()] ){
  9939. if(domUtils.isBr(ci)){
  9940. next = ci.nextSibling;
  9941. if(next && !domUtils.isBr(next)){
  9942. continue;
  9943. }
  9944. }
  9945. domUtils.remove(ci);
  9946. continue;
  9947. }
  9948. }
  9949. if(isLine(ci,true) && ci.tagName != 'SPAN'){
  9950. if(opt.indent){
  9951. ci.style.textIndent = opt.indentValue;
  9952. }
  9953. if(opt.textAlign){
  9954. ci.style.textAlign = opt.textAlign;
  9955. }
  9956. // if(opt.lineHeight)
  9957. // ci.style.lineHeight = opt.lineHeight + 'cm';
  9958. }
  9959. //去掉class,保留的class不去掉
  9960. if(opt.removeClass && ci.className && !remainClass[ci.className.toLowerCase()]){
  9961. if(highlightCont && highlightCont.contains(ci)){
  9962. continue;
  9963. }
  9964. domUtils.removeAttributes(ci,['class']);
  9965. }
  9966. //表情不处理
  9967. if(opt.imageBlockLine && ci.tagName.toLowerCase() == 'img' && !ci.getAttribute('emotion')){
  9968. if(html){
  9969. var img = ci;
  9970. switch (opt.imageBlockLine){
  9971. case 'left':
  9972. case 'right':
  9973. case 'none':
  9974. var pN = img.parentNode,tmpNode,pre,next;
  9975. while(dtd.$inline[pN.tagName] || pN.tagName == 'A'){
  9976. pN = pN.parentNode;
  9977. }
  9978. tmpNode = pN;
  9979. if(tmpNode.tagName == 'P' && domUtils.getStyle(tmpNode,'text-align') == 'center'){
  9980. if(!domUtils.isBody(tmpNode) && domUtils.getChildCount(tmpNode,function(node){return !domUtils.isBr(node) && !domUtils.isWhitespace(node)}) == 1){
  9981. pre = tmpNode.previousSibling;
  9982. next = tmpNode.nextSibling;
  9983. if(pre && next && pre.nodeType == 1 && next.nodeType == 1 && pre.tagName == next.tagName && domUtils.isBlockElm(pre)){
  9984. pre.appendChild(tmpNode.firstChild);
  9985. while(next.firstChild){
  9986. pre.appendChild(next.firstChild);
  9987. }
  9988. domUtils.remove(tmpNode);
  9989. domUtils.remove(next);
  9990. }else{
  9991. domUtils.setStyle(tmpNode,'text-align','');
  9992. }
  9993. }
  9994. }
  9995. domUtils.setStyle(img,'float', opt.imageBlockLine);
  9996. break;
  9997. case 'center':
  9998. if(me.queryCommandValue('imagefloat') != 'center'){
  9999. pN = img.parentNode;
  10000. domUtils.setStyle(img,'float','none');
  10001. tmpNode = img;
  10002. while(pN && domUtils.getChildCount(pN,function(node){return !domUtils.isBr(node) && !domUtils.isWhitespace(node)}) == 1
  10003. && (dtd.$inline[pN.tagName] || pN.tagName == 'A')){
  10004. tmpNode = pN;
  10005. pN = pN.parentNode;
  10006. }
  10007. var pNode = me.document.createElement('p');
  10008. domUtils.setAttributes(pNode,{
  10009. style:'text-align:center'
  10010. });
  10011. tmpNode.parentNode.insertBefore(pNode,tmpNode);
  10012. pNode.appendChild(tmpNode);
  10013. domUtils.setStyle(tmpNode,'float','');
  10014. }
  10015. }
  10016. } else {
  10017. var range = me.selection.getRange();
  10018. range.selectNode(ci).select();
  10019. me.execCommand('imagefloat', opt.imageBlockLine);
  10020. }
  10021. }
  10022. //去掉冗余的标签
  10023. if(opt.removeEmptyNode){
  10024. if(opt.removeTagNames[ci.tagName.toLowerCase()] && domUtils.hasNoAttributes(ci) && domUtils.isEmptyBlock(ci)){
  10025. domUtils.remove(ci);
  10026. }
  10027. }
  10028. }
  10029. if(opt.tobdc){
  10030. var root = UE.htmlparser(cont.innerHTML);
  10031. root.traversal(function(node){
  10032. if(node.type == 'text'){
  10033. node.data = ToDBC(node.data)
  10034. }
  10035. });
  10036. cont.innerHTML = root.toHtml()
  10037. }
  10038. if(opt.bdc2sb){
  10039. var root = UE.htmlparser(cont.innerHTML);
  10040. root.traversal(function(node){
  10041. if(node.type == 'text'){
  10042. node.data = DBC2SB(node.data)
  10043. }
  10044. });
  10045. cont.innerHTML = root.toHtml()
  10046. }
  10047. if(html){
  10048. html.html = cont.innerHTML;
  10049. }
  10050. }
  10051. if(opt.pasteFilter){
  10052. me.addListener('beforepaste',autotype);
  10053. }
  10054. function DBC2SB(str) {
  10055. var result = '';
  10056. for (var i = 0; i < str.length; i++) {
  10057. var code = str.charCodeAt(i); //获取当前字符的unicode编码
  10058. if (code >= 65281 && code <= 65373)//在这个unicode编码范围中的是所有的英文字母已经各种字符
  10059. {
  10060. result += String.fromCharCode(str.charCodeAt(i) - 65248); //把全角字符的unicode编码转换为对应半角字符的unicode码
  10061. } else if (code == 12288)//空格
  10062. {
  10063. result += String.fromCharCode(str.charCodeAt(i) - 12288 + 32);
  10064. } else {
  10065. result += str.charAt(i);
  10066. }
  10067. }
  10068. return result;
  10069. }
  10070. function ToDBC(txtstring) {
  10071. txtstring = utils.html(txtstring);
  10072. var tmp = "";
  10073. var mark = "";/*用于判断,如果是html尖括里的标记,则不进行全角的转换*/
  10074. for (var i = 0; i < txtstring.length; i++) {
  10075. if (txtstring.charCodeAt(i) == 32) {
  10076. tmp = tmp + String.fromCharCode(12288);
  10077. }
  10078. else if (txtstring.charCodeAt(i) < 127) {
  10079. tmp = tmp + String.fromCharCode(txtstring.charCodeAt(i) + 65248);
  10080. }
  10081. else {
  10082. tmp += txtstring.charAt(i);
  10083. }
  10084. }
  10085. return tmp;
  10086. }
  10087. function readLocalOpts() {
  10088. var cookieOpt = me.getPreferences('autotypeset');
  10089. utils.extend(me.options.autotypeset, cookieOpt);
  10090. }
  10091. me.commands['autotypeset'] = {
  10092. execCommand:function () {
  10093. me.removeListener('beforepaste',autotype);
  10094. if(opt.pasteFilter){
  10095. me.addListener('beforepaste',autotype);
  10096. }
  10097. autotype.call(me)
  10098. }
  10099. };
  10100. };
  10101. // plugins/autosubmit.js
  10102. /**
  10103. * 快捷键提交
  10104. * @file
  10105. * @since 1.2.6.1
  10106. */
  10107. /**
  10108. * 提交表单
  10109. * @command autosubmit
  10110. * @method execCommand
  10111. * @param { String } cmd 命令字符串
  10112. * @example
  10113. * ```javascript
  10114. * editor.execCommand( 'autosubmit' );
  10115. * ```
  10116. */
  10117. UE.plugin.register('autosubmit',function(){
  10118. return {
  10119. shortcutkey:{
  10120. "autosubmit":"ctrl+13" //手动提交
  10121. },
  10122. commands:{
  10123. 'autosubmit':{
  10124. execCommand:function () {
  10125. var me=this,
  10126. form = domUtils.findParentByTagName(me.iframe,"form", false);
  10127. if (form){
  10128. if(me.fireEvent("beforesubmit")===false){
  10129. return;
  10130. }
  10131. me.sync();
  10132. form.submit();
  10133. }
  10134. }
  10135. }
  10136. }
  10137. }
  10138. });
  10139. // plugins/background.js
  10140. /**
  10141. * 背景插件,为UEditor提供设置背景功能
  10142. * @file
  10143. * @since 1.2.6.1
  10144. */
  10145. UE.plugin.register('background', function () {
  10146. var me = this,
  10147. cssRuleId = 'editor_background',
  10148. isSetColored,
  10149. reg = new RegExp('body[\\s]*\\{(.+)\\}', 'i');
  10150. function stringToObj(str) {
  10151. var obj = {}, styles = str.split(';');
  10152. utils.each(styles, function (v) {
  10153. var index = v.indexOf(':'),
  10154. key = utils.trim(v.substr(0, index)).toLowerCase();
  10155. key && (obj[key] = utils.trim(v.substr(index + 1) || ''));
  10156. });
  10157. return obj;
  10158. }
  10159. function setBackground(obj) {
  10160. if (obj) {
  10161. var styles = [];
  10162. for (var name in obj) {
  10163. if (obj.hasOwnProperty(name)) {
  10164. styles.push(name + ":" + obj[name] + '; ');
  10165. }
  10166. }
  10167. utils.cssRule(cssRuleId, styles.length ? ('body{' + styles.join("") + '}') : '', me.document);
  10168. } else {
  10169. utils.cssRule(cssRuleId, '', me.document)
  10170. }
  10171. }
  10172. //重写editor.hasContent方法
  10173. var orgFn = me.hasContents;
  10174. me.hasContents = function(){
  10175. if(me.queryCommandValue('background')){
  10176. return true
  10177. }
  10178. return orgFn.apply(me,arguments);
  10179. };
  10180. return {
  10181. bindEvents: {
  10182. 'getAllHtml': function (type, headHtml) {
  10183. var body = this.body,
  10184. su = domUtils.getComputedStyle(body, "background-image"),
  10185. url = "";
  10186. if (su.indexOf(me.options.imagePath) > 0) {
  10187. url = su.substring(su.indexOf(me.options.imagePath), su.length - 1).replace(/"|\(|\)/ig, "");
  10188. } else {
  10189. url = su != "none" ? su.replace(/url\("?|"?\)/ig, "") : "";
  10190. }
  10191. var html = '<style type="text/css">body{';
  10192. var bgObj = {
  10193. "background-color": domUtils.getComputedStyle(body, "background-color") || "#ffffff",
  10194. 'background-image': url ? 'url(' + url + ')' : '',
  10195. 'background-repeat': domUtils.getComputedStyle(body, "background-repeat") || "",
  10196. 'background-position': browser.ie ? (domUtils.getComputedStyle(body, "background-position-x") + " " + domUtils.getComputedStyle(body, "background-position-y")) : domUtils.getComputedStyle(body, "background-position"),
  10197. 'height': domUtils.getComputedStyle(body, "height")
  10198. };
  10199. for (var name in bgObj) {
  10200. if (bgObj.hasOwnProperty(name)) {
  10201. html += name + ":" + bgObj[name] + "; ";
  10202. }
  10203. }
  10204. html += '}</style> ';
  10205. headHtml.push(html);
  10206. },
  10207. 'aftersetcontent': function () {
  10208. if(isSetColored == false) setBackground();
  10209. }
  10210. },
  10211. inputRule: function (root) {
  10212. isSetColored = false;
  10213. utils.each(root.getNodesByTagName('p'), function (p) {
  10214. var styles = p.getAttr('data-background');
  10215. if (styles) {
  10216. isSetColored = true;
  10217. setBackground(stringToObj(styles));
  10218. p.parentNode.removeChild(p);
  10219. }
  10220. })
  10221. },
  10222. outputRule: function (root) {
  10223. var me = this,
  10224. styles = (utils.cssRule(cssRuleId, me.document) || '').replace(/[\n\r]+/g, '').match(reg);
  10225. if (styles) {
  10226. root.appendChild(UE.uNode.createElement('<p style="display:none;" data-background="' + utils.trim(styles[1].replace(/"/g, '').replace(/[\s]+/g, ' ')) + '"><br/></p>'));
  10227. }
  10228. },
  10229. commands: {
  10230. 'background': {
  10231. execCommand: function (cmd, obj) {
  10232. setBackground(obj);
  10233. },
  10234. queryCommandValue: function () {
  10235. var me = this,
  10236. styles = (utils.cssRule(cssRuleId, me.document) || '').replace(/[\n\r]+/g, '').match(reg);
  10237. return styles ? stringToObj(styles[1]) : null;
  10238. },
  10239. notNeedUndo: true
  10240. }
  10241. }
  10242. }
  10243. });
  10244. // plugins/image.js
  10245. /**
  10246. * 图片插入、排版插件
  10247. * @file
  10248. * @since 1.2.6.1
  10249. */
  10250. /**
  10251. * 图片对齐方式
  10252. * @command imagefloat
  10253. * @method execCommand
  10254. * @remind 值center为独占一行居中
  10255. * @param { String } cmd 命令字符串
  10256. * @param { String } align 对齐方式,可传left、right、none、center
  10257. * @remaind center表示图片独占一行
  10258. * @example
  10259. * ```javascript
  10260. * editor.execCommand( 'imagefloat', 'center' );
  10261. * ```
  10262. */
  10263. /**
  10264. * 如果选区所在位置是图片区域
  10265. * @command imagefloat
  10266. * @method queryCommandValue
  10267. * @param { String } cmd 命令字符串
  10268. * @return { String } 返回图片对齐方式
  10269. * @example
  10270. * ```javascript
  10271. * editor.queryCommandValue( 'imagefloat' );
  10272. * ```
  10273. */
  10274. UE.commands['imagefloat'] = {
  10275. execCommand:function (cmd, align) {
  10276. var me = this,
  10277. range = me.selection.getRange();
  10278. if (!range.collapsed) {
  10279. var img = range.getClosedNode();
  10280. if (img && img.tagName == 'IMG') {
  10281. switch (align) {
  10282. case 'left':
  10283. case 'right':
  10284. case 'none':
  10285. var pN = img.parentNode, tmpNode, pre, next;
  10286. while (dtd.$inline[pN.tagName] || pN.tagName == 'A') {
  10287. pN = pN.parentNode;
  10288. }
  10289. tmpNode = pN;
  10290. if (tmpNode.tagName == 'P' && domUtils.getStyle(tmpNode, 'text-align') == 'center') {
  10291. if (!domUtils.isBody(tmpNode) && domUtils.getChildCount(tmpNode, function (node) {
  10292. return !domUtils.isBr(node) && !domUtils.isWhitespace(node);
  10293. }) == 1) {
  10294. pre = tmpNode.previousSibling;
  10295. next = tmpNode.nextSibling;
  10296. if (pre && next && pre.nodeType == 1 && next.nodeType == 1 && pre.tagName == next.tagName && domUtils.isBlockElm(pre)) {
  10297. pre.appendChild(tmpNode.firstChild);
  10298. while (next.firstChild) {
  10299. pre.appendChild(next.firstChild);
  10300. }
  10301. domUtils.remove(tmpNode);
  10302. domUtils.remove(next);
  10303. } else {
  10304. domUtils.setStyle(tmpNode, 'text-align', '');
  10305. }
  10306. }
  10307. range.selectNode(img).select();
  10308. }
  10309. domUtils.setStyle(img, 'float', align == 'none' ? '' : align);
  10310. if(align == 'none'){
  10311. domUtils.removeAttributes(img,'align');
  10312. }
  10313. break;
  10314. case 'center':
  10315. if (me.queryCommandValue('imagefloat') != 'center') {
  10316. pN = img.parentNode;
  10317. domUtils.setStyle(img, 'float', '');
  10318. domUtils.removeAttributes(img,'align');
  10319. tmpNode = img;
  10320. while (pN && domUtils.getChildCount(pN, function (node) {
  10321. return !domUtils.isBr(node) && !domUtils.isWhitespace(node);
  10322. }) == 1
  10323. && (dtd.$inline[pN.tagName] || pN.tagName == 'A')) {
  10324. tmpNode = pN;
  10325. pN = pN.parentNode;
  10326. }
  10327. range.setStartBefore(tmpNode).setCursor(false);
  10328. pN = me.document.createElement('div');
  10329. pN.appendChild(tmpNode);
  10330. domUtils.setStyle(tmpNode, 'float', '');
  10331. me.execCommand('insertHtml', '<p id="_img_parent_tmp" style="text-align:center">' + pN.innerHTML + '</p>');
  10332. tmpNode = me.document.getElementById('_img_parent_tmp');
  10333. tmpNode.removeAttribute('id');
  10334. tmpNode = tmpNode.firstChild;
  10335. range.selectNode(tmpNode).select();
  10336. //去掉后边多余的元素
  10337. next = tmpNode.parentNode.nextSibling;
  10338. if (next && domUtils.isEmptyNode(next)) {
  10339. domUtils.remove(next);
  10340. }
  10341. }
  10342. break;
  10343. }
  10344. }
  10345. }
  10346. },
  10347. queryCommandValue:function () {
  10348. var range = this.selection.getRange(),
  10349. startNode, floatStyle;
  10350. if (range.collapsed) {
  10351. return 'none';
  10352. }
  10353. startNode = range.getClosedNode();
  10354. if (startNode && startNode.nodeType == 1 && startNode.tagName == 'IMG') {
  10355. floatStyle = domUtils.getComputedStyle(startNode, 'float') || startNode.getAttribute('align');
  10356. if (floatStyle == 'none') {
  10357. floatStyle = domUtils.getComputedStyle(startNode.parentNode, 'text-align') == 'center' ? 'center' : floatStyle;
  10358. }
  10359. return {
  10360. left:1,
  10361. right:1,
  10362. center:1
  10363. }[floatStyle] ? floatStyle : 'none';
  10364. }
  10365. return 'none';
  10366. },
  10367. queryCommandState:function () {
  10368. var range = this.selection.getRange(),
  10369. startNode;
  10370. if (range.collapsed) return -1;
  10371. startNode = range.getClosedNode();
  10372. if (startNode && startNode.nodeType == 1 && startNode.tagName == 'IMG') {
  10373. return 0;
  10374. }
  10375. return -1;
  10376. }
  10377. };
  10378. /**
  10379. * 插入图片
  10380. * @command insertimage
  10381. * @method execCommand
  10382. * @param { String } cmd 命令字符串
  10383. * @param { Object } opt 属性键值对,这些属性都将被复制到当前插入图片
  10384. * @remind 该命令第二个参数可接受一个图片配置项对象的数组,可以插入多张图片,
  10385. * 此时数组的每一个元素都是一个Object类型的图片属性集合。
  10386. * @example
  10387. * ```javascript
  10388. * editor.execCommand( 'insertimage', {
  10389. * src:'a/b/c.jpg',
  10390. * width:'100',
  10391. * height:'100'
  10392. * } );
  10393. * ```
  10394. * @example
  10395. * ```javascript
  10396. * editor.execCommand( 'insertimage', [{
  10397. * src:'a/b/c.jpg',
  10398. * width:'100',
  10399. * height:'100'
  10400. * },{
  10401. * src:'a/b/d.jpg',
  10402. * width:'100',
  10403. * height:'100'
  10404. * }] );
  10405. * ```
  10406. */
  10407. UE.commands['insertimage'] = {
  10408. execCommand:function (cmd, opt) {
  10409. opt = utils.isArray(opt) ? opt : [opt];
  10410. if (!opt.length) {
  10411. return;
  10412. }
  10413. var me = this,
  10414. range = me.selection.getRange(),
  10415. img = range.getClosedNode();
  10416. if(me.fireEvent('beforeinsertimage', opt) === true){
  10417. return;
  10418. }
  10419. function unhtmlData(imgCi) {
  10420. utils.each('width,height,border,hspace,vspace'.split(','), function (item) {
  10421. if (imgCi[item]) {
  10422. imgCi[item] = parseInt(imgCi[item], 10) || 0;
  10423. }
  10424. });
  10425. utils.each('src,_src'.split(','), function (item) {
  10426. if (imgCi[item]) {
  10427. imgCi[item] = utils.unhtmlForUrl(imgCi[item]);
  10428. }
  10429. });
  10430. utils.each('title,alt'.split(','), function (item) {
  10431. if (imgCi[item]) {
  10432. imgCi[item] = utils.unhtml(imgCi[item]);
  10433. }
  10434. });
  10435. }
  10436. if (img && /img/i.test(img.tagName) && (img.className != "edui-faked-video" || img.className.indexOf("edui-upload-video")!=-1) && !img.getAttribute("word_img")) {
  10437. var first = opt.shift();
  10438. var floatStyle = first['floatStyle'];
  10439. delete first['floatStyle'];
  10440. //// img.style.border = (first.border||0) +"px solid #000";
  10441. //// img.style.margin = (first.margin||0) +"px";
  10442. // img.style.cssText += ';margin:' + (first.margin||0) +"px;" + 'border:' + (first.border||0) +"px solid #000";
  10443. domUtils.setAttributes(img, first);
  10444. me.execCommand('imagefloat', floatStyle);
  10445. if (opt.length > 0) {
  10446. range.setStartAfter(img).setCursor(false, true);
  10447. me.execCommand('insertimage', opt);
  10448. }
  10449. } else {
  10450. var html = [], str = '', ci;
  10451. ci = opt[0];
  10452. if (opt.length == 1) {
  10453. unhtmlData(ci);
  10454. str = '<img src="' + ci.src + '" ' + (ci._src ? ' _src="' + ci._src + '" ' : '') +
  10455. (ci.width ? 'width="' + ci.width + '" ' : '') +
  10456. (ci.height ? ' height="' + ci.height + '" ' : '') +
  10457. (ci['floatStyle'] == 'left' || ci['floatStyle'] == 'right' ? ' style="float:' + ci['floatStyle'] + ';"' : '') +
  10458. (ci.title && ci.title != "" ? ' title="' + ci.title + '"' : '') +
  10459. (ci.border && ci.border != "0" ? ' border="' + ci.border + '"' : '') +
  10460. (ci.alt && ci.alt != "" ? ' alt="' + ci.alt + '"' : '') +
  10461. (ci.hspace && ci.hspace != "0" ? ' hspace = "' + ci.hspace + '"' : '') +
  10462. (ci.vspace && ci.vspace != "0" ? ' vspace = "' + ci.vspace + '"' : '') + '/>';
  10463. if (ci['floatStyle'] == 'center') {
  10464. str = '<p style="text-align: center">' + str + '</p>';
  10465. }
  10466. html.push(str);
  10467. } else {
  10468. for (var i = 0; ci = opt[i++];) {
  10469. unhtmlData(ci);
  10470. str = '<p ' + (ci['floatStyle'] == 'center' ? 'style="text-align: center" ' : '') + '><img src="' + ci.src + '" ' +
  10471. (ci.width ? 'width="' + ci.width + '" ' : '') + (ci._src ? ' _src="' + ci._src + '" ' : '') +
  10472. (ci.height ? ' height="' + ci.height + '" ' : '') +
  10473. ' style="' + (ci['floatStyle'] && ci['floatStyle'] != 'center' ? 'float:' + ci['floatStyle'] + ';' : '') +
  10474. (ci.border || '') + '" ' +
  10475. (ci.title ? ' title="' + ci.title + '"' : '') + ' /></p>';
  10476. html.push(str);
  10477. }
  10478. }
  10479. me.execCommand('insertHtml', html.join(''));
  10480. }
  10481. me.fireEvent('afterinsertimage', opt)
  10482. }
  10483. };
  10484. // plugins/justify.js
  10485. /**
  10486. * 段落格式
  10487. * @file
  10488. * @since 1.2.6.1
  10489. */
  10490. /**
  10491. * 段落对齐方式
  10492. * @command justify
  10493. * @method execCommand
  10494. * @param { String } cmd 命令字符串
  10495. * @param { String } align 对齐方式:left => 居左,right => 居右,center => 居中,justify => 两端对齐
  10496. * @example
  10497. * ```javascript
  10498. * editor.execCommand( 'justify', 'center' );
  10499. * ```
  10500. */
  10501. /**
  10502. * 如果选区所在位置是段落区域,返回当前段落对齐方式
  10503. * @command justify
  10504. * @method queryCommandValue
  10505. * @param { String } cmd 命令字符串
  10506. * @return { String } 返回段落对齐方式
  10507. * @example
  10508. * ```javascript
  10509. * editor.queryCommandValue( 'justify' );
  10510. * ```
  10511. */
  10512. UE.plugins['justify']=function(){
  10513. var me=this,
  10514. block = domUtils.isBlockElm,
  10515. defaultValue = {
  10516. left:1,
  10517. right:1,
  10518. center:1,
  10519. justify:1
  10520. },
  10521. doJustify = function (range, style) {
  10522. var bookmark = range.createBookmark(),
  10523. filterFn = function (node) {
  10524. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' && !domUtils.isBookmarkNode(node) : !domUtils.isWhitespace(node);
  10525. };
  10526. range.enlarge(true);
  10527. var bookmark2 = range.createBookmark(),
  10528. current = domUtils.getNextDomNode(bookmark2.start, false, filterFn),
  10529. tmpRange = range.cloneRange(),
  10530. tmpNode;
  10531. while (current && !(domUtils.getPosition(current, bookmark2.end) & domUtils.POSITION_FOLLOWING)) {
  10532. if (current.nodeType == 3 || !block(current)) {
  10533. tmpRange.setStartBefore(current);
  10534. while (current && current !== bookmark2.end && !block(current)) {
  10535. tmpNode = current;
  10536. current = domUtils.getNextDomNode(current, false, null, function (node) {
  10537. return !block(node);
  10538. });
  10539. }
  10540. tmpRange.setEndAfter(tmpNode);
  10541. var common = tmpRange.getCommonAncestor();
  10542. if (!domUtils.isBody(common) && block(common)) {
  10543. domUtils.setStyles(common, utils.isString(style) ? {'text-align':style} : style);
  10544. current = common;
  10545. } else {
  10546. var p = range.document.createElement('p');
  10547. domUtils.setStyles(p, utils.isString(style) ? {'text-align':style} : style);
  10548. var frag = tmpRange.extractContents();
  10549. p.appendChild(frag);
  10550. tmpRange.insertNode(p);
  10551. current = p;
  10552. }
  10553. current = domUtils.getNextDomNode(current, false, filterFn);
  10554. } else {
  10555. current = domUtils.getNextDomNode(current, true, filterFn);
  10556. }
  10557. }
  10558. return range.moveToBookmark(bookmark2).moveToBookmark(bookmark);
  10559. };
  10560. UE.commands['justify'] = {
  10561. execCommand:function (cmdName, align) {
  10562. var range = this.selection.getRange(),
  10563. txt;
  10564. //闭合时单独处理
  10565. if (range.collapsed) {
  10566. txt = this.document.createTextNode('p');
  10567. range.insertNode(txt);
  10568. }
  10569. doJustify(range, align);
  10570. if (txt) {
  10571. range.setStartBefore(txt).collapse(true);
  10572. domUtils.remove(txt);
  10573. }
  10574. range.select();
  10575. return true;
  10576. },
  10577. queryCommandValue:function () {
  10578. var startNode = this.selection.getStart(),
  10579. value = domUtils.getComputedStyle(startNode, 'text-align');
  10580. return defaultValue[value] ? value : 'left';
  10581. },
  10582. queryCommandState:function () {
  10583. var start = this.selection.getStart(),
  10584. cell = start && domUtils.findParentByTagName(start, ["td", "th","caption"], true);
  10585. return cell? -1:0;
  10586. }
  10587. };
  10588. };
  10589. // plugins/font.js
  10590. /**
  10591. * 字体颜色,背景色,字号,字体,下划线,删除线
  10592. * @file
  10593. * @since 1.2.6.1
  10594. */
  10595. /**
  10596. * 字体颜色
  10597. * @command forecolor
  10598. * @method execCommand
  10599. * @param { String } cmd 命令字符串
  10600. * @param { String } value 色值(必须十六进制)
  10601. * @example
  10602. * ```javascript
  10603. * editor.execCommand( 'forecolor', '#000' );
  10604. * ```
  10605. */
  10606. /**
  10607. * 返回选区字体颜色
  10608. * @command forecolor
  10609. * @method queryCommandValue
  10610. * @param { String } cmd 命令字符串
  10611. * @return { String } 返回字体颜色
  10612. * @example
  10613. * ```javascript
  10614. * editor.queryCommandValue( 'forecolor' );
  10615. * ```
  10616. */
  10617. /**
  10618. * 字体背景颜色
  10619. * @command backcolor
  10620. * @method execCommand
  10621. * @param { String } cmd 命令字符串
  10622. * @param { String } value 色值(必须十六进制)
  10623. * @example
  10624. * ```javascript
  10625. * editor.execCommand( 'backcolor', '#000' );
  10626. * ```
  10627. */
  10628. /**
  10629. * 返回选区字体颜色
  10630. * @command backcolor
  10631. * @method queryCommandValue
  10632. * @param { String } cmd 命令字符串
  10633. * @return { String } 返回字体背景颜色
  10634. * @example
  10635. * ```javascript
  10636. * editor.queryCommandValue( 'backcolor' );
  10637. * ```
  10638. */
  10639. /**
  10640. * 字体大小
  10641. * @command fontsize
  10642. * @method execCommand
  10643. * @param { String } cmd 命令字符串
  10644. * @param { String } value 字体大小
  10645. * @example
  10646. * ```javascript
  10647. * editor.execCommand( 'fontsize', '14px' );
  10648. * ```
  10649. */
  10650. /**
  10651. * 返回选区字体大小
  10652. * @command fontsize
  10653. * @method queryCommandValue
  10654. * @param { String } cmd 命令字符串
  10655. * @return { String } 返回字体大小
  10656. * @example
  10657. * ```javascript
  10658. * editor.queryCommandValue( 'fontsize' );
  10659. * ```
  10660. */
  10661. /**
  10662. * 字体样式
  10663. * @command fontfamily
  10664. * @method execCommand
  10665. * @param { String } cmd 命令字符串
  10666. * @param { String } value 字体样式
  10667. * @example
  10668. * ```javascript
  10669. * editor.execCommand( 'fontfamily', '微软雅黑' );
  10670. * ```
  10671. */
  10672. /**
  10673. * 返回选区字体样式
  10674. * @command fontfamily
  10675. * @method queryCommandValue
  10676. * @param { String } cmd 命令字符串
  10677. * @return { String } 返回字体样式
  10678. * @example
  10679. * ```javascript
  10680. * editor.queryCommandValue( 'fontfamily' );
  10681. * ```
  10682. */
  10683. /**
  10684. * 字体下划线,与删除线互斥
  10685. * @command underline
  10686. * @method execCommand
  10687. * @param { String } cmd 命令字符串
  10688. * @example
  10689. * ```javascript
  10690. * editor.execCommand( 'underline' );
  10691. * ```
  10692. */
  10693. /**
  10694. * 字体删除线,与下划线互斥
  10695. * @command strikethrough
  10696. * @method execCommand
  10697. * @param { String } cmd 命令字符串
  10698. * @example
  10699. * ```javascript
  10700. * editor.execCommand( 'strikethrough' );
  10701. * ```
  10702. */
  10703. /**
  10704. * 字体边框
  10705. * @command fontborder
  10706. * @method execCommand
  10707. * @param { String } cmd 命令字符串
  10708. * @example
  10709. * ```javascript
  10710. * editor.execCommand( 'fontborder' );
  10711. * ```
  10712. */
  10713. UE.plugins['font'] = function () {
  10714. var me = this,
  10715. fonts = {
  10716. 'forecolor': 'color',
  10717. 'backcolor': 'background-color',
  10718. 'fontsize': 'font-size',
  10719. 'fontfamily': 'font-family',
  10720. 'underline': 'text-decoration',
  10721. 'strikethrough': 'text-decoration',
  10722. 'fontborder': 'border'
  10723. },
  10724. needCmd = {'underline': 1, 'strikethrough': 1, 'fontborder': 1},
  10725. needSetChild = {
  10726. 'forecolor': 'color',
  10727. 'backcolor': 'background-color',
  10728. 'fontsize': 'font-size',
  10729. 'fontfamily': 'font-family'
  10730. };
  10731. me.setOpt({
  10732. 'fontfamily': [
  10733. { name: 'songti', val: '宋体,SimSun'},
  10734. { name: 'yahei', val: '微软雅黑,Microsoft YaHei'},
  10735. { name: 'kaiti', val: '楷体,楷体_GB2312, SimKai'},
  10736. { name: 'heiti', val: '黑体, SimHei'},
  10737. { name: 'lishu', val: '隶书, SimLi'},
  10738. { name: 'andaleMono', val: 'andale mono'},
  10739. { name: 'arial', val: 'arial, helvetica,sans-serif'},
  10740. { name: 'arialBlack', val: 'arial black,avant garde'},
  10741. { name: 'comicSansMs', val: 'comic sans ms'},
  10742. { name: 'impact', val: 'impact,chicago'},
  10743. { name: 'timesNewRoman', val: 'times new roman'}
  10744. ],
  10745. 'fontsize': [10, 11, 12, 14, 16, 18, 20, 24, 36]
  10746. });
  10747. function mergeWithParent(node){
  10748. var parent;
  10749. while(parent = node.parentNode){
  10750. if(parent.tagName == 'SPAN' && domUtils.getChildCount(parent,function(child){
  10751. return !domUtils.isBookmarkNode(child) && !domUtils.isBr(child)
  10752. }) == 1) {
  10753. parent.style.cssText += node.style.cssText;
  10754. domUtils.remove(node,true);
  10755. node = parent;
  10756. }else{
  10757. break;
  10758. }
  10759. }
  10760. }
  10761. function mergeChild(rng,cmdName,value){
  10762. if(needSetChild[cmdName]){
  10763. rng.adjustmentBoundary();
  10764. if(!rng.collapsed && rng.startContainer.nodeType == 1){
  10765. var start = rng.startContainer.childNodes[rng.startOffset];
  10766. if(start && domUtils.isTagNode(start,'span')){
  10767. var bk = rng.createBookmark();
  10768. utils.each(domUtils.getElementsByTagName(start, 'span'), function (span) {
  10769. if (!span.parentNode || domUtils.isBookmarkNode(span))return;
  10770. if(cmdName == 'backcolor' && domUtils.getComputedStyle(span,'background-color').toLowerCase() === value){
  10771. return;
  10772. }
  10773. domUtils.removeStyle(span,needSetChild[cmdName]);
  10774. if(span.style.cssText.replace(/^\s+$/,'').length == 0){
  10775. domUtils.remove(span,true)
  10776. }
  10777. });
  10778. rng.moveToBookmark(bk)
  10779. }
  10780. }
  10781. }
  10782. }
  10783. function mergesibling(rng,cmdName,value) {
  10784. var collapsed = rng.collapsed,
  10785. bk = rng.createBookmark(), common;
  10786. if (collapsed) {
  10787. common = bk.start.parentNode;
  10788. while (dtd.$inline[common.tagName]) {
  10789. common = common.parentNode;
  10790. }
  10791. } else {
  10792. common = domUtils.getCommonAncestor(bk.start, bk.end);
  10793. }
  10794. utils.each(domUtils.getElementsByTagName(common, 'span'), function (span) {
  10795. if (!span.parentNode || domUtils.isBookmarkNode(span))return;
  10796. if (/\s*border\s*:\s*none;?\s*/i.test(span.style.cssText)) {
  10797. if(/^\s*border\s*:\s*none;?\s*$/.test(span.style.cssText)){
  10798. domUtils.remove(span, true);
  10799. }else{
  10800. domUtils.removeStyle(span,'border');
  10801. }
  10802. return
  10803. }
  10804. if (/border/i.test(span.style.cssText) && span.parentNode.tagName == 'SPAN' && /border/i.test(span.parentNode.style.cssText)) {
  10805. span.style.cssText = span.style.cssText.replace(/border[^:]*:[^;]+;?/gi, '');
  10806. }
  10807. if(!(cmdName=='fontborder' && value=='none')){
  10808. var next = span.nextSibling;
  10809. while (next && next.nodeType == 1 && next.tagName == 'SPAN' ) {
  10810. if(domUtils.isBookmarkNode(next) && cmdName == 'fontborder') {
  10811. span.appendChild(next);
  10812. next = span.nextSibling;
  10813. continue;
  10814. }
  10815. if (next.style.cssText == span.style.cssText) {
  10816. domUtils.moveChild(next, span);
  10817. domUtils.remove(next);
  10818. }
  10819. if (span.nextSibling === next)
  10820. break;
  10821. next = span.nextSibling;
  10822. }
  10823. }
  10824. mergeWithParent(span);
  10825. if(browser.ie && browser.version > 8 ){
  10826. //拷贝父亲们的特别的属性,这里只做背景颜色的处理
  10827. var parent = domUtils.findParent(span,function(n){return n.tagName == 'SPAN' && /background-color/.test(n.style.cssText)});
  10828. if(parent && !/background-color/.test(span.style.cssText)){
  10829. span.style.backgroundColor = parent.style.backgroundColor;
  10830. }
  10831. }
  10832. });
  10833. rng.moveToBookmark(bk);
  10834. mergeChild(rng,cmdName,value)
  10835. }
  10836. me.addInputRule(function (root) {
  10837. utils.each(root.getNodesByTagName('u s del font strike'), function (node) {
  10838. if (node.tagName == 'font') {
  10839. var cssStyle = [];
  10840. for (var p in node.attrs) {
  10841. switch (p) {
  10842. case 'size':
  10843. cssStyle.push('font-size:' +
  10844. ({
  10845. '1':'10',
  10846. '2':'12',
  10847. '3':'16',
  10848. '4':'18',
  10849. '5':'24',
  10850. '6':'32',
  10851. '7':'48'
  10852. }[node.attrs[p]] || node.attrs[p]) + 'px');
  10853. break;
  10854. case 'color':
  10855. cssStyle.push('color:' + node.attrs[p]);
  10856. break;
  10857. case 'face':
  10858. cssStyle.push('font-family:' + node.attrs[p]);
  10859. break;
  10860. case 'style':
  10861. cssStyle.push(node.attrs[p]);
  10862. }
  10863. }
  10864. node.attrs = {
  10865. 'style': cssStyle.join(';')
  10866. };
  10867. } else {
  10868. var val = node.tagName == 'u' ? 'underline' : 'line-through';
  10869. node.attrs = {
  10870. 'style': (node.getAttr('style') || '') + 'text-decoration:' + val + ';'
  10871. }
  10872. }
  10873. node.tagName = 'span';
  10874. });
  10875. // utils.each(root.getNodesByTagName('span'), function (node) {
  10876. // var val;
  10877. // if(val = node.getAttr('class')){
  10878. // if(/fontstrikethrough/.test(val)){
  10879. // node.setStyle('text-decoration','line-through');
  10880. // if(node.attrs['class']){
  10881. // node.attrs['class'] = node.attrs['class'].replace(/fontstrikethrough/,'');
  10882. // }else{
  10883. // node.setAttr('class')
  10884. // }
  10885. // }
  10886. // if(/fontborder/.test(val)){
  10887. // node.setStyle('border','1px solid #000');
  10888. // if(node.attrs['class']){
  10889. // node.attrs['class'] = node.attrs['class'].replace(/fontborder/,'');
  10890. // }else{
  10891. // node.setAttr('class')
  10892. // }
  10893. // }
  10894. // }
  10895. // });
  10896. });
  10897. // me.addOutputRule(function(root){
  10898. // utils.each(root.getNodesByTagName('span'), function (node) {
  10899. // var val;
  10900. // if(val = node.getStyle('text-decoration')){
  10901. // if(/line-through/.test(val)){
  10902. // if(node.attrs['class']){
  10903. // node.attrs['class'] += ' fontstrikethrough';
  10904. // }else{
  10905. // node.setAttr('class','fontstrikethrough')
  10906. // }
  10907. // }
  10908. //
  10909. // node.setStyle('text-decoration')
  10910. // }
  10911. // if(val = node.getStyle('border')){
  10912. // if(/1px/.test(val) && /solid/.test(val)){
  10913. // if(node.attrs['class']){
  10914. // node.attrs['class'] += ' fontborder';
  10915. //
  10916. // }else{
  10917. // node.setAttr('class','fontborder')
  10918. // }
  10919. // }
  10920. // node.setStyle('border')
  10921. //
  10922. // }
  10923. // });
  10924. // });
  10925. for (var p in fonts) {
  10926. (function (cmd, style) {
  10927. UE.commands[cmd] = {
  10928. execCommand: function (cmdName, value) {
  10929. value = value || (this.queryCommandState(cmdName) ? 'none' : cmdName == 'underline' ? 'underline' :
  10930. cmdName == 'fontborder' ? '1px solid #000' :
  10931. 'line-through');
  10932. var me = this,
  10933. range = this.selection.getRange(),
  10934. text;
  10935. if (value == 'default') {
  10936. if (range.collapsed) {
  10937. text = me.document.createTextNode('font');
  10938. range.insertNode(text).select();
  10939. }
  10940. me.execCommand('removeFormat', 'span,a', style);
  10941. if (text) {
  10942. range.setStartBefore(text).collapse(true);
  10943. domUtils.remove(text);
  10944. }
  10945. mergesibling(range,cmdName,value);
  10946. range.select()
  10947. } else {
  10948. if (!range.collapsed) {
  10949. if (needCmd[cmd] && me.queryCommandValue(cmd)) {
  10950. me.execCommand('removeFormat', 'span,a', style);
  10951. }
  10952. range = me.selection.getRange();
  10953. range.applyInlineStyle('span', {'style': style + ':' + value});
  10954. mergesibling(range, cmdName,value);
  10955. range.select();
  10956. } else {
  10957. var span = domUtils.findParentByTagName(range.startContainer, 'span', true);
  10958. text = me.document.createTextNode('font');
  10959. if (span && !span.children.length && !span[browser.ie ? 'innerText' : 'textContent'].replace(fillCharReg, '').length) {
  10960. //for ie hack when enter
  10961. range.insertNode(text);
  10962. if (needCmd[cmd]) {
  10963. range.selectNode(text).select();
  10964. me.execCommand('removeFormat', 'span,a', style, null);
  10965. span = domUtils.findParentByTagName(text, 'span', true);
  10966. range.setStartBefore(text);
  10967. }
  10968. span && (span.style.cssText += ';' + style + ':' + value);
  10969. range.collapse(true).select();
  10970. } else {
  10971. range.insertNode(text);
  10972. range.selectNode(text).select();
  10973. span = range.document.createElement('span');
  10974. if (needCmd[cmd]) {
  10975. //a标签内的不处理跳过
  10976. if (domUtils.findParentByTagName(text, 'a', true)) {
  10977. range.setStartBefore(text).setCursor();
  10978. domUtils.remove(text);
  10979. return;
  10980. }
  10981. me.execCommand('removeFormat', 'span,a', style);
  10982. }
  10983. span.style.cssText = style + ':' + value;
  10984. text.parentNode.insertBefore(span, text);
  10985. //修复,span套span 但样式不继承的问题
  10986. if (!browser.ie || browser.ie && browser.version == 9) {
  10987. var spanParent = span.parentNode;
  10988. while (!domUtils.isBlockElm(spanParent)) {
  10989. if (spanParent.tagName == 'SPAN') {
  10990. //opera合并style不会加入";"
  10991. span.style.cssText = spanParent.style.cssText + ";" + span.style.cssText;
  10992. }
  10993. spanParent = spanParent.parentNode;
  10994. }
  10995. }
  10996. if (opera) {
  10997. setTimeout(function () {
  10998. range.setStart(span, 0).collapse(true);
  10999. mergesibling(range, cmdName,value);
  11000. range.select();
  11001. });
  11002. } else {
  11003. range.setStart(span, 0).collapse(true);
  11004. mergesibling(range,cmdName,value);
  11005. range.select();
  11006. }
  11007. //trace:981
  11008. //domUtils.mergeToParent(span)
  11009. }
  11010. domUtils.remove(text);
  11011. }
  11012. }
  11013. return true;
  11014. },
  11015. queryCommandValue: function (cmdName) {
  11016. var startNode = this.selection.getStart();
  11017. //trace:946
  11018. if (cmdName == 'underline' || cmdName == 'strikethrough') {
  11019. var tmpNode = startNode, value;
  11020. while (tmpNode && !domUtils.isBlockElm(tmpNode) && !domUtils.isBody(tmpNode)) {
  11021. if (tmpNode.nodeType == 1) {
  11022. value = domUtils.getComputedStyle(tmpNode, style);
  11023. if (value != 'none') {
  11024. return value;
  11025. }
  11026. }
  11027. tmpNode = tmpNode.parentNode;
  11028. }
  11029. return 'none';
  11030. }
  11031. if (cmdName == 'fontborder') {
  11032. var tmp = startNode, val;
  11033. while (tmp && dtd.$inline[tmp.tagName]) {
  11034. if (val = domUtils.getComputedStyle(tmp, 'border')) {
  11035. if (/1px/.test(val) && /solid/.test(val)) {
  11036. return val;
  11037. }
  11038. }
  11039. tmp = tmp.parentNode;
  11040. }
  11041. return ''
  11042. }
  11043. if( cmdName == 'FontSize' ) {
  11044. var styleVal = domUtils.getComputedStyle(startNode, style),
  11045. tmp = /^([\d\.]+)(\w+)$/.exec( styleVal );
  11046. if( tmp ) {
  11047. return Math.floor( tmp[1] ) + tmp[2];
  11048. }
  11049. return styleVal;
  11050. }
  11051. return domUtils.getComputedStyle(startNode, style);
  11052. },
  11053. queryCommandState: function (cmdName) {
  11054. if (!needCmd[cmdName])
  11055. return 0;
  11056. var val = this.queryCommandValue(cmdName);
  11057. if (cmdName == 'fontborder') {
  11058. return /1px/.test(val) && /solid/.test(val)
  11059. } else {
  11060. return cmdName == 'underline' ? /underline/.test(val) : /line\-through/.test(val);
  11061. }
  11062. }
  11063. };
  11064. })(p, fonts[p]);
  11065. }
  11066. };
  11067. // plugins/link.js
  11068. /**
  11069. * 超链接
  11070. * @file
  11071. * @since 1.2.6.1
  11072. */
  11073. /**
  11074. * 插入超链接
  11075. * @command link
  11076. * @method execCommand
  11077. * @param { String } cmd 命令字符串
  11078. * @param { Object } options 设置自定义属性,例如:url、title、target
  11079. * @example
  11080. * ```javascript
  11081. * editor.execCommand( 'link', '{
  11082. * url:'ueditor.baidu.com',
  11083. * title:'ueditor',
  11084. * target:'_blank'
  11085. * }' );
  11086. * ```
  11087. */
  11088. /**
  11089. * 返回当前选中的第一个超链接节点
  11090. * @command link
  11091. * @method queryCommandValue
  11092. * @param { String } cmd 命令字符串
  11093. * @return { Element } 超链接节点
  11094. * @example
  11095. * ```javascript
  11096. * editor.queryCommandValue( 'link' );
  11097. * ```
  11098. */
  11099. /**
  11100. * 取消超链接
  11101. * @command unlink
  11102. * @method execCommand
  11103. * @param { String } cmd 命令字符串
  11104. * @example
  11105. * ```javascript
  11106. * editor.execCommand( 'unlink');
  11107. * ```
  11108. */
  11109. UE.plugins['link'] = function(){
  11110. function optimize( range ) {
  11111. var start = range.startContainer,end = range.endContainer;
  11112. if ( start = domUtils.findParentByTagName( start, 'a', true ) ) {
  11113. range.setStartBefore( start );
  11114. }
  11115. if ( end = domUtils.findParentByTagName( end, 'a', true ) ) {
  11116. range.setEndAfter( end );
  11117. }
  11118. }
  11119. UE.commands['unlink'] = {
  11120. execCommand : function() {
  11121. var range = this.selection.getRange(),
  11122. bookmark;
  11123. if(range.collapsed && !domUtils.findParentByTagName( range.startContainer, 'a', true )){
  11124. return;
  11125. }
  11126. bookmark = range.createBookmark();
  11127. optimize( range );
  11128. range.removeInlineStyle( 'a' ).moveToBookmark( bookmark ).select();
  11129. },
  11130. queryCommandState : function(){
  11131. return !this.highlight && this.queryCommandValue('link') ? 0 : -1;
  11132. }
  11133. };
  11134. function doLink(range,opt,me){
  11135. var rngClone = range.cloneRange(),
  11136. link = me.queryCommandValue('link');
  11137. optimize( range = range.adjustmentBoundary() );
  11138. var start = range.startContainer;
  11139. if(start.nodeType == 1 && link){
  11140. start = start.childNodes[range.startOffset];
  11141. if(start && start.nodeType == 1 && start.tagName == 'A' && /^(?:https?|ftp|file)\s*:\s*\/\//.test(start[browser.ie?'innerText':'textContent'])){
  11142. start[browser.ie ? 'innerText' : 'textContent'] = utils.html(opt.textValue||opt.href);
  11143. }
  11144. }
  11145. if( !rngClone.collapsed || link){
  11146. range.removeInlineStyle( 'a' );
  11147. rngClone = range.cloneRange();
  11148. }
  11149. if ( rngClone.collapsed ) {
  11150. var a = range.document.createElement( 'a'),
  11151. text = '';
  11152. if(opt.textValue){
  11153. text = utils.html(opt.textValue);
  11154. delete opt.textValue;
  11155. }else{
  11156. text = utils.html(opt.href);
  11157. }
  11158. domUtils.setAttributes( a, opt );
  11159. start = domUtils.findParentByTagName( rngClone.startContainer, 'a', true );
  11160. if(start && domUtils.isInNodeEndBoundary(rngClone,start)){
  11161. range.setStartAfter(start).collapse(true);
  11162. }
  11163. a[browser.ie ? 'innerText' : 'textContent'] = text;
  11164. range.insertNode(a).selectNode( a );
  11165. } else {
  11166. range.applyInlineStyle( 'a', opt );
  11167. }
  11168. }
  11169. UE.commands['link'] = {
  11170. execCommand : function( cmdName, opt ) {
  11171. var range;
  11172. opt._href && (opt._href = utils.unhtml(opt._href,/[<">]/g));
  11173. opt.href && (opt.href = utils.unhtml(opt.href,/[<">]/g));
  11174. opt.textValue && (opt.textValue = utils.unhtml(opt.textValue,/[<">]/g));
  11175. doLink(range=this.selection.getRange(),opt,this);
  11176. //闭合都不加占位符,如果加了会在a后边多个占位符节点,导致a是图片背景组成的列表,出现空白问题
  11177. range.collapse().select(true);
  11178. },
  11179. queryCommandValue : function() {
  11180. var range = this.selection.getRange(),
  11181. node;
  11182. if ( range.collapsed ) {
  11183. // node = this.selection.getStart();
  11184. //在ie下getstart()取值偏上了
  11185. node = range.startContainer;
  11186. node = node.nodeType == 1 ? node : node.parentNode;
  11187. if ( node && (node = domUtils.findParentByTagName( node, 'a', true )) && ! domUtils.isInNodeEndBoundary(range,node)) {
  11188. return node;
  11189. }
  11190. } else {
  11191. //trace:1111 如果是<p><a>xx</a></p> startContainer是p就会找不到a
  11192. range.shrinkBoundary();
  11193. var start = range.startContainer.nodeType == 3 || !range.startContainer.childNodes[range.startOffset] ? range.startContainer : range.startContainer.childNodes[range.startOffset],
  11194. end = range.endContainer.nodeType == 3 || range.endOffset == 0 ? range.endContainer : range.endContainer.childNodes[range.endOffset-1],
  11195. common = range.getCommonAncestor();
  11196. node = domUtils.findParentByTagName( common, 'a', true );
  11197. if ( !node && common.nodeType == 1){
  11198. var as = common.getElementsByTagName( 'a' ),
  11199. ps,pe;
  11200. for ( var i = 0,ci; ci = as[i++]; ) {
  11201. ps = domUtils.getPosition( ci, start ),pe = domUtils.getPosition( ci,end);
  11202. if ( (ps & domUtils.POSITION_FOLLOWING || ps & domUtils.POSITION_CONTAINS)
  11203. &&
  11204. (pe & domUtils.POSITION_PRECEDING || pe & domUtils.POSITION_CONTAINS)
  11205. ) {
  11206. node = ci;
  11207. break;
  11208. }
  11209. }
  11210. }
  11211. return node;
  11212. }
  11213. },
  11214. queryCommandState : function() {
  11215. //判断如果是视频的话连接不可用
  11216. //fix 853
  11217. var img = this.selection.getRange().getClosedNode(),
  11218. flag = img && (img.className == "edui-faked-video" || img.className.indexOf("edui-upload-video")!=-1);
  11219. return flag ? -1 : 0;
  11220. }
  11221. };
  11222. };
  11223. // plugins/iframe.js
  11224. ///import core
  11225. ///import plugins\inserthtml.js
  11226. ///commands 插入框架
  11227. ///commandsName InsertFrame
  11228. ///commandsTitle 插入Iframe
  11229. ///commandsDialog dialogs\insertframe
  11230. UE.plugins['insertframe'] = function() {
  11231. var me =this;
  11232. function deleteIframe(){
  11233. me._iframe && delete me._iframe;
  11234. }
  11235. me.addListener("selectionchange",function(){
  11236. deleteIframe();
  11237. });
  11238. };
  11239. // plugins/scrawl.js
  11240. ///import core
  11241. ///commands 涂鸦
  11242. ///commandsName Scrawl
  11243. ///commandsTitle 涂鸦
  11244. ///commandsDialog dialogs\scrawl
  11245. UE.commands['scrawl'] = {
  11246. queryCommandState : function(){
  11247. return ( browser.ie && browser.version <= 8 ) ? -1 :0;
  11248. }
  11249. };
  11250. // plugins/removeformat.js
  11251. /**
  11252. * 清除格式
  11253. * @file
  11254. * @since 1.2.6.1
  11255. */
  11256. /**
  11257. * 清除文字样式
  11258. * @command removeformat
  11259. * @method execCommand
  11260. * @param { String } cmd 命令字符串
  11261. * @param {String} tags 以逗号隔开的标签。如:strong
  11262. * @param {String} style 样式如:color
  11263. * @param {String} attrs 属性如:width
  11264. * @example
  11265. * ```javascript
  11266. * editor.execCommand( 'removeformat', 'strong','color','width' );
  11267. * ```
  11268. */
  11269. UE.plugins['removeformat'] = function(){
  11270. var me = this;
  11271. me.setOpt({
  11272. 'removeFormatTags': 'b,big,code,del,dfn,em,font,i,ins,kbd,q,samp,small,span,strike,strong,sub,sup,tt,u,var',
  11273. 'removeFormatAttributes':'class,style,lang,width,height,align,hspace,valign'
  11274. });
  11275. me.commands['removeformat'] = {
  11276. execCommand : function( cmdName, tags, style, attrs,notIncludeA ) {
  11277. var tagReg = new RegExp( '^(?:' + (tags || this.options.removeFormatTags).replace( /,/g, '|' ) + ')$', 'i' ) ,
  11278. removeFormatAttributes = style ? [] : (attrs || this.options.removeFormatAttributes).split( ',' ),
  11279. range = new dom.Range( this.document ),
  11280. bookmark,node,parent,
  11281. filter = function( node ) {
  11282. return node.nodeType == 1;
  11283. };
  11284. function isRedundantSpan (node) {
  11285. if (node.nodeType == 3 || node.tagName.toLowerCase() != 'span'){
  11286. return 0;
  11287. }
  11288. if (browser.ie) {
  11289. //ie 下判断实效,所以只能简单用style来判断
  11290. //return node.style.cssText == '' ? 1 : 0;
  11291. var attrs = node.attributes;
  11292. if ( attrs.length ) {
  11293. for ( var i = 0,l = attrs.length; i<l; i++ ) {
  11294. if ( attrs[i].specified ) {
  11295. return 0;
  11296. }
  11297. }
  11298. return 1;
  11299. }
  11300. }
  11301. return !node.attributes.length;
  11302. }
  11303. function doRemove( range ) {
  11304. var bookmark1 = range.createBookmark();
  11305. if ( range.collapsed ) {
  11306. range.enlarge( true );
  11307. }
  11308. //不能把a标签切了
  11309. if(!notIncludeA){
  11310. var aNode = domUtils.findParentByTagName(range.startContainer,'a',true);
  11311. if(aNode){
  11312. range.setStartBefore(aNode);
  11313. }
  11314. aNode = domUtils.findParentByTagName(range.endContainer,'a',true);
  11315. if(aNode){
  11316. range.setEndAfter(aNode);
  11317. }
  11318. }
  11319. bookmark = range.createBookmark();
  11320. node = bookmark.start;
  11321. //切开始
  11322. while ( (parent = node.parentNode) && !domUtils.isBlockElm( parent ) ) {
  11323. domUtils.breakParent( node, parent );
  11324. domUtils.clearEmptySibling( node );
  11325. }
  11326. if ( bookmark.end ) {
  11327. //切结束
  11328. node = bookmark.end;
  11329. while ( (parent = node.parentNode) && !domUtils.isBlockElm( parent ) ) {
  11330. domUtils.breakParent( node, parent );
  11331. domUtils.clearEmptySibling( node );
  11332. }
  11333. //开始去除样式
  11334. var current = domUtils.getNextDomNode( bookmark.start, false, filter ),
  11335. next;
  11336. while ( current ) {
  11337. if ( current == bookmark.end ) {
  11338. break;
  11339. }
  11340. next = domUtils.getNextDomNode( current, true, filter );
  11341. if ( !dtd.$empty[current.tagName.toLowerCase()] && !domUtils.isBookmarkNode( current ) ) {
  11342. if ( tagReg.test( current.tagName ) ) {
  11343. if ( style ) {
  11344. domUtils.removeStyle( current, style );
  11345. if ( isRedundantSpan( current ) && style != 'text-decoration'){
  11346. domUtils.remove( current, true );
  11347. }
  11348. } else {
  11349. domUtils.remove( current, true );
  11350. }
  11351. } else {
  11352. //trace:939 不能把list上的样式去掉
  11353. if(!dtd.$tableContent[current.tagName] && !dtd.$list[current.tagName]){
  11354. domUtils.removeAttributes( current, removeFormatAttributes );
  11355. if ( isRedundantSpan( current ) ){
  11356. domUtils.remove( current, true );
  11357. }
  11358. }
  11359. }
  11360. }
  11361. current = next;
  11362. }
  11363. }
  11364. //trace:1035
  11365. //trace:1096 不能把td上的样式去掉,比如边框
  11366. var pN = bookmark.start.parentNode;
  11367. if(domUtils.isBlockElm(pN) && !dtd.$tableContent[pN.tagName] && !dtd.$list[pN.tagName]){
  11368. domUtils.removeAttributes( pN,removeFormatAttributes );
  11369. }
  11370. pN = bookmark.end.parentNode;
  11371. if(bookmark.end && domUtils.isBlockElm(pN) && !dtd.$tableContent[pN.tagName]&& !dtd.$list[pN.tagName]){
  11372. domUtils.removeAttributes( pN,removeFormatAttributes );
  11373. }
  11374. range.moveToBookmark( bookmark ).moveToBookmark(bookmark1);
  11375. //清除冗余的代码 <b><bookmark></b>
  11376. var node = range.startContainer,
  11377. tmp,
  11378. collapsed = range.collapsed;
  11379. while(node.nodeType == 1 && domUtils.isEmptyNode(node) && dtd.$removeEmpty[node.tagName]){
  11380. tmp = node.parentNode;
  11381. range.setStartBefore(node);
  11382. //trace:937
  11383. //更新结束边界
  11384. if(range.startContainer === range.endContainer){
  11385. range.endOffset--;
  11386. }
  11387. domUtils.remove(node);
  11388. node = tmp;
  11389. }
  11390. if(!collapsed){
  11391. node = range.endContainer;
  11392. while(node.nodeType == 1 && domUtils.isEmptyNode(node) && dtd.$removeEmpty[node.tagName]){
  11393. tmp = node.parentNode;
  11394. range.setEndBefore(node);
  11395. domUtils.remove(node);
  11396. node = tmp;
  11397. }
  11398. }
  11399. }
  11400. range = this.selection.getRange();
  11401. doRemove( range );
  11402. range.select();
  11403. }
  11404. };
  11405. };
  11406. // plugins/blockquote.js
  11407. /**
  11408. * 添加引用
  11409. * @file
  11410. * @since 1.2.6.1
  11411. */
  11412. /**
  11413. * 添加引用
  11414. * @command blockquote
  11415. * @method execCommand
  11416. * @param { String } cmd 命令字符串
  11417. * @example
  11418. * ```javascript
  11419. * editor.execCommand( 'blockquote' );
  11420. * ```
  11421. */
  11422. /**
  11423. * 添加引用
  11424. * @command blockquote
  11425. * @method execCommand
  11426. * @param { String } cmd 命令字符串
  11427. * @param { Object } attrs 节点属性
  11428. * @example
  11429. * ```javascript
  11430. * editor.execCommand( 'blockquote',{
  11431. * style: "color: red;"
  11432. * } );
  11433. * ```
  11434. */
  11435. UE.plugins['blockquote'] = function(){
  11436. var me = this;
  11437. function getObj(editor){
  11438. return domUtils.filterNodeList(editor.selection.getStartElementPath(),'blockquote');
  11439. }
  11440. me.commands['blockquote'] = {
  11441. execCommand : function( cmdName, attrs ) {
  11442. var range = this.selection.getRange(),
  11443. obj = getObj(this),
  11444. blockquote = dtd.blockquote,
  11445. bookmark = range.createBookmark();
  11446. if ( obj ) {
  11447. var start = range.startContainer,
  11448. startBlock = domUtils.isBlockElm(start) ? start : domUtils.findParent(start,function(node){return domUtils.isBlockElm(node)}),
  11449. end = range.endContainer,
  11450. endBlock = domUtils.isBlockElm(end) ? end : domUtils.findParent(end,function(node){return domUtils.isBlockElm(node)});
  11451. //处理一下li
  11452. startBlock = domUtils.findParentByTagName(startBlock,'li',true) || startBlock;
  11453. endBlock = domUtils.findParentByTagName(endBlock,'li',true) || endBlock;
  11454. if(startBlock.tagName == 'LI' || startBlock.tagName == 'TD' || startBlock === obj || domUtils.isBody(startBlock)){
  11455. domUtils.remove(obj,true);
  11456. }else{
  11457. domUtils.breakParent(startBlock,obj);
  11458. }
  11459. if(startBlock !== endBlock){
  11460. obj = domUtils.findParentByTagName(endBlock,'blockquote');
  11461. if(obj){
  11462. if(endBlock.tagName == 'LI' || endBlock.tagName == 'TD'|| domUtils.isBody(endBlock)){
  11463. obj.parentNode && domUtils.remove(obj,true);
  11464. }else{
  11465. domUtils.breakParent(endBlock,obj);
  11466. }
  11467. }
  11468. }
  11469. var blockquotes = domUtils.getElementsByTagName(this.document,'blockquote');
  11470. for(var i=0,bi;bi=blockquotes[i++];){
  11471. if(!bi.childNodes.length){
  11472. domUtils.remove(bi);
  11473. }else if(domUtils.getPosition(bi,startBlock)&domUtils.POSITION_FOLLOWING && domUtils.getPosition(bi,endBlock)&domUtils.POSITION_PRECEDING){
  11474. domUtils.remove(bi,true);
  11475. }
  11476. }
  11477. } else {
  11478. var tmpRange = range.cloneRange(),
  11479. node = tmpRange.startContainer.nodeType == 1 ? tmpRange.startContainer : tmpRange.startContainer.parentNode,
  11480. preNode = node,
  11481. doEnd = 1;
  11482. //调整开始
  11483. while ( 1 ) {
  11484. if ( domUtils.isBody(node) ) {
  11485. if ( preNode !== node ) {
  11486. if ( range.collapsed ) {
  11487. tmpRange.selectNode( preNode );
  11488. doEnd = 0;
  11489. } else {
  11490. tmpRange.setStartBefore( preNode );
  11491. }
  11492. }else{
  11493. tmpRange.setStart(node,0);
  11494. }
  11495. break;
  11496. }
  11497. if ( !blockquote[node.tagName] ) {
  11498. if ( range.collapsed ) {
  11499. tmpRange.selectNode( preNode );
  11500. } else{
  11501. tmpRange.setStartBefore( preNode);
  11502. }
  11503. break;
  11504. }
  11505. preNode = node;
  11506. node = node.parentNode;
  11507. }
  11508. //调整结束
  11509. if ( doEnd ) {
  11510. preNode = node = node = tmpRange.endContainer.nodeType == 1 ? tmpRange.endContainer : tmpRange.endContainer.parentNode;
  11511. while ( 1 ) {
  11512. if ( domUtils.isBody( node ) ) {
  11513. if ( preNode !== node ) {
  11514. tmpRange.setEndAfter( preNode );
  11515. } else {
  11516. tmpRange.setEnd( node, node.childNodes.length );
  11517. }
  11518. break;
  11519. }
  11520. if ( !blockquote[node.tagName] ) {
  11521. tmpRange.setEndAfter( preNode );
  11522. break;
  11523. }
  11524. preNode = node;
  11525. node = node.parentNode;
  11526. }
  11527. }
  11528. node = range.document.createElement( 'blockquote' );
  11529. domUtils.setAttributes( node, attrs );
  11530. node.appendChild( tmpRange.extractContents() );
  11531. tmpRange.insertNode( node );
  11532. //去除重复的
  11533. var childs = domUtils.getElementsByTagName(node,'blockquote');
  11534. for(var i=0,ci;ci=childs[i++];){
  11535. if(ci.parentNode){
  11536. domUtils.remove(ci,true);
  11537. }
  11538. }
  11539. }
  11540. range.moveToBookmark( bookmark ).select();
  11541. },
  11542. queryCommandState : function() {
  11543. return getObj(this) ? 1 : 0;
  11544. }
  11545. };
  11546. };
  11547. // plugins/convertcase.js
  11548. /**
  11549. * 大小写转换
  11550. * @file
  11551. * @since 1.2.6.1
  11552. */
  11553. /**
  11554. * 把选区内文本变大写,与“tolowercase”命令互斥
  11555. * @command touppercase
  11556. * @method execCommand
  11557. * @param { String } cmd 命令字符串
  11558. * @example
  11559. * ```javascript
  11560. * editor.execCommand( 'touppercase' );
  11561. * ```
  11562. */
  11563. /**
  11564. * 把选区内文本变小写,与“touppercase”命令互斥
  11565. * @command tolowercase
  11566. * @method execCommand
  11567. * @param { String } cmd 命令字符串
  11568. * @example
  11569. * ```javascript
  11570. * editor.execCommand( 'tolowercase' );
  11571. * ```
  11572. */
  11573. UE.commands['touppercase'] =
  11574. UE.commands['tolowercase'] = {
  11575. execCommand:function (cmd) {
  11576. var me = this;
  11577. var rng = me.selection.getRange();
  11578. if(rng.collapsed){
  11579. return rng;
  11580. }
  11581. var bk = rng.createBookmark(),
  11582. bkEnd = bk.end,
  11583. filterFn = function( node ) {
  11584. return !domUtils.isBr(node) && !domUtils.isWhitespace( node );
  11585. },
  11586. curNode = domUtils.getNextDomNode( bk.start, false, filterFn );
  11587. while ( curNode && (domUtils.getPosition( curNode, bkEnd ) & domUtils.POSITION_PRECEDING) ) {
  11588. if ( curNode.nodeType == 3 ) {
  11589. curNode.nodeValue = curNode.nodeValue[cmd == 'touppercase' ? 'toUpperCase' : 'toLowerCase']();
  11590. }
  11591. curNode = domUtils.getNextDomNode( curNode, true, filterFn );
  11592. if(curNode === bkEnd){
  11593. break;
  11594. }
  11595. }
  11596. rng.moveToBookmark(bk).select();
  11597. }
  11598. };
  11599. // plugins/indent.js
  11600. /**
  11601. * 首行缩进
  11602. * @file
  11603. * @since 1.2.6.1
  11604. */
  11605. /**
  11606. * 缩进
  11607. * @command indent
  11608. * @method execCommand
  11609. * @param { String } cmd 命令字符串
  11610. * @example
  11611. * ```javascript
  11612. * editor.execCommand( 'indent' );
  11613. * ```
  11614. */
  11615. UE.commands['indent'] = {
  11616. execCommand : function() {
  11617. var me = this,value = me.queryCommandState("indent") ? "0em" : (me.options.indentValue || '2em');
  11618. me.execCommand('Paragraph','p',{style:'text-indent:'+ value});
  11619. },
  11620. queryCommandState : function() {
  11621. var pN = domUtils.filterNodeList(this.selection.getStartElementPath(),'p h1 h2 h3 h4 h5 h6');
  11622. return pN && pN.style.textIndent && parseInt(pN.style.textIndent) ? 1 : 0;
  11623. }
  11624. };
  11625. // plugins/print.js
  11626. /**
  11627. * 打印
  11628. * @file
  11629. * @since 1.2.6.1
  11630. */
  11631. /**
  11632. * 打印
  11633. * @command print
  11634. * @method execCommand
  11635. * @param { String } cmd 命令字符串
  11636. * @example
  11637. * ```javascript
  11638. * editor.execCommand( 'print' );
  11639. * ```
  11640. */
  11641. UE.commands['print'] = {
  11642. execCommand : function(){
  11643. this.window.print();
  11644. },
  11645. notNeedUndo : 1
  11646. };
  11647. // plugins/preview.js
  11648. /**
  11649. * 预览
  11650. * @file
  11651. * @since 1.2.6.1
  11652. */
  11653. /**
  11654. * 预览
  11655. * @command preview
  11656. * @method execCommand
  11657. * @param { String } cmd 命令字符串
  11658. * @example
  11659. * ```javascript
  11660. * editor.execCommand( 'preview' );
  11661. * ```
  11662. */
  11663. UE.commands['preview'] = {
  11664. execCommand : function(){
  11665. var w = window.open('', '_blank', ''),
  11666. d = w.document;
  11667. d.open();
  11668. d.write('<!DOCTYPE html><html><head><meta charset="utf-8"/><script src="'+this.options.UEDITOR_HOME_URL+'ueditor.parse.js"></script><script>' +
  11669. "setTimeout(function(){uParse('div',{rootPath: '"+ this.options.UEDITOR_HOME_URL +"'})},300)" +
  11670. '</script></head><body><div>'+this.getContent(null,null,true)+'</div></body></html>');
  11671. d.close();
  11672. },
  11673. notNeedUndo : 1
  11674. };
  11675. // plugins/selectall.js
  11676. /**
  11677. * 全选
  11678. * @file
  11679. * @since 1.2.6.1
  11680. */
  11681. /**
  11682. * 选中所有内容
  11683. * @command selectall
  11684. * @method execCommand
  11685. * @param { String } cmd 命令字符串
  11686. * @example
  11687. * ```javascript
  11688. * editor.execCommand( 'selectall' );
  11689. * ```
  11690. */
  11691. UE.plugins['selectall'] = function(){
  11692. var me = this;
  11693. me.commands['selectall'] = {
  11694. execCommand : function(){
  11695. //去掉了原生的selectAll,因为会出现报错和当内容为空时,不能出现闭合状态的光标
  11696. var me = this,body = me.body,
  11697. range = me.selection.getRange();
  11698. range.selectNodeContents(body);
  11699. if(domUtils.isEmptyBlock(body)){
  11700. //opera不能自动合并到元素的里边,要手动处理一下
  11701. if(browser.opera && body.firstChild && body.firstChild.nodeType == 1){
  11702. range.setStartAtFirst(body.firstChild);
  11703. }
  11704. range.collapse(true);
  11705. }
  11706. range.select(true);
  11707. },
  11708. notNeedUndo : 1
  11709. };
  11710. //快捷键
  11711. me.addshortcutkey({
  11712. "selectAll" : "ctrl+65"
  11713. });
  11714. };
  11715. // plugins/paragraph.js
  11716. /**
  11717. * 段落样式
  11718. * @file
  11719. * @since 1.2.6.1
  11720. */
  11721. /**
  11722. * 段落格式
  11723. * @command paragraph
  11724. * @method execCommand
  11725. * @param { String } cmd 命令字符串
  11726. * @param {String} style 标签值为:'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
  11727. * @param {Object} attrs 标签的属性
  11728. * @example
  11729. * ```javascript
  11730. * editor.execCommand( 'Paragraph','h1','{
  11731. * class:'test'
  11732. * }' );
  11733. * ```
  11734. */
  11735. /**
  11736. * 返回选区内节点标签名
  11737. * @command paragraph
  11738. * @method queryCommandValue
  11739. * @param { String } cmd 命令字符串
  11740. * @return { String } 节点标签名
  11741. * @example
  11742. * ```javascript
  11743. * editor.queryCommandValue( 'Paragraph' );
  11744. * ```
  11745. */
  11746. UE.plugins['paragraph'] = function() {
  11747. var me = this,
  11748. block = domUtils.isBlockElm,
  11749. notExchange = ['TD','LI','PRE'],
  11750. doParagraph = function(range,style,attrs,sourceCmdName){
  11751. var bookmark = range.createBookmark(),
  11752. filterFn = function( node ) {
  11753. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' && !domUtils.isBookmarkNode(node) : !domUtils.isWhitespace( node );
  11754. },
  11755. para;
  11756. range.enlarge( true );
  11757. var bookmark2 = range.createBookmark(),
  11758. current = domUtils.getNextDomNode( bookmark2.start, false, filterFn ),
  11759. tmpRange = range.cloneRange(),
  11760. tmpNode;
  11761. while ( current && !(domUtils.getPosition( current, bookmark2.end ) & domUtils.POSITION_FOLLOWING) ) {
  11762. if ( current.nodeType == 3 || !block( current ) ) {
  11763. tmpRange.setStartBefore( current );
  11764. while ( current && current !== bookmark2.end && !block( current ) ) {
  11765. tmpNode = current;
  11766. current = domUtils.getNextDomNode( current, false, null, function( node ) {
  11767. return !block( node );
  11768. } );
  11769. }
  11770. tmpRange.setEndAfter( tmpNode );
  11771. para = range.document.createElement( style );
  11772. if(attrs){
  11773. domUtils.setAttributes(para,attrs);
  11774. if(sourceCmdName && sourceCmdName == 'customstyle' && attrs.style){
  11775. para.style.cssText = attrs.style;
  11776. }
  11777. }
  11778. para.appendChild( tmpRange.extractContents() );
  11779. //需要内容占位
  11780. if(domUtils.isEmptyNode(para)){
  11781. domUtils.fillChar(range.document,para);
  11782. }
  11783. tmpRange.insertNode( para );
  11784. var parent = para.parentNode;
  11785. //如果para上一级是一个block元素且不是body,td就删除它
  11786. if ( block( parent ) && !domUtils.isBody( para.parentNode ) && utils.indexOf(notExchange,parent.tagName)==-1) {
  11787. //存储dir,style
  11788. if(!(sourceCmdName && sourceCmdName == 'customstyle')){
  11789. parent.getAttribute('dir') && para.setAttribute('dir',parent.getAttribute('dir'));
  11790. //trace:1070
  11791. parent.style.cssText && (para.style.cssText = parent.style.cssText + ';' + para.style.cssText);
  11792. //trace:1030
  11793. parent.style.textAlign && !para.style.textAlign && (para.style.textAlign = parent.style.textAlign);
  11794. parent.style.textIndent && !para.style.textIndent && (para.style.textIndent = parent.style.textIndent);
  11795. parent.style.padding && !para.style.padding && (para.style.padding = parent.style.padding);
  11796. }
  11797. //trace:1706 选择的就是h1-6要删除
  11798. if(attrs && /h\d/i.test(parent.tagName) && !/h\d/i.test(para.tagName) ){
  11799. domUtils.setAttributes(parent,attrs);
  11800. if(sourceCmdName && sourceCmdName == 'customstyle' && attrs.style){
  11801. parent.style.cssText = attrs.style;
  11802. }
  11803. domUtils.remove(para,true);
  11804. para = parent;
  11805. }else{
  11806. domUtils.remove( para.parentNode, true );
  11807. }
  11808. }
  11809. if( utils.indexOf(notExchange,parent.tagName)!=-1){
  11810. current = parent;
  11811. }else{
  11812. current = para;
  11813. }
  11814. current = domUtils.getNextDomNode( current, false, filterFn );
  11815. } else {
  11816. current = domUtils.getNextDomNode( current, true, filterFn );
  11817. }
  11818. }
  11819. return range.moveToBookmark( bookmark2 ).moveToBookmark( bookmark );
  11820. };
  11821. me.setOpt('paragraph',{'p':'', 'h1':'', 'h2':'', 'h3':'', 'h4':'', 'h5':'', 'h6':''});
  11822. me.commands['paragraph'] = {
  11823. execCommand : function( cmdName, style,attrs,sourceCmdName ) {
  11824. var range = this.selection.getRange();
  11825. //闭合时单独处理
  11826. if(range.collapsed){
  11827. var txt = this.document.createTextNode('p');
  11828. range.insertNode(txt);
  11829. //去掉冗余的fillchar
  11830. if(browser.ie){
  11831. var node = txt.previousSibling;
  11832. if(node && domUtils.isWhitespace(node)){
  11833. domUtils.remove(node);
  11834. }
  11835. node = txt.nextSibling;
  11836. if(node && domUtils.isWhitespace(node)){
  11837. domUtils.remove(node);
  11838. }
  11839. }
  11840. }
  11841. range = doParagraph(range,style,attrs,sourceCmdName);
  11842. if(txt){
  11843. range.setStartBefore(txt).collapse(true);
  11844. pN = txt.parentNode;
  11845. domUtils.remove(txt);
  11846. if(domUtils.isBlockElm(pN)&&domUtils.isEmptyNode(pN)){
  11847. domUtils.fillNode(this.document,pN);
  11848. }
  11849. }
  11850. if(browser.gecko && range.collapsed && range.startContainer.nodeType == 1){
  11851. var child = range.startContainer.childNodes[range.startOffset];
  11852. if(child && child.nodeType == 1 && child.tagName.toLowerCase() == style){
  11853. range.setStart(child,0).collapse(true);
  11854. }
  11855. }
  11856. //trace:1097 原来有true,原因忘了,但去了就不能清除多余的占位符了
  11857. range.select();
  11858. return true;
  11859. },
  11860. queryCommandValue : function() {
  11861. var node = domUtils.filterNodeList(this.selection.getStartElementPath(),'p h1 h2 h3 h4 h5 h6');
  11862. return node ? node.tagName.toLowerCase() : '';
  11863. }
  11864. };
  11865. };
  11866. // plugins/directionality.js
  11867. /**
  11868. * 设置文字输入的方向的插件
  11869. * @file
  11870. * @since 1.2.6.1
  11871. */
  11872. (function() {
  11873. var block = domUtils.isBlockElm ,
  11874. getObj = function(editor){
  11875. // var startNode = editor.selection.getStart(),
  11876. // parents;
  11877. // if ( startNode ) {
  11878. // //查找所有的是block的父亲节点
  11879. // parents = domUtils.findParents( startNode, true, block, true );
  11880. // for ( var i = 0,ci; ci = parents[i++]; ) {
  11881. // if ( ci.getAttribute( 'dir' ) ) {
  11882. // return ci;
  11883. // }
  11884. // }
  11885. // }
  11886. return domUtils.filterNodeList(editor.selection.getStartElementPath(),function(n){return n && n.nodeType == 1 && n.getAttribute('dir')});
  11887. },
  11888. doDirectionality = function(range,editor,forward){
  11889. var bookmark,
  11890. filterFn = function( node ) {
  11891. return node.nodeType == 1 ? !domUtils.isBookmarkNode(node) : !domUtils.isWhitespace(node);
  11892. },
  11893. obj = getObj( editor );
  11894. if ( obj && range.collapsed ) {
  11895. obj.setAttribute( 'dir', forward );
  11896. return range;
  11897. }
  11898. bookmark = range.createBookmark();
  11899. range.enlarge( true );
  11900. var bookmark2 = range.createBookmark(),
  11901. current = domUtils.getNextDomNode( bookmark2.start, false, filterFn ),
  11902. tmpRange = range.cloneRange(),
  11903. tmpNode;
  11904. while ( current && !(domUtils.getPosition( current, bookmark2.end ) & domUtils.POSITION_FOLLOWING) ) {
  11905. if ( current.nodeType == 3 || !block( current ) ) {
  11906. tmpRange.setStartBefore( current );
  11907. while ( current && current !== bookmark2.end && !block( current ) ) {
  11908. tmpNode = current;
  11909. current = domUtils.getNextDomNode( current, false, null, function( node ) {
  11910. return !block( node );
  11911. } );
  11912. }
  11913. tmpRange.setEndAfter( tmpNode );
  11914. var common = tmpRange.getCommonAncestor();
  11915. if ( !domUtils.isBody( common ) && block( common ) ) {
  11916. //遍历到了block节点
  11917. common.setAttribute( 'dir', forward );
  11918. current = common;
  11919. } else {
  11920. //没有遍历到,添加一个block节点
  11921. var p = range.document.createElement( 'p' );
  11922. p.setAttribute( 'dir', forward );
  11923. var frag = tmpRange.extractContents();
  11924. p.appendChild( frag );
  11925. tmpRange.insertNode( p );
  11926. current = p;
  11927. }
  11928. current = domUtils.getNextDomNode( current, false, filterFn );
  11929. } else {
  11930. current = domUtils.getNextDomNode( current, true, filterFn );
  11931. }
  11932. }
  11933. return range.moveToBookmark( bookmark2 ).moveToBookmark( bookmark );
  11934. };
  11935. /**
  11936. * 文字输入方向
  11937. * @command directionality
  11938. * @method execCommand
  11939. * @param { String } cmdName 命令字符串
  11940. * @param { String } forward 传入'ltr'表示从左向右输入,传入'rtl'表示从右向左输入
  11941. * @example
  11942. * ```javascript
  11943. * editor.execCommand( 'directionality', 'ltr');
  11944. * ```
  11945. */
  11946. /**
  11947. * 查询当前选区的文字输入方向
  11948. * @command directionality
  11949. * @method queryCommandValue
  11950. * @param { String } cmdName 命令字符串
  11951. * @return { String } 返回'ltr'表示从左向右输入,返回'rtl'表示从右向左输入
  11952. * @example
  11953. * ```javascript
  11954. * editor.queryCommandValue( 'directionality');
  11955. * ```
  11956. */
  11957. UE.commands['directionality'] = {
  11958. execCommand : function( cmdName,forward ) {
  11959. var range = this.selection.getRange();
  11960. //闭合时单独处理
  11961. if(range.collapsed){
  11962. var txt = this.document.createTextNode('d');
  11963. range.insertNode(txt);
  11964. }
  11965. doDirectionality(range,this,forward);
  11966. if(txt){
  11967. range.setStartBefore(txt).collapse(true);
  11968. domUtils.remove(txt);
  11969. }
  11970. range.select();
  11971. return true;
  11972. },
  11973. queryCommandValue : function() {
  11974. var node = getObj(this);
  11975. return node ? node.getAttribute('dir') : 'ltr';
  11976. }
  11977. };
  11978. })();
  11979. // plugins/horizontal.js
  11980. /**
  11981. * 插入分割线插件
  11982. * @file
  11983. * @since 1.2.6.1
  11984. */
  11985. /**
  11986. * 插入分割线
  11987. * @command horizontal
  11988. * @method execCommand
  11989. * @param { String } cmdName 命令字符串
  11990. * @example
  11991. * ```javascript
  11992. * editor.execCommand( 'horizontal' );
  11993. * ```
  11994. */
  11995. UE.plugins['horizontal'] = function(){
  11996. var me = this;
  11997. me.commands['horizontal'] = {
  11998. execCommand : function( cmdName ) {
  11999. var me = this;
  12000. if(me.queryCommandState(cmdName)!==-1){
  12001. me.execCommand('insertHtml','<hr>');
  12002. var range = me.selection.getRange(),
  12003. start = range.startContainer;
  12004. if(start.nodeType == 1 && !start.childNodes[range.startOffset] ){
  12005. var tmp;
  12006. if(tmp = start.childNodes[range.startOffset - 1]){
  12007. if(tmp.nodeType == 1 && tmp.tagName == 'HR'){
  12008. if(me.options.enterTag == 'p'){
  12009. tmp = me.document.createElement('p');
  12010. range.insertNode(tmp);
  12011. range.setStart(tmp,0).setCursor();
  12012. }else{
  12013. tmp = me.document.createElement('br');
  12014. range.insertNode(tmp);
  12015. range.setStartBefore(tmp).setCursor();
  12016. }
  12017. }
  12018. }
  12019. }
  12020. return true;
  12021. }
  12022. },
  12023. //边界在table里不能加分隔线
  12024. queryCommandState : function() {
  12025. return domUtils.filterNodeList(this.selection.getStartElementPath(),'table') ? -1 : 0;
  12026. }
  12027. };
  12028. // me.addListener('delkeyup',function(){
  12029. // var rng = this.selection.getRange();
  12030. // if(browser.ie && browser.version > 8){
  12031. // rng.txtToElmBoundary(true);
  12032. // if(domUtils.isStartInblock(rng)){
  12033. // var tmpNode = rng.startContainer;
  12034. // var pre = tmpNode.previousSibling;
  12035. // if(pre && domUtils.isTagNode(pre,'hr')){
  12036. // domUtils.remove(pre);
  12037. // rng.select();
  12038. // return;
  12039. // }
  12040. // }
  12041. // }
  12042. // if(domUtils.isBody(rng.startContainer)){
  12043. // var hr = rng.startContainer.childNodes[rng.startOffset -1];
  12044. // if(hr && hr.nodeName == 'HR'){
  12045. // var next = hr.nextSibling;
  12046. // if(next){
  12047. // rng.setStart(next,0)
  12048. // }else if(hr.previousSibling){
  12049. // rng.setStartAtLast(hr.previousSibling)
  12050. // }else{
  12051. // var p = this.document.createElement('p');
  12052. // hr.parentNode.insertBefore(p,hr);
  12053. // domUtils.fillNode(this.document,p);
  12054. // rng.setStart(p,0);
  12055. // }
  12056. // domUtils.remove(hr);
  12057. // rng.setCursor(false,true);
  12058. // }
  12059. // }
  12060. // })
  12061. me.addListener('delkeydown',function(name,evt){
  12062. var rng = this.selection.getRange();
  12063. rng.txtToElmBoundary(true);
  12064. if(domUtils.isStartInblock(rng)){
  12065. var tmpNode = rng.startContainer;
  12066. var pre = tmpNode.previousSibling;
  12067. if(pre && domUtils.isTagNode(pre,'hr')){
  12068. domUtils.remove(pre);
  12069. rng.select();
  12070. domUtils.preventDefault(evt);
  12071. return true;
  12072. }
  12073. }
  12074. })
  12075. };
  12076. // plugins/time.js
  12077. /**
  12078. * 插入时间和日期
  12079. * @file
  12080. * @since 1.2.6.1
  12081. */
  12082. /**
  12083. * 插入时间,默认格式:12:59:59
  12084. * @command time
  12085. * @method execCommand
  12086. * @param { String } cmd 命令字符串
  12087. * @example
  12088. * ```javascript
  12089. * editor.execCommand( 'time');
  12090. * ```
  12091. */
  12092. /**
  12093. * 插入日期,默认格式:2013-08-30
  12094. * @command date
  12095. * @method execCommand
  12096. * @param { String } cmd 命令字符串
  12097. * @example
  12098. * ```javascript
  12099. * editor.execCommand( 'date');
  12100. * ```
  12101. */
  12102. UE.commands['time'] = UE.commands["date"] = {
  12103. execCommand : function(cmd, format){
  12104. var date = new Date;
  12105. function formatTime(date, format) {
  12106. var hh = ('0' + date.getHours()).slice(-2),
  12107. ii = ('0' + date.getMinutes()).slice(-2),
  12108. ss = ('0' + date.getSeconds()).slice(-2);
  12109. format = format || 'hh:ii:ss';
  12110. return format.replace(/hh/ig, hh).replace(/ii/ig, ii).replace(/ss/ig, ss);
  12111. }
  12112. function formatDate(date, format) {
  12113. var yyyy = ('000' + date.getFullYear()).slice(-4),
  12114. yy = yyyy.slice(-2),
  12115. mm = ('0' + (date.getMonth()+1)).slice(-2),
  12116. dd = ('0' + date.getDate()).slice(-2);
  12117. format = format || 'yyyy-mm-dd';
  12118. return format.replace(/yyyy/ig, yyyy).replace(/yy/ig, yy).replace(/mm/ig, mm).replace(/dd/ig, dd);
  12119. }
  12120. this.execCommand('insertHtml',cmd == "time" ? formatTime(date, format):formatDate(date, format) );
  12121. }
  12122. };
  12123. // plugins/rowspacing.js
  12124. /**
  12125. * 段前段后间距插件
  12126. * @file
  12127. * @since 1.2.6.1
  12128. */
  12129. /**
  12130. * 设置段间距
  12131. * @command rowspacing
  12132. * @method execCommand
  12133. * @param { String } cmd 命令字符串
  12134. * @param { String } value 段间距的值,以px为单位
  12135. * @param { String } dir 间距位置,top或bottom,分别表示段前和段后
  12136. * @example
  12137. * ```javascript
  12138. * editor.execCommand( 'rowspacing', '10', 'top' );
  12139. * ```
  12140. */
  12141. UE.plugins['rowspacing'] = function(){
  12142. var me = this;
  12143. me.setOpt({
  12144. 'rowspacingtop':['5', '10', '15', '20', '25'],
  12145. 'rowspacingbottom':['5', '10', '15', '20', '25']
  12146. });
  12147. me.commands['rowspacing'] = {
  12148. execCommand : function( cmdName,value,dir ) {
  12149. this.execCommand('paragraph','p',{style:'margin-'+dir+':'+value + 'px'});
  12150. return true;
  12151. },
  12152. queryCommandValue : function(cmdName,dir) {
  12153. var pN = domUtils.filterNodeList(this.selection.getStartElementPath(),function(node){return domUtils.isBlockElm(node) }),
  12154. value;
  12155. //trace:1026
  12156. if(pN){
  12157. value = domUtils.getComputedStyle(pN,'margin-'+dir).replace(/[^\d]/g,'');
  12158. return !value ? 0 : value;
  12159. }
  12160. return 0;
  12161. }
  12162. };
  12163. };
  12164. // plugins/lineheight.js
  12165. /**
  12166. * 设置行内间距
  12167. * @file
  12168. * @since 1.2.6.1
  12169. */
  12170. UE.plugins['lineheight'] = function(){
  12171. var me = this;
  12172. me.setOpt({'lineheight':['1', '1.5','1.75','2', '3', '4', '5']});
  12173. /**
  12174. * 行距
  12175. * @command lineheight
  12176. * @method execCommand
  12177. * @param { String } cmdName 命令字符串
  12178. * @param { String } value 传入的行高值, 该值是当前字体的倍数, 例如: 1.5, 1.75
  12179. * @example
  12180. * ```javascript
  12181. * editor.execCommand( 'lineheight', 1.5);
  12182. * ```
  12183. */
  12184. /**
  12185. * 查询当前选区内容的行高大小
  12186. * @command lineheight
  12187. * @method queryCommandValue
  12188. * @param { String } cmd 命令字符串
  12189. * @return { String } 返回当前行高大小
  12190. * @example
  12191. * ```javascript
  12192. * editor.queryCommandValue( 'lineheight' );
  12193. * ```
  12194. */
  12195. me.commands['lineheight'] = {
  12196. execCommand : function( cmdName,value ) {
  12197. this.execCommand('paragraph','p',{style:'line-height:'+ (value == "1" ? "normal" : value + 'em') });
  12198. return true;
  12199. },
  12200. queryCommandValue : function() {
  12201. var pN = domUtils.filterNodeList(this.selection.getStartElementPath(),function(node){return domUtils.isBlockElm(node)});
  12202. if(pN){
  12203. var value = domUtils.getComputedStyle(pN,'line-height');
  12204. return value == 'normal' ? 1 : value.replace(/[^\d.]*/ig,"");
  12205. }
  12206. }
  12207. };
  12208. };
  12209. // plugins/insertcode.js
  12210. /**
  12211. * 插入代码插件
  12212. * @file
  12213. * @since 1.2.6.1
  12214. */
  12215. UE.plugins['insertcode'] = function() {
  12216. var me = this;
  12217. me.ready(function(){
  12218. utils.cssRule('pre','pre{margin:.5em 0;padding:.4em .6em;border-radius:8px;background:#f8f8f8;}',
  12219. me.document)
  12220. });
  12221. me.setOpt('insertcode',{
  12222. 'as3':'ActionScript3',
  12223. 'bash':'Bash/Shell',
  12224. 'cpp':'C/C++',
  12225. 'css':'Css',
  12226. 'cf':'CodeFunction',
  12227. 'c#':'C#',
  12228. 'delphi':'Delphi',
  12229. 'diff':'Diff',
  12230. 'erlang':'Erlang',
  12231. 'groovy':'Groovy',
  12232. 'html':'Html',
  12233. 'java':'Java',
  12234. 'jfx':'JavaFx',
  12235. 'js':'Javascript',
  12236. 'pl':'Perl',
  12237. 'php':'Php',
  12238. 'plain':'Plain Text',
  12239. 'ps':'PowerShell',
  12240. 'python':'Python',
  12241. 'ruby':'Ruby',
  12242. 'scala':'Scala',
  12243. 'sql':'Sql',
  12244. 'vb':'Vb',
  12245. 'xml':'Xml'
  12246. });
  12247. /**
  12248. * 插入代码
  12249. * @command insertcode
  12250. * @method execCommand
  12251. * @param { String } cmd 命令字符串
  12252. * @param { String } lang 插入代码的语言
  12253. * @example
  12254. * ```javascript
  12255. * editor.execCommand( 'insertcode', 'javascript' );
  12256. * ```
  12257. */
  12258. /**
  12259. * 如果选区所在位置是插入插入代码区域,返回代码的语言
  12260. * @command insertcode
  12261. * @method queryCommandValue
  12262. * @param { String } cmd 命令字符串
  12263. * @return { String } 返回代码的语言
  12264. * @example
  12265. * ```javascript
  12266. * editor.queryCommandValue( 'insertcode' );
  12267. * ```
  12268. */
  12269. me.commands['insertcode'] = {
  12270. execCommand : function(cmd,lang){
  12271. var me = this,
  12272. rng = me.selection.getRange(),
  12273. pre = domUtils.findParentByTagName(rng.startContainer,'pre',true);
  12274. if(pre){
  12275. pre.className = 'brush:'+lang+';toolbar:false;';
  12276. }else{
  12277. var code = '';
  12278. if(rng.collapsed){
  12279. code = browser.ie && browser.ie11below ? (browser.version <= 8 ? '&nbsp;':''):'<br/>';
  12280. }else{
  12281. var frag = rng.extractContents();
  12282. var div = me.document.createElement('div');
  12283. div.appendChild(frag);
  12284. utils.each(UE.filterNode(UE.htmlparser(div.innerHTML.replace(/[\r\t]/g,'')),me.options.filterTxtRules).children,function(node){
  12285. if(browser.ie && browser.ie11below && browser.version > 8){
  12286. if(node.type =='element'){
  12287. if(node.tagName == 'br'){
  12288. code += '\n'
  12289. }else if(!dtd.$empty[node.tagName]){
  12290. utils.each(node.children,function(cn){
  12291. if(cn.type =='element'){
  12292. if(cn.tagName == 'br'){
  12293. code += '\n'
  12294. }else if(!dtd.$empty[node.tagName]){
  12295. code += cn.innerText();
  12296. }
  12297. }else{
  12298. code += cn.data
  12299. }
  12300. })
  12301. if(!/\n$/.test(code)){
  12302. code += '\n';
  12303. }
  12304. }
  12305. }else{
  12306. code += node.data + '\n'
  12307. }
  12308. if(!node.nextSibling() && /\n$/.test(code)){
  12309. code = code.replace(/\n$/,'');
  12310. }
  12311. }else{
  12312. if(browser.ie && browser.ie11below){
  12313. if(node.type =='element'){
  12314. if(node.tagName == 'br'){
  12315. code += '<br>'
  12316. }else if(!dtd.$empty[node.tagName]){
  12317. utils.each(node.children,function(cn){
  12318. if(cn.type =='element'){
  12319. if(cn.tagName == 'br'){
  12320. code += '<br>'
  12321. }else if(!dtd.$empty[node.tagName]){
  12322. code += cn.innerText();
  12323. }
  12324. }else{
  12325. code += cn.data
  12326. }
  12327. });
  12328. if(!/br>$/.test(code)){
  12329. code += '<br>';
  12330. }
  12331. }
  12332. }else{
  12333. code += node.data + '<br>'
  12334. }
  12335. if(!node.nextSibling() && /<br>$/.test(code)){
  12336. code = code.replace(/<br>$/,'');
  12337. }
  12338. }else{
  12339. code += (node.type == 'element' ? (dtd.$empty[node.tagName] ? '' : node.innerText()) : node.data);
  12340. if(!/br\/?\s*>$/.test(code)){
  12341. if(!node.nextSibling())
  12342. return;
  12343. code += '<br>'
  12344. }
  12345. }
  12346. }
  12347. });
  12348. }
  12349. me.execCommand('inserthtml','<pre id="coder"class="brush:'+lang+';toolbar:false">'+code+'</pre>',true);
  12350. pre = me.document.getElementById('coder');
  12351. domUtils.removeAttributes(pre,'id');
  12352. var tmpNode = pre.previousSibling;
  12353. if(tmpNode && (tmpNode.nodeType == 3 && tmpNode.nodeValue.length == 1 && browser.ie && browser.version == 6 || domUtils.isEmptyBlock(tmpNode))){
  12354. domUtils.remove(tmpNode)
  12355. }
  12356. var rng = me.selection.getRange();
  12357. if(domUtils.isEmptyBlock(pre)){
  12358. rng.setStart(pre,0).setCursor(false,true)
  12359. }else{
  12360. rng.selectNodeContents(pre).select()
  12361. }
  12362. }
  12363. },
  12364. queryCommandValue : function(){
  12365. var path = this.selection.getStartElementPath();
  12366. var lang = '';
  12367. utils.each(path,function(node){
  12368. if(node.nodeName =='PRE'){
  12369. var match = node.className.match(/brush:([^;]+)/);
  12370. lang = match && match[1] ? match[1] : '';
  12371. return false;
  12372. }
  12373. });
  12374. return lang;
  12375. }
  12376. };
  12377. me.addInputRule(function(root){
  12378. utils.each(root.getNodesByTagName('pre'),function(pre){
  12379. var brs = pre.getNodesByTagName('br');
  12380. if(brs.length){
  12381. browser.ie && browser.ie11below && browser.version > 8 && utils.each(brs,function(br){
  12382. var txt = UE.uNode.createText('\n');
  12383. br.parentNode.insertBefore(txt,br);
  12384. br.parentNode.removeChild(br);
  12385. });
  12386. return;
  12387. }
  12388. if(browser.ie && browser.ie11below && browser.version > 8)
  12389. return;
  12390. var code = pre.innerText().split(/\n/);
  12391. pre.innerHTML('');
  12392. utils.each(code,function(c){
  12393. if(c.length){
  12394. pre.appendChild(UE.uNode.createText(c));
  12395. }
  12396. pre.appendChild(UE.uNode.createElement('br'))
  12397. })
  12398. })
  12399. });
  12400. me.addOutputRule(function(root){
  12401. utils.each(root.getNodesByTagName('pre'),function(pre){
  12402. var code = '';
  12403. utils.each(pre.children,function(n){
  12404. if(n.type == 'text'){
  12405. //在ie下文本内容有可能末尾带有\n要去掉
  12406. //trace:3396
  12407. code += n.data.replace(/[ ]/g,'&nbsp;').replace(/\n$/,'');
  12408. }else{
  12409. if(n.tagName == 'br'){
  12410. code += '\n'
  12411. }else{
  12412. code += (!dtd.$empty[n.tagName] ? '' : n.innerText());
  12413. }
  12414. }
  12415. });
  12416. pre.innerText(code.replace(/(&nbsp;|\n)+$/,''))
  12417. })
  12418. });
  12419. //不需要判断highlight的command列表
  12420. me.notNeedCodeQuery ={
  12421. help:1,
  12422. undo:1,
  12423. redo:1,
  12424. source:1,
  12425. print:1,
  12426. searchreplace:1,
  12427. fullscreen:1,
  12428. preview:1,
  12429. insertparagraph:1,
  12430. elementpath:1,
  12431. insertcode:1,
  12432. inserthtml:1,
  12433. selectall:1
  12434. };
  12435. //将queyCommamndState重置
  12436. var orgQuery = me.queryCommandState;
  12437. me.queryCommandState = function(cmd){
  12438. var me = this;
  12439. if(!me.notNeedCodeQuery[cmd.toLowerCase()] && me.selection && me.queryCommandValue('insertcode')){
  12440. return -1;
  12441. }
  12442. return UE.Editor.prototype.queryCommandState.apply(this,arguments)
  12443. };
  12444. me.addListener('beforeenterkeydown',function(){
  12445. var rng = me.selection.getRange();
  12446. var pre = domUtils.findParentByTagName(rng.startContainer,'pre',true);
  12447. if(pre){
  12448. me.fireEvent('saveScene');
  12449. if(!rng.collapsed){
  12450. rng.deleteContents();
  12451. }
  12452. if(!browser.ie || browser.ie9above){
  12453. var tmpNode = me.document.createElement('br'),pre;
  12454. rng.insertNode(tmpNode).setStartAfter(tmpNode).collapse(true);
  12455. var next = tmpNode.nextSibling;
  12456. if(!next && (!browser.ie || browser.version > 10)){
  12457. rng.insertNode(tmpNode.cloneNode(false));
  12458. }else{
  12459. rng.setStartAfter(tmpNode);
  12460. }
  12461. pre = tmpNode.previousSibling;
  12462. var tmp;
  12463. while(pre ){
  12464. tmp = pre;
  12465. pre = pre.previousSibling;
  12466. if(!pre || pre.nodeName == 'BR'){
  12467. pre = tmp;
  12468. break;
  12469. }
  12470. }
  12471. if(pre){
  12472. var str = '';
  12473. while(pre && pre.nodeName != 'BR' && new RegExp('^[\\s'+domUtils.fillChar+']*$').test(pre.nodeValue)){
  12474. str += pre.nodeValue;
  12475. pre = pre.nextSibling;
  12476. }
  12477. if(pre.nodeName != 'BR'){
  12478. var match = pre.nodeValue.match(new RegExp('^([\\s'+domUtils.fillChar+']+)'));
  12479. if(match && match[1]){
  12480. str += match[1]
  12481. }
  12482. }
  12483. if(str){
  12484. str = me.document.createTextNode(str);
  12485. rng.insertNode(str).setStartAfter(str);
  12486. }
  12487. }
  12488. rng.collapse(true).select(true);
  12489. }else{
  12490. if(browser.version > 8){
  12491. var txt = me.document.createTextNode('\n');
  12492. var start = rng.startContainer;
  12493. if(rng.startOffset == 0){
  12494. var preNode = start.previousSibling;
  12495. if(preNode){
  12496. rng.insertNode(txt);
  12497. var fillchar = me.document.createTextNode(' ');
  12498. rng.setStartAfter(txt).insertNode(fillchar).setStart(fillchar,0).collapse(true).select(true)
  12499. }
  12500. }else{
  12501. rng.insertNode(txt).setStartAfter(txt);
  12502. var fillchar = me.document.createTextNode(' ');
  12503. start = rng.startContainer.childNodes[rng.startOffset];
  12504. if(start && !/^\n/.test(start.nodeValue)){
  12505. rng.setStartBefore(txt)
  12506. }
  12507. rng.insertNode(fillchar).setStart(fillchar,0).collapse(true).select(true)
  12508. }
  12509. }else{
  12510. var tmpNode = me.document.createElement('br');
  12511. rng.insertNode(tmpNode);
  12512. rng.insertNode(me.document.createTextNode(domUtils.fillChar));
  12513. rng.setStartAfter(tmpNode);
  12514. pre = tmpNode.previousSibling;
  12515. var tmp;
  12516. while(pre ){
  12517. tmp = pre;
  12518. pre = pre.previousSibling;
  12519. if(!pre || pre.nodeName == 'BR'){
  12520. pre = tmp;
  12521. break;
  12522. }
  12523. }
  12524. if(pre){
  12525. var str = '';
  12526. while(pre && pre.nodeName != 'BR' && new RegExp('^[ '+domUtils.fillChar+']*$').test(pre.nodeValue)){
  12527. str += pre.nodeValue;
  12528. pre = pre.nextSibling;
  12529. }
  12530. if(pre.nodeName != 'BR'){
  12531. var match = pre.nodeValue.match(new RegExp('^([ '+domUtils.fillChar+']+)'));
  12532. if(match && match[1]){
  12533. str += match[1]
  12534. }
  12535. }
  12536. str = me.document.createTextNode(str);
  12537. rng.insertNode(str).setStartAfter(str);
  12538. }
  12539. rng.collapse(true).select();
  12540. }
  12541. }
  12542. me.fireEvent('saveScene');
  12543. return true;
  12544. }
  12545. });
  12546. me.addListener('tabkeydown',function(cmd,evt){
  12547. var rng = me.selection.getRange();
  12548. var pre = domUtils.findParentByTagName(rng.startContainer,'pre',true);
  12549. if(pre){
  12550. me.fireEvent('saveScene');
  12551. if(evt.shiftKey){
  12552. }else{
  12553. if(!rng.collapsed){
  12554. var bk = rng.createBookmark();
  12555. var start = bk.start.previousSibling;
  12556. while(start){
  12557. if(pre.firstChild === start && !domUtils.isBr(start)){
  12558. pre.insertBefore(me.document.createTextNode(' '),start);
  12559. break;
  12560. }
  12561. if(domUtils.isBr(start)){
  12562. pre.insertBefore(me.document.createTextNode(' '),start.nextSibling);
  12563. break;
  12564. }
  12565. start = start.previousSibling;
  12566. }
  12567. var end = bk.end;
  12568. start = bk.start.nextSibling;
  12569. if(pre.firstChild === bk.start){
  12570. pre.insertBefore(me.document.createTextNode(' '),start.nextSibling)
  12571. }
  12572. while(start && start !== end){
  12573. if(domUtils.isBr(start) && start.nextSibling){
  12574. if(start.nextSibling === end){
  12575. break;
  12576. }
  12577. pre.insertBefore(me.document.createTextNode(' '),start.nextSibling)
  12578. }
  12579. start = start.nextSibling;
  12580. }
  12581. rng.moveToBookmark(bk).select();
  12582. }else{
  12583. var tmpNode = me.document.createTextNode(' ');
  12584. rng.insertNode(tmpNode).setStartAfter(tmpNode).collapse(true).select(true);
  12585. }
  12586. }
  12587. me.fireEvent('saveScene');
  12588. return true;
  12589. }
  12590. });
  12591. me.addListener('beforeinserthtml',function(evtName,html){
  12592. var me = this,
  12593. rng = me.selection.getRange(),
  12594. pre = domUtils.findParentByTagName(rng.startContainer,'pre',true);
  12595. if(pre){
  12596. if(!rng.collapsed){
  12597. rng.deleteContents()
  12598. }
  12599. var htmlstr = '';
  12600. if(browser.ie && browser.version > 8){
  12601. utils.each(UE.filterNode(UE.htmlparser(html),me.options.filterTxtRules).children,function(node){
  12602. if(node.type =='element'){
  12603. if(node.tagName == 'br'){
  12604. htmlstr += '\n'
  12605. }else if(!dtd.$empty[node.tagName]){
  12606. utils.each(node.children,function(cn){
  12607. if(cn.type =='element'){
  12608. if(cn.tagName == 'br'){
  12609. htmlstr += '\n'
  12610. }else if(!dtd.$empty[node.tagName]){
  12611. htmlstr += cn.innerText();
  12612. }
  12613. }else{
  12614. htmlstr += cn.data
  12615. }
  12616. })
  12617. if(!/\n$/.test(htmlstr)){
  12618. htmlstr += '\n';
  12619. }
  12620. }
  12621. }else{
  12622. htmlstr += node.data + '\n'
  12623. }
  12624. if(!node.nextSibling() && /\n$/.test(htmlstr)){
  12625. htmlstr = htmlstr.replace(/\n$/,'');
  12626. }
  12627. });
  12628. var tmpNode = me.document.createTextNode(utils.html(htmlstr.replace(/&nbsp;/g,' ')));
  12629. rng.insertNode(tmpNode).selectNode(tmpNode).select();
  12630. }else{
  12631. var frag = me.document.createDocumentFragment();
  12632. utils.each(UE.filterNode(UE.htmlparser(html),me.options.filterTxtRules).children,function(node){
  12633. if(node.type =='element'){
  12634. if(node.tagName == 'br'){
  12635. frag.appendChild(me.document.createElement('br'))
  12636. }else if(!dtd.$empty[node.tagName]){
  12637. utils.each(node.children,function(cn){
  12638. if(cn.type =='element'){
  12639. if(cn.tagName == 'br'){
  12640. frag.appendChild(me.document.createElement('br'))
  12641. }else if(!dtd.$empty[node.tagName]){
  12642. frag.appendChild(me.document.createTextNode(utils.html(cn.innerText().replace(/&nbsp;/g,' '))));
  12643. }
  12644. }else{
  12645. frag.appendChild(me.document.createTextNode(utils.html( cn.data.replace(/&nbsp;/g,' '))));
  12646. }
  12647. })
  12648. if(frag.lastChild.nodeName != 'BR'){
  12649. frag.appendChild(me.document.createElement('br'))
  12650. }
  12651. }
  12652. }else{
  12653. frag.appendChild(me.document.createTextNode(utils.html( node.data.replace(/&nbsp;/g,' '))));
  12654. }
  12655. if(!node.nextSibling() && frag.lastChild.nodeName == 'BR'){
  12656. frag.removeChild(frag.lastChild)
  12657. }
  12658. });
  12659. rng.insertNode(frag).select();
  12660. }
  12661. return true;
  12662. }
  12663. });
  12664. //方向键的处理
  12665. me.addListener('keydown',function(cmd,evt){
  12666. var me = this,keyCode = evt.keyCode || evt.which;
  12667. if(keyCode == 40){
  12668. var rng = me.selection.getRange(),pre,start = rng.startContainer;
  12669. if(rng.collapsed && (pre = domUtils.findParentByTagName(rng.startContainer,'pre',true)) && !pre.nextSibling){
  12670. var last = pre.lastChild
  12671. while(last && last.nodeName == 'BR'){
  12672. last = last.previousSibling;
  12673. }
  12674. if(last === start || rng.startContainer === pre && rng.startOffset == pre.childNodes.length){
  12675. me.execCommand('insertparagraph');
  12676. domUtils.preventDefault(evt)
  12677. }
  12678. }
  12679. }
  12680. });
  12681. //trace:3395
  12682. me.addListener('delkeydown',function(type,evt){
  12683. var rng = this.selection.getRange();
  12684. rng.txtToElmBoundary(true);
  12685. var start = rng.startContainer;
  12686. if(domUtils.isTagNode(start,'pre') && rng.collapsed && domUtils.isStartInblock(rng)){
  12687. var p = me.document.createElement('p');
  12688. domUtils.fillNode(me.document,p);
  12689. start.parentNode.insertBefore(p,start);
  12690. domUtils.remove(start);
  12691. rng.setStart(p,0).setCursor(false,true);
  12692. domUtils.preventDefault(evt);
  12693. return true;
  12694. }
  12695. })
  12696. };
  12697. // plugins/cleardoc.js
  12698. /**
  12699. * 清空文档插件
  12700. * @file
  12701. * @since 1.2.6.1
  12702. */
  12703. /**
  12704. * 清空文档
  12705. * @command cleardoc
  12706. * @method execCommand
  12707. * @param { String } cmd 命令字符串
  12708. * @example
  12709. * ```javascript
  12710. * //editor 是编辑器实例
  12711. * editor.execCommand('cleardoc');
  12712. * ```
  12713. */
  12714. UE.commands['cleardoc'] = {
  12715. execCommand : function( cmdName) {
  12716. var me = this,
  12717. enterTag = me.options.enterTag,
  12718. range = me.selection.getRange();
  12719. if(enterTag == "br"){
  12720. me.body.innerHTML = "<br/>";
  12721. range.setStart(me.body,0).setCursor();
  12722. }else{
  12723. me.body.innerHTML = "<p>"+(ie ? "" : "<br/>")+"</p>";
  12724. range.setStart(me.body.firstChild,0).setCursor(false,true);
  12725. }
  12726. setTimeout(function(){
  12727. me.fireEvent("clearDoc");
  12728. },0);
  12729. }
  12730. };
  12731. // plugins/anchor.js
  12732. /**
  12733. * 锚点插件,为UEditor提供插入锚点支持
  12734. * @file
  12735. * @since 1.2.6.1
  12736. */
  12737. UE.plugin.register('anchor', function (){
  12738. return {
  12739. bindEvents:{
  12740. 'ready':function(){
  12741. utils.cssRule('anchor',
  12742. '.anchorclass{background: url(\''
  12743. + this.options.themePath
  12744. + this.options.theme +'/images/anchor.gif\') no-repeat scroll left center transparent;cursor: auto;display: inline-block;height: 16px;width: 15px;}',
  12745. this.document);
  12746. }
  12747. },
  12748. outputRule: function(root){
  12749. utils.each(root.getNodesByTagName('img'),function(a){
  12750. var val;
  12751. if(val = a.getAttr('anchorname')){
  12752. a.tagName = 'a';
  12753. a.setAttr({
  12754. anchorname : '',
  12755. name : val,
  12756. 'class' : ''
  12757. })
  12758. }
  12759. })
  12760. },
  12761. inputRule:function(root){
  12762. utils.each(root.getNodesByTagName('a'),function(a){
  12763. var val;
  12764. if((val = a.getAttr('name')) && !a.getAttr('href')){
  12765. a.tagName = 'img';
  12766. a.setAttr({
  12767. anchorname :a.getAttr('name'),
  12768. 'class' : 'anchorclass'
  12769. });
  12770. a.setAttr('name')
  12771. }
  12772. })
  12773. },
  12774. commands:{
  12775. /**
  12776. * 插入锚点
  12777. * @command anchor
  12778. * @method execCommand
  12779. * @param { String } cmd 命令字符串
  12780. * @param { String } name 锚点名称字符串
  12781. * @example
  12782. * ```javascript
  12783. * //editor 是编辑器实例
  12784. * editor.execCommand('anchor', 'anchor1');
  12785. * ```
  12786. */
  12787. 'anchor':{
  12788. execCommand:function (cmd, name) {
  12789. var range = this.selection.getRange(),img = range.getClosedNode();
  12790. if (img && img.getAttribute('anchorname')) {
  12791. if (name) {
  12792. img.setAttribute('anchorname', name);
  12793. } else {
  12794. range.setStartBefore(img).setCursor();
  12795. domUtils.remove(img);
  12796. }
  12797. } else {
  12798. if (name) {
  12799. //只在选区的开始插入
  12800. var anchor = this.document.createElement('img');
  12801. range.collapse(true);
  12802. domUtils.setAttributes(anchor,{
  12803. 'anchorname':name,
  12804. 'class':'anchorclass'
  12805. });
  12806. range.insertNode(anchor).setStartAfter(anchor).setCursor(false,true);
  12807. }
  12808. }
  12809. }
  12810. }
  12811. }
  12812. }
  12813. });
  12814. // plugins/wordcount.js
  12815. ///import core
  12816. ///commands 字数统计
  12817. ///commandsName WordCount,wordCount
  12818. ///commandsTitle 字数统计
  12819. /*
  12820. * Created by JetBrains WebStorm.
  12821. * User: taoqili
  12822. * Date: 11-9-7
  12823. * Time: 下午8:18
  12824. * To change this template use File | Settings | File Templates.
  12825. */
  12826. UE.plugins['wordcount'] = function(){
  12827. var me = this;
  12828. me.setOpt('wordCount',true);
  12829. me.addListener('contentchange',function(){
  12830. me.fireEvent('wordcount');
  12831. });
  12832. var timer;
  12833. me.addListener('ready',function(){
  12834. var me = this;
  12835. domUtils.on(me.body,"keyup",function(evt){
  12836. var code = evt.keyCode||evt.which,
  12837. //忽略的按键,ctr,alt,shift,方向键
  12838. ignores = {"16":1,"18":1,"20":1,"37":1,"38":1,"39":1,"40":1};
  12839. if(code in ignores) return;
  12840. clearTimeout(timer);
  12841. timer = setTimeout(function(){
  12842. me.fireEvent('wordcount');
  12843. },200)
  12844. })
  12845. });
  12846. };
  12847. // plugins/pagebreak.js
  12848. /**
  12849. * 分页功能插件
  12850. * @file
  12851. * @since 1.2.6.1
  12852. */
  12853. UE.plugins['pagebreak'] = function () {
  12854. var me = this,
  12855. notBreakTags = ['td'];
  12856. me.setOpt('pageBreakTag','_ueditor_page_break_tag_');
  12857. function fillNode(node){
  12858. if(domUtils.isEmptyBlock(node)){
  12859. var firstChild = node.firstChild,tmpNode;
  12860. while(firstChild && firstChild.nodeType == 1 && domUtils.isEmptyBlock(firstChild)){
  12861. tmpNode = firstChild;
  12862. firstChild = firstChild.firstChild;
  12863. }
  12864. !tmpNode && (tmpNode = node);
  12865. domUtils.fillNode(me.document,tmpNode);
  12866. }
  12867. }
  12868. //分页符样式添加
  12869. me.ready(function(){
  12870. utils.cssRule('pagebreak','.pagebreak{display:block;clear:both !important;cursor:default !important;width: 100% !important;margin:0;}',me.document);
  12871. });
  12872. function isHr(node){
  12873. return node && node.nodeType == 1 && node.tagName == 'HR' && node.className == 'pagebreak';
  12874. }
  12875. me.addInputRule(function(root){
  12876. root.traversal(function(node){
  12877. if(node.type == 'text' && node.data == me.options.pageBreakTag){
  12878. var hr = UE.uNode.createElement('<hr class="pagebreak" noshade="noshade" size="5" style="-webkit-user-select: none;">');
  12879. node.parentNode.insertBefore(hr,node);
  12880. node.parentNode.removeChild(node)
  12881. }
  12882. })
  12883. });
  12884. me.addOutputRule(function(node){
  12885. utils.each(node.getNodesByTagName('hr'),function(n){
  12886. if(n.getAttr('class') == 'pagebreak'){
  12887. var txt = UE.uNode.createText(me.options.pageBreakTag);
  12888. n.parentNode.insertBefore(txt,n);
  12889. n.parentNode.removeChild(n);
  12890. }
  12891. })
  12892. });
  12893. /**
  12894. * 插入分页符
  12895. * @command pagebreak
  12896. * @method execCommand
  12897. * @param { String } cmd 命令字符串
  12898. * @remind 在表格中插入分页符会把表格切分成两部分
  12899. * @remind 获取编辑器内的数据时, 编辑器会把分页符转换成“_ueditor_page_break_tag_”字符串,
  12900. * 以便于提交数据到服务器端后处理分页。
  12901. * @example
  12902. * ```javascript
  12903. * editor.execCommand( 'pagebreak'); //插入一个hr标签,带有样式类名pagebreak
  12904. * ```
  12905. */
  12906. me.commands['pagebreak'] = {
  12907. execCommand:function () {
  12908. var range = me.selection.getRange(),hr = me.document.createElement('hr');
  12909. domUtils.setAttributes(hr,{
  12910. 'class' : 'pagebreak',
  12911. noshade:"noshade",
  12912. size:"5"
  12913. });
  12914. domUtils.unSelectable(hr);
  12915. //table单独处理
  12916. var node = domUtils.findParentByTagName(range.startContainer, notBreakTags, true),
  12917. parents = [], pN;
  12918. if (node) {
  12919. switch (node.tagName) {
  12920. case 'TD':
  12921. pN = node.parentNode;
  12922. if (!pN.previousSibling) {
  12923. var table = domUtils.findParentByTagName(pN, 'table');
  12924. // var tableWrapDiv = table.parentNode;
  12925. // if(tableWrapDiv && tableWrapDiv.nodeType == 1
  12926. // && tableWrapDiv.tagName == 'DIV'
  12927. // && tableWrapDiv.getAttribute('dropdrag')
  12928. // ){
  12929. // domUtils.remove(tableWrapDiv,true);
  12930. // }
  12931. table.parentNode.insertBefore(hr, table);
  12932. parents = domUtils.findParents(hr, true);
  12933. } else {
  12934. pN.parentNode.insertBefore(hr, pN);
  12935. parents = domUtils.findParents(hr);
  12936. }
  12937. pN = parents[1];
  12938. if (hr !== pN) {
  12939. domUtils.breakParent(hr, pN);
  12940. }
  12941. //table要重写绑定一下拖拽
  12942. me.fireEvent('afteradjusttable',me.document);
  12943. }
  12944. } else {
  12945. if (!range.collapsed) {
  12946. range.deleteContents();
  12947. var start = range.startContainer;
  12948. while ( !domUtils.isBody(start) && domUtils.isBlockElm(start) && domUtils.isEmptyNode(start)) {
  12949. range.setStartBefore(start).collapse(true);
  12950. domUtils.remove(start);
  12951. start = range.startContainer;
  12952. }
  12953. }
  12954. range.insertNode(hr);
  12955. var pN = hr.parentNode, nextNode;
  12956. while (!domUtils.isBody(pN)) {
  12957. domUtils.breakParent(hr, pN);
  12958. nextNode = hr.nextSibling;
  12959. if (nextNode && domUtils.isEmptyBlock(nextNode)) {
  12960. domUtils.remove(nextNode);
  12961. }
  12962. pN = hr.parentNode;
  12963. }
  12964. nextNode = hr.nextSibling;
  12965. var pre = hr.previousSibling;
  12966. if(isHr(pre)){
  12967. domUtils.remove(pre);
  12968. }else{
  12969. pre && fillNode(pre);
  12970. }
  12971. if(!nextNode){
  12972. var p = me.document.createElement('p');
  12973. hr.parentNode.appendChild(p);
  12974. domUtils.fillNode(me.document,p);
  12975. range.setStart(p,0).collapse(true);
  12976. }else{
  12977. if(isHr(nextNode)){
  12978. domUtils.remove(nextNode);
  12979. }else{
  12980. fillNode(nextNode);
  12981. }
  12982. range.setEndAfter(hr).collapse(false);
  12983. }
  12984. range.select(true);
  12985. }
  12986. }
  12987. };
  12988. };
  12989. // plugins/wordimage.js
  12990. ///import core
  12991. ///commands 本地图片引导上传
  12992. ///commandsName WordImage
  12993. ///commandsTitle 本地图片引导上传
  12994. ///commandsDialog dialogs\wordimage
  12995. UE.plugin.register('wordimage',function(){
  12996. var me = this,
  12997. images = [];
  12998. return {
  12999. commands : {
  13000. 'wordimage':{
  13001. execCommand:function () {
  13002. var images = domUtils.getElementsByTagName(me.body, "img");
  13003. var urlList = [];
  13004. for (var i = 0, ci; ci = images[i++];) {
  13005. var url = ci.getAttribute("word_img");
  13006. url && urlList.push(url);
  13007. }
  13008. return urlList;
  13009. },
  13010. queryCommandState:function () {
  13011. images = domUtils.getElementsByTagName(me.body, "img");
  13012. for (var i = 0, ci; ci = images[i++];) {
  13013. if (ci.getAttribute("word_img")) {
  13014. return 1;
  13015. }
  13016. }
  13017. return -1;
  13018. },
  13019. notNeedUndo:true
  13020. }
  13021. },
  13022. inputRule : function (root) {
  13023. utils.each(root.getNodesByTagName('img'), function (img) {
  13024. var attrs = img.attrs,
  13025. flag = parseInt(attrs.width) < 128 || parseInt(attrs.height) < 43,
  13026. opt = me.options,
  13027. src = opt.UEDITOR_HOME_URL + 'themes/default/images/spacer.gif';
  13028. if (attrs['src'] && /^(?:(file:\/+))/.test(attrs['src'])) {
  13029. img.setAttr({
  13030. width:attrs.width,
  13031. height:attrs.height,
  13032. alt:attrs.alt,
  13033. word_img: attrs.src,
  13034. src:src,
  13035. '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'
  13036. })
  13037. }
  13038. })
  13039. }
  13040. }
  13041. });
  13042. // plugins/dragdrop.js
  13043. UE.plugins['dragdrop'] = function (){
  13044. var me = this;
  13045. me.ready(function(){
  13046. domUtils.on(this.body,'dragend',function(){
  13047. var rng = me.selection.getRange();
  13048. var node = rng.getClosedNode()||me.selection.getStart();
  13049. if(node && node.tagName == 'IMG'){
  13050. var pre = node.previousSibling,next;
  13051. while(next = node.nextSibling){
  13052. if(next.nodeType == 1 && next.tagName == 'SPAN' && !next.firstChild){
  13053. domUtils.remove(next)
  13054. }else{
  13055. break;
  13056. }
  13057. }
  13058. if((pre && pre.nodeType == 1 && !domUtils.isEmptyBlock(pre) || !pre) && (!next || next && !domUtils.isEmptyBlock(next))){
  13059. if(pre && pre.tagName == 'P' && !domUtils.isEmptyBlock(pre)){
  13060. pre.appendChild(node);
  13061. domUtils.moveChild(next,pre);
  13062. domUtils.remove(next);
  13063. }else if(next && next.tagName == 'P' && !domUtils.isEmptyBlock(next)){
  13064. next.insertBefore(node,next.firstChild);
  13065. }
  13066. if(pre && pre.tagName == 'P' && domUtils.isEmptyBlock(pre)){
  13067. domUtils.remove(pre)
  13068. }
  13069. if(next && next.tagName == 'P' && domUtils.isEmptyBlock(next)){
  13070. domUtils.remove(next)
  13071. }
  13072. rng.selectNode(node).select();
  13073. me.fireEvent('saveScene');
  13074. }
  13075. }
  13076. })
  13077. });
  13078. me.addListener('keyup', function(type, evt) {
  13079. var keyCode = evt.keyCode || evt.which;
  13080. if (keyCode == 13) {
  13081. var rng = me.selection.getRange(),node;
  13082. if(node = domUtils.findParentByTagName(rng.startContainer,'p',true)){
  13083. if(domUtils.getComputedStyle(node,'text-align') == 'center'){
  13084. domUtils.removeStyle(node,'text-align')
  13085. }
  13086. }
  13087. }
  13088. })
  13089. };
  13090. // plugins/undo.js
  13091. /**
  13092. * undo redo
  13093. * @file
  13094. * @since 1.2.6.1
  13095. */
  13096. /**
  13097. * 撤销上一次执行的命令
  13098. * @command undo
  13099. * @method execCommand
  13100. * @param { String } cmd 命令字符串
  13101. * @example
  13102. * ```javascript
  13103. * editor.execCommand( 'undo' );
  13104. * ```
  13105. */
  13106. /**
  13107. * 重做上一次执行的命令
  13108. * @command redo
  13109. * @method execCommand
  13110. * @param { String } cmd 命令字符串
  13111. * @example
  13112. * ```javascript
  13113. * editor.execCommand( 'redo' );
  13114. * ```
  13115. */
  13116. UE.plugins['undo'] = function () {
  13117. var saveSceneTimer;
  13118. var me = this,
  13119. maxUndoCount = me.options.maxUndoCount || 20,
  13120. maxInputCount = me.options.maxInputCount || 20,
  13121. fillchar = new RegExp(domUtils.fillChar + '|<\/hr>', 'gi');// ie会产生多余的</hr>
  13122. var noNeedFillCharTags = {
  13123. ol:1,ul:1,table:1,tbody:1,tr:1,body:1
  13124. };
  13125. var orgState = me.options.autoClearEmptyNode;
  13126. function compareAddr(indexA, indexB) {
  13127. if (indexA.length != indexB.length)
  13128. return 0;
  13129. for (var i = 0, l = indexA.length; i < l; i++) {
  13130. if (indexA[i] != indexB[i])
  13131. return 0
  13132. }
  13133. return 1;
  13134. }
  13135. function compareRangeAddress(rngAddrA, rngAddrB) {
  13136. if (rngAddrA.collapsed != rngAddrB.collapsed) {
  13137. return 0;
  13138. }
  13139. if (!compareAddr(rngAddrA.startAddress, rngAddrB.startAddress) || !compareAddr(rngAddrA.endAddress, rngAddrB.endAddress)) {
  13140. return 0;
  13141. }
  13142. return 1;
  13143. }
  13144. function UndoManager() {
  13145. this.list = [];
  13146. this.index = 0;
  13147. this.hasUndo = false;
  13148. this.hasRedo = false;
  13149. var _disabled = false;
  13150. this.undo = function () {
  13151. if (this.hasUndo) {
  13152. if (!this.list[this.index - 1] && this.list.length == 1) {
  13153. this.reset();
  13154. return;
  13155. }
  13156. while (this.list[this.index].content == this.list[this.index - 1].content) {
  13157. this.index--;
  13158. if (this.index == 0) {
  13159. return this.restore(0);
  13160. }
  13161. }
  13162. this.restore(--this.index);
  13163. }
  13164. };
  13165. this.redo = function () {
  13166. if (this.hasRedo) {
  13167. while (this.list[this.index].content == this.list[this.index + 1].content) {
  13168. this.index++;
  13169. if (this.index == this.list.length - 1) {
  13170. return this.restore(this.index);
  13171. }
  13172. }
  13173. this.restore(++this.index);
  13174. }
  13175. };
  13176. this.restore = function () {
  13177. var me = this.editor;
  13178. var scene = this.list[this.index];
  13179. var root = UE.htmlparser(scene.content.replace(fillchar, ''));
  13180. me.options.autoClearEmptyNode = false;
  13181. me.filterInputRule(root);
  13182. me.options.autoClearEmptyNode = orgState;
  13183. //trace:873
  13184. //去掉展位符
  13185. me.document.body.innerHTML = root.toHtml();
  13186. me.fireEvent('afterscencerestore');
  13187. //处理undo后空格不展位的问题
  13188. if (browser.ie) {
  13189. utils.each(domUtils.getElementsByTagName(me.document,'td th caption p'),function(node){
  13190. if(domUtils.isEmptyNode(node)){
  13191. domUtils.fillNode(me.document, node);
  13192. }
  13193. })
  13194. }
  13195. try{
  13196. var rng = new dom.Range(me.document).moveToAddress(scene.address);
  13197. rng.select(noNeedFillCharTags[rng.startContainer.nodeName.toLowerCase()]);
  13198. }catch(e){}
  13199. this.update();
  13200. this.clearKey();
  13201. //不能把自己reset了
  13202. me.fireEvent('reset', true);
  13203. };
  13204. this.getScene = function () {
  13205. var me = this.editor;
  13206. var rng = me.selection.getRange(),
  13207. rngAddress = rng.createAddress(false,true);
  13208. me.fireEvent('beforegetscene');
  13209. var root = UE.htmlparser(me.body.innerHTML);
  13210. me.options.autoClearEmptyNode = false;
  13211. me.filterOutputRule(root);
  13212. me.options.autoClearEmptyNode = orgState;
  13213. var cont = root.toHtml();
  13214. //trace:3461
  13215. //这个会引起回退时导致空格丢失的情况
  13216. // browser.ie && (cont = cont.replace(/>&nbsp;</g, '><').replace(/\s*</g, '<').replace(/>\s*/g, '>'));
  13217. me.fireEvent('aftergetscene');
  13218. return {
  13219. address:rngAddress,
  13220. content:cont
  13221. }
  13222. };
  13223. this.save = function (notCompareRange,notSetCursor) {
  13224. clearTimeout(saveSceneTimer);
  13225. if(_disabled) return;
  13226. var currentScene = this.getScene(notSetCursor),
  13227. lastScene = this.list[this.index];
  13228. if(lastScene && lastScene.content != currentScene.content){
  13229. me.trigger('contentchange')
  13230. }
  13231. //内容相同位置相同不存
  13232. if (lastScene && lastScene.content == currentScene.content &&
  13233. ( notCompareRange ? 1 : compareRangeAddress(lastScene.address, currentScene.address) )
  13234. ) {
  13235. return;
  13236. }
  13237. this.list = this.list.slice(0, this.index + 1);
  13238. this.list.push(currentScene);
  13239. //如果大于最大数量了,就把最前的剔除
  13240. if (this.list.length > maxUndoCount) {
  13241. this.list.shift();
  13242. }
  13243. this.index = this.list.length - 1;
  13244. this.clearKey();
  13245. //跟新undo/redo状态
  13246. this.update();
  13247. };
  13248. this.enable = function(){
  13249. _disabled = false;
  13250. return this;
  13251. }
  13252. this.disable = function(){
  13253. _disabled = true;
  13254. return this;
  13255. }
  13256. this.update = function () {
  13257. this.hasRedo = !!this.list[this.index + 1];
  13258. this.hasUndo = !!this.list[this.index - 1];
  13259. };
  13260. this.reset = function () {
  13261. this.list = [];
  13262. this.index = 0;
  13263. this.hasUndo = false;
  13264. this.hasRedo = false;
  13265. this.clearKey();
  13266. };
  13267. this.clearKey = function () {
  13268. keycont = 0;
  13269. lastKeyCode = null;
  13270. };
  13271. }
  13272. me.undoManger = new UndoManager();
  13273. me.undoManger.editor = me;
  13274. function saveScene() {
  13275. this.undoManger.save();
  13276. }
  13277. me.addListener('saveScene', function () {
  13278. var args = Array.prototype.splice.call(arguments,1);
  13279. this.undoManger.save.apply(this.undoManger,args);
  13280. });
  13281. // me.addListener('beforeexeccommand', saveScene);
  13282. // me.addListener('afterexeccommand', saveScene);
  13283. me.addListener('reset', function (type, exclude) {
  13284. if (!exclude) {
  13285. this.undoManger.reset();
  13286. }
  13287. });
  13288. me.commands['redo'] = me.commands['undo'] = {
  13289. execCommand:function (cmdName) {
  13290. this.undoManger[cmdName]();
  13291. },
  13292. queryCommandState:function (cmdName) {
  13293. return this.undoManger['has' + (cmdName.toLowerCase() == 'undo' ? 'Undo' : 'Redo')] ? 0 : -1;
  13294. },
  13295. notNeedUndo:1
  13296. };
  13297. var keys = {
  13298. // /*Backspace*/ 8:1, /*Delete*/ 46:1,
  13299. /*Shift*/ 16:1, /*Ctrl*/ 17:1, /*Alt*/ 18:1,
  13300. 37:1, 38:1, 39:1, 40:1
  13301. },
  13302. keycont = 0,
  13303. lastKeyCode;
  13304. //输入法状态下不计算字符数
  13305. var inputType = false;
  13306. me.addListener('ready', function () {
  13307. domUtils.on(this.body, 'compositionstart', function () {
  13308. inputType = true;
  13309. });
  13310. domUtils.on(this.body, 'compositionend', function () {
  13311. inputType = false;
  13312. })
  13313. });
  13314. //快捷键
  13315. me.addshortcutkey({
  13316. "Undo":"ctrl+90", //undo
  13317. "Redo":"ctrl+89" //redo
  13318. });
  13319. var isCollapsed = true;
  13320. me.addListener('keydown', function (type, evt) {
  13321. var me = this;
  13322. var keyCode = evt.keyCode || evt.which;
  13323. if (!keys[keyCode] && !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey) {
  13324. if (inputType)
  13325. return;
  13326. if(!me.selection.getRange().collapsed){
  13327. me.undoManger.save(false,true);
  13328. isCollapsed = false;
  13329. return;
  13330. }
  13331. if (me.undoManger.list.length == 0) {
  13332. me.undoManger.save(true);
  13333. }
  13334. clearTimeout(saveSceneTimer);
  13335. function save(cont){
  13336. cont.undoManger.save(false,true);
  13337. cont.fireEvent('selectionchange');
  13338. }
  13339. saveSceneTimer = setTimeout(function(){
  13340. if(inputType){
  13341. var interalTimer = setInterval(function(){
  13342. if(!inputType){
  13343. save(me);
  13344. clearInterval(interalTimer)
  13345. }
  13346. },300)
  13347. return;
  13348. }
  13349. save(me);
  13350. },200);
  13351. lastKeyCode = keyCode;
  13352. keycont++;
  13353. if (keycont >= maxInputCount ) {
  13354. save(me)
  13355. }
  13356. }
  13357. });
  13358. me.addListener('keyup', function (type, evt) {
  13359. var keyCode = evt.keyCode || evt.which;
  13360. if (!keys[keyCode] && !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey) {
  13361. if (inputType)
  13362. return;
  13363. if(!isCollapsed){
  13364. this.undoManger.save(false,true);
  13365. isCollapsed = true;
  13366. }
  13367. }
  13368. });
  13369. //扩展实例,添加关闭和开启命令undo
  13370. me.stopCmdUndo = function(){
  13371. me.__hasEnterExecCommand = true;
  13372. };
  13373. me.startCmdUndo = function(){
  13374. me.__hasEnterExecCommand = false;
  13375. }
  13376. };
  13377. // plugins/copy.js
  13378. UE.plugin.register('copy', function () {
  13379. var me = this;
  13380. function initZeroClipboard() {
  13381. ZeroClipboard.config({
  13382. debug: false,
  13383. swfPath: me.options.UEDITOR_HOME_URL + 'third-party/zeroclipboard/ZeroClipboard.swf'
  13384. });
  13385. var client = me.zeroclipboard = new ZeroClipboard();
  13386. // 复制内容
  13387. client.on('copy', function (e) {
  13388. var client = e.client,
  13389. rng = me.selection.getRange(),
  13390. div = document.createElement('div');
  13391. div.appendChild(rng.cloneContents());
  13392. client.setText(div.innerText || div.textContent);
  13393. client.setHtml(div.innerHTML);
  13394. rng.select();
  13395. });
  13396. // hover事件传递到target
  13397. client.on('mouseover mouseout', function (e) {
  13398. var target = e.target;
  13399. if (e.type == 'mouseover') {
  13400. domUtils.addClass(target, 'edui-state-hover');
  13401. } else if (e.type == 'mouseout') {
  13402. domUtils.removeClasses(target, 'edui-state-hover');
  13403. }
  13404. });
  13405. // flash加载不成功
  13406. client.on('wrongflash noflash', function () {
  13407. ZeroClipboard.destroy();
  13408. });
  13409. }
  13410. return {
  13411. bindEvents: {
  13412. 'ready': function () {
  13413. if (!browser.ie) {
  13414. if (window.ZeroClipboard) {
  13415. initZeroClipboard();
  13416. } else {
  13417. utils.loadFile(document, {
  13418. src: me.options.UEDITOR_HOME_URL + "third-party/zeroclipboard/ZeroClipboard.js",
  13419. tag: "script",
  13420. type: "text/javascript",
  13421. defer: "defer"
  13422. }, function () {
  13423. initZeroClipboard();
  13424. });
  13425. }
  13426. }
  13427. }
  13428. },
  13429. commands: {
  13430. 'copy': {
  13431. execCommand: function (cmd) {
  13432. if (!me.document.execCommand('copy')) {
  13433. alert(me.getLang('copymsg'));
  13434. }
  13435. }
  13436. }
  13437. }
  13438. }
  13439. });
  13440. // plugins/paste.js
  13441. ///import core
  13442. ///import plugins/inserthtml.js
  13443. ///import plugins/undo.js
  13444. ///import plugins/serialize.js
  13445. ///commands 粘贴
  13446. ///commandsName PastePlain
  13447. ///commandsTitle 纯文本粘贴模式
  13448. /**
  13449. * @description 粘贴
  13450. * @author zhanyi
  13451. */
  13452. UE.plugins['paste'] = function () {
  13453. function getClipboardData(callback) {
  13454. var doc = this.document;
  13455. if (doc.getElementById('baidu_pastebin')) {
  13456. return;
  13457. }
  13458. var range = this.selection.getRange(),
  13459. bk = range.createBookmark(),
  13460. //创建剪贴的容器div
  13461. pastebin = doc.createElement('div');
  13462. pastebin.id = 'baidu_pastebin';
  13463. // Safari 要求div必须有内容,才能粘贴内容进来
  13464. browser.webkit && pastebin.appendChild(doc.createTextNode(domUtils.fillChar + domUtils.fillChar));
  13465. doc.body.appendChild(pastebin);
  13466. //trace:717 隐藏的span不能得到top
  13467. //bk.start.innerHTML = '&nbsp;';
  13468. bk.start.style.display = '';
  13469. pastebin.style.cssText = "position:absolute;width:1px;height:1px;overflow:hidden;left:-1000px;white-space:nowrap;top:" +
  13470. //要在现在光标平行的位置加入,否则会出现跳动的问题
  13471. domUtils.getXY(bk.start).y + 'px';
  13472. range.selectNodeContents(pastebin).select(true);
  13473. setTimeout(function () {
  13474. if (browser.webkit) {
  13475. for (var i = 0, pastebins = doc.querySelectorAll('#baidu_pastebin'), pi; pi = pastebins[i++];) {
  13476. if (domUtils.isEmptyNode(pi)) {
  13477. domUtils.remove(pi);
  13478. } else {
  13479. pastebin = pi;
  13480. break;
  13481. }
  13482. }
  13483. }
  13484. try {
  13485. pastebin.parentNode.removeChild(pastebin);
  13486. } catch (e) {
  13487. }
  13488. range.moveToBookmark(bk).select(true);
  13489. callback(pastebin);
  13490. }, 0);
  13491. }
  13492. var me = this;
  13493. me.setOpt({
  13494. retainOnlyLabelPasted : false
  13495. });
  13496. var txtContent, htmlContent, address;
  13497. function getPureHtml(html){
  13498. return html.replace(/<(\/?)([\w\-]+)([^>]*)>/gi, function (a, b, tagName, attrs) {
  13499. tagName = tagName.toLowerCase();
  13500. if ({img: 1}[tagName]) {
  13501. return a;
  13502. }
  13503. attrs = attrs.replace(/([\w\-]*?)\s*=\s*(("([^"]*)")|('([^']*)')|([^\s>]+))/gi, function (str, atr, val) {
  13504. if ({
  13505. 'src': 1,
  13506. 'href': 1,
  13507. 'name': 1
  13508. }[atr.toLowerCase()]) {
  13509. return atr + '=' + val + ' '
  13510. }
  13511. return ''
  13512. });
  13513. if ({
  13514. 'span': 1,
  13515. 'div': 1
  13516. }[tagName]) {
  13517. return ''
  13518. } else {
  13519. return '<' + b + tagName + ' ' + utils.trim(attrs) + '>'
  13520. }
  13521. });
  13522. }
  13523. function filter(div) {
  13524. var html;
  13525. if (div.firstChild) {
  13526. //去掉cut中添加的边界值
  13527. var nodes = domUtils.getElementsByTagName(div, 'span');
  13528. for (var i = 0, ni; ni = nodes[i++];) {
  13529. if (ni.id == '_baidu_cut_start' || ni.id == '_baidu_cut_end') {
  13530. domUtils.remove(ni);
  13531. }
  13532. }
  13533. if (browser.webkit) {
  13534. var brs = div.querySelectorAll('div br');
  13535. for (var i = 0, bi; bi = brs[i++];) {
  13536. var pN = bi.parentNode;
  13537. if (pN.tagName == 'DIV' && pN.childNodes.length == 1) {
  13538. pN.innerHTML = '<p><br/></p>';
  13539. domUtils.remove(pN);
  13540. }
  13541. }
  13542. var divs = div.querySelectorAll('#baidu_pastebin');
  13543. for (var i = 0, di; di = divs[i++];) {
  13544. var tmpP = me.document.createElement('p');
  13545. di.parentNode.insertBefore(tmpP, di);
  13546. while (di.firstChild) {
  13547. tmpP.appendChild(di.firstChild);
  13548. }
  13549. domUtils.remove(di);
  13550. }
  13551. var metas = div.querySelectorAll('meta');
  13552. for (var i = 0, ci; ci = metas[i++];) {
  13553. domUtils.remove(ci);
  13554. }
  13555. var brs = div.querySelectorAll('br');
  13556. for (i = 0; ci = brs[i++];) {
  13557. if (/^apple-/i.test(ci.className)) {
  13558. domUtils.remove(ci);
  13559. }
  13560. }
  13561. }
  13562. if (browser.gecko) {
  13563. var dirtyNodes = div.querySelectorAll('[_moz_dirty]');
  13564. for (i = 0; ci = dirtyNodes[i++];) {
  13565. ci.removeAttribute('_moz_dirty');
  13566. }
  13567. }
  13568. if (!browser.ie) {
  13569. var spans = div.querySelectorAll('span.Apple-style-span');
  13570. for (var i = 0, ci; ci = spans[i++];) {
  13571. domUtils.remove(ci, true);
  13572. }
  13573. }
  13574. //ie下使用innerHTML会产生多余的\r\n字符,也会产生&nbsp;这里过滤掉
  13575. html = div.innerHTML;//.replace(/>(?:(\s|&nbsp;)*?)</g,'><');
  13576. //过滤word粘贴过来的冗余属性
  13577. html = UE.filterWord(html);
  13578. //取消了忽略空白的第二个参数,粘贴过来的有些是有空白的,会被套上相关的标签
  13579. var root = UE.htmlparser(html);
  13580. //如果给了过滤规则就先进行过滤
  13581. if (me.options.filterRules) {
  13582. UE.filterNode(root, me.options.filterRules);
  13583. }
  13584. //执行默认的处理
  13585. me.filterInputRule(root);
  13586. //针对chrome的处理
  13587. if (browser.webkit) {
  13588. var br = root.lastChild();
  13589. if (br && br.type == 'element' && br.tagName == 'br') {
  13590. root.removeChild(br)
  13591. }
  13592. utils.each(me.body.querySelectorAll('div'), function (node) {
  13593. if (domUtils.isEmptyBlock(node)) {
  13594. domUtils.remove(node,true)
  13595. }
  13596. })
  13597. }
  13598. html = {'html': root.toHtml()};
  13599. me.fireEvent('beforepaste', html, root);
  13600. //抢了默认的粘贴,那后边的内容就不执行了,比如表格粘贴
  13601. if(!html.html){
  13602. return;
  13603. }
  13604. root = UE.htmlparser(html.html,true);
  13605. //如果开启了纯文本模式
  13606. if (me.queryCommandState('pasteplain') === 1) {
  13607. me.execCommand('insertHtml', UE.filterNode(root, me.options.filterTxtRules).toHtml(), true);
  13608. } else {
  13609. //文本模式
  13610. UE.filterNode(root, me.options.filterTxtRules);
  13611. txtContent = root.toHtml();
  13612. //完全模式
  13613. htmlContent = html.html;
  13614. address = me.selection.getRange().createAddress(true);
  13615. me.execCommand('insertHtml', me.getOpt('retainOnlyLabelPasted') === true ? getPureHtml(htmlContent) : htmlContent, true);
  13616. }
  13617. me.fireEvent("afterpaste", html);
  13618. }
  13619. }
  13620. me.addListener('pasteTransfer', function (cmd, plainType) {
  13621. if (address && txtContent && htmlContent && txtContent != htmlContent) {
  13622. var range = me.selection.getRange();
  13623. range.moveToAddress(address, true);
  13624. if (!range.collapsed) {
  13625. while (!domUtils.isBody(range.startContainer)
  13626. ) {
  13627. var start = range.startContainer;
  13628. if(start.nodeType == 1){
  13629. start = start.childNodes[range.startOffset];
  13630. if(!start){
  13631. range.setStartBefore(range.startContainer);
  13632. continue;
  13633. }
  13634. var pre = start.previousSibling;
  13635. if(pre && pre.nodeType == 3 && new RegExp('^[\n\r\t '+domUtils.fillChar+']*$').test(pre.nodeValue)){
  13636. range.setStartBefore(pre)
  13637. }
  13638. }
  13639. if(range.startOffset == 0){
  13640. range.setStartBefore(range.startContainer);
  13641. }else{
  13642. break;
  13643. }
  13644. }
  13645. while (!domUtils.isBody(range.endContainer)
  13646. ) {
  13647. var end = range.endContainer;
  13648. if(end.nodeType == 1){
  13649. end = end.childNodes[range.endOffset];
  13650. if(!end){
  13651. range.setEndAfter(range.endContainer);
  13652. continue;
  13653. }
  13654. var next = end.nextSibling;
  13655. if(next && next.nodeType == 3 && new RegExp('^[\n\r\t'+domUtils.fillChar+']*$').test(next.nodeValue)){
  13656. range.setEndAfter(next)
  13657. }
  13658. }
  13659. if(range.endOffset == range.endContainer[range.endContainer.nodeType == 3 ? 'nodeValue' : 'childNodes'].length){
  13660. range.setEndAfter(range.endContainer);
  13661. }else{
  13662. break;
  13663. }
  13664. }
  13665. }
  13666. range.deleteContents();
  13667. range.select(true);
  13668. me.__hasEnterExecCommand = true;
  13669. var html = htmlContent;
  13670. if (plainType === 2 ) {
  13671. html = getPureHtml(html);
  13672. } else if (plainType) {
  13673. html = txtContent;
  13674. }
  13675. me.execCommand('inserthtml', html, true);
  13676. me.__hasEnterExecCommand = false;
  13677. var rng = me.selection.getRange();
  13678. while (!domUtils.isBody(rng.startContainer) && !rng.startOffset &&
  13679. rng.startContainer[rng.startContainer.nodeType == 3 ? 'nodeValue' : 'childNodes'].length
  13680. ) {
  13681. rng.setStartBefore(rng.startContainer);
  13682. }
  13683. var tmpAddress = rng.createAddress(true);
  13684. address.endAddress = tmpAddress.startAddress;
  13685. }
  13686. });
  13687. me.addListener('ready', function () {
  13688. domUtils.on(me.body, 'cut', function () {
  13689. var range = me.selection.getRange();
  13690. if (!range.collapsed && me.undoManger) {
  13691. me.undoManger.save();
  13692. }
  13693. });
  13694. //ie下beforepaste在点击右键时也会触发,所以用监控键盘才处理
  13695. domUtils.on(me.body, browser.ie || browser.opera ? 'keydown' : 'paste', function (e) {
  13696. if ((browser.ie || browser.opera) && ((!e.ctrlKey && !e.metaKey) || e.keyCode != '86')) {
  13697. return;
  13698. }
  13699. getClipboardData.call(me, function (div) {
  13700. filter(div);
  13701. });
  13702. });
  13703. });
  13704. me.commands['paste'] = {
  13705. execCommand: function (cmd) {
  13706. if (browser.ie) {
  13707. getClipboardData.call(me, function (div) {
  13708. filter(div);
  13709. });
  13710. me.document.execCommand('paste');
  13711. } else {
  13712. alert(me.getLang('pastemsg'));
  13713. }
  13714. }
  13715. }
  13716. };
  13717. // plugins/puretxtpaste.js
  13718. /**
  13719. * 纯文本粘贴插件
  13720. * @file
  13721. * @since 1.2.6.1
  13722. */
  13723. UE.plugins['pasteplain'] = function(){
  13724. var me = this;
  13725. me.setOpt({
  13726. 'pasteplain':false,
  13727. 'filterTxtRules' : function(){
  13728. function transP(node){
  13729. node.tagName = 'p';
  13730. node.setStyle();
  13731. }
  13732. function removeNode(node){
  13733. node.parentNode.removeChild(node,true)
  13734. }
  13735. return {
  13736. //直接删除及其字节点内容
  13737. '-' : 'script style object iframe embed input select',
  13738. 'p': {$:{}},
  13739. 'br':{$:{}},
  13740. div: function (node) {
  13741. var tmpNode, p = UE.uNode.createElement('p');
  13742. while (tmpNode = node.firstChild()) {
  13743. if (tmpNode.type == 'text' || !UE.dom.dtd.$block[tmpNode.tagName]) {
  13744. p.appendChild(tmpNode);
  13745. } else {
  13746. if (p.firstChild()) {
  13747. node.parentNode.insertBefore(p, node);
  13748. p = UE.uNode.createElement('p');
  13749. } else {
  13750. node.parentNode.insertBefore(tmpNode, node);
  13751. }
  13752. }
  13753. }
  13754. if (p.firstChild()) {
  13755. node.parentNode.insertBefore(p, node);
  13756. }
  13757. node.parentNode.removeChild(node);
  13758. },
  13759. ol: removeNode,
  13760. ul: removeNode,
  13761. dl:removeNode,
  13762. dt:removeNode,
  13763. dd:removeNode,
  13764. 'li':removeNode,
  13765. 'caption':transP,
  13766. 'th':transP,
  13767. 'tr':transP,
  13768. 'h1':transP,'h2':transP,'h3':transP,'h4':transP,'h5':transP,'h6':transP,
  13769. 'td':function(node){
  13770. //没有内容的td直接删掉
  13771. var txt = !!node.innerText();
  13772. if(txt){
  13773. node.parentNode.insertAfter(UE.uNode.createText(' &nbsp; &nbsp;'),node);
  13774. }
  13775. node.parentNode.removeChild(node,node.innerText())
  13776. }
  13777. }
  13778. }()
  13779. });
  13780. //暂时这里支持一下老版本的属性
  13781. var pasteplain = me.options.pasteplain;
  13782. /**
  13783. * 启用或取消纯文本粘贴模式
  13784. * @command pasteplain
  13785. * @method execCommand
  13786. * @param { String } cmd 命令字符串
  13787. * @example
  13788. * ```javascript
  13789. * editor.queryCommandState( 'pasteplain' );
  13790. * ```
  13791. */
  13792. /**
  13793. * 查询当前是否处于纯文本粘贴模式
  13794. * @command pasteplain
  13795. * @method queryCommandState
  13796. * @param { String } cmd 命令字符串
  13797. * @return { int } 如果处于纯文本模式,返回1,否则,返回0
  13798. * @example
  13799. * ```javascript
  13800. * editor.queryCommandState( 'pasteplain' );
  13801. * ```
  13802. */
  13803. me.commands['pasteplain'] = {
  13804. queryCommandState: function (){
  13805. return pasteplain ? 1 : 0;
  13806. },
  13807. execCommand: function (){
  13808. pasteplain = !pasteplain|0;
  13809. },
  13810. notNeedUndo : 1
  13811. };
  13812. };
  13813. // plugins/list.js
  13814. /**
  13815. * 有序列表,无序列表插件
  13816. * @file
  13817. * @since 1.2.6.1
  13818. */
  13819. UE.plugins['list'] = function () {
  13820. var me = this,
  13821. notExchange = {
  13822. 'TD':1,
  13823. 'PRE':1,
  13824. 'BLOCKQUOTE':1
  13825. };
  13826. var customStyle = {
  13827. 'cn' : 'cn-1-',
  13828. 'cn1' : 'cn-2-',
  13829. 'cn2' : 'cn-3-',
  13830. 'num': 'num-1-',
  13831. 'num1' : 'num-2-',
  13832. 'num2' : 'num-3-',
  13833. 'dash' : 'dash',
  13834. 'dot':'dot'
  13835. };
  13836. me.setOpt( {
  13837. 'autoTransWordToList':false,
  13838. 'insertorderedlist':{
  13839. 'num':'',
  13840. 'num1':'',
  13841. 'num2':'',
  13842. 'cn':'',
  13843. 'cn1':'',
  13844. 'cn2':'',
  13845. 'decimal':'',
  13846. 'lower-alpha':'',
  13847. 'lower-roman':'',
  13848. 'upper-alpha':'',
  13849. 'upper-roman':''
  13850. },
  13851. 'insertunorderedlist':{
  13852. 'circle':'',
  13853. 'disc':'',
  13854. 'square':'',
  13855. 'dash' : '',
  13856. 'dot':''
  13857. },
  13858. listDefaultPaddingLeft : '30',
  13859. listiconpath : 'http://bs.baidu.com/listicon/',
  13860. maxListLevel : -1,//-1不限制
  13861. disablePInList:false
  13862. } );
  13863. function listToArray(list){
  13864. var arr = [];
  13865. for(var p in list){
  13866. arr.push(p)
  13867. }
  13868. return arr;
  13869. }
  13870. var listStyle = {
  13871. 'OL':listToArray(me.options.insertorderedlist),
  13872. 'UL':listToArray(me.options.insertunorderedlist)
  13873. };
  13874. var liiconpath = me.options.listiconpath;
  13875. //根据用户配置,调整customStyle
  13876. for(var s in customStyle){
  13877. if(!me.options.insertorderedlist.hasOwnProperty(s) && !me.options.insertunorderedlist.hasOwnProperty(s)){
  13878. delete customStyle[s];
  13879. }
  13880. }
  13881. me.ready(function () {
  13882. var customCss = [];
  13883. for(var p in customStyle){
  13884. if(p == 'dash' || p == 'dot'){
  13885. customCss.push('li.list-' + customStyle[p] + '{background-image:url(' + liiconpath +customStyle[p]+'.gif)}');
  13886. customCss.push('ul.custom_'+p+'{list-style:none;}ul.custom_'+p+' li{background-position:0 3px;background-repeat:no-repeat}');
  13887. }else{
  13888. for(var i= 0;i<99;i++){
  13889. customCss.push('li.list-' + customStyle[p] + i + '{background-image:url(' + liiconpath + 'list-'+customStyle[p] + i + '.gif)}')
  13890. }
  13891. customCss.push('ol.custom_'+p+'{list-style:none;}ol.custom_'+p+' li{background-position:0 3px;background-repeat:no-repeat}');
  13892. }
  13893. switch(p){
  13894. case 'cn':
  13895. customCss.push('li.list-'+p+'-paddingleft-1{padding-left:25px}');
  13896. customCss.push('li.list-'+p+'-paddingleft-2{padding-left:40px}');
  13897. customCss.push('li.list-'+p+'-paddingleft-3{padding-left:55px}');
  13898. break;
  13899. case 'cn1':
  13900. customCss.push('li.list-'+p+'-paddingleft-1{padding-left:30px}');
  13901. customCss.push('li.list-'+p+'-paddingleft-2{padding-left:40px}');
  13902. customCss.push('li.list-'+p+'-paddingleft-3{padding-left:55px}');
  13903. break;
  13904. case 'cn2':
  13905. customCss.push('li.list-'+p+'-paddingleft-1{padding-left:40px}');
  13906. customCss.push('li.list-'+p+'-paddingleft-2{padding-left:55px}');
  13907. customCss.push('li.list-'+p+'-paddingleft-3{padding-left:68px}');
  13908. break;
  13909. case 'num':
  13910. case 'num1':
  13911. customCss.push('li.list-'+p+'-paddingleft-1{padding-left:25px}');
  13912. break;
  13913. case 'num2':
  13914. customCss.push('li.list-'+p+'-paddingleft-1{padding-left:35px}');
  13915. customCss.push('li.list-'+p+'-paddingleft-2{padding-left:40px}');
  13916. break;
  13917. case 'dash':
  13918. customCss.push('li.list-'+p+'-paddingleft{padding-left:35px}');
  13919. break;
  13920. case 'dot':
  13921. customCss.push('li.list-'+p+'-paddingleft{padding-left:20px}');
  13922. }
  13923. }
  13924. customCss.push('.list-paddingleft-1{padding-left:0}');
  13925. customCss.push('.list-paddingleft-2{padding-left:'+me.options.listDefaultPaddingLeft+'px}');
  13926. customCss.push('.list-paddingleft-3{padding-left:'+me.options.listDefaultPaddingLeft*2+'px}');
  13927. //如果不给宽度会在自定应样式里出现滚动条
  13928. utils.cssRule('list', 'ol,ul{margin:0;pading:0;'+(browser.ie ? '' : 'width:95%')+'}li{clear:both;}'+customCss.join('\n'), me.document);
  13929. });
  13930. //单独处理剪切的问题
  13931. me.ready(function(){
  13932. domUtils.on(me.body,'cut',function(){
  13933. setTimeout(function(){
  13934. var rng = me.selection.getRange(),li;
  13935. //trace:3416
  13936. if(!rng.collapsed){
  13937. if(li = domUtils.findParentByTagName(rng.startContainer,'li',true)){
  13938. if(!li.nextSibling && domUtils.isEmptyBlock(li)){
  13939. var pn = li.parentNode,node;
  13940. if(node = pn.previousSibling){
  13941. domUtils.remove(pn);
  13942. rng.setStartAtLast(node).collapse(true);
  13943. rng.select(true);
  13944. }else if(node = pn.nextSibling){
  13945. domUtils.remove(pn);
  13946. rng.setStartAtFirst(node).collapse(true);
  13947. rng.select(true);
  13948. }else{
  13949. var tmpNode = me.document.createElement('p');
  13950. domUtils.fillNode(me.document,tmpNode);
  13951. pn.parentNode.insertBefore(tmpNode,pn);
  13952. domUtils.remove(pn);
  13953. rng.setStart(tmpNode,0).collapse(true);
  13954. rng.select(true);
  13955. }
  13956. }
  13957. }
  13958. }
  13959. })
  13960. })
  13961. });
  13962. function getStyle(node){
  13963. var cls = node.className;
  13964. if(domUtils.hasClass(node,/custom_/)){
  13965. return cls.match(/custom_(\w+)/)[1]
  13966. }
  13967. return domUtils.getStyle(node, 'list-style-type')
  13968. }
  13969. me.addListener('beforepaste',function(type,html){
  13970. var me = this,
  13971. rng = me.selection.getRange(),li;
  13972. var root = UE.htmlparser(html.html,true);
  13973. if(li = domUtils.findParentByTagName(rng.startContainer,'li',true)){
  13974. var list = li.parentNode,tagName = list.tagName == 'OL' ? 'ul':'ol';
  13975. utils.each(root.getNodesByTagName(tagName),function(n){
  13976. n.tagName = list.tagName;
  13977. n.setAttr();
  13978. if(n.parentNode === root){
  13979. type = getStyle(list) || (list.tagName == 'OL' ? 'decimal' : 'disc')
  13980. }else{
  13981. var className = n.parentNode.getAttr('class');
  13982. if(className && /custom_/.test(className)){
  13983. type = className.match(/custom_(\w+)/)[1]
  13984. }else{
  13985. type = n.parentNode.getStyle('list-style-type');
  13986. }
  13987. if(!type){
  13988. type = list.tagName == 'OL' ? 'decimal' : 'disc';
  13989. }
  13990. }
  13991. var index = utils.indexOf(listStyle[list.tagName], type);
  13992. if(n.parentNode !== root)
  13993. index = index + 1 == listStyle[list.tagName].length ? 0 : index + 1;
  13994. var currentStyle = listStyle[list.tagName][index];
  13995. if(customStyle[currentStyle]){
  13996. n.setAttr('class', 'custom_' + currentStyle)
  13997. }else{
  13998. n.setStyle('list-style-type',currentStyle)
  13999. }
  14000. })
  14001. }
  14002. html.html = root.toHtml();
  14003. });
  14004. //导出时,去掉p标签
  14005. me.getOpt('disablePInList') === true && me.addOutputRule(function(root){
  14006. utils.each(root.getNodesByTagName('li'),function(li){
  14007. var newChildrens = [],index=0;
  14008. utils.each(li.children,function(n){
  14009. if(n.tagName == 'p'){
  14010. var tmpNode;
  14011. while(tmpNode = n.children.pop()) {
  14012. newChildrens.splice(index,0,tmpNode);
  14013. tmpNode.parentNode = li;
  14014. lastNode = tmpNode;
  14015. }
  14016. tmpNode = newChildrens[newChildrens.length-1];
  14017. if(!tmpNode || tmpNode.type != 'element' || tmpNode.tagName != 'br'){
  14018. var br = UE.uNode.createElement('br');
  14019. br.parentNode = li;
  14020. newChildrens.push(br);
  14021. }
  14022. index = newChildrens.length;
  14023. }
  14024. });
  14025. if(newChildrens.length){
  14026. li.children = newChildrens;
  14027. }
  14028. });
  14029. });
  14030. //进入编辑器的li要套p标签
  14031. me.addInputRule(function(root){
  14032. utils.each(root.getNodesByTagName('li'),function(li){
  14033. var tmpP = UE.uNode.createElement('p');
  14034. for(var i= 0,ci;ci=li.children[i];){
  14035. if(ci.type == 'text' || dtd.p[ci.tagName]){
  14036. tmpP.appendChild(ci);
  14037. }else{
  14038. if(tmpP.firstChild()){
  14039. li.insertBefore(tmpP,ci);
  14040. tmpP = UE.uNode.createElement('p');
  14041. i = i + 2;
  14042. }else{
  14043. i++;
  14044. }
  14045. }
  14046. }
  14047. if(tmpP.firstChild() && !tmpP.parentNode || !li.firstChild()){
  14048. li.appendChild(tmpP);
  14049. }
  14050. //trace:3357
  14051. //p不能为空
  14052. if (!tmpP.firstChild()) {
  14053. tmpP.innerHTML(browser.ie ? '&nbsp;' : '<br/>')
  14054. }
  14055. //去掉末尾的空白
  14056. var p = li.firstChild();
  14057. var lastChild = p.lastChild();
  14058. if(lastChild && lastChild.type == 'text' && /^\s*$/.test(lastChild.data)){
  14059. p.removeChild(lastChild)
  14060. }
  14061. });
  14062. if(me.options.autoTransWordToList){
  14063. var orderlisttype = {
  14064. 'num1':/^\d+\)/,
  14065. 'decimal':/^\d+\./,
  14066. 'lower-alpha':/^[a-z]+\)/,
  14067. 'upper-alpha':/^[A-Z]+\./,
  14068. 'cn':/^[\u4E00\u4E8C\u4E09\u56DB\u516d\u4e94\u4e03\u516b\u4e5d]+[\u3001]/,
  14069. 'cn2':/^\([\u4E00\u4E8C\u4E09\u56DB\u516d\u4e94\u4e03\u516b\u4e5d]+\)/
  14070. },
  14071. unorderlisttype = {
  14072. 'square':'n'
  14073. };
  14074. function checkListType(content,container){
  14075. var span = container.firstChild();
  14076. if(span && span.type == 'element' && span.tagName == 'span' && /Wingdings|Symbol/.test(span.getStyle('font-family'))){
  14077. for(var p in unorderlisttype){
  14078. if(unorderlisttype[p] == span.data){
  14079. return p
  14080. }
  14081. }
  14082. return 'disc'
  14083. }
  14084. for(var p in orderlisttype){
  14085. if(orderlisttype[p].test(content)){
  14086. return p;
  14087. }
  14088. }
  14089. }
  14090. utils.each(root.getNodesByTagName('p'),function(node){
  14091. if(node.getAttr('class') != 'MsoListParagraph'){
  14092. return
  14093. }
  14094. //word粘贴过来的会带有margin要去掉,但这样也可能会误命中一些央视
  14095. node.setStyle('margin','');
  14096. node.setStyle('margin-left','');
  14097. node.setAttr('class','');
  14098. function appendLi(list,p,type){
  14099. if(list.tagName == 'ol'){
  14100. if(browser.ie){
  14101. var first = p.firstChild();
  14102. if(first.type =='element' && first.tagName == 'span' && orderlisttype[type].test(first.innerText())){
  14103. p.removeChild(first);
  14104. }
  14105. }else{
  14106. p.innerHTML(p.innerHTML().replace(orderlisttype[type],''));
  14107. }
  14108. }else{
  14109. p.removeChild(p.firstChild())
  14110. }
  14111. var li = UE.uNode.createElement('li');
  14112. li.appendChild(p);
  14113. list.appendChild(li);
  14114. }
  14115. var tmp = node,type,cacheNode = node;
  14116. if(node.parentNode.tagName != 'li' && (type = checkListType(node.innerText(),node))){
  14117. var list = UE.uNode.createElement(me.options.insertorderedlist.hasOwnProperty(type) ? 'ol' : 'ul');
  14118. if(customStyle[type]){
  14119. list.setAttr('class','custom_'+type)
  14120. }else{
  14121. list.setStyle('list-style-type',type)
  14122. }
  14123. while(node && node.parentNode.tagName != 'li' && checkListType(node.innerText(),node)){
  14124. tmp = node.nextSibling();
  14125. if(!tmp){
  14126. node.parentNode.insertBefore(list,node)
  14127. }
  14128. appendLi(list,node,type);
  14129. node = tmp;
  14130. }
  14131. if(!list.parentNode && node && node.parentNode){
  14132. node.parentNode.insertBefore(list,node)
  14133. }
  14134. }
  14135. var span = cacheNode.firstChild();
  14136. if(span && span.type == 'element' && span.tagName == 'span' && /^\s*(&nbsp;)+\s*$/.test(span.innerText())){
  14137. span.parentNode.removeChild(span)
  14138. }
  14139. })
  14140. }
  14141. });
  14142. //调整索引标签
  14143. me.addListener('contentchange',function(){
  14144. adjustListStyle(me.document)
  14145. });
  14146. function adjustListStyle(doc,ignore){
  14147. utils.each(domUtils.getElementsByTagName(doc,'ol ul'),function(node){
  14148. if(!domUtils.inDoc(node,doc))
  14149. return;
  14150. var parent = node.parentNode;
  14151. if(parent.tagName == node.tagName){
  14152. var nodeStyleType = getStyle(node) || (node.tagName == 'OL' ? 'decimal' : 'disc'),
  14153. parentStyleType = getStyle(parent) || (parent.tagName == 'OL' ? 'decimal' : 'disc');
  14154. if(nodeStyleType == parentStyleType){
  14155. var styleIndex = utils.indexOf(listStyle[node.tagName], nodeStyleType);
  14156. styleIndex = styleIndex + 1 == listStyle[node.tagName].length ? 0 : styleIndex + 1;
  14157. setListStyle(node,listStyle[node.tagName][styleIndex])
  14158. }
  14159. }
  14160. var index = 0,type = 2;
  14161. if( domUtils.hasClass(node,/custom_/)){
  14162. if(!(/[ou]l/i.test(parent.tagName) && domUtils.hasClass(parent,/custom_/))){
  14163. type = 1;
  14164. }
  14165. }else{
  14166. if(/[ou]l/i.test(parent.tagName) && domUtils.hasClass(parent,/custom_/)){
  14167. type = 3;
  14168. }
  14169. }
  14170. var style = domUtils.getStyle(node, 'list-style-type');
  14171. style && (node.style.cssText = 'list-style-type:' + style);
  14172. node.className = utils.trim(node.className.replace(/list-paddingleft-\w+/,'')) + ' list-paddingleft-' + type;
  14173. utils.each(domUtils.getElementsByTagName(node,'li'),function(li){
  14174. li.style.cssText && (li.style.cssText = '');
  14175. if(!li.firstChild){
  14176. domUtils.remove(li);
  14177. return;
  14178. }
  14179. if(li.parentNode !== node){
  14180. return;
  14181. }
  14182. index++;
  14183. if(domUtils.hasClass(node,/custom_/) ){
  14184. var paddingLeft = 1,currentStyle = getStyle(node);
  14185. if(node.tagName == 'OL'){
  14186. if(currentStyle){
  14187. switch(currentStyle){
  14188. case 'cn' :
  14189. case 'cn1':
  14190. case 'cn2':
  14191. if(index > 10 && (index % 10 == 0 || index > 10 && index < 20)){
  14192. paddingLeft = 2
  14193. }else if(index > 20){
  14194. paddingLeft = 3
  14195. }
  14196. break;
  14197. case 'num2' :
  14198. if(index > 9){
  14199. paddingLeft = 2
  14200. }
  14201. }
  14202. }
  14203. li.className = 'list-'+customStyle[currentStyle]+ index + ' ' + 'list-'+currentStyle+'-paddingleft-' + paddingLeft;
  14204. }else{
  14205. li.className = 'list-'+customStyle[currentStyle] + ' ' + 'list-'+currentStyle+'-paddingleft';
  14206. }
  14207. }else{
  14208. li.className = li.className.replace(/list-[\w\-]+/gi,'');
  14209. }
  14210. var className = li.getAttribute('class');
  14211. if(className !== null && !className.replace(/\s/g,'')){
  14212. domUtils.removeAttributes(li,'class')
  14213. }
  14214. });
  14215. !ignore && adjustList(node,node.tagName.toLowerCase(),getStyle(node)||domUtils.getStyle(node, 'list-style-type'),true);
  14216. })
  14217. }
  14218. function adjustList(list, tag, style,ignoreEmpty) {
  14219. var nextList = list.nextSibling;
  14220. if (nextList && nextList.nodeType == 1 && nextList.tagName.toLowerCase() == tag && (getStyle(nextList) || domUtils.getStyle(nextList, 'list-style-type') || (tag == 'ol' ? 'decimal' : 'disc')) == style) {
  14221. domUtils.moveChild(nextList, list);
  14222. if (nextList.childNodes.length == 0) {
  14223. domUtils.remove(nextList);
  14224. }
  14225. }
  14226. if(nextList && domUtils.isFillChar(nextList)){
  14227. domUtils.remove(nextList);
  14228. }
  14229. var preList = list.previousSibling;
  14230. if (preList && preList.nodeType == 1 && preList.tagName.toLowerCase() == tag && (getStyle(preList) || domUtils.getStyle(preList, 'list-style-type') || (tag == 'ol' ? 'decimal' : 'disc')) == style) {
  14231. domUtils.moveChild(list, preList);
  14232. }
  14233. if(preList && domUtils.isFillChar(preList)){
  14234. domUtils.remove(preList);
  14235. }
  14236. !ignoreEmpty && domUtils.isEmptyBlock(list) && domUtils.remove(list);
  14237. if(getStyle(list)){
  14238. adjustListStyle(list.ownerDocument,true)
  14239. }
  14240. }
  14241. function setListStyle(list,style){
  14242. if(customStyle[style]){
  14243. list.className = 'custom_' + style;
  14244. }
  14245. try{
  14246. domUtils.setStyle(list, 'list-style-type', style);
  14247. }catch(e){}
  14248. }
  14249. function clearEmptySibling(node) {
  14250. var tmpNode = node.previousSibling;
  14251. if (tmpNode && domUtils.isEmptyBlock(tmpNode)) {
  14252. domUtils.remove(tmpNode);
  14253. }
  14254. tmpNode = node.nextSibling;
  14255. if (tmpNode && domUtils.isEmptyBlock(tmpNode)) {
  14256. domUtils.remove(tmpNode);
  14257. }
  14258. }
  14259. me.addListener('keydown', function (type, evt) {
  14260. function preventAndSave() {
  14261. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  14262. me.fireEvent('contentchange');
  14263. me.undoManger && me.undoManger.save();
  14264. }
  14265. function findList(node,filterFn){
  14266. while(node && !domUtils.isBody(node)){
  14267. if(filterFn(node)){
  14268. return null
  14269. }
  14270. if(node.nodeType == 1 && /[ou]l/i.test(node.tagName)){
  14271. return node;
  14272. }
  14273. node = node.parentNode;
  14274. }
  14275. return null;
  14276. }
  14277. var keyCode = evt.keyCode || evt.which;
  14278. if (keyCode == 13 && !evt.shiftKey) {//回车
  14279. var rng = me.selection.getRange(),
  14280. parent = domUtils.findParent(rng.startContainer,function(node){return domUtils.isBlockElm(node)},true),
  14281. li = domUtils.findParentByTagName(rng.startContainer,'li',true);
  14282. if(parent && parent.tagName != 'PRE' && !li){
  14283. var html = parent.innerHTML.replace(new RegExp(domUtils.fillChar, 'g'),'');
  14284. if(/^\s*1\s*\.[^\d]/.test(html)){
  14285. parent.innerHTML = html.replace(/^\s*1\s*\./,'');
  14286. rng.setStartAtLast(parent).collapse(true).select();
  14287. me.__hasEnterExecCommand = true;
  14288. me.execCommand('insertorderedlist');
  14289. me.__hasEnterExecCommand = false;
  14290. }
  14291. }
  14292. var range = me.selection.getRange(),
  14293. start = findList(range.startContainer,function (node) {
  14294. return node.tagName == 'TABLE';
  14295. }),
  14296. end = range.collapsed ? start : findList(range.endContainer,function (node) {
  14297. return node.tagName == 'TABLE';
  14298. });
  14299. if (start && end && start === end) {
  14300. if (!range.collapsed) {
  14301. start = domUtils.findParentByTagName(range.startContainer, 'li', true);
  14302. end = domUtils.findParentByTagName(range.endContainer, 'li', true);
  14303. if (start && end && start === end) {
  14304. range.deleteContents();
  14305. li = domUtils.findParentByTagName(range.startContainer, 'li', true);
  14306. if (li && domUtils.isEmptyBlock(li)) {
  14307. pre = li.previousSibling;
  14308. next = li.nextSibling;
  14309. p = me.document.createElement('p');
  14310. domUtils.fillNode(me.document, p);
  14311. parentList = li.parentNode;
  14312. if (pre && next) {
  14313. range.setStart(next, 0).collapse(true).select(true);
  14314. domUtils.remove(li);
  14315. } else {
  14316. if (!pre && !next || !pre) {
  14317. parentList.parentNode.insertBefore(p, parentList);
  14318. } else {
  14319. li.parentNode.parentNode.insertBefore(p, parentList.nextSibling);
  14320. }
  14321. domUtils.remove(li);
  14322. if (!parentList.firstChild) {
  14323. domUtils.remove(parentList);
  14324. }
  14325. range.setStart(p, 0).setCursor();
  14326. }
  14327. preventAndSave();
  14328. return;
  14329. }
  14330. } else {
  14331. var tmpRange = range.cloneRange(),
  14332. bk = tmpRange.collapse(false).createBookmark();
  14333. range.deleteContents();
  14334. tmpRange.moveToBookmark(bk);
  14335. var li = domUtils.findParentByTagName(tmpRange.startContainer, 'li', true);
  14336. clearEmptySibling(li);
  14337. tmpRange.select();
  14338. preventAndSave();
  14339. return;
  14340. }
  14341. }
  14342. li = domUtils.findParentByTagName(range.startContainer, 'li', true);
  14343. if (li) {
  14344. if (domUtils.isEmptyBlock(li)) {
  14345. bk = range.createBookmark();
  14346. var parentList = li.parentNode;
  14347. if (li !== parentList.lastChild) {
  14348. domUtils.breakParent(li, parentList);
  14349. clearEmptySibling(li);
  14350. } else {
  14351. parentList.parentNode.insertBefore(li, parentList.nextSibling);
  14352. if (domUtils.isEmptyNode(parentList)) {
  14353. domUtils.remove(parentList);
  14354. }
  14355. }
  14356. //嵌套不处理
  14357. if (!dtd.$list[li.parentNode.tagName]) {
  14358. if (!domUtils.isBlockElm(li.firstChild)) {
  14359. p = me.document.createElement('p');
  14360. li.parentNode.insertBefore(p, li);
  14361. while (li.firstChild) {
  14362. p.appendChild(li.firstChild);
  14363. }
  14364. domUtils.remove(li);
  14365. } else {
  14366. domUtils.remove(li, true);
  14367. }
  14368. }
  14369. range.moveToBookmark(bk).select();
  14370. } else {
  14371. var first = li.firstChild;
  14372. if (!first || !domUtils.isBlockElm(first)) {
  14373. var p = me.document.createElement('p');
  14374. !li.firstChild && domUtils.fillNode(me.document, p);
  14375. while (li.firstChild) {
  14376. p.appendChild(li.firstChild);
  14377. }
  14378. li.appendChild(p);
  14379. first = p;
  14380. }
  14381. var span = me.document.createElement('span');
  14382. range.insertNode(span);
  14383. domUtils.breakParent(span, li);
  14384. var nextLi = span.nextSibling;
  14385. first = nextLi.firstChild;
  14386. if (!first) {
  14387. p = me.document.createElement('p');
  14388. domUtils.fillNode(me.document, p);
  14389. nextLi.appendChild(p);
  14390. first = p;
  14391. }
  14392. if (domUtils.isEmptyNode(first)) {
  14393. first.innerHTML = '';
  14394. domUtils.fillNode(me.document, first);
  14395. }
  14396. range.setStart(first, 0).collapse(true).shrinkBoundary().select();
  14397. domUtils.remove(span);
  14398. var pre = nextLi.previousSibling;
  14399. if (pre && domUtils.isEmptyBlock(pre)) {
  14400. pre.innerHTML = '<p></p>';
  14401. domUtils.fillNode(me.document, pre.firstChild);
  14402. }
  14403. }
  14404. // }
  14405. preventAndSave();
  14406. }
  14407. }
  14408. }
  14409. if (keyCode == 8) {
  14410. //修中ie中li下的问题
  14411. range = me.selection.getRange();
  14412. if (range.collapsed && domUtils.isStartInblock(range)) {
  14413. tmpRange = range.cloneRange().trimBoundary();
  14414. li = domUtils.findParentByTagName(range.startContainer, 'li', true);
  14415. //要在li的最左边,才能处理
  14416. if (li && domUtils.isStartInblock(tmpRange)) {
  14417. start = domUtils.findParentByTagName(range.startContainer, 'p', true);
  14418. if (start && start !== li.firstChild) {
  14419. var parentList = domUtils.findParentByTagName(start,['ol','ul']);
  14420. domUtils.breakParent(start,parentList);
  14421. clearEmptySibling(start);
  14422. me.fireEvent('contentchange');
  14423. range.setStart(start,0).setCursor(false,true);
  14424. me.fireEvent('saveScene');
  14425. domUtils.preventDefault(evt);
  14426. return;
  14427. }
  14428. if (li && (pre = li.previousSibling)) {
  14429. if (keyCode == 46 && li.childNodes.length) {
  14430. return;
  14431. }
  14432. //有可能上边的兄弟节点是个2级菜单,要追加到2级菜单的最后的li
  14433. if (dtd.$list[pre.tagName]) {
  14434. pre = pre.lastChild;
  14435. }
  14436. me.undoManger && me.undoManger.save();
  14437. first = li.firstChild;
  14438. if (domUtils.isBlockElm(first)) {
  14439. if (domUtils.isEmptyNode(first)) {
  14440. // range.setEnd(pre, pre.childNodes.length).shrinkBoundary().collapse().select(true);
  14441. pre.appendChild(first);
  14442. range.setStart(first, 0).setCursor(false, true);
  14443. //first不是唯一的节点
  14444. while (li.firstChild) {
  14445. pre.appendChild(li.firstChild);
  14446. }
  14447. } else {
  14448. span = me.document.createElement('span');
  14449. range.insertNode(span);
  14450. //判断pre是否是空的节点,如果是<p><br/></p>类型的空节点,干掉p标签防止它占位
  14451. if (domUtils.isEmptyBlock(pre)) {
  14452. pre.innerHTML = '';
  14453. }
  14454. domUtils.moveChild(li, pre);
  14455. range.setStartBefore(span).collapse(true).select(true);
  14456. domUtils.remove(span);
  14457. }
  14458. } else {
  14459. if (domUtils.isEmptyNode(li)) {
  14460. var p = me.document.createElement('p');
  14461. pre.appendChild(p);
  14462. range.setStart(p, 0).setCursor();
  14463. // range.setEnd(pre, pre.childNodes.length).shrinkBoundary().collapse().select(true);
  14464. } else {
  14465. range.setEnd(pre, pre.childNodes.length).collapse().select(true);
  14466. while (li.firstChild) {
  14467. pre.appendChild(li.firstChild);
  14468. }
  14469. }
  14470. }
  14471. domUtils.remove(li);
  14472. me.fireEvent('contentchange');
  14473. me.fireEvent('saveScene');
  14474. domUtils.preventDefault(evt);
  14475. return;
  14476. }
  14477. //trace:980
  14478. if (li && !li.previousSibling) {
  14479. var parentList = li.parentNode;
  14480. var bk = range.createBookmark();
  14481. if(domUtils.isTagNode(parentList.parentNode,'ol ul')){
  14482. parentList.parentNode.insertBefore(li,parentList);
  14483. if(domUtils.isEmptyNode(parentList)){
  14484. domUtils.remove(parentList)
  14485. }
  14486. }else{
  14487. while(li.firstChild){
  14488. parentList.parentNode.insertBefore(li.firstChild,parentList);
  14489. }
  14490. domUtils.remove(li);
  14491. if(domUtils.isEmptyNode(parentList)){
  14492. domUtils.remove(parentList)
  14493. }
  14494. }
  14495. range.moveToBookmark(bk).setCursor(false,true);
  14496. me.fireEvent('contentchange');
  14497. me.fireEvent('saveScene');
  14498. domUtils.preventDefault(evt);
  14499. return;
  14500. }
  14501. }
  14502. }
  14503. }
  14504. });
  14505. me.addListener('keyup',function(type, evt){
  14506. var keyCode = evt.keyCode || evt.which;
  14507. if (keyCode == 8) {
  14508. var rng = me.selection.getRange(),list;
  14509. if(list = domUtils.findParentByTagName(rng.startContainer,['ol', 'ul'],true)){
  14510. adjustList(list,list.tagName.toLowerCase(),getStyle(list)||domUtils.getComputedStyle(list,'list-style-type'),true)
  14511. }
  14512. }
  14513. });
  14514. //处理tab键
  14515. me.addListener('tabkeydown',function(){
  14516. var range = me.selection.getRange();
  14517. //控制级数
  14518. function checkLevel(li){
  14519. if(me.options.maxListLevel != -1){
  14520. var level = li.parentNode,levelNum = 0;
  14521. while(/[ou]l/i.test(level.tagName)){
  14522. levelNum++;
  14523. level = level.parentNode;
  14524. }
  14525. if(levelNum >= me.options.maxListLevel){
  14526. return true;
  14527. }
  14528. }
  14529. }
  14530. //只以开始为准
  14531. //todo 后续改进
  14532. var li = domUtils.findParentByTagName(range.startContainer, 'li', true);
  14533. if(li){
  14534. var bk;
  14535. if(range.collapsed){
  14536. if(checkLevel(li))
  14537. return true;
  14538. var parentLi = li.parentNode,
  14539. list = me.document.createElement(parentLi.tagName),
  14540. index = utils.indexOf(listStyle[list.tagName], getStyle(parentLi)||domUtils.getComputedStyle(parentLi, 'list-style-type'));
  14541. index = index + 1 == listStyle[list.tagName].length ? 0 : index + 1;
  14542. var currentStyle = listStyle[list.tagName][index];
  14543. setListStyle(list,currentStyle);
  14544. if(domUtils.isStartInblock(range)){
  14545. me.fireEvent('saveScene');
  14546. bk = range.createBookmark();
  14547. parentLi.insertBefore(list, li);
  14548. list.appendChild(li);
  14549. adjustList(list,list.tagName.toLowerCase(),currentStyle);
  14550. me.fireEvent('contentchange');
  14551. range.moveToBookmark(bk).select(true);
  14552. return true;
  14553. }
  14554. }else{
  14555. me.fireEvent('saveScene');
  14556. bk = range.createBookmark();
  14557. for(var i= 0,closeList,parents = domUtils.findParents(li),ci;ci=parents[i++];){
  14558. if(domUtils.isTagNode(ci,'ol ul')){
  14559. closeList = ci;
  14560. break;
  14561. }
  14562. }
  14563. var current = li;
  14564. if(bk.end){
  14565. while(current && !(domUtils.getPosition(current, bk.end) & domUtils.POSITION_FOLLOWING)){
  14566. if(checkLevel(current)){
  14567. current = domUtils.getNextDomNode(current,false,null,function(node){return node !== closeList});
  14568. continue;
  14569. }
  14570. var parentLi = current.parentNode,
  14571. list = me.document.createElement(parentLi.tagName),
  14572. index = utils.indexOf(listStyle[list.tagName], getStyle(parentLi)||domUtils.getComputedStyle(parentLi, 'list-style-type'));
  14573. var currentIndex = index + 1 == listStyle[list.tagName].length ? 0 : index + 1;
  14574. var currentStyle = listStyle[list.tagName][currentIndex];
  14575. setListStyle(list,currentStyle);
  14576. parentLi.insertBefore(list, current);
  14577. while(current && !(domUtils.getPosition(current, bk.end) & domUtils.POSITION_FOLLOWING)){
  14578. li = current.nextSibling;
  14579. list.appendChild(current);
  14580. if(!li || domUtils.isTagNode(li,'ol ul')){
  14581. if(li){
  14582. while(li = li.firstChild){
  14583. if(li.tagName == 'LI'){
  14584. break;
  14585. }
  14586. }
  14587. }else{
  14588. li = domUtils.getNextDomNode(current,false,null,function(node){return node !== closeList});
  14589. }
  14590. break;
  14591. }
  14592. current = li;
  14593. }
  14594. adjustList(list,list.tagName.toLowerCase(),currentStyle);
  14595. current = li;
  14596. }
  14597. }
  14598. me.fireEvent('contentchange');
  14599. range.moveToBookmark(bk).select();
  14600. return true;
  14601. }
  14602. }
  14603. });
  14604. function getLi(start){
  14605. while(start && !domUtils.isBody(start)){
  14606. if(start.nodeName == 'TABLE'){
  14607. return null;
  14608. }
  14609. if(start.nodeName == 'LI'){
  14610. return start
  14611. }
  14612. start = start.parentNode;
  14613. }
  14614. }
  14615. /**
  14616. * 有序列表,与“insertunorderedlist”命令互斥
  14617. * @command insertorderedlist
  14618. * @method execCommand
  14619. * @param { String } command 命令字符串
  14620. * @param { String } style 插入的有序列表类型,值为:decimal,lower-alpha,lower-roman,upper-alpha,upper-roman,cn,cn1,cn2,num,num1,num2
  14621. * @example
  14622. * ```javascript
  14623. * editor.execCommand( 'insertorderedlist','decimal');
  14624. * ```
  14625. */
  14626. /**
  14627. * 查询当前选区内容是否有序列表
  14628. * @command insertorderedlist
  14629. * @method queryCommandState
  14630. * @param { String } cmd 命令字符串
  14631. * @return { int } 如果当前选区是有序列表返回1,否则返回0
  14632. * @example
  14633. * ```javascript
  14634. * editor.queryCommandState( 'insertorderedlist' );
  14635. * ```
  14636. */
  14637. /**
  14638. * 查询当前选区内容是否有序列表
  14639. * @command insertorderedlist
  14640. * @method queryCommandValue
  14641. * @param { String } cmd 命令字符串
  14642. * @return { String } 返回当前有序列表的类型,值为null或decimal,lower-alpha,lower-roman,upper-alpha,upper-roman,cn,cn1,cn2,num,num1,num2
  14643. * @example
  14644. * ```javascript
  14645. * editor.queryCommandValue( 'insertorderedlist' );
  14646. * ```
  14647. */
  14648. /**
  14649. * 无序列表,与“insertorderedlist”命令互斥
  14650. * @command insertunorderedlist
  14651. * @method execCommand
  14652. * @param { String } command 命令字符串
  14653. * @param { String } style 插入的无序列表类型,值为:circle,disc,square,dash,dot
  14654. * @example
  14655. * ```javascript
  14656. * editor.execCommand( 'insertunorderedlist','circle');
  14657. * ```
  14658. */
  14659. /**
  14660. * 查询当前是否有word文档粘贴进来的图片
  14661. * @command insertunorderedlist
  14662. * @method insertunorderedlist
  14663. * @param { String } command 命令字符串
  14664. * @return { int } 如果当前选区是无序列表返回1,否则返回0
  14665. * @example
  14666. * ```javascript
  14667. * editor.queryCommandState( 'insertunorderedlist' );
  14668. * ```
  14669. */
  14670. /**
  14671. * 查询当前选区内容是否有序列表
  14672. * @command insertunorderedlist
  14673. * @method queryCommandValue
  14674. * @param { String } command 命令字符串
  14675. * @return { String } 返回当前无序列表的类型,值为null或circle,disc,square,dash,dot
  14676. * @example
  14677. * ```javascript
  14678. * editor.queryCommandValue( 'insertunorderedlist' );
  14679. * ```
  14680. */
  14681. me.commands['insertorderedlist'] =
  14682. me.commands['insertunorderedlist'] = {
  14683. execCommand:function (command, style) {
  14684. if (!style) {
  14685. style = command.toLowerCase() == 'insertorderedlist' ? 'decimal' : 'disc';
  14686. }
  14687. var me = this,
  14688. range = this.selection.getRange(),
  14689. filterFn = function (node) {
  14690. return node.nodeType == 1 ? node.tagName.toLowerCase() != 'br' : !domUtils.isWhitespace(node);
  14691. },
  14692. tag = command.toLowerCase() == 'insertorderedlist' ? 'ol' : 'ul',
  14693. frag = me.document.createDocumentFragment();
  14694. //去掉是因为会出现选到末尾,导致adjustmentBoundary缩到ol/ul的位置
  14695. //range.shrinkBoundary();//.adjustmentBoundary();
  14696. range.adjustmentBoundary().shrinkBoundary();
  14697. var bko = range.createBookmark(true),
  14698. start = getLi(me.document.getElementById(bko.start)),
  14699. modifyStart = 0,
  14700. end = getLi(me.document.getElementById(bko.end)),
  14701. modifyEnd = 0,
  14702. startParent, endParent,
  14703. list, tmp;
  14704. if (start || end) {
  14705. start && (startParent = start.parentNode);
  14706. if (!bko.end) {
  14707. end = start;
  14708. }
  14709. end && (endParent = end.parentNode);
  14710. if (startParent === endParent) {
  14711. while (start !== end) {
  14712. tmp = start;
  14713. start = start.nextSibling;
  14714. if (!domUtils.isBlockElm(tmp.firstChild)) {
  14715. var p = me.document.createElement('p');
  14716. while (tmp.firstChild) {
  14717. p.appendChild(tmp.firstChild);
  14718. }
  14719. tmp.appendChild(p);
  14720. }
  14721. frag.appendChild(tmp);
  14722. }
  14723. tmp = me.document.createElement('span');
  14724. startParent.insertBefore(tmp, end);
  14725. if (!domUtils.isBlockElm(end.firstChild)) {
  14726. p = me.document.createElement('p');
  14727. while (end.firstChild) {
  14728. p.appendChild(end.firstChild);
  14729. }
  14730. end.appendChild(p);
  14731. }
  14732. frag.appendChild(end);
  14733. domUtils.breakParent(tmp, startParent);
  14734. if (domUtils.isEmptyNode(tmp.previousSibling)) {
  14735. domUtils.remove(tmp.previousSibling);
  14736. }
  14737. if (domUtils.isEmptyNode(tmp.nextSibling)) {
  14738. domUtils.remove(tmp.nextSibling)
  14739. }
  14740. var nodeStyle = getStyle(startParent) || domUtils.getComputedStyle(startParent, 'list-style-type') || (command.toLowerCase() == 'insertorderedlist' ? 'decimal' : 'disc');
  14741. if (startParent.tagName.toLowerCase() == tag && nodeStyle == style) {
  14742. for (var i = 0, ci, tmpFrag = me.document.createDocumentFragment(); ci = frag.firstChild;) {
  14743. if(domUtils.isTagNode(ci,'ol ul')){
  14744. // 删除时,子列表不处理
  14745. // utils.each(domUtils.getElementsByTagName(ci,'li'),function(li){
  14746. // while(li.firstChild){
  14747. // tmpFrag.appendChild(li.firstChild);
  14748. // }
  14749. //
  14750. // });
  14751. tmpFrag.appendChild(ci);
  14752. }else{
  14753. while (ci.firstChild) {
  14754. tmpFrag.appendChild(ci.firstChild);
  14755. domUtils.remove(ci);
  14756. }
  14757. }
  14758. }
  14759. tmp.parentNode.insertBefore(tmpFrag, tmp);
  14760. } else {
  14761. list = me.document.createElement(tag);
  14762. setListStyle(list,style);
  14763. list.appendChild(frag);
  14764. tmp.parentNode.insertBefore(list, tmp);
  14765. }
  14766. domUtils.remove(tmp);
  14767. list && adjustList(list, tag, style);
  14768. range.moveToBookmark(bko).select();
  14769. return;
  14770. }
  14771. //开始
  14772. if (start) {
  14773. while (start) {
  14774. tmp = start.nextSibling;
  14775. if (domUtils.isTagNode(start, 'ol ul')) {
  14776. frag.appendChild(start);
  14777. } else {
  14778. var tmpfrag = me.document.createDocumentFragment(),
  14779. hasBlock = 0;
  14780. while (start.firstChild) {
  14781. if (domUtils.isBlockElm(start.firstChild)) {
  14782. hasBlock = 1;
  14783. }
  14784. tmpfrag.appendChild(start.firstChild);
  14785. }
  14786. if (!hasBlock) {
  14787. var tmpP = me.document.createElement('p');
  14788. tmpP.appendChild(tmpfrag);
  14789. frag.appendChild(tmpP);
  14790. } else {
  14791. frag.appendChild(tmpfrag);
  14792. }
  14793. domUtils.remove(start);
  14794. }
  14795. start = tmp;
  14796. }
  14797. startParent.parentNode.insertBefore(frag, startParent.nextSibling);
  14798. if (domUtils.isEmptyNode(startParent)) {
  14799. range.setStartBefore(startParent);
  14800. domUtils.remove(startParent);
  14801. } else {
  14802. range.setStartAfter(startParent);
  14803. }
  14804. modifyStart = 1;
  14805. }
  14806. if (end && domUtils.inDoc(endParent, me.document)) {
  14807. //结束
  14808. start = endParent.firstChild;
  14809. while (start && start !== end) {
  14810. tmp = start.nextSibling;
  14811. if (domUtils.isTagNode(start, 'ol ul')) {
  14812. frag.appendChild(start);
  14813. } else {
  14814. tmpfrag = me.document.createDocumentFragment();
  14815. hasBlock = 0;
  14816. while (start.firstChild) {
  14817. if (domUtils.isBlockElm(start.firstChild)) {
  14818. hasBlock = 1;
  14819. }
  14820. tmpfrag.appendChild(start.firstChild);
  14821. }
  14822. if (!hasBlock) {
  14823. tmpP = me.document.createElement('p');
  14824. tmpP.appendChild(tmpfrag);
  14825. frag.appendChild(tmpP);
  14826. } else {
  14827. frag.appendChild(tmpfrag);
  14828. }
  14829. domUtils.remove(start);
  14830. }
  14831. start = tmp;
  14832. }
  14833. var tmpDiv = domUtils.createElement(me.document, 'div', {
  14834. 'tmpDiv':1
  14835. });
  14836. domUtils.moveChild(end, tmpDiv);
  14837. frag.appendChild(tmpDiv);
  14838. domUtils.remove(end);
  14839. endParent.parentNode.insertBefore(frag, endParent);
  14840. range.setEndBefore(endParent);
  14841. if (domUtils.isEmptyNode(endParent)) {
  14842. domUtils.remove(endParent);
  14843. }
  14844. modifyEnd = 1;
  14845. }
  14846. }
  14847. if (!modifyStart) {
  14848. range.setStartBefore(me.document.getElementById(bko.start));
  14849. }
  14850. if (bko.end && !modifyEnd) {
  14851. range.setEndAfter(me.document.getElementById(bko.end));
  14852. }
  14853. range.enlarge(true, function (node) {
  14854. return notExchange[node.tagName];
  14855. });
  14856. frag = me.document.createDocumentFragment();
  14857. var bk = range.createBookmark(),
  14858. current = domUtils.getNextDomNode(bk.start, false, filterFn),
  14859. tmpRange = range.cloneRange(),
  14860. tmpNode,
  14861. block = domUtils.isBlockElm;
  14862. while (current && current !== bk.end && (domUtils.getPosition(current, bk.end) & domUtils.POSITION_PRECEDING)) {
  14863. if (current.nodeType == 3 || dtd.li[current.tagName]) {
  14864. if (current.nodeType == 1 && dtd.$list[current.tagName]) {
  14865. while (current.firstChild) {
  14866. frag.appendChild(current.firstChild);
  14867. }
  14868. tmpNode = domUtils.getNextDomNode(current, false, filterFn);
  14869. domUtils.remove(current);
  14870. current = tmpNode;
  14871. continue;
  14872. }
  14873. tmpNode = current;
  14874. tmpRange.setStartBefore(current);
  14875. while (current && current !== bk.end && (!block(current) || domUtils.isBookmarkNode(current) )) {
  14876. tmpNode = current;
  14877. current = domUtils.getNextDomNode(current, false, null, function (node) {
  14878. return !notExchange[node.tagName];
  14879. });
  14880. }
  14881. if (current && block(current)) {
  14882. tmp = domUtils.getNextDomNode(tmpNode, false, filterFn);
  14883. if (tmp && domUtils.isBookmarkNode(tmp)) {
  14884. current = domUtils.getNextDomNode(tmp, false, filterFn);
  14885. tmpNode = tmp;
  14886. }
  14887. }
  14888. tmpRange.setEndAfter(tmpNode);
  14889. current = domUtils.getNextDomNode(tmpNode, false, filterFn);
  14890. var li = range.document.createElement('li');
  14891. li.appendChild(tmpRange.extractContents());
  14892. if(domUtils.isEmptyNode(li)){
  14893. var tmpNode = range.document.createElement('p');
  14894. while(li.firstChild){
  14895. tmpNode.appendChild(li.firstChild)
  14896. }
  14897. li.appendChild(tmpNode);
  14898. }
  14899. frag.appendChild(li);
  14900. } else {
  14901. current = domUtils.getNextDomNode(current, true, filterFn);
  14902. }
  14903. }
  14904. range.moveToBookmark(bk).collapse(true);
  14905. list = me.document.createElement(tag);
  14906. setListStyle(list,style);
  14907. list.appendChild(frag);
  14908. range.insertNode(list);
  14909. //当前list上下看能否合并
  14910. adjustList(list, tag, style);
  14911. //去掉冗余的tmpDiv
  14912. for (var i = 0, ci, tmpDivs = domUtils.getElementsByTagName(list, 'div'); ci = tmpDivs[i++];) {
  14913. if (ci.getAttribute('tmpDiv')) {
  14914. domUtils.remove(ci, true)
  14915. }
  14916. }
  14917. range.moveToBookmark(bko).select();
  14918. },
  14919. queryCommandState:function (command) {
  14920. var tag = command.toLowerCase() == 'insertorderedlist' ? 'ol' : 'ul';
  14921. var path = this.selection.getStartElementPath();
  14922. for(var i= 0,ci;ci = path[i++];){
  14923. if(ci.nodeName == 'TABLE'){
  14924. return 0
  14925. }
  14926. if(tag == ci.nodeName.toLowerCase()){
  14927. return 1
  14928. };
  14929. }
  14930. return 0;
  14931. },
  14932. queryCommandValue:function (command) {
  14933. var tag = command.toLowerCase() == 'insertorderedlist' ? 'ol' : 'ul';
  14934. var path = this.selection.getStartElementPath(),
  14935. node;
  14936. for(var i= 0,ci;ci = path[i++];){
  14937. if(ci.nodeName == 'TABLE'){
  14938. node = null;
  14939. break;
  14940. }
  14941. if(tag == ci.nodeName.toLowerCase()){
  14942. node = ci;
  14943. break;
  14944. };
  14945. }
  14946. return node ? getStyle(node) || domUtils.getComputedStyle(node, 'list-style-type') : null;
  14947. }
  14948. };
  14949. };
  14950. // plugins/source.js
  14951. /**
  14952. * 源码编辑插件
  14953. * @file
  14954. * @since 1.2.6.1
  14955. */
  14956. (function (){
  14957. var sourceEditors = {
  14958. textarea: function (editor, holder){
  14959. var textarea = holder.ownerDocument.createElement('textarea');
  14960. textarea.style.cssText = 'position:absolute;resize:none;width:100%;height:100%;border:0;padding:0;margin:0;overflow-y:auto;';
  14961. // todo: IE下只有onresize属性可用... 很纠结
  14962. if (browser.ie && browser.version < 8) {
  14963. textarea.style.width = holder.offsetWidth + 'px';
  14964. textarea.style.height = holder.offsetHeight + 'px';
  14965. holder.onresize = function (){
  14966. textarea.style.width = holder.offsetWidth + 'px';
  14967. textarea.style.height = holder.offsetHeight + 'px';
  14968. };
  14969. }
  14970. holder.appendChild(textarea);
  14971. return {
  14972. setContent: function (content){
  14973. textarea.value = content;
  14974. },
  14975. getContent: function (){
  14976. return textarea.value;
  14977. },
  14978. select: function (){
  14979. var range;
  14980. if (browser.ie) {
  14981. range = textarea.createTextRange();
  14982. range.collapse(true);
  14983. range.select();
  14984. } else {
  14985. //todo: chrome下无法设置焦点
  14986. textarea.setSelectionRange(0, 0);
  14987. textarea.focus();
  14988. }
  14989. },
  14990. dispose: function (){
  14991. holder.removeChild(textarea);
  14992. // todo
  14993. holder.onresize = null;
  14994. textarea = null;
  14995. holder = null;
  14996. }
  14997. };
  14998. },
  14999. codemirror: function (editor, holder){
  15000. var codeEditor = window.CodeMirror(holder, {
  15001. mode: "text/html",
  15002. tabMode: "indent",
  15003. lineNumbers: true,
  15004. lineWrapping:true
  15005. });
  15006. var dom = codeEditor.getWrapperElement();
  15007. dom.style.cssText = 'position:absolute;left:0;top:0;width:100%;height:100%;font-family:consolas,"Courier new",monospace;font-size:13px;';
  15008. codeEditor.getScrollerElement().style.cssText = 'position:absolute;left:0;top:0;width:100%;height:100%;';
  15009. codeEditor.refresh();
  15010. return {
  15011. getCodeMirror:function(){
  15012. return codeEditor;
  15013. },
  15014. setContent: function (content){
  15015. codeEditor.setValue(content);
  15016. },
  15017. getContent: function (){
  15018. return codeEditor.getValue();
  15019. },
  15020. select: function (){
  15021. codeEditor.focus();
  15022. },
  15023. dispose: function (){
  15024. holder.removeChild(dom);
  15025. dom = null;
  15026. codeEditor = null;
  15027. }
  15028. };
  15029. }
  15030. };
  15031. UE.plugins['source'] = function (){
  15032. var me = this;
  15033. var opt = this.options;
  15034. var sourceMode = false;
  15035. var sourceEditor;
  15036. var orgSetContent;
  15037. opt.sourceEditor = browser.ie ? 'textarea' : (opt.sourceEditor || 'codemirror');
  15038. me.setOpt({
  15039. sourceEditorFirst:false
  15040. });
  15041. function createSourceEditor(holder){
  15042. return sourceEditors[opt.sourceEditor == 'codemirror' && window.CodeMirror ? 'codemirror' : 'textarea'](me, holder);
  15043. }
  15044. var bakCssText;
  15045. //解决在源码模式下getContent不能得到最新的内容问题
  15046. var oldGetContent,
  15047. bakAddress;
  15048. /**
  15049. * 切换源码模式和编辑模式
  15050. * @command source
  15051. * @method execCommand
  15052. * @param { String } cmd 命令字符串
  15053. * @example
  15054. * ```javascript
  15055. * editor.execCommand( 'source');
  15056. * ```
  15057. */
  15058. /**
  15059. * 查询当前编辑区域的状态是源码模式还是可视化模式
  15060. * @command source
  15061. * @method queryCommandState
  15062. * @param { String } cmd 命令字符串
  15063. * @return { int } 如果当前是源码编辑模式,返回1,否则返回0
  15064. * @example
  15065. * ```javascript
  15066. * editor.queryCommandState( 'source' );
  15067. * ```
  15068. */
  15069. me.commands['source'] = {
  15070. execCommand: function (){
  15071. sourceMode = !sourceMode;
  15072. if (sourceMode) {
  15073. bakAddress = me.selection.getRange().createAddress(false,true);
  15074. me.undoManger && me.undoManger.save(true);
  15075. if(browser.gecko){
  15076. me.body.contentEditable = false;
  15077. }
  15078. bakCssText = me.iframe.style.cssText;
  15079. me.iframe.style.cssText += 'position:absolute;left:-32768px;top:-32768px;';
  15080. me.fireEvent('beforegetcontent');
  15081. var root = UE.htmlparser(me.body.innerHTML);
  15082. me.filterOutputRule(root);
  15083. root.traversal(function (node) {
  15084. if (node.type == 'element') {
  15085. switch (node.tagName) {
  15086. case 'td':
  15087. case 'th':
  15088. case 'caption':
  15089. if(node.children && node.children.length == 1){
  15090. if(node.firstChild().tagName == 'br' ){
  15091. node.removeChild(node.firstChild())
  15092. }
  15093. };
  15094. break;
  15095. case 'pre':
  15096. node.innerText(node.innerText().replace(/&nbsp;/g,' '))
  15097. }
  15098. }
  15099. });
  15100. me.fireEvent('aftergetcontent');
  15101. var content = root.toHtml(true);
  15102. sourceEditor = createSourceEditor(me.iframe.parentNode);
  15103. sourceEditor.setContent(content);
  15104. orgSetContent = me.setContent;
  15105. me.setContent = function(html){
  15106. //这里暂时不触发事件,防止报错
  15107. var root = UE.htmlparser(html);
  15108. me.filterInputRule(root);
  15109. html = root.toHtml();
  15110. sourceEditor.setContent(html);
  15111. };
  15112. setTimeout(function (){
  15113. sourceEditor.select();
  15114. me.addListener('fullscreenchanged', function(){
  15115. try{
  15116. sourceEditor.getCodeMirror().refresh()
  15117. }catch(e){}
  15118. });
  15119. });
  15120. //重置getContent,源码模式下取值也能是最新的数据
  15121. oldGetContent = me.getContent;
  15122. me.getContent = function (){
  15123. return sourceEditor.getContent() || '<p>' + (browser.ie ? '' : '<br/>')+'</p>';
  15124. };
  15125. } else {
  15126. me.iframe.style.cssText = bakCssText;
  15127. var cont = sourceEditor.getContent() || '<p>' + (browser.ie ? '' : '<br/>')+'</p>';
  15128. //处理掉block节点前后的空格,有可能会误命中,暂时不考虑
  15129. cont = cont.replace(new RegExp('[\\r\\t\\n ]*<\/?(\\w+)\\s*(?:[^>]*)>','g'), function(a,b){
  15130. if(b && !dtd.$inlineWithA[b.toLowerCase()]){
  15131. return a.replace(/(^[\n\r\t ]*)|([\n\r\t ]*$)/g,'');
  15132. }
  15133. return a.replace(/(^[\n\r\t]*)|([\n\r\t]*$)/g,'')
  15134. });
  15135. me.setContent = orgSetContent;
  15136. me.setContent(cont);
  15137. sourceEditor.dispose();
  15138. sourceEditor = null;
  15139. //还原getContent方法
  15140. me.getContent = oldGetContent;
  15141. var first = me.body.firstChild;
  15142. //trace:1106 都删除空了,下边会报错,所以补充一个p占位
  15143. if(!first){
  15144. me.body.innerHTML = '<p>'+(browser.ie?'':'<br/>')+'</p>';
  15145. first = me.body.firstChild;
  15146. }
  15147. //要在ifm为显示时ff才能取到selection,否则报错
  15148. //这里不能比较位置了
  15149. me.undoManger && me.undoManger.save(true);
  15150. if(browser.gecko){
  15151. var input = document.createElement('input');
  15152. input.style.cssText = 'position:absolute;left:0;top:-32768px';
  15153. document.body.appendChild(input);
  15154. me.body.contentEditable = false;
  15155. setTimeout(function(){
  15156. domUtils.setViewportOffset(input, { left: -32768, top: 0 });
  15157. input.focus();
  15158. setTimeout(function(){
  15159. me.body.contentEditable = true;
  15160. me.selection.getRange().moveToAddress(bakAddress).select(true);
  15161. domUtils.remove(input);
  15162. });
  15163. });
  15164. }else{
  15165. //ie下有可能报错,比如在代码顶头的情况
  15166. try{
  15167. me.selection.getRange().moveToAddress(bakAddress).select(true);
  15168. }catch(e){}
  15169. }
  15170. }
  15171. this.fireEvent('sourcemodechanged', sourceMode);
  15172. },
  15173. queryCommandState: function (){
  15174. return sourceMode|0;
  15175. },
  15176. notNeedUndo : 1
  15177. };
  15178. var oldQueryCommandState = me.queryCommandState;
  15179. me.queryCommandState = function (cmdName){
  15180. cmdName = cmdName.toLowerCase();
  15181. if (sourceMode) {
  15182. //源码模式下可以开启的命令
  15183. return cmdName in {
  15184. 'source' : 1,
  15185. 'fullscreen' : 1
  15186. } ? 1 : -1
  15187. }
  15188. return oldQueryCommandState.apply(this, arguments);
  15189. };
  15190. if(opt.sourceEditor == "codemirror"){
  15191. me.addListener("ready",function(){
  15192. utils.loadFile(document,{
  15193. src : opt.codeMirrorJsUrl || opt.UEDITOR_HOME_URL + "third-party/codemirror/codemirror.js",
  15194. tag : "script",
  15195. type : "text/javascript",
  15196. defer : "defer"
  15197. },function(){
  15198. if(opt.sourceEditorFirst){
  15199. setTimeout(function(){
  15200. me.execCommand("source");
  15201. },0);
  15202. }
  15203. });
  15204. utils.loadFile(document,{
  15205. tag : "link",
  15206. rel : "stylesheet",
  15207. type : "text/css",
  15208. href : opt.codeMirrorCssUrl || opt.UEDITOR_HOME_URL + "third-party/codemirror/codemirror.css"
  15209. });
  15210. });
  15211. }
  15212. };
  15213. })();
  15214. // plugins/enterkey.js
  15215. ///import core
  15216. ///import plugins/undo.js
  15217. ///commands 设置回车标签p或br
  15218. ///commandsName EnterKey
  15219. ///commandsTitle 设置回车标签p或br
  15220. /**
  15221. * @description 处理回车
  15222. * @author zhanyi
  15223. */
  15224. UE.plugins['enterkey'] = function() {
  15225. var hTag,
  15226. me = this,
  15227. tag = me.options.enterTag;
  15228. me.addListener('keyup', function(type, evt) {
  15229. var keyCode = evt.keyCode || evt.which;
  15230. if (keyCode == 13) {
  15231. var range = me.selection.getRange(),
  15232. start = range.startContainer,
  15233. doSave;
  15234. //修正在h1-h6里边回车后不能嵌套p的问题
  15235. if (!browser.ie) {
  15236. if (/h\d/i.test(hTag)) {
  15237. if (browser.gecko) {
  15238. var h = domUtils.findParentByTagName(start, [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6','blockquote','caption','table'], true);
  15239. if (!h) {
  15240. me.document.execCommand('formatBlock', false, '<p>');
  15241. doSave = 1;
  15242. }
  15243. } else {
  15244. //chrome remove div
  15245. if (start.nodeType == 1) {
  15246. var tmp = me.document.createTextNode(''),div;
  15247. range.insertNode(tmp);
  15248. div = domUtils.findParentByTagName(tmp, 'div', true);
  15249. if (div) {
  15250. var p = me.document.createElement('p');
  15251. while (div.firstChild) {
  15252. p.appendChild(div.firstChild);
  15253. }
  15254. div.parentNode.insertBefore(p, div);
  15255. domUtils.remove(div);
  15256. range.setStartBefore(tmp).setCursor();
  15257. doSave = 1;
  15258. }
  15259. domUtils.remove(tmp);
  15260. }
  15261. }
  15262. if (me.undoManger && doSave) {
  15263. me.undoManger.save();
  15264. }
  15265. }
  15266. //没有站位符,会出现多行的问题
  15267. browser.opera && range.select();
  15268. }else{
  15269. me.fireEvent('saveScene',true,true)
  15270. }
  15271. }
  15272. });
  15273. me.addListener('keydown', function(type, evt) {
  15274. var keyCode = evt.keyCode || evt.which;
  15275. if (keyCode == 13) {//回车
  15276. if(me.fireEvent('beforeenterkeydown')){
  15277. domUtils.preventDefault(evt);
  15278. return;
  15279. }
  15280. me.fireEvent('saveScene',true,true);
  15281. hTag = '';
  15282. var range = me.selection.getRange();
  15283. if (!range.collapsed) {
  15284. //跨td不能删
  15285. var start = range.startContainer,
  15286. end = range.endContainer,
  15287. startTd = domUtils.findParentByTagName(start, 'td', true),
  15288. endTd = domUtils.findParentByTagName(end, 'td', true);
  15289. if (startTd && endTd && startTd !== endTd || !startTd && endTd || startTd && !endTd) {
  15290. evt.preventDefault ? evt.preventDefault() : ( evt.returnValue = false);
  15291. return;
  15292. }
  15293. }
  15294. if (tag == 'p') {
  15295. if (!browser.ie) {
  15296. start = domUtils.findParentByTagName(range.startContainer, ['ol','ul','p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6','blockquote','caption'], true);
  15297. //opera下执行formatblock会在table的场景下有问题,回车在opera原生支持很好,所以暂时在opera去掉调用这个原生的command
  15298. //trace:2431
  15299. if (!start && !browser.opera) {
  15300. me.document.execCommand('formatBlock', false, '<p>');
  15301. if (browser.gecko) {
  15302. range = me.selection.getRange();
  15303. start = domUtils.findParentByTagName(range.startContainer, 'p', true);
  15304. start && domUtils.removeDirtyAttr(start);
  15305. }
  15306. } else {
  15307. hTag = start.tagName;
  15308. start.tagName.toLowerCase() == 'p' && browser.gecko && domUtils.removeDirtyAttr(start);
  15309. }
  15310. }
  15311. } else {
  15312. evt.preventDefault ? evt.preventDefault() : ( evt.returnValue = false);
  15313. if (!range.collapsed) {
  15314. range.deleteContents();
  15315. start = range.startContainer;
  15316. if (start.nodeType == 1 && (start = start.childNodes[range.startOffset])) {
  15317. while (start.nodeType == 1) {
  15318. if (dtd.$empty[start.tagName]) {
  15319. range.setStartBefore(start).setCursor();
  15320. if (me.undoManger) {
  15321. me.undoManger.save();
  15322. }
  15323. return false;
  15324. }
  15325. if (!start.firstChild) {
  15326. var br = range.document.createElement('br');
  15327. start.appendChild(br);
  15328. range.setStart(start, 0).setCursor();
  15329. if (me.undoManger) {
  15330. me.undoManger.save();
  15331. }
  15332. return false;
  15333. }
  15334. start = start.firstChild;
  15335. }
  15336. if (start === range.startContainer.childNodes[range.startOffset]) {
  15337. br = range.document.createElement('br');
  15338. range.insertNode(br).setCursor();
  15339. } else {
  15340. range.setStart(start, 0).setCursor();
  15341. }
  15342. } else {
  15343. br = range.document.createElement('br');
  15344. range.insertNode(br).setStartAfter(br).setCursor();
  15345. }
  15346. } else {
  15347. br = range.document.createElement('br');
  15348. range.insertNode(br);
  15349. var parent = br.parentNode;
  15350. if (parent.lastChild === br) {
  15351. br.parentNode.insertBefore(br.cloneNode(true), br);
  15352. range.setStartBefore(br);
  15353. } else {
  15354. range.setStartAfter(br);
  15355. }
  15356. range.setCursor();
  15357. }
  15358. }
  15359. }
  15360. });
  15361. };
  15362. // plugins/keystrokes.js
  15363. /* 处理特殊键的兼容性问题 */
  15364. UE.plugins['keystrokes'] = function() {
  15365. var me = this;
  15366. var collapsed = true;
  15367. me.addListener('keydown', function(type, evt) {
  15368. var keyCode = evt.keyCode || evt.which,
  15369. rng = me.selection.getRange();
  15370. //处理全选的情况
  15371. if(!rng.collapsed && !(evt.ctrlKey || evt.shiftKey || evt.altKey || evt.metaKey) && (keyCode >= 65 && keyCode <=90
  15372. || keyCode >= 48 && keyCode <= 57 ||
  15373. keyCode >= 96 && keyCode <= 111 || {
  15374. 13:1,
  15375. 8:1,
  15376. 46:1
  15377. }[keyCode])
  15378. ){
  15379. var tmpNode = rng.startContainer;
  15380. if(domUtils.isFillChar(tmpNode)){
  15381. rng.setStartBefore(tmpNode)
  15382. }
  15383. tmpNode = rng.endContainer;
  15384. if(domUtils.isFillChar(tmpNode)){
  15385. rng.setEndAfter(tmpNode)
  15386. }
  15387. rng.txtToElmBoundary();
  15388. //结束边界可能放到了br的前边,要把br包含进来
  15389. // x[xxx]<br/>
  15390. if(rng.endContainer && rng.endContainer.nodeType == 1){
  15391. tmpNode = rng.endContainer.childNodes[rng.endOffset];
  15392. if(tmpNode && domUtils.isBr(tmpNode)){
  15393. rng.setEndAfter(tmpNode);
  15394. }
  15395. }
  15396. if(rng.startOffset == 0){
  15397. tmpNode = rng.startContainer;
  15398. if(domUtils.isBoundaryNode(tmpNode,'firstChild') ){
  15399. tmpNode = rng.endContainer;
  15400. if(rng.endOffset == (tmpNode.nodeType == 3 ? tmpNode.nodeValue.length : tmpNode.childNodes.length) && domUtils.isBoundaryNode(tmpNode,'lastChild')){
  15401. me.fireEvent('saveScene');
  15402. me.body.innerHTML = '<p>'+(browser.ie ? '' : '<br/>')+'</p>';
  15403. rng.setStart(me.body.firstChild,0).setCursor(false,true);
  15404. me._selectionChange();
  15405. return;
  15406. }
  15407. }
  15408. }
  15409. }
  15410. //处理backspace
  15411. if (keyCode == keymap.Backspace) {
  15412. rng = me.selection.getRange();
  15413. collapsed = rng.collapsed;
  15414. if(me.fireEvent('delkeydown',evt)){
  15415. return;
  15416. }
  15417. var start,end;
  15418. //避免按两次删除才能生效的问题
  15419. if(rng.collapsed && rng.inFillChar()){
  15420. start = rng.startContainer;
  15421. if(domUtils.isFillChar(start)){
  15422. rng.setStartBefore(start).shrinkBoundary(true).collapse(true);
  15423. domUtils.remove(start)
  15424. }else{
  15425. start.nodeValue = start.nodeValue.replace(new RegExp('^' + domUtils.fillChar ),'');
  15426. rng.startOffset--;
  15427. rng.collapse(true).select(true)
  15428. }
  15429. }
  15430. //解决选中control元素不能删除的问题
  15431. if (start = rng.getClosedNode()) {
  15432. me.fireEvent('saveScene');
  15433. rng.setStartBefore(start);
  15434. domUtils.remove(start);
  15435. rng.setCursor();
  15436. me.fireEvent('saveScene');
  15437. domUtils.preventDefault(evt);
  15438. return;
  15439. }
  15440. //阻止在table上的删除
  15441. if (!browser.ie) {
  15442. start = domUtils.findParentByTagName(rng.startContainer, 'table', true);
  15443. end = domUtils.findParentByTagName(rng.endContainer, 'table', true);
  15444. if (start && !end || !start && end || start !== end) {
  15445. evt.preventDefault();
  15446. return;
  15447. }
  15448. }
  15449. }
  15450. //处理tab键的逻辑
  15451. if (keyCode == keymap.Tab) {
  15452. //不处理以下标签
  15453. var excludeTagNameForTabKey = {
  15454. 'ol' : 1,
  15455. 'ul' : 1,
  15456. 'table':1
  15457. };
  15458. //处理组件里的tab按下事件
  15459. if(me.fireEvent('tabkeydown',evt)){
  15460. domUtils.preventDefault(evt);
  15461. return;
  15462. }
  15463. var range = me.selection.getRange();
  15464. me.fireEvent('saveScene');
  15465. for (var i = 0,txt = '',tabSize = me.options.tabSize|| 4,tabNode = me.options.tabNode || '&nbsp;'; i < tabSize; i++) {
  15466. txt += tabNode;
  15467. }
  15468. var span = me.document.createElement('span');
  15469. span.innerHTML = txt + domUtils.fillChar;
  15470. if (range.collapsed) {
  15471. range.insertNode(span.cloneNode(true).firstChild).setCursor(true);
  15472. } else {
  15473. var filterFn = function(node) {
  15474. return domUtils.isBlockElm(node) && !excludeTagNameForTabKey[node.tagName.toLowerCase()]
  15475. };
  15476. //普通的情况
  15477. start = domUtils.findParent(range.startContainer, filterFn,true);
  15478. end = domUtils.findParent(range.endContainer, filterFn,true);
  15479. if (start && end && start === end) {
  15480. range.deleteContents();
  15481. range.insertNode(span.cloneNode(true).firstChild).setCursor(true);
  15482. } else {
  15483. var bookmark = range.createBookmark();
  15484. range.enlarge(true);
  15485. var bookmark2 = range.createBookmark(),
  15486. current = domUtils.getNextDomNode(bookmark2.start, false, filterFn);
  15487. while (current && !(domUtils.getPosition(current, bookmark2.end) & domUtils.POSITION_FOLLOWING)) {
  15488. current.insertBefore(span.cloneNode(true).firstChild, current.firstChild);
  15489. current = domUtils.getNextDomNode(current, false, filterFn);
  15490. }
  15491. range.moveToBookmark(bookmark2).moveToBookmark(bookmark).select();
  15492. }
  15493. }
  15494. domUtils.preventDefault(evt)
  15495. }
  15496. //trace:1634
  15497. //ff的del键在容器空的时候,也会删除
  15498. if(browser.gecko && keyCode == 46){
  15499. range = me.selection.getRange();
  15500. if(range.collapsed){
  15501. start = range.startContainer;
  15502. if(domUtils.isEmptyBlock(start)){
  15503. var parent = start.parentNode;
  15504. while(domUtils.getChildCount(parent) == 1 && !domUtils.isBody(parent)){
  15505. start = parent;
  15506. parent = parent.parentNode;
  15507. }
  15508. if(start === parent.lastChild)
  15509. evt.preventDefault();
  15510. return;
  15511. }
  15512. }
  15513. }
  15514. });
  15515. me.addListener('keyup', function(type, evt) {
  15516. var keyCode = evt.keyCode || evt.which,
  15517. rng,me = this;
  15518. if(keyCode == keymap.Backspace){
  15519. if(me.fireEvent('delkeyup')){
  15520. return;
  15521. }
  15522. rng = me.selection.getRange();
  15523. if(rng.collapsed){
  15524. var tmpNode,
  15525. autoClearTagName = ['h1','h2','h3','h4','h5','h6'];
  15526. if(tmpNode = domUtils.findParentByTagName(rng.startContainer,autoClearTagName,true)){
  15527. if(domUtils.isEmptyBlock(tmpNode)){
  15528. var pre = tmpNode.previousSibling;
  15529. if(pre && pre.nodeName != 'TABLE'){
  15530. domUtils.remove(tmpNode);
  15531. rng.setStartAtLast(pre).setCursor(false,true);
  15532. return;
  15533. }else{
  15534. var next = tmpNode.nextSibling;
  15535. if(next && next.nodeName != 'TABLE'){
  15536. domUtils.remove(tmpNode);
  15537. rng.setStartAtFirst(next).setCursor(false,true);
  15538. return;
  15539. }
  15540. }
  15541. }
  15542. }
  15543. //处理当删除到body时,要重新给p标签展位
  15544. if(domUtils.isBody(rng.startContainer)){
  15545. var tmpNode = domUtils.createElement(me.document,'p',{
  15546. 'innerHTML' : browser.ie ? domUtils.fillChar : '<br/>'
  15547. });
  15548. rng.insertNode(tmpNode).setStart(tmpNode,0).setCursor(false,true);
  15549. }
  15550. }
  15551. //chrome下如果删除了inline标签,浏览器会有记忆,在输入文字还是会套上刚才删除的标签,所以这里再选一次就不会了
  15552. if( !collapsed && (rng.startContainer.nodeType == 3 || rng.startContainer.nodeType == 1 && domUtils.isEmptyBlock(rng.startContainer))){
  15553. if(browser.ie){
  15554. var span = rng.document.createElement('span');
  15555. rng.insertNode(span).setStartBefore(span).collapse(true);
  15556. rng.select();
  15557. domUtils.remove(span)
  15558. }else{
  15559. rng.select()
  15560. }
  15561. }
  15562. }
  15563. })
  15564. };
  15565. // plugins/fiximgclick.js
  15566. ///import core
  15567. ///commands 修复chrome下图片不能点击的问题,出现八个角可改变大小
  15568. ///commandsName FixImgClick
  15569. ///commandsTitle 修复chrome下图片不能点击的问题,出现八个角可改变大小
  15570. //修复chrome下图片不能点击的问题,出现八个角可改变大小
  15571. UE.plugins['fiximgclick'] = (function () {
  15572. var elementUpdated = false;
  15573. function Scale() {
  15574. this.editor = null;
  15575. this.resizer = null;
  15576. this.cover = null;
  15577. this.doc = document;
  15578. this.prePos = {x: 0, y: 0};
  15579. this.startPos = {x: 0, y: 0};
  15580. }
  15581. (function () {
  15582. var rect = [
  15583. //[left, top, width, height]
  15584. [0, 0, -1, -1],
  15585. [0, 0, 0, -1],
  15586. [0, 0, 1, -1],
  15587. [0, 0, -1, 0],
  15588. [0, 0, 1, 0],
  15589. [0, 0, -1, 1],
  15590. [0, 0, 0, 1],
  15591. [0, 0, 1, 1]
  15592. ];
  15593. Scale.prototype = {
  15594. init: function (editor) {
  15595. var me = this;
  15596. me.editor = editor;
  15597. me.startPos = this.prePos = {x: 0, y: 0};
  15598. me.dragId = -1;
  15599. var hands = [],
  15600. cover = me.cover = document.createElement('div'),
  15601. resizer = me.resizer = document.createElement('div');
  15602. cover.id = me.editor.ui.id + '_imagescale_cover';
  15603. cover.style.cssText = 'position:absolute;display:none;z-index:' + (me.editor.options.zIndex) + ';filter:alpha(opacity=0); opacity:0;background:#CCC;';
  15604. domUtils.on(cover, 'mousedown click', function () {
  15605. me.hide();
  15606. });
  15607. for (i = 0; i < 8; i++) {
  15608. hands.push('<span class="edui-editor-imagescale-hand' + i + '"></span>');
  15609. }
  15610. resizer.id = me.editor.ui.id + '_imagescale';
  15611. resizer.className = 'edui-editor-imagescale';
  15612. resizer.innerHTML = hands.join('');
  15613. resizer.style.cssText += ';display:none;border:1px solid #3b77ff;z-index:' + (me.editor.options.zIndex) + ';';
  15614. me.editor.ui.getDom().appendChild(cover);
  15615. me.editor.ui.getDom().appendChild(resizer);
  15616. me.initStyle();
  15617. me.initEvents();
  15618. },
  15619. initStyle: function () {
  15620. 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;}' +
  15621. '.edui-editor-imagescale span{position:absolute;width:6px;height:6px;overflow:hidden;font-size:0px;display:block;background-color:#3C9DD0;}'
  15622. + '.edui-editor-imagescale .edui-editor-imagescale-hand0{cursor:nw-resize;top:0;margin-top:-4px;left:0;margin-left:-4px;}'
  15623. + '.edui-editor-imagescale .edui-editor-imagescale-hand1{cursor:n-resize;top:0;margin-top:-4px;left:50%;margin-left:-4px;}'
  15624. + '.edui-editor-imagescale .edui-editor-imagescale-hand2{cursor:ne-resize;top:0;margin-top:-4px;left:100%;margin-left:-3px;}'
  15625. + '.edui-editor-imagescale .edui-editor-imagescale-hand3{cursor:w-resize;top:50%;margin-top:-4px;left:0;margin-left:-4px;}'
  15626. + '.edui-editor-imagescale .edui-editor-imagescale-hand4{cursor:e-resize;top:50%;margin-top:-4px;left:100%;margin-left:-3px;}'
  15627. + '.edui-editor-imagescale .edui-editor-imagescale-hand5{cursor:sw-resize;top:100%;margin-top:-3px;left:0;margin-left:-4px;}'
  15628. + '.edui-editor-imagescale .edui-editor-imagescale-hand6{cursor:s-resize;top:100%;margin-top:-3px;left:50%;margin-left:-4px;}'
  15629. + '.edui-editor-imagescale .edui-editor-imagescale-hand7{cursor:se-resize;top:100%;margin-top:-3px;left:100%;margin-left:-3px;}');
  15630. },
  15631. initEvents: function () {
  15632. var me = this;
  15633. me.startPos.x = me.startPos.y = 0;
  15634. me.isDraging = false;
  15635. },
  15636. _eventHandler: function (e) {
  15637. var me = this;
  15638. switch (e.type) {
  15639. case 'mousedown':
  15640. var hand = e.target || e.srcElement, hand;
  15641. if (hand.className.indexOf('edui-editor-imagescale-hand') != -1 && me.dragId == -1) {
  15642. me.dragId = hand.className.slice(-1);
  15643. me.startPos.x = me.prePos.x = e.clientX;
  15644. me.startPos.y = me.prePos.y = e.clientY;
  15645. domUtils.on(me.doc,'mousemove', me.proxy(me._eventHandler, me));
  15646. }
  15647. break;
  15648. case 'mousemove':
  15649. if (me.dragId != -1) {
  15650. me.updateContainerStyle(me.dragId, {x: e.clientX - me.prePos.x, y: e.clientY - me.prePos.y});
  15651. me.prePos.x = e.clientX;
  15652. me.prePos.y = e.clientY;
  15653. elementUpdated = true;
  15654. me.updateTargetElement();
  15655. }
  15656. break;
  15657. case 'mouseup':
  15658. if (me.dragId != -1) {
  15659. me.updateContainerStyle(me.dragId, {x: e.clientX - me.prePos.x, y: e.clientY - me.prePos.y});
  15660. me.updateTargetElement();
  15661. if (me.target.parentNode) me.attachTo(me.target);
  15662. me.dragId = -1;
  15663. }
  15664. domUtils.un(me.doc,'mousemove', me.proxy(me._eventHandler, me));
  15665. //修复只是点击挪动点,但没有改变大小,不应该触发contentchange
  15666. if(elementUpdated){
  15667. elementUpdated = false;
  15668. me.editor.fireEvent('contentchange');
  15669. }
  15670. break;
  15671. default:
  15672. break;
  15673. }
  15674. },
  15675. updateTargetElement: function () {
  15676. var me = this;
  15677. domUtils.setStyles(me.target, {
  15678. 'width': me.resizer.style.width,
  15679. 'height': me.resizer.style.height
  15680. });
  15681. me.target.width = parseInt(me.resizer.style.width);
  15682. me.target.height = parseInt(me.resizer.style.height);
  15683. me.attachTo(me.target);
  15684. },
  15685. updateContainerStyle: function (dir, offset) {
  15686. var me = this,
  15687. dom = me.resizer, tmp;
  15688. if (rect[dir][0] != 0) {
  15689. tmp = parseInt(dom.style.left) + offset.x;
  15690. dom.style.left = me._validScaledProp('left', tmp) + 'px';
  15691. }
  15692. if (rect[dir][1] != 0) {
  15693. tmp = parseInt(dom.style.top) + offset.y;
  15694. dom.style.top = me._validScaledProp('top', tmp) + 'px';
  15695. }
  15696. if (rect[dir][2] != 0) {
  15697. tmp = dom.clientWidth + rect[dir][2] * offset.x;
  15698. dom.style.width = me._validScaledProp('width', tmp) + 'px';
  15699. }
  15700. if (rect[dir][3] != 0) {
  15701. tmp = dom.clientHeight + rect[dir][3] * offset.y;
  15702. dom.style.height = me._validScaledProp('height', tmp) + 'px';
  15703. }
  15704. },
  15705. _validScaledProp: function (prop, value) {
  15706. var ele = this.resizer,
  15707. wrap = document;
  15708. value = isNaN(value) ? 0 : value;
  15709. switch (prop) {
  15710. case 'left':
  15711. return value < 0 ? 0 : (value + ele.clientWidth) > wrap.clientWidth ? wrap.clientWidth - ele.clientWidth : value;
  15712. case 'top':
  15713. return value < 0 ? 0 : (value + ele.clientHeight) > wrap.clientHeight ? wrap.clientHeight - ele.clientHeight : value;
  15714. case 'width':
  15715. return value <= 0 ? 1 : (value + ele.offsetLeft) > wrap.clientWidth ? wrap.clientWidth - ele.offsetLeft : value;
  15716. case 'height':
  15717. return value <= 0 ? 1 : (value + ele.offsetTop) > wrap.clientHeight ? wrap.clientHeight - ele.offsetTop : value;
  15718. }
  15719. },
  15720. hideCover: function () {
  15721. this.cover.style.display = 'none';
  15722. },
  15723. showCover: function () {
  15724. var me = this,
  15725. editorPos = domUtils.getXY(me.editor.ui.getDom()),
  15726. iframePos = domUtils.getXY(me.editor.iframe);
  15727. domUtils.setStyles(me.cover, {
  15728. 'width': me.editor.iframe.offsetWidth + 'px',
  15729. 'height': me.editor.iframe.offsetHeight + 'px',
  15730. 'top': iframePos.y - editorPos.y + 'px',
  15731. 'left': iframePos.x - editorPos.x + 'px',
  15732. 'position': 'absolute',
  15733. 'display': ''
  15734. })
  15735. },
  15736. show: function (targetObj) {
  15737. var me = this;
  15738. me.resizer.style.display = 'block';
  15739. if(targetObj) me.attachTo(targetObj);
  15740. domUtils.on(this.resizer, 'mousedown', me.proxy(me._eventHandler, me));
  15741. domUtils.on(me.doc, 'mouseup', me.proxy(me._eventHandler, me));
  15742. me.showCover();
  15743. me.editor.fireEvent('afterscaleshow', me);
  15744. me.editor.fireEvent('saveScene');
  15745. },
  15746. hide: function () {
  15747. var me = this;
  15748. me.hideCover();
  15749. me.resizer.style.display = 'none';
  15750. domUtils.un(me.resizer, 'mousedown', me.proxy(me._eventHandler, me));
  15751. domUtils.un(me.doc, 'mouseup', me.proxy(me._eventHandler, me));
  15752. me.editor.fireEvent('afterscalehide', me);
  15753. },
  15754. proxy: function( fn, context ) {
  15755. return function(e) {
  15756. return fn.apply( context || this, arguments);
  15757. };
  15758. },
  15759. attachTo: function (targetObj) {
  15760. var me = this,
  15761. target = me.target = targetObj,
  15762. resizer = this.resizer,
  15763. imgPos = domUtils.getXY(target),
  15764. iframePos = domUtils.getXY(me.editor.iframe),
  15765. editorPos = domUtils.getXY(resizer.parentNode);
  15766. domUtils.setStyles(resizer, {
  15767. 'width': target.width + 'px',
  15768. 'height': target.height + 'px',
  15769. 'left': iframePos.x + imgPos.x - me.editor.document.body.scrollLeft - editorPos.x - parseInt(resizer.style.borderLeftWidth) + 'px',
  15770. 'top': iframePos.y + imgPos.y - me.editor.document.body.scrollTop - editorPos.y - parseInt(resizer.style.borderTopWidth) + 'px'
  15771. });
  15772. }
  15773. }
  15774. })();
  15775. return function () {
  15776. var me = this,
  15777. imageScale;
  15778. me.setOpt('imageScaleEnabled', true);
  15779. if ( !browser.ie && me.options.imageScaleEnabled) {
  15780. me.addListener('click', function (type, e) {
  15781. var range = me.selection.getRange(),
  15782. img = range.getClosedNode();
  15783. if (img && img.tagName == 'IMG' && me.body.contentEditable!="false") {
  15784. if (img.className.indexOf("edui-faked-music") != -1 ||
  15785. img.getAttribute("anchorname") ||
  15786. domUtils.hasClass(img, 'loadingclass') ||
  15787. domUtils.hasClass(img, 'loaderrorclass')) { return }
  15788. if (!imageScale) {
  15789. imageScale = new Scale();
  15790. imageScale.init(me);
  15791. me.ui.getDom().appendChild(imageScale.resizer);
  15792. var _keyDownHandler = function (e) {
  15793. imageScale.hide();
  15794. if(imageScale.target) me.selection.getRange().selectNode(imageScale.target).select();
  15795. }, _mouseDownHandler = function (e) {
  15796. var ele = e.target || e.srcElement;
  15797. if (ele && (ele.className===undefined || ele.className.indexOf('edui-editor-imagescale') == -1)) {
  15798. _keyDownHandler(e);
  15799. }
  15800. }, timer;
  15801. me.addListener('afterscaleshow', function (e) {
  15802. me.addListener('beforekeydown', _keyDownHandler);
  15803. me.addListener('beforemousedown', _mouseDownHandler);
  15804. domUtils.on(document, 'keydown', _keyDownHandler);
  15805. domUtils.on(document,'mousedown', _mouseDownHandler);
  15806. me.selection.getNative().removeAllRanges();
  15807. });
  15808. me.addListener('afterscalehide', function (e) {
  15809. me.removeListener('beforekeydown', _keyDownHandler);
  15810. me.removeListener('beforemousedown', _mouseDownHandler);
  15811. domUtils.un(document, 'keydown', _keyDownHandler);
  15812. domUtils.un(document,'mousedown', _mouseDownHandler);
  15813. var target = imageScale.target;
  15814. if (target.parentNode) {
  15815. me.selection.getRange().selectNode(target).select();
  15816. }
  15817. });
  15818. //TODO 有iframe的情况,mousedown不能往下传。。
  15819. domUtils.on(imageScale.resizer, 'mousedown', function (e) {
  15820. me.selection.getNative().removeAllRanges();
  15821. var ele = e.target || e.srcElement;
  15822. if (ele && ele.className.indexOf('edui-editor-imagescale-hand') == -1) {
  15823. timer = setTimeout(function () {
  15824. imageScale.hide();
  15825. if(imageScale.target) me.selection.getRange().selectNode(ele).select();
  15826. }, 200);
  15827. }
  15828. });
  15829. domUtils.on(imageScale.resizer, 'mouseup', function (e) {
  15830. var ele = e.target || e.srcElement;
  15831. if (ele && ele.className.indexOf('edui-editor-imagescale-hand') == -1) {
  15832. clearTimeout(timer);
  15833. }
  15834. });
  15835. }
  15836. imageScale.show(img);
  15837. } else {
  15838. if (imageScale && imageScale.resizer.style.display != 'none') imageScale.hide();
  15839. }
  15840. });
  15841. }
  15842. if (browser.webkit) {
  15843. me.addListener('click', function (type, e) {
  15844. if (e.target.tagName == 'IMG' && me.body.contentEditable!="false") {
  15845. var range = new dom.Range(me.document);
  15846. range.selectNode(e.target).select();
  15847. }
  15848. });
  15849. }
  15850. }
  15851. })();
  15852. // plugins/autolink.js
  15853. ///import core
  15854. ///commands 为非ie浏览器自动添加a标签
  15855. ///commandsName AutoLink
  15856. ///commandsTitle 自动增加链接
  15857. /**
  15858. * @description 为非ie浏览器自动添加a标签
  15859. * @author zhanyi
  15860. */
  15861. UE.plugin.register('autolink',function(){
  15862. var cont = 0;
  15863. return !browser.ie ? {
  15864. bindEvents:{
  15865. 'reset' : function(){
  15866. cont = 0;
  15867. },
  15868. 'keydown':function(type, evt) {
  15869. var me = this;
  15870. var keyCode = evt.keyCode || evt.which;
  15871. if (keyCode == 32 || keyCode == 13) {
  15872. var sel = me.selection.getNative(),
  15873. range = sel.getRangeAt(0).cloneRange(),
  15874. offset,
  15875. charCode;
  15876. var start = range.startContainer;
  15877. while (start.nodeType == 1 && range.startOffset > 0) {
  15878. start = range.startContainer.childNodes[range.startOffset - 1];
  15879. if (!start){
  15880. break;
  15881. }
  15882. range.setStart(start, start.nodeType == 1 ? start.childNodes.length : start.nodeValue.length);
  15883. range.collapse(true);
  15884. start = range.startContainer;
  15885. }
  15886. do{
  15887. if (range.startOffset == 0) {
  15888. start = range.startContainer.previousSibling;
  15889. while (start && start.nodeType == 1) {
  15890. start = start.lastChild;
  15891. }
  15892. if (!start || domUtils.isFillChar(start)){
  15893. break;
  15894. }
  15895. offset = start.nodeValue.length;
  15896. } else {
  15897. start = range.startContainer;
  15898. offset = range.startOffset;
  15899. }
  15900. range.setStart(start, offset - 1);
  15901. charCode = range.toString().charCodeAt(0);
  15902. } while (charCode != 160 && charCode != 32);
  15903. if (range.toString().replace(new RegExp(domUtils.fillChar, 'g'), '').match(/(?:https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.)/i)) {
  15904. while(range.toString().length){
  15905. if(/^(?:https?:\/\/|ssh:\/\/|ftp:\/\/|file:\/|www\.)/i.test(range.toString())){
  15906. break;
  15907. }
  15908. try{
  15909. range.setStart(range.startContainer,range.startOffset+1);
  15910. }catch(e){
  15911. //trace:2121
  15912. var start = range.startContainer;
  15913. while(!(next = start.nextSibling)){
  15914. if(domUtils.isBody(start)){
  15915. return;
  15916. }
  15917. start = start.parentNode;
  15918. }
  15919. range.setStart(next,0);
  15920. }
  15921. }
  15922. //range的开始边界已经在a标签里的不再处理
  15923. if(domUtils.findParentByTagName(range.startContainer,'a',true)){
  15924. return;
  15925. }
  15926. var a = me.document.createElement('a'),text = me.document.createTextNode(' '),href;
  15927. me.undoManger && me.undoManger.save();
  15928. a.appendChild(range.extractContents());
  15929. a.href = a.innerHTML = a.innerHTML.replace(/<[^>]+>/g,'');
  15930. href = a.getAttribute("href").replace(new RegExp(domUtils.fillChar,'g'),'');
  15931. href = /^(?:https?:\/\/)/ig.test(href) ? href : "http://"+ href;
  15932. a.setAttribute('_src',utils.html(href));
  15933. a.href = utils.html(href);
  15934. range.insertNode(a);
  15935. a.parentNode.insertBefore(text, a.nextSibling);
  15936. range.setStart(text, 0);
  15937. range.collapse(true);
  15938. sel.removeAllRanges();
  15939. sel.addRange(range);
  15940. me.undoManger && me.undoManger.save();
  15941. }
  15942. }
  15943. }
  15944. }
  15945. }:{}
  15946. },function(){
  15947. var keyCodes = {
  15948. 37:1, 38:1, 39:1, 40:1,
  15949. 13:1,32:1
  15950. };
  15951. function checkIsCludeLink(node){
  15952. if(node.nodeType == 3){
  15953. return null
  15954. }
  15955. if(node.nodeName == 'A'){
  15956. return node;
  15957. }
  15958. var lastChild = node.lastChild;
  15959. while(lastChild){
  15960. if(lastChild.nodeName == 'A'){
  15961. return lastChild;
  15962. }
  15963. if(lastChild.nodeType == 3){
  15964. if(domUtils.isWhitespace(lastChild)){
  15965. lastChild = lastChild.previousSibling;
  15966. continue;
  15967. }
  15968. return null
  15969. }
  15970. lastChild = lastChild.lastChild;
  15971. }
  15972. }
  15973. browser.ie && this.addListener('keyup',function(cmd,evt){
  15974. var me = this,keyCode = evt.keyCode;
  15975. if(keyCodes[keyCode]){
  15976. var rng = me.selection.getRange();
  15977. var start = rng.startContainer;
  15978. if(keyCode == 13){
  15979. while(start && !domUtils.isBody(start) && !domUtils.isBlockElm(start)){
  15980. start = start.parentNode;
  15981. }
  15982. if(start && !domUtils.isBody(start) && start.nodeName == 'P'){
  15983. var pre = start.previousSibling;
  15984. if(pre && pre.nodeType == 1){
  15985. var pre = checkIsCludeLink(pre);
  15986. if(pre && !pre.getAttribute('_href')){
  15987. domUtils.remove(pre,true);
  15988. }
  15989. }
  15990. }
  15991. }else if(keyCode == 32 ){
  15992. if(start.nodeType == 3 && /^\s$/.test(start.nodeValue)){
  15993. start = start.previousSibling;
  15994. if(start && start.nodeName == 'A' && !start.getAttribute('_href')){
  15995. domUtils.remove(start,true);
  15996. }
  15997. }
  15998. }else {
  15999. start = domUtils.findParentByTagName(start,'a',true);
  16000. if(start && !start.getAttribute('_href')){
  16001. var bk = rng.createBookmark();
  16002. domUtils.remove(start,true);
  16003. rng.moveToBookmark(bk).select(true)
  16004. }
  16005. }
  16006. }
  16007. });
  16008. }
  16009. );
  16010. // plugins/autoheight.js
  16011. ///import core
  16012. ///commands 当输入内容超过编辑器高度时,编辑器自动增高
  16013. ///commandsName AutoHeight,autoHeightEnabled
  16014. ///commandsTitle 自动增高
  16015. /**
  16016. * @description 自动伸展
  16017. * @author zhanyi
  16018. */
  16019. UE.plugins['autoheight'] = function () {
  16020. var me = this;
  16021. //提供开关,就算加载也可以关闭
  16022. me.autoHeightEnabled = me.options.autoHeightEnabled !== false;
  16023. if (!me.autoHeightEnabled) {
  16024. return;
  16025. }
  16026. var bakOverflow,
  16027. lastHeight = 0,
  16028. options = me.options,
  16029. currentHeight,
  16030. timer;
  16031. function adjustHeight() {
  16032. var me = this;
  16033. clearTimeout(timer);
  16034. if(isFullscreen)return;
  16035. if (!me.queryCommandState || me.queryCommandState && me.queryCommandState('source') != 1) {
  16036. timer = setTimeout(function(){
  16037. var node = me.body.lastChild;
  16038. while(node && node.nodeType != 1){
  16039. node = node.previousSibling;
  16040. }
  16041. if(node && node.nodeType == 1){
  16042. node.style.clear = 'both';
  16043. currentHeight = Math.max(domUtils.getXY(node).y + node.offsetHeight + 25 ,Math.max(options.minFrameHeight, options.initialFrameHeight)) ;
  16044. if (currentHeight != lastHeight) {
  16045. if (currentHeight !== parseInt(me.iframe.parentNode.style.height)) {
  16046. me.iframe.parentNode.style.height = currentHeight + 'px';
  16047. }
  16048. me.body.style.height = currentHeight + 'px';
  16049. lastHeight = currentHeight;
  16050. }
  16051. domUtils.removeStyle(node,'clear');
  16052. }
  16053. },50)
  16054. }
  16055. }
  16056. var isFullscreen;
  16057. me.addListener('fullscreenchanged',function(cmd,f){
  16058. isFullscreen = f
  16059. });
  16060. me.addListener('destroy', function () {
  16061. me.removeListener('contentchange afterinserthtml keyup mouseup',adjustHeight)
  16062. });
  16063. me.enableAutoHeight = function () {
  16064. var me = this;
  16065. if (!me.autoHeightEnabled) {
  16066. return;
  16067. }
  16068. var doc = me.document;
  16069. me.autoHeightEnabled = true;
  16070. bakOverflow = doc.body.style.overflowY;
  16071. doc.body.style.overflowY = 'hidden';
  16072. me.addListener('contentchange afterinserthtml keyup mouseup',adjustHeight);
  16073. //ff不给事件算得不对
  16074. setTimeout(function () {
  16075. adjustHeight.call(me);
  16076. }, browser.gecko ? 100 : 0);
  16077. me.fireEvent('autoheightchanged', me.autoHeightEnabled);
  16078. };
  16079. me.disableAutoHeight = function () {
  16080. me.body.style.overflowY = bakOverflow || '';
  16081. me.removeListener('contentchange', adjustHeight);
  16082. me.removeListener('keyup', adjustHeight);
  16083. me.removeListener('mouseup', adjustHeight);
  16084. me.autoHeightEnabled = false;
  16085. me.fireEvent('autoheightchanged', me.autoHeightEnabled);
  16086. };
  16087. me.on('setHeight',function(){
  16088. me.disableAutoHeight()
  16089. });
  16090. me.addListener('ready', function () {
  16091. me.enableAutoHeight();
  16092. //trace:1764
  16093. var timer;
  16094. domUtils.on(browser.ie ? me.body : me.document, browser.webkit ? 'dragover' : 'drop', function () {
  16095. clearTimeout(timer);
  16096. timer = setTimeout(function () {
  16097. //trace:3681
  16098. adjustHeight.call(me);
  16099. }, 100);
  16100. });
  16101. //修复内容过多时,回到顶部,顶部内容被工具栏遮挡问题
  16102. var lastScrollY;
  16103. window.onscroll = function(){
  16104. if(lastScrollY === null){
  16105. lastScrollY = this.scrollY
  16106. }else if(this.scrollY == 0 && lastScrollY != 0){
  16107. me.window.scrollTo(0,0);
  16108. lastScrollY = null;
  16109. }
  16110. }
  16111. });
  16112. };
  16113. // plugins/autofloat.js
  16114. ///import core
  16115. ///commands 悬浮工具栏
  16116. ///commandsName AutoFloat,autoFloatEnabled
  16117. ///commandsTitle 悬浮工具栏
  16118. /**
  16119. * modified by chengchao01
  16120. * 注意: 引入此功能后,在IE6下会将body的背景图片覆盖掉!
  16121. */
  16122. UE.plugins['autofloat'] = function() {
  16123. var me = this,
  16124. lang = me.getLang();
  16125. me.setOpt({
  16126. topOffset:0
  16127. });
  16128. var optsAutoFloatEnabled = me.options.autoFloatEnabled !== false,
  16129. topOffset = me.options.topOffset;
  16130. //如果不固定toolbar的位置,则直接退出
  16131. if(!optsAutoFloatEnabled){
  16132. return;
  16133. }
  16134. var uiUtils = UE.ui.uiUtils,
  16135. LteIE6 = browser.ie && browser.version <= 6,
  16136. quirks = browser.quirks;
  16137. function checkHasUI(){
  16138. if(!UE.ui){
  16139. alert(lang.autofloatMsg);
  16140. return 0;
  16141. }
  16142. return 1;
  16143. }
  16144. function fixIE6FixedPos(){
  16145. var docStyle = document.body.style;
  16146. docStyle.backgroundImage = 'url("about:blank")';
  16147. docStyle.backgroundAttachment = 'fixed';
  16148. }
  16149. var bakCssText,
  16150. placeHolder = document.createElement('div'),
  16151. toolbarBox,orgTop,
  16152. getPosition,
  16153. flag =true; //ie7模式下需要偏移
  16154. function setFloating(){
  16155. var toobarBoxPos = domUtils.getXY(toolbarBox),
  16156. origalFloat = domUtils.getComputedStyle(toolbarBox,'position'),
  16157. origalLeft = domUtils.getComputedStyle(toolbarBox,'left');
  16158. toolbarBox.style.width = toolbarBox.offsetWidth + 'px';
  16159. toolbarBox.style.zIndex = me.options.zIndex * 1 + 1;
  16160. toolbarBox.parentNode.insertBefore(placeHolder, toolbarBox);
  16161. if (LteIE6 || (quirks && browser.ie)) {
  16162. if(toolbarBox.style.position != 'absolute'){
  16163. toolbarBox.style.position = 'absolute';
  16164. }
  16165. toolbarBox.style.top = (document.body.scrollTop||document.documentElement.scrollTop) - orgTop + topOffset + 'px';
  16166. } else {
  16167. if (browser.ie7Compat && flag) {
  16168. flag = false;
  16169. toolbarBox.style.left = domUtils.getXY(toolbarBox).x - document.documentElement.getBoundingClientRect().left+2 + 'px';
  16170. }
  16171. if(toolbarBox.style.position != 'fixed'){
  16172. toolbarBox.style.position = 'fixed';
  16173. toolbarBox.style.top = topOffset +"px";
  16174. ((origalFloat == 'absolute' || origalFloat == 'relative') && parseFloat(origalLeft)) && (toolbarBox.style.left = toobarBoxPos.x + 'px');
  16175. }
  16176. }
  16177. }
  16178. function unsetFloating(){
  16179. flag = true;
  16180. if(placeHolder.parentNode){
  16181. placeHolder.parentNode.removeChild(placeHolder);
  16182. }
  16183. toolbarBox.style.cssText = bakCssText;
  16184. }
  16185. function updateFloating(){
  16186. var rect3 = getPosition(me.container);
  16187. var offset=me.options.toolbarTopOffset||0;
  16188. if (rect3.top < 0 && rect3.bottom - toolbarBox.offsetHeight > offset) {
  16189. setFloating();
  16190. }else{
  16191. unsetFloating();
  16192. }
  16193. }
  16194. var defer_updateFloating = utils.defer(function(){
  16195. updateFloating();
  16196. },browser.ie ? 200 : 100,true);
  16197. me.addListener('destroy',function(){
  16198. domUtils.un(window, ['scroll','resize'], updateFloating);
  16199. me.removeListener('keydown', defer_updateFloating);
  16200. });
  16201. me.addListener('ready', function(){
  16202. if(checkHasUI(me)){
  16203. //加载了ui组件,但在new时,没有加载ui,导致编辑器实例上没有ui类,所以这里做判断
  16204. if(!me.ui){
  16205. return;
  16206. }
  16207. getPosition = uiUtils.getClientRect;
  16208. toolbarBox = me.ui.getDom('toolbarbox');
  16209. orgTop = getPosition(toolbarBox).top;
  16210. bakCssText = toolbarBox.style.cssText;
  16211. placeHolder.style.height = toolbarBox.offsetHeight + 'px';
  16212. if(LteIE6){
  16213. fixIE6FixedPos();
  16214. }
  16215. domUtils.on(window, ['scroll','resize'], updateFloating);
  16216. me.addListener('keydown', defer_updateFloating);
  16217. me.addListener('beforefullscreenchange', function (t, enabled){
  16218. if (enabled) {
  16219. unsetFloating();
  16220. }
  16221. });
  16222. me.addListener('fullscreenchanged', function (t, enabled){
  16223. if (!enabled) {
  16224. updateFloating();
  16225. }
  16226. });
  16227. me.addListener('sourcemodechanged', function (t, enabled){
  16228. setTimeout(function (){
  16229. updateFloating();
  16230. },0);
  16231. });
  16232. me.addListener("clearDoc",function(){
  16233. setTimeout(function(){
  16234. updateFloating();
  16235. },0);
  16236. })
  16237. }
  16238. });
  16239. };
  16240. // plugins/video.js
  16241. /**
  16242. * video插件, 为UEditor提供视频插入支持
  16243. * @file
  16244. * @since 1.2.6.1
  16245. */
  16246. UE.plugins['video'] = function (){
  16247. var me =this;
  16248. /**
  16249. * 创建插入视频字符窜
  16250. * @param url 视频地址
  16251. * @param width 视频宽度
  16252. * @param height 视频高度
  16253. * @param align 视频对齐
  16254. * @param toEmbed 是否以flash代替显示
  16255. * @param addParagraph 是否需要添加P 标签
  16256. */
  16257. function creatInsertStr(url,width,height,id,align,classname,type){
  16258. url = utils.unhtmlForUrl(url);
  16259. align = utils.unhtml(align);
  16260. classname = utils.unhtml(classname);
  16261. width = parseInt(width, 10) || 0;
  16262. height = parseInt(height, 10) || 0;
  16263. var str;
  16264. switch (type){
  16265. case 'image':
  16266. str = '<img ' + (id ? 'id="' + id+'"' : '') + ' width="'+ width +'" height="' + height + '" _url="'+url+'" class="' + classname.replace(/\bvideo-js\b/, '') + '"' +
  16267. ' 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 + ';': '')+'" />'
  16268. break;
  16269. case 'embed':
  16270. str = '<embed type="application/x-shockwave-flash" class="' + classname + '" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
  16271. ' src="' + utils.html(url) + '" width="' + width + '" height="' + height + '"' + (align ? ' style="float:' + align + '"': '') +
  16272. ' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >';
  16273. break;
  16274. case 'video':
  16275. var ext = url.substr(url.lastIndexOf('.') + 1);
  16276. if(ext == 'ogv') ext = 'ogg';
  16277. str = '<video' + (id ? ' id="' + id + '"' : '') + ' class="' + classname + ' video-js" ' + (align ? ' style="float:' + align + '"': '') +
  16278. ' controls preload="none" width="' + width + '" height="' + height + '" src="' + url + '" data-setup="{}">' +
  16279. '<source src="' + url + '" type="video/' + ext + '" /></video>';
  16280. break;
  16281. }
  16282. return str;
  16283. }
  16284. function switchImgAndVideo(root,img2video){
  16285. utils.each(root.getNodesByTagName(img2video ? 'img' : 'embed video'),function(node){
  16286. var className = node.getAttr('class');
  16287. if(className && className.indexOf('edui-faked-video') != -1){
  16288. var html = creatInsertStr( img2video ? node.getAttr('_url') : node.getAttr('src'),node.getAttr('width'),node.getAttr('height'),null,node.getStyle('float') || '',className,img2video ? 'embed':'image');
  16289. node.parentNode.replaceChild(UE.uNode.createElement(html),node);
  16290. }
  16291. if(className && className.indexOf('edui-upload-video') != -1){
  16292. var html = creatInsertStr( img2video ? node.getAttr('_url') : node.getAttr('src'),node.getAttr('width'),node.getAttr('height'),null,node.getStyle('float') || '',className,img2video ? 'video':'image');
  16293. node.parentNode.replaceChild(UE.uNode.createElement(html),node);
  16294. }
  16295. })
  16296. }
  16297. me.addOutputRule(function(root){
  16298. switchImgAndVideo(root,true)
  16299. });
  16300. me.addInputRule(function(root){
  16301. switchImgAndVideo(root)
  16302. });
  16303. /**
  16304. * 插入视频
  16305. * @command insertvideo
  16306. * @method execCommand
  16307. * @param { String } cmd 命令字符串
  16308. * @param { Object } videoAttr 键值对对象, 描述一个视频的所有属性
  16309. * @example
  16310. * ```javascript
  16311. *
  16312. * var videoAttr = {
  16313. * //视频地址
  16314. * url: 'http://www.youku.com/xxx',
  16315. * //视频宽高值, 单位px
  16316. * width: 200,
  16317. * height: 100
  16318. * };
  16319. *
  16320. * //editor 是编辑器实例
  16321. * //向编辑器插入单个视频
  16322. * editor.execCommand( 'insertvideo', videoAttr );
  16323. * ```
  16324. */
  16325. /**
  16326. * 插入视频
  16327. * @command insertvideo
  16328. * @method execCommand
  16329. * @param { String } cmd 命令字符串
  16330. * @param { Array } videoArr 需要插入的视频的数组, 其中的每一个元素都是一个键值对对象, 描述了一个视频的所有属性
  16331. * @example
  16332. * ```javascript
  16333. *
  16334. * var videoAttr1 = {
  16335. * //视频地址
  16336. * url: 'http://www.youku.com/xxx',
  16337. * //视频宽高值, 单位px
  16338. * width: 200,
  16339. * height: 100
  16340. * },
  16341. * videoAttr2 = {
  16342. * //视频地址
  16343. * url: 'http://www.youku.com/xxx',
  16344. * //视频宽高值, 单位px
  16345. * width: 200,
  16346. * height: 100
  16347. * }
  16348. *
  16349. * //editor 是编辑器实例
  16350. * //该方法将会向编辑器内插入两个视频
  16351. * editor.execCommand( 'insertvideo', [ videoAttr1, videoAttr2 ] );
  16352. * ```
  16353. */
  16354. /**
  16355. * 查询当前光标所在处是否是一个视频
  16356. * @command insertvideo
  16357. * @method queryCommandState
  16358. * @param { String } cmd 需要查询的命令字符串
  16359. * @return { int } 如果当前光标所在处的元素是一个视频对象, 则返回1,否则返回0
  16360. * @example
  16361. * ```javascript
  16362. *
  16363. * //editor 是编辑器实例
  16364. * editor.queryCommandState( 'insertvideo' );
  16365. * ```
  16366. */
  16367. me.commands["insertvideo"] = {
  16368. execCommand: function (cmd, videoObjs, type){
  16369. videoObjs = utils.isArray(videoObjs)?videoObjs:[videoObjs];
  16370. var html = [],id = 'tmpVedio', cl;
  16371. for(var i=0,vi,len = videoObjs.length;i<len;i++){
  16372. vi = videoObjs[i];
  16373. cl = (type == 'upload' ? 'edui-upload-video video-js vjs-default-skin':'edui-faked-video');
  16374. html.push(creatInsertStr( vi.url, vi.width || 420, vi.height || 280, id + i, null, cl, 'image'));
  16375. }
  16376. me.execCommand("inserthtml",html.join(""),true);
  16377. var rng = this.selection.getRange();
  16378. for(var i= 0,len=videoObjs.length;i<len;i++){
  16379. var img = this.document.getElementById('tmpVedio'+i);
  16380. domUtils.removeAttributes(img,'id');
  16381. rng.selectNode(img).select();
  16382. me.execCommand('imagefloat',videoObjs[i].align)
  16383. }
  16384. },
  16385. queryCommandState : function(){
  16386. var img = me.selection.getRange().getClosedNode(),
  16387. flag = img && (img.className == "edui-faked-video" || img.className.indexOf("edui-upload-video")!=-1);
  16388. return flag ? 1 : 0;
  16389. }
  16390. };
  16391. };
  16392. // plugins/table.core.js
  16393. /**
  16394. * Created with JetBrains WebStorm.
  16395. * User: taoqili
  16396. * Date: 13-1-18
  16397. * Time: 上午11:09
  16398. * To change this template use File | Settings | File Templates.
  16399. */
  16400. /**
  16401. * UE表格操作类
  16402. * @param table
  16403. * @constructor
  16404. */
  16405. (function () {
  16406. var UETable = UE.UETable = function (table) {
  16407. this.table = table;
  16408. this.indexTable = [];
  16409. this.selectedTds = [];
  16410. this.cellsRange = {};
  16411. this.update(table);
  16412. };
  16413. //===以下为静态工具方法===
  16414. UETable.removeSelectedClass = function (cells) {
  16415. utils.each(cells, function (cell) {
  16416. domUtils.removeClasses(cell, "selectTdClass");
  16417. })
  16418. };
  16419. UETable.addSelectedClass = function (cells) {
  16420. utils.each(cells, function (cell) {
  16421. domUtils.addClass(cell, "selectTdClass");
  16422. })
  16423. };
  16424. UETable.isEmptyBlock = function (node) {
  16425. var reg = new RegExp(domUtils.fillChar, 'g');
  16426. if (node[browser.ie ? 'innerText' : 'textContent'].replace(/^\s*$/, '').replace(reg, '').length > 0) {
  16427. return 0;
  16428. }
  16429. for (var i in dtd.$isNotEmpty) if (dtd.$isNotEmpty.hasOwnProperty(i)) {
  16430. if (node.getElementsByTagName(i).length) {
  16431. return 0;
  16432. }
  16433. }
  16434. return 1;
  16435. };
  16436. UETable.getWidth = function (cell) {
  16437. if (!cell)return 0;
  16438. return parseInt(domUtils.getComputedStyle(cell, "width"), 10);
  16439. };
  16440. /**
  16441. * 获取单元格或者单元格组的“对齐”状态。 如果当前的检测对象是一个单元格组, 只有在满足所有单元格的 水平和竖直 对齐属性都相同的
  16442. * 条件时才会返回其状态值,否则将返回null; 如果当前只检测了一个单元格, 则直接返回当前单元格的对齐状态;
  16443. * @param table cell or table cells , 支持单个单元格dom对象 或者 单元格dom对象数组
  16444. * @return { align: 'left' || 'right' || 'center', valign: 'top' || 'middle' || 'bottom' } 或者 null
  16445. */
  16446. UETable.getTableCellAlignState = function ( cells ) {
  16447. !utils.isArray( cells ) && ( cells = [cells] );
  16448. var result = {},
  16449. status = ['align', 'valign'],
  16450. tempStatus = null,
  16451. isSame = true;//状态是否相同
  16452. utils.each( cells, function( cellNode ){
  16453. utils.each( status, function( currentState ){
  16454. tempStatus = cellNode.getAttribute( currentState );
  16455. if( !result[ currentState ] && tempStatus ) {
  16456. result[ currentState ] = tempStatus;
  16457. } else if( !result[ currentState ] || ( tempStatus !== result[ currentState ] ) ) {
  16458. isSame = false;
  16459. return false;
  16460. }
  16461. } );
  16462. return isSame;
  16463. });
  16464. return isSame ? result : null;
  16465. };
  16466. /**
  16467. * 根据当前选区获取相关的table信息
  16468. * @return {Object}
  16469. */
  16470. UETable.getTableItemsByRange = function (editor) {
  16471. var start = editor.selection.getStart();
  16472. //ff下会选中bookmark
  16473. if( start && start.id && start.id.indexOf('_baidu_bookmark_start_') === 0 && start.nextSibling) {
  16474. start = start.nextSibling;
  16475. }
  16476. //在table或者td边缘有可能存在选中tr的情况
  16477. var cell = start && domUtils.findParentByTagName(start, ["td", "th"], true),
  16478. tr = cell && cell.parentNode,
  16479. caption = start && domUtils.findParentByTagName(start, 'caption', true),
  16480. table = caption ? caption.parentNode : tr && tr.parentNode.parentNode;
  16481. return {
  16482. cell:cell,
  16483. tr:tr,
  16484. table:table,
  16485. caption:caption
  16486. }
  16487. };
  16488. UETable.getUETableBySelected = function (editor) {
  16489. var table = UETable.getTableItemsByRange(editor).table;
  16490. if (table && table.ueTable && table.ueTable.selectedTds.length) {
  16491. return table.ueTable;
  16492. }
  16493. return null;
  16494. };
  16495. UETable.getDefaultValue = function (editor, table) {
  16496. var borderMap = {
  16497. thin:'0px',
  16498. medium:'1px',
  16499. thick:'2px'
  16500. },
  16501. tableBorder, tdPadding, tdBorder, tmpValue;
  16502. if (!table) {
  16503. table = editor.document.createElement('table');
  16504. table.insertRow(0).insertCell(0).innerHTML = 'xxx';
  16505. editor.body.appendChild(table);
  16506. var td = table.getElementsByTagName('td')[0];
  16507. tmpValue = domUtils.getComputedStyle(table, 'border-left-width');
  16508. tableBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16509. tmpValue = domUtils.getComputedStyle(td, 'padding-left');
  16510. tdPadding = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16511. tmpValue = domUtils.getComputedStyle(td, 'border-left-width');
  16512. tdBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16513. domUtils.remove(table);
  16514. return {
  16515. tableBorder:tableBorder,
  16516. tdPadding:tdPadding,
  16517. tdBorder:tdBorder
  16518. };
  16519. } else {
  16520. td = table.getElementsByTagName('td')[0];
  16521. tmpValue = domUtils.getComputedStyle(table, 'border-left-width');
  16522. tableBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16523. tmpValue = domUtils.getComputedStyle(td, 'padding-left');
  16524. tdPadding = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16525. tmpValue = domUtils.getComputedStyle(td, 'border-left-width');
  16526. tdBorder = parseInt(borderMap[tmpValue] || tmpValue, 10);
  16527. return {
  16528. tableBorder:tableBorder,
  16529. tdPadding:tdPadding,
  16530. tdBorder:tdBorder
  16531. };
  16532. }
  16533. };
  16534. /**
  16535. * 根据当前点击的td或者table获取索引对象
  16536. * @param tdOrTable
  16537. */
  16538. UETable.getUETable = function (tdOrTable) {
  16539. var tag = tdOrTable.tagName.toLowerCase();
  16540. tdOrTable = (tag == "td" || tag == "th" || tag == 'caption') ? domUtils.findParentByTagName(tdOrTable, "table", true) : tdOrTable;
  16541. if (!tdOrTable.ueTable) {
  16542. tdOrTable.ueTable = new UETable(tdOrTable);
  16543. }
  16544. return tdOrTable.ueTable;
  16545. };
  16546. UETable.cloneCell = function(cell,ignoreMerge,keepPro){
  16547. if (!cell || utils.isString(cell)) {
  16548. return this.table.ownerDocument.createElement(cell || 'td');
  16549. }
  16550. var flag = domUtils.hasClass(cell, "selectTdClass");
  16551. flag && domUtils.removeClasses(cell, "selectTdClass");
  16552. var tmpCell = cell.cloneNode(true);
  16553. if (ignoreMerge) {
  16554. tmpCell.rowSpan = tmpCell.colSpan = 1;
  16555. }
  16556. //去掉宽高
  16557. !keepPro && domUtils.removeAttributes(tmpCell,'width height');
  16558. !keepPro && domUtils.removeAttributes(tmpCell,'style');
  16559. tmpCell.style.borderLeftStyle = "";
  16560. tmpCell.style.borderTopStyle = "";
  16561. tmpCell.style.borderLeftColor = cell.style.borderRightColor;
  16562. tmpCell.style.borderLeftWidth = cell.style.borderRightWidth;
  16563. tmpCell.style.borderTopColor = cell.style.borderBottomColor;
  16564. tmpCell.style.borderTopWidth = cell.style.borderBottomWidth;
  16565. flag && domUtils.addClass(cell, "selectTdClass");
  16566. return tmpCell;
  16567. }
  16568. UETable.prototype = {
  16569. getMaxRows:function () {
  16570. var rows = this.table.rows, maxLen = 1;
  16571. for (var i = 0, row; row = rows[i]; i++) {
  16572. var currentMax = 1;
  16573. for (var j = 0, cj; cj = row.cells[j++];) {
  16574. currentMax = Math.max(cj.rowSpan || 1, currentMax);
  16575. }
  16576. maxLen = Math.max(currentMax + i, maxLen);
  16577. }
  16578. return maxLen;
  16579. },
  16580. /**
  16581. * 获取当前表格的最大列数
  16582. */
  16583. getMaxCols:function () {
  16584. var rows = this.table.rows, maxLen = 0, cellRows = {};
  16585. for (var i = 0, row; row = rows[i]; i++) {
  16586. var cellsNum = 0;
  16587. for (var j = 0, cj; cj = row.cells[j++];) {
  16588. cellsNum += (cj.colSpan || 1);
  16589. if (cj.rowSpan && cj.rowSpan > 1) {
  16590. for (var k = 1; k < cj.rowSpan; k++) {
  16591. if (!cellRows['row_' + (i + k)]) {
  16592. cellRows['row_' + (i + k)] = (cj.colSpan || 1);
  16593. } else {
  16594. cellRows['row_' + (i + k)]++
  16595. }
  16596. }
  16597. }
  16598. }
  16599. cellsNum += cellRows['row_' + i] || 0;
  16600. maxLen = Math.max(cellsNum, maxLen);
  16601. }
  16602. return maxLen;
  16603. },
  16604. getCellColIndex:function (cell) {
  16605. },
  16606. /**
  16607. * 获取当前cell旁边的单元格,
  16608. * @param cell
  16609. * @param right
  16610. */
  16611. getHSideCell:function (cell, right) {
  16612. try {
  16613. var cellInfo = this.getCellInfo(cell),
  16614. previewRowIndex, previewColIndex;
  16615. var len = this.selectedTds.length,
  16616. range = this.cellsRange;
  16617. //首行或者首列没有前置单元格
  16618. if ((!right && (!len ? !cellInfo.colIndex : !range.beginColIndex)) || (right && (!len ? (cellInfo.colIndex == (this.colsNum - 1)) : (range.endColIndex == this.colsNum - 1)))) return null;
  16619. previewRowIndex = !len ? cellInfo.rowIndex : range.beginRowIndex;
  16620. previewColIndex = !right ? ( !len ? (cellInfo.colIndex < 1 ? 0 : (cellInfo.colIndex - 1)) : range.beginColIndex - 1)
  16621. : ( !len ? cellInfo.colIndex + 1 : range.endColIndex + 1);
  16622. return this.getCell(this.indexTable[previewRowIndex][previewColIndex].rowIndex, this.indexTable[previewRowIndex][previewColIndex].cellIndex);
  16623. } catch (e) {
  16624. showError(e);
  16625. }
  16626. },
  16627. getTabNextCell:function (cell, preRowIndex) {
  16628. var cellInfo = this.getCellInfo(cell),
  16629. rowIndex = preRowIndex || cellInfo.rowIndex,
  16630. colIndex = cellInfo.colIndex + 1 + (cellInfo.colSpan - 1),
  16631. nextCell;
  16632. try {
  16633. nextCell = this.getCell(this.indexTable[rowIndex][colIndex].rowIndex, this.indexTable[rowIndex][colIndex].cellIndex);
  16634. } catch (e) {
  16635. try {
  16636. rowIndex = rowIndex * 1 + 1;
  16637. colIndex = 0;
  16638. nextCell = this.getCell(this.indexTable[rowIndex][colIndex].rowIndex, this.indexTable[rowIndex][colIndex].cellIndex);
  16639. } catch (e) {
  16640. }
  16641. }
  16642. return nextCell;
  16643. },
  16644. /**
  16645. * 获取视觉上的后置单元格
  16646. * @param cell
  16647. * @param bottom
  16648. */
  16649. getVSideCell:function (cell, bottom, ignoreRange) {
  16650. try {
  16651. var cellInfo = this.getCellInfo(cell),
  16652. nextRowIndex, nextColIndex;
  16653. var len = this.selectedTds.length && !ignoreRange,
  16654. range = this.cellsRange;
  16655. //末行或者末列没有后置单元格
  16656. if ((!bottom && (cellInfo.rowIndex == 0)) || (bottom && (!len ? (cellInfo.rowIndex + cellInfo.rowSpan > this.rowsNum - 1) : (range.endRowIndex == this.rowsNum - 1)))) return null;
  16657. nextRowIndex = !bottom ? ( !len ? cellInfo.rowIndex - 1 : range.beginRowIndex - 1)
  16658. : ( !len ? (cellInfo.rowIndex + cellInfo.rowSpan) : range.endRowIndex + 1);
  16659. nextColIndex = !len ? cellInfo.colIndex : range.beginColIndex;
  16660. return this.getCell(this.indexTable[nextRowIndex][nextColIndex].rowIndex, this.indexTable[nextRowIndex][nextColIndex].cellIndex);
  16661. } catch (e) {
  16662. showError(e);
  16663. }
  16664. },
  16665. /**
  16666. * 获取相同结束位置的单元格,xOrY指代了是获取x轴相同还是y轴相同
  16667. */
  16668. getSameEndPosCells:function (cell, xOrY) {
  16669. try {
  16670. var flag = (xOrY.toLowerCase() === "x"),
  16671. end = domUtils.getXY(cell)[flag ? 'x' : 'y'] + cell["offset" + (flag ? 'Width' : 'Height')],
  16672. rows = this.table.rows,
  16673. cells = null, returns = [];
  16674. for (var i = 0; i < this.rowsNum; i++) {
  16675. cells = rows[i].cells;
  16676. for (var j = 0, tmpCell; tmpCell = cells[j++];) {
  16677. var tmpEnd = domUtils.getXY(tmpCell)[flag ? 'x' : 'y'] + tmpCell["offset" + (flag ? 'Width' : 'Height')];
  16678. //对应行的td已经被上面行rowSpan了
  16679. if (tmpEnd > end && flag) break;
  16680. if (cell == tmpCell || end == tmpEnd) {
  16681. //只获取单一的单元格
  16682. //todo 仅获取单一单元格在特定情况下会造成returns为空,从而影响后续的拖拽实现,修正这个。需考虑性能
  16683. if (tmpCell[flag ? "colSpan" : "rowSpan"] == 1) {
  16684. returns.push(tmpCell);
  16685. }
  16686. if (flag) break;
  16687. }
  16688. }
  16689. }
  16690. return returns;
  16691. } catch (e) {
  16692. showError(e);
  16693. }
  16694. },
  16695. setCellContent:function (cell, content) {
  16696. cell.innerHTML = content || (browser.ie ? domUtils.fillChar : "<br />");
  16697. },
  16698. cloneCell:UETable.cloneCell,
  16699. /**
  16700. * 获取跟当前单元格的右边竖线为左边的所有未合并单元格
  16701. */
  16702. getSameStartPosXCells:function (cell) {
  16703. try {
  16704. var start = domUtils.getXY(cell).x + cell.offsetWidth,
  16705. rows = this.table.rows, cells , returns = [];
  16706. for (var i = 0; i < this.rowsNum; i++) {
  16707. cells = rows[i].cells;
  16708. for (var j = 0, tmpCell; tmpCell = cells[j++];) {
  16709. var tmpStart = domUtils.getXY(tmpCell).x;
  16710. if (tmpStart > start) break;
  16711. if (tmpStart == start && tmpCell.colSpan == 1) {
  16712. returns.push(tmpCell);
  16713. break;
  16714. }
  16715. }
  16716. }
  16717. return returns;
  16718. } catch (e) {
  16719. showError(e);
  16720. }
  16721. },
  16722. /**
  16723. * 更新table对应的索引表
  16724. */
  16725. update:function (table) {
  16726. this.table = table || this.table;
  16727. this.selectedTds = [];
  16728. this.cellsRange = {};
  16729. this.indexTable = [];
  16730. var rows = this.table.rows,
  16731. rowsNum = this.getMaxRows(),
  16732. dNum = rowsNum - rows.length,
  16733. colsNum = this.getMaxCols();
  16734. while (dNum--) {
  16735. this.table.insertRow(rows.length);
  16736. }
  16737. this.rowsNum = rowsNum;
  16738. this.colsNum = colsNum;
  16739. for (var i = 0, len = rows.length; i < len; i++) {
  16740. this.indexTable[i] = new Array(colsNum);
  16741. }
  16742. //填充索引表
  16743. for (var rowIndex = 0, row; row = rows[rowIndex]; rowIndex++) {
  16744. for (var cellIndex = 0, cell, cells = row.cells; cell = cells[cellIndex]; cellIndex++) {
  16745. //修正整行被rowSpan时导致的行数计算错误
  16746. if (cell.rowSpan > rowsNum) {
  16747. cell.rowSpan = rowsNum;
  16748. }
  16749. var colIndex = cellIndex,
  16750. rowSpan = cell.rowSpan || 1,
  16751. colSpan = cell.colSpan || 1;
  16752. //当已经被上一行rowSpan或者被前一列colSpan了,则跳到下一个单元格进行
  16753. while (this.indexTable[rowIndex][colIndex]) colIndex++;
  16754. for (var j = 0; j < rowSpan; j++) {
  16755. for (var k = 0; k < colSpan; k++) {
  16756. this.indexTable[rowIndex + j][colIndex + k] = {
  16757. rowIndex:rowIndex,
  16758. cellIndex:cellIndex,
  16759. colIndex:colIndex,
  16760. rowSpan:rowSpan,
  16761. colSpan:colSpan
  16762. }
  16763. }
  16764. }
  16765. }
  16766. }
  16767. //修复残缺td
  16768. for (j = 0; j < rowsNum; j++) {
  16769. for (k = 0; k < colsNum; k++) {
  16770. if (this.indexTable[j][k] === undefined) {
  16771. row = rows[j];
  16772. cell = row.cells[row.cells.length - 1];
  16773. cell = cell ? cell.cloneNode(true) : this.table.ownerDocument.createElement("td");
  16774. this.setCellContent(cell);
  16775. if (cell.colSpan !== 1)cell.colSpan = 1;
  16776. if (cell.rowSpan !== 1)cell.rowSpan = 1;
  16777. row.appendChild(cell);
  16778. this.indexTable[j][k] = {
  16779. rowIndex:j,
  16780. cellIndex:cell.cellIndex,
  16781. colIndex:k,
  16782. rowSpan:1,
  16783. colSpan:1
  16784. }
  16785. }
  16786. }
  16787. }
  16788. //当框选后删除行或者列后撤销,需要重建选区。
  16789. var tds = domUtils.getElementsByTagName(this.table, "td"),
  16790. selectTds = [];
  16791. utils.each(tds, function (td) {
  16792. if (domUtils.hasClass(td, "selectTdClass")) {
  16793. selectTds.push(td);
  16794. }
  16795. });
  16796. if (selectTds.length) {
  16797. var start = selectTds[0],
  16798. end = selectTds[selectTds.length - 1],
  16799. startInfo = this.getCellInfo(start),
  16800. endInfo = this.getCellInfo(end);
  16801. this.selectedTds = selectTds;
  16802. this.cellsRange = {
  16803. beginRowIndex:startInfo.rowIndex,
  16804. beginColIndex:startInfo.colIndex,
  16805. endRowIndex:endInfo.rowIndex + endInfo.rowSpan - 1,
  16806. endColIndex:endInfo.colIndex + endInfo.colSpan - 1
  16807. };
  16808. }
  16809. //给第一行设置firstRow的样式名称,在排序图标的样式上使用到
  16810. if(!domUtils.hasClass(this.table.rows[0], "firstRow")) {
  16811. domUtils.addClass(this.table.rows[0], "firstRow");
  16812. for(var i = 1; i< this.table.rows.length; i++) {
  16813. domUtils.removeClasses(this.table.rows[i], "firstRow");
  16814. }
  16815. }
  16816. },
  16817. /**
  16818. * 获取单元格的索引信息
  16819. */
  16820. getCellInfo:function (cell) {
  16821. if (!cell) return;
  16822. var cellIndex = cell.cellIndex,
  16823. rowIndex = cell.parentNode.rowIndex,
  16824. rowInfo = this.indexTable[rowIndex],
  16825. numCols = this.colsNum;
  16826. for (var colIndex = cellIndex; colIndex < numCols; colIndex++) {
  16827. var cellInfo = rowInfo[colIndex];
  16828. if (cellInfo.rowIndex === rowIndex && cellInfo.cellIndex === cellIndex) {
  16829. return cellInfo;
  16830. }
  16831. }
  16832. },
  16833. /**
  16834. * 根据行列号获取单元格
  16835. */
  16836. getCell:function (rowIndex, cellIndex) {
  16837. return rowIndex < this.rowsNum && this.table.rows[rowIndex].cells[cellIndex] || null;
  16838. },
  16839. /**
  16840. * 删除单元格
  16841. */
  16842. deleteCell:function (cell, rowIndex) {
  16843. rowIndex = typeof rowIndex == 'number' ? rowIndex : cell.parentNode.rowIndex;
  16844. var row = this.table.rows[rowIndex];
  16845. row.deleteCell(cell.cellIndex);
  16846. },
  16847. /**
  16848. * 根据始末两个单元格获取被框选的所有单元格范围
  16849. */
  16850. getCellsRange:function (cellA, cellB) {
  16851. function checkRange(beginRowIndex, beginColIndex, endRowIndex, endColIndex) {
  16852. var tmpBeginRowIndex = beginRowIndex,
  16853. tmpBeginColIndex = beginColIndex,
  16854. tmpEndRowIndex = endRowIndex,
  16855. tmpEndColIndex = endColIndex,
  16856. cellInfo, colIndex, rowIndex;
  16857. // 通过indexTable检查是否存在超出TableRange上边界的情况
  16858. if (beginRowIndex > 0) {
  16859. for (colIndex = beginColIndex; colIndex < endColIndex; colIndex++) {
  16860. cellInfo = me.indexTable[beginRowIndex][colIndex];
  16861. rowIndex = cellInfo.rowIndex;
  16862. if (rowIndex < beginRowIndex) {
  16863. tmpBeginRowIndex = Math.min(rowIndex, tmpBeginRowIndex);
  16864. }
  16865. }
  16866. }
  16867. // 通过indexTable检查是否存在超出TableRange右边界的情况
  16868. if (endColIndex < me.colsNum) {
  16869. for (rowIndex = beginRowIndex; rowIndex < endRowIndex; rowIndex++) {
  16870. cellInfo = me.indexTable[rowIndex][endColIndex];
  16871. colIndex = cellInfo.colIndex + cellInfo.colSpan - 1;
  16872. if (colIndex > endColIndex) {
  16873. tmpEndColIndex = Math.max(colIndex, tmpEndColIndex);
  16874. }
  16875. }
  16876. }
  16877. // 检查是否有超出TableRange下边界的情况
  16878. if (endRowIndex < me.rowsNum) {
  16879. for (colIndex = beginColIndex; colIndex < endColIndex; colIndex++) {
  16880. cellInfo = me.indexTable[endRowIndex][colIndex];
  16881. rowIndex = cellInfo.rowIndex + cellInfo.rowSpan - 1;
  16882. if (rowIndex > endRowIndex) {
  16883. tmpEndRowIndex = Math.max(rowIndex, tmpEndRowIndex);
  16884. }
  16885. }
  16886. }
  16887. // 检查是否有超出TableRange左边界的情况
  16888. if (beginColIndex > 0) {
  16889. for (rowIndex = beginRowIndex; rowIndex < endRowIndex; rowIndex++) {
  16890. cellInfo = me.indexTable[rowIndex][beginColIndex];
  16891. colIndex = cellInfo.colIndex;
  16892. if (colIndex < beginColIndex) {
  16893. tmpBeginColIndex = Math.min(cellInfo.colIndex, tmpBeginColIndex);
  16894. }
  16895. }
  16896. }
  16897. //递归调用直至所有完成所有框选单元格的扩展
  16898. if (tmpBeginRowIndex != beginRowIndex || tmpBeginColIndex != beginColIndex || tmpEndRowIndex != endRowIndex || tmpEndColIndex != endColIndex) {
  16899. return checkRange(tmpBeginRowIndex, tmpBeginColIndex, tmpEndRowIndex, tmpEndColIndex);
  16900. } else {
  16901. // 不需要扩展TableRange的情况
  16902. return {
  16903. beginRowIndex:beginRowIndex,
  16904. beginColIndex:beginColIndex,
  16905. endRowIndex:endRowIndex,
  16906. endColIndex:endColIndex
  16907. };
  16908. }
  16909. }
  16910. try {
  16911. var me = this,
  16912. cellAInfo = me.getCellInfo(cellA);
  16913. if (cellA === cellB) {
  16914. return {
  16915. beginRowIndex:cellAInfo.rowIndex,
  16916. beginColIndex:cellAInfo.colIndex,
  16917. endRowIndex:cellAInfo.rowIndex + cellAInfo.rowSpan - 1,
  16918. endColIndex:cellAInfo.colIndex + cellAInfo.colSpan - 1
  16919. };
  16920. }
  16921. var cellBInfo = me.getCellInfo(cellB);
  16922. // 计算TableRange的四个边
  16923. var beginRowIndex = Math.min(cellAInfo.rowIndex, cellBInfo.rowIndex),
  16924. beginColIndex = Math.min(cellAInfo.colIndex, cellBInfo.colIndex),
  16925. endRowIndex = Math.max(cellAInfo.rowIndex + cellAInfo.rowSpan - 1, cellBInfo.rowIndex + cellBInfo.rowSpan - 1),
  16926. endColIndex = Math.max(cellAInfo.colIndex + cellAInfo.colSpan - 1, cellBInfo.colIndex + cellBInfo.colSpan - 1);
  16927. return checkRange(beginRowIndex, beginColIndex, endRowIndex, endColIndex);
  16928. } catch (e) {
  16929. //throw e;
  16930. }
  16931. },
  16932. /**
  16933. * 依据cellsRange获取对应的单元格集合
  16934. */
  16935. getCells:function (range) {
  16936. //每次获取cells之前必须先清除上次的选择,否则会对后续获取操作造成影响
  16937. this.clearSelected();
  16938. var beginRowIndex = range.beginRowIndex,
  16939. beginColIndex = range.beginColIndex,
  16940. endRowIndex = range.endRowIndex,
  16941. endColIndex = range.endColIndex,
  16942. cellInfo, rowIndex, colIndex, tdHash = {}, returnTds = [];
  16943. for (var i = beginRowIndex; i <= endRowIndex; i++) {
  16944. for (var j = beginColIndex; j <= endColIndex; j++) {
  16945. cellInfo = this.indexTable[i][j];
  16946. rowIndex = cellInfo.rowIndex;
  16947. colIndex = cellInfo.colIndex;
  16948. // 如果Cells里已经包含了此Cell则跳过
  16949. var key = rowIndex + '|' + colIndex;
  16950. if (tdHash[key]) continue;
  16951. tdHash[key] = 1;
  16952. if (rowIndex < i || colIndex < j || rowIndex + cellInfo.rowSpan - 1 > endRowIndex || colIndex + cellInfo.colSpan - 1 > endColIndex) {
  16953. return null;
  16954. }
  16955. returnTds.push(this.getCell(rowIndex, cellInfo.cellIndex));
  16956. }
  16957. }
  16958. return returnTds;
  16959. },
  16960. /**
  16961. * 清理已经选中的单元格
  16962. */
  16963. clearSelected:function () {
  16964. UETable.removeSelectedClass(this.selectedTds);
  16965. this.selectedTds = [];
  16966. this.cellsRange = {};
  16967. },
  16968. /**
  16969. * 根据range设置已经选中的单元格
  16970. */
  16971. setSelected:function (range) {
  16972. var cells = this.getCells(range);
  16973. UETable.addSelectedClass(cells);
  16974. this.selectedTds = cells;
  16975. this.cellsRange = range;
  16976. },
  16977. isFullRow:function () {
  16978. var range = this.cellsRange;
  16979. return (range.endColIndex - range.beginColIndex + 1) == this.colsNum;
  16980. },
  16981. isFullCol:function () {
  16982. var range = this.cellsRange,
  16983. table = this.table,
  16984. ths = table.getElementsByTagName("th"),
  16985. rows = range.endRowIndex - range.beginRowIndex + 1;
  16986. return !ths.length ? rows == this.rowsNum : rows == this.rowsNum || (rows == this.rowsNum - 1);
  16987. },
  16988. /**
  16989. * 获取视觉上的前置单元格,默认是左边,top传入时
  16990. * @param cell
  16991. * @param top
  16992. */
  16993. getNextCell:function (cell, bottom, ignoreRange) {
  16994. try {
  16995. var cellInfo = this.getCellInfo(cell),
  16996. nextRowIndex, nextColIndex;
  16997. var len = this.selectedTds.length && !ignoreRange,
  16998. range = this.cellsRange;
  16999. //末行或者末列没有后置单元格
  17000. if ((!bottom && (cellInfo.rowIndex == 0)) || (bottom && (!len ? (cellInfo.rowIndex + cellInfo.rowSpan > this.rowsNum - 1) : (range.endRowIndex == this.rowsNum - 1)))) return null;
  17001. nextRowIndex = !bottom ? ( !len ? cellInfo.rowIndex - 1 : range.beginRowIndex - 1)
  17002. : ( !len ? (cellInfo.rowIndex + cellInfo.rowSpan) : range.endRowIndex + 1);
  17003. nextColIndex = !len ? cellInfo.colIndex : range.beginColIndex;
  17004. return this.getCell(this.indexTable[nextRowIndex][nextColIndex].rowIndex, this.indexTable[nextRowIndex][nextColIndex].cellIndex);
  17005. } catch (e) {
  17006. showError(e);
  17007. }
  17008. },
  17009. getPreviewCell:function (cell, top) {
  17010. try {
  17011. var cellInfo = this.getCellInfo(cell),
  17012. previewRowIndex, previewColIndex;
  17013. var len = this.selectedTds.length,
  17014. range = this.cellsRange;
  17015. //首行或者首列没有前置单元格
  17016. if ((!top && (!len ? !cellInfo.colIndex : !range.beginColIndex)) || (top && (!len ? (cellInfo.rowIndex > (this.colsNum - 1)) : (range.endColIndex == this.colsNum - 1)))) return null;
  17017. previewRowIndex = !top ? ( !len ? cellInfo.rowIndex : range.beginRowIndex )
  17018. : ( !len ? (cellInfo.rowIndex < 1 ? 0 : (cellInfo.rowIndex - 1)) : range.beginRowIndex);
  17019. previewColIndex = !top ? ( !len ? (cellInfo.colIndex < 1 ? 0 : (cellInfo.colIndex - 1)) : range.beginColIndex - 1)
  17020. : ( !len ? cellInfo.colIndex : range.endColIndex + 1);
  17021. return this.getCell(this.indexTable[previewRowIndex][previewColIndex].rowIndex, this.indexTable[previewRowIndex][previewColIndex].cellIndex);
  17022. } catch (e) {
  17023. showError(e);
  17024. }
  17025. },
  17026. /**
  17027. * 移动单元格中的内容
  17028. */
  17029. moveContent:function (cellTo, cellFrom) {
  17030. if (UETable.isEmptyBlock(cellFrom)) return;
  17031. if (UETable.isEmptyBlock(cellTo)) {
  17032. cellTo.innerHTML = cellFrom.innerHTML;
  17033. return;
  17034. }
  17035. var child = cellTo.lastChild;
  17036. if (child.nodeType == 3 || !dtd.$block[child.tagName]) {
  17037. cellTo.appendChild(cellTo.ownerDocument.createElement('br'))
  17038. }
  17039. while (child = cellFrom.firstChild) {
  17040. cellTo.appendChild(child);
  17041. }
  17042. },
  17043. /**
  17044. * 向右合并单元格
  17045. */
  17046. mergeRight:function (cell) {
  17047. var cellInfo = this.getCellInfo(cell),
  17048. rightColIndex = cellInfo.colIndex + cellInfo.colSpan,
  17049. rightCellInfo = this.indexTable[cellInfo.rowIndex][rightColIndex],
  17050. rightCell = this.getCell(rightCellInfo.rowIndex, rightCellInfo.cellIndex);
  17051. //合并
  17052. cell.colSpan = cellInfo.colSpan + rightCellInfo.colSpan;
  17053. //被合并的单元格不应存在宽度属性
  17054. cell.removeAttribute("width");
  17055. //移动内容
  17056. this.moveContent(cell, rightCell);
  17057. //删掉被合并的Cell
  17058. this.deleteCell(rightCell, rightCellInfo.rowIndex);
  17059. this.update();
  17060. },
  17061. /**
  17062. * 向下合并单元格
  17063. */
  17064. mergeDown:function (cell) {
  17065. var cellInfo = this.getCellInfo(cell),
  17066. downRowIndex = cellInfo.rowIndex + cellInfo.rowSpan,
  17067. downCellInfo = this.indexTable[downRowIndex][cellInfo.colIndex],
  17068. downCell = this.getCell(downCellInfo.rowIndex, downCellInfo.cellIndex);
  17069. cell.rowSpan = cellInfo.rowSpan + downCellInfo.rowSpan;
  17070. cell.removeAttribute("height");
  17071. this.moveContent(cell, downCell);
  17072. this.deleteCell(downCell, downCellInfo.rowIndex);
  17073. this.update();
  17074. },
  17075. /**
  17076. * 合并整个range中的内容
  17077. */
  17078. mergeRange:function () {
  17079. //由于合并操作可以在任意时刻进行,所以无法通过鼠标位置等信息实时生成range,只能通过缓存实例中的cellsRange对象来访问
  17080. var range = this.cellsRange,
  17081. leftTopCell = this.getCell(range.beginRowIndex, this.indexTable[range.beginRowIndex][range.beginColIndex].cellIndex);
  17082. if (leftTopCell.tagName == "TH" && range.endRowIndex !== range.beginRowIndex) {
  17083. var index = this.indexTable,
  17084. info = this.getCellInfo(leftTopCell);
  17085. leftTopCell = this.getCell(1, index[1][info.colIndex].cellIndex);
  17086. range = this.getCellsRange(leftTopCell, this.getCell(index[this.rowsNum - 1][info.colIndex].rowIndex, index[this.rowsNum - 1][info.colIndex].cellIndex));
  17087. }
  17088. // 删除剩余的Cells
  17089. var cells = this.getCells(range);
  17090. for(var i= 0,ci;ci=cells[i++];){
  17091. if (ci !== leftTopCell) {
  17092. this.moveContent(leftTopCell, ci);
  17093. this.deleteCell(ci);
  17094. }
  17095. }
  17096. // 修改左上角Cell的rowSpan和colSpan,并调整宽度属性设置
  17097. leftTopCell.rowSpan = range.endRowIndex - range.beginRowIndex + 1;
  17098. leftTopCell.rowSpan > 1 && leftTopCell.removeAttribute("height");
  17099. leftTopCell.colSpan = range.endColIndex - range.beginColIndex + 1;
  17100. leftTopCell.colSpan > 1 && leftTopCell.removeAttribute("width");
  17101. if (leftTopCell.rowSpan == this.rowsNum && leftTopCell.colSpan != 1) {
  17102. leftTopCell.colSpan = 1;
  17103. }
  17104. if (leftTopCell.colSpan == this.colsNum && leftTopCell.rowSpan != 1) {
  17105. var rowIndex = leftTopCell.parentNode.rowIndex;
  17106. //解决IE下的表格操作问题
  17107. if( this.table.deleteRow ) {
  17108. for (var i = rowIndex+ 1, curIndex=rowIndex+ 1, len=leftTopCell.rowSpan; i < len; i++) {
  17109. this.table.deleteRow(curIndex);
  17110. }
  17111. } else {
  17112. for (var i = 0, len=leftTopCell.rowSpan - 1; i < len; i++) {
  17113. var row = this.table.rows[rowIndex + 1];
  17114. row.parentNode.removeChild(row);
  17115. }
  17116. }
  17117. leftTopCell.rowSpan = 1;
  17118. }
  17119. this.update();
  17120. },
  17121. /**
  17122. * 插入一行单元格
  17123. */
  17124. insertRow:function (rowIndex, sourceCell) {
  17125. var numCols = this.colsNum,
  17126. table = this.table,
  17127. row = table.insertRow(rowIndex), cell,
  17128. isInsertTitle = typeof sourceCell == 'string' && sourceCell.toUpperCase() == 'TH';
  17129. function replaceTdToTh(colIndex, cell, tableRow) {
  17130. if (colIndex == 0) {
  17131. var tr = tableRow.nextSibling || tableRow.previousSibling,
  17132. th = tr.cells[colIndex];
  17133. if (th.tagName == 'TH') {
  17134. th = cell.ownerDocument.createElement("th");
  17135. th.appendChild(cell.firstChild);
  17136. tableRow.insertBefore(th, cell);
  17137. domUtils.remove(cell)
  17138. }
  17139. }else{
  17140. if (cell.tagName == 'TH') {
  17141. var td = cell.ownerDocument.createElement("td");
  17142. td.appendChild(cell.firstChild);
  17143. tableRow.insertBefore(td, cell);
  17144. domUtils.remove(cell)
  17145. }
  17146. }
  17147. }
  17148. //首行直接插入,无需考虑部分单元格被rowspan的情况
  17149. if (rowIndex == 0 || rowIndex == this.rowsNum) {
  17150. for (var colIndex = 0; colIndex < numCols; colIndex++) {
  17151. cell = this.cloneCell(sourceCell, true);
  17152. this.setCellContent(cell);
  17153. cell.getAttribute('vAlign') && cell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17154. row.appendChild(cell);
  17155. if(!isInsertTitle) replaceTdToTh(colIndex, cell, row);
  17156. }
  17157. } else {
  17158. var infoRow = this.indexTable[rowIndex],
  17159. cellIndex = 0;
  17160. for (colIndex = 0; colIndex < numCols; colIndex++) {
  17161. var cellInfo = infoRow[colIndex];
  17162. //如果存在某个单元格的rowspan穿过待插入行的位置,则修改该单元格的rowspan即可,无需插入单元格
  17163. if (cellInfo.rowIndex < rowIndex) {
  17164. cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
  17165. cell.rowSpan = cellInfo.rowSpan + 1;
  17166. } else {
  17167. cell = this.cloneCell(sourceCell, true);
  17168. this.setCellContent(cell);
  17169. row.appendChild(cell);
  17170. }
  17171. if(!isInsertTitle) replaceTdToTh(colIndex, cell, row);
  17172. }
  17173. }
  17174. //框选时插入不触发contentchange,需要手动更新索引。
  17175. this.update();
  17176. return row;
  17177. },
  17178. /**
  17179. * 删除一行单元格
  17180. * @param rowIndex
  17181. */
  17182. deleteRow:function (rowIndex) {
  17183. var row = this.table.rows[rowIndex],
  17184. infoRow = this.indexTable[rowIndex],
  17185. colsNum = this.colsNum,
  17186. count = 0; //处理计数
  17187. for (var colIndex = 0; colIndex < colsNum;) {
  17188. var cellInfo = infoRow[colIndex],
  17189. cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
  17190. if (cell.rowSpan > 1) {
  17191. if (cellInfo.rowIndex == rowIndex) {
  17192. var clone = cell.cloneNode(true);
  17193. clone.rowSpan = cell.rowSpan - 1;
  17194. clone.innerHTML = "";
  17195. cell.rowSpan = 1;
  17196. var nextRowIndex = rowIndex + 1,
  17197. nextRow = this.table.rows[nextRowIndex],
  17198. insertCellIndex,
  17199. preMerged = this.getPreviewMergedCellsNum(nextRowIndex, colIndex) - count;
  17200. if (preMerged < colIndex) {
  17201. insertCellIndex = colIndex - preMerged - 1;
  17202. //nextRow.insertCell(insertCellIndex);
  17203. domUtils.insertAfter(nextRow.cells[insertCellIndex], clone);
  17204. } else {
  17205. if (nextRow.cells.length) nextRow.insertBefore(clone, nextRow.cells[0])
  17206. }
  17207. count += 1;
  17208. //cell.parentNode.removeChild(cell);
  17209. }
  17210. }
  17211. colIndex += cell.colSpan || 1;
  17212. }
  17213. var deleteTds = [], cacheMap = {};
  17214. for (colIndex = 0; colIndex < colsNum; colIndex++) {
  17215. var tmpRowIndex = infoRow[colIndex].rowIndex,
  17216. tmpCellIndex = infoRow[colIndex].cellIndex,
  17217. key = tmpRowIndex + "_" + tmpCellIndex;
  17218. if (cacheMap[key])continue;
  17219. cacheMap[key] = 1;
  17220. cell = this.getCell(tmpRowIndex, tmpCellIndex);
  17221. deleteTds.push(cell);
  17222. }
  17223. var mergeTds = [];
  17224. utils.each(deleteTds, function (td) {
  17225. if (td.rowSpan == 1) {
  17226. td.parentNode.removeChild(td);
  17227. } else {
  17228. mergeTds.push(td);
  17229. }
  17230. });
  17231. utils.each(mergeTds, function (td) {
  17232. td.rowSpan--;
  17233. });
  17234. row.parentNode.removeChild(row);
  17235. //浏览器方法本身存在bug,采用自定义方法删除
  17236. //this.table.deleteRow(rowIndex);
  17237. this.update();
  17238. },
  17239. insertCol:function (colIndex, sourceCell, defaultValue) {
  17240. var rowsNum = this.rowsNum,
  17241. rowIndex = 0,
  17242. tableRow, cell,
  17243. backWidth = parseInt((this.table.offsetWidth - (this.colsNum + 1) * 20 - (this.colsNum + 1)) / (this.colsNum + 1), 10),
  17244. isInsertTitleCol = typeof sourceCell == 'string' && sourceCell.toUpperCase() == 'TH';
  17245. function replaceTdToTh(rowIndex, cell, tableRow) {
  17246. if (rowIndex == 0) {
  17247. var th = cell.nextSibling || cell.previousSibling;
  17248. if (th.tagName == 'TH') {
  17249. th = cell.ownerDocument.createElement("th");
  17250. th.appendChild(cell.firstChild);
  17251. tableRow.insertBefore(th, cell);
  17252. domUtils.remove(cell)
  17253. }
  17254. }else{
  17255. if (cell.tagName == 'TH') {
  17256. var td = cell.ownerDocument.createElement("td");
  17257. td.appendChild(cell.firstChild);
  17258. tableRow.insertBefore(td, cell);
  17259. domUtils.remove(cell)
  17260. }
  17261. }
  17262. }
  17263. var preCell;
  17264. if (colIndex == 0 || colIndex == this.colsNum) {
  17265. for (; rowIndex < rowsNum; rowIndex++) {
  17266. tableRow = this.table.rows[rowIndex];
  17267. preCell = tableRow.cells[colIndex == 0 ? colIndex : tableRow.cells.length];
  17268. cell = this.cloneCell(sourceCell, true); //tableRow.insertCell(colIndex == 0 ? colIndex : tableRow.cells.length);
  17269. this.setCellContent(cell);
  17270. cell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17271. preCell && cell.setAttribute('width', preCell.getAttribute('width'));
  17272. if (!colIndex) {
  17273. tableRow.insertBefore(cell, tableRow.cells[0]);
  17274. } else {
  17275. domUtils.insertAfter(tableRow.cells[tableRow.cells.length - 1], cell);
  17276. }
  17277. if(!isInsertTitleCol) replaceTdToTh(rowIndex, cell, tableRow)
  17278. }
  17279. } else {
  17280. for (; rowIndex < rowsNum; rowIndex++) {
  17281. var cellInfo = this.indexTable[rowIndex][colIndex];
  17282. if (cellInfo.colIndex < colIndex) {
  17283. cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
  17284. cell.colSpan = cellInfo.colSpan + 1;
  17285. } else {
  17286. tableRow = this.table.rows[rowIndex];
  17287. preCell = tableRow.cells[cellInfo.cellIndex];
  17288. cell = this.cloneCell(sourceCell, true);//tableRow.insertCell(cellInfo.cellIndex);
  17289. this.setCellContent(cell);
  17290. cell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17291. preCell && cell.setAttribute('width', preCell.getAttribute('width'));
  17292. //防止IE下报错
  17293. preCell ? tableRow.insertBefore(cell, preCell) : tableRow.appendChild(cell);
  17294. }
  17295. if(!isInsertTitleCol) replaceTdToTh(rowIndex, cell, tableRow);
  17296. }
  17297. }
  17298. //框选时插入不触发contentchange,需要手动更新索引
  17299. this.update();
  17300. this.updateWidth(backWidth, defaultValue || {tdPadding:10, tdBorder:1});
  17301. },
  17302. updateWidth:function (width, defaultValue) {
  17303. var table = this.table,
  17304. tmpWidth = UETable.getWidth(table) - defaultValue.tdPadding * 2 - defaultValue.tdBorder + width;
  17305. if (tmpWidth < table.ownerDocument.body.offsetWidth) {
  17306. table.setAttribute("width", tmpWidth);
  17307. return;
  17308. }
  17309. var tds = domUtils.getElementsByTagName(this.table, "td th");
  17310. utils.each(tds, function (td) {
  17311. td.setAttribute("width", width);
  17312. })
  17313. },
  17314. deleteCol:function (colIndex) {
  17315. var indexTable = this.indexTable,
  17316. tableRows = this.table.rows,
  17317. backTableWidth = this.table.getAttribute("width"),
  17318. backTdWidth = 0,
  17319. rowsNum = this.rowsNum,
  17320. cacheMap = {};
  17321. for (var rowIndex = 0; rowIndex < rowsNum;) {
  17322. var infoRow = indexTable[rowIndex],
  17323. cellInfo = infoRow[colIndex],
  17324. key = cellInfo.rowIndex + '_' + cellInfo.colIndex;
  17325. // 跳过已经处理过的Cell
  17326. if (cacheMap[key])continue;
  17327. cacheMap[key] = 1;
  17328. var cell = this.getCell(cellInfo.rowIndex, cellInfo.cellIndex);
  17329. if (!backTdWidth) backTdWidth = cell && parseInt(cell.offsetWidth / cell.colSpan, 10).toFixed(0);
  17330. // 如果Cell的colSpan大于1, 就修改colSpan, 否则就删掉这个Cell
  17331. if (cell.colSpan > 1) {
  17332. cell.colSpan--;
  17333. } else {
  17334. tableRows[rowIndex].deleteCell(cellInfo.cellIndex);
  17335. }
  17336. rowIndex += cellInfo.rowSpan || 1;
  17337. }
  17338. this.table.setAttribute("width", backTableWidth - backTdWidth);
  17339. this.update();
  17340. },
  17341. splitToCells:function (cell) {
  17342. var me = this,
  17343. cells = this.splitToRows(cell);
  17344. utils.each(cells, function (cell) {
  17345. me.splitToCols(cell);
  17346. })
  17347. },
  17348. splitToRows:function (cell) {
  17349. var cellInfo = this.getCellInfo(cell),
  17350. rowIndex = cellInfo.rowIndex,
  17351. colIndex = cellInfo.colIndex,
  17352. results = [];
  17353. // 修改Cell的rowSpan
  17354. cell.rowSpan = 1;
  17355. results.push(cell);
  17356. // 补齐单元格
  17357. for (var i = rowIndex, endRow = rowIndex + cellInfo.rowSpan; i < endRow; i++) {
  17358. if (i == rowIndex)continue;
  17359. var tableRow = this.table.rows[i],
  17360. tmpCell = tableRow.insertCell(colIndex - this.getPreviewMergedCellsNum(i, colIndex));
  17361. tmpCell.colSpan = cellInfo.colSpan;
  17362. this.setCellContent(tmpCell);
  17363. tmpCell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17364. tmpCell.setAttribute('align', cell.getAttribute('align'));
  17365. if (cell.style.cssText) {
  17366. tmpCell.style.cssText = cell.style.cssText;
  17367. }
  17368. results.push(tmpCell);
  17369. }
  17370. this.update();
  17371. return results;
  17372. },
  17373. getPreviewMergedCellsNum:function (rowIndex, colIndex) {
  17374. var indexRow = this.indexTable[rowIndex],
  17375. num = 0;
  17376. for (var i = 0; i < colIndex;) {
  17377. var colSpan = indexRow[i].colSpan,
  17378. tmpRowIndex = indexRow[i].rowIndex;
  17379. num += (colSpan - (tmpRowIndex == rowIndex ? 1 : 0));
  17380. i += colSpan;
  17381. }
  17382. return num;
  17383. },
  17384. splitToCols:function (cell) {
  17385. var backWidth = (cell.offsetWidth / cell.colSpan - 22).toFixed(0),
  17386. cellInfo = this.getCellInfo(cell),
  17387. rowIndex = cellInfo.rowIndex,
  17388. colIndex = cellInfo.colIndex,
  17389. results = [];
  17390. // 修改Cell的rowSpan
  17391. cell.colSpan = 1;
  17392. cell.setAttribute("width", backWidth);
  17393. results.push(cell);
  17394. // 补齐单元格
  17395. for (var j = colIndex, endCol = colIndex + cellInfo.colSpan; j < endCol; j++) {
  17396. if (j == colIndex)continue;
  17397. var tableRow = this.table.rows[rowIndex],
  17398. tmpCell = tableRow.insertCell(this.indexTable[rowIndex][j].cellIndex + 1);
  17399. tmpCell.rowSpan = cellInfo.rowSpan;
  17400. this.setCellContent(tmpCell);
  17401. tmpCell.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17402. tmpCell.setAttribute('align', cell.getAttribute('align'));
  17403. tmpCell.setAttribute('width', backWidth);
  17404. if (cell.style.cssText) {
  17405. tmpCell.style.cssText = cell.style.cssText;
  17406. }
  17407. //处理th的情况
  17408. if (cell.tagName == 'TH') {
  17409. var th = cell.ownerDocument.createElement('th');
  17410. th.appendChild(tmpCell.firstChild);
  17411. th.setAttribute('vAlign', cell.getAttribute('vAlign'));
  17412. th.rowSpan = tmpCell.rowSpan;
  17413. tableRow.insertBefore(th, tmpCell);
  17414. domUtils.remove(tmpCell);
  17415. }
  17416. results.push(tmpCell);
  17417. }
  17418. this.update();
  17419. return results;
  17420. },
  17421. isLastCell:function (cell, rowsNum, colsNum) {
  17422. rowsNum = rowsNum || this.rowsNum;
  17423. colsNum = colsNum || this.colsNum;
  17424. var cellInfo = this.getCellInfo(cell);
  17425. return ((cellInfo.rowIndex + cellInfo.rowSpan) == rowsNum) &&
  17426. ((cellInfo.colIndex + cellInfo.colSpan) == colsNum);
  17427. },
  17428. getLastCell:function (cells) {
  17429. cells = cells || this.table.getElementsByTagName("td");
  17430. var firstInfo = this.getCellInfo(cells[0]);
  17431. var me = this, last = cells[0],
  17432. tr = last.parentNode,
  17433. cellsNum = 0, cols = 0, rows;
  17434. utils.each(cells, function (cell) {
  17435. if (cell.parentNode == tr)cols += cell.colSpan || 1;
  17436. cellsNum += cell.rowSpan * cell.colSpan || 1;
  17437. });
  17438. rows = cellsNum / cols;
  17439. utils.each(cells, function (cell) {
  17440. if (me.isLastCell(cell, rows, cols)) {
  17441. last = cell;
  17442. return false;
  17443. }
  17444. });
  17445. return last;
  17446. },
  17447. selectRow:function (rowIndex) {
  17448. var indexRow = this.indexTable[rowIndex],
  17449. start = this.getCell(indexRow[0].rowIndex, indexRow[0].cellIndex),
  17450. end = this.getCell(indexRow[this.colsNum - 1].rowIndex, indexRow[this.colsNum - 1].cellIndex),
  17451. range = this.getCellsRange(start, end);
  17452. this.setSelected(range);
  17453. },
  17454. selectTable:function () {
  17455. var tds = this.table.getElementsByTagName("td"),
  17456. range = this.getCellsRange(tds[0], tds[tds.length - 1]);
  17457. this.setSelected(range);
  17458. },
  17459. setBackground:function (cells, value) {
  17460. if (typeof value === "string") {
  17461. utils.each(cells, function (cell) {
  17462. cell.style.backgroundColor = value;
  17463. })
  17464. } else if (typeof value === "object") {
  17465. value = utils.extend({
  17466. repeat:true,
  17467. colorList:["#ddd", "#fff"]
  17468. }, value);
  17469. var rowIndex = this.getCellInfo(cells[0]).rowIndex,
  17470. count = 0,
  17471. colors = value.colorList,
  17472. getColor = function (list, index, repeat) {
  17473. return list[index] ? list[index] : repeat ? list[index % list.length] : "";
  17474. };
  17475. for (var i = 0, cell; cell = cells[i++];) {
  17476. var cellInfo = this.getCellInfo(cell);
  17477. cell.style.backgroundColor = getColor(colors, ((rowIndex + count) == cellInfo.rowIndex) ? count : ++count, value.repeat);
  17478. }
  17479. }
  17480. },
  17481. removeBackground:function (cells) {
  17482. utils.each(cells, function (cell) {
  17483. cell.style.backgroundColor = "";
  17484. })
  17485. }
  17486. };
  17487. function showError(e) {
  17488. }
  17489. })();
  17490. // plugins/table.cmds.js
  17491. /**
  17492. * Created with JetBrains PhpStorm.
  17493. * User: taoqili
  17494. * Date: 13-2-20
  17495. * Time: 下午6:25
  17496. * To change this template use File | Settings | File Templates.
  17497. */
  17498. ;
  17499. (function () {
  17500. var UT = UE.UETable,
  17501. getTableItemsByRange = function (editor) {
  17502. return UT.getTableItemsByRange(editor);
  17503. },
  17504. getUETableBySelected = function (editor) {
  17505. return UT.getUETableBySelected(editor)
  17506. },
  17507. getDefaultValue = function (editor, table) {
  17508. return UT.getDefaultValue(editor, table);
  17509. },
  17510. getUETable = function (tdOrTable) {
  17511. return UT.getUETable(tdOrTable);
  17512. };
  17513. UE.commands['inserttable'] = {
  17514. queryCommandState: function () {
  17515. return getTableItemsByRange(this).table ? -1 : 0;
  17516. },
  17517. execCommand: function (cmd, opt) {
  17518. function createTable(opt, tdWidth) {
  17519. var html = [],
  17520. rowsNum = opt.numRows,
  17521. colsNum = opt.numCols;
  17522. for (var r = 0; r < rowsNum; r++) {
  17523. html.push('<tr' + (r == 0 ? ' class="firstRow"':'') + '>');
  17524. for (var c = 0; c < colsNum; c++) {
  17525. html.push('<td width="' + tdWidth + '" vAlign="' + opt.tdvalign + '" >' + (browser.ie && browser.version < 11 ? domUtils.fillChar : '<br/>') + '</td>')
  17526. }
  17527. html.push('</tr>')
  17528. }
  17529. //禁止指定table-width
  17530. return '<table><tbody>' + html.join('') + '</tbody></table>'
  17531. }
  17532. if (!opt) {
  17533. opt = utils.extend({}, {
  17534. numCols: this.options.defaultCols,
  17535. numRows: this.options.defaultRows,
  17536. tdvalign: this.options.tdvalign
  17537. })
  17538. }
  17539. var me = this;
  17540. var range = this.selection.getRange(),
  17541. start = range.startContainer,
  17542. firstParentBlock = domUtils.findParent(start, function (node) {
  17543. return domUtils.isBlockElm(node);
  17544. }, true) || me.body;
  17545. var defaultValue = getDefaultValue(me),
  17546. tableWidth = firstParentBlock.offsetWidth,
  17547. tdWidth = Math.floor(tableWidth / opt.numCols - defaultValue.tdPadding * 2 - defaultValue.tdBorder);
  17548. //todo其他属性
  17549. !opt.tdvalign && (opt.tdvalign = me.options.tdvalign);
  17550. me.execCommand("inserthtml", createTable(opt, tdWidth));
  17551. }
  17552. };
  17553. UE.commands['insertparagraphbeforetable'] = {
  17554. queryCommandState: function () {
  17555. return getTableItemsByRange(this).cell ? 0 : -1;
  17556. },
  17557. execCommand: function () {
  17558. var table = getTableItemsByRange(this).table;
  17559. if (table) {
  17560. var p = this.document.createElement("p");
  17561. p.innerHTML = browser.ie ? '&nbsp;' : '<br />';
  17562. table.parentNode.insertBefore(p, table);
  17563. this.selection.getRange().setStart(p, 0).setCursor();
  17564. }
  17565. }
  17566. };
  17567. UE.commands['deletetable'] = {
  17568. queryCommandState: function () {
  17569. var rng = this.selection.getRange();
  17570. return domUtils.findParentByTagName(rng.startContainer, 'table', true) ? 0 : -1;
  17571. },
  17572. execCommand: function (cmd, table) {
  17573. var rng = this.selection.getRange();
  17574. table = table || domUtils.findParentByTagName(rng.startContainer, 'table', true);
  17575. if (table) {
  17576. var next = table.nextSibling;
  17577. if (!next) {
  17578. next = domUtils.createElement(this.document, 'p', {
  17579. 'innerHTML': browser.ie ? domUtils.fillChar : '<br/>'
  17580. });
  17581. table.parentNode.insertBefore(next, table);
  17582. }
  17583. domUtils.remove(table);
  17584. rng = this.selection.getRange();
  17585. if (next.nodeType == 3) {
  17586. rng.setStartBefore(next)
  17587. } else {
  17588. rng.setStart(next, 0)
  17589. }
  17590. rng.setCursor(false, true)
  17591. this.fireEvent("tablehasdeleted")
  17592. }
  17593. }
  17594. };
  17595. UE.commands['cellalign'] = {
  17596. queryCommandState: function () {
  17597. return getSelectedArr(this).length ? 0 : -1
  17598. },
  17599. execCommand: function (cmd, align) {
  17600. var selectedTds = getSelectedArr(this);
  17601. if (selectedTds.length) {
  17602. for (var i = 0, ci; ci = selectedTds[i++];) {
  17603. ci.setAttribute('align', align);
  17604. }
  17605. }
  17606. }
  17607. };
  17608. UE.commands['cellvalign'] = {
  17609. queryCommandState: function () {
  17610. return getSelectedArr(this).length ? 0 : -1;
  17611. },
  17612. execCommand: function (cmd, valign) {
  17613. var selectedTds = getSelectedArr(this);
  17614. if (selectedTds.length) {
  17615. for (var i = 0, ci; ci = selectedTds[i++];) {
  17616. ci.setAttribute('vAlign', valign);
  17617. }
  17618. }
  17619. }
  17620. };
  17621. UE.commands['insertcaption'] = {
  17622. queryCommandState: function () {
  17623. var table = getTableItemsByRange(this).table;
  17624. if (table) {
  17625. return table.getElementsByTagName('caption').length == 0 ? 1 : -1;
  17626. }
  17627. return -1;
  17628. },
  17629. execCommand: function () {
  17630. var table = getTableItemsByRange(this).table;
  17631. if (table) {
  17632. var caption = this.document.createElement('caption');
  17633. caption.innerHTML = browser.ie ? domUtils.fillChar : '<br/>';
  17634. table.insertBefore(caption, table.firstChild);
  17635. var range = this.selection.getRange();
  17636. range.setStart(caption, 0).setCursor();
  17637. }
  17638. }
  17639. };
  17640. UE.commands['deletecaption'] = {
  17641. queryCommandState: function () {
  17642. var rng = this.selection.getRange(),
  17643. table = domUtils.findParentByTagName(rng.startContainer, 'table');
  17644. if (table) {
  17645. return table.getElementsByTagName('caption').length == 0 ? -1 : 1;
  17646. }
  17647. return -1;
  17648. },
  17649. execCommand: function () {
  17650. var rng = this.selection.getRange(),
  17651. table = domUtils.findParentByTagName(rng.startContainer, 'table');
  17652. if (table) {
  17653. domUtils.remove(table.getElementsByTagName('caption')[0]);
  17654. var range = this.selection.getRange();
  17655. range.setStart(table.rows[0].cells[0], 0).setCursor();
  17656. }
  17657. }
  17658. };
  17659. UE.commands['inserttitle'] = {
  17660. queryCommandState: function () {
  17661. var table = getTableItemsByRange(this).table;
  17662. if (table) {
  17663. var firstRow = table.rows[0];
  17664. return firstRow.cells[firstRow.cells.length-1].tagName.toLowerCase() != 'th' ? 0 : -1
  17665. }
  17666. return -1;
  17667. },
  17668. execCommand: function () {
  17669. var table = getTableItemsByRange(this).table;
  17670. if (table) {
  17671. getUETable(table).insertRow(0, 'th');
  17672. }
  17673. var th = table.getElementsByTagName('th')[0];
  17674. this.selection.getRange().setStart(th, 0).setCursor(false, true);
  17675. }
  17676. };
  17677. UE.commands['deletetitle'] = {
  17678. queryCommandState: function () {
  17679. var table = getTableItemsByRange(this).table;
  17680. if (table) {
  17681. var firstRow = table.rows[0];
  17682. return firstRow.cells[firstRow.cells.length-1].tagName.toLowerCase() == 'th' ? 0 : -1
  17683. }
  17684. return -1;
  17685. },
  17686. execCommand: function () {
  17687. var table = getTableItemsByRange(this).table;
  17688. if (table) {
  17689. domUtils.remove(table.rows[0])
  17690. }
  17691. var td = table.getElementsByTagName('td')[0];
  17692. this.selection.getRange().setStart(td, 0).setCursor(false, true);
  17693. }
  17694. };
  17695. UE.commands['inserttitlecol'] = {
  17696. queryCommandState: function () {
  17697. var table = getTableItemsByRange(this).table;
  17698. if (table) {
  17699. var lastRow = table.rows[table.rows.length-1];
  17700. return lastRow.getElementsByTagName('th').length ? -1 : 0;
  17701. }
  17702. return -1;
  17703. },
  17704. execCommand: function (cmd) {
  17705. var table = getTableItemsByRange(this).table;
  17706. if (table) {
  17707. getUETable(table).insertCol(0, 'th');
  17708. }
  17709. resetTdWidth(table, this);
  17710. var th = table.getElementsByTagName('th')[0];
  17711. this.selection.getRange().setStart(th, 0).setCursor(false, true);
  17712. }
  17713. };
  17714. UE.commands['deletetitlecol'] = {
  17715. queryCommandState: function () {
  17716. var table = getTableItemsByRange(this).table;
  17717. if (table) {
  17718. var lastRow = table.rows[table.rows.length-1];
  17719. return lastRow.getElementsByTagName('th').length ? 0 : -1;
  17720. }
  17721. return -1;
  17722. },
  17723. execCommand: function () {
  17724. var table = getTableItemsByRange(this).table;
  17725. if (table) {
  17726. for(var i = 0; i< table.rows.length; i++ ){
  17727. domUtils.remove(table.rows[i].children[0])
  17728. }
  17729. }
  17730. resetTdWidth(table, this);
  17731. var td = table.getElementsByTagName('td')[0];
  17732. this.selection.getRange().setStart(td, 0).setCursor(false, true);
  17733. }
  17734. };
  17735. UE.commands["mergeright"] = {
  17736. queryCommandState: function (cmd) {
  17737. var tableItems = getTableItemsByRange(this),
  17738. table = tableItems.table,
  17739. cell = tableItems.cell;
  17740. if (!table || !cell) return -1;
  17741. var ut = getUETable(table);
  17742. if (ut.selectedTds.length) return -1;
  17743. var cellInfo = ut.getCellInfo(cell),
  17744. rightColIndex = cellInfo.colIndex + cellInfo.colSpan;
  17745. if (rightColIndex >= ut.colsNum) return -1; // 如果处于最右边则不能向右合并
  17746. var rightCellInfo = ut.indexTable[cellInfo.rowIndex][rightColIndex],
  17747. rightCell = table.rows[rightCellInfo.rowIndex].cells[rightCellInfo.cellIndex];
  17748. if (!rightCell || cell.tagName != rightCell.tagName) return -1; // TH和TD不能相互合并
  17749. // 当且仅当两个Cell的开始列号和结束列号一致时能进行合并
  17750. return (rightCellInfo.rowIndex == cellInfo.rowIndex && rightCellInfo.rowSpan == cellInfo.rowSpan) ? 0 : -1;
  17751. },
  17752. execCommand: function (cmd) {
  17753. var rng = this.selection.getRange(),
  17754. bk = rng.createBookmark(true);
  17755. var cell = getTableItemsByRange(this).cell,
  17756. ut = getUETable(cell);
  17757. ut.mergeRight(cell);
  17758. rng.moveToBookmark(bk).select();
  17759. }
  17760. };
  17761. UE.commands["mergedown"] = {
  17762. queryCommandState: function (cmd) {
  17763. var tableItems = getTableItemsByRange(this),
  17764. table = tableItems.table,
  17765. cell = tableItems.cell;
  17766. if (!table || !cell) return -1;
  17767. var ut = getUETable(table);
  17768. if (ut.selectedTds.length)return -1;
  17769. var cellInfo = ut.getCellInfo(cell),
  17770. downRowIndex = cellInfo.rowIndex + cellInfo.rowSpan;
  17771. if (downRowIndex >= ut.rowsNum) return -1; // 如果处于最下边则不能向下合并
  17772. var downCellInfo = ut.indexTable[downRowIndex][cellInfo.colIndex],
  17773. downCell = table.rows[downCellInfo.rowIndex].cells[downCellInfo.cellIndex];
  17774. if (!downCell || cell.tagName != downCell.tagName) return -1; // TH和TD不能相互合并
  17775. // 当且仅当两个Cell的开始列号和结束列号一致时能进行合并
  17776. return (downCellInfo.colIndex == cellInfo.colIndex && downCellInfo.colSpan == cellInfo.colSpan) ? 0 : -1;
  17777. },
  17778. execCommand: function () {
  17779. var rng = this.selection.getRange(),
  17780. bk = rng.createBookmark(true);
  17781. var cell = getTableItemsByRange(this).cell,
  17782. ut = getUETable(cell);
  17783. ut.mergeDown(cell);
  17784. rng.moveToBookmark(bk).select();
  17785. }
  17786. };
  17787. UE.commands["mergecells"] = {
  17788. queryCommandState: function () {
  17789. return getUETableBySelected(this) ? 0 : -1;
  17790. },
  17791. execCommand: function () {
  17792. var ut = getUETableBySelected(this);
  17793. if (ut && ut.selectedTds.length) {
  17794. var cell = ut.selectedTds[0];
  17795. ut.mergeRange();
  17796. var rng = this.selection.getRange();
  17797. if (domUtils.isEmptyBlock(cell)) {
  17798. rng.setStart(cell, 0).collapse(true)
  17799. } else {
  17800. rng.selectNodeContents(cell)
  17801. }
  17802. rng.select();
  17803. }
  17804. }
  17805. };
  17806. UE.commands["insertrow"] = {
  17807. queryCommandState: function () {
  17808. var tableItems = getTableItemsByRange(this),
  17809. cell = tableItems.cell;
  17810. return cell && (cell.tagName == "TD" || (cell.tagName == 'TH' && tableItems.tr !== tableItems.table.rows[0])) &&
  17811. getUETable(tableItems.table).rowsNum < this.options.maxRowNum ? 0 : -1;
  17812. },
  17813. execCommand: function () {
  17814. var rng = this.selection.getRange(),
  17815. bk = rng.createBookmark(true);
  17816. var tableItems = getTableItemsByRange(this),
  17817. cell = tableItems.cell,
  17818. table = tableItems.table,
  17819. ut = getUETable(table),
  17820. cellInfo = ut.getCellInfo(cell);
  17821. //ut.insertRow(!ut.selectedTds.length ? cellInfo.rowIndex:ut.cellsRange.beginRowIndex,'');
  17822. if (!ut.selectedTds.length) {
  17823. ut.insertRow(cellInfo.rowIndex, cell);
  17824. } else {
  17825. var range = ut.cellsRange;
  17826. for (var i = 0, len = range.endRowIndex - range.beginRowIndex + 1; i < len; i++) {
  17827. ut.insertRow(range.beginRowIndex, cell);
  17828. }
  17829. }
  17830. rng.moveToBookmark(bk).select();
  17831. if (table.getAttribute("interlaced") === "enabled")this.fireEvent("interlacetable", table);
  17832. }
  17833. };
  17834. //后插入行
  17835. UE.commands["insertrownext"] = {
  17836. queryCommandState: function () {
  17837. var tableItems = getTableItemsByRange(this),
  17838. cell = tableItems.cell;
  17839. return cell && (cell.tagName == "TD") && getUETable(tableItems.table).rowsNum < this.options.maxRowNum ? 0 : -1;
  17840. },
  17841. execCommand: function () {
  17842. var rng = this.selection.getRange(),
  17843. bk = rng.createBookmark(true);
  17844. var tableItems = getTableItemsByRange(this),
  17845. cell = tableItems.cell,
  17846. table = tableItems.table,
  17847. ut = getUETable(table),
  17848. cellInfo = ut.getCellInfo(cell);
  17849. //ut.insertRow(!ut.selectedTds.length? cellInfo.rowIndex + cellInfo.rowSpan : ut.cellsRange.endRowIndex + 1,'');
  17850. if (!ut.selectedTds.length) {
  17851. ut.insertRow(cellInfo.rowIndex + cellInfo.rowSpan, cell);
  17852. } else {
  17853. var range = ut.cellsRange;
  17854. for (var i = 0, len = range.endRowIndex - range.beginRowIndex + 1; i < len; i++) {
  17855. ut.insertRow(range.endRowIndex + 1, cell);
  17856. }
  17857. }
  17858. rng.moveToBookmark(bk).select();
  17859. if (table.getAttribute("interlaced") === "enabled")this.fireEvent("interlacetable", table);
  17860. }
  17861. };
  17862. UE.commands["deleterow"] = {
  17863. queryCommandState: function () {
  17864. var tableItems = getTableItemsByRange(this);
  17865. return tableItems.cell ? 0 : -1;
  17866. },
  17867. execCommand: function () {
  17868. var cell = getTableItemsByRange(this).cell,
  17869. ut = getUETable(cell),
  17870. cellsRange = ut.cellsRange,
  17871. cellInfo = ut.getCellInfo(cell),
  17872. preCell = ut.getVSideCell(cell),
  17873. nextCell = ut.getVSideCell(cell, true),
  17874. rng = this.selection.getRange();
  17875. if (utils.isEmptyObject(cellsRange)) {
  17876. ut.deleteRow(cellInfo.rowIndex);
  17877. } else {
  17878. for (var i = cellsRange.beginRowIndex; i < cellsRange.endRowIndex + 1; i++) {
  17879. ut.deleteRow(cellsRange.beginRowIndex);
  17880. }
  17881. }
  17882. var table = ut.table;
  17883. if (!table.getElementsByTagName('td').length) {
  17884. var nextSibling = table.nextSibling;
  17885. domUtils.remove(table);
  17886. if (nextSibling) {
  17887. rng.setStart(nextSibling, 0).setCursor(false, true);
  17888. }
  17889. } else {
  17890. if (cellInfo.rowSpan == 1 || cellInfo.rowSpan == cellsRange.endRowIndex - cellsRange.beginRowIndex + 1) {
  17891. if (nextCell || preCell) rng.selectNodeContents(nextCell || preCell).setCursor(false, true);
  17892. } else {
  17893. var newCell = ut.getCell(cellInfo.rowIndex, ut.indexTable[cellInfo.rowIndex][cellInfo.colIndex].cellIndex);
  17894. if (newCell) rng.selectNodeContents(newCell).setCursor(false, true);
  17895. }
  17896. }
  17897. if (table.getAttribute("interlaced") === "enabled")this.fireEvent("interlacetable", table);
  17898. }
  17899. };
  17900. UE.commands["insertcol"] = {
  17901. queryCommandState: function (cmd) {
  17902. var tableItems = getTableItemsByRange(this),
  17903. cell = tableItems.cell;
  17904. return cell && (cell.tagName == "TD" || (cell.tagName == 'TH' && cell !== tableItems.tr.cells[0])) &&
  17905. getUETable(tableItems.table).colsNum < this.options.maxColNum ? 0 : -1;
  17906. },
  17907. execCommand: function (cmd) {
  17908. var rng = this.selection.getRange(),
  17909. bk = rng.createBookmark(true);
  17910. if (this.queryCommandState(cmd) == -1)return;
  17911. var cell = getTableItemsByRange(this).cell,
  17912. ut = getUETable(cell),
  17913. cellInfo = ut.getCellInfo(cell);
  17914. //ut.insertCol(!ut.selectedTds.length ? cellInfo.colIndex:ut.cellsRange.beginColIndex);
  17915. if (!ut.selectedTds.length) {
  17916. ut.insertCol(cellInfo.colIndex, cell);
  17917. } else {
  17918. var range = ut.cellsRange;
  17919. for (var i = 0, len = range.endColIndex - range.beginColIndex + 1; i < len; i++) {
  17920. ut.insertCol(range.beginColIndex, cell);
  17921. }
  17922. }
  17923. rng.moveToBookmark(bk).select(true);
  17924. }
  17925. };
  17926. UE.commands["insertcolnext"] = {
  17927. queryCommandState: function () {
  17928. var tableItems = getTableItemsByRange(this),
  17929. cell = tableItems.cell;
  17930. return cell && getUETable(tableItems.table).colsNum < this.options.maxColNum ? 0 : -1;
  17931. },
  17932. execCommand: function () {
  17933. var rng = this.selection.getRange(),
  17934. bk = rng.createBookmark(true);
  17935. var cell = getTableItemsByRange(this).cell,
  17936. ut = getUETable(cell),
  17937. cellInfo = ut.getCellInfo(cell);
  17938. //ut.insertCol(!ut.selectedTds.length ? cellInfo.colIndex + cellInfo.colSpan:ut.cellsRange.endColIndex +1);
  17939. if (!ut.selectedTds.length) {
  17940. ut.insertCol(cellInfo.colIndex + cellInfo.colSpan, cell);
  17941. } else {
  17942. var range = ut.cellsRange;
  17943. for (var i = 0, len = range.endColIndex - range.beginColIndex + 1; i < len; i++) {
  17944. ut.insertCol(range.endColIndex + 1, cell);
  17945. }
  17946. }
  17947. rng.moveToBookmark(bk).select();
  17948. }
  17949. };
  17950. UE.commands["deletecol"] = {
  17951. queryCommandState: function () {
  17952. var tableItems = getTableItemsByRange(this);
  17953. return tableItems.cell ? 0 : -1;
  17954. },
  17955. execCommand: function () {
  17956. var cell = getTableItemsByRange(this).cell,
  17957. ut = getUETable(cell),
  17958. range = ut.cellsRange,
  17959. cellInfo = ut.getCellInfo(cell),
  17960. preCell = ut.getHSideCell(cell),
  17961. nextCell = ut.getHSideCell(cell, true);
  17962. if (utils.isEmptyObject(range)) {
  17963. ut.deleteCol(cellInfo.colIndex);
  17964. } else {
  17965. for (var i = range.beginColIndex; i < range.endColIndex + 1; i++) {
  17966. ut.deleteCol(range.beginColIndex);
  17967. }
  17968. }
  17969. var table = ut.table,
  17970. rng = this.selection.getRange();
  17971. if (!table.getElementsByTagName('td').length) {
  17972. var nextSibling = table.nextSibling;
  17973. domUtils.remove(table);
  17974. if (nextSibling) {
  17975. rng.setStart(nextSibling, 0).setCursor(false, true);
  17976. }
  17977. } else {
  17978. if (domUtils.inDoc(cell, this.document)) {
  17979. rng.setStart(cell, 0).setCursor(false, true);
  17980. } else {
  17981. if (nextCell && domUtils.inDoc(nextCell, this.document)) {
  17982. rng.selectNodeContents(nextCell).setCursor(false, true);
  17983. } else {
  17984. if (preCell && domUtils.inDoc(preCell, this.document)) {
  17985. rng.selectNodeContents(preCell).setCursor(true, true);
  17986. }
  17987. }
  17988. }
  17989. }
  17990. }
  17991. };
  17992. UE.commands["splittocells"] = {
  17993. queryCommandState: function () {
  17994. var tableItems = getTableItemsByRange(this),
  17995. cell = tableItems.cell;
  17996. if (!cell) return -1;
  17997. var ut = getUETable(tableItems.table);
  17998. if (ut.selectedTds.length > 0) return -1;
  17999. return cell && (cell.colSpan > 1 || cell.rowSpan > 1) ? 0 : -1;
  18000. },
  18001. execCommand: function () {
  18002. var rng = this.selection.getRange(),
  18003. bk = rng.createBookmark(true);
  18004. var cell = getTableItemsByRange(this).cell,
  18005. ut = getUETable(cell);
  18006. ut.splitToCells(cell);
  18007. rng.moveToBookmark(bk).select();
  18008. }
  18009. };
  18010. UE.commands["splittorows"] = {
  18011. queryCommandState: function () {
  18012. var tableItems = getTableItemsByRange(this),
  18013. cell = tableItems.cell;
  18014. if (!cell) return -1;
  18015. var ut = getUETable(tableItems.table);
  18016. if (ut.selectedTds.length > 0) return -1;
  18017. return cell && cell.rowSpan > 1 ? 0 : -1;
  18018. },
  18019. execCommand: function () {
  18020. var rng = this.selection.getRange(),
  18021. bk = rng.createBookmark(true);
  18022. var cell = getTableItemsByRange(this).cell,
  18023. ut = getUETable(cell);
  18024. ut.splitToRows(cell);
  18025. rng.moveToBookmark(bk).select();
  18026. }
  18027. };
  18028. UE.commands["splittocols"] = {
  18029. queryCommandState: function () {
  18030. var tableItems = getTableItemsByRange(this),
  18031. cell = tableItems.cell;
  18032. if (!cell) return -1;
  18033. var ut = getUETable(tableItems.table);
  18034. if (ut.selectedTds.length > 0) return -1;
  18035. return cell && cell.colSpan > 1 ? 0 : -1;
  18036. },
  18037. execCommand: function () {
  18038. var rng = this.selection.getRange(),
  18039. bk = rng.createBookmark(true);
  18040. var cell = getTableItemsByRange(this).cell,
  18041. ut = getUETable(cell);
  18042. ut.splitToCols(cell);
  18043. rng.moveToBookmark(bk).select();
  18044. }
  18045. };
  18046. UE.commands["adaptbytext"] =
  18047. UE.commands["adaptbywindow"] = {
  18048. queryCommandState: function () {
  18049. return getTableItemsByRange(this).table ? 0 : -1
  18050. },
  18051. execCommand: function (cmd) {
  18052. var tableItems = getTableItemsByRange(this),
  18053. table = tableItems.table;
  18054. if (table) {
  18055. if (cmd == 'adaptbywindow') {
  18056. resetTdWidth(table, this);
  18057. } else {
  18058. var cells = domUtils.getElementsByTagName(table, "td th");
  18059. utils.each(cells, function (cell) {
  18060. cell.removeAttribute("width");
  18061. });
  18062. table.removeAttribute("width");
  18063. }
  18064. }
  18065. }
  18066. };
  18067. //平均分配各列
  18068. UE.commands['averagedistributecol'] = {
  18069. queryCommandState: function () {
  18070. var ut = getUETableBySelected(this);
  18071. if (!ut) return -1;
  18072. return ut.isFullRow() || ut.isFullCol() ? 0 : -1;
  18073. },
  18074. execCommand: function (cmd) {
  18075. var me = this,
  18076. ut = getUETableBySelected(me);
  18077. function getAverageWidth() {
  18078. var tb = ut.table,
  18079. averageWidth, sumWidth = 0, colsNum = 0,
  18080. tbAttr = getDefaultValue(me, tb);
  18081. if (ut.isFullRow()) {
  18082. sumWidth = tb.offsetWidth;
  18083. colsNum = ut.colsNum;
  18084. } else {
  18085. var begin = ut.cellsRange.beginColIndex,
  18086. end = ut.cellsRange.endColIndex,
  18087. node;
  18088. for (var i = begin; i <= end;) {
  18089. node = ut.selectedTds[i];
  18090. sumWidth += node.offsetWidth;
  18091. i += node.colSpan;
  18092. colsNum += 1;
  18093. }
  18094. }
  18095. averageWidth = Math.ceil(sumWidth / colsNum) - tbAttr.tdBorder * 2 - tbAttr.tdPadding * 2;
  18096. return averageWidth;
  18097. }
  18098. function setAverageWidth(averageWidth) {
  18099. utils.each(domUtils.getElementsByTagName(ut.table, "th"), function (node) {
  18100. node.setAttribute("width", "");
  18101. });
  18102. var cells = ut.isFullRow() ? domUtils.getElementsByTagName(ut.table, "td") : ut.selectedTds;
  18103. utils.each(cells, function (node) {
  18104. if (node.colSpan == 1) {
  18105. node.setAttribute("width", averageWidth);
  18106. }
  18107. });
  18108. }
  18109. if (ut && ut.selectedTds.length) {
  18110. setAverageWidth(getAverageWidth());
  18111. }
  18112. }
  18113. };
  18114. //平均分配各行
  18115. UE.commands['averagedistributerow'] = {
  18116. queryCommandState: function () {
  18117. var ut = getUETableBySelected(this);
  18118. if (!ut) return -1;
  18119. if (ut.selectedTds && /th/ig.test(ut.selectedTds[0].tagName)) return -1;
  18120. return ut.isFullRow() || ut.isFullCol() ? 0 : -1;
  18121. },
  18122. execCommand: function (cmd) {
  18123. var me = this,
  18124. ut = getUETableBySelected(me);
  18125. function getAverageHeight() {
  18126. var averageHeight, rowNum, sumHeight = 0,
  18127. tb = ut.table,
  18128. tbAttr = getDefaultValue(me, tb),
  18129. tdpadding = parseInt(domUtils.getComputedStyle(tb.getElementsByTagName('td')[0], "padding-top"));
  18130. if (ut.isFullCol()) {
  18131. var captionArr = domUtils.getElementsByTagName(tb, "caption"),
  18132. thArr = domUtils.getElementsByTagName(tb, "th"),
  18133. captionHeight, thHeight;
  18134. if (captionArr.length > 0) {
  18135. captionHeight = captionArr[0].offsetHeight;
  18136. }
  18137. if (thArr.length > 0) {
  18138. thHeight = thArr[0].offsetHeight;
  18139. }
  18140. sumHeight = tb.offsetHeight - (captionHeight || 0) - (thHeight || 0);
  18141. rowNum = thArr.length == 0 ? ut.rowsNum : (ut.rowsNum - 1);
  18142. } else {
  18143. var begin = ut.cellsRange.beginRowIndex,
  18144. end = ut.cellsRange.endRowIndex,
  18145. count = 0,
  18146. trs = domUtils.getElementsByTagName(tb, "tr");
  18147. for (var i = begin; i <= end; i++) {
  18148. sumHeight += trs[i].offsetHeight;
  18149. count += 1;
  18150. }
  18151. rowNum = count;
  18152. }
  18153. //ie8下是混杂模式
  18154. if (browser.ie && browser.version < 9) {
  18155. averageHeight = Math.ceil(sumHeight / rowNum);
  18156. } else {
  18157. averageHeight = Math.ceil(sumHeight / rowNum) - tbAttr.tdBorder * 2 - tdpadding * 2;
  18158. }
  18159. return averageHeight;
  18160. }
  18161. function setAverageHeight(averageHeight) {
  18162. var cells = ut.isFullCol() ? domUtils.getElementsByTagName(ut.table, "td") : ut.selectedTds;
  18163. utils.each(cells, function (node) {
  18164. if (node.rowSpan == 1) {
  18165. node.setAttribute("height", averageHeight);
  18166. }
  18167. });
  18168. }
  18169. if (ut && ut.selectedTds.length) {
  18170. setAverageHeight(getAverageHeight());
  18171. }
  18172. }
  18173. };
  18174. //单元格对齐方式
  18175. UE.commands['cellalignment'] = {
  18176. queryCommandState: function () {
  18177. return getTableItemsByRange(this).table ? 0 : -1
  18178. },
  18179. execCommand: function (cmd, data) {
  18180. var me = this,
  18181. ut = getUETableBySelected(me);
  18182. if (!ut) {
  18183. var start = me.selection.getStart(),
  18184. cell = start && domUtils.findParentByTagName(start, ["td", "th", "caption"], true);
  18185. if (!/caption/ig.test(cell.tagName)) {
  18186. domUtils.setAttributes(cell, data);
  18187. } else {
  18188. cell.style.textAlign = data.align;
  18189. cell.style.verticalAlign = data.vAlign;
  18190. }
  18191. me.selection.getRange().setCursor(true);
  18192. } else {
  18193. utils.each(ut.selectedTds, function (cell) {
  18194. domUtils.setAttributes(cell, data);
  18195. });
  18196. }
  18197. },
  18198. /**
  18199. * 查询当前点击的单元格的对齐状态, 如果当前已经选择了多个单元格, 则会返回所有单元格经过统一协调过后的状态
  18200. * @see UE.UETable.getTableCellAlignState
  18201. */
  18202. queryCommandValue: function (cmd) {
  18203. var activeMenuCell = getTableItemsByRange( this).cell;
  18204. if( !activeMenuCell ) {
  18205. activeMenuCell = getSelectedArr(this)[0];
  18206. }
  18207. if (!activeMenuCell) {
  18208. return null;
  18209. } else {
  18210. //获取同时选中的其他单元格
  18211. var cells = UE.UETable.getUETable(activeMenuCell).selectedTds;
  18212. !cells.length && ( cells = activeMenuCell );
  18213. return UE.UETable.getTableCellAlignState(cells);
  18214. }
  18215. }
  18216. };
  18217. //表格对齐方式
  18218. UE.commands['tablealignment'] = {
  18219. queryCommandState: function () {
  18220. if (browser.ie && browser.version < 8) {
  18221. return -1;
  18222. }
  18223. return getTableItemsByRange(this).table ? 0 : -1
  18224. },
  18225. execCommand: function (cmd, value) {
  18226. var me = this,
  18227. start = me.selection.getStart(),
  18228. table = start && domUtils.findParentByTagName(start, ["table"], true);
  18229. if (table) {
  18230. table.setAttribute("align",value);
  18231. }
  18232. }
  18233. };
  18234. //表格属性
  18235. UE.commands['edittable'] = {
  18236. queryCommandState: function () {
  18237. return getTableItemsByRange(this).table ? 0 : -1
  18238. },
  18239. execCommand: function (cmd, color) {
  18240. var rng = this.selection.getRange(),
  18241. table = domUtils.findParentByTagName(rng.startContainer, 'table');
  18242. if (table) {
  18243. var arr = domUtils.getElementsByTagName(table, "td").concat(
  18244. domUtils.getElementsByTagName(table, "th"),
  18245. domUtils.getElementsByTagName(table, "caption")
  18246. );
  18247. utils.each(arr, function (node) {
  18248. node.style.borderColor = color;
  18249. });
  18250. }
  18251. }
  18252. };
  18253. //单元格属性
  18254. UE.commands['edittd'] = {
  18255. queryCommandState: function () {
  18256. return getTableItemsByRange(this).table ? 0 : -1
  18257. },
  18258. execCommand: function (cmd, bkColor) {
  18259. var me = this,
  18260. ut = getUETableBySelected(me);
  18261. if (!ut) {
  18262. var start = me.selection.getStart(),
  18263. cell = start && domUtils.findParentByTagName(start, ["td", "th", "caption"], true);
  18264. if (cell) {
  18265. cell.style.backgroundColor = bkColor;
  18266. }
  18267. } else {
  18268. utils.each(ut.selectedTds, function (cell) {
  18269. cell.style.backgroundColor = bkColor;
  18270. });
  18271. }
  18272. }
  18273. };
  18274. UE.commands["settablebackground"] = {
  18275. queryCommandState: function () {
  18276. return getSelectedArr(this).length > 1 ? 0 : -1;
  18277. },
  18278. execCommand: function (cmd, value) {
  18279. var cells, ut;
  18280. cells = getSelectedArr(this);
  18281. ut = getUETable(cells[0]);
  18282. ut.setBackground(cells, value);
  18283. }
  18284. };
  18285. UE.commands["cleartablebackground"] = {
  18286. queryCommandState: function () {
  18287. var cells = getSelectedArr(this);
  18288. if (!cells.length)return -1;
  18289. for (var i = 0, cell; cell = cells[i++];) {
  18290. if (cell.style.backgroundColor !== "") return 0;
  18291. }
  18292. return -1;
  18293. },
  18294. execCommand: function () {
  18295. var cells = getSelectedArr(this),
  18296. ut = getUETable(cells[0]);
  18297. ut.removeBackground(cells);
  18298. }
  18299. };
  18300. UE.commands["interlacetable"] = UE.commands["uninterlacetable"] = {
  18301. queryCommandState: function (cmd) {
  18302. var table = getTableItemsByRange(this).table;
  18303. if (!table) return -1;
  18304. var interlaced = table.getAttribute("interlaced");
  18305. if (cmd == "interlacetable") {
  18306. //TODO 待定
  18307. //是否需要待定,如果设置,则命令只能单次执行成功,但反射具备toggle效果;否则可以覆盖前次命令,但反射将不存在toggle效果
  18308. return (interlaced === "enabled") ? -1 : 0;
  18309. } else {
  18310. return (!interlaced || interlaced === "disabled") ? -1 : 0;
  18311. }
  18312. },
  18313. execCommand: function (cmd, classList) {
  18314. var table = getTableItemsByRange(this).table;
  18315. if (cmd == "interlacetable") {
  18316. table.setAttribute("interlaced", "enabled");
  18317. this.fireEvent("interlacetable", table, classList);
  18318. } else {
  18319. table.setAttribute("interlaced", "disabled");
  18320. this.fireEvent("uninterlacetable", table);
  18321. }
  18322. }
  18323. };
  18324. UE.commands["setbordervisible"] = {
  18325. queryCommandState: function (cmd) {
  18326. var table = getTableItemsByRange(this).table;
  18327. if (!table) return -1;
  18328. return 0;
  18329. },
  18330. execCommand: function () {
  18331. var table = getTableItemsByRange(this).table;
  18332. utils.each(domUtils.getElementsByTagName(table,'td'),function(td){
  18333. td.style.borderWidth = '1px';
  18334. td.style.borderStyle = 'solid';
  18335. })
  18336. }
  18337. };
  18338. function resetTdWidth(table, editor) {
  18339. var tds = domUtils.getElementsByTagName(table,'td th');
  18340. utils.each(tds, function (td) {
  18341. td.removeAttribute("width");
  18342. });
  18343. table.setAttribute('width', getTableWidth(editor, true, getDefaultValue(editor, table)));
  18344. var tdsWidths = [];
  18345. setTimeout(function () {
  18346. utils.each(tds, function (td) {
  18347. (td.colSpan == 1) && tdsWidths.push(td.offsetWidth)
  18348. })
  18349. utils.each(tds, function (td,i) {
  18350. (td.colSpan == 1) && td.setAttribute("width", tdsWidths[i] + "");
  18351. })
  18352. }, 0);
  18353. }
  18354. function getTableWidth(editor, needIEHack, defaultValue) {
  18355. var body = editor.body;
  18356. return body.offsetWidth - (needIEHack ? parseInt(domUtils.getComputedStyle(body, 'margin-left'), 10) * 2 : 0) - defaultValue.tableBorder * 2 - (editor.options.offsetWidth || 0);
  18357. }
  18358. function getSelectedArr(editor) {
  18359. var cell = getTableItemsByRange(editor).cell;
  18360. if (cell) {
  18361. var ut = getUETable(cell);
  18362. return ut.selectedTds.length ? ut.selectedTds : [cell];
  18363. } else {
  18364. return [];
  18365. }
  18366. }
  18367. })();
  18368. // plugins/table.action.js
  18369. /**
  18370. * Created with JetBrains PhpStorm.
  18371. * User: taoqili
  18372. * Date: 12-10-12
  18373. * Time: 上午10:05
  18374. * To change this template use File | Settings | File Templates.
  18375. */
  18376. UE.plugins['table'] = function () {
  18377. var me = this,
  18378. tabTimer = null,
  18379. //拖动计时器
  18380. tableDragTimer = null,
  18381. //双击计时器
  18382. tableResizeTimer = null,
  18383. //单元格最小宽度
  18384. cellMinWidth = 5,
  18385. isInResizeBuffer = false,
  18386. //单元格边框大小
  18387. cellBorderWidth = 5,
  18388. //鼠标偏移距离
  18389. offsetOfTableCell = 10,
  18390. //记录在有限时间内的点击状态, 共有3个取值, 0, 1, 2。 0代表未初始化, 1代表单击了1次,2代表2次
  18391. singleClickState = 0,
  18392. userActionStatus = null,
  18393. //双击允许的时间范围
  18394. dblclickTime = 360,
  18395. UT = UE.UETable,
  18396. getUETable = function (tdOrTable) {
  18397. return UT.getUETable(tdOrTable);
  18398. },
  18399. getUETableBySelected = function (editor) {
  18400. return UT.getUETableBySelected(editor);
  18401. },
  18402. getDefaultValue = function (editor, table) {
  18403. return UT.getDefaultValue(editor, table);
  18404. },
  18405. removeSelectedClass = function (cells) {
  18406. return UT.removeSelectedClass(cells);
  18407. };
  18408. function showError(e) {
  18409. // throw e;
  18410. }
  18411. me.ready(function(){
  18412. var me = this;
  18413. var orgGetText = me.selection.getText;
  18414. me.selection.getText = function(){
  18415. var table = getUETableBySelected(me);
  18416. if(table){
  18417. var str = '';
  18418. utils.each(table.selectedTds,function(td){
  18419. str += td[browser.ie?'innerText':'textContent'];
  18420. })
  18421. return str;
  18422. }else{
  18423. return orgGetText.call(me.selection)
  18424. }
  18425. }
  18426. })
  18427. //处理拖动及框选相关方法
  18428. var startTd = null, //鼠标按下时的锚点td
  18429. currentTd = null, //当前鼠标经过时的td
  18430. onDrag = "", //指示当前拖动状态,其值可为"","h","v" ,分别表示未拖动状态,横向拖动状态,纵向拖动状态,用于鼠标移动过程中的判断
  18431. onBorder = false, //检测鼠标按下时是否处在单元格边缘位置
  18432. dragButton = null,
  18433. dragOver = false,
  18434. dragLine = null, //模拟的拖动线
  18435. dragTd = null; //发生拖动的目标td
  18436. var mousedown = false,
  18437. //todo 判断混乱模式
  18438. needIEHack = true;
  18439. me.setOpt({
  18440. 'maxColNum':20,
  18441. 'maxRowNum':100,
  18442. 'defaultCols':5,
  18443. 'defaultRows':5,
  18444. 'tdvalign':'top',
  18445. 'cursorpath':me.options.UEDITOR_HOME_URL + "themes/default/images/cursor_",
  18446. 'tableDragable':false,
  18447. 'classList':["ue-table-interlace-color-single","ue-table-interlace-color-double"]
  18448. });
  18449. me.getUETable = getUETable;
  18450. var commands = {
  18451. 'deletetable':1,
  18452. 'inserttable':1,
  18453. 'cellvalign':1,
  18454. 'insertcaption':1,
  18455. 'deletecaption':1,
  18456. 'inserttitle':1,
  18457. 'deletetitle':1,
  18458. "mergeright":1,
  18459. "mergedown":1,
  18460. "mergecells":1,
  18461. "insertrow":1,
  18462. "insertrownext":1,
  18463. "deleterow":1,
  18464. "insertcol":1,
  18465. "insertcolnext":1,
  18466. "deletecol":1,
  18467. "splittocells":1,
  18468. "splittorows":1,
  18469. "splittocols":1,
  18470. "adaptbytext":1,
  18471. "adaptbywindow":1,
  18472. "adaptbycustomer":1,
  18473. "insertparagraph":1,
  18474. "insertparagraphbeforetable":1,
  18475. "averagedistributecol":1,
  18476. "averagedistributerow":1
  18477. };
  18478. me.ready(function () {
  18479. utils.cssRule('table',
  18480. //选中的td上的样式
  18481. '.selectTdClass{background-color:#edf5fa !important}' +
  18482. 'table.noBorderTable td,table.noBorderTable th,table.noBorderTable caption{border:1px dashed #ddd !important}' +
  18483. //插入的表格的默认样式
  18484. 'table{margin-bottom:10px;border-collapse:collapse;display:table;}' +
  18485. 'td,th{padding: 5px 10px;border: 1px solid #DDD;}' +
  18486. 'caption{border:1px dashed #DDD;border-bottom:0;padding:3px;text-align:center;}' +
  18487. 'th{border-top:1px solid #BBB;background-color:#F7F7F7;}' +
  18488. 'table tr.firstRow th{border-top-width:2px;}' +
  18489. '.ue-table-interlace-color-single{ background-color: #fcfcfc; } .ue-table-interlace-color-double{ background-color: #f7faff; }' +
  18490. 'td p{margin:0;padding:0;}', me.document);
  18491. var tableCopyList, isFullCol, isFullRow;
  18492. //注册del/backspace事件
  18493. me.addListener('keydown', function (cmd, evt) {
  18494. var me = this;
  18495. var keyCode = evt.keyCode || evt.which;
  18496. if (keyCode == 8) {
  18497. var ut = getUETableBySelected(me);
  18498. if (ut && ut.selectedTds.length) {
  18499. if (ut.isFullCol()) {
  18500. me.execCommand('deletecol')
  18501. } else if (ut.isFullRow()) {
  18502. me.execCommand('deleterow')
  18503. } else {
  18504. me.fireEvent('delcells');
  18505. }
  18506. domUtils.preventDefault(evt);
  18507. }
  18508. var caption = domUtils.findParentByTagName(me.selection.getStart(), 'caption', true),
  18509. range = me.selection.getRange();
  18510. if (range.collapsed && caption && isEmptyBlock(caption)) {
  18511. me.fireEvent('saveScene');
  18512. var table = caption.parentNode;
  18513. domUtils.remove(caption);
  18514. if (table) {
  18515. range.setStart(table.rows[0].cells[0], 0).setCursor(false, true);
  18516. }
  18517. me.fireEvent('saveScene');
  18518. }
  18519. }
  18520. if (keyCode == 46) {
  18521. ut = getUETableBySelected(me);
  18522. if (ut) {
  18523. me.fireEvent('saveScene');
  18524. for (var i = 0, ci; ci = ut.selectedTds[i++];) {
  18525. domUtils.fillNode(me.document, ci)
  18526. }
  18527. me.fireEvent('saveScene');
  18528. domUtils.preventDefault(evt);
  18529. }
  18530. }
  18531. if (keyCode == 13) {
  18532. var rng = me.selection.getRange(),
  18533. caption = domUtils.findParentByTagName(rng.startContainer, 'caption', true);
  18534. if (caption) {
  18535. var table = domUtils.findParentByTagName(caption, 'table');
  18536. if (!rng.collapsed) {
  18537. rng.deleteContents();
  18538. me.fireEvent('saveScene');
  18539. } else {
  18540. if (caption) {
  18541. rng.setStart(table.rows[0].cells[0], 0).setCursor(false, true);
  18542. }
  18543. }
  18544. domUtils.preventDefault(evt);
  18545. return;
  18546. }
  18547. if (rng.collapsed) {
  18548. var table = domUtils.findParentByTagName(rng.startContainer, 'table');
  18549. if (table) {
  18550. var cell = table.rows[0].cells[0],
  18551. start = domUtils.findParentByTagName(me.selection.getStart(), ['td', 'th'], true),
  18552. preNode = table.previousSibling;
  18553. if (cell === start && (!preNode || preNode.nodeType == 1 && preNode.tagName == 'TABLE' ) && domUtils.isStartInblock(rng)) {
  18554. var first = domUtils.findParent(me.selection.getStart(), function(n){return domUtils.isBlockElm(n)}, true);
  18555. if(first && ( /t(h|d)/i.test(first.tagName) || first === start.firstChild )){
  18556. me.execCommand('insertparagraphbeforetable');
  18557. domUtils.preventDefault(evt);
  18558. }
  18559. }
  18560. }
  18561. }
  18562. }
  18563. if ((evt.ctrlKey || evt.metaKey) && evt.keyCode == '67') {
  18564. tableCopyList = null;
  18565. var ut = getUETableBySelected(me);
  18566. if (ut) {
  18567. var tds = ut.selectedTds;
  18568. isFullCol = ut.isFullCol();
  18569. isFullRow = ut.isFullRow();
  18570. tableCopyList = [
  18571. [ut.cloneCell(tds[0],null,true)]
  18572. ];
  18573. for (var i = 1, ci; ci = tds[i]; i++) {
  18574. if (ci.parentNode !== tds[i - 1].parentNode) {
  18575. tableCopyList.push([ut.cloneCell(ci,null,true)]);
  18576. } else {
  18577. tableCopyList[tableCopyList.length - 1].push(ut.cloneCell(ci,null,true));
  18578. }
  18579. }
  18580. }
  18581. }
  18582. });
  18583. me.addListener("tablehasdeleted",function(){
  18584. toggleDraggableState(this, false, "", null);
  18585. if (dragButton)domUtils.remove(dragButton);
  18586. });
  18587. me.addListener('beforepaste', function (cmd, html) {
  18588. var me = this;
  18589. var rng = me.selection.getRange();
  18590. if (domUtils.findParentByTagName(rng.startContainer, 'caption', true)) {
  18591. var div = me.document.createElement("div");
  18592. div.innerHTML = html.html;
  18593. //trace:3729
  18594. html.html = div[browser.ie9below ? 'innerText' : 'textContent'];
  18595. return;
  18596. }
  18597. var table = getUETableBySelected(me);
  18598. if (tableCopyList) {
  18599. me.fireEvent('saveScene');
  18600. var rng = me.selection.getRange();
  18601. var td = domUtils.findParentByTagName(rng.startContainer, ['td', 'th'], true), tmpNode, preNode;
  18602. if (td) {
  18603. var ut = getUETable(td);
  18604. if (isFullRow) {
  18605. var rowIndex = ut.getCellInfo(td).rowIndex;
  18606. if (td.tagName == 'TH') {
  18607. rowIndex++;
  18608. }
  18609. for (var i = 0, ci; ci = tableCopyList[i++];) {
  18610. var tr = ut.insertRow(rowIndex++, "td");
  18611. for (var j = 0, cj; cj = ci[j]; j++) {
  18612. var cell = tr.cells[j];
  18613. if (!cell) {
  18614. cell = tr.insertCell(j)
  18615. }
  18616. cell.innerHTML = cj.innerHTML;
  18617. cj.getAttribute('width') && cell.setAttribute('width', cj.getAttribute('width'));
  18618. cj.getAttribute('vAlign') && cell.setAttribute('vAlign', cj.getAttribute('vAlign'));
  18619. cj.getAttribute('align') && cell.setAttribute('align', cj.getAttribute('align'));
  18620. cj.style.cssText && (cell.style.cssText = cj.style.cssText)
  18621. }
  18622. for (var j = 0, cj; cj = tr.cells[j]; j++) {
  18623. if (!ci[j])
  18624. break;
  18625. cj.innerHTML = ci[j].innerHTML;
  18626. ci[j].getAttribute('width') && cj.setAttribute('width', ci[j].getAttribute('width'));
  18627. ci[j].getAttribute('vAlign') && cj.setAttribute('vAlign', ci[j].getAttribute('vAlign'));
  18628. ci[j].getAttribute('align') && cj.setAttribute('align', ci[j].getAttribute('align'));
  18629. ci[j].style.cssText && (cj.style.cssText = ci[j].style.cssText)
  18630. }
  18631. }
  18632. } else {
  18633. if (isFullCol) {
  18634. cellInfo = ut.getCellInfo(td);
  18635. var maxColNum = 0;
  18636. for (var j = 0, ci = tableCopyList[0], cj; cj = ci[j++];) {
  18637. maxColNum += cj.colSpan || 1;
  18638. }
  18639. me.__hasEnterExecCommand = true;
  18640. for (i = 0; i < maxColNum; i++) {
  18641. me.execCommand('insertcol');
  18642. }
  18643. me.__hasEnterExecCommand = false;
  18644. td = ut.table.rows[0].cells[cellInfo.cellIndex];
  18645. if (td.tagName == 'TH') {
  18646. td = ut.table.rows[1].cells[cellInfo.cellIndex];
  18647. }
  18648. }
  18649. for (var i = 0, ci; ci = tableCopyList[i++];) {
  18650. tmpNode = td;
  18651. for (var j = 0, cj; cj = ci[j++];) {
  18652. if (td) {
  18653. td.innerHTML = cj.innerHTML;
  18654. //todo 定制处理
  18655. cj.getAttribute('width') && td.setAttribute('width', cj.getAttribute('width'));
  18656. cj.getAttribute('vAlign') && td.setAttribute('vAlign', cj.getAttribute('vAlign'));
  18657. cj.getAttribute('align') && td.setAttribute('align', cj.getAttribute('align'));
  18658. cj.style.cssText && (td.style.cssText = cj.style.cssText);
  18659. preNode = td;
  18660. td = td.nextSibling;
  18661. } else {
  18662. var cloneTd = cj.cloneNode(true);
  18663. domUtils.removeAttributes(cloneTd, ['class', 'rowSpan', 'colSpan']);
  18664. preNode.parentNode.appendChild(cloneTd)
  18665. }
  18666. }
  18667. td = ut.getNextCell(tmpNode, true, true);
  18668. if (!tableCopyList[i])
  18669. break;
  18670. if (!td) {
  18671. var cellInfo = ut.getCellInfo(tmpNode);
  18672. ut.table.insertRow(ut.table.rows.length);
  18673. ut.update();
  18674. td = ut.getVSideCell(tmpNode, true);
  18675. }
  18676. }
  18677. }
  18678. ut.update();
  18679. } else {
  18680. table = me.document.createElement('table');
  18681. for (var i = 0, ci; ci = tableCopyList[i++];) {
  18682. var tr = table.insertRow(table.rows.length);
  18683. for (var j = 0, cj; cj = ci[j++];) {
  18684. cloneTd = UT.cloneCell(cj,null,true);
  18685. domUtils.removeAttributes(cloneTd, ['class']);
  18686. tr.appendChild(cloneTd)
  18687. }
  18688. if (j == 2 && cloneTd.rowSpan > 1) {
  18689. cloneTd.rowSpan = 1;
  18690. }
  18691. }
  18692. var defaultValue = getDefaultValue(me),
  18693. width = me.body.offsetWidth -
  18694. (needIEHack ? parseInt(domUtils.getComputedStyle(me.body, 'margin-left'), 10) * 2 : 0) - defaultValue.tableBorder * 2 - (me.options.offsetWidth || 0);
  18695. me.execCommand('insertHTML', '<table ' +
  18696. ( isFullCol && isFullRow ? 'width="' + width + '"' : '') +
  18697. '>' + table.innerHTML.replace(/>\s*</g, '><').replace(/\bth\b/gi, "td") + '</table>')
  18698. }
  18699. me.fireEvent('contentchange');
  18700. me.fireEvent('saveScene');
  18701. html.html = '';
  18702. return true;
  18703. } else {
  18704. var div = me.document.createElement("div"), tables;
  18705. div.innerHTML = html.html;
  18706. tables = div.getElementsByTagName("table");
  18707. if (domUtils.findParentByTagName(me.selection.getStart(), 'table')) {
  18708. utils.each(tables, function (t) {
  18709. domUtils.remove(t)
  18710. });
  18711. if (domUtils.findParentByTagName(me.selection.getStart(), 'caption', true)) {
  18712. div.innerHTML = div[browser.ie ? 'innerText' : 'textContent'];
  18713. }
  18714. } else {
  18715. utils.each(tables, function (table) {
  18716. removeStyleSize(table, true);
  18717. domUtils.removeAttributes(table, ['style', 'border']);
  18718. utils.each(domUtils.getElementsByTagName(table, "td"), function (td) {
  18719. if (isEmptyBlock(td)) {
  18720. domUtils.fillNode(me.document, td);
  18721. }
  18722. removeStyleSize(td, true);
  18723. // domUtils.removeAttributes(td, ['style'])
  18724. });
  18725. });
  18726. }
  18727. html.html = div.innerHTML;
  18728. }
  18729. });
  18730. me.addListener('afterpaste', function () {
  18731. utils.each(domUtils.getElementsByTagName(me.body, "table"), function (table) {
  18732. if (table.offsetWidth > me.body.offsetWidth) {
  18733. var defaultValue = getDefaultValue(me, table);
  18734. 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'
  18735. }
  18736. })
  18737. });
  18738. me.addListener('blur', function () {
  18739. tableCopyList = null;
  18740. });
  18741. var timer;
  18742. me.addListener('keydown', function () {
  18743. clearTimeout(timer);
  18744. timer = setTimeout(function () {
  18745. var rng = me.selection.getRange(),
  18746. cell = domUtils.findParentByTagName(rng.startContainer, ['th', 'td'], true);
  18747. if (cell) {
  18748. var table = cell.parentNode.parentNode.parentNode;
  18749. if (table.offsetWidth > table.getAttribute("width")) {
  18750. cell.style.wordBreak = "break-all";
  18751. }
  18752. }
  18753. }, 100);
  18754. });
  18755. me.addListener("selectionchange", function () {
  18756. toggleDraggableState(me, false, "", null);
  18757. });
  18758. //内容变化时触发索引更新
  18759. //todo 可否考虑标记检测,如果不涉及表格的变化就不进行索引重建和更新
  18760. me.addListener("contentchange", function () {
  18761. var me = this;
  18762. //尽可能排除一些不需要更新的状况
  18763. hideDragLine(me);
  18764. if (getUETableBySelected(me))return;
  18765. var rng = me.selection.getRange();
  18766. var start = rng.startContainer;
  18767. start = domUtils.findParentByTagName(start, ['td', 'th'], true);
  18768. utils.each(domUtils.getElementsByTagName(me.document, 'table'), function (table) {
  18769. if (me.fireEvent("excludetable", table) === true) return;
  18770. table.ueTable = new UT(table);
  18771. //trace:3742
  18772. // utils.each(domUtils.getElementsByTagName(me.document, 'td'), function (td) {
  18773. //
  18774. // if (domUtils.isEmptyBlock(td) && td !== start) {
  18775. // domUtils.fillNode(me.document, td);
  18776. // if (browser.ie && browser.version == 6) {
  18777. // td.innerHTML = '&nbsp;'
  18778. // }
  18779. // }
  18780. // });
  18781. // utils.each(domUtils.getElementsByTagName(me.document, 'th'), function (th) {
  18782. // if (domUtils.isEmptyBlock(th) && th !== start) {
  18783. // domUtils.fillNode(me.document, th);
  18784. // if (browser.ie && browser.version == 6) {
  18785. // th.innerHTML = '&nbsp;'
  18786. // }
  18787. // }
  18788. // });
  18789. table.onmouseover = function () {
  18790. me.fireEvent('tablemouseover', table);
  18791. };
  18792. table.onmousemove = function () {
  18793. me.fireEvent('tablemousemove', table);
  18794. me.options.tableDragable && toggleDragButton(true, this, me);
  18795. utils.defer(function(){
  18796. me.fireEvent('contentchange',50)
  18797. },true)
  18798. };
  18799. table.onmouseout = function () {
  18800. me.fireEvent('tablemouseout', table);
  18801. toggleDraggableState(me, false, "", null);
  18802. hideDragLine(me);
  18803. };
  18804. table.onclick = function (evt) {
  18805. evt = me.window.event || evt;
  18806. var target = getParentTdOrTh(evt.target || evt.srcElement);
  18807. if (!target)return;
  18808. var ut = getUETable(target),
  18809. table = ut.table,
  18810. cellInfo = ut.getCellInfo(target),
  18811. cellsRange,
  18812. rng = me.selection.getRange();
  18813. // if ("topLeft" == inPosition(table, mouseCoords(evt))) {
  18814. // cellsRange = ut.getCellsRange(ut.table.rows[0].cells[0], ut.getLastCell());
  18815. // ut.setSelected(cellsRange);
  18816. // return;
  18817. // }
  18818. // if ("bottomRight" == inPosition(table, mouseCoords(evt))) {
  18819. //
  18820. // return;
  18821. // }
  18822. if (inTableSide(table, target, evt, true)) {
  18823. var endTdCol = ut.getCell(ut.indexTable[ut.rowsNum - 1][cellInfo.colIndex].rowIndex, ut.indexTable[ut.rowsNum - 1][cellInfo.colIndex].cellIndex);
  18824. if (evt.shiftKey && ut.selectedTds.length) {
  18825. if (ut.selectedTds[0] !== endTdCol) {
  18826. cellsRange = ut.getCellsRange(ut.selectedTds[0], endTdCol);
  18827. ut.setSelected(cellsRange);
  18828. } else {
  18829. rng && rng.selectNodeContents(endTdCol).select();
  18830. }
  18831. } else {
  18832. if (target !== endTdCol) {
  18833. cellsRange = ut.getCellsRange(target, endTdCol);
  18834. ut.setSelected(cellsRange);
  18835. } else {
  18836. rng && rng.selectNodeContents(endTdCol).select();
  18837. }
  18838. }
  18839. return;
  18840. }
  18841. if (inTableSide(table, target, evt)) {
  18842. var endTdRow = ut.getCell(ut.indexTable[cellInfo.rowIndex][ut.colsNum - 1].rowIndex, ut.indexTable[cellInfo.rowIndex][ut.colsNum - 1].cellIndex);
  18843. if (evt.shiftKey && ut.selectedTds.length) {
  18844. if (ut.selectedTds[0] !== endTdRow) {
  18845. cellsRange = ut.getCellsRange(ut.selectedTds[0], endTdRow);
  18846. ut.setSelected(cellsRange);
  18847. } else {
  18848. rng && rng.selectNodeContents(endTdRow).select();
  18849. }
  18850. } else {
  18851. if (target !== endTdRow) {
  18852. cellsRange = ut.getCellsRange(target, endTdRow);
  18853. ut.setSelected(cellsRange);
  18854. } else {
  18855. rng && rng.selectNodeContents(endTdRow).select();
  18856. }
  18857. }
  18858. }
  18859. };
  18860. });
  18861. switchBorderColor(me, true);
  18862. });
  18863. domUtils.on(me.document, "mousemove", mouseMoveEvent);
  18864. domUtils.on(me.document, "mouseout", function (evt) {
  18865. var target = evt.target || evt.srcElement;
  18866. if (target.tagName == "TABLE") {
  18867. toggleDraggableState(me, false, "", null);
  18868. }
  18869. });
  18870. /**
  18871. * 表格隔行变色
  18872. */
  18873. me.addListener("interlacetable",function(type,table,classList){
  18874. if(!table) return;
  18875. var me = this,
  18876. rows = table.rows,
  18877. len = rows.length,
  18878. getClass = function(list,index,repeat){
  18879. return list[index] ? list[index] : repeat ? list[index % list.length]: "";
  18880. };
  18881. for(var i = 0;i<len;i++){
  18882. rows[i].className = getClass( classList|| me.options.classList,i,true);
  18883. }
  18884. });
  18885. me.addListener("uninterlacetable",function(type,table){
  18886. if(!table) return;
  18887. var me = this,
  18888. rows = table.rows,
  18889. classList = me.options.classList,
  18890. len = rows.length;
  18891. for(var i = 0;i<len;i++){
  18892. domUtils.removeClasses( rows[i], classList );
  18893. }
  18894. });
  18895. me.addListener("mousedown", mouseDownEvent);
  18896. me.addListener("mouseup", mouseUpEvent);
  18897. //拖动的时候触发mouseup
  18898. domUtils.on( me.body, 'dragstart', function( evt ){
  18899. mouseUpEvent.call( me, 'dragstart', evt );
  18900. });
  18901. me.addOutputRule(function(root){
  18902. utils.each(root.getNodesByTagName('div'),function(n){
  18903. if (n.getAttr('id') == 'ue_tableDragLine') {
  18904. n.parentNode.removeChild(n);
  18905. }
  18906. });
  18907. });
  18908. var currentRowIndex = 0;
  18909. me.addListener("mousedown", function () {
  18910. currentRowIndex = 0;
  18911. });
  18912. me.addListener('tabkeydown', function () {
  18913. var range = this.selection.getRange(),
  18914. common = range.getCommonAncestor(true, true),
  18915. table = domUtils.findParentByTagName(common, 'table');
  18916. if (table) {
  18917. if (domUtils.findParentByTagName(common, 'caption', true)) {
  18918. var cell = domUtils.getElementsByTagName(table, 'th td');
  18919. if (cell && cell.length) {
  18920. range.setStart(cell[0], 0).setCursor(false, true)
  18921. }
  18922. } else {
  18923. var cell = domUtils.findParentByTagName(common, ['td', 'th'], true),
  18924. ua = getUETable(cell);
  18925. currentRowIndex = cell.rowSpan > 1 ? currentRowIndex : ua.getCellInfo(cell).rowIndex;
  18926. var nextCell = ua.getTabNextCell(cell, currentRowIndex);
  18927. if (nextCell) {
  18928. if (isEmptyBlock(nextCell)) {
  18929. range.setStart(nextCell, 0).setCursor(false, true)
  18930. } else {
  18931. range.selectNodeContents(nextCell).select()
  18932. }
  18933. } else {
  18934. me.fireEvent('saveScene');
  18935. me.__hasEnterExecCommand = true;
  18936. this.execCommand('insertrownext');
  18937. me.__hasEnterExecCommand = false;
  18938. range = this.selection.getRange();
  18939. range.setStart(table.rows[table.rows.length - 1].cells[0], 0).setCursor();
  18940. me.fireEvent('saveScene');
  18941. }
  18942. }
  18943. return true;
  18944. }
  18945. });
  18946. browser.ie && me.addListener('selectionchange', function () {
  18947. toggleDraggableState(this, false, "", null);
  18948. });
  18949. me.addListener("keydown", function (type, evt) {
  18950. var me = this;
  18951. //处理在表格的最后一个输入tab产生新的表格
  18952. var keyCode = evt.keyCode || evt.which;
  18953. if (keyCode == 8 || keyCode == 46) {
  18954. return;
  18955. }
  18956. var notCtrlKey = !evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey;
  18957. notCtrlKey && removeSelectedClass(domUtils.getElementsByTagName(me.body, "td"));
  18958. var ut = getUETableBySelected(me);
  18959. if (!ut) return;
  18960. notCtrlKey && ut.clearSelected();
  18961. });
  18962. me.addListener("beforegetcontent", function () {
  18963. switchBorderColor(this, false);
  18964. browser.ie && utils.each(this.document.getElementsByTagName('caption'), function (ci) {
  18965. if (domUtils.isEmptyNode(ci)) {
  18966. ci.innerHTML = '&nbsp;'
  18967. }
  18968. });
  18969. });
  18970. me.addListener("aftergetcontent", function () {
  18971. switchBorderColor(this, true);
  18972. });
  18973. me.addListener("getAllHtml", function () {
  18974. removeSelectedClass(me.document.getElementsByTagName("td"));
  18975. });
  18976. //修正全屏状态下插入的表格宽度在非全屏状态下撑开编辑器的情况
  18977. me.addListener("fullscreenchanged", function (type, fullscreen) {
  18978. if (!fullscreen) {
  18979. var ratio = this.body.offsetWidth / document.body.offsetWidth,
  18980. tables = domUtils.getElementsByTagName(this.body, "table");
  18981. utils.each(tables, function (table) {
  18982. if (table.offsetWidth < me.body.offsetWidth) return false;
  18983. var tds = domUtils.getElementsByTagName(table, "td"),
  18984. backWidths = [];
  18985. utils.each(tds, function (td) {
  18986. backWidths.push(td.offsetWidth);
  18987. });
  18988. for (var i = 0, td; td = tds[i]; i++) {
  18989. td.setAttribute("width", Math.floor(backWidths[i] * ratio));
  18990. }
  18991. table.setAttribute("width", Math.floor(getTableWidth(me, needIEHack, getDefaultValue(me))))
  18992. });
  18993. }
  18994. });
  18995. //重写execCommand命令,用于处理框选时的处理
  18996. var oldExecCommand = me.execCommand;
  18997. me.execCommand = function (cmd, datatat) {
  18998. var me = this,
  18999. args = arguments;
  19000. cmd = cmd.toLowerCase();
  19001. var ut = getUETableBySelected(me), tds,
  19002. range = new dom.Range(me.document),
  19003. cmdFun = me.commands[cmd] || UE.commands[cmd],
  19004. result;
  19005. if (!cmdFun) return;
  19006. if (ut && !commands[cmd] && !cmdFun.notNeedUndo && !me.__hasEnterExecCommand) {
  19007. me.__hasEnterExecCommand = true;
  19008. me.fireEvent("beforeexeccommand", cmd);
  19009. tds = ut.selectedTds;
  19010. var lastState = -2, lastValue = -2, value, state;
  19011. for (var i = 0, td; td = tds[i]; i++) {
  19012. if (isEmptyBlock(td)) {
  19013. range.setStart(td, 0).setCursor(false, true)
  19014. } else {
  19015. range.selectNode(td).select(true);
  19016. }
  19017. state = me.queryCommandState(cmd);
  19018. value = me.queryCommandValue(cmd);
  19019. if (state != -1) {
  19020. if (lastState !== state || lastValue !== value) {
  19021. me._ignoreContentChange = true;
  19022. result = oldExecCommand.apply(me, arguments);
  19023. me._ignoreContentChange = false;
  19024. }
  19025. lastState = me.queryCommandState(cmd);
  19026. lastValue = me.queryCommandValue(cmd);
  19027. if (domUtils.isEmptyBlock(td)) {
  19028. domUtils.fillNode(me.document, td)
  19029. }
  19030. }
  19031. }
  19032. range.setStart(tds[0], 0).shrinkBoundary(true).setCursor(false, true);
  19033. me.fireEvent('contentchange');
  19034. me.fireEvent("afterexeccommand", cmd);
  19035. me.__hasEnterExecCommand = false;
  19036. me._selectionChange();
  19037. } else {
  19038. result = oldExecCommand.apply(me, arguments);
  19039. }
  19040. return result;
  19041. };
  19042. });
  19043. /**
  19044. * 删除obj的宽高style,改成属性宽高
  19045. * @param obj
  19046. * @param replaceToProperty
  19047. */
  19048. function removeStyleSize(obj, replaceToProperty) {
  19049. removeStyle(obj, "width", true);
  19050. removeStyle(obj, "height", true);
  19051. }
  19052. function removeStyle(obj, styleName, replaceToProperty) {
  19053. if (obj.style[styleName]) {
  19054. replaceToProperty && obj.setAttribute(styleName, parseInt(obj.style[styleName], 10));
  19055. obj.style[styleName] = "";
  19056. }
  19057. }
  19058. function getParentTdOrTh(ele) {
  19059. if (ele.tagName == "TD" || ele.tagName == "TH") return ele;
  19060. var td;
  19061. if (td = domUtils.findParentByTagName(ele, "td", true) || domUtils.findParentByTagName(ele, "th", true)) return td;
  19062. return null;
  19063. }
  19064. function isEmptyBlock(node) {
  19065. var reg = new RegExp(domUtils.fillChar, 'g');
  19066. if (node[browser.ie ? 'innerText' : 'textContent'].replace(/^\s*$/, '').replace(reg, '').length > 0) {
  19067. return 0;
  19068. }
  19069. for (var n in dtd.$isNotEmpty) {
  19070. if (node.getElementsByTagName(n).length) {
  19071. return 0;
  19072. }
  19073. }
  19074. return 1;
  19075. }
  19076. function mouseCoords(evt) {
  19077. if (evt.pageX || evt.pageY) {
  19078. return { x:evt.pageX, y:evt.pageY };
  19079. }
  19080. return {
  19081. x:evt.clientX + me.document.body.scrollLeft - me.document.body.clientLeft,
  19082. y:evt.clientY + me.document.body.scrollTop - me.document.body.clientTop
  19083. };
  19084. }
  19085. function mouseMoveEvent(evt) {
  19086. if( isEditorDisabled() ) {
  19087. return;
  19088. }
  19089. try {
  19090. //普通状态下鼠标移动
  19091. var target = getParentTdOrTh(evt.target || evt.srcElement),
  19092. pos;
  19093. //区分用户的行为是拖动还是双击
  19094. if( isInResizeBuffer ) {
  19095. me.body.style.webkitUserSelect = 'none';
  19096. if( Math.abs( userActionStatus.x - evt.clientX ) > offsetOfTableCell || Math.abs( userActionStatus.y - evt.clientY ) > offsetOfTableCell ) {
  19097. clearTableDragTimer();
  19098. isInResizeBuffer = false;
  19099. singleClickState = 0;
  19100. //drag action
  19101. tableBorderDrag(evt);
  19102. }
  19103. }
  19104. //修改单元格大小时的鼠标移动
  19105. if (onDrag && dragTd) {
  19106. singleClickState = 0;
  19107. me.body.style.webkitUserSelect = 'none';
  19108. me.selection.getNative()[browser.ie9below ? 'empty' : 'removeAllRanges']();
  19109. pos = mouseCoords(evt);
  19110. toggleDraggableState(me, true, onDrag, pos, target);
  19111. if (onDrag == "h") {
  19112. dragLine.style.left = getPermissionX(dragTd, evt) + "px";
  19113. } else if (onDrag == "v") {
  19114. dragLine.style.top = getPermissionY(dragTd, evt) + "px";
  19115. }
  19116. return;
  19117. }
  19118. //当鼠标处于table上时,修改移动过程中的光标状态
  19119. if (target) {
  19120. //针对使用table作为容器的组件不触发拖拽效果
  19121. if (me.fireEvent('excludetable', target) === true)
  19122. return;
  19123. pos = mouseCoords(evt);
  19124. var state = getRelation(target, pos),
  19125. table = domUtils.findParentByTagName(target, "table", true);
  19126. if (inTableSide(table, target, evt, true)) {
  19127. if (me.fireEvent("excludetable", table) === true) return;
  19128. me.body.style.cursor = "url(" + me.options.cursorpath + "h.png),pointer";
  19129. } else if (inTableSide(table, target, evt)) {
  19130. if (me.fireEvent("excludetable", table) === true) return;
  19131. me.body.style.cursor = "url(" + me.options.cursorpath + "v.png),pointer";
  19132. } else {
  19133. me.body.style.cursor = "text";
  19134. var curCell = target;
  19135. if (/\d/.test(state)) {
  19136. state = state.replace(/\d/, '');
  19137. target = getUETable(target).getPreviewCell(target, state == "v");
  19138. }
  19139. //位于第一行的顶部或者第一列的左边时不可拖动
  19140. toggleDraggableState(me, target ? !!state : false, target ? state : '', pos, target);
  19141. }
  19142. } else {
  19143. toggleDragButton(false, table, me);
  19144. }
  19145. } catch (e) {
  19146. showError(e);
  19147. }
  19148. }
  19149. var dragButtonTimer;
  19150. function toggleDragButton(show, table, editor) {
  19151. if (!show) {
  19152. if (dragOver)return;
  19153. dragButtonTimer = setTimeout(function () {
  19154. !dragOver && dragButton && dragButton.parentNode && dragButton.parentNode.removeChild(dragButton);
  19155. }, 2000);
  19156. } else {
  19157. createDragButton(table, editor);
  19158. }
  19159. }
  19160. function createDragButton(table, editor) {
  19161. var pos = domUtils.getXY(table),
  19162. doc = table.ownerDocument;
  19163. if (dragButton && dragButton.parentNode)return dragButton;
  19164. dragButton = doc.createElement("div");
  19165. dragButton.contentEditable = false;
  19166. dragButton.innerHTML = "";
  19167. 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;";
  19168. domUtils.unSelectable(dragButton);
  19169. dragButton.onmouseover = function (evt) {
  19170. dragOver = true;
  19171. };
  19172. dragButton.onmouseout = function (evt) {
  19173. dragOver = false;
  19174. };
  19175. domUtils.on(dragButton, 'click', function (type, evt) {
  19176. doClick(evt, this);
  19177. });
  19178. domUtils.on(dragButton, 'dblclick', function (type, evt) {
  19179. doDblClick(evt);
  19180. });
  19181. domUtils.on(dragButton, 'dragstart', function (type, evt) {
  19182. domUtils.preventDefault(evt);
  19183. });
  19184. var timer;
  19185. function doClick(evt, button) {
  19186. // 部分浏览器下需要清理
  19187. clearTimeout(timer);
  19188. timer = setTimeout(function () {
  19189. editor.fireEvent("tableClicked", table, button);
  19190. }, 300);
  19191. }
  19192. function doDblClick(evt) {
  19193. clearTimeout(timer);
  19194. var ut = getUETable(table),
  19195. start = table.rows[0].cells[0],
  19196. end = ut.getLastCell(),
  19197. range = ut.getCellsRange(start, end);
  19198. editor.selection.getRange().setStart(start, 0).setCursor(false, true);
  19199. ut.setSelected(range);
  19200. }
  19201. doc.body.appendChild(dragButton);
  19202. }
  19203. // function inPosition(table, pos) {
  19204. // var tablePos = domUtils.getXY(table),
  19205. // width = table.offsetWidth,
  19206. // height = table.offsetHeight;
  19207. // if (pos.x - tablePos.x < 5 && pos.y - tablePos.y < 5) {
  19208. // return "topLeft";
  19209. // } else if (tablePos.x + width - pos.x < 5 && tablePos.y + height - pos.y < 5) {
  19210. // return "bottomRight";
  19211. // }
  19212. // }
  19213. function inTableSide(table, cell, evt, top) {
  19214. var pos = mouseCoords(evt),
  19215. state = getRelation(cell, pos);
  19216. if (top) {
  19217. var caption = table.getElementsByTagName("caption")[0],
  19218. capHeight = caption ? caption.offsetHeight : 0;
  19219. return (state == "v1") && ((pos.y - domUtils.getXY(table).y - capHeight) < 8);
  19220. } else {
  19221. return (state == "h1") && ((pos.x - domUtils.getXY(table).x) < 8);
  19222. }
  19223. }
  19224. /**
  19225. * 获取拖动时允许的X轴坐标
  19226. * @param dragTd
  19227. * @param evt
  19228. */
  19229. function getPermissionX(dragTd, evt) {
  19230. var ut = getUETable(dragTd);
  19231. if (ut) {
  19232. var preTd = ut.getSameEndPosCells(dragTd, "x")[0],
  19233. nextTd = ut.getSameStartPosXCells(dragTd)[0],
  19234. mouseX = mouseCoords(evt).x,
  19235. left = (preTd ? domUtils.getXY(preTd).x : domUtils.getXY(ut.table).x) + 20 ,
  19236. right = nextTd ? domUtils.getXY(nextTd).x + nextTd.offsetWidth - 20 : (me.body.offsetWidth + 5 || parseInt(domUtils.getComputedStyle(me.body, "width"), 10));
  19237. left += cellMinWidth;
  19238. right -= cellMinWidth;
  19239. return mouseX < left ? left : mouseX > right ? right : mouseX;
  19240. }
  19241. }
  19242. /**
  19243. * 获取拖动时允许的Y轴坐标
  19244. */
  19245. function getPermissionY(dragTd, evt) {
  19246. try {
  19247. var top = domUtils.getXY(dragTd).y,
  19248. mousePosY = mouseCoords(evt).y;
  19249. return mousePosY < top ? top : mousePosY;
  19250. } catch (e) {
  19251. showError(e);
  19252. }
  19253. }
  19254. /**
  19255. * 移动状态切换
  19256. */
  19257. function toggleDraggableState(editor, draggable, dir, mousePos, cell) {
  19258. try {
  19259. editor.body.style.cursor = dir == "h" ? "col-resize" : dir == "v" ? "row-resize" : "text";
  19260. if (browser.ie) {
  19261. if (dir && !mousedown && !getUETableBySelected(editor)) {
  19262. getDragLine(editor, editor.document);
  19263. showDragLineAt(dir, cell);
  19264. } else {
  19265. hideDragLine(editor)
  19266. }
  19267. }
  19268. onBorder = draggable;
  19269. } catch (e) {
  19270. showError(e);
  19271. }
  19272. }
  19273. /**
  19274. * 获取与UETable相关的resize line
  19275. * @param uetable UETable对象
  19276. */
  19277. function getResizeLineByUETable() {
  19278. var lineId = '_UETableResizeLine',
  19279. line = this.document.getElementById( lineId );
  19280. if( !line ) {
  19281. line = this.document.createElement("div");
  19282. line.id = lineId;
  19283. line.contnetEditable = false;
  19284. line.setAttribute("unselectable", "on");
  19285. var styles = {
  19286. width: 2*cellBorderWidth + 1 + 'px',
  19287. position: 'absolute',
  19288. 'z-index': 100000,
  19289. cursor: 'col-resize',
  19290. background: 'red',
  19291. display: 'none'
  19292. };
  19293. //切换状态
  19294. line.onmouseout = function(){
  19295. this.style.display = 'none';
  19296. };
  19297. utils.extend( line.style, styles );
  19298. this.document.body.appendChild( line );
  19299. }
  19300. return line;
  19301. }
  19302. /**
  19303. * 更新resize-line
  19304. */
  19305. function updateResizeLine( cell, uetable ) {
  19306. var line = getResizeLineByUETable.call( this ),
  19307. table = uetable.table,
  19308. styles = {
  19309. top: domUtils.getXY( table ).y + 'px',
  19310. left: domUtils.getXY( cell).x + cell.offsetWidth - cellBorderWidth + 'px',
  19311. display: 'block',
  19312. height: table.offsetHeight + 'px'
  19313. };
  19314. utils.extend( line.style, styles );
  19315. }
  19316. /**
  19317. * 显示resize-line
  19318. */
  19319. function showResizeLine( cell ) {
  19320. var uetable = getUETable( cell );
  19321. updateResizeLine.call( this, cell, uetable );
  19322. }
  19323. /**
  19324. * 获取鼠标与当前单元格的相对位置
  19325. * @param ele
  19326. * @param mousePos
  19327. */
  19328. function getRelation(ele, mousePos) {
  19329. var elePos = domUtils.getXY(ele);
  19330. if( !elePos ) {
  19331. return '';
  19332. }
  19333. if (elePos.x + ele.offsetWidth - mousePos.x < cellBorderWidth) {
  19334. return "h";
  19335. }
  19336. if (mousePos.x - elePos.x < cellBorderWidth) {
  19337. return 'h1'
  19338. }
  19339. if (elePos.y + ele.offsetHeight - mousePos.y < cellBorderWidth) {
  19340. return "v";
  19341. }
  19342. if (mousePos.y - elePos.y < cellBorderWidth) {
  19343. return 'v1'
  19344. }
  19345. return '';
  19346. }
  19347. function mouseDownEvent(type, evt) {
  19348. if( isEditorDisabled() ) {
  19349. return ;
  19350. }
  19351. userActionStatus = {
  19352. x: evt.clientX,
  19353. y: evt.clientY
  19354. };
  19355. //右键菜单单独处理
  19356. if (evt.button == 2) {
  19357. var ut = getUETableBySelected(me),
  19358. flag = false;
  19359. if (ut) {
  19360. var td = getTargetTd(me, evt);
  19361. utils.each(ut.selectedTds, function (ti) {
  19362. if (ti === td) {
  19363. flag = true;
  19364. }
  19365. });
  19366. if (!flag) {
  19367. removeSelectedClass(domUtils.getElementsByTagName(me.body, "th td"));
  19368. ut.clearSelected()
  19369. } else {
  19370. td = ut.selectedTds[0];
  19371. setTimeout(function () {
  19372. me.selection.getRange().setStart(td, 0).setCursor(false, true);
  19373. }, 0);
  19374. }
  19375. }
  19376. } else {
  19377. tableClickHander( evt );
  19378. }
  19379. }
  19380. //清除表格的计时器
  19381. function clearTableTimer() {
  19382. tabTimer && clearTimeout( tabTimer );
  19383. tabTimer = null;
  19384. }
  19385. //双击收缩
  19386. function tableDbclickHandler(evt) {
  19387. singleClickState = 0;
  19388. evt = evt || me.window.event;
  19389. var target = getParentTdOrTh(evt.target || evt.srcElement);
  19390. if (target) {
  19391. var h;
  19392. if (h = getRelation(target, mouseCoords(evt))) {
  19393. hideDragLine( me );
  19394. if (h == 'h1') {
  19395. h = 'h';
  19396. if (inTableSide(domUtils.findParentByTagName(target, "table"), target, evt)) {
  19397. me.execCommand('adaptbywindow');
  19398. } else {
  19399. target = getUETable(target).getPreviewCell(target);
  19400. if (target) {
  19401. var rng = me.selection.getRange();
  19402. rng.selectNodeContents(target).setCursor(true, true)
  19403. }
  19404. }
  19405. }
  19406. if (h == 'h') {
  19407. var ut = getUETable(target),
  19408. table = ut.table,
  19409. cells = getCellsByMoveBorder( target, table, true );
  19410. cells = extractArray( cells, 'left' );
  19411. ut.width = ut.offsetWidth;
  19412. var oldWidth = [],
  19413. newWidth = [];
  19414. utils.each( cells, function( cell ){
  19415. oldWidth.push( cell.offsetWidth );
  19416. } );
  19417. utils.each( cells, function( cell ){
  19418. cell.removeAttribute("width");
  19419. } );
  19420. window.setTimeout( function(){
  19421. //是否允许改变
  19422. var changeable = true;
  19423. utils.each( cells, function( cell, index ){
  19424. var width = cell.offsetWidth;
  19425. if( width > oldWidth[index] ) {
  19426. changeable = false;
  19427. return false;
  19428. }
  19429. newWidth.push( width );
  19430. } );
  19431. var change = changeable ? newWidth : oldWidth;
  19432. utils.each( cells, function( cell, index ){
  19433. cell.width = change[index] - getTabcellSpace();
  19434. } );
  19435. }, 0 );
  19436. // minWidth -= cellMinWidth;
  19437. //
  19438. // table.removeAttribute("width");
  19439. // utils.each(cells, function (cell) {
  19440. // cell.style.width = "";
  19441. // cell.width -= minWidth;
  19442. // });
  19443. }
  19444. }
  19445. }
  19446. }
  19447. function tableClickHander( evt ) {
  19448. removeSelectedClass(domUtils.getElementsByTagName(me.body, "td th"));
  19449. //trace:3113
  19450. //选中单元格,点击table外部,不会清掉table上挂的ueTable,会引起getUETableBySelected方法返回值
  19451. utils.each(me.document.getElementsByTagName('table'), function (t) {
  19452. t.ueTable = null;
  19453. });
  19454. startTd = getTargetTd(me, evt);
  19455. if( !startTd ) return;
  19456. var table = domUtils.findParentByTagName(startTd, "table", true);
  19457. ut = getUETable(table);
  19458. ut && ut.clearSelected();
  19459. //判断当前鼠标状态
  19460. if (!onBorder) {
  19461. me.document.body.style.webkitUserSelect = '';
  19462. mousedown = true;
  19463. me.addListener('mouseover', mouseOverEvent);
  19464. } else {
  19465. //边框上的动作处理
  19466. borderActionHandler( evt );
  19467. }
  19468. }
  19469. //处理表格边框上的动作, 这里做延时处理,避免两种动作互相影响
  19470. function borderActionHandler( evt ) {
  19471. if ( browser.ie ) {
  19472. evt = reconstruct(evt );
  19473. }
  19474. clearTableDragTimer();
  19475. //是否正在等待resize的缓冲中
  19476. isInResizeBuffer = true;
  19477. tableDragTimer = setTimeout(function(){
  19478. tableBorderDrag( evt );
  19479. }, dblclickTime);
  19480. }
  19481. function extractArray( originArr, key ) {
  19482. var result = [],
  19483. tmp = null;
  19484. for( var i = 0, len = originArr.length; i<len; i++ ) {
  19485. tmp = originArr[ i ][ key ];
  19486. if( tmp ) {
  19487. result.push( tmp );
  19488. }
  19489. }
  19490. return result;
  19491. }
  19492. function clearTableDragTimer() {
  19493. tableDragTimer && clearTimeout(tableDragTimer);
  19494. tableDragTimer = null;
  19495. }
  19496. function reconstruct( obj ) {
  19497. var attrs = ['pageX', 'pageY', 'clientX', 'clientY', 'srcElement', 'target'],
  19498. newObj = {};
  19499. if( obj ) {
  19500. for( var i = 0, key, val; key = attrs[i]; i++ ) {
  19501. val=obj[ key ];
  19502. val && (newObj[ key ] = val);
  19503. }
  19504. }
  19505. return newObj;
  19506. }
  19507. //边框拖动
  19508. function tableBorderDrag( evt ) {
  19509. isInResizeBuffer = false;
  19510. startTd = evt.target || evt.srcElement;
  19511. if( !startTd ) return;
  19512. var state = getRelation(startTd, mouseCoords(evt));
  19513. if (/\d/.test(state)) {
  19514. state = state.replace(/\d/, '');
  19515. startTd = getUETable(startTd).getPreviewCell(startTd, state == 'v');
  19516. }
  19517. hideDragLine(me);
  19518. getDragLine(me, me.document);
  19519. me.fireEvent('saveScene');
  19520. showDragLineAt(state, startTd);
  19521. mousedown = true;
  19522. //拖动开始
  19523. onDrag = state;
  19524. dragTd = startTd;
  19525. }
  19526. function mouseUpEvent(type, evt) {
  19527. if( isEditorDisabled() ) {
  19528. return ;
  19529. }
  19530. clearTableDragTimer();
  19531. isInResizeBuffer = false;
  19532. if( onBorder ) {
  19533. singleClickState = ++singleClickState % 3;
  19534. userActionStatus = {
  19535. x: evt.clientX,
  19536. y: evt.clientY
  19537. };
  19538. tableResizeTimer = setTimeout(function(){
  19539. singleClickState > 0 && singleClickState--;
  19540. }, dblclickTime );
  19541. if( singleClickState === 2 ) {
  19542. singleClickState = 0;
  19543. tableDbclickHandler(evt);
  19544. return;
  19545. }
  19546. }
  19547. if (evt.button == 2)return;
  19548. var me = this;
  19549. //清除表格上原生跨选问题
  19550. var range = me.selection.getRange(),
  19551. start = domUtils.findParentByTagName(range.startContainer, 'table', true),
  19552. end = domUtils.findParentByTagName(range.endContainer, 'table', true);
  19553. if (start || end) {
  19554. if (start === end) {
  19555. start = domUtils.findParentByTagName(range.startContainer, ['td', 'th', 'caption'], true);
  19556. end = domUtils.findParentByTagName(range.endContainer, ['td', 'th', 'caption'], true);
  19557. if (start !== end) {
  19558. me.selection.clearRange()
  19559. }
  19560. } else {
  19561. me.selection.clearRange()
  19562. }
  19563. }
  19564. mousedown = false;
  19565. me.document.body.style.webkitUserSelect = '';
  19566. //拖拽状态下的mouseUP
  19567. if ( onDrag && dragTd ) {
  19568. me.selection.getNative()[browser.ie9below ? 'empty' : 'removeAllRanges']();
  19569. singleClickState = 0;
  19570. dragLine = me.document.getElementById('ue_tableDragLine');
  19571. // trace 3973
  19572. if (dragLine) {
  19573. var dragTdPos = domUtils.getXY(dragTd),
  19574. dragLinePos = domUtils.getXY(dragLine);
  19575. switch (onDrag) {
  19576. case "h":
  19577. changeColWidth(dragTd, dragLinePos.x - dragTdPos.x);
  19578. break;
  19579. case "v":
  19580. changeRowHeight(dragTd, dragLinePos.y - dragTdPos.y - dragTd.offsetHeight);
  19581. break;
  19582. default:
  19583. }
  19584. onDrag = "";
  19585. dragTd = null;
  19586. hideDragLine(me);
  19587. me.fireEvent('saveScene');
  19588. return;
  19589. }
  19590. }
  19591. //正常状态下的mouseup
  19592. if (!startTd) {
  19593. var target = domUtils.findParentByTagName(evt.target || evt.srcElement, "td", true);
  19594. if (!target) target = domUtils.findParentByTagName(evt.target || evt.srcElement, "th", true);
  19595. if (target && (target.tagName == "TD" || target.tagName == "TH")) {
  19596. if (me.fireEvent("excludetable", target) === true) return;
  19597. range = new dom.Range(me.document);
  19598. range.setStart(target, 0).setCursor(false, true);
  19599. }
  19600. } else {
  19601. var ut = getUETable(startTd),
  19602. cell = ut ? ut.selectedTds[0] : null;
  19603. if (cell) {
  19604. range = new dom.Range(me.document);
  19605. if (domUtils.isEmptyBlock(cell)) {
  19606. range.setStart(cell, 0).setCursor(false, true);
  19607. } else {
  19608. range.selectNodeContents(cell).shrinkBoundary().setCursor(false, true);
  19609. }
  19610. } else {
  19611. range = me.selection.getRange().shrinkBoundary();
  19612. if (!range.collapsed) {
  19613. var start = domUtils.findParentByTagName(range.startContainer, ['td', 'th'], true),
  19614. end = domUtils.findParentByTagName(range.endContainer, ['td', 'th'], true);
  19615. //在table里边的不能清除
  19616. if (start && !end || !start && end || start && end && start !== end) {
  19617. range.setCursor(false, true);
  19618. }
  19619. }
  19620. }
  19621. startTd = null;
  19622. me.removeListener('mouseover', mouseOverEvent);
  19623. }
  19624. me._selectionChange(250, evt);
  19625. }
  19626. function mouseOverEvent(type, evt) {
  19627. if( isEditorDisabled() ) {
  19628. return;
  19629. }
  19630. var me = this,
  19631. tar = evt.target || evt.srcElement;
  19632. currentTd = domUtils.findParentByTagName(tar, "td", true) || domUtils.findParentByTagName(tar, "th", true);
  19633. //需要判断两个TD是否位于同一个表格内
  19634. if (startTd && currentTd &&
  19635. ((startTd.tagName == "TD" && currentTd.tagName == "TD") || (startTd.tagName == "TH" && currentTd.tagName == "TH")) &&
  19636. domUtils.findParentByTagName(startTd, 'table') == domUtils.findParentByTagName(currentTd, 'table')) {
  19637. var ut = getUETable(currentTd);
  19638. if (startTd != currentTd) {
  19639. me.document.body.style.webkitUserSelect = 'none';
  19640. me.selection.getNative()[browser.ie9below ? 'empty' : 'removeAllRanges']();
  19641. var range = ut.getCellsRange(startTd, currentTd);
  19642. ut.setSelected(range);
  19643. } else {
  19644. me.document.body.style.webkitUserSelect = '';
  19645. ut.clearSelected();
  19646. }
  19647. }
  19648. evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
  19649. }
  19650. function setCellHeight(cell, height, backHeight) {
  19651. var lineHight = parseInt(domUtils.getComputedStyle(cell, "line-height"), 10),
  19652. tmpHeight = backHeight + height;
  19653. height = tmpHeight < lineHight ? lineHight : tmpHeight;
  19654. if (cell.style.height) cell.style.height = "";
  19655. cell.rowSpan == 1 ? cell.setAttribute("height", height) : (cell.removeAttribute && cell.removeAttribute("height"));
  19656. }
  19657. function getWidth(cell) {
  19658. if (!cell)return 0;
  19659. return parseInt(domUtils.getComputedStyle(cell, "width"), 10);
  19660. }
  19661. function changeColWidth(cell, changeValue) {
  19662. var ut = getUETable(cell);
  19663. if (ut) {
  19664. //根据当前移动的边框获取相关的单元格
  19665. var table = ut.table,
  19666. cells = getCellsByMoveBorder( cell, table );
  19667. table.style.width = "";
  19668. table.removeAttribute("width");
  19669. //修正改变量
  19670. changeValue = correctChangeValue( changeValue, cell, cells );
  19671. if (cell.nextSibling) {
  19672. var i=0;
  19673. utils.each( cells, function( cellGroup ){
  19674. cellGroup.left.width = (+cellGroup.left.width)+changeValue;
  19675. cellGroup.right && ( cellGroup.right.width = (+cellGroup.right.width)-changeValue );
  19676. } );
  19677. } else {
  19678. utils.each( cells, function( cellGroup ){
  19679. cellGroup.left.width -= -changeValue;
  19680. } );
  19681. }
  19682. }
  19683. }
  19684. function isEditorDisabled() {
  19685. return me.body.contentEditable === "false";
  19686. }
  19687. function changeRowHeight(td, changeValue) {
  19688. if (Math.abs(changeValue) < 10) return;
  19689. var ut = getUETable(td);
  19690. if (ut) {
  19691. var cells = ut.getSameEndPosCells(td, "y"),
  19692. //备份需要连带变化的td的原始高度,否则后期无法获取正确的值
  19693. backHeight = cells[0] ? cells[0].offsetHeight : 0;
  19694. for (var i = 0, cell; cell = cells[i++];) {
  19695. setCellHeight(cell, changeValue, backHeight);
  19696. }
  19697. }
  19698. }
  19699. /**
  19700. * 获取调整单元格大小的相关单元格
  19701. * @isContainMergeCell 返回的结果中是否包含发生合并后的单元格
  19702. */
  19703. function getCellsByMoveBorder( cell, table, isContainMergeCell ) {
  19704. if( !table ) {
  19705. table = domUtils.findParentByTagName( cell, 'table' );
  19706. }
  19707. if( !table ) {
  19708. return null;
  19709. }
  19710. //获取到该单元格所在行的序列号
  19711. var index = domUtils.getNodeIndex( cell ),
  19712. temp = cell,
  19713. rows = table.rows,
  19714. colIndex = 0;
  19715. while( temp ) {
  19716. //获取到当前单元格在未发生单元格合并时的序列
  19717. if( temp.nodeType === 1 ) {
  19718. colIndex += (temp.colSpan || 1);
  19719. }
  19720. temp = temp.previousSibling;
  19721. }
  19722. temp = null;
  19723. //记录想关的单元格
  19724. var borderCells = [];
  19725. utils.each(rows, function( tabRow ){
  19726. var cells = tabRow.cells,
  19727. currIndex = 0;
  19728. utils.each( cells, function( tabCell ){
  19729. currIndex += (tabCell.colSpan || 1);
  19730. if( currIndex === colIndex ) {
  19731. borderCells.push({
  19732. left: tabCell,
  19733. right: tabCell.nextSibling || null
  19734. });
  19735. return false;
  19736. } else if( currIndex > colIndex ) {
  19737. if( isContainMergeCell ) {
  19738. borderCells.push({
  19739. left: tabCell
  19740. });
  19741. }
  19742. return false;
  19743. }
  19744. } );
  19745. });
  19746. return borderCells;
  19747. }
  19748. /**
  19749. * 通过给定的单元格集合获取最小的单元格width
  19750. */
  19751. function getMinWidthByTableCells( cells ) {
  19752. var minWidth = Number.MAX_VALUE;
  19753. for( var i = 0, curCell; curCell = cells[ i ] ; i++ ) {
  19754. minWidth = Math.min( minWidth, curCell.width || getTableCellWidth( curCell ) );
  19755. }
  19756. return minWidth;
  19757. }
  19758. function correctChangeValue( changeValue, relatedCell, cells ) {
  19759. //为单元格的paading预留空间
  19760. changeValue -= getTabcellSpace();
  19761. if( changeValue < 0 ) {
  19762. return 0;
  19763. }
  19764. changeValue -= getTableCellWidth( relatedCell );
  19765. //确定方向
  19766. var direction = changeValue < 0 ? 'left':'right';
  19767. changeValue = Math.abs(changeValue);
  19768. //只关心非最后一个单元格就可以
  19769. utils.each( cells, function( cellGroup ){
  19770. var curCell = cellGroup[direction];
  19771. //为单元格保留最小空间
  19772. if( curCell ) {
  19773. changeValue = Math.min( changeValue, getTableCellWidth( curCell )-cellMinWidth );
  19774. }
  19775. } );
  19776. //修正越界
  19777. changeValue = changeValue < 0 ? 0 : changeValue;
  19778. return direction === 'left' ? -changeValue : changeValue;
  19779. }
  19780. function getTableCellWidth( cell ) {
  19781. var width = 0,
  19782. //偏移纠正量
  19783. offset = 0,
  19784. width = cell.offsetWidth - getTabcellSpace();
  19785. //最后一个节点纠正一下
  19786. if( !cell.nextSibling ) {
  19787. width -= getTableCellOffset( cell );
  19788. }
  19789. width = width < 0 ? 0 : width;
  19790. try {
  19791. cell.width = width;
  19792. } catch(e) {
  19793. }
  19794. return width;
  19795. }
  19796. /**
  19797. * 获取单元格所在表格的最末单元格的偏移量
  19798. */
  19799. function getTableCellOffset( cell ) {
  19800. tab = domUtils.findParentByTagName( cell, "table", false);
  19801. if( tab.offsetVal === undefined ) {
  19802. var prev = cell.previousSibling;
  19803. if( prev ) {
  19804. //最后一个单元格和前一个单元格的width diff结果 如果恰好为一个border width, 则条件成立
  19805. tab.offsetVal = cell.offsetWidth - prev.offsetWidth === UT.borderWidth ? UT.borderWidth : 0;
  19806. } else {
  19807. tab.offsetVal = 0;
  19808. }
  19809. }
  19810. return tab.offsetVal;
  19811. }
  19812. function getTabcellSpace() {
  19813. if( UT.tabcellSpace === undefined ) {
  19814. var cell = null,
  19815. tab = me.document.createElement("table"),
  19816. tbody = me.document.createElement("tbody"),
  19817. trow = me.document.createElement("tr"),
  19818. tabcell = me.document.createElement("td"),
  19819. mirror = null;
  19820. tabcell.style.cssText = 'border: 0;';
  19821. tabcell.width = 1;
  19822. trow.appendChild( tabcell );
  19823. trow.appendChild( mirror = tabcell.cloneNode( false ) );
  19824. tbody.appendChild( trow );
  19825. tab.appendChild( tbody );
  19826. tab.style.cssText = "visibility: hidden;";
  19827. me.body.appendChild( tab );
  19828. UT.paddingSpace = tabcell.offsetWidth - 1;
  19829. var tmpTabWidth = tab.offsetWidth;
  19830. tabcell.style.cssText = '';
  19831. mirror.style.cssText = '';
  19832. UT.borderWidth = ( tab.offsetWidth - tmpTabWidth ) / 3;
  19833. UT.tabcellSpace = UT.paddingSpace + UT.borderWidth;
  19834. me.body.removeChild( tab );
  19835. }
  19836. getTabcellSpace = function(){ return UT.tabcellSpace; };
  19837. return UT.tabcellSpace;
  19838. }
  19839. function getDragLine(editor, doc) {
  19840. if (mousedown)return;
  19841. dragLine = editor.document.createElement("div");
  19842. domUtils.setAttributes(dragLine, {
  19843. id:"ue_tableDragLine",
  19844. unselectable:'on',
  19845. contenteditable:false,
  19846. 'onresizestart':'return false',
  19847. 'ondragstart':'return false',
  19848. 'onselectstart':'return false',
  19849. style:"background-color:blue;position:absolute;padding:0;margin:0;background-image:none;border:0px none;opacity:0;filter:alpha(opacity=0)"
  19850. });
  19851. editor.body.appendChild(dragLine);
  19852. }
  19853. function hideDragLine(editor) {
  19854. if (mousedown)return;
  19855. var line;
  19856. while (line = editor.document.getElementById('ue_tableDragLine')) {
  19857. domUtils.remove(line)
  19858. }
  19859. }
  19860. /**
  19861. * 依据state(v|h)在cell位置显示横线
  19862. * @param state
  19863. * @param cell
  19864. */
  19865. function showDragLineAt(state, cell) {
  19866. if (!cell) return;
  19867. var table = domUtils.findParentByTagName(cell, "table"),
  19868. caption = table.getElementsByTagName('caption'),
  19869. width = table.offsetWidth,
  19870. height = table.offsetHeight - (caption.length > 0 ? caption[0].offsetHeight : 0),
  19871. tablePos = domUtils.getXY(table),
  19872. cellPos = domUtils.getXY(cell), css;
  19873. switch (state) {
  19874. case "h":
  19875. css = 'height:' + height + 'px;top:' + (tablePos.y + (caption.length > 0 ? caption[0].offsetHeight : 0)) + 'px;left:' + (cellPos.x + cell.offsetWidth);
  19876. dragLine.style.cssText = css + 'px;position: absolute;display:block;background-color:blue;width:1px;border:0; color:blue;opacity:.3;filter:alpha(opacity=30)';
  19877. break;
  19878. case "v":
  19879. css = 'width:' + width + 'px;left:' + tablePos.x + 'px;top:' + (cellPos.y + cell.offsetHeight );
  19880. //必须加上border:0和color:blue,否则低版ie不支持背景色显示
  19881. 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)';
  19882. break;
  19883. default:
  19884. }
  19885. }
  19886. /**
  19887. * 当表格边框颜色为白色时设置为虚线,true为添加虚线
  19888. * @param editor
  19889. * @param flag
  19890. */
  19891. function switchBorderColor(editor, flag) {
  19892. var tableArr = domUtils.getElementsByTagName(editor.body, "table"), color;
  19893. for (var i = 0, node; node = tableArr[i++];) {
  19894. var td = domUtils.getElementsByTagName(node, "td");
  19895. if (td[0]) {
  19896. if (flag) {
  19897. color = (td[0].style.borderColor).replace(/\s/g, "");
  19898. if (/(#ffffff)|(rgb\(255,255,255\))/ig.test(color))
  19899. domUtils.addClass(node, "noBorderTable")
  19900. } else {
  19901. domUtils.removeClasses(node, "noBorderTable")
  19902. }
  19903. }
  19904. }
  19905. }
  19906. function getTableWidth(editor, needIEHack, defaultValue) {
  19907. var body = editor.body;
  19908. return body.offsetWidth - (needIEHack ? parseInt(domUtils.getComputedStyle(body, 'margin-left'), 10) * 2 : 0) - defaultValue.tableBorder * 2 - (editor.options.offsetWidth || 0);
  19909. }
  19910. /**
  19911. * 获取当前拖动的单元格
  19912. */
  19913. function getTargetTd(editor, evt) {
  19914. var target = domUtils.findParentByTagName(evt.target || evt.srcElement, ["td", "th"], true),
  19915. dir = null;
  19916. if( !target ) {
  19917. return null;
  19918. }
  19919. dir = getRelation( target, mouseCoords( evt ) );
  19920. //如果有前一个节点, 需要做一个修正, 否则可能会得到一个错误的td
  19921. if( !target ) {
  19922. return null;
  19923. }
  19924. if( dir === 'h1' && target.previousSibling ) {
  19925. var position = domUtils.getXY( target),
  19926. cellWidth = target.offsetWidth;
  19927. if( Math.abs( position.x + cellWidth - evt.clientX ) > cellWidth / 3 ) {
  19928. target = target.previousSibling;
  19929. }
  19930. } else if( dir === 'v1' && target.parentNode.previousSibling ) {
  19931. var position = domUtils.getXY( target),
  19932. cellHeight = target.offsetHeight;
  19933. if( Math.abs( position.y + cellHeight - evt.clientY ) > cellHeight / 3 ) {
  19934. target = target.parentNode.previousSibling.firstChild;
  19935. }
  19936. }
  19937. //排除了非td内部以及用于代码高亮部分的td
  19938. return target && !(editor.fireEvent("excludetable", target) === true) ? target : null;
  19939. }
  19940. };
  19941. // plugins/table.sort.js
  19942. /**
  19943. * Created with JetBrains PhpStorm.
  19944. * User: Jinqn
  19945. * Date: 13-10-12
  19946. * Time: 上午10:20
  19947. * To change this template use File | Settings | File Templates.
  19948. */
  19949. UE.UETable.prototype.sortTable = function (sortByCellIndex, compareFn) {
  19950. var table = this.table,
  19951. rows = table.rows,
  19952. trArray = [],
  19953. flag = rows[0].cells[0].tagName === "TH",
  19954. lastRowIndex = 0;
  19955. if(this.selectedTds.length){
  19956. var range = this.cellsRange,
  19957. len = range.endRowIndex + 1;
  19958. for (var i = range.beginRowIndex; i < len; i++) {
  19959. trArray[i] = rows[i];
  19960. }
  19961. trArray.splice(0,range.beginRowIndex);
  19962. lastRowIndex = (range.endRowIndex +1) === this.rowsNum ? 0 : range.endRowIndex +1;
  19963. }else{
  19964. for (var i = 0,len = rows.length; i < len; i++) {
  19965. trArray[i] = rows[i];
  19966. }
  19967. }
  19968. var Fn = {
  19969. 'reversecurrent': function(td1,td2){
  19970. return 1;
  19971. },
  19972. 'orderbyasc': function(td1,td2){
  19973. var value1 = td1.innerText||td1.textContent,
  19974. value2 = td2.innerText||td2.textContent;
  19975. return value1.localeCompare(value2);
  19976. },
  19977. 'reversebyasc': function(td1,td2){
  19978. var value1 = td1.innerHTML,
  19979. value2 = td2.innerHTML;
  19980. return value2.localeCompare(value1);
  19981. },
  19982. 'orderbynum': function(td1,td2){
  19983. var value1 = td1[browser.ie ? 'innerText':'textContent'].match(/\d+/),
  19984. value2 = td2[browser.ie ? 'innerText':'textContent'].match(/\d+/);
  19985. if(value1) value1 = +value1[0];
  19986. if(value2) value2 = +value2[0];
  19987. return (value1||0) - (value2||0);
  19988. },
  19989. 'reversebynum': function(td1,td2){
  19990. var value1 = td1[browser.ie ? 'innerText':'textContent'].match(/\d+/),
  19991. value2 = td2[browser.ie ? 'innerText':'textContent'].match(/\d+/);
  19992. if(value1) value1 = +value1[0];
  19993. if(value2) value2 = +value2[0];
  19994. return (value2||0) - (value1||0);
  19995. }
  19996. };
  19997. //对表格设置排序的标记data-sort-type
  19998. table.setAttribute('data-sort-type', compareFn && typeof compareFn === "string" && Fn[compareFn] ? compareFn:'');
  19999. //th不参与排序
  20000. flag && trArray.splice(0, 1);
  20001. trArray = utils.sort(trArray,function (tr1, tr2) {
  20002. var result;
  20003. if (compareFn && typeof compareFn === "function") {
  20004. result = compareFn.call(this, tr1.cells[sortByCellIndex], tr2.cells[sortByCellIndex]);
  20005. } else if (compareFn && typeof compareFn === "number") {
  20006. result = 1;
  20007. } else if (compareFn && typeof compareFn === "string" && Fn[compareFn]) {
  20008. result = Fn[compareFn].call(this, tr1.cells[sortByCellIndex], tr2.cells[sortByCellIndex]);
  20009. } else {
  20010. result = Fn['orderbyasc'].call(this, tr1.cells[sortByCellIndex], tr2.cells[sortByCellIndex]);
  20011. }
  20012. return result;
  20013. });
  20014. var fragment = table.ownerDocument.createDocumentFragment();
  20015. for (var j = 0, len = trArray.length; j < len; j++) {
  20016. fragment.appendChild(trArray[j]);
  20017. }
  20018. var tbody = table.getElementsByTagName("tbody")[0];
  20019. if(!lastRowIndex){
  20020. tbody.appendChild(fragment);
  20021. }else{
  20022. tbody.insertBefore(fragment,rows[lastRowIndex- range.endRowIndex + range.beginRowIndex - 1])
  20023. }
  20024. };
  20025. UE.plugins['tablesort'] = function () {
  20026. var me = this,
  20027. UT = UE.UETable,
  20028. getUETable = function (tdOrTable) {
  20029. return UT.getUETable(tdOrTable);
  20030. },
  20031. getTableItemsByRange = function (editor) {
  20032. return UT.getTableItemsByRange(editor);
  20033. };
  20034. me.ready(function () {
  20035. //添加表格可排序的样式
  20036. utils.cssRule('tablesort',
  20037. 'table.sortEnabled tr.firstRow th,table.sortEnabled tr.firstRow td{padding-right:20px;background-repeat: no-repeat;background-position: center right;' +
  20038. ' background-image:url(' + me.options.themePath + me.options.theme + '/images/sortable.png);}',
  20039. me.document);
  20040. //做单元格合并操作时,清除可排序标识
  20041. me.addListener("afterexeccommand", function (type, cmd) {
  20042. if( cmd == 'mergeright' || cmd == 'mergedown' || cmd == 'mergecells') {
  20043. this.execCommand('disablesort');
  20044. }
  20045. });
  20046. });
  20047. //表格排序
  20048. UE.commands['sorttable'] = {
  20049. queryCommandState: function () {
  20050. var me = this,
  20051. tableItems = getTableItemsByRange(me);
  20052. if (!tableItems.cell) return -1;
  20053. var table = tableItems.table,
  20054. cells = table.getElementsByTagName("td");
  20055. for (var i = 0, cell; cell = cells[i++];) {
  20056. if (cell.rowSpan != 1 || cell.colSpan != 1) return -1;
  20057. }
  20058. return 0;
  20059. },
  20060. execCommand: function (cmd, fn) {
  20061. var me = this,
  20062. range = me.selection.getRange(),
  20063. bk = range.createBookmark(true),
  20064. tableItems = getTableItemsByRange(me),
  20065. cell = tableItems.cell,
  20066. ut = getUETable(tableItems.table),
  20067. cellInfo = ut.getCellInfo(cell);
  20068. ut.sortTable(cellInfo.cellIndex, fn);
  20069. range.moveToBookmark(bk);
  20070. try{
  20071. range.select();
  20072. }catch(e){}
  20073. }
  20074. };
  20075. //设置表格可排序,清除表格可排序
  20076. UE.commands["enablesort"] = UE.commands["disablesort"] = {
  20077. queryCommandState: function (cmd) {
  20078. var table = getTableItemsByRange(this).table;
  20079. if(table && cmd=='enablesort') {
  20080. var cells = domUtils.getElementsByTagName(table, 'th td');
  20081. for(var i = 0; i<cells.length; i++) {
  20082. if(cells[i].getAttribute('colspan')>1 || cells[i].getAttribute('rowspan')>1) return -1;
  20083. }
  20084. }
  20085. return !table ? -1: cmd=='enablesort' ^ table.getAttribute('data-sort')!='sortEnabled' ? -1:0;
  20086. },
  20087. execCommand: function (cmd) {
  20088. var table = getTableItemsByRange(this).table;
  20089. table.setAttribute("data-sort", cmd == "enablesort" ? "sortEnabled" : "sortDisabled");
  20090. cmd == "enablesort" ? domUtils.addClass(table,"sortEnabled"):domUtils.removeClasses(table,"sortEnabled");
  20091. }
  20092. };
  20093. };
  20094. // plugins/contextmenu.js
  20095. ///import core
  20096. ///commands 右键菜单
  20097. ///commandsName ContextMenu
  20098. ///commandsTitle 右键菜单
  20099. /**
  20100. * 右键菜单
  20101. * @function
  20102. * @name baidu.editor.plugins.contextmenu
  20103. * @author zhanyi
  20104. */
  20105. UE.plugins['contextmenu'] = function () {
  20106. var me = this;
  20107. me.setOpt('enableContextMenu',true);
  20108. if(me.getOpt('enableContextMenu') === false){
  20109. return;
  20110. }
  20111. var lang = me.getLang( "contextMenu" ),
  20112. menu,
  20113. items = me.options.contextMenu || [
  20114. {label:lang['selectall'], cmdName:'selectall'},
  20115. {
  20116. label:lang.cleardoc,
  20117. cmdName:'cleardoc',
  20118. exec:function () {
  20119. if ( confirm( lang.confirmclear ) ) {
  20120. this.execCommand( 'cleardoc' );
  20121. }
  20122. }
  20123. },
  20124. '-',
  20125. {
  20126. label:lang.unlink,
  20127. cmdName:'unlink'
  20128. },
  20129. '-',
  20130. {
  20131. group:lang.paragraph,
  20132. icon:'justifyjustify',
  20133. subMenu:[
  20134. {
  20135. label:lang.justifyleft,
  20136. cmdName:'justify',
  20137. value:'left'
  20138. },
  20139. {
  20140. label:lang.justifyright,
  20141. cmdName:'justify',
  20142. value:'right'
  20143. },
  20144. {
  20145. label:lang.justifycenter,
  20146. cmdName:'justify',
  20147. value:'center'
  20148. },
  20149. {
  20150. label:lang.justifyjustify,
  20151. cmdName:'justify',
  20152. value:'justify'
  20153. }
  20154. ]
  20155. },
  20156. '-',
  20157. {
  20158. group:lang.table,
  20159. icon:'table',
  20160. subMenu:[
  20161. {
  20162. label:lang.inserttable,
  20163. cmdName:'inserttable'
  20164. },
  20165. {
  20166. label:lang.deletetable,
  20167. cmdName:'deletetable'
  20168. },
  20169. '-',
  20170. {
  20171. label:lang.deleterow,
  20172. cmdName:'deleterow'
  20173. },
  20174. {
  20175. label:lang.deletecol,
  20176. cmdName:'deletecol'
  20177. },
  20178. {
  20179. label:lang.insertcol,
  20180. cmdName:'insertcol'
  20181. },
  20182. {
  20183. label:lang.insertcolnext,
  20184. cmdName:'insertcolnext'
  20185. },
  20186. {
  20187. label:lang.insertrow,
  20188. cmdName:'insertrow'
  20189. },
  20190. {
  20191. label:lang.insertrownext,
  20192. cmdName:'insertrownext'
  20193. },
  20194. '-',
  20195. {
  20196. label:lang.insertcaption,
  20197. cmdName:'insertcaption'
  20198. },
  20199. {
  20200. label:lang.deletecaption,
  20201. cmdName:'deletecaption'
  20202. },
  20203. {
  20204. label:lang.inserttitle,
  20205. cmdName:'inserttitle'
  20206. },
  20207. {
  20208. label:lang.deletetitle,
  20209. cmdName:'deletetitle'
  20210. },
  20211. {
  20212. label:lang.inserttitlecol,
  20213. cmdName:'inserttitlecol'
  20214. },
  20215. {
  20216. label:lang.deletetitlecol,
  20217. cmdName:'deletetitlecol'
  20218. },
  20219. '-',
  20220. {
  20221. label:lang.mergecells,
  20222. cmdName:'mergecells'
  20223. },
  20224. {
  20225. label:lang.mergeright,
  20226. cmdName:'mergeright'
  20227. },
  20228. {
  20229. label:lang.mergedown,
  20230. cmdName:'mergedown'
  20231. },
  20232. '-',
  20233. {
  20234. label:lang.splittorows,
  20235. cmdName:'splittorows'
  20236. },
  20237. {
  20238. label:lang.splittocols,
  20239. cmdName:'splittocols'
  20240. },
  20241. {
  20242. label:lang.splittocells,
  20243. cmdName:'splittocells'
  20244. },
  20245. '-',
  20246. {
  20247. label:lang.averageDiseRow,
  20248. cmdName:'averagedistributerow'
  20249. },
  20250. {
  20251. label:lang.averageDisCol,
  20252. cmdName:'averagedistributecol'
  20253. },
  20254. '-',
  20255. {
  20256. label:lang.edittd,
  20257. cmdName:'edittd',
  20258. exec:function () {
  20259. if ( UE.ui['edittd'] ) {
  20260. new UE.ui['edittd']( this );
  20261. }
  20262. this.getDialog('edittd').open();
  20263. }
  20264. },
  20265. {
  20266. label:lang.edittable,
  20267. cmdName:'edittable',
  20268. exec:function () {
  20269. if ( UE.ui['edittable'] ) {
  20270. new UE.ui['edittable']( this );
  20271. }
  20272. this.getDialog('edittable').open();
  20273. }
  20274. },
  20275. {
  20276. label:lang.setbordervisible,
  20277. cmdName:'setbordervisible'
  20278. }
  20279. ]
  20280. },
  20281. {
  20282. group:lang.tablesort,
  20283. icon:'tablesort',
  20284. subMenu:[
  20285. {
  20286. label:lang.enablesort,
  20287. cmdName:'enablesort'
  20288. },
  20289. {
  20290. label:lang.disablesort,
  20291. cmdName:'disablesort'
  20292. },
  20293. '-',
  20294. {
  20295. label:lang.reversecurrent,
  20296. cmdName:'sorttable',
  20297. value:'reversecurrent'
  20298. },
  20299. {
  20300. label:lang.orderbyasc,
  20301. cmdName:'sorttable',
  20302. value:'orderbyasc'
  20303. },
  20304. {
  20305. label:lang.reversebyasc,
  20306. cmdName:'sorttable',
  20307. value:'reversebyasc'
  20308. },
  20309. {
  20310. label:lang.orderbynum,
  20311. cmdName:'sorttable',
  20312. value:'orderbynum'
  20313. },
  20314. {
  20315. label:lang.reversebynum,
  20316. cmdName:'sorttable',
  20317. value:'reversebynum'
  20318. }
  20319. ]
  20320. },
  20321. {
  20322. group:lang.borderbk,
  20323. icon:'borderBack',
  20324. subMenu:[
  20325. {
  20326. label:lang.setcolor,
  20327. cmdName:"interlacetable",
  20328. exec:function(){
  20329. this.execCommand("interlacetable");
  20330. }
  20331. },
  20332. {
  20333. label:lang.unsetcolor,
  20334. cmdName:"uninterlacetable",
  20335. exec:function(){
  20336. this.execCommand("uninterlacetable");
  20337. }
  20338. },
  20339. {
  20340. label:lang.setbackground,
  20341. cmdName:"settablebackground",
  20342. exec:function(){
  20343. this.execCommand("settablebackground",{repeat:true,colorList:["#bbb","#ccc"]});
  20344. }
  20345. },
  20346. {
  20347. label:lang.unsetbackground,
  20348. cmdName:"cleartablebackground",
  20349. exec:function(){
  20350. this.execCommand("cleartablebackground");
  20351. }
  20352. },
  20353. {
  20354. label:lang.redandblue,
  20355. cmdName:"settablebackground",
  20356. exec:function(){
  20357. this.execCommand("settablebackground",{repeat:true,colorList:["red","blue"]});
  20358. }
  20359. },
  20360. {
  20361. label:lang.threecolorgradient,
  20362. cmdName:"settablebackground",
  20363. exec:function(){
  20364. this.execCommand("settablebackground",{repeat:true,colorList:["#aaa","#bbb","#ccc"]});
  20365. }
  20366. }
  20367. ]
  20368. },
  20369. {
  20370. group:lang.aligntd,
  20371. icon:'aligntd',
  20372. subMenu:[
  20373. {
  20374. cmdName:'cellalignment',
  20375. value:{align:'left',vAlign:'top'}
  20376. },
  20377. {
  20378. cmdName:'cellalignment',
  20379. value:{align:'center',vAlign:'top'}
  20380. },
  20381. {
  20382. cmdName:'cellalignment',
  20383. value:{align:'right',vAlign:'top'}
  20384. },
  20385. {
  20386. cmdName:'cellalignment',
  20387. value:{align:'left',vAlign:'middle'}
  20388. },
  20389. {
  20390. cmdName:'cellalignment',
  20391. value:{align:'center',vAlign:'middle'}
  20392. },
  20393. {
  20394. cmdName:'cellalignment',
  20395. value:{align:'right',vAlign:'middle'}
  20396. },
  20397. {
  20398. cmdName:'cellalignment',
  20399. value:{align:'left',vAlign:'bottom'}
  20400. },
  20401. {
  20402. cmdName:'cellalignment',
  20403. value:{align:'center',vAlign:'bottom'}
  20404. },
  20405. {
  20406. cmdName:'cellalignment',
  20407. value:{align:'right',vAlign:'bottom'}
  20408. }
  20409. ]
  20410. },
  20411. {
  20412. group:lang.aligntable,
  20413. icon:'aligntable',
  20414. subMenu:[
  20415. {
  20416. cmdName:'tablealignment',
  20417. className: 'left',
  20418. label:lang.tableleft,
  20419. value:"left"
  20420. },
  20421. {
  20422. cmdName:'tablealignment',
  20423. className: 'center',
  20424. label:lang.tablecenter,
  20425. value:"center"
  20426. },
  20427. {
  20428. cmdName:'tablealignment',
  20429. className: 'right',
  20430. label:lang.tableright,
  20431. value:"right"
  20432. }
  20433. ]
  20434. },
  20435. '-',
  20436. {
  20437. label:lang.insertparagraphbefore,
  20438. cmdName:'insertparagraph',
  20439. value:true
  20440. },
  20441. {
  20442. label:lang.insertparagraphafter,
  20443. cmdName:'insertparagraph'
  20444. },
  20445. {
  20446. label:lang['copy'],
  20447. cmdName:'copy'
  20448. },
  20449. {
  20450. label:lang['paste'],
  20451. cmdName:'paste'
  20452. }
  20453. ];
  20454. if ( !items.length ) {
  20455. return;
  20456. }
  20457. var uiUtils = UE.ui.uiUtils;
  20458. me.addListener( 'contextmenu', function ( type, evt ) {
  20459. var offset = uiUtils.getViewportOffsetByEvent( evt );
  20460. me.fireEvent( 'beforeselectionchange' );
  20461. if ( menu ) {
  20462. menu.destroy();
  20463. }
  20464. for ( var i = 0, ti, contextItems = []; ti = items[i]; i++ ) {
  20465. var last;
  20466. (function ( item ) {
  20467. if ( item == '-' ) {
  20468. if ( (last = contextItems[contextItems.length - 1 ] ) && last !== '-' ) {
  20469. contextItems.push( '-' );
  20470. }
  20471. } else if ( item.hasOwnProperty( "group" ) ) {
  20472. for ( var j = 0, cj, subMenu = []; cj = item.subMenu[j]; j++ ) {
  20473. (function ( subItem ) {
  20474. if ( subItem == '-' ) {
  20475. if ( (last = subMenu[subMenu.length - 1 ] ) && last !== '-' ) {
  20476. subMenu.push( '-' );
  20477. }else{
  20478. subMenu.splice(subMenu.length-1);
  20479. }
  20480. } else {
  20481. if ( (me.commands[subItem.cmdName] || UE.commands[subItem.cmdName] || subItem.query) &&
  20482. (subItem.query ? subItem.query() : me.queryCommandState( subItem.cmdName )) > -1 ) {
  20483. subMenu.push( {
  20484. 'label':subItem.label || me.getLang( "contextMenu." + subItem.cmdName + (subItem.value || '') )||"",
  20485. 'className':'edui-for-' +subItem.cmdName + ( subItem.className ? ( ' edui-for-' + subItem.cmdName + '-' + subItem.className ) : '' ),
  20486. onclick:subItem.exec ? function () {
  20487. subItem.exec.call( me );
  20488. } : function () {
  20489. me.execCommand( subItem.cmdName, subItem.value );
  20490. }
  20491. } );
  20492. }
  20493. }
  20494. })( cj );
  20495. }
  20496. if ( subMenu.length ) {
  20497. function getLabel(){
  20498. switch (item.icon){
  20499. case "table":
  20500. return me.getLang( "contextMenu.table" );
  20501. case "justifyjustify":
  20502. return me.getLang( "contextMenu.paragraph" );
  20503. case "aligntd":
  20504. return me.getLang("contextMenu.aligntd");
  20505. case "aligntable":
  20506. return me.getLang("contextMenu.aligntable");
  20507. case "tablesort":
  20508. return lang.tablesort;
  20509. case "borderBack":
  20510. return lang.borderbk;
  20511. default :
  20512. return '';
  20513. }
  20514. }
  20515. contextItems.push( {
  20516. //todo 修正成自动获取方式
  20517. 'label':getLabel(),
  20518. className:'edui-for-' + item.icon,
  20519. 'subMenu':{
  20520. items:subMenu,
  20521. editor:me
  20522. }
  20523. } );
  20524. }
  20525. } else {
  20526. //有可能commmand没有加载右键不能出来,或者没有command也想能展示出来添加query方法
  20527. if ( (me.commands[item.cmdName] || UE.commands[item.cmdName] || item.query) &&
  20528. (item.query ? item.query.call(me) : me.queryCommandState( item.cmdName )) > -1 ) {
  20529. contextItems.push( {
  20530. 'label':item.label || me.getLang( "contextMenu." + item.cmdName ),
  20531. className:'edui-for-' + (item.icon ? item.icon : item.cmdName + (item.value || '')),
  20532. onclick:item.exec ? function () {
  20533. item.exec.call( me );
  20534. } : function () {
  20535. me.execCommand( item.cmdName, item.value );
  20536. }
  20537. } );
  20538. }
  20539. }
  20540. })( ti );
  20541. }
  20542. if ( contextItems[contextItems.length - 1] == '-' ) {
  20543. contextItems.pop();
  20544. }
  20545. menu = new UE.ui.Menu( {
  20546. items:contextItems,
  20547. className:"edui-contextmenu",
  20548. editor:me
  20549. } );
  20550. menu.render();
  20551. menu.showAt( offset );
  20552. me.fireEvent("aftershowcontextmenu",menu);
  20553. domUtils.preventDefault( evt );
  20554. if ( browser.ie ) {
  20555. var ieRange;
  20556. try {
  20557. ieRange = me.selection.getNative().createRange();
  20558. } catch ( e ) {
  20559. return;
  20560. }
  20561. if ( ieRange.item ) {
  20562. var range = new dom.Range( me.document );
  20563. range.selectNode( ieRange.item( 0 ) ).select( true, true );
  20564. }
  20565. }
  20566. });
  20567. // 添加复制的flash按钮
  20568. me.addListener('aftershowcontextmenu', function(type, menu) {
  20569. if (me.zeroclipboard) {
  20570. var items = menu.items;
  20571. for (var key in items) {
  20572. if (items[key].className == 'edui-for-copy') {
  20573. me.zeroclipboard.clip(items[key].getDom());
  20574. }
  20575. }
  20576. }
  20577. });
  20578. };
  20579. // plugins/shortcutmenu.js
  20580. ///import core
  20581. ///commands 弹出菜单
  20582. // commandsName popupmenu
  20583. ///commandsTitle 弹出菜单
  20584. /**
  20585. * 弹出菜单
  20586. * @function
  20587. * @name baidu.editor.plugins.popupmenu
  20588. * @author xuheng
  20589. */
  20590. UE.plugins['shortcutmenu'] = function () {
  20591. var me = this,
  20592. menu,
  20593. items = me.options.shortcutMenu || [];
  20594. if (!items.length) {
  20595. return;
  20596. }
  20597. //contextmenu mouseup
  20598. me.addListener ('mouseup' , function (type , e) {
  20599. var me = this,
  20600. customEvt = {
  20601. type : type ,
  20602. target : e.target || e.srcElement ,
  20603. screenX : e.screenX ,
  20604. screenY : e.screenY ,
  20605. clientX : e.clientX ,
  20606. clientY : e.clientY
  20607. };
  20608. setTimeout (function () {
  20609. const el = e.target || e.srcElement;
  20610. const selection = me.selection.getNative();
  20611. if(el.tagName === 'IMG' && selection.containsNode(el)) return;
  20612. var rng = me.selection.getRange();
  20613. if (rng.collapsed === false) {
  20614. if (!menu) {
  20615. menu = new baidu.editor.ui.ShortCutMenu ({
  20616. editor : me ,
  20617. items : items ,
  20618. theme : me.options.theme ,
  20619. className : 'edui-shortcutmenu'
  20620. });
  20621. menu.render ();
  20622. me.fireEvent ("afterrendershortcutmenu" , menu);
  20623. }
  20624. menu.show (customEvt , !!UE.plugins['contextmenu']);
  20625. }
  20626. });
  20627. if (type == 'contextmenu') {
  20628. domUtils.preventDefault (e);
  20629. if (browser.ie9below) {
  20630. var ieRange;
  20631. try {
  20632. ieRange = me.selection.getNative().createRange();
  20633. } catch (e) {
  20634. return;
  20635. }
  20636. if (ieRange.item) {
  20637. var range = new dom.Range (me.document);
  20638. range.selectNode (ieRange.item (0)).select (true , true);
  20639. }
  20640. }
  20641. }
  20642. });
  20643. me.addListener ('keydown' , function (type) {
  20644. if (type == "keydown") {
  20645. menu && !menu.isHidden && menu.hide ();
  20646. }
  20647. });
  20648. };
  20649. // plugins/basestyle.js
  20650. /**
  20651. * B、I、sub、super命令支持
  20652. * @file
  20653. * @since 1.2.6.1
  20654. */
  20655. UE.plugins['basestyle'] = function(){
  20656. /**
  20657. * 字体加粗
  20658. * @command bold
  20659. * @param { String } cmd 命令字符串
  20660. * @remind 对已加粗的文本内容执行该命令, 将取消加粗
  20661. * @method execCommand
  20662. * @example
  20663. * ```javascript
  20664. * //editor是编辑器实例
  20665. * //对当前选中的文本内容执行加粗操作
  20666. * //第一次执行, 文本内容加粗
  20667. * editor.execCommand( 'bold' );
  20668. *
  20669. * //第二次执行, 文本内容取消加粗
  20670. * editor.execCommand( 'bold' );
  20671. * ```
  20672. */
  20673. /**
  20674. * 字体倾斜
  20675. * @command italic
  20676. * @method execCommand
  20677. * @param { String } cmd 命令字符串
  20678. * @remind 对已倾斜的文本内容执行该命令, 将取消倾斜
  20679. * @example
  20680. * ```javascript
  20681. * //editor是编辑器实例
  20682. * //对当前选中的文本内容执行斜体操作
  20683. * //第一次操作, 文本内容将变成斜体
  20684. * editor.execCommand( 'italic' );
  20685. *
  20686. * //再次对同一文本内容执行, 则文本内容将恢复正常
  20687. * editor.execCommand( 'italic' );
  20688. * ```
  20689. */
  20690. /**
  20691. * 下标文本,与“superscript”命令互斥
  20692. * @command subscript
  20693. * @method execCommand
  20694. * @remind 把选中的文本内容切换成下标文本, 如果当前选中的文本已经是下标, 则该操作会把文本内容还原成正常文本
  20695. * @param { String } cmd 命令字符串
  20696. * @example
  20697. * ```javascript
  20698. * //editor是编辑器实例
  20699. * //对当前选中的文本内容执行下标操作
  20700. * //第一次操作, 文本内容将变成下标文本
  20701. * editor.execCommand( 'subscript' );
  20702. *
  20703. * //再次对同一文本内容执行, 则文本内容将恢复正常
  20704. * editor.execCommand( 'subscript' );
  20705. * ```
  20706. */
  20707. /**
  20708. * 上标文本,与“subscript”命令互斥
  20709. * @command superscript
  20710. * @method execCommand
  20711. * @remind 把选中的文本内容切换成上标文本, 如果当前选中的文本已经是上标, 则该操作会把文本内容还原成正常文本
  20712. * @param { String } cmd 命令字符串
  20713. * @example
  20714. * ```javascript
  20715. * //editor是编辑器实例
  20716. * //对当前选中的文本内容执行上标操作
  20717. * //第一次操作, 文本内容将变成上标文本
  20718. * editor.execCommand( 'superscript' );
  20719. *
  20720. * //再次对同一文本内容执行, 则文本内容将恢复正常
  20721. * editor.execCommand( 'superscript' );
  20722. * ```
  20723. */
  20724. var basestyles = {
  20725. 'bold':['strong','b'],
  20726. 'italic':['em','i'],
  20727. 'subscript':['sub'],
  20728. 'superscript':['sup']
  20729. },
  20730. getObj = function(editor,tagNames){
  20731. return domUtils.filterNodeList(editor.selection.getStartElementPath(),tagNames);
  20732. },
  20733. me = this;
  20734. //添加快捷键
  20735. me.addshortcutkey({
  20736. "Bold" : "ctrl+66",//^B
  20737. "Italic" : "ctrl+73", //^I
  20738. "Underline" : "ctrl+85"//^U
  20739. });
  20740. me.addInputRule(function(root){
  20741. utils.each(root.getNodesByTagName('b i'),function(node){
  20742. switch (node.tagName){
  20743. case 'b':
  20744. node.tagName = 'strong';
  20745. break;
  20746. case 'i':
  20747. node.tagName = 'em';
  20748. }
  20749. });
  20750. });
  20751. for ( var style in basestyles ) {
  20752. (function( cmd, tagNames ) {
  20753. me.commands[cmd] = {
  20754. execCommand : function( cmdName ) {
  20755. var range = me.selection.getRange(),obj = getObj(this,tagNames);
  20756. if ( range.collapsed ) {
  20757. if ( obj ) {
  20758. var tmpText = me.document.createTextNode('');
  20759. range.insertNode( tmpText ).removeInlineStyle( tagNames );
  20760. range.setStartBefore(tmpText);
  20761. domUtils.remove(tmpText);
  20762. } else {
  20763. var tmpNode = range.document.createElement( tagNames[0] );
  20764. if(cmdName == 'superscript' || cmdName == 'subscript'){
  20765. tmpText = me.document.createTextNode('');
  20766. range.insertNode(tmpText)
  20767. .removeInlineStyle(['sub','sup'])
  20768. .setStartBefore(tmpText)
  20769. .collapse(true);
  20770. }
  20771. range.insertNode( tmpNode ).setStart( tmpNode, 0 );
  20772. }
  20773. range.collapse( true );
  20774. } else {
  20775. if(cmdName == 'superscript' || cmdName == 'subscript'){
  20776. if(!obj || obj.tagName.toLowerCase() != cmdName){
  20777. range.removeInlineStyle(['sub','sup']);
  20778. }
  20779. }
  20780. obj ? range.removeInlineStyle( tagNames ) : range.applyInlineStyle( tagNames[0] );
  20781. }
  20782. range.select();
  20783. },
  20784. queryCommandState : function() {
  20785. return getObj(this,tagNames) ? 1 : 0;
  20786. }
  20787. };
  20788. })( style, basestyles[style] );
  20789. }
  20790. };
  20791. // plugins/elementpath.js
  20792. /**
  20793. * 选取路径命令
  20794. * @file
  20795. */
  20796. UE.plugins['elementpath'] = function(){
  20797. var currentLevel,
  20798. tagNames,
  20799. me = this;
  20800. me.setOpt('elementPathEnabled',true);
  20801. if(!me.options.elementPathEnabled){
  20802. return;
  20803. }
  20804. me.commands['elementpath'] = {
  20805. execCommand : function( cmdName, level ) {
  20806. var start = tagNames[level],
  20807. range = me.selection.getRange();
  20808. currentLevel = level*1;
  20809. range.selectNode(start).select();
  20810. },
  20811. queryCommandValue : function() {
  20812. //产生一个副本,不能修改原来的startElementPath;
  20813. var parents = [].concat(this.selection.getStartElementPath()).reverse(),
  20814. names = [];
  20815. tagNames = parents;
  20816. for(var i=0,ci;ci=parents[i];i++){
  20817. if(ci.nodeType == 3) {
  20818. continue;
  20819. }
  20820. var name = ci.tagName.toLowerCase();
  20821. if(name == 'img' && ci.getAttribute('anchorname')){
  20822. name = 'anchor';
  20823. }
  20824. names[i] = name;
  20825. if(currentLevel == i){
  20826. currentLevel = -1;
  20827. break;
  20828. }
  20829. }
  20830. return names;
  20831. }
  20832. };
  20833. };
  20834. // plugins/formatmatch.js
  20835. /**
  20836. * 格式刷,只格式inline的
  20837. * @file
  20838. * @since 1.2.6.1
  20839. */
  20840. /**
  20841. * 格式刷
  20842. * @command formatmatch
  20843. * @method execCommand
  20844. * @remind 该操作不能复制段落格式
  20845. * @param { String } cmd 命令字符串
  20846. * @example
  20847. * ```javascript
  20848. * //editor是编辑器实例
  20849. * //获取格式刷
  20850. * editor.execCommand( 'formatmatch' );
  20851. * ```
  20852. */
  20853. UE.plugins['formatmatch'] = function(){
  20854. var me = this,
  20855. list = [],img,
  20856. flag = 0;
  20857. me.addListener('reset',function(){
  20858. list = [];
  20859. flag = 0;
  20860. });
  20861. function addList(type,evt){
  20862. if(browser.webkit){
  20863. var target = evt.target.tagName == 'IMG' ? evt.target : null;
  20864. }
  20865. function addFormat(range){
  20866. if(text){
  20867. range.selectNode(text);
  20868. }
  20869. return range.applyInlineStyle(list[list.length-1].tagName,null,list);
  20870. }
  20871. me.undoManger && me.undoManger.save();
  20872. var range = me.selection.getRange(),
  20873. imgT = target || range.getClosedNode();
  20874. if(img && imgT && imgT.tagName == 'IMG'){
  20875. //trace:964
  20876. imgT.style.cssText += ';float:' + (img.style.cssFloat || img.style.styleFloat ||'none') + ';display:' + (img.style.display||'inline');
  20877. img = null;
  20878. }else{
  20879. if(!img){
  20880. var collapsed = range.collapsed;
  20881. if(collapsed){
  20882. var text = me.document.createTextNode('match');
  20883. range.insertNode(text).select();
  20884. }
  20885. me.__hasEnterExecCommand = true;
  20886. //不能把block上的属性干掉
  20887. //trace:1553
  20888. var removeFormatAttributes = me.options.removeFormatAttributes;
  20889. me.options.removeFormatAttributes = '';
  20890. me.execCommand('removeformat');
  20891. me.options.removeFormatAttributes = removeFormatAttributes;
  20892. me.__hasEnterExecCommand = false;
  20893. //trace:969
  20894. range = me.selection.getRange();
  20895. if(list.length){
  20896. addFormat(range);
  20897. }
  20898. if(text){
  20899. range.setStartBefore(text).collapse(true);
  20900. }
  20901. range.select();
  20902. text && domUtils.remove(text);
  20903. }
  20904. }
  20905. me.undoManger && me.undoManger.save();
  20906. me.removeListener('mouseup',addList);
  20907. flag = 0;
  20908. }
  20909. me.commands['formatmatch'] = {
  20910. execCommand : function( cmdName ) {
  20911. if(flag){
  20912. flag = 0;
  20913. list = [];
  20914. me.removeListener('mouseup',addList);
  20915. return;
  20916. }
  20917. var range = me.selection.getRange();
  20918. img = range.getClosedNode();
  20919. if(!img || img.tagName != 'IMG'){
  20920. range.collapse(true).shrinkBoundary();
  20921. var start = range.startContainer;
  20922. list = domUtils.findParents(start,true,function(node){
  20923. return !domUtils.isBlockElm(node) && node.nodeType == 1;
  20924. });
  20925. //a不能加入格式刷, 并且克隆节点
  20926. for(var i=0,ci;ci=list[i];i++){
  20927. if(ci.tagName == 'A'){
  20928. list.splice(i,1);
  20929. break;
  20930. }
  20931. }
  20932. }
  20933. me.addListener('mouseup',addList);
  20934. flag = 1;
  20935. },
  20936. queryCommandState : function() {
  20937. return flag;
  20938. },
  20939. notNeedUndo : 1
  20940. };
  20941. };
  20942. // plugins/searchreplace.js
  20943. ///import core
  20944. ///commands 查找替换
  20945. ///commandsName SearchReplace
  20946. ///commandsTitle 查询替换
  20947. ///commandsDialog dialogs\searchreplace
  20948. /**
  20949. * @description 查找替换
  20950. * @author zhanyi
  20951. */
  20952. UE.plugin.register('searchreplace',function(){
  20953. var me = this;
  20954. var _blockElm = {'table':1,'tbody':1,'tr':1,'ol':1,'ul':1};
  20955. function findTextInString(textContent,opt,currentIndex){
  20956. var str = opt.searchStr;
  20957. if(opt.dir == -1){
  20958. textContent = textContent.split('').reverse().join('');
  20959. str = str.split('').reverse().join('');
  20960. currentIndex = textContent.length - currentIndex;
  20961. }
  20962. var reg = new RegExp(str,'g' + (opt.casesensitive ? '' : 'i')),match;
  20963. while(match = reg.exec(textContent)){
  20964. if(match.index >= currentIndex){
  20965. return opt.dir == -1 ? textContent.length - match.index - opt.searchStr.length : match.index;
  20966. }
  20967. }
  20968. return -1
  20969. }
  20970. function findTextBlockElm(node,currentIndex,opt){
  20971. var textContent,index,methodName = opt.all || opt.dir == 1 ? 'getNextDomNode' : 'getPreDomNode';
  20972. if(domUtils.isBody(node)){
  20973. node = node.firstChild;
  20974. }
  20975. var first = 1;
  20976. while(node){
  20977. textContent = node.nodeType == 3 ? node.nodeValue : node[browser.ie ? 'innerText' : 'textContent'];
  20978. index = findTextInString(textContent,opt,currentIndex );
  20979. first = 0;
  20980. if(index!=-1){
  20981. return {
  20982. 'node':node,
  20983. 'index':index
  20984. }
  20985. }
  20986. node = domUtils[methodName](node);
  20987. while(node && _blockElm[node.nodeName.toLowerCase()]){
  20988. node = domUtils[methodName](node,true);
  20989. }
  20990. if(node){
  20991. currentIndex = opt.dir == -1 ? (node.nodeType == 3 ? node.nodeValue : node[browser.ie ? 'innerText' : 'textContent']).length : 0;
  20992. }
  20993. }
  20994. }
  20995. function findNTextInBlockElm(node,index,str){
  20996. var currentIndex = 0,
  20997. currentNode = node.firstChild,
  20998. currentNodeLength = 0,
  20999. result;
  21000. while(currentNode){
  21001. if(currentNode.nodeType == 3){
  21002. currentNodeLength = currentNode.nodeValue.replace(/(^[\t\r\n]+)|([\t\r\n]+$)/,'').length;
  21003. currentIndex += currentNodeLength;
  21004. if(currentIndex >= index){
  21005. return {
  21006. 'node':currentNode,
  21007. 'index': currentNodeLength - (currentIndex - index)
  21008. }
  21009. }
  21010. }else if(!dtd.$empty[currentNode.tagName]){
  21011. currentNodeLength = currentNode[browser.ie ? 'innerText' : 'textContent'].replace(/(^[\t\r\n]+)|([\t\r\n]+$)/,'').length
  21012. currentIndex += currentNodeLength;
  21013. if(currentIndex >= index){
  21014. result = findNTextInBlockElm(currentNode,currentNodeLength - (currentIndex - index),str);
  21015. if(result){
  21016. return result;
  21017. }
  21018. }
  21019. }
  21020. currentNode = domUtils.getNextDomNode(currentNode);
  21021. }
  21022. }
  21023. function searchReplace(me,opt){
  21024. var rng = me.selection.getRange(),
  21025. startBlockNode,
  21026. searchStr = opt.searchStr,
  21027. span = me.document.createElement('span');
  21028. span.innerHTML = '$$ueditor_searchreplace_key$$';
  21029. rng.shrinkBoundary(true);
  21030. //判断是不是第一次选中
  21031. if(!rng.collapsed){
  21032. rng.select();
  21033. var rngText = me.selection.getText();
  21034. if(new RegExp('^' + opt.searchStr + '$',(opt.casesensitive ? '' : 'i')).test(rngText)){
  21035. if(opt.replaceStr != undefined){
  21036. replaceText(rng,opt.replaceStr);
  21037. rng.select();
  21038. return true;
  21039. }else{
  21040. rng.collapse(opt.dir == -1)
  21041. }
  21042. }
  21043. }
  21044. rng.insertNode(span);
  21045. rng.enlargeToBlockElm(true);
  21046. startBlockNode = rng.startContainer;
  21047. var currentIndex = startBlockNode[browser.ie ? 'innerText' : 'textContent'].indexOf('$$ueditor_searchreplace_key$$');
  21048. rng.setStartBefore(span);
  21049. domUtils.remove(span);
  21050. var result = findTextBlockElm(startBlockNode,currentIndex,opt);
  21051. if(result){
  21052. var rngStart = findNTextInBlockElm(result.node,result.index,searchStr);
  21053. var rngEnd = findNTextInBlockElm(result.node,result.index + searchStr.length,searchStr);
  21054. rng.setStart(rngStart.node,rngStart.index).setEnd(rngEnd.node,rngEnd.index);
  21055. if(opt.replaceStr !== undefined){
  21056. replaceText(rng,opt.replaceStr)
  21057. }
  21058. rng.select();
  21059. return true;
  21060. }else{
  21061. rng.setCursor()
  21062. }
  21063. }
  21064. function replaceText(rng,str){
  21065. str = me.document.createTextNode(str);
  21066. rng.deleteContents().insertNode(str);
  21067. }
  21068. return {
  21069. commands:{
  21070. 'searchreplace':{
  21071. execCommand:function(cmdName,opt){
  21072. utils.extend(opt,{
  21073. all : false,
  21074. casesensitive : false,
  21075. dir : 1
  21076. },true);
  21077. var num = 0;
  21078. if(opt.all){
  21079. var rng = me.selection.getRange(),
  21080. first = me.body.firstChild;
  21081. if(first && first.nodeType == 1){
  21082. rng.setStart(first,0);
  21083. rng.shrinkBoundary(true);
  21084. }else if(first.nodeType == 3){
  21085. rng.setStartBefore(first)
  21086. }
  21087. rng.collapse(true).select(true);
  21088. if(opt.replaceStr !== undefined){
  21089. me.fireEvent('saveScene');
  21090. }
  21091. while(searchReplace(this,opt)){
  21092. num++;
  21093. }
  21094. if(num){
  21095. me.fireEvent('saveScene');
  21096. }
  21097. }else{
  21098. if(opt.replaceStr !== undefined){
  21099. me.fireEvent('saveScene');
  21100. }
  21101. if(searchReplace(this,opt)){
  21102. num++
  21103. }
  21104. if(num){
  21105. me.fireEvent('saveScene');
  21106. }
  21107. }
  21108. return num;
  21109. },
  21110. notNeedUndo:1
  21111. }
  21112. }
  21113. }
  21114. });
  21115. // plugins/customstyle.js
  21116. /**
  21117. * 自定义样式
  21118. * @file
  21119. * @since 1.2.6.1
  21120. */
  21121. /**
  21122. * 根据config配置文件里“customstyle”选项的值对匹配的标签执行样式替换。
  21123. * @command customstyle
  21124. * @method execCommand
  21125. * @param { String } cmd 命令字符串
  21126. * @example
  21127. * ```javascript
  21128. * editor.execCommand( 'customstyle' );
  21129. * ```
  21130. */
  21131. UE.plugins['customstyle'] = function() {
  21132. var me = this;
  21133. me.setOpt({ 'customstyle':[
  21134. {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;'},
  21135. {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;'},
  21136. {tag:'span',name:'im', style:'font-size:16px;font-style:italic;font-weight:bold;line-height:18px;'},
  21137. {tag:'span',name:'hi', style:'font-size:16px;font-style:italic;font-weight:bold;color:rgb(51, 153, 204);line-height:18px;'}
  21138. ]});
  21139. me.commands['customstyle'] = {
  21140. execCommand : function(cmdName, obj) {
  21141. var me = this,
  21142. tagName = obj.tag,
  21143. node = domUtils.findParent(me.selection.getStart(), function(node) {
  21144. return node.getAttribute('label');
  21145. }, true),
  21146. range,bk,tmpObj = {};
  21147. for (var p in obj) {
  21148. if(obj[p]!==undefined)
  21149. tmpObj[p] = obj[p];
  21150. }
  21151. delete tmpObj.tag;
  21152. if (node && node.getAttribute('label') == obj.label) {
  21153. range = this.selection.getRange();
  21154. bk = range.createBookmark();
  21155. if (range.collapsed) {
  21156. //trace:1732 删掉自定义标签,要有p来回填站位
  21157. if(dtd.$block[node.tagName]){
  21158. var fillNode = me.document.createElement('p');
  21159. domUtils.moveChild(node, fillNode);
  21160. node.parentNode.insertBefore(fillNode, node);
  21161. domUtils.remove(node);
  21162. }else{
  21163. domUtils.remove(node,true);
  21164. }
  21165. } else {
  21166. var common = domUtils.getCommonAncestor(bk.start, bk.end),
  21167. nodes = domUtils.getElementsByTagName(common, tagName);
  21168. if(new RegExp(tagName,'i').test(common.tagName)){
  21169. nodes.push(common);
  21170. }
  21171. for (var i = 0,ni; ni = nodes[i++];) {
  21172. if (ni.getAttribute('label') == obj.label) {
  21173. var ps = domUtils.getPosition(ni, bk.start),pe = domUtils.getPosition(ni, bk.end);
  21174. if ((ps & domUtils.POSITION_FOLLOWING || ps & domUtils.POSITION_CONTAINS)
  21175. &&
  21176. (pe & domUtils.POSITION_PRECEDING || pe & domUtils.POSITION_CONTAINS)
  21177. )
  21178. if (dtd.$block[tagName]) {
  21179. var fillNode = me.document.createElement('p');
  21180. domUtils.moveChild(ni, fillNode);
  21181. ni.parentNode.insertBefore(fillNode, ni);
  21182. }
  21183. domUtils.remove(ni, true);
  21184. }
  21185. }
  21186. node = domUtils.findParent(common, function(node) {
  21187. return node.getAttribute('label') == obj.label;
  21188. }, true);
  21189. if (node) {
  21190. domUtils.remove(node, true);
  21191. }
  21192. }
  21193. range.moveToBookmark(bk).select();
  21194. } else {
  21195. if (dtd.$block[tagName]) {
  21196. this.execCommand('paragraph', tagName, tmpObj,'customstyle');
  21197. range = me.selection.getRange();
  21198. if (!range.collapsed) {
  21199. range.collapse();
  21200. node = domUtils.findParent(me.selection.getStart(), function(node) {
  21201. return node.getAttribute('label') == obj.label;
  21202. }, true);
  21203. var pNode = me.document.createElement('p');
  21204. domUtils.insertAfter(node, pNode);
  21205. domUtils.fillNode(me.document, pNode);
  21206. range.setStart(pNode, 0).setCursor();
  21207. }
  21208. } else {
  21209. range = me.selection.getRange();
  21210. if (range.collapsed) {
  21211. node = me.document.createElement(tagName);
  21212. domUtils.setAttributes(node, tmpObj);
  21213. range.insertNode(node).setStart(node, 0).setCursor();
  21214. return;
  21215. }
  21216. bk = range.createBookmark();
  21217. range.applyInlineStyle(tagName, tmpObj).moveToBookmark(bk).select();
  21218. }
  21219. }
  21220. },
  21221. queryCommandValue : function() {
  21222. var parent = domUtils.filterNodeList(
  21223. this.selection.getStartElementPath(),
  21224. function(node){return node.getAttribute('label')}
  21225. );
  21226. return parent ? parent.getAttribute('label') : '';
  21227. }
  21228. };
  21229. //当去掉customstyle是,如果是块元素,用p代替
  21230. me.addListener('keyup', function(type, evt) {
  21231. var keyCode = evt.keyCode || evt.which;
  21232. if (keyCode == 32 || keyCode == 13) {
  21233. var range = me.selection.getRange();
  21234. if (range.collapsed) {
  21235. var node = domUtils.findParent(me.selection.getStart(), function(node) {
  21236. return node.getAttribute('label');
  21237. }, true);
  21238. if (node && dtd.$block[node.tagName] && domUtils.isEmptyNode(node)) {
  21239. var p = me.document.createElement('p');
  21240. domUtils.insertAfter(node, p);
  21241. domUtils.fillNode(me.document, p);
  21242. domUtils.remove(node);
  21243. range.setStart(p, 0).setCursor();
  21244. }
  21245. }
  21246. }
  21247. });
  21248. };
  21249. // plugins/catchremoteimage.js
  21250. ///import core
  21251. ///commands 远程图片抓取
  21252. ///commandsName catchRemoteImage,catchremoteimageenable
  21253. ///commandsTitle 远程图片抓取
  21254. /**
  21255. * 远程图片抓取,当开启本插件时所有不符合本地域名的图片都将被抓取成为本地服务器上的图片
  21256. */
  21257. UE.plugins['catchremoteimage'] = function () {
  21258. var me = this,
  21259. ajax = UE.ajax;
  21260. /* 设置默认值 */
  21261. if (me.options.catchRemoteImageEnable === false) return;
  21262. me.setOpt({
  21263. catchRemoteImageEnable: false
  21264. });
  21265. me.addListener("afterpaste", function () {
  21266. me.fireEvent("catchRemoteImage");
  21267. });
  21268. me.addListener("catchRemoteImage", function () {
  21269. var catcherLocalDomain = me.getOpt('catcherLocalDomain'),
  21270. catcherActionUrl = me.getActionUrl(me.getOpt('catcherActionName')),
  21271. catcherUrlPrefix = me.getOpt('catcherUrlPrefix'),
  21272. catcherFieldName = me.getOpt('catcherFieldName');
  21273. var remoteImages = [],
  21274. imgs = domUtils.getElementsByTagName(me.document, "img"),
  21275. test = function (src, urls) {
  21276. if (src.indexOf(location.host) != -1 || /(^\.)|(^\/)/.test(src)) {
  21277. return true;
  21278. }
  21279. if (urls) {
  21280. for (var j = 0, url; url = urls[j++];) {
  21281. if (src.indexOf(url) !== -1) {
  21282. return true;
  21283. }
  21284. }
  21285. }
  21286. return false;
  21287. };
  21288. for (var i = 0, ci; ci = imgs[i++];) {
  21289. if (ci.getAttribute("word_img")) {
  21290. continue;
  21291. }
  21292. var src = ci.getAttribute("_src") || ci.src || "";
  21293. if (/^(https?|ftp):/i.test(src) && !test(src, catcherLocalDomain)) {
  21294. remoteImages.push(src);
  21295. }
  21296. }
  21297. if (remoteImages.length) {
  21298. catchremoteimage(remoteImages, {
  21299. //成功抓取
  21300. success: function (r) {
  21301. try {
  21302. var info = r.state !== undefined ? r:eval("(" + r.responseText + ")");
  21303. } catch (e) {
  21304. return;
  21305. }
  21306. /* 获取源路径和新路径 */
  21307. var i, j, ci, cj, oldSrc, newSrc, list = info.list;
  21308. for (i = 0; ci = imgs[i++];) {
  21309. oldSrc = ci.getAttribute("_src") || ci.src || "";
  21310. for (j = 0; cj = list[j++];) {
  21311. if (oldSrc == cj.source && cj.state == "SUCCESS") { //抓取失败时不做替换处理
  21312. newSrc = catcherUrlPrefix + cj.url;
  21313. domUtils.setAttributes(ci, {
  21314. "src": newSrc,
  21315. "_src": newSrc
  21316. });
  21317. break;
  21318. }
  21319. }
  21320. }
  21321. me.fireEvent('catchremotesuccess')
  21322. },
  21323. //回调失败,本次请求超时
  21324. error: function () {
  21325. me.fireEvent("catchremoteerror");
  21326. }
  21327. });
  21328. }
  21329. function catchremoteimage(imgs, callbacks) {
  21330. var params = utils.serializeParam(me.queryCommandValue('serverparam')) || '',
  21331. url = utils.formatUrl(catcherActionUrl + (catcherActionUrl.indexOf('?') == -1 ? '?':'&') + params),
  21332. isJsonp = utils.isCrossDomainUrl(url),
  21333. opt = {
  21334. 'method': 'POST',
  21335. 'dataType': isJsonp ? 'jsonp':'',
  21336. 'timeout': 60000, //单位:毫秒,回调请求超时设置。目标用户如果网速不是很快的话此处建议设置一个较大的数值
  21337. 'onsuccess': callbacks["success"],
  21338. 'onerror': callbacks["error"]
  21339. };
  21340. opt[catcherFieldName] = imgs;
  21341. ajax.request(url, opt);
  21342. }
  21343. });
  21344. };
  21345. // plugins/snapscreen.js
  21346. /**
  21347. * 截屏插件,为UEditor提供插入支持
  21348. * @file
  21349. * @since 1.4.2
  21350. */
  21351. UE.plugin.register('snapscreen', function (){
  21352. var me = this;
  21353. var snapplugin;
  21354. function getLocation(url){
  21355. var search,
  21356. a = document.createElement('a'),
  21357. params = utils.serializeParam(me.queryCommandValue('serverparam')) || '';
  21358. a.href = url;
  21359. if (browser.ie) {
  21360. a.href = a.href;
  21361. }
  21362. search = a.search;
  21363. if (params) {
  21364. search = search + (search.indexOf('?') == -1 ? '?':'&')+ params;
  21365. search = search.replace(/[&]+/ig, '&');
  21366. }
  21367. return {
  21368. 'port': a.port,
  21369. 'hostname': a.hostname,
  21370. 'path': a.pathname + search || + a.hash
  21371. }
  21372. }
  21373. return {
  21374. commands:{
  21375. /**
  21376. * 字体背景颜色
  21377. * @command snapscreen
  21378. * @method execCommand
  21379. * @param { String } cmd 命令字符串
  21380. * @example
  21381. * ```javascript
  21382. * editor.execCommand('snapscreen');
  21383. * ```
  21384. */
  21385. 'snapscreen':{
  21386. execCommand:function (cmd) {
  21387. var url, local, res;
  21388. var lang = me.getLang("snapScreen_plugin");
  21389. if(!snapplugin){
  21390. var container = me.container;
  21391. var doc = me.container.ownerDocument || me.container.document;
  21392. snapplugin = doc.createElement("object");
  21393. try{snapplugin.type = "application/x-pluginbaidusnap";}catch(e){
  21394. return;
  21395. }
  21396. snapplugin.style.cssText = "position:absolute;left:-9999px;width:0;height:0;";
  21397. snapplugin.setAttribute("width","0");
  21398. snapplugin.setAttribute("height","0");
  21399. container.appendChild(snapplugin);
  21400. }
  21401. function onSuccess(rs){
  21402. try{
  21403. rs = eval("("+ rs +")");
  21404. if(rs.state == 'SUCCESS'){
  21405. var opt = me.options;
  21406. me.execCommand('insertimage', {
  21407. src: opt.snapscreenUrlPrefix + rs.url,
  21408. _src: opt.snapscreenUrlPrefix + rs.url,
  21409. alt: rs.title || '',
  21410. floatStyle: opt.snapscreenImgAlign
  21411. });
  21412. } else {
  21413. alert(rs.state);
  21414. }
  21415. }catch(e){
  21416. alert(lang.callBackErrorMsg);
  21417. }
  21418. }
  21419. url = me.getActionUrl(me.getOpt('snapscreenActionName'));
  21420. local = getLocation(url);
  21421. setTimeout(function () {
  21422. try{
  21423. res =snapplugin.saveSnapshot(local.hostname, local.path, local.port);
  21424. }catch(e){
  21425. me.ui._dialogs['snapscreenDialog'].open();
  21426. return;
  21427. }
  21428. onSuccess(res);
  21429. }, 50);
  21430. },
  21431. queryCommandState: function(){
  21432. return (navigator.userAgent.indexOf("Windows",0) != -1) ? 0:-1;
  21433. }
  21434. }
  21435. }
  21436. }
  21437. });
  21438. // plugins/insertparagraph.js
  21439. /**
  21440. * 插入段落
  21441. * @file
  21442. * @since 1.2.6.1
  21443. */
  21444. /**
  21445. * 插入段落
  21446. * @command insertparagraph
  21447. * @method execCommand
  21448. * @param { String } cmd 命令字符串
  21449. * @example
  21450. * ```javascript
  21451. * //editor是编辑器实例
  21452. * editor.execCommand( 'insertparagraph' );
  21453. * ```
  21454. */
  21455. UE.commands['insertparagraph'] = {
  21456. execCommand : function( cmdName,front) {
  21457. var me = this,
  21458. range = me.selection.getRange(),
  21459. start = range.startContainer,tmpNode;
  21460. while(start ){
  21461. if(domUtils.isBody(start)){
  21462. break;
  21463. }
  21464. tmpNode = start;
  21465. start = start.parentNode;
  21466. }
  21467. if(tmpNode){
  21468. var p = me.document.createElement('p');
  21469. if(front){
  21470. tmpNode.parentNode.insertBefore(p,tmpNode)
  21471. }else{
  21472. tmpNode.parentNode.insertBefore(p,tmpNode.nextSibling)
  21473. }
  21474. domUtils.fillNode(me.document,p);
  21475. range.setStart(p,0).setCursor(false,true);
  21476. }
  21477. }
  21478. };
  21479. // plugins/webapp.js
  21480. /**
  21481. * 百度应用
  21482. * @file
  21483. * @since 1.2.6.1
  21484. */
  21485. /**
  21486. * 插入百度应用
  21487. * @command webapp
  21488. * @method execCommand
  21489. * @remind 需要百度APPKey
  21490. * @remind 百度应用主页: <a href="http://app.baidu.com/" target="_blank">http://app.baidu.com/</a>
  21491. * @param { Object } appOptions 应用所需的参数项, 支持的key有: title=>应用标题, width=>应用容器宽度,
  21492. * height=>应用容器高度,logo=>应用logo,url=>应用地址
  21493. * @example
  21494. * ```javascript
  21495. * //editor是编辑器实例
  21496. * //在编辑器里插入一个“植物大战僵尸”的APP
  21497. * editor.execCommand( 'webapp' , {
  21498. * title: '植物大战僵尸',
  21499. * width: 560,
  21500. * height: 465,
  21501. * logo: '应用展示的图片',
  21502. * url: '百度应用的地址'
  21503. * } );
  21504. * ```
  21505. */
  21506. //UE.plugins['webapp'] = function () {
  21507. // var me = this;
  21508. // function createInsertStr( obj, toIframe, addParagraph ) {
  21509. // return !toIframe ?
  21510. // (addParagraph ? '<p>' : '') + '<img title="'+obj.title+'" width="' + obj.width + '" height="' + obj.height + '"' +
  21511. // ' 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 + '" />' +
  21512. // (addParagraph ? '</p>' : '')
  21513. // :
  21514. // '<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>';
  21515. // }
  21516. //
  21517. // function switchImgAndIframe( img2frame ) {
  21518. // var tmpdiv,
  21519. // nodes = domUtils.getElementsByTagName( me.document, !img2frame ? "iframe" : "img" );
  21520. // for ( var i = 0, node; node = nodes[i++]; ) {
  21521. // if ( node.className != "edui-faked-webapp" ){
  21522. // continue;
  21523. // }
  21524. // tmpdiv = me.document.createElement( "div" );
  21525. // 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 );
  21526. // node.parentNode.replaceChild( tmpdiv.firstChild, node );
  21527. // }
  21528. // }
  21529. //
  21530. // me.addListener( "beforegetcontent", function () {
  21531. // switchImgAndIframe( true );
  21532. // } );
  21533. // me.addListener( 'aftersetcontent', function () {
  21534. // switchImgAndIframe( false );
  21535. // } );
  21536. // me.addListener( 'aftergetcontent', function ( cmdName ) {
  21537. // if ( cmdName == 'aftergetcontent' && me.queryCommandState( 'source' ) ){
  21538. // return;
  21539. // }
  21540. // switchImgAndIframe( false );
  21541. // } );
  21542. //
  21543. // me.commands['webapp'] = {
  21544. // execCommand:function ( cmd, obj ) {
  21545. // me.execCommand( "inserthtml", createInsertStr( obj, false,true ) );
  21546. // }
  21547. // };
  21548. //};
  21549. UE.plugin.register('webapp', function (){
  21550. var me = this;
  21551. function createInsertStr(obj,toEmbed){
  21552. return !toEmbed ?
  21553. '<img title="'+obj.title+'" width="' + obj.width + '" height="' + obj.height + '"' +
  21554. ' src="' + me.options.UEDITOR_HOME_URL + 'themes/default/images/spacer.gif" _logo_url="'+obj.logo+'" style="background:url(' + obj.logo
  21555. +') no-repeat center center; border:1px solid gray;" class="edui-faked-webapp" _url="' + obj.url + '" ' +
  21556. (obj.align && !obj.cssfloat? 'align="' + obj.align + '"' : '') +
  21557. (obj.cssfloat ? 'style="float:' + obj.cssfloat + '"' : '') +
  21558. '/>'
  21559. :
  21560. '<iframe class="edui-faked-webapp" title="'+obj.title+'" ' +
  21561. (obj.align && !obj.cssfloat? 'align="' + obj.align + '"' : '') +
  21562. (obj.cssfloat ? 'style="float:' + obj.cssfloat + '"' : '') +
  21563. 'width="' + obj.width + '" height="' + obj.height + '" scrolling="no" frameborder="0" src="' + obj.url + '" logo_url = "'+obj.logo+'"></iframe>'
  21564. }
  21565. return {
  21566. outputRule: function(root){
  21567. utils.each(root.getNodesByTagName('img'),function(node){
  21568. var html;
  21569. if(node.getAttr('class') == 'edui-faked-webapp'){
  21570. html = createInsertStr({
  21571. title:node.getAttr('title'),
  21572. 'width':node.getAttr('width'),
  21573. 'height':node.getAttr('height'),
  21574. 'align':node.getAttr('align'),
  21575. 'cssfloat':node.getStyle('float'),
  21576. 'url':node.getAttr("_url"),
  21577. 'logo':node.getAttr('_logo_url')
  21578. },true);
  21579. var embed = UE.uNode.createElement(html);
  21580. node.parentNode.replaceChild(embed,node);
  21581. }
  21582. })
  21583. },
  21584. inputRule:function(root){
  21585. utils.each(root.getNodesByTagName('iframe'),function(node){
  21586. if(node.getAttr('class') == 'edui-faked-webapp'){
  21587. var img = UE.uNode.createElement(createInsertStr({
  21588. title:node.getAttr('title'),
  21589. 'width':node.getAttr('width'),
  21590. 'height':node.getAttr('height'),
  21591. 'align':node.getAttr('align'),
  21592. 'cssfloat':node.getStyle('float'),
  21593. 'url':node.getAttr("src"),
  21594. 'logo':node.getAttr('logo_url')
  21595. }));
  21596. node.parentNode.replaceChild(img,node);
  21597. }
  21598. })
  21599. },
  21600. commands:{
  21601. /**
  21602. * 插入百度应用
  21603. * @command webapp
  21604. * @method execCommand
  21605. * @remind 需要百度APPKey
  21606. * @remind 百度应用主页: <a href="http://app.baidu.com/" target="_blank">http://app.baidu.com/</a>
  21607. * @param { Object } appOptions 应用所需的参数项, 支持的key有: title=>应用标题, width=>应用容器宽度,
  21608. * height=>应用容器高度,logo=>应用logo,url=>应用地址
  21609. * @example
  21610. * ```javascript
  21611. * //editor是编辑器实例
  21612. * //在编辑器里插入一个“植物大战僵尸”的APP
  21613. * editor.execCommand( 'webapp' , {
  21614. * title: '植物大战僵尸',
  21615. * width: 560,
  21616. * height: 465,
  21617. * logo: '应用展示的图片',
  21618. * url: '百度应用的地址'
  21619. * } );
  21620. * ```
  21621. */
  21622. 'webapp':{
  21623. execCommand:function (cmd, obj) {
  21624. var me = this,
  21625. str = createInsertStr(utils.extend(obj,{
  21626. align:'none'
  21627. }), false);
  21628. me.execCommand("inserthtml",str);
  21629. },
  21630. queryCommandState:function () {
  21631. var me = this,
  21632. img = me.selection.getRange().getClosedNode(),
  21633. flag = img && (img.className == "edui-faked-webapp");
  21634. return flag ? 1 : 0;
  21635. }
  21636. }
  21637. }
  21638. }
  21639. });
  21640. // plugins/template.js
  21641. ///import core
  21642. ///import plugins\inserthtml.js
  21643. ///import plugins\cleardoc.js
  21644. ///commands 模板
  21645. ///commandsName template
  21646. ///commandsTitle 模板
  21647. ///commandsDialog dialogs\template
  21648. UE.plugins['template'] = function () {
  21649. UE.commands['template'] = {
  21650. execCommand:function (cmd, obj) {
  21651. obj.html && this.execCommand("inserthtml", obj.html);
  21652. }
  21653. };
  21654. this.addListener("click", function (type, evt) {
  21655. var el = evt.target || evt.srcElement,
  21656. range = this.selection.getRange();
  21657. var tnode = domUtils.findParent(el, function (node) {
  21658. if (node.className && domUtils.hasClass(node, "ue_t")) {
  21659. return node;
  21660. }
  21661. }, true);
  21662. tnode && range.selectNode(tnode).shrinkBoundary().select();
  21663. });
  21664. this.addListener("keydown", function (type, evt) {
  21665. var range = this.selection.getRange();
  21666. if (!range.collapsed) {
  21667. if (!evt.ctrlKey && !evt.metaKey && !evt.shiftKey && !evt.altKey) {
  21668. var tnode = domUtils.findParent(range.startContainer, function (node) {
  21669. if (node.className && domUtils.hasClass(node, "ue_t")) {
  21670. return node;
  21671. }
  21672. }, true);
  21673. if (tnode) {
  21674. domUtils.removeClasses(tnode, ["ue_t"]);
  21675. }
  21676. }
  21677. }
  21678. });
  21679. };
  21680. // plugins/music.js
  21681. /**
  21682. * 插入音乐命令
  21683. * @file
  21684. */
  21685. UE.plugin.register('music', function (){
  21686. var me = this;
  21687. function creatInsertStr(url,width,height,align,cssfloat,toEmbed){
  21688. return !toEmbed ?
  21689. '<img ' +
  21690. (align && !cssfloat? 'align="' + align + '"' : '') +
  21691. (cssfloat ? 'style="float:' + cssfloat + '"' : '') +
  21692. ' width="'+ width +'" height="' + height + '" _url="'+url+'" class="edui-faked-music"' +
  21693. ' src="'+me.options.langPath+me.options.lang+'/images/music.png" />'
  21694. :
  21695. '<embed type="application/x-shockwave-flash" class="edui-faked-music" pluginspage="http://www.macromedia.com/go/getflashplayer"' +
  21696. ' src="' + url + '" width="' + width + '" height="' + height + '" '+ (align && !cssfloat? 'align="' + align + '"' : '') +
  21697. (cssfloat ? 'style="float:' + cssfloat + '"' : '') +
  21698. ' wmode="transparent" play="true" loop="false" menu="false" allowscriptaccess="never" allowfullscreen="true" >';
  21699. }
  21700. return {
  21701. outputRule: function(root){
  21702. utils.each(root.getNodesByTagName('img'),function(node){
  21703. var html;
  21704. if(node.getAttr('class') == 'edui-faked-music'){
  21705. var cssfloat = node.getStyle('float');
  21706. var align = node.getAttr('align');
  21707. html = creatInsertStr(node.getAttr("_url"), node.getAttr('width'), node.getAttr('height'), align, cssfloat, true);
  21708. var embed = UE.uNode.createElement(html);
  21709. node.parentNode.replaceChild(embed,node);
  21710. }
  21711. })
  21712. },
  21713. inputRule:function(root){
  21714. utils.each(root.getNodesByTagName('embed'),function(node){
  21715. if(node.getAttr('class') == 'edui-faked-music'){
  21716. var cssfloat = node.getStyle('float');
  21717. var align = node.getAttr('align');
  21718. html = creatInsertStr(node.getAttr("src"), node.getAttr('width'), node.getAttr('height'), align, cssfloat,false);
  21719. var img = UE.uNode.createElement(html);
  21720. node.parentNode.replaceChild(img,node);
  21721. }
  21722. })
  21723. },
  21724. commands:{
  21725. /**
  21726. * 插入音乐
  21727. * @command music
  21728. * @method execCommand
  21729. * @param { Object } musicOptions 插入音乐的参数项, 支持的key有: url=>音乐地址;
  21730. * width=>音乐容器宽度;height=>音乐容器高度;align=>音乐文件的对齐方式, 可选值有: left, center, right, none
  21731. * @example
  21732. * ```javascript
  21733. * //editor是编辑器实例
  21734. * //在编辑器里插入一个“植物大战僵尸”的APP
  21735. * editor.execCommand( 'music' , {
  21736. * width: 400,
  21737. * height: 95,
  21738. * align: "center",
  21739. * url: "音乐地址"
  21740. * } );
  21741. * ```
  21742. */
  21743. 'music':{
  21744. execCommand:function (cmd, musicObj) {
  21745. var me = this,
  21746. str = creatInsertStr(musicObj.url, musicObj.width || 400, musicObj.height || 95, "none", false);
  21747. me.execCommand("inserthtml",str);
  21748. },
  21749. queryCommandState:function () {
  21750. var me = this,
  21751. img = me.selection.getRange().getClosedNode(),
  21752. flag = img && (img.className == "edui-faked-music");
  21753. return flag ? 1 : 0;
  21754. }
  21755. }
  21756. }
  21757. }
  21758. });
  21759. // plugins/autoupload.js
  21760. /**
  21761. * @description
  21762. * 1.拖放文件到编辑区域,自动上传并插入到选区
  21763. * 2.插入粘贴板的图片,自动上传并插入到选区
  21764. * @author Jinqn
  21765. * @date 2013-10-14
  21766. */
  21767. UE.plugin.register('autoupload', function (){
  21768. function sendAndInsertFile(file, editor) {
  21769. var me = editor;
  21770. //模拟数据
  21771. var fieldName, urlPrefix, maxSize, allowFiles, actionUrl,
  21772. loadingHtml, errorHandler, successHandler,
  21773. filetype = /image\/\w+/i.test(file.type) ? 'image':'file',
  21774. loadingId = 'loading_' + (+new Date()).toString(36);
  21775. fieldName = me.getOpt(filetype + 'FieldName');
  21776. urlPrefix = me.getOpt(filetype + 'UrlPrefix');
  21777. maxSize = me.getOpt(filetype + 'MaxSize');
  21778. allowFiles = me.getOpt(filetype + 'AllowFiles');
  21779. actionUrl = me.getActionUrl(me.getOpt(filetype + 'ActionName'));
  21780. errorHandler = function(title) {
  21781. var loader = me.document.getElementById(loadingId);
  21782. loader && domUtils.remove(loader);
  21783. me.fireEvent('showmessage', {
  21784. 'id': loadingId,
  21785. 'content': title,
  21786. 'type': 'error',
  21787. 'timeout': 4000
  21788. });
  21789. };
  21790. if (filetype == 'image') {
  21791. loadingHtml = '<img class="loadingclass" id="' + loadingId + '" src="' +
  21792. me.options.themePath + me.options.theme +
  21793. '/images/spacer.gif" title="' + (me.getLang('autoupload.loading') || '') + '" >';
  21794. successHandler = function(data) {
  21795. var link = urlPrefix + data.url,
  21796. loader = me.document.getElementById(loadingId);
  21797. if (loader) {
  21798. loader.setAttribute('src', link);
  21799. loader.setAttribute('_src', link);
  21800. loader.setAttribute('title', data.title || '');
  21801. loader.setAttribute('alt', data.original || '');
  21802. loader.removeAttribute('id');
  21803. domUtils.removeClasses(loader, 'loadingclass');
  21804. }
  21805. };
  21806. } else {
  21807. loadingHtml = '<p>' +
  21808. '<img class="loadingclass" id="' + loadingId + '" src="' +
  21809. me.options.themePath + me.options.theme +
  21810. '/images/spacer.gif" title="' + (me.getLang('autoupload.loading') || '') + '" >' +
  21811. '</p>';
  21812. successHandler = function(data) {
  21813. var link = urlPrefix + data.url,
  21814. loader = me.document.getElementById(loadingId);
  21815. var rng = me.selection.getRange(),
  21816. bk = rng.createBookmark();
  21817. rng.selectNode(loader).select();
  21818. me.execCommand('insertfile', {'url': link});
  21819. rng.moveToBookmark(bk).select();
  21820. };
  21821. }
  21822. /* 插入loading的占位符 */
  21823. me.execCommand('inserthtml', loadingHtml);
  21824. /* 判断后端配置是否没有加载成功 */
  21825. if (!me.getOpt(filetype + 'ActionName')) {
  21826. errorHandler(me.getLang('autoupload.errorLoadConfig'));
  21827. return;
  21828. }
  21829. /* 判断文件大小是否超出限制 */
  21830. if(file.size > maxSize) {
  21831. errorHandler(me.getLang('autoupload.exceedSizeError'));
  21832. return;
  21833. }
  21834. /* 判断文件格式是否超出允许 */
  21835. var fileext = file.name ? file.name.substr(file.name.lastIndexOf('.')):'';
  21836. if ((fileext && filetype != 'image') || (allowFiles && (allowFiles.join('') + '.').indexOf(fileext.toLowerCase() + '.') == -1)) {
  21837. errorHandler(me.getLang('autoupload.exceedTypeError'));
  21838. return;
  21839. }
  21840. /* 创建Ajax并提交 */
  21841. var xhr = new XMLHttpRequest(),
  21842. fd = new FormData(),
  21843. params = utils.serializeParam(me.queryCommandValue('serverparam')) || '',
  21844. url = utils.formatUrl(actionUrl + (actionUrl.indexOf('?') == -1 ? '?':'&') + params);
  21845. fd.append(fieldName, file, file.name || ('blob.' + file.type.substr('image/'.length)));
  21846. fd.append('type', 'ajax');
  21847. xhr.open("post", url, true);
  21848. xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
  21849. xhr.addEventListener('load', function (e) {
  21850. try{
  21851. var json = (new Function("return " + utils.trim(e.target.response)))();
  21852. // if (json.state == 'SUCCESS' && json.url) {
  21853. if (json.code == 1) {
  21854. successHandler(json);
  21855. } else {
  21856. errorHandler(json.state);
  21857. }
  21858. }catch(er){
  21859. errorHandler(me.getLang('autoupload.loadError'));
  21860. }
  21861. });
  21862. xhr.send(fd);
  21863. }
  21864. function getPasteImage(e){
  21865. return e.clipboardData && e.clipboardData.items && e.clipboardData.items.length == 1 && /^image\//.test(e.clipboardData.items[0].type) ? e.clipboardData.items:null;
  21866. }
  21867. function getDropImage(e){
  21868. return e.dataTransfer && e.dataTransfer.files ? e.dataTransfer.files:null;
  21869. }
  21870. return {
  21871. outputRule: function(root){
  21872. utils.each(root.getNodesByTagName('img'),function(n){
  21873. if (/\b(loaderrorclass)|(bloaderrorclass)\b/.test(n.getAttr('class'))) {
  21874. n.parentNode.removeChild(n);
  21875. }
  21876. });
  21877. utils.each(root.getNodesByTagName('p'),function(n){
  21878. if (/\bloadpara\b/.test(n.getAttr('class'))) {
  21879. n.parentNode.removeChild(n);
  21880. }
  21881. });
  21882. },
  21883. bindEvents:{
  21884. //插入粘贴板的图片,拖放插入图片
  21885. 'ready':function(e){
  21886. var me = this;
  21887. if(window.FormData && window.FileReader) {
  21888. domUtils.on(me.body, 'paste drop', function(e){
  21889. var hasImg = false,
  21890. items;
  21891. //获取粘贴板文件列表或者拖放文件列表
  21892. items = e.type == 'paste' ? getPasteImage(e):getDropImage(e);
  21893. if(items){
  21894. var len = items.length,
  21895. file;
  21896. while (len--){
  21897. file = items[len];
  21898. if(file.getAsFile) file = file.getAsFile();
  21899. if(file && file.size > 0) {
  21900. sendAndInsertFile(file, me);
  21901. hasImg = true;
  21902. }
  21903. }
  21904. hasImg && e.preventDefault();
  21905. }
  21906. });
  21907. //取消拖放图片时出现的文字光标位置提示
  21908. domUtils.on(me.body, 'dragover', function (e) {
  21909. if(e.dataTransfer.types[0] == 'Files') {
  21910. e.preventDefault();
  21911. }
  21912. });
  21913. //设置loading的样式
  21914. utils.cssRule('loading',
  21915. '.loadingclass{display:inline-block;cursor:default;background: url(\''
  21916. + this.options.themePath
  21917. + this.options.theme +'/images/loading.gif\') no-repeat center center transparent;border:1px solid #cccccc;margin-left:1px;height: 22px;width: 22px;}\n' +
  21918. '.loaderrorclass{display:inline-block;cursor:default;background: url(\''
  21919. + this.options.themePath
  21920. + this.options.theme +'/images/loaderror.png\') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;' +
  21921. '}',
  21922. this.document);
  21923. }
  21924. }
  21925. }
  21926. }
  21927. });
  21928. // plugins/autosave.js
  21929. UE.plugin.register('autosave', function (){
  21930. var me = this,
  21931. //无限循环保护
  21932. lastSaveTime = new Date(),
  21933. //最小保存间隔时间
  21934. MIN_TIME = 20,
  21935. //auto save key
  21936. saveKey = null;
  21937. function save ( editor ) {
  21938. var saveData;
  21939. if ( new Date() - lastSaveTime < MIN_TIME ) {
  21940. return;
  21941. }
  21942. if ( !editor.hasContents() ) {
  21943. //这里不能调用命令来删除, 会造成事件死循环
  21944. saveKey && me.removePreferences( saveKey );
  21945. return;
  21946. }
  21947. lastSaveTime = new Date();
  21948. editor._saveFlag = null;
  21949. saveData = me.body.innerHTML;
  21950. if ( editor.fireEvent( "beforeautosave", {
  21951. content: saveData
  21952. } ) === false ) {
  21953. return;
  21954. }
  21955. me.setPreferences( saveKey, saveData );
  21956. editor.fireEvent( "afterautosave", {
  21957. content: saveData
  21958. } );
  21959. }
  21960. return {
  21961. defaultOptions: {
  21962. //默认间隔时间
  21963. saveInterval: 500
  21964. },
  21965. bindEvents:{
  21966. 'ready':function(){
  21967. var _suffix = "-drafts-data",
  21968. key = null;
  21969. if ( me.key ) {
  21970. key = me.key + _suffix;
  21971. } else {
  21972. key = ( me.container.parentNode.id || 'ue-common' ) + _suffix;
  21973. }
  21974. //页面地址+编辑器ID 保持唯一
  21975. saveKey = ( location.protocol + location.host + location.pathname ).replace( /[.:\/]/g, '_' ) + key;
  21976. },
  21977. 'contentchange': function () {
  21978. if ( !saveKey ) {
  21979. return;
  21980. }
  21981. if ( me._saveFlag ) {
  21982. window.clearTimeout( me._saveFlag );
  21983. }
  21984. if ( me.options.saveInterval > 0 ) {
  21985. me._saveFlag = window.setTimeout( function () {
  21986. save( me );
  21987. }, me.options.saveInterval );
  21988. } else {
  21989. save(me);
  21990. }
  21991. }
  21992. },
  21993. commands:{
  21994. 'clearlocaldata':{
  21995. execCommand:function (cmd, name) {
  21996. if ( saveKey && me.getPreferences( saveKey ) ) {
  21997. me.removePreferences( saveKey )
  21998. }
  21999. },
  22000. notNeedUndo: true,
  22001. ignoreContentChange:true
  22002. },
  22003. 'getlocaldata':{
  22004. execCommand:function (cmd, name) {
  22005. return saveKey ? me.getPreferences( saveKey ) || '' : '';
  22006. },
  22007. notNeedUndo: true,
  22008. ignoreContentChange:true
  22009. },
  22010. 'drafts':{
  22011. execCommand:function (cmd, name) {
  22012. if ( saveKey ) {
  22013. me.body.innerHTML = me.getPreferences( saveKey ) || '<p>'+domUtils.fillHtml+'</p>';
  22014. me.focus(true);
  22015. }
  22016. },
  22017. queryCommandState: function () {
  22018. return saveKey ? ( me.getPreferences( saveKey ) === null ? -1 : 0 ) : -1;
  22019. },
  22020. notNeedUndo: true,
  22021. ignoreContentChange:true
  22022. }
  22023. }
  22024. }
  22025. });
  22026. // plugins/charts.js
  22027. UE.plugin.register('charts', function (){
  22028. var me = this;
  22029. return {
  22030. bindEvents: {
  22031. 'chartserror': function () {
  22032. }
  22033. },
  22034. commands:{
  22035. 'charts': {
  22036. execCommand: function ( cmd, data ) {
  22037. var tableNode = domUtils.findParentByTagName(this.selection.getRange().startContainer, 'table', true),
  22038. flagText = [],
  22039. config = {};
  22040. if ( !tableNode ) {
  22041. return false;
  22042. }
  22043. if ( !validData( tableNode ) ) {
  22044. me.fireEvent( "chartserror" );
  22045. return false;
  22046. }
  22047. config.title = data.title || '';
  22048. config.subTitle = data.subTitle || '';
  22049. config.xTitle = data.xTitle || '';
  22050. config.yTitle = data.yTitle || '';
  22051. config.suffix = data.suffix || '';
  22052. config.tip = data.tip || '';
  22053. //数据对齐方式
  22054. config.dataFormat = data.tableDataFormat || '';
  22055. //图表类型
  22056. config.chartType = data.chartType || 0;
  22057. for ( var key in config ) {
  22058. if ( !config.hasOwnProperty( key ) ) {
  22059. continue;
  22060. }
  22061. flagText.push( key+":"+config[ key ] );
  22062. }
  22063. tableNode.setAttribute( "data-chart", flagText.join( ";" ) );
  22064. domUtils.addClass( tableNode, "edui-charts-table" );
  22065. },
  22066. queryCommandState: function ( cmd, name ) {
  22067. var tableNode = domUtils.findParentByTagName(this.selection.getRange().startContainer, 'table', true);
  22068. return tableNode && validData( tableNode ) ? 0 : -1;
  22069. }
  22070. }
  22071. },
  22072. inputRule:function(root){
  22073. utils.each(root.getNodesByTagName('table'),function( tableNode ){
  22074. if ( tableNode.getAttr("data-chart") !== undefined ) {
  22075. tableNode.setAttr("style");
  22076. }
  22077. })
  22078. },
  22079. outputRule:function(root){
  22080. utils.each(root.getNodesByTagName('table'),function( tableNode ){
  22081. if ( tableNode.getAttr("data-chart") !== undefined ) {
  22082. tableNode.setAttr("style", "display: none;");
  22083. }
  22084. })
  22085. }
  22086. }
  22087. function validData ( table ) {
  22088. var firstRows = null,
  22089. cellCount = 0;
  22090. //行数不够
  22091. if ( table.rows.length < 2 ) {
  22092. return false;
  22093. }
  22094. //列数不够
  22095. if ( table.rows[0].cells.length < 2 ) {
  22096. return false;
  22097. }
  22098. //第一行所有cell必须是th
  22099. firstRows = table.rows[ 0 ].cells;
  22100. cellCount = firstRows.length;
  22101. for ( var i = 0, cell; cell = firstRows[ i ]; i++ ) {
  22102. if ( cell.tagName.toLowerCase() !== 'th' ) {
  22103. return false;
  22104. }
  22105. }
  22106. for ( var i = 1, row; row = table.rows[ i ]; i++ ) {
  22107. //每行单元格数不匹配, 返回false
  22108. if ( row.cells.length != cellCount ) {
  22109. return false;
  22110. }
  22111. //第一列不是th也返回false
  22112. if ( row.cells[0].tagName.toLowerCase() !== 'th' ) {
  22113. return false;
  22114. }
  22115. for ( var j = 1, cell; cell = row.cells[ j ]; j++ ) {
  22116. var value = utils.trim( ( cell.innerText || cell.textContent || '' ) );
  22117. value = value.replace( new RegExp( UE.dom.domUtils.fillChar, 'g' ), '' ).replace( /^\s+|\s+$/g, '' );
  22118. //必须是数字
  22119. if ( !/^\d*\.?\d+$/.test( value ) ) {
  22120. return false;
  22121. }
  22122. }
  22123. }
  22124. return true;
  22125. }
  22126. });
  22127. // plugins/section.js
  22128. /**
  22129. * 目录大纲支持插件
  22130. * @file
  22131. * @since 1.3.0
  22132. */
  22133. UE.plugin.register('section', function (){
  22134. /* 目录节点对象 */
  22135. function Section(option){
  22136. this.tag = '';
  22137. this.level = -1,
  22138. this.dom = null;
  22139. this.nextSection = null;
  22140. this.previousSection = null;
  22141. this.parentSection = null;
  22142. this.startAddress = [];
  22143. this.endAddress = [];
  22144. this.children = [];
  22145. }
  22146. function getSection(option) {
  22147. var section = new Section();
  22148. return utils.extend(section, option);
  22149. }
  22150. function getNodeFromAddress(startAddress, root) {
  22151. var current = root;
  22152. for(var i = 0;i < startAddress.length; i++) {
  22153. if(!current.childNodes) return null;
  22154. current = current.childNodes[startAddress[i]];
  22155. }
  22156. return current;
  22157. }
  22158. var me = this;
  22159. return {
  22160. bindMultiEvents:{
  22161. type: 'aftersetcontent afterscencerestore',
  22162. handler: function(){
  22163. me.fireEvent('updateSections');
  22164. }
  22165. },
  22166. bindEvents:{
  22167. /* 初始化、拖拽、粘贴、执行setcontent之后 */
  22168. 'ready': function (){
  22169. me.fireEvent('updateSections');
  22170. domUtils.on(me.body, 'drop paste', function(){
  22171. me.fireEvent('updateSections');
  22172. });
  22173. },
  22174. /* 执行paragraph命令之后 */
  22175. 'afterexeccommand': function (type, cmd) {
  22176. if(cmd == 'paragraph') {
  22177. me.fireEvent('updateSections');
  22178. }
  22179. },
  22180. /* 部分键盘操作,触发updateSections事件 */
  22181. 'keyup': function (type, e) {
  22182. var me = this,
  22183. range = me.selection.getRange();
  22184. if(range.collapsed != true) {
  22185. me.fireEvent('updateSections');
  22186. } else {
  22187. var keyCode = e.keyCode || e.which;
  22188. if(keyCode == 13 || keyCode == 8 || keyCode == 46) {
  22189. me.fireEvent('updateSections');
  22190. }
  22191. }
  22192. }
  22193. },
  22194. commands:{
  22195. 'getsections': {
  22196. execCommand: function (cmd, levels) {
  22197. var levelFn = levels || ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
  22198. for (var i = 0; i < levelFn.length; i++) {
  22199. if (typeof levelFn[i] == 'string') {
  22200. levelFn[i] = function(fn){
  22201. return function(node){
  22202. return node.tagName == fn.toUpperCase()
  22203. };
  22204. }(levelFn[i]);
  22205. } else if (typeof levelFn[i] != 'function') {
  22206. levelFn[i] = function (node) {
  22207. return null;
  22208. }
  22209. }
  22210. }
  22211. function getSectionLevel(node) {
  22212. for (var i = 0; i < levelFn.length; i++) {
  22213. if (levelFn[i](node)) return i;
  22214. }
  22215. return -1;
  22216. }
  22217. var me = this,
  22218. Directory = getSection({'level':-1, 'title':'root'}),
  22219. previous = Directory;
  22220. function traversal(node, Directory) {
  22221. var level,
  22222. tmpSection = null,
  22223. parent,
  22224. child,
  22225. children = node.childNodes;
  22226. for (var i = 0, len = children.length; i < len; i++) {
  22227. child = children[i];
  22228. level = getSectionLevel(child);
  22229. if (level >= 0) {
  22230. var address = me.selection.getRange().selectNode(child).createAddress(true).startAddress,
  22231. current = getSection({
  22232. 'tag': child.tagName,
  22233. 'title': child.innerText || child.textContent || '',
  22234. 'level': level,
  22235. 'dom': child,
  22236. 'startAddress': utils.clone(address, []),
  22237. 'endAddress': utils.clone(address, []),
  22238. 'children': []
  22239. });
  22240. previous.nextSection = current;
  22241. current.previousSection = previous;
  22242. parent = previous;
  22243. while(level <= parent.level){
  22244. parent = parent.parentSection;
  22245. }
  22246. current.parentSection = parent;
  22247. parent.children.push(current);
  22248. tmpSection = previous = current;
  22249. } else {
  22250. child.nodeType === 1 && traversal(child, Directory);
  22251. tmpSection && tmpSection.endAddress[tmpSection.endAddress.length - 1] ++;
  22252. }
  22253. }
  22254. }
  22255. traversal(me.body, Directory);
  22256. return Directory;
  22257. },
  22258. notNeedUndo: true
  22259. },
  22260. 'movesection': {
  22261. execCommand: function (cmd, sourceSection, targetSection, isAfter) {
  22262. var me = this,
  22263. targetAddress,
  22264. target;
  22265. if(!sourceSection || !targetSection || targetSection.level == -1) return;
  22266. targetAddress = isAfter ? targetSection.endAddress:targetSection.startAddress;
  22267. target = getNodeFromAddress(targetAddress, me.body);
  22268. /* 判断目标地址是否被源章节包含 */
  22269. if(!targetAddress || !target || isContainsAddress(sourceSection.startAddress, sourceSection.endAddress, targetAddress)) return;
  22270. var startNode = getNodeFromAddress(sourceSection.startAddress, me.body),
  22271. endNode = getNodeFromAddress(sourceSection.endAddress, me.body),
  22272. current,
  22273. nextNode;
  22274. if(isAfter) {
  22275. current = endNode;
  22276. while ( current && !(domUtils.getPosition( startNode, current ) & domUtils.POSITION_FOLLOWING) ) {
  22277. nextNode = current.previousSibling;
  22278. domUtils.insertAfter(target, current);
  22279. if(current == startNode) break;
  22280. current = nextNode;
  22281. }
  22282. } else {
  22283. current = startNode;
  22284. while ( current && !(domUtils.getPosition( current, endNode ) & domUtils.POSITION_FOLLOWING) ) {
  22285. nextNode = current.nextSibling;
  22286. target.parentNode.insertBefore(current, target);
  22287. if(current == endNode) break;
  22288. current = nextNode;
  22289. }
  22290. }
  22291. me.fireEvent('updateSections');
  22292. /* 获取地址的包含关系 */
  22293. function isContainsAddress(startAddress, endAddress, addressTarget){
  22294. var isAfterStartAddress = false,
  22295. isBeforeEndAddress = false;
  22296. for(var i = 0; i< startAddress.length; i++){
  22297. if(i >= addressTarget.length) break;
  22298. if(addressTarget[i] > startAddress[i]) {
  22299. isAfterStartAddress = true;
  22300. break;
  22301. } else if(addressTarget[i] < startAddress[i]) {
  22302. break;
  22303. }
  22304. }
  22305. for(var i = 0; i< endAddress.length; i++){
  22306. if(i >= addressTarget.length) break;
  22307. if(addressTarget[i] < startAddress[i]) {
  22308. isBeforeEndAddress = true;
  22309. break;
  22310. } else if(addressTarget[i] > startAddress[i]) {
  22311. break;
  22312. }
  22313. }
  22314. return isAfterStartAddress && isBeforeEndAddress;
  22315. }
  22316. }
  22317. },
  22318. 'deletesection': {
  22319. execCommand: function (cmd, section, keepChildren) {
  22320. var me = this;
  22321. if(!section) return;
  22322. function getNodeFromAddress(startAddress) {
  22323. var current = me.body;
  22324. for(var i = 0;i < startAddress.length; i++) {
  22325. if(!current.childNodes) return null;
  22326. current = current.childNodes[startAddress[i]];
  22327. }
  22328. return current;
  22329. }
  22330. var startNode = getNodeFromAddress(section.startAddress),
  22331. endNode = getNodeFromAddress(section.endAddress),
  22332. current = startNode,
  22333. nextNode;
  22334. if(!keepChildren) {
  22335. while ( current && domUtils.inDoc(endNode, me.document) && !(domUtils.getPosition( current, endNode ) & domUtils.POSITION_FOLLOWING) ) {
  22336. nextNode = current.nextSibling;
  22337. domUtils.remove(current);
  22338. current = nextNode;
  22339. }
  22340. } else {
  22341. domUtils.remove(current);
  22342. }
  22343. me.fireEvent('updateSections');
  22344. }
  22345. },
  22346. 'selectsection': {
  22347. execCommand: function (cmd, section) {
  22348. if(!section && !section.dom) return false;
  22349. var me = this,
  22350. range = me.selection.getRange(),
  22351. address = {
  22352. 'startAddress':utils.clone(section.startAddress, []),
  22353. 'endAddress':utils.clone(section.endAddress, [])
  22354. };
  22355. address.endAddress[address.endAddress.length - 1]++;
  22356. range.moveToAddress(address).select().scrollToView();
  22357. return true;
  22358. },
  22359. notNeedUndo: true
  22360. },
  22361. 'scrolltosection': {
  22362. execCommand: function (cmd, section) {
  22363. if(!section && !section.dom) return false;
  22364. var me = this,
  22365. range = me.selection.getRange(),
  22366. address = {
  22367. 'startAddress':section.startAddress,
  22368. 'endAddress':section.endAddress
  22369. };
  22370. address.endAddress[address.endAddress.length - 1]++;
  22371. range.moveToAddress(address).scrollToView();
  22372. return true;
  22373. },
  22374. notNeedUndo: true
  22375. }
  22376. }
  22377. }
  22378. });
  22379. // plugins/simpleupload.js
  22380. /**
  22381. * @description
  22382. * 简单上传:点击按钮,直接选择文件上传
  22383. * @author Jinqn
  22384. * @date 2014-03-31
  22385. */
  22386. UE.plugin.register('simpleupload', function (){
  22387. var me = this,
  22388. isLoaded = false,
  22389. containerBtn;
  22390. function initUploadBtn(){
  22391. var w = containerBtn.offsetWidth || 20,
  22392. h = containerBtn.offsetHeight || 20,
  22393. btnIframe = document.createElement('iframe'),
  22394. 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;';
  22395. domUtils.on(btnIframe, 'load', function(){
  22396. var timestrap = (+new Date()).toString(36),
  22397. wrapper,
  22398. btnIframeDoc,
  22399. btnIframeBody;
  22400. btnIframeDoc = (btnIframe.contentDocument || btnIframe.contentWindow.document);
  22401. btnIframeBody = btnIframeDoc.body;
  22402. wrapper = btnIframeDoc.createElement('div');
  22403. wrapper.innerHTML = '<form id="edui_form_' + timestrap + '" target="edui_iframe_' + timestrap + '" method="POST" enctype="multipart/form-data" action="' + me.getOpt('serverUrl') + '" ' +
  22404. 'style="' + btnStyle + '">' +
  22405. // '<input id="edui_input_' + timestrap + '" type="file" accept="image/*" name="' + me.options.imageFieldName + '" ' +
  22406. '<input id="edui_input_' + timestrap + '" type="file" accept="image/jpg,image/jpeg,image/png,image/gif" name="' + me.options.imageFieldName + '" ' +
  22407. 'style="' + btnStyle + '">' +
  22408. '</form>' +
  22409. '<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>';
  22410. wrapper.className = 'edui-' + me.options.theme;
  22411. wrapper.id = me.ui.id + '_iframeupload';
  22412. btnIframeBody.style.cssText = btnStyle;
  22413. btnIframeBody.style.width = w + 'px';
  22414. btnIframeBody.style.height = h + 'px';
  22415. btnIframeBody.appendChild(wrapper);
  22416. if (btnIframeBody.parentNode) {
  22417. btnIframeBody.parentNode.style.width = w + 'px';
  22418. btnIframeBody.parentNode.style.height = w + 'px';
  22419. }
  22420. var form = btnIframeDoc.getElementById('edui_form_' + timestrap);
  22421. var input = btnIframeDoc.getElementById('edui_input_' + timestrap);
  22422. var iframe = btnIframeDoc.getElementById('edui_iframe_' + timestrap);
  22423. domUtils.on(input, 'change', function(){
  22424. if(!input.value) return;
  22425. var loadingId = 'loading_' + (+new Date()).toString(36);
  22426. var params = utils.serializeParam(me.queryCommandValue('serverparam')) || '';
  22427. var imageActionUrl = me.getActionUrl(me.getOpt('imageActionName'));
  22428. var allowFiles = me.getOpt('imageAllowFiles');
  22429. me.focus();
  22430. // me.execCommand('inserthtml', '<img class="loadingclass" id="' + loadingId + '" src="' + me.options.themePath + me.options.theme +'/images/spacer.gif" title="' + (me.getLang('simpleupload.loading') || '') + '" >');
  22431. me.execCommand('inserthtml', '<img style="max-width:100%;" class="loadingclass canCut" id="' + loadingId + '" src="' + me.options.themePath + me.options.theme +'/images/spacer.gif" title="' + (me.getLang('simpleupload.loading') || '') + '" >');
  22432. function callback(){
  22433. try{
  22434. var link, json, loader,
  22435. body = (iframe.contentDocument || iframe.contentWindow.document).body,
  22436. result = body.innerText || body.textContent || '';
  22437. json = (new Function("return " + result))();
  22438. link = me.options.imageUrlPrefix + json.url;
  22439. if(json.state == 'SUCCESS' && json.url) {
  22440. loader = me.document.getElementById(loadingId);
  22441. loader.setAttribute('src', link);
  22442. loader.setAttribute('_src', link);
  22443. loader.setAttribute('title', json.title || '');
  22444. loader.setAttribute('alt', json.original || '');
  22445. loader.removeAttribute('id');
  22446. domUtils.removeClasses(loader, 'loadingclass');
  22447. } else {
  22448. showErrorLoader && showErrorLoader(json.state);
  22449. }
  22450. }catch(er){
  22451. showErrorLoader && showErrorLoader(me.getLang('simpleupload.loadError'));
  22452. }
  22453. form.reset();
  22454. domUtils.un(iframe, 'load', callback);
  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. if (!me.getOpt('imageActionName')) {
  22470. errorHandler(me.getLang('autoupload.errorLoadConfig'));
  22471. return;
  22472. }
  22473. // 判断文件格式是否错误
  22474. var filename = input.value,
  22475. fileext = filename ? filename.substr(filename.lastIndexOf('.')):'';
  22476. if (!fileext || (allowFiles && (allowFiles.join('') + '.').indexOf(fileext.toLowerCase() + '.') == -1)) {
  22477. showErrorLoader(me.getLang('simpleupload.exceedTypeError'));
  22478. return;
  22479. }
  22480. domUtils.on(iframe, 'load', callback);
  22481. form.action = utils.formatUrl(imageActionUrl + (imageActionUrl.indexOf('?') == -1 ? '?':'&') + params);
  22482. form.submit();
  22483. });
  22484. var stateTimer;
  22485. me.addListener('selectionchange', function () {
  22486. clearTimeout(stateTimer);
  22487. stateTimer = setTimeout(function() {
  22488. var state = me.queryCommandState('simpleupload');
  22489. if (state == -1) {
  22490. input.disabled = 'disabled';
  22491. } else {
  22492. input.disabled = false;
  22493. }
  22494. }, 400);
  22495. });
  22496. isLoaded = true;
  22497. });
  22498. btnIframe.style.cssText = btnStyle;
  22499. containerBtn.appendChild(btnIframe);
  22500. }
  22501. return {
  22502. bindEvents:{
  22503. 'ready': function() {
  22504. //设置loading的样式
  22505. utils.cssRule('loading',
  22506. '.loadingclass{display:inline-block;cursor:default;background: url(\''
  22507. + this.options.themePath
  22508. + this.options.theme +'/images/loading.gif\') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;}\n' +
  22509. '.loaderrorclass{display:inline-block;cursor:default;background: url(\''
  22510. + this.options.themePath
  22511. + this.options.theme +'/images/loaderror.png\') no-repeat center center transparent;border:1px solid #cccccc;margin-right:1px;height: 22px;width: 22px;' +
  22512. '}',
  22513. this.document);
  22514. },
  22515. /* 初始化简单上传按钮 */
  22516. 'simpleuploadbtnready': function(type, container) {
  22517. containerBtn = container;
  22518. me.afterConfigReady(initUploadBtn);
  22519. }
  22520. },
  22521. outputRule: function(root){
  22522. utils.each(root.getNodesByTagName('img'),function(n){
  22523. if (/\b(loaderrorclass)|(bloaderrorclass)\b/.test(n.getAttr('class'))) {
  22524. n.parentNode.removeChild(n);
  22525. }
  22526. });
  22527. },
  22528. commands: {
  22529. 'simpleupload': {
  22530. queryCommandState: function () {
  22531. return isLoaded ? 0:-1;
  22532. }
  22533. }
  22534. }
  22535. }
  22536. });
  22537. // plugins/serverparam.js
  22538. /**
  22539. * 服务器提交的额外参数列表设置插件
  22540. * @file
  22541. * @since 1.2.6.1
  22542. */
  22543. UE.plugin.register('serverparam', function (){
  22544. var me = this,
  22545. serverParam = {};
  22546. return {
  22547. commands:{
  22548. /**
  22549. * 修改服务器提交的额外参数列表,清除所有项
  22550. * @command serverparam
  22551. * @method execCommand
  22552. * @param { String } cmd 命令字符串
  22553. * @example
  22554. * ```javascript
  22555. * editor.execCommand('serverparam');
  22556. * editor.queryCommandValue('serverparam'); //返回空
  22557. * ```
  22558. */
  22559. /**
  22560. * 修改服务器提交的额外参数列表,删除指定项
  22561. * @command serverparam
  22562. * @method execCommand
  22563. * @param { String } cmd 命令字符串
  22564. * @param { String } key 要清除的属性
  22565. * @example
  22566. * ```javascript
  22567. * editor.execCommand('serverparam', 'name'); //删除属性name
  22568. * ```
  22569. */
  22570. /**
  22571. * 修改服务器提交的额外参数列表,使用键值添加项
  22572. * @command serverparam
  22573. * @method execCommand
  22574. * @param { String } cmd 命令字符串
  22575. * @param { String } key 要添加的属性
  22576. * @param { String } value 要添加属性的值
  22577. * @example
  22578. * ```javascript
  22579. * editor.execCommand('serverparam', 'name', 'hello');
  22580. * editor.queryCommandValue('serverparam'); //返回对象 {'name': 'hello'}
  22581. * ```
  22582. */
  22583. /**
  22584. * 修改服务器提交的额外参数列表,传入键值对对象添加多项
  22585. * @command serverparam
  22586. * @method execCommand
  22587. * @param { String } cmd 命令字符串
  22588. * @param { Object } key 传入的键值对对象
  22589. * @example
  22590. * ```javascript
  22591. * editor.execCommand('serverparam', {'name': 'hello'});
  22592. * editor.queryCommandValue('serverparam'); //返回对象 {'name': 'hello'}
  22593. * ```
  22594. */
  22595. /**
  22596. * 修改服务器提交的额外参数列表,使用自定义函数添加多项
  22597. * @command serverparam
  22598. * @method execCommand
  22599. * @param { String } cmd 命令字符串
  22600. * @param { Function } key 自定义获取参数的函数
  22601. * @example
  22602. * ```javascript
  22603. * editor.execCommand('serverparam', function(editor){
  22604. * return {'key': 'value'};
  22605. * });
  22606. * editor.queryCommandValue('serverparam'); //返回对象 {'key': 'value'}
  22607. * ```
  22608. */
  22609. /**
  22610. * 获取服务器提交的额外参数列表
  22611. * @command serverparam
  22612. * @method queryCommandValue
  22613. * @param { String } cmd 命令字符串
  22614. * @example
  22615. * ```javascript
  22616. * editor.queryCommandValue( 'serverparam' ); //返回对象 {'key': 'value'}
  22617. * ```
  22618. */
  22619. 'serverparam':{
  22620. execCommand:function (cmd, key, value) {
  22621. if (key === undefined || key === null) { //不传参数,清空列表
  22622. serverParam = {};
  22623. } else if (utils.isString(key)) { //传入键值
  22624. if(value === undefined || value === null) {
  22625. delete serverParam[key];
  22626. } else {
  22627. serverParam[key] = value;
  22628. }
  22629. } else if (utils.isObject(key)) { //传入对象,覆盖列表项
  22630. utils.extend(serverParam, key, true);
  22631. } else if (utils.isFunction(key)){ //传入函数,添加列表项
  22632. utils.extend(serverParam, key(), true);
  22633. }
  22634. },
  22635. queryCommandValue: function(){
  22636. return serverParam || {};
  22637. }
  22638. }
  22639. }
  22640. }
  22641. });
  22642. // plugins/insertfile.js
  22643. /**
  22644. * 插入附件
  22645. */
  22646. UE.plugin.register('insertfile', function (){
  22647. var me = this;
  22648. function getFileIcon(url){
  22649. var ext = url.substr(url.lastIndexOf('.') + 1).toLowerCase(),
  22650. maps = {
  22651. "rar":"icon_rar.gif",
  22652. "zip":"icon_rar.gif",
  22653. "tar":"icon_rar.gif",
  22654. "gz":"icon_rar.gif",
  22655. "bz2":"icon_rar.gif",
  22656. "doc":"icon_doc.gif",
  22657. "docx":"icon_doc.gif",
  22658. "pdf":"icon_pdf.gif",
  22659. "mp3":"icon_mp3.gif",
  22660. "xls":"icon_xls.gif",
  22661. "chm":"icon_chm.gif",
  22662. "ppt":"icon_ppt.gif",
  22663. "pptx":"icon_ppt.gif",
  22664. "avi":"icon_mv.gif",
  22665. "rmvb":"icon_mv.gif",
  22666. "wmv":"icon_mv.gif",
  22667. "flv":"icon_mv.gif",
  22668. "swf":"icon_mv.gif",
  22669. "rm":"icon_mv.gif",
  22670. "exe":"icon_exe.gif",
  22671. "psd":"icon_psd.gif",
  22672. "txt":"icon_txt.gif",
  22673. "jpg":"icon_jpg.gif",
  22674. "png":"icon_jpg.gif",
  22675. "jpeg":"icon_jpg.gif",
  22676. "gif":"icon_jpg.gif",
  22677. "ico":"icon_jpg.gif",
  22678. "bmp":"icon_jpg.gif"
  22679. };
  22680. return maps[ext] ? maps[ext]:maps['txt'];
  22681. }
  22682. return {
  22683. commands:{
  22684. 'insertfile': {
  22685. execCommand: function (command, filelist){
  22686. filelist = utils.isArray(filelist) ? filelist : [filelist];
  22687. var i, item, icon, title,
  22688. html = '',
  22689. URL = me.getOpt('UEDITOR_HOME_URL'),
  22690. iconDir = URL + (URL.substr(URL.length - 1) == '/' ? '':'/') + 'dialogs/attachment/fileTypeImages/';
  22691. for (i = 0; i < filelist.length; i++) {
  22692. item = filelist[i];
  22693. icon = iconDir + getFileIcon(item.url);
  22694. title = item.title || item.url.substr(item.url.lastIndexOf('/') + 1);
  22695. html += '<p style="line-height: 16px;">' +
  22696. '<img style="vertical-align: middle; margin-right: 2px;" src="'+ icon + '" _src="' + icon + '" />' +
  22697. '<a style="font-size:12px; color:#0066cc;" href="' + item.url +'" title="' + title + '">' + title + '</a>' +
  22698. '</p>';
  22699. }
  22700. me.execCommand('insertHtml', html);
  22701. }
  22702. }
  22703. }
  22704. }
  22705. });
  22706. // plugins/xssFilter.js
  22707. /**
  22708. * @file xssFilter.js
  22709. * @desc xss过滤器
  22710. * @author robbenmu
  22711. */
  22712. UE.plugins.xssFilter = function() {
  22713. var config = UEDITOR_CONFIG;
  22714. var whitList = config.whitList;
  22715. function filter(node) {
  22716. var tagName = node.tagName;
  22717. var attrs = node.attrs;
  22718. if (!whitList.hasOwnProperty(tagName)) {
  22719. node.parentNode.removeChild(node);
  22720. return false;
  22721. }
  22722. UE.utils.each(attrs, function (val, key) {
  22723. if (whitList[tagName].indexOf(key) === -1) {
  22724. node.setAttr(key);
  22725. }
  22726. });
  22727. }
  22728. // 添加inserthtml\paste等操作用的过滤规则
  22729. if (whitList && config.xssFilterRules) {
  22730. this.options.filterRules = function () {
  22731. var result = {};
  22732. UE.utils.each(whitList, function(val, key) {
  22733. result[key] = function (node) {
  22734. return filter(node);
  22735. };
  22736. });
  22737. return result;
  22738. }();
  22739. }
  22740. var tagList = [];
  22741. UE.utils.each(whitList, function (val, key) {
  22742. tagList.push(key);
  22743. });
  22744. // 添加input过滤规则
  22745. //
  22746. if (whitList && config.inputXssFilter) {
  22747. this.addInputRule(function (root) {
  22748. root.traversal(function(node) {
  22749. if (node.type !== 'element') {
  22750. return false;
  22751. }
  22752. filter(node);
  22753. });
  22754. });
  22755. }
  22756. // 添加output过滤规则
  22757. //
  22758. if (whitList && config.outputXssFilter) {
  22759. this.addOutputRule(function (root) {
  22760. root.traversal(function(node) {
  22761. if (node.type !== 'element') {
  22762. return false;
  22763. }
  22764. filter(node);
  22765. });
  22766. });
  22767. }
  22768. };
  22769. // ui/ui.js
  22770. var baidu = baidu || {};
  22771. baidu.editor = baidu.editor || {};
  22772. UE.ui = baidu.editor.ui = {};
  22773. // ui/uiutils.js
  22774. (function (){
  22775. var browser = baidu.editor.browser,
  22776. domUtils = baidu.editor.dom.domUtils;
  22777. var magic = '$EDITORUI';
  22778. var root = window[magic] = {};
  22779. var uidMagic = 'ID' + magic;
  22780. var uidCount = 0;
  22781. var uiUtils = baidu.editor.ui.uiUtils = {
  22782. uid: function (obj){
  22783. return (obj ? obj[uidMagic] || (obj[uidMagic] = ++ uidCount) : ++ uidCount);
  22784. },
  22785. hook: function ( fn, callback ) {
  22786. var dg;
  22787. if (fn && fn._callbacks) {
  22788. dg = fn;
  22789. } else {
  22790. dg = function (){
  22791. var q;
  22792. if (fn) {
  22793. q = fn.apply(this, arguments);
  22794. }
  22795. var callbacks = dg._callbacks;
  22796. var k = callbacks.length;
  22797. while (k --) {
  22798. var r = callbacks[k].apply(this, arguments);
  22799. if (q === undefined) {
  22800. q = r;
  22801. }
  22802. }
  22803. return q;
  22804. };
  22805. dg._callbacks = [];
  22806. }
  22807. dg._callbacks.push(callback);
  22808. return dg;
  22809. },
  22810. createElementByHtml: function (html){
  22811. var el = document.createElement('div');
  22812. el.innerHTML = html;
  22813. el = el.firstChild;
  22814. el.parentNode.removeChild(el);
  22815. return el;
  22816. },
  22817. getViewportElement: function (){
  22818. return (browser.ie && browser.quirks) ?
  22819. document.body : document.documentElement;
  22820. },
  22821. getClientRect: function (element){
  22822. var bcr;
  22823. //trace IE6下在控制编辑器显隐时可能会报错,catch一下
  22824. try{
  22825. bcr = element.getBoundingClientRect();
  22826. }catch(e){
  22827. bcr={left:0,top:0,height:0,width:0}
  22828. }
  22829. var rect = {
  22830. left: Math.round(bcr.left),
  22831. top: Math.round(bcr.top),
  22832. height: Math.round(bcr.bottom - bcr.top),
  22833. width: Math.round(bcr.right - bcr.left)
  22834. };
  22835. var doc;
  22836. while ((doc = element.ownerDocument) !== document &&
  22837. (element = domUtils.getWindow(doc).frameElement)) {
  22838. bcr = element.getBoundingClientRect();
  22839. rect.left += bcr.left;
  22840. rect.top += bcr.top;
  22841. }
  22842. rect.bottom = rect.top + rect.height;
  22843. rect.right = rect.left + rect.width;
  22844. return rect;
  22845. },
  22846. getViewportRect: function (){
  22847. var viewportEl = uiUtils.getViewportElement();
  22848. var width = (window.innerWidth || viewportEl.clientWidth) | 0;
  22849. var height = (window.innerHeight ||viewportEl.clientHeight) | 0;
  22850. return {
  22851. left: 0,
  22852. top: 0,
  22853. height: height,
  22854. width: width,
  22855. bottom: height,
  22856. right: width
  22857. };
  22858. },
  22859. setViewportOffset: function (element, offset){
  22860. var rect;
  22861. var fixedLayer = uiUtils.getFixedLayer();
  22862. if (element.parentNode === fixedLayer) {
  22863. element.style.left = offset.left + 'px';
  22864. element.style.top = offset.top + 'px';
  22865. } else {
  22866. domUtils.setViewportOffset(element, offset);
  22867. }
  22868. },
  22869. getEventOffset: function (evt){
  22870. var el = evt.target || evt.srcElement;
  22871. var rect = uiUtils.getClientRect(el);
  22872. var offset = uiUtils.getViewportOffsetByEvent(evt);
  22873. return {
  22874. left: offset.left - rect.left,
  22875. top: offset.top - rect.top
  22876. };
  22877. },
  22878. getViewportOffsetByEvent: function (evt){
  22879. var el = evt.target || evt.srcElement;
  22880. var frameEl = domUtils.getWindow(el).frameElement;
  22881. var offset = {
  22882. left: evt.clientX,
  22883. top: evt.clientY
  22884. };
  22885. if (frameEl && el.ownerDocument !== document) {
  22886. var rect = uiUtils.getClientRect(frameEl);
  22887. offset.left += rect.left;
  22888. offset.top += rect.top;
  22889. }
  22890. return offset;
  22891. },
  22892. setGlobal: function (id, obj){
  22893. root[id] = obj;
  22894. return magic + '["' + id + '"]';
  22895. },
  22896. unsetGlobal: function (id){
  22897. delete root[id];
  22898. },
  22899. copyAttributes: function (tgt, src){
  22900. var attributes = src.attributes;
  22901. var k = attributes.length;
  22902. while (k --) {
  22903. var attrNode = attributes[k];
  22904. if ( attrNode.nodeName != 'style' && attrNode.nodeName != 'class' && (!browser.ie || attrNode.specified) ) {
  22905. tgt.setAttribute(attrNode.nodeName, attrNode.nodeValue);
  22906. }
  22907. }
  22908. if (src.className) {
  22909. domUtils.addClass(tgt,src.className);
  22910. }
  22911. if (src.style.cssText) {
  22912. tgt.style.cssText += ';' + src.style.cssText;
  22913. }
  22914. },
  22915. removeStyle: function (el, styleName){
  22916. if (el.style.removeProperty) {
  22917. el.style.removeProperty(styleName);
  22918. } else if (el.style.removeAttribute) {
  22919. el.style.removeAttribute(styleName);
  22920. } else throw '';
  22921. },
  22922. contains: function (elA, elB){
  22923. return elA && elB && (elA === elB ? false : (
  22924. elA.contains ? elA.contains(elB) :
  22925. elA.compareDocumentPosition(elB) & 16
  22926. ));
  22927. },
  22928. startDrag: function (evt, callbacks,doc){
  22929. var doc = doc || document;
  22930. var startX = evt.clientX;
  22931. var startY = evt.clientY;
  22932. function handleMouseMove(evt){
  22933. var x = evt.clientX - startX;
  22934. var y = evt.clientY - startY;
  22935. callbacks.ondragmove(x, y,evt);
  22936. if (evt.stopPropagation) {
  22937. evt.stopPropagation();
  22938. } else {
  22939. evt.cancelBubble = true;
  22940. }
  22941. }
  22942. if (doc.addEventListener) {
  22943. function handleMouseUp(evt){
  22944. doc.removeEventListener('mousemove', handleMouseMove, true);
  22945. doc.removeEventListener('mouseup', handleMouseUp, true);
  22946. window.removeEventListener('mouseup', handleMouseUp, true);
  22947. callbacks.ondragstop();
  22948. }
  22949. doc.addEventListener('mousemove', handleMouseMove, true);
  22950. doc.addEventListener('mouseup', handleMouseUp, true);
  22951. window.addEventListener('mouseup', handleMouseUp, true);
  22952. evt.preventDefault();
  22953. } else {
  22954. var elm = evt.srcElement;
  22955. elm.setCapture();
  22956. function releaseCaptrue(){
  22957. elm.releaseCapture();
  22958. elm.detachEvent('onmousemove', handleMouseMove);
  22959. elm.detachEvent('onmouseup', releaseCaptrue);
  22960. elm.detachEvent('onlosecaptrue', releaseCaptrue);
  22961. callbacks.ondragstop();
  22962. }
  22963. elm.attachEvent('onmousemove', handleMouseMove);
  22964. elm.attachEvent('onmouseup', releaseCaptrue);
  22965. elm.attachEvent('onlosecaptrue', releaseCaptrue);
  22966. evt.returnValue = false;
  22967. }
  22968. callbacks.ondragstart();
  22969. },
  22970. getFixedLayer: function (){
  22971. var layer = document.getElementById('edui_fixedlayer');
  22972. if (layer == null) {
  22973. layer = document.createElement('div');
  22974. layer.id = 'edui_fixedlayer';
  22975. document.body.appendChild(layer);
  22976. if (browser.ie && browser.version <= 8) {
  22977. layer.style.position = 'absolute';
  22978. bindFixedLayer();
  22979. setTimeout(updateFixedOffset);
  22980. } else {
  22981. layer.style.position = 'fixed';
  22982. }
  22983. layer.style.left = '0';
  22984. layer.style.top = '0';
  22985. layer.style.width = '0';
  22986. layer.style.height = '0';
  22987. }
  22988. return layer;
  22989. },
  22990. makeUnselectable: function (element){
  22991. if (browser.opera || (browser.ie && browser.version < 9)) {
  22992. element.unselectable = 'on';
  22993. if (element.hasChildNodes()) {
  22994. for (var i=0; i<element.childNodes.length; i++) {
  22995. if (element.childNodes[i].nodeType == 1) {
  22996. uiUtils.makeUnselectable(element.childNodes[i]);
  22997. }
  22998. }
  22999. }
  23000. } else {
  23001. if (element.style.MozUserSelect !== undefined) {
  23002. element.style.MozUserSelect = 'none';
  23003. } else if (element.style.WebkitUserSelect !== undefined) {
  23004. element.style.WebkitUserSelect = 'none';
  23005. } else if (element.style.KhtmlUserSelect !== undefined) {
  23006. element.style.KhtmlUserSelect = 'none';
  23007. }
  23008. }
  23009. }
  23010. };
  23011. function updateFixedOffset(){
  23012. var layer = document.getElementById('edui_fixedlayer');
  23013. uiUtils.setViewportOffset(layer, {
  23014. left: 0,
  23015. top: 0
  23016. });
  23017. // layer.style.display = 'none';
  23018. // layer.style.display = 'block';
  23019. //#trace: 1354
  23020. // setTimeout(updateFixedOffset);
  23021. }
  23022. function bindFixedLayer(adjOffset){
  23023. domUtils.on(window, 'scroll', updateFixedOffset);
  23024. domUtils.on(window, 'resize', baidu.editor.utils.defer(updateFixedOffset, 0, true));
  23025. }
  23026. })();
  23027. // ui/uibase.js
  23028. (function () {
  23029. var utils = baidu.editor.utils,
  23030. uiUtils = baidu.editor.ui.uiUtils,
  23031. EventBase = baidu.editor.EventBase,
  23032. UIBase = baidu.editor.ui.UIBase = function () {
  23033. };
  23034. UIBase.prototype = {
  23035. className:'',
  23036. uiName:'',
  23037. initOptions:function (options) {
  23038. var me = this;
  23039. for (var k in options) {
  23040. me[k] = options[k];
  23041. }
  23042. this.id = this.id || 'edui' + uiUtils.uid();
  23043. },
  23044. initUIBase:function () {
  23045. this._globalKey = utils.unhtml(uiUtils.setGlobal(this.id, this));
  23046. },
  23047. render:function (holder) {
  23048. var html = this.renderHtml();
  23049. var el = uiUtils.createElementByHtml(html);
  23050. //by xuheng 给每个node添加class
  23051. var list = domUtils.getElementsByTagName(el, "*");
  23052. var theme = "edui-" + (this.theme || this.editor.options.theme);
  23053. var layer = document.getElementById('edui_fixedlayer');
  23054. for (var i = 0, node; node = list[i++];) {
  23055. domUtils.addClass(node, theme);
  23056. }
  23057. domUtils.addClass(el, theme);
  23058. if(layer){
  23059. layer.className="";
  23060. domUtils.addClass(layer,theme);
  23061. }
  23062. var seatEl = this.getDom();
  23063. if (seatEl != null) {
  23064. seatEl.parentNode.replaceChild(el, seatEl);
  23065. uiUtils.copyAttributes(el, seatEl);
  23066. } else {
  23067. if (typeof holder == 'string') {
  23068. holder = document.getElementById(holder);
  23069. }
  23070. holder = holder || uiUtils.getFixedLayer();
  23071. domUtils.addClass(holder, theme);
  23072. holder.appendChild(el);
  23073. }
  23074. this.postRender();
  23075. },
  23076. getDom:function (name) {
  23077. if (!name) {
  23078. return document.getElementById(this.id);
  23079. } else {
  23080. return document.getElementById(this.id + '_' + name);
  23081. }
  23082. },
  23083. postRender:function () {
  23084. this.fireEvent('postrender');
  23085. },
  23086. getHtmlTpl:function () {
  23087. return '';
  23088. },
  23089. formatHtml:function (tpl) {
  23090. var prefix = 'edui-' + this.uiName;
  23091. return (tpl
  23092. .replace(/##/g, this.id)
  23093. .replace(/%%-/g, this.uiName ? prefix + '-' : '')
  23094. .replace(/%%/g, (this.uiName ? prefix : '') + ' ' + this.className)
  23095. .replace(/\$\$/g, this._globalKey));
  23096. },
  23097. renderHtml:function () {
  23098. return this.formatHtml(this.getHtmlTpl());
  23099. },
  23100. dispose:function () {
  23101. var box = this.getDom();
  23102. if (box) baidu.editor.dom.domUtils.remove(box);
  23103. uiUtils.unsetGlobal(this.id);
  23104. }
  23105. };
  23106. utils.inherits(UIBase, EventBase);
  23107. })();
  23108. // ui/separator.js
  23109. (function (){
  23110. var utils = baidu.editor.utils,
  23111. UIBase = baidu.editor.ui.UIBase,
  23112. Separator = baidu.editor.ui.Separator = function (options){
  23113. this.initOptions(options);
  23114. this.initSeparator();
  23115. };
  23116. Separator.prototype = {
  23117. uiName: 'separator',
  23118. initSeparator: function (){
  23119. this.initUIBase();
  23120. },
  23121. getHtmlTpl: function (){
  23122. return '<div id="##" class="edui-box %%"></div>';
  23123. }
  23124. };
  23125. utils.inherits(Separator, UIBase);
  23126. })();
  23127. // ui/mask.js
  23128. ///import core
  23129. ///import uicore
  23130. (function (){
  23131. var utils = baidu.editor.utils,
  23132. domUtils = baidu.editor.dom.domUtils,
  23133. UIBase = baidu.editor.ui.UIBase,
  23134. uiUtils = baidu.editor.ui.uiUtils;
  23135. var Mask = baidu.editor.ui.Mask = function (options){
  23136. this.initOptions(options);
  23137. this.initUIBase();
  23138. };
  23139. Mask.prototype = {
  23140. getHtmlTpl: function (){
  23141. return '<div id="##" class="edui-mask %%" onclick="return $$._onClick(event, this);" onmousedown="return $$._onMouseDown(event, this);"></div>';
  23142. },
  23143. postRender: function (){
  23144. var me = this;
  23145. domUtils.on(window, 'resize', function (){
  23146. setTimeout(function (){
  23147. if (!me.isHidden()) {
  23148. me._fill();
  23149. }
  23150. });
  23151. });
  23152. },
  23153. show: function (zIndex){
  23154. this._fill();
  23155. this.getDom().style.display = '';
  23156. this.getDom().style.zIndex = zIndex;
  23157. },
  23158. hide: function (){
  23159. this.getDom().style.display = 'none';
  23160. this.getDom().style.zIndex = '';
  23161. },
  23162. isHidden: function (){
  23163. return this.getDom().style.display == 'none';
  23164. },
  23165. _onMouseDown: function (){
  23166. return false;
  23167. },
  23168. _onClick: function (e, target){
  23169. this.fireEvent('click', e, target);
  23170. },
  23171. _fill: function (){
  23172. var el = this.getDom();
  23173. var vpRect = uiUtils.getViewportRect();
  23174. el.style.width = vpRect.width + 'px';
  23175. el.style.height = vpRect.height + 'px';
  23176. }
  23177. };
  23178. utils.inherits(Mask, UIBase);
  23179. })();
  23180. // ui/popup.js
  23181. ///import core
  23182. ///import uicore
  23183. (function () {
  23184. var utils = baidu.editor.utils,
  23185. uiUtils = baidu.editor.ui.uiUtils,
  23186. domUtils = baidu.editor.dom.domUtils,
  23187. UIBase = baidu.editor.ui.UIBase,
  23188. Popup = baidu.editor.ui.Popup = function (options){
  23189. this.initOptions(options);
  23190. this.initPopup();
  23191. };
  23192. var allPopups = [];
  23193. function closeAllPopup( evt,el ){
  23194. for ( var i = 0; i < allPopups.length; i++ ) {
  23195. var pop = allPopups[i];
  23196. if (!pop.isHidden()) {
  23197. if (pop.queryAutoHide(el) !== false) {
  23198. if(evt&&/scroll/ig.test(evt.type)&&pop.className=="edui-wordpastepop") return;
  23199. // pop.hide();
  23200. pop.hide(false, evt); //editmark
  23201. }
  23202. }
  23203. }
  23204. if(allPopups.length)
  23205. // pop.editor.fireEvent("afterhidepop");
  23206. pop.editor.fireEvent("afterhidepop", evt); //editmark
  23207. }
  23208. Popup.postHide = closeAllPopup;
  23209. var ANCHOR_CLASSES = ['edui-anchor-topleft','edui-anchor-topright',
  23210. 'edui-anchor-bottomleft','edui-anchor-bottomright'];
  23211. Popup.prototype = {
  23212. SHADOW_RADIUS: 5,
  23213. content: null,
  23214. _hidden: false,
  23215. autoRender: true,
  23216. canSideLeft: true,
  23217. canSideUp: true,
  23218. initPopup: function (){
  23219. this.initUIBase();
  23220. allPopups.push( this );
  23221. },
  23222. getHtmlTpl: function (){
  23223. return '<div id="##" class="edui-popup %%" onmousedown="return false;">' +
  23224. ' <div id="##_body" class="edui-popup-body">' +
  23225. ' <iframe style="position:absolute;z-index:-1;left:0;top:0;background-color: transparent;" frameborder="0" width="100%" height="100%" src="about:blank"></iframe>' +
  23226. ' <div class="edui-shadow"></div>' +
  23227. ' <div id="##_content" class="edui-popup-content">' +
  23228. this.getContentHtmlTpl() +
  23229. ' </div>' +
  23230. ' </div>' +
  23231. '</div>';
  23232. },
  23233. getContentHtmlTpl: function (){
  23234. if(this.content){
  23235. if (typeof this.content == 'string') {
  23236. return this.content;
  23237. }
  23238. return this.content.renderHtml();
  23239. }else{
  23240. return ''
  23241. }
  23242. },
  23243. _UIBase_postRender: UIBase.prototype.postRender,
  23244. postRender: function (){
  23245. if (this.content instanceof UIBase) {
  23246. this.content.postRender();
  23247. }
  23248. //捕获鼠标滚轮
  23249. if( this.captureWheel && !this.captured ) {
  23250. this.captured = true;
  23251. var winHeight = ( document.documentElement.clientHeight || document.body.clientHeight ) - 80,
  23252. _height = this.getDom().offsetHeight,
  23253. _top = uiUtils.getClientRect( this.combox.getDom() ).top,
  23254. content = this.getDom('content'),
  23255. ifr = this.getDom('body').getElementsByTagName('iframe'),
  23256. me = this;
  23257. ifr.length && ( ifr = ifr[0] );
  23258. while( _top + _height > winHeight ) {
  23259. _height -= 30;
  23260. }
  23261. content.style.height = _height + 'px';
  23262. //同步更改iframe高度
  23263. ifr && ( ifr.style.height = _height + 'px' );
  23264. //阻止在combox上的鼠标滚轮事件, 防止用户的正常操作被误解
  23265. if( window.XMLHttpRequest ) {
  23266. domUtils.on( content, ( 'onmousewheel' in document.body ) ? 'mousewheel' :'DOMMouseScroll' , function(e){
  23267. if(e.preventDefault) {
  23268. e.preventDefault();
  23269. } else {
  23270. e.returnValue = false;
  23271. }
  23272. if( e.wheelDelta ) {
  23273. content.scrollTop -= ( e.wheelDelta / 120 )*60;
  23274. } else {
  23275. content.scrollTop -= ( e.detail / -3 )*60;
  23276. }
  23277. });
  23278. } else {
  23279. //ie6
  23280. domUtils.on( this.getDom(), 'mousewheel' , function(e){
  23281. e.returnValue = false;
  23282. me.getDom('content').scrollTop -= ( e.wheelDelta / 120 )*60;
  23283. });
  23284. }
  23285. }
  23286. this.fireEvent('postRenderAfter');
  23287. this.hide(true);
  23288. this._UIBase_postRender();
  23289. },
  23290. _doAutoRender: function (){
  23291. if (!this.getDom() && this.autoRender) {
  23292. this.render();
  23293. }
  23294. },
  23295. mesureSize: function (){
  23296. var box = this.getDom('content');
  23297. return uiUtils.getClientRect(box);
  23298. },
  23299. fitSize: function (){
  23300. if( this.captureWheel && this.sized ) {
  23301. return this.__size;
  23302. }
  23303. this.sized = true;
  23304. var popBodyEl = this.getDom('body');
  23305. popBodyEl.style.width = '';
  23306. popBodyEl.style.height = '';
  23307. var size = this.mesureSize();
  23308. if( this.captureWheel ) {
  23309. popBodyEl.style.width = -(-20 -size.width) + 'px';
  23310. var height = parseInt( this.getDom('content').style.height, 10 );
  23311. !window.isNaN( height ) && ( size.height = height );
  23312. } else {
  23313. popBodyEl.style.width = size.width + 'px';
  23314. }
  23315. popBodyEl.style.height = size.height + 'px';
  23316. this.__size = size;
  23317. this.captureWheel && (this.getDom('content').style.overflow = 'auto');
  23318. return size;
  23319. },
  23320. showAnchor: function ( element, hoz ){
  23321. this.showAnchorRect( uiUtils.getClientRect( element ), hoz );
  23322. },
  23323. showAnchorRect: function ( rect, hoz, adj ){
  23324. this._doAutoRender();
  23325. var vpRect = uiUtils.getViewportRect();
  23326. this.getDom().style.visibility = 'hidden';
  23327. this._show();
  23328. var popSize = this.fitSize();
  23329. var sideLeft, sideUp, left, top;
  23330. if (hoz) {
  23331. sideLeft = this.canSideLeft && (rect.right + popSize.width > vpRect.right && rect.left > popSize.width);
  23332. sideUp = this.canSideUp && (rect.top + popSize.height > vpRect.bottom && rect.bottom > popSize.height);
  23333. left = (sideLeft ? rect.left - popSize.width : rect.right);
  23334. top = (sideUp ? rect.bottom - popSize.height : rect.top);
  23335. } else {
  23336. sideLeft = this.canSideLeft && (rect.right + popSize.width > vpRect.right && rect.left > popSize.width);
  23337. sideUp = this.canSideUp && (rect.top + popSize.height > vpRect.bottom && rect.bottom > popSize.height);
  23338. left = (sideLeft ? rect.right - popSize.width : rect.left);
  23339. top = (sideUp ? rect.top - popSize.height : rect.bottom);
  23340. }
  23341. var popEl = this.getDom();
  23342. uiUtils.setViewportOffset(popEl, {
  23343. left: left,
  23344. top: top
  23345. });
  23346. domUtils.removeClasses(popEl, ANCHOR_CLASSES);
  23347. popEl.className += ' ' + ANCHOR_CLASSES[(sideUp ? 1 : 0) * 2 + (sideLeft ? 1 : 0)];
  23348. if(this.editor){
  23349. popEl.style.zIndex = this.editor.container.style.zIndex * 1 + 10;
  23350. baidu.editor.ui.uiUtils.getFixedLayer().style.zIndex = popEl.style.zIndex - 1;
  23351. }
  23352. this.getDom().style.visibility = 'visible';
  23353. },
  23354. showAt: function (offset) {
  23355. var left = offset.left;
  23356. var top = offset.top;
  23357. var rect = {
  23358. left: left,
  23359. top: top,
  23360. right: left,
  23361. bottom: top,
  23362. height: 0,
  23363. width: 0
  23364. };
  23365. this.showAnchorRect(rect, false, true);
  23366. },
  23367. _show: function (){
  23368. if (this._hidden) {
  23369. var box = this.getDom();
  23370. box.style.display = '';
  23371. this._hidden = false;
  23372. // if (box.setActive) {
  23373. // box.setActive();
  23374. // }
  23375. this.fireEvent('show');
  23376. }
  23377. },
  23378. isHidden: function (){
  23379. return this._hidden;
  23380. },
  23381. show: function (){
  23382. this._doAutoRender();
  23383. this._show();
  23384. },
  23385. // hide: function (notNofity){
  23386. hide: function (notNofity, evt){
  23387. if (!this._hidden && this.getDom()) {
  23388. this.getDom().style.display = 'none';
  23389. this._hidden = true;
  23390. if (!notNofity) {
  23391. // this.fireEvent('hide');
  23392. this.fireEvent('hide', evt);
  23393. }
  23394. }
  23395. },
  23396. queryAutoHide: function (el){
  23397. return !el || !uiUtils.contains(this.getDom(), el);
  23398. }
  23399. };
  23400. utils.inherits(Popup, UIBase);
  23401. domUtils.on( document, 'mousedown', function ( evt ) {
  23402. var el = evt.target || evt.srcElement;
  23403. closeAllPopup( evt,el );
  23404. } );
  23405. domUtils.on( window, 'scroll', function (evt,el) {
  23406. closeAllPopup( evt,el );
  23407. } );
  23408. })();
  23409. // ui/colorpicker.js
  23410. ///import core
  23411. ///import uicore
  23412. (function (){
  23413. var utils = baidu.editor.utils,
  23414. UIBase = baidu.editor.ui.UIBase,
  23415. ColorPicker = baidu.editor.ui.ColorPicker = function (options){
  23416. this.initOptions(options);
  23417. this.noColorText = this.noColorText || this.editor.getLang("clearColor");
  23418. this.initUIBase();
  23419. };
  23420. ColorPicker.prototype = {
  23421. getHtmlTpl: function (){
  23422. return genColorPicker(this.noColorText,this.editor);
  23423. },
  23424. _onTableClick: function (evt){
  23425. var tgt = evt.target || evt.srcElement;
  23426. var color = tgt.getAttribute('data-color');
  23427. if (color) {
  23428. this.fireEvent('pickcolor', color);
  23429. }
  23430. },
  23431. _onTableOver: function (evt){
  23432. var tgt = evt.target || evt.srcElement;
  23433. var color = tgt.getAttribute('data-color');
  23434. if (color) {
  23435. this.getDom('preview').style.backgroundColor = color;
  23436. }
  23437. },
  23438. _onTableOut: function (){
  23439. this.getDom('preview').style.backgroundColor = '';
  23440. },
  23441. _onPickNoColor: function (){
  23442. this.fireEvent('picknocolor');
  23443. }
  23444. };
  23445. utils.inherits(ColorPicker, UIBase);
  23446. var COLORS = (
  23447. 'ffffff,000000,eeece1,1f497d,4f81bd,c0504d,9bbb59,8064a2,4bacc6,f79646,' +
  23448. 'f2f2f2,7f7f7f,ddd9c3,c6d9f0,dbe5f1,f2dcdb,ebf1dd,e5e0ec,dbeef3,fdeada,' +
  23449. 'd8d8d8,595959,c4bd97,8db3e2,b8cce4,e5b9b7,d7e3bc,ccc1d9,b7dde8,fbd5b5,' +
  23450. 'bfbfbf,3f3f3f,938953,548dd4,95b3d7,d99694,c3d69b,b2a2c7,92cddc,fac08f,' +
  23451. 'a5a5a5,262626,494429,17365d,366092,953734,76923c,5f497a,31859b,e36c09,' +
  23452. '7f7f7f,0c0c0c,1d1b10,0f243e,244061,632423,4f6128,3f3151,205867,974806,' +
  23453. 'c00000,ff0000,ffc000,ffff00,92d050,00b050,00b0f0,0070c0,002060,7030a0,').split(',');
  23454. function genColorPicker(noColorText,editor){
  23455. var html = '<div id="##" class="edui-colorpicker %%">' +
  23456. '<div class="edui-colorpicker-topbar edui-clearfix">' +
  23457. '<div unselectable="on" id="##_preview" class="edui-colorpicker-preview"></div>' +
  23458. '<div unselectable="on" class="edui-colorpicker-nocolor" onclick="$$._onPickNoColor(event, this);">'+ noColorText +'</div>' +
  23459. '</div>' +
  23460. '<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">' +
  23461. '<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>'+
  23462. '<tr class="edui-colorpicker-tablefirstrow" >';
  23463. for (var i=0; i<COLORS.length; i++) {
  23464. if (i && i%10 === 0) {
  23465. 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"':'')+'>';
  23466. }
  23467. 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"' +
  23468. ' data-color="#'+ COLORS[i] +'"'+
  23469. ' style="background-color:#'+ COLORS[i] +';border:solid #ccc;'+
  23470. (i<10 || i>=60?'border-width:1px;':
  23471. i>=10&&i<20?'border-width:1px 1px 0 1px;':
  23472. 'border-width:0 1px 0 1px;')+
  23473. '"' +
  23474. '></a></td>':'';
  23475. }
  23476. html += '</tr></table></div>';
  23477. return html;
  23478. }
  23479. })();
  23480. // ui/tablepicker.js
  23481. ///import core
  23482. ///import uicore
  23483. (function (){
  23484. var utils = baidu.editor.utils,
  23485. uiUtils = baidu.editor.ui.uiUtils,
  23486. UIBase = baidu.editor.ui.UIBase;
  23487. var TablePicker = baidu.editor.ui.TablePicker = function (options){
  23488. this.initOptions(options);
  23489. this.initTablePicker();
  23490. };
  23491. TablePicker.prototype = {
  23492. defaultNumRows: 10,
  23493. defaultNumCols: 10,
  23494. maxNumRows: 20,
  23495. maxNumCols: 20,
  23496. numRows: 10,
  23497. numCols: 10,
  23498. lengthOfCellSide: 22,
  23499. initTablePicker: function (){
  23500. this.initUIBase();
  23501. },
  23502. getHtmlTpl: function (){
  23503. var me = this;
  23504. return '<div id="##" class="edui-tablepicker %%">' +
  23505. '<div class="edui-tablepicker-body">' +
  23506. '<div class="edui-infoarea">' +
  23507. '<span id="##_label" class="edui-label"></span>' +
  23508. '</div>' +
  23509. '<div class="edui-pickarea"' +
  23510. ' onmousemove="$$._onMouseMove(event, this);"' +
  23511. ' onmouseover="$$._onMouseOver(event, this);"' +
  23512. ' onmouseout="$$._onMouseOut(event, this);"' +
  23513. ' onclick="$$._onClick(event, this);"' +
  23514. '>' +
  23515. '<div id="##_overlay" class="edui-overlay"></div>' +
  23516. '</div>' +
  23517. '</div>' +
  23518. '</div>';
  23519. },
  23520. _UIBase_render: UIBase.prototype.render,
  23521. render: function (holder){
  23522. this._UIBase_render(holder);
  23523. this.getDom('label').innerHTML = '0'+this.editor.getLang("t_row")+' x 0'+this.editor.getLang("t_col");
  23524. },
  23525. _track: function (numCols, numRows){
  23526. var style = this.getDom('overlay').style;
  23527. var sideLen = this.lengthOfCellSide;
  23528. style.width = numCols * sideLen + 'px';
  23529. style.height = numRows * sideLen + 'px';
  23530. var label = this.getDom('label');
  23531. label.innerHTML = numCols +this.editor.getLang("t_col")+' x ' + numRows + this.editor.getLang("t_row");
  23532. this.numCols = numCols;
  23533. this.numRows = numRows;
  23534. },
  23535. _onMouseOver: function (evt, el){
  23536. var rel = evt.relatedTarget || evt.fromElement;
  23537. if (!uiUtils.contains(el, rel) && el !== rel) {
  23538. this.getDom('label').innerHTML = '0'+this.editor.getLang("t_col")+' x 0'+this.editor.getLang("t_row");
  23539. this.getDom('overlay').style.visibility = '';
  23540. }
  23541. },
  23542. _onMouseOut: function (evt, el){
  23543. var rel = evt.relatedTarget || evt.toElement;
  23544. if (!uiUtils.contains(el, rel) && el !== rel) {
  23545. this.getDom('label').innerHTML = '0'+this.editor.getLang("t_col")+' x 0'+this.editor.getLang("t_row");
  23546. this.getDom('overlay').style.visibility = 'hidden';
  23547. }
  23548. },
  23549. _onMouseMove: function (evt, el){
  23550. var style = this.getDom('overlay').style;
  23551. var offset = uiUtils.getEventOffset(evt);
  23552. var sideLen = this.lengthOfCellSide;
  23553. var numCols = Math.ceil(offset.left / sideLen);
  23554. var numRows = Math.ceil(offset.top / sideLen);
  23555. this._track(numCols, numRows);
  23556. },
  23557. _onClick: function (){
  23558. this.fireEvent('picktable', this.numCols, this.numRows);
  23559. }
  23560. };
  23561. utils.inherits(TablePicker, UIBase);
  23562. })();
  23563. // ui/stateful.js
  23564. (function (){
  23565. var browser = baidu.editor.browser,
  23566. domUtils = baidu.editor.dom.domUtils,
  23567. uiUtils = baidu.editor.ui.uiUtils;
  23568. var TPL_STATEFUL = 'onmousedown="$$.Stateful_onMouseDown(event, this);"' +
  23569. ' onmouseup="$$.Stateful_onMouseUp(event, this);"' +
  23570. ( browser.ie ? (
  23571. ' onmouseenter="$$.Stateful_onMouseEnter(event, this);"' +
  23572. ' onmouseleave="$$.Stateful_onMouseLeave(event, this);"' )
  23573. : (
  23574. ' onmouseover="$$.Stateful_onMouseOver(event, this);"' +
  23575. ' onmouseout="$$.Stateful_onMouseOut(event, this);"' ));
  23576. baidu.editor.ui.Stateful = {
  23577. alwalysHoverable: false,
  23578. target:null,//目标元素和this指向dom不一样
  23579. Stateful_init: function (){
  23580. this._Stateful_dGetHtmlTpl = this.getHtmlTpl;
  23581. this.getHtmlTpl = this.Stateful_getHtmlTpl;
  23582. },
  23583. Stateful_getHtmlTpl: function (){
  23584. var tpl = this._Stateful_dGetHtmlTpl();
  23585. // 使用function避免$转义
  23586. return tpl.replace(/stateful/g, function (){ return TPL_STATEFUL; });
  23587. },
  23588. Stateful_onMouseEnter: function (evt, el){
  23589. this.target=el;
  23590. if (!this.isDisabled() || this.alwalysHoverable) {
  23591. this.addState('hover');
  23592. this.fireEvent('over');
  23593. }
  23594. },
  23595. Stateful_onMouseLeave: function (evt, el){
  23596. if (!this.isDisabled() || this.alwalysHoverable) {
  23597. this.removeState('hover');
  23598. this.removeState('active');
  23599. this.fireEvent('out');
  23600. }
  23601. },
  23602. Stateful_onMouseOver: function (evt, el){
  23603. var rel = evt.relatedTarget;
  23604. if (!uiUtils.contains(el, rel) && el !== rel) {
  23605. this.Stateful_onMouseEnter(evt, el);
  23606. }
  23607. },
  23608. Stateful_onMouseOut: function (evt, el){
  23609. var rel = evt.relatedTarget;
  23610. if (!uiUtils.contains(el, rel) && el !== rel) {
  23611. this.Stateful_onMouseLeave(evt, el);
  23612. }
  23613. },
  23614. Stateful_onMouseDown: function (evt, el){
  23615. if (!this.isDisabled()) {
  23616. this.addState('active');
  23617. }
  23618. },
  23619. Stateful_onMouseUp: function (evt, el){
  23620. if (!this.isDisabled()) {
  23621. this.removeState('active');
  23622. }
  23623. },
  23624. Stateful_postRender: function (){
  23625. if (this.disabled && !this.hasState('disabled')) {
  23626. this.addState('disabled');
  23627. }
  23628. },
  23629. hasState: function (state){
  23630. return domUtils.hasClass(this.getStateDom(), 'edui-state-' + state);
  23631. },
  23632. addState: function (state){
  23633. if (!this.hasState(state)) {
  23634. this.getStateDom().className += ' edui-state-' + state;
  23635. }
  23636. },
  23637. removeState: function (state){
  23638. if (this.hasState(state)) {
  23639. domUtils.removeClasses(this.getStateDom(), ['edui-state-' + state]);
  23640. }
  23641. },
  23642. getStateDom: function (){
  23643. return this.getDom('state');
  23644. },
  23645. isChecked: function (){
  23646. return this.hasState('checked');
  23647. },
  23648. setChecked: function (checked){
  23649. if (!this.isDisabled() && checked) {
  23650. this.addState('checked');
  23651. } else {
  23652. this.removeState('checked');
  23653. }
  23654. },
  23655. isDisabled: function (){
  23656. return this.hasState('disabled');
  23657. },
  23658. setDisabled: function (disabled){
  23659. if (disabled) {
  23660. this.removeState('hover');
  23661. this.removeState('checked');
  23662. this.removeState('active');
  23663. this.addState('disabled');
  23664. } else {
  23665. this.removeState('disabled');
  23666. }
  23667. }
  23668. };
  23669. })();
  23670. // ui/button.js
  23671. ///import core
  23672. ///import uicore
  23673. ///import ui/stateful.js
  23674. (function (){
  23675. var utils = baidu.editor.utils,
  23676. UIBase = baidu.editor.ui.UIBase,
  23677. Stateful = baidu.editor.ui.Stateful,
  23678. Button = baidu.editor.ui.Button = function (options){
  23679. if(options.name){
  23680. var btnName = options.name;
  23681. var cssRules = options.cssRules;
  23682. if(!options.className){
  23683. options.className = 'edui-for-' + btnName;
  23684. }
  23685. options.cssRules = '.edui-default .edui-for-'+ btnName +' .edui-icon {'+ cssRules +'}'
  23686. }
  23687. this.initOptions(options);
  23688. this.initButton();
  23689. };
  23690. Button.prototype = {
  23691. uiName: 'button',
  23692. label: '',
  23693. title: '',
  23694. showIcon: true,
  23695. showText: true,
  23696. cssRules:'',
  23697. initButton: function (){
  23698. this.initUIBase();
  23699. this.Stateful_init();
  23700. if(this.cssRules){
  23701. utils.cssRule('edui-customize-'+this.name+'-style',this.cssRules);
  23702. }
  23703. },
  23704. getHtmlTpl: function (){
  23705. return '<div id="##" class="edui-box %%">' +
  23706. '<div id="##_state" stateful>' +
  23707. '<div class="%%-wrap"><div id="##_body" unselectable="on" ' + (this.title ? 'title="' + this.title + '"' : '') +
  23708. ' class="%%-body" onmousedown="return $$._onMouseDown(event, this);" onclick="return $$._onClick(event, this);">' +
  23709. (this.showIcon ? '<div class="edui-box edui-icon"></div>' : '') +
  23710. (this.showText ? '<div class="edui-box edui-label">' + this.label + '</div>' : '') +
  23711. '</div>' +
  23712. '</div>' +
  23713. '</div></div>';
  23714. },
  23715. postRender: function (){
  23716. this.Stateful_postRender();
  23717. this.setDisabled(this.disabled)
  23718. },
  23719. _onMouseDown: function (e){
  23720. var target = e.target || e.srcElement,
  23721. tagName = target && target.tagName && target.tagName.toLowerCase();
  23722. if (tagName == 'input' || tagName == 'object' || tagName == 'object') {
  23723. return false;
  23724. }
  23725. },
  23726. _onClick: function (){
  23727. if (!this.isDisabled()) {
  23728. this.fireEvent('click');
  23729. }
  23730. },
  23731. setTitle: function(text){
  23732. var label = this.getDom('label');
  23733. label.innerHTML = text;
  23734. }
  23735. };
  23736. utils.inherits(Button, UIBase);
  23737. utils.extend(Button.prototype, Stateful);
  23738. })();
  23739. // ui/splitbutton.js
  23740. ///import core
  23741. ///import uicore
  23742. ///import ui/stateful.js
  23743. (function (){
  23744. var utils = baidu.editor.utils,
  23745. uiUtils = baidu.editor.ui.uiUtils,
  23746. domUtils = baidu.editor.dom.domUtils,
  23747. UIBase = baidu.editor.ui.UIBase,
  23748. Stateful = baidu.editor.ui.Stateful,
  23749. SplitButton = baidu.editor.ui.SplitButton = function (options){
  23750. this.initOptions(options);
  23751. this.initSplitButton();
  23752. };
  23753. SplitButton.prototype = {
  23754. popup: null,
  23755. uiName: 'splitbutton',
  23756. title: '',
  23757. initSplitButton: function (){
  23758. this.initUIBase();
  23759. this.Stateful_init();
  23760. var me = this;
  23761. if (this.popup != null) {
  23762. var popup = this.popup;
  23763. this.popup = null;
  23764. this.setPopup(popup);
  23765. }
  23766. },
  23767. _UIBase_postRender: UIBase.prototype.postRender,
  23768. postRender: function (){
  23769. this.Stateful_postRender();
  23770. this._UIBase_postRender();
  23771. },
  23772. setPopup: function (popup){
  23773. if (this.popup === popup) return;
  23774. if (this.popup != null) {
  23775. this.popup.dispose();
  23776. }
  23777. popup.addListener('show', utils.bind(this._onPopupShow, this));
  23778. popup.addListener('hide', utils.bind(this._onPopupHide, this));
  23779. popup.addListener('postrender', utils.bind(function (){
  23780. popup.getDom('body').appendChild(
  23781. uiUtils.createElementByHtml('<div id="' +
  23782. this.popup.id + '_bordereraser" class="edui-bordereraser edui-background" style="width:' +
  23783. (uiUtils.getClientRect(this.getDom()).width + 20) + 'px"></div>')
  23784. );
  23785. popup.getDom().className += ' ' + this.className;
  23786. }, this));
  23787. this.popup = popup;
  23788. },
  23789. _onPopupShow: function (){
  23790. this.addState('opened');
  23791. },
  23792. _onPopupHide: function (){
  23793. this.removeState('opened');
  23794. },
  23795. getHtmlTpl: function (){
  23796. return '<div id="##" class="edui-box %%">' +
  23797. '<div '+ (this.title ? 'title="' + this.title + '"' : '') +' id="##_state" stateful><div class="%%-body">' +
  23798. '<div id="##_button_body" class="edui-box edui-button-body" onclick="$$._onButtonClick(event, this);">' +
  23799. '<div class="edui-box edui-icon"></div>' +
  23800. '</div>' +
  23801. '<div class="edui-box edui-splitborder"></div>' +
  23802. '<div class="edui-box edui-arrow" onclick="$$._onArrowClick();"></div>' +
  23803. '</div></div></div>';
  23804. },
  23805. showPopup: function (){
  23806. // 当popup往上弹出的时候,做特殊处理
  23807. var rect = uiUtils.getClientRect(this.getDom());
  23808. rect.top -= this.popup.SHADOW_RADIUS;
  23809. rect.height += this.popup.SHADOW_RADIUS;
  23810. this.popup.showAnchorRect(rect);
  23811. },
  23812. _onArrowClick: function (event, el){
  23813. if (!this.isDisabled()) {
  23814. this.showPopup();
  23815. }
  23816. },
  23817. _onButtonClick: function (){
  23818. if (!this.isDisabled()) {
  23819. this.fireEvent('buttonclick');
  23820. }
  23821. }
  23822. };
  23823. utils.inherits(SplitButton, UIBase);
  23824. utils.extend(SplitButton.prototype, Stateful, true);
  23825. })();
  23826. // ui/colorbutton.js
  23827. ///import core
  23828. ///import uicore
  23829. ///import ui/colorpicker.js
  23830. ///import ui/popup.js
  23831. ///import ui/splitbutton.js
  23832. (function (){
  23833. var utils = baidu.editor.utils,
  23834. uiUtils = baidu.editor.ui.uiUtils,
  23835. ColorPicker = baidu.editor.ui.ColorPicker,
  23836. Popup = baidu.editor.ui.Popup,
  23837. SplitButton = baidu.editor.ui.SplitButton,
  23838. ColorButton = baidu.editor.ui.ColorButton = function (options){
  23839. this.initOptions(options);
  23840. this.initColorButton();
  23841. };
  23842. ColorButton.prototype = {
  23843. initColorButton: function (){
  23844. var me = this;
  23845. this.popup = new Popup({
  23846. content: new ColorPicker({
  23847. noColorText: me.editor.getLang("clearColor"),
  23848. editor:me.editor,
  23849. onpickcolor: function (t, color){
  23850. me._onPickColor(color);
  23851. },
  23852. onpicknocolor: function (t, color){
  23853. me._onPickNoColor(color);
  23854. }
  23855. }),
  23856. editor:me.editor
  23857. });
  23858. this.initSplitButton();
  23859. },
  23860. _SplitButton_postRender: SplitButton.prototype.postRender,
  23861. postRender: function (){
  23862. this._SplitButton_postRender();
  23863. this.getDom('button_body').appendChild(
  23864. uiUtils.createElementByHtml('<div id="' + this.id + '_colorlump" class="edui-colorlump"></div>')
  23865. );
  23866. this.getDom().className += ' edui-colorbutton';
  23867. },
  23868. setColor: function (color){
  23869. this.getDom('colorlump').style.backgroundColor = color;
  23870. this.color = color;
  23871. },
  23872. _onPickColor: function (color){
  23873. if (this.fireEvent('pickcolor', color) !== false) {
  23874. this.setColor(color);
  23875. this.popup.hide();
  23876. }
  23877. },
  23878. _onPickNoColor: function (color){
  23879. if (this.fireEvent('picknocolor') !== false) {
  23880. this.popup.hide();
  23881. }
  23882. }
  23883. };
  23884. utils.inherits(ColorButton, SplitButton);
  23885. })();
  23886. // ui/tablebutton.js
  23887. ///import core
  23888. ///import uicore
  23889. ///import ui/popup.js
  23890. ///import ui/tablepicker.js
  23891. ///import ui/splitbutton.js
  23892. (function (){
  23893. var utils = baidu.editor.utils,
  23894. Popup = baidu.editor.ui.Popup,
  23895. TablePicker = baidu.editor.ui.TablePicker,
  23896. SplitButton = baidu.editor.ui.SplitButton,
  23897. TableButton = baidu.editor.ui.TableButton = function (options){
  23898. this.initOptions(options);
  23899. this.initTableButton();
  23900. };
  23901. TableButton.prototype = {
  23902. initTableButton: function (){
  23903. var me = this;
  23904. this.popup = new Popup({
  23905. content: new TablePicker({
  23906. editor:me.editor,
  23907. onpicktable: function (t, numCols, numRows){
  23908. me._onPickTable(numCols, numRows);
  23909. }
  23910. }),
  23911. 'editor':me.editor
  23912. });
  23913. this.initSplitButton();
  23914. },
  23915. _onPickTable: function (numCols, numRows){
  23916. if (this.fireEvent('picktable', numCols, numRows) !== false) {
  23917. this.popup.hide();
  23918. }
  23919. }
  23920. };
  23921. utils.inherits(TableButton, SplitButton);
  23922. })();
  23923. // ui/autotypesetpicker.js
  23924. ///import core
  23925. ///import uicore
  23926. (function () {
  23927. var utils = baidu.editor.utils,
  23928. UIBase = baidu.editor.ui.UIBase;
  23929. var AutoTypeSetPicker = baidu.editor.ui.AutoTypeSetPicker = function (options) {
  23930. this.initOptions(options);
  23931. this.initAutoTypeSetPicker();
  23932. };
  23933. AutoTypeSetPicker.prototype = {
  23934. initAutoTypeSetPicker:function () {
  23935. this.initUIBase();
  23936. },
  23937. getHtmlTpl:function () {
  23938. var me = this.editor,
  23939. opt = me.options.autotypeset,
  23940. lang = me.getLang("autoTypeSet");
  23941. var textAlignInputName = 'textAlignValue' + me.uid,
  23942. imageBlockInputName = 'imageBlockLineValue' + me.uid,
  23943. symbolConverInputName = 'symbolConverValue' + me.uid;
  23944. return '<div id="##" class="edui-autotypesetpicker %%">' +
  23945. '<div class="edui-autotypesetpicker-body">' +
  23946. '<table >' +
  23947. '<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>' +
  23948. '<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>' +
  23949. '<tr>' +
  23950. '<td nowrap><input type="checkbox" name="textAlign" ' + (opt["textAlign"] ? "checked" : "" ) + '>' + lang.alignment + '</td>' +
  23951. '<td colspan="2" id="' + textAlignInputName + '">' +
  23952. '<input type="radio" name="'+ textAlignInputName +'" value="left" ' + ((opt["textAlign"] && opt["textAlign"] == "left") ? "checked" : "") + '>' + me.getLang("justifyleft") +
  23953. '<input type="radio" name="'+ textAlignInputName +'" value="center" ' + ((opt["textAlign"] && opt["textAlign"] == "center") ? "checked" : "") + '>' + me.getLang("justifycenter") +
  23954. '<input type="radio" name="'+ textAlignInputName +'" value="right" ' + ((opt["textAlign"] && opt["textAlign"] == "right") ? "checked" : "") + '>' + me.getLang("justifyright") +
  23955. '</td>' +
  23956. '</tr>' +
  23957. '<tr>' +
  23958. '<td nowrap><input type="checkbox" name="imageBlockLine" ' + (opt["imageBlockLine"] ? "checked" : "" ) + '>' + lang.imageFloat + '</td>' +
  23959. '<td nowrap id="'+ imageBlockInputName +'">' +
  23960. '<input type="radio" name="'+ imageBlockInputName +'" value="none" ' + ((opt["imageBlockLine"] && opt["imageBlockLine"] == "none") ? "checked" : "") + '>' + me.getLang("default") +
  23961. '<input type="radio" name="'+ imageBlockInputName +'" value="left" ' + ((opt["imageBlockLine"] && opt["imageBlockLine"] == "left") ? "checked" : "") + '>' + me.getLang("justifyleft") +
  23962. '<input type="radio" name="'+ imageBlockInputName +'" value="center" ' + ((opt["imageBlockLine"] && opt["imageBlockLine"] == "center") ? "checked" : "") + '>' + me.getLang("justifycenter") +
  23963. '<input type="radio" name="'+ imageBlockInputName +'" value="right" ' + ((opt["imageBlockLine"] && opt["imageBlockLine"] == "right") ? "checked" : "") + '>' + me.getLang("justifyright") +
  23964. '</td>' +
  23965. '</tr>' +
  23966. '<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>' +
  23967. '<tr><td nowrap colspan="3"><input type="checkbox" name="removeEmptyNode" ' + (opt["removeEmptyNode"] ? "checked" : "" ) + '>' + lang.removeHtml + '</td></tr>' +
  23968. '<tr><td nowrap colspan="3"><input type="checkbox" name="pasteFilter" ' + (opt["pasteFilter"] ? "checked" : "" ) + '>' + lang.pasteFilter + '</td></tr>' +
  23969. '<tr>' +
  23970. '<td nowrap><input type="checkbox" name="symbolConver" ' + (opt["bdc2sb"] || opt["tobdc"] ? "checked" : "" ) + '>' + lang.symbol + '</td>' +
  23971. '<td id="' + symbolConverInputName + '">' +
  23972. '<input type="radio" name="bdc" value="bdc2sb" ' + (opt["bdc2sb"] ? "checked" : "" ) + '>' + lang.bdc2sb +
  23973. '<input type="radio" name="bdc" value="tobdc" ' + (opt["tobdc"] ? "checked" : "" ) + '>' + lang.tobdc + '' +
  23974. '</td>' +
  23975. '<td nowrap align="right"><button >' + lang.run + '</button></td>' +
  23976. '</tr>' +
  23977. '</table>' +
  23978. '</div>' +
  23979. '</div>';
  23980. },
  23981. _UIBase_render:UIBase.prototype.render
  23982. };
  23983. utils.inherits(AutoTypeSetPicker, UIBase);
  23984. })();
  23985. // ui/autotypesetbutton.js
  23986. ///import core
  23987. ///import uicore
  23988. ///import ui/popup.js
  23989. ///import ui/autotypesetpicker.js
  23990. ///import ui/splitbutton.js
  23991. (function (){
  23992. var utils = baidu.editor.utils,
  23993. Popup = baidu.editor.ui.Popup,
  23994. AutoTypeSetPicker = baidu.editor.ui.AutoTypeSetPicker,
  23995. SplitButton = baidu.editor.ui.SplitButton,
  23996. AutoTypeSetButton = baidu.editor.ui.AutoTypeSetButton = function (options){
  23997. this.initOptions(options);
  23998. this.initAutoTypeSetButton();
  23999. };
  24000. function getPara(me){
  24001. var opt = {},
  24002. cont = me.getDom(),
  24003. editorId = me.editor.uid,
  24004. inputType = null,
  24005. attrName = null,
  24006. ipts = domUtils.getElementsByTagName(cont,"input");
  24007. for(var i=ipts.length-1,ipt;ipt=ipts[i--];){
  24008. inputType = ipt.getAttribute("type");
  24009. if(inputType=="checkbox"){
  24010. attrName = ipt.getAttribute("name");
  24011. opt[attrName] && delete opt[attrName];
  24012. if(ipt.checked){
  24013. var attrValue = document.getElementById( attrName + "Value" + editorId );
  24014. if(attrValue){
  24015. if(/input/ig.test(attrValue.tagName)){
  24016. opt[attrName] = attrValue.value;
  24017. } else {
  24018. var iptChilds = attrValue.getElementsByTagName("input");
  24019. for(var j=iptChilds.length-1,iptchild;iptchild=iptChilds[j--];){
  24020. if(iptchild.checked){
  24021. opt[attrName] = iptchild.value;
  24022. break;
  24023. }
  24024. }
  24025. }
  24026. } else {
  24027. opt[attrName] = true;
  24028. }
  24029. } else {
  24030. opt[attrName] = false;
  24031. }
  24032. } else {
  24033. opt[ipt.getAttribute("value")] = ipt.checked;
  24034. }
  24035. }
  24036. var selects = domUtils.getElementsByTagName(cont,"select");
  24037. for(var i=0,si;si=selects[i++];){
  24038. var attr = si.getAttribute('name');
  24039. opt[attr] = opt[attr] ? si.value : '';
  24040. }
  24041. utils.extend(me.editor.options.autotypeset,opt);
  24042. me.editor.setPreferences('autotypeset', opt);
  24043. }
  24044. AutoTypeSetButton.prototype = {
  24045. initAutoTypeSetButton: function (){
  24046. var me = this;
  24047. this.popup = new Popup({
  24048. //传入配置参数
  24049. content: new AutoTypeSetPicker({editor:me.editor}),
  24050. 'editor':me.editor,
  24051. hide : function(){
  24052. if (!this._hidden && this.getDom()) {
  24053. getPara(this);
  24054. this.getDom().style.display = 'none';
  24055. this._hidden = true;
  24056. this.fireEvent('hide');
  24057. }
  24058. }
  24059. });
  24060. var flag = 0;
  24061. this.popup.addListener('postRenderAfter',function(){
  24062. var popupUI = this;
  24063. if(flag)return;
  24064. var cont = this.getDom(),
  24065. btn = cont.getElementsByTagName('button')[0];
  24066. btn.onclick = function(){
  24067. getPara(popupUI);
  24068. me.editor.execCommand('autotypeset');
  24069. popupUI.hide()
  24070. };
  24071. domUtils.on(cont, 'click', function(e) {
  24072. var target = e.target || e.srcElement,
  24073. editorId = me.editor.uid;
  24074. if (target && target.tagName == 'INPUT') {
  24075. // 点击图片浮动的checkbox,去除对应的radio
  24076. if (target.name == 'imageBlockLine' || target.name == 'textAlign' || target.name == 'symbolConver') {
  24077. var checked = target.checked,
  24078. radioTd = document.getElementById( target.name + 'Value' + editorId),
  24079. radios = radioTd.getElementsByTagName('input'),
  24080. defalutSelect = {
  24081. 'imageBlockLine': 'none',
  24082. 'textAlign': 'left',
  24083. 'symbolConver': 'tobdc'
  24084. };
  24085. for (var i = 0; i < radios.length; i++) {
  24086. if (checked) {
  24087. if (radios[i].value == defalutSelect[target.name]) {
  24088. radios[i].checked = 'checked';
  24089. }
  24090. } else {
  24091. radios[i].checked = false;
  24092. }
  24093. }
  24094. }
  24095. // 点击radio,选中对应的checkbox
  24096. if (target.name == ('imageBlockLineValue' + editorId) || target.name == ('textAlignValue' + editorId) || target.name == 'bdc') {
  24097. var checkboxs = target.parentNode.previousSibling.getElementsByTagName('input');
  24098. checkboxs && (checkboxs[0].checked = true);
  24099. }
  24100. getPara(popupUI);
  24101. }
  24102. });
  24103. flag = 1;
  24104. });
  24105. this.initSplitButton();
  24106. }
  24107. };
  24108. utils.inherits(AutoTypeSetButton, SplitButton);
  24109. })();
  24110. // ui/cellalignpicker.js
  24111. ///import core
  24112. ///import uicore
  24113. (function () {
  24114. var utils = baidu.editor.utils,
  24115. Popup = baidu.editor.ui.Popup,
  24116. Stateful = baidu.editor.ui.Stateful,
  24117. UIBase = baidu.editor.ui.UIBase;
  24118. /**
  24119. * 该参数将新增一个参数: selected, 参数类型为一个Object, 形如{ 'align': 'center', 'valign': 'top' }, 表示单元格的初始
  24120. * 对齐状态为: 竖直居上,水平居中; 其中 align的取值为:'center', 'left', 'right'; valign的取值为: 'top', 'middle', 'bottom'
  24121. * @update 2013/4/2 hancong03@baidu.com
  24122. */
  24123. var CellAlignPicker = baidu.editor.ui.CellAlignPicker = function (options) {
  24124. this.initOptions(options);
  24125. this.initSelected();
  24126. this.initCellAlignPicker();
  24127. };
  24128. CellAlignPicker.prototype = {
  24129. //初始化选中状态, 该方法将根据传递进来的参数获取到应该选中的对齐方式图标的索引
  24130. initSelected: function(){
  24131. var status = {
  24132. valign: {
  24133. top: 0,
  24134. middle: 1,
  24135. bottom: 2
  24136. },
  24137. align: {
  24138. left: 0,
  24139. center: 1,
  24140. right: 2
  24141. },
  24142. count: 3
  24143. },
  24144. result = -1;
  24145. if( this.selected ) {
  24146. this.selectedIndex = status.valign[ this.selected.valign ] * status.count + status.align[ this.selected.align ];
  24147. }
  24148. },
  24149. initCellAlignPicker:function () {
  24150. this.initUIBase();
  24151. this.Stateful_init();
  24152. },
  24153. getHtmlTpl:function () {
  24154. var alignType = [ 'left', 'center', 'right' ],
  24155. COUNT = 9,
  24156. tempClassName = null,
  24157. tempIndex = -1,
  24158. tmpl = [];
  24159. for( var i= 0; i<COUNT; i++ ) {
  24160. tempClassName = this.selectedIndex === i ? ' class="edui-cellalign-selected" ' : '';
  24161. tempIndex = i % 3;
  24162. tempIndex === 0 && tmpl.push('<tr>');
  24163. tmpl.push( '<td index="'+ i +'" ' + tempClassName + ' stateful><div class="edui-icon edui-'+ alignType[ tempIndex ] +'"></div></td>' );
  24164. tempIndex === 2 && tmpl.push('</tr>');
  24165. }
  24166. return '<div id="##" class="edui-cellalignpicker %%">' +
  24167. '<div class="edui-cellalignpicker-body">' +
  24168. '<table onclick="$$._onClick(event);">' +
  24169. tmpl.join('') +
  24170. '</table>' +
  24171. '</div>' +
  24172. '</div>';
  24173. },
  24174. getStateDom: function (){
  24175. return this.target;
  24176. },
  24177. _onClick: function (evt){
  24178. var target= evt.target || evt.srcElement;
  24179. if(/icon/.test(target.className)){
  24180. this.items[target.parentNode.getAttribute("index")].onclick();
  24181. Popup.postHide(evt);
  24182. }
  24183. },
  24184. _UIBase_render:UIBase.prototype.render
  24185. };
  24186. utils.inherits(CellAlignPicker, UIBase);
  24187. utils.extend(CellAlignPicker.prototype, Stateful,true);
  24188. })();
  24189. // ui/pastepicker.js
  24190. ///import core
  24191. ///import uicore
  24192. (function () {
  24193. var utils = baidu.editor.utils,
  24194. Stateful = baidu.editor.ui.Stateful,
  24195. uiUtils = baidu.editor.ui.uiUtils,
  24196. UIBase = baidu.editor.ui.UIBase;
  24197. var PastePicker = baidu.editor.ui.PastePicker = function (options) {
  24198. this.initOptions(options);
  24199. this.initPastePicker();
  24200. };
  24201. PastePicker.prototype = {
  24202. initPastePicker:function () {
  24203. this.initUIBase();
  24204. this.Stateful_init();
  24205. },
  24206. getHtmlTpl:function () {
  24207. return '<div class="edui-pasteicon" onclick="$$._onClick(this)"></div>' +
  24208. '<div class="edui-pastecontainer">' +
  24209. '<div class="edui-title">' + this.editor.getLang("pasteOpt") + '</div>' +
  24210. '<div class="edui-button">' +
  24211. '<div title="' + this.editor.getLang("pasteSourceFormat") + '" onclick="$$.format(false)" stateful>' +
  24212. '<div class="edui-richtxticon"></div></div>' +
  24213. '<div title="' + this.editor.getLang("tagFormat") + '" onclick="$$.format(2)" stateful>' +
  24214. '<div class="edui-tagicon"></div></div>' +
  24215. '<div title="' + this.editor.getLang("pasteTextFormat") + '" onclick="$$.format(true)" stateful>' +
  24216. '<div class="edui-plaintxticon"></div></div>' +
  24217. '</div>' +
  24218. '</div>' +
  24219. '</div>'
  24220. },
  24221. getStateDom:function () {
  24222. return this.target;
  24223. },
  24224. format:function (param) {
  24225. this.editor.ui._isTransfer = true;
  24226. this.editor.fireEvent('pasteTransfer', param);
  24227. },
  24228. _onClick:function (cur) {
  24229. var node = domUtils.getNextDomNode(cur),
  24230. screenHt = uiUtils.getViewportRect().height,
  24231. subPop = uiUtils.getClientRect(node);
  24232. if ((subPop.top + subPop.height) > screenHt)
  24233. node.style.top = (-subPop.height - cur.offsetHeight) + "px";
  24234. else
  24235. node.style.top = "";
  24236. if (/hidden/ig.test(domUtils.getComputedStyle(node, "visibility"))) {
  24237. node.style.visibility = "visible";
  24238. domUtils.addClass(cur, "edui-state-opened");
  24239. } else {
  24240. node.style.visibility = "hidden";
  24241. domUtils.removeClasses(cur, "edui-state-opened")
  24242. }
  24243. },
  24244. _UIBase_render:UIBase.prototype.render
  24245. };
  24246. utils.inherits(PastePicker, UIBase);
  24247. utils.extend(PastePicker.prototype, Stateful, true);
  24248. })();
  24249. // ui/toolbar.js
  24250. (function (){
  24251. var utils = baidu.editor.utils,
  24252. uiUtils = baidu.editor.ui.uiUtils,
  24253. UIBase = baidu.editor.ui.UIBase,
  24254. Toolbar = baidu.editor.ui.Toolbar = function (options){
  24255. this.initOptions(options);
  24256. this.initToolbar();
  24257. };
  24258. Toolbar.prototype = {
  24259. items: null,
  24260. initToolbar: function (){
  24261. this.items = this.items || [];
  24262. this.initUIBase();
  24263. },
  24264. add: function (item,index){
  24265. if(index === undefined){
  24266. this.items.push(item);
  24267. }else{
  24268. this.items.splice(index,0,item)
  24269. }
  24270. },
  24271. getHtmlTpl: function (){
  24272. var buff = [];
  24273. for (var i=0; i<this.items.length; i++) {
  24274. buff[i] = this.items[i].renderHtml();
  24275. }
  24276. return '<div id="##" class="edui-toolbar %%" onselectstart="return false;" onmousedown="return $$._onMouseDown(event, this);">' +
  24277. buff.join('') +
  24278. '</div>'
  24279. },
  24280. postRender: function (){
  24281. var box = this.getDom();
  24282. for (var i=0; i<this.items.length; i++) {
  24283. this.items[i].postRender();
  24284. }
  24285. uiUtils.makeUnselectable(box);
  24286. },
  24287. _onMouseDown: function (e){
  24288. var target = e.target || e.srcElement,
  24289. tagName = target && target.tagName && target.tagName.toLowerCase();
  24290. if (tagName == 'input' || tagName == 'object' || tagName == 'object') {
  24291. return false;
  24292. }
  24293. }
  24294. };
  24295. utils.inherits(Toolbar, UIBase);
  24296. })();
  24297. // ui/menu.js
  24298. ///import core
  24299. ///import uicore
  24300. ///import ui\popup.js
  24301. ///import ui\stateful.js
  24302. (function () {
  24303. var utils = baidu.editor.utils,
  24304. domUtils = baidu.editor.dom.domUtils,
  24305. uiUtils = baidu.editor.ui.uiUtils,
  24306. UIBase = baidu.editor.ui.UIBase,
  24307. Popup = baidu.editor.ui.Popup,
  24308. Stateful = baidu.editor.ui.Stateful,
  24309. CellAlignPicker = baidu.editor.ui.CellAlignPicker,
  24310. Menu = baidu.editor.ui.Menu = function (options) {
  24311. this.initOptions(options);
  24312. this.initMenu();
  24313. };
  24314. var menuSeparator = {
  24315. renderHtml:function () {
  24316. return '<div class="edui-menuitem edui-menuseparator"><div class="edui-menuseparator-inner"></div></div>';
  24317. },
  24318. postRender:function () {
  24319. },
  24320. queryAutoHide:function () {
  24321. return true;
  24322. }
  24323. };
  24324. Menu.prototype = {
  24325. items:null,
  24326. uiName:'menu',
  24327. initMenu:function () {
  24328. this.items = this.items || [];
  24329. this.initPopup();
  24330. this.initItems();
  24331. },
  24332. initItems:function () {
  24333. for (var i = 0; i < this.items.length; i++) {
  24334. var item = this.items[i];
  24335. if (item == '-') {
  24336. this.items[i] = this.getSeparator();
  24337. } else if (!(item instanceof MenuItem)) {
  24338. item.editor = this.editor;
  24339. item.theme = this.editor.options.theme;
  24340. this.items[i] = this.createItem(item);
  24341. }
  24342. }
  24343. },
  24344. getSeparator:function () {
  24345. return menuSeparator;
  24346. },
  24347. createItem:function (item) {
  24348. //新增一个参数menu, 该参数存储了menuItem所对应的menu引用
  24349. item.menu = this;
  24350. return new MenuItem(item);
  24351. },
  24352. _Popup_getContentHtmlTpl:Popup.prototype.getContentHtmlTpl,
  24353. getContentHtmlTpl:function () {
  24354. if (this.items.length == 0) {
  24355. return this._Popup_getContentHtmlTpl();
  24356. }
  24357. var buff = [];
  24358. for (var i = 0; i < this.items.length; i++) {
  24359. var item = this.items[i];
  24360. buff[i] = item.renderHtml();
  24361. }
  24362. return ('<div class="%%-body">' + buff.join('') + '</div>');
  24363. },
  24364. _Popup_postRender:Popup.prototype.postRender,
  24365. postRender:function () {
  24366. var me = this;
  24367. for (var i = 0; i < this.items.length; i++) {
  24368. var item = this.items[i];
  24369. item.ownerMenu = this;
  24370. item.postRender();
  24371. }
  24372. domUtils.on(this.getDom(), 'mouseover', function (evt) {
  24373. evt = evt || event;
  24374. var rel = evt.relatedTarget || evt.fromElement;
  24375. var el = me.getDom();
  24376. if (!uiUtils.contains(el, rel) && el !== rel) {
  24377. me.fireEvent('over');
  24378. }
  24379. });
  24380. this._Popup_postRender();
  24381. },
  24382. queryAutoHide:function (el) {
  24383. if (el) {
  24384. if (uiUtils.contains(this.getDom(), el)) {
  24385. return false;
  24386. }
  24387. for (var i = 0; i < this.items.length; i++) {
  24388. var item = this.items[i];
  24389. if (item.queryAutoHide(el) === false) {
  24390. return false;
  24391. }
  24392. }
  24393. }
  24394. },
  24395. clearItems:function () {
  24396. for (var i = 0; i < this.items.length; i++) {
  24397. var item = this.items[i];
  24398. clearTimeout(item._showingTimer);
  24399. clearTimeout(item._closingTimer);
  24400. if (item.subMenu) {
  24401. item.subMenu.destroy();
  24402. }
  24403. }
  24404. this.items = [];
  24405. },
  24406. destroy:function () {
  24407. if (this.getDom()) {
  24408. domUtils.remove(this.getDom());
  24409. }
  24410. this.clearItems();
  24411. },
  24412. dispose:function () {
  24413. this.destroy();
  24414. }
  24415. };
  24416. utils.inherits(Menu, Popup);
  24417. /**
  24418. * @update 2013/04/03 hancong03 新增一个参数menu, 该参数存储了menuItem所对应的menu引用
  24419. * @type {Function}
  24420. */
  24421. var MenuItem = baidu.editor.ui.MenuItem = function (options) {
  24422. this.initOptions(options);
  24423. this.initUIBase();
  24424. this.Stateful_init();
  24425. if (this.subMenu && !(this.subMenu instanceof Menu)) {
  24426. if (options.className && options.className.indexOf("aligntd") != -1) {
  24427. var me = this;
  24428. //获取单元格对齐初始状态
  24429. this.subMenu.selected = this.editor.queryCommandValue( 'cellalignment' );
  24430. this.subMenu = new Popup({
  24431. content:new CellAlignPicker(this.subMenu),
  24432. parentMenu:me,
  24433. editor:me.editor,
  24434. destroy:function () {
  24435. if (this.getDom()) {
  24436. domUtils.remove(this.getDom());
  24437. }
  24438. }
  24439. });
  24440. this.subMenu.addListener("postRenderAfter", function () {
  24441. domUtils.on(this.getDom(), "mouseover", function () {
  24442. me.addState('opened');
  24443. });
  24444. });
  24445. } else {
  24446. this.subMenu = new Menu(this.subMenu);
  24447. }
  24448. }
  24449. };
  24450. MenuItem.prototype = {
  24451. label:'',
  24452. subMenu:null,
  24453. ownerMenu:null,
  24454. uiName:'menuitem',
  24455. alwalysHoverable:true,
  24456. getHtmlTpl:function () {
  24457. return '<div id="##" class="%%" stateful onclick="$$._onClick(event, this);">' +
  24458. '<div class="%%-body">' +
  24459. this.renderLabelHtml() +
  24460. '</div>' +
  24461. '</div>';
  24462. },
  24463. postRender:function () {
  24464. var me = this;
  24465. this.addListener('over', function () {
  24466. me.ownerMenu.fireEvent('submenuover', me);
  24467. if (me.subMenu) {
  24468. me.delayShowSubMenu();
  24469. }
  24470. });
  24471. if (this.subMenu) {
  24472. this.getDom().className += ' edui-hassubmenu';
  24473. this.subMenu.render();
  24474. this.addListener('out', function () {
  24475. me.delayHideSubMenu();
  24476. });
  24477. this.subMenu.addListener('over', function () {
  24478. clearTimeout(me._closingTimer);
  24479. me._closingTimer = null;
  24480. me.addState('opened');
  24481. });
  24482. this.ownerMenu.addListener('hide', function () {
  24483. me.hideSubMenu();
  24484. });
  24485. this.ownerMenu.addListener('submenuover', function (t, subMenu) {
  24486. if (subMenu !== me) {
  24487. me.delayHideSubMenu();
  24488. }
  24489. });
  24490. this.subMenu._bakQueryAutoHide = this.subMenu.queryAutoHide;
  24491. this.subMenu.queryAutoHide = function (el) {
  24492. if (el && uiUtils.contains(me.getDom(), el)) {
  24493. return false;
  24494. }
  24495. return this._bakQueryAutoHide(el);
  24496. };
  24497. }
  24498. this.getDom().style.tabIndex = '-1';
  24499. uiUtils.makeUnselectable(this.getDom());
  24500. this.Stateful_postRender();
  24501. },
  24502. delayShowSubMenu:function () {
  24503. var me = this;
  24504. if (!me.isDisabled()) {
  24505. me.addState('opened');
  24506. clearTimeout(me._showingTimer);
  24507. clearTimeout(me._closingTimer);
  24508. me._closingTimer = null;
  24509. me._showingTimer = setTimeout(function () {
  24510. me.showSubMenu();
  24511. }, 250);
  24512. }
  24513. },
  24514. delayHideSubMenu:function () {
  24515. var me = this;
  24516. if (!me.isDisabled()) {
  24517. me.removeState('opened');
  24518. clearTimeout(me._showingTimer);
  24519. if (!me._closingTimer) {
  24520. me._closingTimer = setTimeout(function () {
  24521. if (!me.hasState('opened')) {
  24522. me.hideSubMenu();
  24523. }
  24524. me._closingTimer = null;
  24525. }, 400);
  24526. }
  24527. }
  24528. },
  24529. renderLabelHtml:function () {
  24530. return '<div class="edui-arrow"></div>' +
  24531. '<div class="edui-box edui-icon"></div>' +
  24532. '<div class="edui-box edui-label %%-label">' + (this.label || '') + '</div>';
  24533. },
  24534. getStateDom:function () {
  24535. return this.getDom();
  24536. },
  24537. queryAutoHide:function (el) {
  24538. if (this.subMenu && this.hasState('opened')) {
  24539. return this.subMenu.queryAutoHide(el);
  24540. }
  24541. },
  24542. _onClick:function (event, this_) {
  24543. if (this.hasState('disabled')) return;
  24544. if (this.fireEvent('click', event, this_) !== false) {
  24545. if (this.subMenu) {
  24546. this.showSubMenu();
  24547. } else {
  24548. Popup.postHide(event);
  24549. }
  24550. }
  24551. },
  24552. showSubMenu:function () {
  24553. var rect = uiUtils.getClientRect(this.getDom());
  24554. rect.right -= 5;
  24555. rect.left += 2;
  24556. rect.width -= 7;
  24557. rect.top -= 4;
  24558. rect.bottom += 4;
  24559. rect.height += 8;
  24560. this.subMenu.showAnchorRect(rect, true, true);
  24561. },
  24562. hideSubMenu:function () {
  24563. this.subMenu.hide();
  24564. }
  24565. };
  24566. utils.inherits(MenuItem, UIBase);
  24567. utils.extend(MenuItem.prototype, Stateful, true);
  24568. })();
  24569. // ui/combox.js
  24570. ///import core
  24571. ///import uicore
  24572. ///import ui/menu.js
  24573. ///import ui/splitbutton.js
  24574. (function (){
  24575. // todo: menu和item提成通用list
  24576. var utils = baidu.editor.utils,
  24577. uiUtils = baidu.editor.ui.uiUtils,
  24578. Menu = baidu.editor.ui.Menu,
  24579. SplitButton = baidu.editor.ui.SplitButton,
  24580. Combox = baidu.editor.ui.Combox = function (options){
  24581. this.initOptions(options);
  24582. this.initCombox();
  24583. };
  24584. Combox.prototype = {
  24585. uiName: 'combox',
  24586. onbuttonclick:function () {
  24587. this.showPopup();
  24588. },
  24589. initCombox: function (){
  24590. var me = this;
  24591. this.items = this.items || [];
  24592. for (var i=0; i<this.items.length; i++) {
  24593. var item = this.items[i];
  24594. item.uiName = 'listitem';
  24595. item.index = i;
  24596. item.onclick = function (){
  24597. me.selectByIndex(this.index);
  24598. };
  24599. }
  24600. this.popup = new Menu({
  24601. items: this.items,
  24602. uiName: 'list',
  24603. editor:this.editor,
  24604. captureWheel: true,
  24605. combox: this
  24606. });
  24607. this.initSplitButton();
  24608. },
  24609. _SplitButton_postRender: SplitButton.prototype.postRender,
  24610. postRender: function (){
  24611. this._SplitButton_postRender();
  24612. this.setLabel(this.label || '');
  24613. this.setValue(this.initValue || '');
  24614. },
  24615. showPopup: function (){
  24616. var rect = uiUtils.getClientRect(this.getDom());
  24617. rect.top += 1;
  24618. rect.bottom -= 1;
  24619. rect.height -= 2;
  24620. this.popup.showAnchorRect(rect);
  24621. },
  24622. getValue: function (){
  24623. return this.value;
  24624. },
  24625. setValue: function (value){
  24626. var index = this.indexByValue(value);
  24627. if (index != -1) {
  24628. this.selectedIndex = index;
  24629. this.setLabel(this.items[index].label);
  24630. this.value = this.items[index].value;
  24631. } else {
  24632. this.selectedIndex = -1;
  24633. this.setLabel(this.getLabelForUnknowValue(value));
  24634. this.value = value;
  24635. }
  24636. },
  24637. setLabel: function (label){
  24638. this.getDom('button_body').innerHTML = label;
  24639. this.label = label;
  24640. },
  24641. getLabelForUnknowValue: function (value){
  24642. return value;
  24643. },
  24644. indexByValue: function (value){
  24645. for (var i=0; i<this.items.length; i++) {
  24646. if (value == this.items[i].value) {
  24647. return i;
  24648. }
  24649. }
  24650. return -1;
  24651. },
  24652. getItem: function (index){
  24653. return this.items[index];
  24654. },
  24655. selectByIndex: function (index){
  24656. if (index < this.items.length && this.fireEvent('select', index) !== false) {
  24657. this.selectedIndex = index;
  24658. this.value = this.items[index].value;
  24659. this.setLabel(this.items[index].label);
  24660. }
  24661. }
  24662. };
  24663. utils.inherits(Combox, SplitButton);
  24664. })();
  24665. // ui/dialog.js
  24666. ///import core
  24667. ///import uicore
  24668. ///import ui/mask.js
  24669. ///import ui/button.js
  24670. (function (){
  24671. var utils = baidu.editor.utils,
  24672. domUtils = baidu.editor.dom.domUtils,
  24673. uiUtils = baidu.editor.ui.uiUtils,
  24674. Mask = baidu.editor.ui.Mask,
  24675. UIBase = baidu.editor.ui.UIBase,
  24676. Button = baidu.editor.ui.Button,
  24677. Dialog = baidu.editor.ui.Dialog = function (options){
  24678. if(options.name){
  24679. var name = options.name;
  24680. var cssRules = options.cssRules;
  24681. if(!options.className){
  24682. options.className = 'edui-for-' + name;
  24683. }
  24684. if(cssRules){
  24685. options.cssRules = '.edui-default .edui-for-'+ name +' .edui-dialog-content {'+ cssRules +'}'
  24686. }
  24687. }
  24688. this.initOptions(utils.extend({
  24689. autoReset: true,
  24690. draggable: true,
  24691. onok: function (){},
  24692. oncancel: function (){},
  24693. onclose: function (t, ok){
  24694. return ok ? this.onok() : this.oncancel();
  24695. },
  24696. //是否控制dialog中的scroll事件, 默认为不阻止
  24697. holdScroll: false
  24698. },options));
  24699. this.initDialog();
  24700. };
  24701. var modalMask;
  24702. var dragMask;
  24703. var activeDialog;
  24704. Dialog.prototype = {
  24705. draggable: false,
  24706. uiName: 'dialog',
  24707. initDialog: function (){
  24708. var me = this,
  24709. theme=this.editor.options.theme;
  24710. if(this.cssRules){
  24711. utils.cssRule('edui-customize-'+this.name+'-style',this.cssRules);
  24712. }
  24713. this.initUIBase();
  24714. this.modalMask = (modalMask || (modalMask = new Mask({
  24715. className: 'edui-dialog-modalmask',
  24716. theme:theme,
  24717. onclick: function (){
  24718. activeDialog && activeDialog.close(false);
  24719. }
  24720. })));
  24721. this.dragMask = (dragMask || (dragMask = new Mask({
  24722. className: 'edui-dialog-dragmask',
  24723. theme:theme
  24724. })));
  24725. this.closeButton = new Button({
  24726. className: 'edui-dialog-closebutton',
  24727. title: me.closeDialog,
  24728. theme:theme,
  24729. onclick: function (){
  24730. me.close(false);
  24731. }
  24732. });
  24733. this.fullscreen && this.initResizeEvent();
  24734. if (this.buttons) {
  24735. for (var i=0; i<this.buttons.length; i++) {
  24736. if (!(this.buttons[i] instanceof Button)) {
  24737. this.buttons[i] = new Button(utils.extend(this.buttons[i],{
  24738. editor : this.editor
  24739. },true));
  24740. }
  24741. }
  24742. }
  24743. },
  24744. initResizeEvent: function () {
  24745. var me = this;
  24746. domUtils.on( window, "resize", function () {
  24747. if ( me._hidden || me._hidden === undefined ) {
  24748. return;
  24749. }
  24750. if ( me.__resizeTimer ) {
  24751. window.clearTimeout( me.__resizeTimer );
  24752. }
  24753. me.__resizeTimer = window.setTimeout( function () {
  24754. me.__resizeTimer = null;
  24755. var dialogWrapNode = me.getDom(),
  24756. contentNode = me.getDom('content'),
  24757. wrapRect = UE.ui.uiUtils.getClientRect( dialogWrapNode ),
  24758. contentRect = UE.ui.uiUtils.getClientRect( contentNode ),
  24759. vpRect = uiUtils.getViewportRect();
  24760. contentNode.style.width = ( vpRect.width - wrapRect.width + contentRect.width ) + "px";
  24761. contentNode.style.height = ( vpRect.height - wrapRect.height + contentRect.height ) + "px";
  24762. dialogWrapNode.style.width = vpRect.width + "px";
  24763. dialogWrapNode.style.height = vpRect.height + "px";
  24764. me.fireEvent( "resize" );
  24765. }, 100 );
  24766. } );
  24767. },
  24768. fitSize: function (){
  24769. var popBodyEl = this.getDom('body');
  24770. // if (!(baidu.editor.browser.ie && baidu.editor.browser.version == 7)) {
  24771. // uiUtils.removeStyle(popBodyEl, 'width');
  24772. // uiUtils.removeStyle(popBodyEl, 'height');
  24773. // }
  24774. var size = this.mesureSize();
  24775. popBodyEl.style.width = size.width + 'px';
  24776. popBodyEl.style.height = size.height + 'px';
  24777. return size;
  24778. },
  24779. safeSetOffset: function (offset){
  24780. var me = this;
  24781. var el = me.getDom();
  24782. var vpRect = uiUtils.getViewportRect();
  24783. var rect = uiUtils.getClientRect(el);
  24784. var left = offset.left;
  24785. if (left + rect.width > vpRect.right) {
  24786. left = vpRect.right - rect.width;
  24787. }
  24788. var top = offset.top;
  24789. if (top + rect.height > vpRect.bottom) {
  24790. top = vpRect.bottom - rect.height;
  24791. }
  24792. el.style.left = Math.max(left, 0) + 'px';
  24793. el.style.top = Math.max(top, 0) + 'px';
  24794. },
  24795. showAtCenter: function (){
  24796. var vpRect = uiUtils.getViewportRect();
  24797. if ( !this.fullscreen ) {
  24798. this.getDom().style.display = '';
  24799. var popSize = this.fitSize();
  24800. var titleHeight = this.getDom('titlebar').offsetHeight | 0;
  24801. var left = vpRect.width / 2 - popSize.width / 2;
  24802. var top = vpRect.height / 2 - (popSize.height - titleHeight) / 2 - titleHeight;
  24803. var popEl = this.getDom();
  24804. this.safeSetOffset({
  24805. left: Math.max(left | 0, 0),
  24806. top: Math.max(top | 0, 0)
  24807. });
  24808. if (!domUtils.hasClass(popEl, 'edui-state-centered')) {
  24809. popEl.className += ' edui-state-centered';
  24810. }
  24811. } else {
  24812. var dialogWrapNode = this.getDom(),
  24813. contentNode = this.getDom('content');
  24814. dialogWrapNode.style.display = "block";
  24815. var wrapRect = UE.ui.uiUtils.getClientRect( dialogWrapNode ),
  24816. contentRect = UE.ui.uiUtils.getClientRect( contentNode );
  24817. dialogWrapNode.style.left = "-100000px";
  24818. contentNode.style.width = ( vpRect.width - wrapRect.width + contentRect.width ) + "px";
  24819. contentNode.style.height = ( vpRect.height - wrapRect.height + contentRect.height ) + "px";
  24820. dialogWrapNode.style.width = vpRect.width + "px";
  24821. dialogWrapNode.style.height = vpRect.height + "px";
  24822. dialogWrapNode.style.left = 0;
  24823. //保存环境的overflow值
  24824. this._originalContext = {
  24825. html: {
  24826. overflowX: document.documentElement.style.overflowX,
  24827. overflowY: document.documentElement.style.overflowY
  24828. },
  24829. body: {
  24830. overflowX: document.body.style.overflowX,
  24831. overflowY: document.body.style.overflowY
  24832. }
  24833. };
  24834. document.documentElement.style.overflowX = 'hidden';
  24835. document.documentElement.style.overflowY = 'hidden';
  24836. document.body.style.overflowX = 'hidden';
  24837. document.body.style.overflowY = 'hidden';
  24838. }
  24839. this._show();
  24840. },
  24841. getContentHtml: function (){
  24842. var contentHtml = '';
  24843. if (typeof this.content == 'string') {
  24844. contentHtml = this.content;
  24845. } else if (this.iframeUrl) {
  24846. contentHtml = '<span id="'+ this.id +'_contmask" class="dialogcontmask"></span><iframe id="'+ this.id +
  24847. '_iframe" class="%%-iframe" height="100%" width="100%" frameborder="0" src="'+ this.iframeUrl +'"></iframe>';
  24848. }
  24849. return contentHtml;
  24850. },
  24851. getHtmlTpl: function (){
  24852. var footHtml = '';
  24853. if (this.buttons) {
  24854. var buff = [];
  24855. for (var i=0; i<this.buttons.length; i++) {
  24856. buff[i] = this.buttons[i].renderHtml();
  24857. }
  24858. footHtml = '<div class="%%-foot">' +
  24859. '<div id="##_buttons" class="%%-buttons">' + buff.join('') + '</div>' +
  24860. '</div>';
  24861. }
  24862. return '<div id="##" class="%%"><div '+ ( !this.fullscreen ? 'class="%%"' : 'class="%%-wrap edui-dialog-fullscreen-flag"' ) +'><div id="##_body" class="%%-body">' +
  24863. '<div class="%%-shadow"></div>' +
  24864. '<div id="##_titlebar" class="%%-titlebar">' +
  24865. '<div class="%%-draghandle" onmousedown="$$._onTitlebarMouseDown(event, this);">' +
  24866. '<span class="%%-caption">' + (this.title || '') + '</span>' +
  24867. '</div>' +
  24868. this.closeButton.renderHtml() +
  24869. '</div>' +
  24870. '<div id="##_content" class="%%-content">'+ ( this.autoReset ? '' : this.getContentHtml()) +'</div>' +
  24871. footHtml +
  24872. '</div></div></div>';
  24873. },
  24874. postRender: function (){
  24875. // todo: 保持居中/记住上次关闭位置选项
  24876. if (!this.modalMask.getDom()) {
  24877. this.modalMask.render();
  24878. this.modalMask.hide();
  24879. }
  24880. if (!this.dragMask.getDom()) {
  24881. this.dragMask.render();
  24882. this.dragMask.hide();
  24883. }
  24884. var me = this;
  24885. this.addListener('show', function (){
  24886. me.modalMask.show(this.getDom().style.zIndex - 2);
  24887. });
  24888. this.addListener('hide', function (){
  24889. me.modalMask.hide();
  24890. });
  24891. if (this.buttons) {
  24892. for (var i=0; i<this.buttons.length; i++) {
  24893. this.buttons[i].postRender();
  24894. }
  24895. }
  24896. domUtils.on(window, 'resize', function (){
  24897. setTimeout(function (){
  24898. if (!me.isHidden()) {
  24899. me.safeSetOffset(uiUtils.getClientRect(me.getDom()));
  24900. }
  24901. });
  24902. });
  24903. //hold住scroll事件,防止dialog的滚动影响页面
  24904. // if( this.holdScroll ) {
  24905. //
  24906. // if( !me.iframeUrl ) {
  24907. // domUtils.on( document.getElementById( me.id + "_iframe"), !browser.gecko ? "mousewheel" : "DOMMouseScroll", function(e){
  24908. // domUtils.preventDefault(e);
  24909. // } );
  24910. // } else {
  24911. // me.addListener('dialogafterreset', function(){
  24912. // window.setTimeout(function(){
  24913. // var iframeWindow = document.getElementById( me.id + "_iframe").contentWindow;
  24914. //
  24915. // if( browser.ie ) {
  24916. //
  24917. // var timer = window.setInterval(function(){
  24918. //
  24919. // if( iframeWindow.document && iframeWindow.document.body ) {
  24920. // window.clearInterval( timer );
  24921. // timer = null;
  24922. // domUtils.on( iframeWindow.document.body, !browser.gecko ? "mousewheel" : "DOMMouseScroll", function(e){
  24923. // domUtils.preventDefault(e);
  24924. // } );
  24925. // }
  24926. //
  24927. // }, 100);
  24928. //
  24929. // } else {
  24930. // domUtils.on( iframeWindow, !browser.gecko ? "mousewheel" : "DOMMouseScroll", function(e){
  24931. // domUtils.preventDefault(e);
  24932. // } );
  24933. // }
  24934. //
  24935. // }, 1);
  24936. // });
  24937. // }
  24938. //
  24939. // }
  24940. this._hide();
  24941. },
  24942. mesureSize: function (){
  24943. var body = this.getDom('body');
  24944. var width = uiUtils.getClientRect(this.getDom('content')).width;
  24945. var dialogBodyStyle = body.style;
  24946. dialogBodyStyle.width = width;
  24947. return uiUtils.getClientRect(body);
  24948. },
  24949. _onTitlebarMouseDown: function (evt, el){
  24950. if (this.draggable) {
  24951. var rect;
  24952. var vpRect = uiUtils.getViewportRect();
  24953. var me = this;
  24954. uiUtils.startDrag(evt, {
  24955. ondragstart: function (){
  24956. rect = uiUtils.getClientRect(me.getDom());
  24957. me.getDom('contmask').style.visibility = 'visible';
  24958. me.dragMask.show(me.getDom().style.zIndex - 1);
  24959. },
  24960. ondragmove: function (x, y){
  24961. var left = rect.left + x;
  24962. var top = rect.top + y;
  24963. me.safeSetOffset({
  24964. left: left,
  24965. top: top
  24966. });
  24967. },
  24968. ondragstop: function (){
  24969. me.getDom('contmask').style.visibility = 'hidden';
  24970. domUtils.removeClasses(me.getDom(), ['edui-state-centered']);
  24971. me.dragMask.hide();
  24972. }
  24973. });
  24974. }
  24975. },
  24976. reset: function (){
  24977. this.getDom('content').innerHTML = this.getContentHtml();
  24978. this.fireEvent('dialogafterreset');
  24979. },
  24980. _show: function (){
  24981. if (this._hidden) {
  24982. this.getDom().style.display = '';
  24983. //要高过编辑器的zindxe
  24984. this.editor.container.style.zIndex && (this.getDom().style.zIndex = this.editor.container.style.zIndex * 1 + 10);
  24985. this._hidden = false;
  24986. this.fireEvent('show');
  24987. baidu.editor.ui.uiUtils.getFixedLayer().style.zIndex = this.getDom().style.zIndex - 4;
  24988. }
  24989. },
  24990. isHidden: function (){
  24991. return this._hidden;
  24992. },
  24993. _hide: function (){
  24994. if (!this._hidden) {
  24995. var wrapNode = this.getDom();
  24996. wrapNode.style.display = 'none';
  24997. wrapNode.style.zIndex = '';
  24998. wrapNode.style.width = '';
  24999. wrapNode.style.height = '';
  25000. this._hidden = true;
  25001. this.fireEvent('hide');
  25002. }
  25003. },
  25004. open: function (){
  25005. if (this.autoReset) {
  25006. //有可能还没有渲染
  25007. try{
  25008. this.reset();
  25009. }catch(e){
  25010. this.render();
  25011. this.open()
  25012. }
  25013. }
  25014. this.showAtCenter();
  25015. if (this.iframeUrl) {
  25016. try {
  25017. this.getDom('iframe').focus();
  25018. } catch(ex){}
  25019. }
  25020. activeDialog = this;
  25021. },
  25022. _onCloseButtonClick: function (evt, el){
  25023. this.close(false);
  25024. },
  25025. close: function (ok){
  25026. if (this.fireEvent('close', ok) !== false) {
  25027. //还原环境
  25028. if ( this.fullscreen ) {
  25029. document.documentElement.style.overflowX = this._originalContext.html.overflowX;
  25030. document.documentElement.style.overflowY = this._originalContext.html.overflowY;
  25031. document.body.style.overflowX = this._originalContext.body.overflowX;
  25032. document.body.style.overflowY = this._originalContext.body.overflowY;
  25033. delete this._originalContext;
  25034. }
  25035. this._hide();
  25036. //销毁content
  25037. var content = this.getDom('content');
  25038. var iframe = this.getDom('iframe');
  25039. if (content && iframe) {
  25040. var doc = iframe.contentDocument || iframe.contentWindow.document;
  25041. doc && (doc.body.innerHTML = '');
  25042. domUtils.remove(content);
  25043. }
  25044. }
  25045. }
  25046. };
  25047. utils.inherits(Dialog, UIBase);
  25048. })();
  25049. // ui/menubutton.js
  25050. ///import core
  25051. ///import uicore
  25052. ///import ui/menu.js
  25053. ///import ui/splitbutton.js
  25054. (function (){
  25055. var utils = baidu.editor.utils,
  25056. Menu = baidu.editor.ui.Menu,
  25057. SplitButton = baidu.editor.ui.SplitButton,
  25058. MenuButton = baidu.editor.ui.MenuButton = function (options){
  25059. this.initOptions(options);
  25060. this.initMenuButton();
  25061. };
  25062. MenuButton.prototype = {
  25063. initMenuButton: function (){
  25064. var me = this;
  25065. this.uiName = "menubutton";
  25066. this.popup = new Menu({
  25067. items: me.items,
  25068. className: me.className,
  25069. editor:me.editor
  25070. });
  25071. this.popup.addListener('show', function (){
  25072. var list = this;
  25073. for (var i=0; i<list.items.length; i++) {
  25074. list.items[i].removeState('checked');
  25075. if (list.items[i].value == me._value) {
  25076. list.items[i].addState('checked');
  25077. this.value = me._value;
  25078. }
  25079. }
  25080. });
  25081. this.initSplitButton();
  25082. },
  25083. setValue : function(value){
  25084. this._value = value;
  25085. }
  25086. };
  25087. utils.inherits(MenuButton, SplitButton);
  25088. })();
  25089. // ui/multiMenu.js
  25090. ///import core
  25091. ///import uicore
  25092. ///commands 表情
  25093. (function(){
  25094. var utils = baidu.editor.utils,
  25095. Popup = baidu.editor.ui.Popup,
  25096. SplitButton = baidu.editor.ui.SplitButton,
  25097. MultiMenuPop = baidu.editor.ui.MultiMenuPop = function(options){
  25098. this.initOptions(options);
  25099. this.initMultiMenu();
  25100. };
  25101. MultiMenuPop.prototype = {
  25102. initMultiMenu: function (){
  25103. var me = this;
  25104. this.popup = new Popup({
  25105. content: '',
  25106. editor : me.editor,
  25107. iframe_rendered: false,
  25108. onshow: function (){
  25109. if (!this.iframe_rendered) {
  25110. this.iframe_rendered = true;
  25111. this.getDom('content').innerHTML = '<iframe id="'+me.id+'_iframe" src="'+ me.iframeUrl +'" frameborder="0"></iframe>';
  25112. me.editor.container.style.zIndex && (this.getDom().style.zIndex = me.editor.container.style.zIndex * 1 + 1);
  25113. }
  25114. }
  25115. // canSideUp:false,
  25116. // canSideLeft:false
  25117. });
  25118. this.onbuttonclick = function(){
  25119. this.showPopup();
  25120. };
  25121. this.initSplitButton();
  25122. }
  25123. };
  25124. utils.inherits(MultiMenuPop, SplitButton);
  25125. })();
  25126. // ui/shortcutmenu.js
  25127. (function () {
  25128. var UI = baidu.editor.ui,
  25129. UIBase = UI.UIBase,
  25130. uiUtils = UI.uiUtils,
  25131. utils = baidu.editor.utils,
  25132. domUtils = baidu.editor.dom.domUtils;
  25133. var allMenus = [],//存储所有快捷菜单
  25134. timeID,
  25135. isSubMenuShow = false;//是否有子pop显示
  25136. var ShortCutMenu = UI.ShortCutMenu = function (options) {
  25137. this.initOptions (options);
  25138. this.initShortCutMenu ();
  25139. };
  25140. ShortCutMenu.postHide = hideAllMenu;
  25141. ShortCutMenu.prototype = {
  25142. isHidden : true ,
  25143. SPACE : 5 ,
  25144. initShortCutMenu : function () {
  25145. this.items = this.items || [];
  25146. this.initUIBase ();
  25147. this.initItems ();
  25148. this.initEvent ();
  25149. allMenus.push (this);
  25150. } ,
  25151. initEvent : function () {
  25152. var me = this,
  25153. doc = me.editor.document;
  25154. domUtils.on(doc, "mousemove", function(e) {
  25155. !1 !== me.isHidden || me.getSubMenuMark() || "contextmenu" == me.eventType || me.getDom()
  25156. });
  25157. me.editor.addListener("afterhidepop", function() {
  25158. me.isHidden || (isSubMenuShow = !0)
  25159. })
  25160. // var me = this,
  25161. // doc = me.editor.document;
  25162. // domUtils.on (doc , "mousemove" , function (e) {
  25163. // if (me.isHidden === false) {
  25164. // //有pop显示就不隐藏快捷菜单
  25165. // if (me.getSubMenuMark () || me.eventType == "contextmenu") return;
  25166. // var flag = true,
  25167. // el = me.getDom (),
  25168. // wt = el.offsetWidth,
  25169. // ht = el.offsetHeight,
  25170. // distanceX = wt / 2 + me.SPACE,//距离中心X标准
  25171. // distanceY = ht / 2,//距离中心Y标准
  25172. // x = Math.abs (e.screenX - me.left),//离中心距离横坐标
  25173. // y = Math.abs (e.screenY - me.top);//离中心距离纵坐标
  25174. // clearTimeout (timeID);
  25175. // timeID = setTimeout (function () {
  25176. // if (y > 0 && y < distanceY) {
  25177. // me.setOpacity (el , "1");
  25178. // } else if (y > distanceY && y < distanceY + 70) {
  25179. // me.setOpacity (el , "0.5");
  25180. // flag = false;
  25181. // } else if (y > distanceY + 70 && y < distanceY + 140) {
  25182. // me.hide ();
  25183. // }
  25184. // if (flag && x > 0 && x < distanceX) {
  25185. // me.setOpacity (el , "1")
  25186. // } else if (x > distanceX && x < distanceX + 70) {
  25187. // me.setOpacity (el , "0.5")
  25188. // } else if (x > distanceX + 70 && x < distanceX + 140) {
  25189. // me.hide ();
  25190. // }
  25191. // });
  25192. // }
  25193. // });
  25194. // //ie\ff下 mouseout不准
  25195. // if (browser.chrome) {
  25196. // domUtils.on (doc , "mouseout" , function (e) {
  25197. // var relatedTgt = e.relatedTarget || e.toElement;
  25198. // if (relatedTgt == null || relatedTgt.tagName == "HTML") {
  25199. // me.hide ();
  25200. // }
  25201. // });
  25202. // }
  25203. // me.editor.addListener ("afterhidepop" , function () {
  25204. // if (!me.isHidden) {
  25205. // isSubMenuShow = true;
  25206. // }
  25207. // });
  25208. } ,
  25209. initItems : function () {
  25210. if (utils.isArray (this.items)) {
  25211. for (var i = 0, len = this.items.length ; i < len ; i++) {
  25212. var item = this.items[i].toLowerCase ();
  25213. if (UI[item]) {
  25214. this.items[i] = new UI[item] (this.editor);
  25215. this.items[i].className += " edui-shortcutsubmenu ";
  25216. }
  25217. }
  25218. }
  25219. } ,
  25220. setOpacity : function (el , value) {
  25221. if (browser.ie && browser.version < 9) {
  25222. el.style.filter = "alpha(opacity = " + parseFloat (value) * 100 + ");"
  25223. } else {
  25224. el.style.opacity = value;
  25225. }
  25226. } ,
  25227. getSubMenuMark : function () {
  25228. isSubMenuShow = false;
  25229. var layerEle = uiUtils.getFixedLayer ();
  25230. var list = domUtils.getElementsByTagName (layerEle , "div" , function (node) {
  25231. return domUtils.hasClass (node , "edui-shortcutsubmenu edui-popup")
  25232. });
  25233. for (var i = 0, node ; node = list[i++] ;) {
  25234. if (node.style.display != "none") {
  25235. isSubMenuShow = true;
  25236. }
  25237. }
  25238. return isSubMenuShow;
  25239. } ,
  25240. show : function (e , hasContextmenu) {
  25241. var me = this,
  25242. offset = {},
  25243. el = this.getDom (),
  25244. fixedlayer = uiUtils.getFixedLayer ();
  25245. function setPos (offset) {
  25246. if (offset.left < 0) {
  25247. offset.left = 0;
  25248. }
  25249. if (offset.top < 0) {
  25250. offset.top = 0;
  25251. }
  25252. el.style.cssText = "position:absolute;left:" + offset.left + "px;top:" + offset.top + "px;";
  25253. }
  25254. function setPosByCxtMenu (menu) {
  25255. if (!menu.tagName) {
  25256. menu = menu.getDom ();
  25257. }
  25258. offset.left = parseInt (menu.style.left);
  25259. offset.top = parseInt (menu.style.top);
  25260. offset.top -= el.offsetHeight + 15;
  25261. setPos (offset);
  25262. }
  25263. me.eventType = e.type;
  25264. el.style.cssText = "display:block;left:-9999px";
  25265. if (e.type == "contextmenu" && hasContextmenu) {
  25266. var menu = domUtils.getElementsByTagName (fixedlayer , "div" , "edui-contextmenu")[0];
  25267. if (menu) {
  25268. setPosByCxtMenu (menu)
  25269. } else {
  25270. me.editor.addListener ("aftershowcontextmenu" , function (type , menu) {
  25271. setPosByCxtMenu (menu);
  25272. });
  25273. }
  25274. } else {
  25275. offset = uiUtils.getViewportOffsetByEvent (e);
  25276. offset.top -= el.offsetHeight + me.SPACE;
  25277. offset.left += me.SPACE + 20;
  25278. setPos (offset);
  25279. // me.setOpacity (el , 0.2);
  25280. me.setOpacity (el , 1);
  25281. }
  25282. me.isHidden = false;
  25283. me.left = e.screenX + el.offsetWidth / 2 - me.SPACE;
  25284. me.top = e.screenY - (el.offsetHeight / 2) - me.SPACE;
  25285. if (me.editor) {
  25286. el.style.zIndex = me.editor.container.style.zIndex * 1 + 10;
  25287. fixedlayer.style.zIndex = el.style.zIndex - 1;
  25288. }
  25289. } ,
  25290. hide : function () {
  25291. if (this.getDom ()) {
  25292. this.getDom ().style.display = "none";
  25293. }
  25294. this.isHidden = true;
  25295. } ,
  25296. postRender : function () {
  25297. if (utils.isArray (this.items)) {
  25298. for (var i = 0, item ; item = this.items[i++] ;) {
  25299. // item.postRender ();
  25300. "function" == typeof item.renderHtml && item.postRender()
  25301. }
  25302. }
  25303. } ,
  25304. getHtmlTpl : function () {
  25305. var buff;
  25306. if (utils.isArray (this.items)) {
  25307. buff = [];
  25308. for (var i = 0 ; i < this.items.length ; i++) {
  25309. if ("function" == typeof this.items[i].renderHtml)
  25310. buff[i] = this.items[i].renderHtml ();
  25311. else if ("|" == this.items[i] || "<br>" == this.items[i])
  25312. buff[i] = "<br/>";
  25313. // buff[i] = this.items[i].renderHtml ();
  25314. }
  25315. buff = buff.join ("");
  25316. } else {
  25317. buff = this.items;
  25318. }
  25319. return '<div id="##" class="%% edui-toolbar" data-src="shortcutmenu" onmousedown="return false;" onselectstart="return false;" >' +
  25320. buff +
  25321. '</div>';
  25322. }
  25323. };
  25324. utils.inherits (ShortCutMenu , UIBase);
  25325. function hideAllMenu (e) {
  25326. var tgt = e.target || e.srcElement,
  25327. cur = domUtils.findParent (tgt , function (node) {
  25328. return domUtils.hasClass (node , "edui-shortcutmenu") || domUtils.hasClass (node , "edui-popup");
  25329. } , true);
  25330. if (!cur) {
  25331. for (var i = 0, menu ; menu = allMenus[i++] ;) {
  25332. menu.hide ()
  25333. }
  25334. }
  25335. }
  25336. domUtils.on (document , 'mousedown' , function (e) {
  25337. hideAllMenu (e);
  25338. });
  25339. domUtils.on (window , 'scroll' , function (e) {
  25340. hideAllMenu (e);
  25341. });
  25342. }) ();
  25343. // ui/breakline.js
  25344. (function (){
  25345. var utils = baidu.editor.utils,
  25346. UIBase = baidu.editor.ui.UIBase,
  25347. Breakline = baidu.editor.ui.Breakline = function (options){
  25348. this.initOptions(options);
  25349. this.initSeparator();
  25350. };
  25351. Breakline.prototype = {
  25352. uiName: 'Breakline',
  25353. initSeparator: function (){
  25354. this.initUIBase();
  25355. },
  25356. getHtmlTpl: function (){
  25357. return '<br/>';
  25358. }
  25359. };
  25360. utils.inherits(Breakline, UIBase);
  25361. })();
  25362. // ui/message.js
  25363. ///import core
  25364. ///import uicore
  25365. (function () {
  25366. var utils = baidu.editor.utils,
  25367. domUtils = baidu.editor.dom.domUtils,
  25368. UIBase = baidu.editor.ui.UIBase,
  25369. Message = baidu.editor.ui.Message = function (options){
  25370. this.initOptions(options);
  25371. this.initMessage();
  25372. };
  25373. Message.prototype = {
  25374. initMessage: function (){
  25375. this.initUIBase();
  25376. },
  25377. getHtmlTpl: function (){
  25378. return '<div id="##" class="edui-message %%">' +
  25379. ' <div id="##_closer" class="edui-message-closer">×</div>' +
  25380. ' <div id="##_body" class="edui-message-body edui-message-type-info">' +
  25381. ' <iframe style="position:absolute;z-index:-1;left:0;top:0;background-color: transparent;" frameborder="0" width="100%" height="100%" src="about:blank"></iframe>' +
  25382. ' <div class="edui-shadow"></div>' +
  25383. ' <div id="##_content" class="edui-message-content">' +
  25384. ' </div>' +
  25385. ' </div>' +
  25386. '</div>';
  25387. },
  25388. reset: function(opt){
  25389. var me = this;
  25390. if (!opt.keepshow) {
  25391. clearTimeout(this.timer);
  25392. me.timer = setTimeout(function(){
  25393. me.hide();
  25394. }, opt.timeout || 4000);
  25395. }
  25396. opt.content !== undefined && me.setContent(opt.content);
  25397. opt.type !== undefined && me.setType(opt.type);
  25398. me.show();
  25399. },
  25400. postRender: function(){
  25401. var me = this,
  25402. closer = this.getDom('closer');
  25403. closer && domUtils.on(closer, 'click', function(){
  25404. me.hide();
  25405. });
  25406. },
  25407. setContent: function(content){
  25408. this.getDom('content').innerHTML = content;
  25409. },
  25410. setType: function(type){
  25411. type = type || 'info';
  25412. var body = this.getDom('body');
  25413. body.className = body.className.replace(/edui-message-type-[\w-]+/, 'edui-message-type-' + type);
  25414. },
  25415. getContent: function(){
  25416. return this.getDom('content').innerHTML;
  25417. },
  25418. getType: function(){
  25419. var arr = this.getDom('body').match(/edui-message-type-([\w-]+)/);
  25420. return arr ? arr[1]:'';
  25421. },
  25422. show: function (){
  25423. this.getDom().style.display = 'block';
  25424. },
  25425. hide: function (){
  25426. var dom = this.getDom();
  25427. if (dom) {
  25428. dom.style.display = 'none';
  25429. dom.parentNode && dom.parentNode.removeChild(dom);
  25430. }
  25431. }
  25432. };
  25433. utils.inherits(Message, UIBase);
  25434. })();
  25435. // adapter/editorui.js
  25436. //ui跟编辑器的适配層
  25437. //那个按钮弹出是dialog,是下拉筐等都是在这个js中配置
  25438. //自己写的ui也要在这里配置,放到baidu.editor.ui下边,当编辑器实例化的时候会根据ueditor.config中的toolbars找到相应的进行实例化
  25439. (function () {
  25440. var utils = baidu.editor.utils;
  25441. var editorui = baidu.editor.ui;
  25442. var _Dialog = editorui.Dialog;
  25443. editorui.buttons = {};
  25444. editorui.Dialog = function (options) {
  25445. var dialog = new _Dialog(options);
  25446. dialog.addListener('hide', function () {
  25447. if (dialog.editor) {
  25448. var editor = dialog.editor;
  25449. try {
  25450. if (browser.gecko) {
  25451. var y = editor.window.scrollY,
  25452. x = editor.window.scrollX;
  25453. editor.body.focus();
  25454. editor.window.scrollTo(x, y);
  25455. } else {
  25456. editor.focus();
  25457. }
  25458. } catch (ex) {
  25459. }
  25460. }
  25461. });
  25462. return dialog;
  25463. };
  25464. var iframeUrlMap = {
  25465. 'anchor':'~/dialogs/anchor/anchor.html',
  25466. 'insertimage':'~/dialogs/image/image.html',
  25467. 'link':'~/dialogs/link/link.html',
  25468. 'spechars':'~/dialogs/spechars/spechars.html',
  25469. 'searchreplace':'~/dialogs/searchreplace/searchreplace.html',
  25470. 'map':'~/dialogs/map/map.html',
  25471. 'gmap':'~/dialogs/gmap/gmap.html',
  25472. 'insertvideo':'~/dialogs/video/video.html',
  25473. 'help':'~/dialogs/help/help.html',
  25474. 'preview':'~/dialogs/preview/preview.html',
  25475. 'emotion':'~/dialogs/emotion/emotion.html',
  25476. 'wordimage':'~/dialogs/wordimage/wordimage.html',
  25477. 'attachment':'~/dialogs/attachment/attachment.html',
  25478. 'insertframe':'~/dialogs/insertframe/insertframe.html',
  25479. 'edittip':'~/dialogs/table/edittip.html',
  25480. 'edittable':'~/dialogs/table/edittable.html',
  25481. 'edittd':'~/dialogs/table/edittd.html',
  25482. 'webapp':'~/dialogs/webapp/webapp.html',
  25483. 'snapscreen':'~/dialogs/snapscreen/snapscreen.html',
  25484. 'scrawl':'~/dialogs/scrawl/scrawl.html',
  25485. 'music':'~/dialogs/music/music.html',
  25486. 'template':'~/dialogs/template/template.html',
  25487. 'background':'~/dialogs/background/background.html',
  25488. 'charts': '~/dialogs/charts/charts.html'
  25489. };
  25490. //为工具栏添加按钮,以下都是统一的按钮触发命令,所以写在一起
  25491. var btnCmds = ['undo', 'redo', 'formatmatch',
  25492. 'bold', 'italic', 'underline', 'fontborder', 'touppercase', 'tolowercase',
  25493. 'strikethrough', 'subscript', 'superscript', 'source', 'indent', 'outdent',
  25494. 'blockquote', 'pasteplain', 'pagebreak',
  25495. 'selectall', 'print','horizontal', 'removeformat', 'time', 'date', 'unlink',
  25496. 'insertparagraphbeforetable', 'insertrow', 'insertcol', 'mergeright', 'mergedown', 'deleterow',
  25497. 'deletecol', 'splittorows', 'splittocols', 'splittocells', 'mergecells', 'deletetable', 'drafts'];
  25498. for (var i = 0, ci; ci = btnCmds[i++];) {
  25499. ci = ci.toLowerCase();
  25500. editorui[ci] = function (cmd) {
  25501. return function (editor) {
  25502. var ui = new editorui.Button({
  25503. className:'edui-for-' + cmd,
  25504. title:editor.options.labelMap[cmd] || editor.getLang("labelMap." + cmd) || '',
  25505. onclick:function () {
  25506. editor.execCommand(cmd);
  25507. },
  25508. theme:editor.options.theme,
  25509. showText:false
  25510. });
  25511. editorui.buttons[cmd] = ui;
  25512. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25513. var state = editor.queryCommandState(cmd);
  25514. if (state == -1) {
  25515. ui.setDisabled(true);
  25516. ui.setChecked(false);
  25517. } else {
  25518. if (!uiReady) {
  25519. ui.setDisabled(false);
  25520. ui.setChecked(state);
  25521. }
  25522. }
  25523. });
  25524. return ui;
  25525. };
  25526. }(ci);
  25527. }
  25528. //清除文档
  25529. editorui.cleardoc = function (editor) {
  25530. var ui = new editorui.Button({
  25531. className:'edui-for-cleardoc',
  25532. title:editor.options.labelMap.cleardoc || editor.getLang("labelMap.cleardoc") || '',
  25533. theme:editor.options.theme,
  25534. onclick:function () {
  25535. if (confirm(editor.getLang("confirmClear"))) {
  25536. editor.execCommand('cleardoc');
  25537. }
  25538. }
  25539. });
  25540. editorui.buttons["cleardoc"] = ui;
  25541. editor.addListener('selectionchange', function () {
  25542. ui.setDisabled(editor.queryCommandState('cleardoc') == -1);
  25543. });
  25544. return ui;
  25545. };
  25546. //排版,图片排版,文字方向
  25547. var typeset = {
  25548. 'justify':['left', 'right', 'center', 'justify'],
  25549. 'imagefloat':['none', 'left', 'center', 'right'],
  25550. 'directionality':['ltr', 'rtl']
  25551. };
  25552. for (var p in typeset) {
  25553. (function (cmd, val) {
  25554. for (var i = 0, ci; ci = val[i++];) {
  25555. (function (cmd2) {
  25556. editorui[cmd.replace('float', '') + cmd2] = function (editor) {
  25557. var ui = new editorui.Button({
  25558. className:'edui-for-' + cmd.replace('float', '') + cmd2,
  25559. title:editor.options.labelMap[cmd.replace('float', '') + cmd2] || editor.getLang("labelMap." + cmd.replace('float', '') + cmd2) || '',
  25560. theme:editor.options.theme,
  25561. onclick:function () {
  25562. editor.execCommand(cmd, cmd2);
  25563. }
  25564. });
  25565. editorui.buttons[cmd] = ui;
  25566. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25567. ui.setDisabled(editor.queryCommandState(cmd) == -1);
  25568. ui.setChecked(editor.queryCommandValue(cmd) == cmd2 && !uiReady);
  25569. });
  25570. return ui;
  25571. };
  25572. })(ci)
  25573. }
  25574. })(p, typeset[p])
  25575. }
  25576. //字体颜色和背景颜色
  25577. for (var i = 0, ci; ci = ['backcolor', 'forecolor'][i++];) {
  25578. editorui[ci] = function (cmd) {
  25579. return function (editor) {
  25580. var ui = new editorui.ColorButton({
  25581. className:'edui-for-' + cmd,
  25582. color:'default',
  25583. title:editor.options.labelMap[cmd] || editor.getLang("labelMap." + cmd) || '',
  25584. editor:editor,
  25585. onpickcolor:function (t, color) {
  25586. editor.execCommand(cmd, color);
  25587. },
  25588. onpicknocolor:function () {
  25589. editor.execCommand(cmd, 'default');
  25590. this.setColor('transparent');
  25591. this.color = 'default';
  25592. },
  25593. onbuttonclick:function () {
  25594. editor.execCommand(cmd, this.color);
  25595. }
  25596. });
  25597. editorui.buttons[cmd] = ui;
  25598. editor.addListener('selectionchange', function () {
  25599. ui.setDisabled(editor.queryCommandState(cmd) == -1);
  25600. });
  25601. return ui;
  25602. };
  25603. }(ci);
  25604. }
  25605. var dialogBtns = {
  25606. noOk:['searchreplace', 'help', 'spechars', 'webapp','preview'],
  25607. ok:['attachment', 'anchor', 'link', 'insertimage', 'map', 'gmap', 'insertframe', 'wordimage',
  25608. 'insertvideo', 'insertframe', 'edittip', 'edittable', 'edittd', 'scrawl', 'template', 'music', 'background', 'charts']
  25609. };
  25610. for (var p in dialogBtns) {
  25611. (function (type, vals) {
  25612. for (var i = 0, ci; ci = vals[i++];) {
  25613. //todo opera下存在问题
  25614. if (browser.opera && ci === "searchreplace") {
  25615. continue;
  25616. }
  25617. (function (cmd) {
  25618. editorui[cmd] = function (editor, iframeUrl, title) {
  25619. iframeUrl = iframeUrl || (editor.options.iframeUrlMap || {})[cmd] || iframeUrlMap[cmd];
  25620. title = editor.options.labelMap[cmd] || editor.getLang("labelMap." + cmd) || '';
  25621. var dialog;
  25622. //没有iframeUrl不创建dialog
  25623. if (iframeUrl) {
  25624. dialog = new editorui.Dialog(utils.extend({
  25625. iframeUrl:editor.ui.mapUrl(iframeUrl),
  25626. editor:editor,
  25627. className:'edui-for-' + cmd,
  25628. title:title,
  25629. holdScroll: cmd === 'insertimage',
  25630. fullscreen: /charts|preview/.test(cmd),
  25631. closeDialog:editor.getLang("closeDialog")
  25632. }, type == 'ok' ? {
  25633. buttons:[
  25634. {
  25635. className:'edui-okbutton',
  25636. label:editor.getLang("ok"),
  25637. editor:editor,
  25638. onclick:function () {
  25639. dialog.close(true);
  25640. }
  25641. },
  25642. {
  25643. className:'edui-cancelbutton',
  25644. label:editor.getLang("cancel"),
  25645. editor:editor,
  25646. onclick:function () {
  25647. dialog.close(false);
  25648. }
  25649. }
  25650. ]
  25651. } : {}));
  25652. editor.ui._dialogs[cmd + "Dialog"] = dialog;
  25653. }
  25654. var ui = new editorui.Button({
  25655. className:'edui-for-' + cmd,
  25656. title:title,
  25657. onclick:function () {
  25658. if (dialog) {
  25659. switch (cmd) {
  25660. case "wordimage":
  25661. var images = editor.execCommand("wordimage");
  25662. if (images && images.length) {
  25663. dialog.render();
  25664. dialog.open();
  25665. }
  25666. break;
  25667. case "scrawl":
  25668. if (editor.queryCommandState("scrawl") != -1) {
  25669. dialog.render();
  25670. dialog.open();
  25671. }
  25672. break;
  25673. default:
  25674. dialog.render();
  25675. dialog.open();
  25676. }
  25677. }
  25678. },
  25679. theme:editor.options.theme,
  25680. disabled:(cmd == 'scrawl' && editor.queryCommandState("scrawl") == -1) || ( cmd == 'charts' )
  25681. });
  25682. editorui.buttons[cmd] = ui;
  25683. editor.addListener('selectionchange', function () {
  25684. //只存在于右键菜单而无工具栏按钮的ui不需要检测状态
  25685. var unNeedCheckState = {'edittable':1};
  25686. if (cmd in unNeedCheckState)return;
  25687. var state = editor.queryCommandState(cmd);
  25688. if (ui.getDom()) {
  25689. ui.setDisabled(state == -1);
  25690. ui.setChecked(state);
  25691. }
  25692. });
  25693. return ui;
  25694. };
  25695. })(ci.toLowerCase())
  25696. }
  25697. })(p, dialogBtns[p]);
  25698. }
  25699. editorui.snapscreen = function (editor, iframeUrl, title) {
  25700. title = editor.options.labelMap['snapscreen'] || editor.getLang("labelMap.snapscreen") || '';
  25701. var ui = new editorui.Button({
  25702. className:'edui-for-snapscreen',
  25703. title:title,
  25704. onclick:function () {
  25705. editor.execCommand("snapscreen");
  25706. },
  25707. theme:editor.options.theme
  25708. });
  25709. editorui.buttons['snapscreen'] = ui;
  25710. iframeUrl = iframeUrl || (editor.options.iframeUrlMap || {})["snapscreen"] || iframeUrlMap["snapscreen"];
  25711. if (iframeUrl) {
  25712. var dialog = new editorui.Dialog({
  25713. iframeUrl:editor.ui.mapUrl(iframeUrl),
  25714. editor:editor,
  25715. className:'edui-for-snapscreen',
  25716. title:title,
  25717. buttons:[
  25718. {
  25719. className:'edui-okbutton',
  25720. label:editor.getLang("ok"),
  25721. editor:editor,
  25722. onclick:function () {
  25723. dialog.close(true);
  25724. }
  25725. },
  25726. {
  25727. className:'edui-cancelbutton',
  25728. label:editor.getLang("cancel"),
  25729. editor:editor,
  25730. onclick:function () {
  25731. dialog.close(false);
  25732. }
  25733. }
  25734. ]
  25735. });
  25736. dialog.render();
  25737. editor.ui._dialogs["snapscreenDialog"] = dialog;
  25738. }
  25739. editor.addListener('selectionchange', function () {
  25740. ui.setDisabled(editor.queryCommandState('snapscreen') == -1);
  25741. });
  25742. return ui;
  25743. };
  25744. editorui.insertcode = function (editor, list, title) {
  25745. list = editor.options['insertcode'] || [];
  25746. title = editor.options.labelMap['insertcode'] || editor.getLang("labelMap.insertcode") || '';
  25747. // if (!list.length) return;
  25748. var items = [];
  25749. utils.each(list,function(key,val){
  25750. items.push({
  25751. label:key,
  25752. value:val,
  25753. theme:editor.options.theme,
  25754. renderLabelHtml:function () {
  25755. return '<div class="edui-label %%-label" >' + (this.label || '') + '</div>';
  25756. }
  25757. });
  25758. });
  25759. var ui = new editorui.Combox({
  25760. editor:editor,
  25761. items:items,
  25762. onselect:function (t, index) {
  25763. editor.execCommand('insertcode', this.items[index].value);
  25764. },
  25765. onbuttonclick:function () {
  25766. this.showPopup();
  25767. },
  25768. title:title,
  25769. initValue:title,
  25770. className:'edui-for-insertcode',
  25771. indexByValue:function (value) {
  25772. if (value) {
  25773. for (var i = 0, ci; ci = this.items[i]; i++) {
  25774. if (ci.value.indexOf(value) != -1)
  25775. return i;
  25776. }
  25777. }
  25778. return -1;
  25779. }
  25780. });
  25781. editorui.buttons['insertcode'] = ui;
  25782. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25783. if (!uiReady) {
  25784. var state = editor.queryCommandState('insertcode');
  25785. if (state == -1) {
  25786. ui.setDisabled(true);
  25787. } else {
  25788. ui.setDisabled(false);
  25789. var value = editor.queryCommandValue('insertcode');
  25790. if(!value){
  25791. ui.setValue(title);
  25792. return;
  25793. }
  25794. //trace:1871 ie下从源码模式切换回来时,字体会带单引号,而且会有逗号
  25795. value && (value = value.replace(/['"]/g, '').split(',')[0]);
  25796. ui.setValue(value);
  25797. }
  25798. }
  25799. });
  25800. return ui;
  25801. };
  25802. editorui.fontfamily = function (editor, list, title) {
  25803. list = editor.options['fontfamily'] || [];
  25804. title = editor.options.labelMap['fontfamily'] || editor.getLang("labelMap.fontfamily") || '';
  25805. if (!list.length) return;
  25806. for (var i = 0, ci, items = []; ci = list[i]; i++) {
  25807. var langLabel = editor.getLang('fontfamily')[ci.name] || "";
  25808. (function (key, val) {
  25809. items.push({
  25810. label:key,
  25811. value:val,
  25812. theme:editor.options.theme,
  25813. renderLabelHtml:function () {
  25814. return '<div class="edui-label %%-label" style="font-family:' +
  25815. utils.unhtml(this.value) + '">' + (this.label || '') + '</div>';
  25816. }
  25817. });
  25818. })(ci.label || langLabel, ci.val)
  25819. }
  25820. var ui = new editorui.Combox({
  25821. editor:editor,
  25822. items:items,
  25823. onselect:function (t, index) {
  25824. editor.execCommand('FontFamily', this.items[index].value);
  25825. },
  25826. onbuttonclick:function () {
  25827. this.showPopup();
  25828. },
  25829. title:title,
  25830. initValue:title,
  25831. className:'edui-for-fontfamily',
  25832. indexByValue:function (value) {
  25833. if (value) {
  25834. for (var i = 0, ci; ci = this.items[i]; i++) {
  25835. if (ci.value.indexOf(value) != -1)
  25836. return i;
  25837. }
  25838. }
  25839. return -1;
  25840. }
  25841. });
  25842. editorui.buttons['fontfamily'] = ui;
  25843. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25844. if (!uiReady) {
  25845. var state = editor.queryCommandState('FontFamily');
  25846. if (state == -1) {
  25847. ui.setDisabled(true);
  25848. } else {
  25849. ui.setDisabled(false);
  25850. var value = editor.queryCommandValue('FontFamily');
  25851. //trace:1871 ie下从源码模式切换回来时,字体会带单引号,而且会有逗号
  25852. value && (value = value.replace(/['"]/g, '').split(',')[0]);
  25853. ui.setValue(value);
  25854. }
  25855. }
  25856. });
  25857. return ui;
  25858. };
  25859. editorui.fontsize = function (editor, list, title) {
  25860. title = editor.options.labelMap['fontsize'] || editor.getLang("labelMap.fontsize") || '';
  25861. list = list || editor.options['fontsize'] || [];
  25862. if (!list.length) return;
  25863. var items = [];
  25864. for (var i = 0; i < list.length; i++) {
  25865. var size = list[i] + 'px';
  25866. items.push({
  25867. label:size,
  25868. value:size,
  25869. theme:editor.options.theme,
  25870. renderLabelHtml:function () {
  25871. return '<div class="edui-label %%-label" style="line-height:1;font-size:' +
  25872. this.value + '">' + (this.label || '') + '</div>';
  25873. }
  25874. });
  25875. }
  25876. var ui = new editorui.Combox({
  25877. editor:editor,
  25878. items:items,
  25879. title:title,
  25880. initValue:title,
  25881. onselect:function (t, index) {
  25882. editor.execCommand('FontSize', this.items[index].value);
  25883. },
  25884. onbuttonclick:function () {
  25885. this.showPopup();
  25886. },
  25887. className:'edui-for-fontsize'
  25888. });
  25889. editorui.buttons['fontsize'] = ui;
  25890. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25891. if (!uiReady) {
  25892. var state = editor.queryCommandState('FontSize');
  25893. if (state == -1) {
  25894. ui.setDisabled(true);
  25895. } else {
  25896. ui.setDisabled(false);
  25897. ui.setValue(editor.queryCommandValue('FontSize'));
  25898. }
  25899. }
  25900. });
  25901. return ui;
  25902. };
  25903. editorui.paragraph = function (editor, list, title) {
  25904. title = editor.options.labelMap['paragraph'] || editor.getLang("labelMap.paragraph") || '';
  25905. list = editor.options['paragraph'] || [];
  25906. if (utils.isEmptyObject(list)) return;
  25907. var items = [];
  25908. for (var i in list) {
  25909. items.push({
  25910. value:i,
  25911. label:list[i] || editor.getLang("paragraph")[i],
  25912. theme:editor.options.theme,
  25913. renderLabelHtml:function () {
  25914. return '<div class="edui-label %%-label"><span class="edui-for-' + this.value + '">' + (this.label || '') + '</span></div>';
  25915. }
  25916. })
  25917. }
  25918. var ui = new editorui.Combox({
  25919. editor:editor,
  25920. items:items,
  25921. title:title,
  25922. initValue:title,
  25923. className:'edui-for-paragraph',
  25924. onselect:function (t, index) {
  25925. editor.execCommand('Paragraph', this.items[index].value);
  25926. },
  25927. onbuttonclick:function () {
  25928. this.showPopup();
  25929. }
  25930. });
  25931. editorui.buttons['paragraph'] = ui;
  25932. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25933. if (!uiReady) {
  25934. var state = editor.queryCommandState('Paragraph');
  25935. if (state == -1) {
  25936. ui.setDisabled(true);
  25937. } else {
  25938. ui.setDisabled(false);
  25939. var value = editor.queryCommandValue('Paragraph');
  25940. var index = ui.indexByValue(value);
  25941. if (index != -1) {
  25942. ui.setValue(value);
  25943. } else {
  25944. ui.setValue(ui.initValue);
  25945. }
  25946. }
  25947. }
  25948. });
  25949. return ui;
  25950. };
  25951. //自定义标题
  25952. editorui.customstyle = function (editor) {
  25953. var list = editor.options['customstyle'] || [],
  25954. title = editor.options.labelMap['customstyle'] || editor.getLang("labelMap.customstyle") || '';
  25955. if (!list.length)return;
  25956. var langCs = editor.getLang('customstyle');
  25957. for (var i = 0, items = [], t; t = list[i++];) {
  25958. (function (t) {
  25959. var ck = {};
  25960. ck.label = t.label ? t.label : langCs[t.name];
  25961. ck.style = t.style;
  25962. ck.className = t.className;
  25963. ck.tag = t.tag;
  25964. items.push({
  25965. label:ck.label,
  25966. value:ck,
  25967. theme:editor.options.theme,
  25968. renderLabelHtml:function () {
  25969. return '<div class="edui-label %%-label">' + '<' + ck.tag + ' ' + (ck.className ? ' class="' + ck.className + '"' : "")
  25970. + (ck.style ? ' style="' + ck.style + '"' : "") + '>' + ck.label + "<\/" + ck.tag + ">"
  25971. + '</div>';
  25972. }
  25973. });
  25974. })(t);
  25975. }
  25976. var ui = new editorui.Combox({
  25977. editor:editor,
  25978. items:items,
  25979. title:title,
  25980. initValue:title,
  25981. className:'edui-for-customstyle',
  25982. onselect:function (t, index) {
  25983. editor.execCommand('customstyle', this.items[index].value);
  25984. },
  25985. onbuttonclick:function () {
  25986. this.showPopup();
  25987. },
  25988. indexByValue:function (value) {
  25989. for (var i = 0, ti; ti = this.items[i++];) {
  25990. if (ti.label == value) {
  25991. return i - 1
  25992. }
  25993. }
  25994. return -1;
  25995. }
  25996. });
  25997. editorui.buttons['customstyle'] = ui;
  25998. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  25999. if (!uiReady) {
  26000. var state = editor.queryCommandState('customstyle');
  26001. if (state == -1) {
  26002. ui.setDisabled(true);
  26003. } else {
  26004. ui.setDisabled(false);
  26005. var value = editor.queryCommandValue('customstyle');
  26006. var index = ui.indexByValue(value);
  26007. if (index != -1) {
  26008. ui.setValue(value);
  26009. } else {
  26010. ui.setValue(ui.initValue);
  26011. }
  26012. }
  26013. }
  26014. });
  26015. return ui;
  26016. };
  26017. editorui.inserttable = function (editor, iframeUrl, title) {
  26018. title = editor.options.labelMap['inserttable'] || editor.getLang("labelMap.inserttable") || '';
  26019. var ui = new editorui.TableButton({
  26020. editor:editor,
  26021. title:title,
  26022. className:'edui-for-inserttable',
  26023. onpicktable:function (t, numCols, numRows) {
  26024. editor.execCommand('InsertTable', {numRows:numRows, numCols:numCols, border:1});
  26025. },
  26026. onbuttonclick:function () {
  26027. this.showPopup();
  26028. }
  26029. });
  26030. editorui.buttons['inserttable'] = ui;
  26031. editor.addListener('selectionchange', function () {
  26032. ui.setDisabled(editor.queryCommandState('inserttable') == -1);
  26033. });
  26034. return ui;
  26035. };
  26036. editorui.lineheight = function (editor) {
  26037. var val = editor.options.lineheight || [];
  26038. if (!val.length)return;
  26039. for (var i = 0, ci, items = []; ci = val[i++];) {
  26040. items.push({
  26041. //todo:写死了
  26042. label:ci,
  26043. value:ci,
  26044. theme:editor.options.theme,
  26045. onclick:function () {
  26046. editor.execCommand("lineheight", this.value);
  26047. }
  26048. })
  26049. }
  26050. var ui = new editorui.MenuButton({
  26051. editor:editor,
  26052. className:'edui-for-lineheight',
  26053. title:editor.options.labelMap['lineheight'] || editor.getLang("labelMap.lineheight") || '',
  26054. items:items,
  26055. onbuttonclick:function () {
  26056. var value = editor.queryCommandValue('LineHeight') || this.value;
  26057. editor.execCommand("LineHeight", value);
  26058. }
  26059. });
  26060. editorui.buttons['lineheight'] = ui;
  26061. editor.addListener('selectionchange', function () {
  26062. var state = editor.queryCommandState('LineHeight');
  26063. if (state == -1) {
  26064. ui.setDisabled(true);
  26065. } else {
  26066. ui.setDisabled(false);
  26067. var value = editor.queryCommandValue('LineHeight');
  26068. value && ui.setValue((value + '').replace(/cm/, ''));
  26069. ui.setChecked(state)
  26070. }
  26071. });
  26072. return ui;
  26073. };
  26074. var rowspacings = ['top', 'bottom'];
  26075. for (var r = 0, ri; ri = rowspacings[r++];) {
  26076. (function (cmd) {
  26077. editorui['rowspacing' + cmd] = function (editor) {
  26078. var val = editor.options['rowspacing' + cmd] || [];
  26079. if (!val.length) return null;
  26080. for (var i = 0, ci, items = []; ci = val[i++];) {
  26081. items.push({
  26082. label:ci,
  26083. value:ci,
  26084. theme:editor.options.theme,
  26085. onclick:function () {
  26086. editor.execCommand("rowspacing", this.value, cmd);
  26087. }
  26088. })
  26089. }
  26090. var ui = new editorui.MenuButton({
  26091. editor:editor,
  26092. className:'edui-for-rowspacing' + cmd,
  26093. title:editor.options.labelMap['rowspacing' + cmd] || editor.getLang("labelMap.rowspacing" + cmd) || '',
  26094. items:items,
  26095. onbuttonclick:function () {
  26096. var value = editor.queryCommandValue('rowspacing', cmd) || this.value;
  26097. editor.execCommand("rowspacing", value, cmd);
  26098. }
  26099. });
  26100. editorui.buttons[cmd] = ui;
  26101. editor.addListener('selectionchange', function () {
  26102. var state = editor.queryCommandState('rowspacing', cmd);
  26103. if (state == -1) {
  26104. ui.setDisabled(true);
  26105. } else {
  26106. ui.setDisabled(false);
  26107. var value = editor.queryCommandValue('rowspacing', cmd);
  26108. value && ui.setValue((value + '').replace(/%/, ''));
  26109. ui.setChecked(state)
  26110. }
  26111. });
  26112. return ui;
  26113. }
  26114. })(ri)
  26115. }
  26116. //有序,无序列表
  26117. var lists = ['insertorderedlist', 'insertunorderedlist'];
  26118. for (var l = 0, cl; cl = lists[l++];) {
  26119. (function (cmd) {
  26120. editorui[cmd] = function (editor) {
  26121. var vals = editor.options[cmd],
  26122. _onMenuClick = function () {
  26123. editor.execCommand(cmd, this.value);
  26124. }, items = [];
  26125. for (var i in vals) {
  26126. items.push({
  26127. label:vals[i] || editor.getLang()[cmd][i] || "",
  26128. value:i,
  26129. theme:editor.options.theme,
  26130. onclick:_onMenuClick
  26131. })
  26132. }
  26133. var ui = new editorui.MenuButton({
  26134. editor:editor,
  26135. className:'edui-for-' + cmd,
  26136. title:editor.getLang("labelMap." + cmd) || '',
  26137. 'items':items,
  26138. onbuttonclick:function () {
  26139. var value = editor.queryCommandValue(cmd) || this.value;
  26140. editor.execCommand(cmd, value);
  26141. }
  26142. });
  26143. editorui.buttons[cmd] = ui;
  26144. editor.addListener('selectionchange', function () {
  26145. var state = editor.queryCommandState(cmd);
  26146. if (state == -1) {
  26147. ui.setDisabled(true);
  26148. } else {
  26149. ui.setDisabled(false);
  26150. var value = editor.queryCommandValue(cmd);
  26151. ui.setValue(value);
  26152. ui.setChecked(state)
  26153. }
  26154. });
  26155. return ui;
  26156. };
  26157. })(cl)
  26158. }
  26159. editorui.fullscreen = function (editor, title) {
  26160. title = editor.options.labelMap['fullscreen'] || editor.getLang("labelMap.fullscreen") || '';
  26161. var ui = new editorui.Button({
  26162. className:'edui-for-fullscreen',
  26163. title:title,
  26164. theme:editor.options.theme,
  26165. onclick:function () {
  26166. if (editor.ui) {
  26167. editor.ui.setFullScreen(!editor.ui.isFullScreen());
  26168. }
  26169. this.setChecked(editor.ui.isFullScreen());
  26170. }
  26171. });
  26172. editorui.buttons['fullscreen'] = ui;
  26173. editor.addListener('selectionchange', function () {
  26174. var state = editor.queryCommandState('fullscreen');
  26175. ui.setDisabled(state == -1);
  26176. ui.setChecked(editor.ui.isFullScreen());
  26177. });
  26178. return ui;
  26179. };
  26180. // 表情
  26181. editorui["emotion"] = function (editor, iframeUrl) {
  26182. var cmd = "emotion";
  26183. var ui = new editorui.MultiMenuPop({
  26184. title:editor.options.labelMap[cmd] || editor.getLang("labelMap." + cmd + "") || '',
  26185. editor:editor,
  26186. className:'edui-for-' + cmd,
  26187. iframeUrl:editor.ui.mapUrl(iframeUrl || (editor.options.iframeUrlMap || {})[cmd] || iframeUrlMap[cmd])
  26188. });
  26189. editorui.buttons[cmd] = ui;
  26190. editor.addListener('selectionchange', function () {
  26191. ui.setDisabled(editor.queryCommandState(cmd) == -1)
  26192. });
  26193. return ui;
  26194. };
  26195. editorui.autotypeset = function (editor) {
  26196. var ui = new editorui.AutoTypeSetButton({
  26197. editor:editor,
  26198. title:editor.options.labelMap['autotypeset'] || editor.getLang("labelMap.autotypeset") || '',
  26199. className:'edui-for-autotypeset',
  26200. onbuttonclick:function () {
  26201. editor.execCommand('autotypeset')
  26202. }
  26203. });
  26204. editorui.buttons['autotypeset'] = ui;
  26205. editor.addListener('selectionchange', function () {
  26206. ui.setDisabled(editor.queryCommandState('autotypeset') == -1);
  26207. });
  26208. return ui;
  26209. };
  26210. /* 简单上传插件 */
  26211. editorui["simpleupload"] = function (editor) {
  26212. var name = 'simpleupload',
  26213. ui = new editorui.Button({
  26214. className:'edui-for-' + name,
  26215. title:editor.options.labelMap[name] || editor.getLang("labelMap." + name) || '',
  26216. onclick:function () {},
  26217. theme:editor.options.theme,
  26218. showText:false
  26219. });
  26220. editorui.buttons[name] = ui;
  26221. editor.addListener('ready', function() {
  26222. var b = ui.getDom('body'),
  26223. iconSpan = b.children[0];
  26224. editor.fireEvent('simpleuploadbtnready', iconSpan);
  26225. });
  26226. editor.addListener('selectionchange', function (type, causeByUi, uiReady) {
  26227. var state = editor.queryCommandState(name);
  26228. if (state == -1) {
  26229. ui.setDisabled(true);
  26230. ui.setChecked(false);
  26231. } else {
  26232. if (!uiReady) {
  26233. ui.setDisabled(false);
  26234. ui.setChecked(state);
  26235. }
  26236. }
  26237. });
  26238. return ui;
  26239. };
  26240. })();
  26241. // adapter/editor.js
  26242. ///import core
  26243. ///commands 全屏
  26244. ///commandsName FullScreen
  26245. ///commandsTitle 全屏
  26246. (function () {
  26247. var utils = baidu.editor.utils,
  26248. uiUtils = baidu.editor.ui.uiUtils,
  26249. UIBase = baidu.editor.ui.UIBase,
  26250. domUtils = baidu.editor.dom.domUtils;
  26251. var nodeStack = [];
  26252. function EditorUI(options) {
  26253. this.initOptions(options);
  26254. this.initEditorUI();
  26255. }
  26256. EditorUI.prototype = {
  26257. uiName:'editor',
  26258. initEditorUI:function () {
  26259. this.editor.ui = this;
  26260. this._dialogs = {};
  26261. this.initUIBase();
  26262. this._initToolbars();
  26263. var editor = this.editor,
  26264. me = this;
  26265. editor.addListener('ready', function () {
  26266. //提供getDialog方法
  26267. editor.getDialog = function (name) {
  26268. return editor.ui._dialogs[name + "Dialog"];
  26269. };
  26270. domUtils.on(editor.window, 'scroll', function (evt) {
  26271. baidu.editor.ui.Popup.postHide(evt);
  26272. });
  26273. //提供编辑器实时宽高(全屏时宽高不变化)
  26274. editor.ui._actualFrameWidth = editor.options.initialFrameWidth;
  26275. UE.browser.ie && UE.browser.version === 6 && editor.container.ownerDocument.execCommand("BackgroundImageCache", false, true);
  26276. //display bottom-bar label based on config
  26277. if (editor.options.elementPathEnabled) {
  26278. editor.ui.getDom('elementpath').innerHTML = '<div class="edui-editor-breadcrumb">' + editor.getLang("elementPathTip") + ':</div>';
  26279. }
  26280. if (editor.options.wordCount) {
  26281. function countFn() {
  26282. setCount(editor,me);
  26283. domUtils.un(editor.document, "click", arguments.callee);
  26284. }
  26285. domUtils.on(editor.document, "click", countFn);
  26286. editor.ui.getDom('wordcount').innerHTML = editor.getLang("wordCountTip");
  26287. }
  26288. editor.ui._scale();
  26289. if (editor.options.scaleEnabled) {
  26290. if (editor.autoHeightEnabled) {
  26291. editor.disableAutoHeight();
  26292. }
  26293. me.enableScale();
  26294. } else {
  26295. me.disableScale();
  26296. }
  26297. if (!editor.options.elementPathEnabled && !editor.options.wordCount && !editor.options.scaleEnabled) {
  26298. editor.ui.getDom('elementpath').style.display = "none";
  26299. editor.ui.getDom('wordcount').style.display = "none";
  26300. editor.ui.getDom('scale').style.display = "none";
  26301. }
  26302. if (!editor.selection.isFocus())return;
  26303. editor.fireEvent('selectionchange', false, true);
  26304. });
  26305. editor.addListener('mousedown', function (t, evt) {
  26306. var el = evt.target || evt.srcElement;
  26307. baidu.editor.ui.Popup.postHide(evt, el);
  26308. baidu.editor.ui.ShortCutMenu.postHide(evt);
  26309. });
  26310. editor.addListener("delcells", function () {
  26311. if (UE.ui['edittip']) {
  26312. new UE.ui['edittip'](editor);
  26313. }
  26314. editor.getDialog('edittip').open();
  26315. });
  26316. var pastePop, isPaste = false, timer;
  26317. editor.addListener("afterpaste", function () {
  26318. if(editor.queryCommandState('pasteplain'))
  26319. return;
  26320. if(baidu.editor.ui.PastePicker){
  26321. pastePop = new baidu.editor.ui.Popup({
  26322. content:new baidu.editor.ui.PastePicker({editor:editor}),
  26323. editor:editor,
  26324. className:'edui-wordpastepop'
  26325. });
  26326. pastePop.render();
  26327. }
  26328. isPaste = true;
  26329. });
  26330. editor.addListener("afterinserthtml", function () {
  26331. clearTimeout(timer);
  26332. timer = setTimeout(function () {
  26333. if (pastePop && (isPaste || editor.ui._isTransfer)) {
  26334. if(pastePop.isHidden()){
  26335. var span = domUtils.createElement(editor.document, 'span', {
  26336. 'style':"line-height:0px;",
  26337. 'innerHTML':'\ufeff'
  26338. }),
  26339. range = editor.selection.getRange();
  26340. range.insertNode(span);
  26341. var tmp= getDomNode(span, 'firstChild', 'previousSibling');
  26342. tmp && pastePop.showAnchor(tmp.nodeType == 3 ? tmp.parentNode : tmp);
  26343. domUtils.remove(span);
  26344. }else{
  26345. pastePop.show();
  26346. }
  26347. delete editor.ui._isTransfer;
  26348. isPaste = false;
  26349. }
  26350. }, 200)
  26351. });
  26352. editor.addListener('contextmenu', function (t, evt) {
  26353. baidu.editor.ui.Popup.postHide(evt);
  26354. });
  26355. editor.addListener('keydown', function (t, evt) {
  26356. if (pastePop) pastePop.dispose(evt);
  26357. var keyCode = evt.keyCode || evt.which;
  26358. if(evt.altKey&&keyCode==90){
  26359. UE.ui.buttons['fullscreen'].onclick();
  26360. }
  26361. });
  26362. editor.addListener('wordcount', function (type) {
  26363. setCount(this,me);
  26364. });
  26365. function setCount(editor,ui) {
  26366. editor.setOpt({
  26367. wordCount:true,
  26368. maximumWords:10000,
  26369. wordCountMsg:editor.options.wordCountMsg || editor.getLang("wordCountMsg"),
  26370. wordOverFlowMsg:editor.options.wordOverFlowMsg || editor.getLang("wordOverFlowMsg")
  26371. });
  26372. var opt = editor.options,
  26373. max = opt.maximumWords,
  26374. msg = opt.wordCountMsg ,
  26375. errMsg = opt.wordOverFlowMsg,
  26376. countDom = ui.getDom('wordcount');
  26377. if (!opt.wordCount) {
  26378. return;
  26379. }
  26380. var count = editor.getContentLength(true);
  26381. if (count > max) {
  26382. countDom.innerHTML = errMsg;
  26383. editor.fireEvent("wordcountoverflow");
  26384. } else {
  26385. countDom.innerHTML = msg.replace("{#leave}", max - count).replace("{#count}", count);
  26386. }
  26387. }
  26388. editor.addListener('selectionchange', function () {
  26389. if (editor.options.elementPathEnabled) {
  26390. me[(editor.queryCommandState('elementpath') == -1 ? 'dis' : 'en') + 'ableElementPath']()
  26391. }
  26392. if (editor.options.scaleEnabled) {
  26393. me[(editor.queryCommandState('scale') == -1 ? 'dis' : 'en') + 'ableScale']();
  26394. }
  26395. });
  26396. var popup = new baidu.editor.ui.Popup({
  26397. editor:editor,
  26398. content:'',
  26399. className:'edui-bubble',
  26400. _onEditButtonClick:function () {
  26401. this.hide();
  26402. editor.ui._dialogs.linkDialog.open();
  26403. },
  26404. _onImgEditButtonClick:function (name) {
  26405. this.hide();
  26406. editor.ui._dialogs[name] && editor.ui._dialogs[name].open();
  26407. },
  26408. _onImgSetFloat:function (value) {
  26409. this.hide();
  26410. editor.execCommand("imagefloat", value);
  26411. },
  26412. _setIframeAlign:function (value) {
  26413. var frame = popup.anchorEl;
  26414. var newFrame = frame.cloneNode(true);
  26415. switch (value) {
  26416. case -2:
  26417. newFrame.setAttribute("align", "");
  26418. break;
  26419. case -1:
  26420. newFrame.setAttribute("align", "left");
  26421. break;
  26422. case 1:
  26423. newFrame.setAttribute("align", "right");
  26424. break;
  26425. }
  26426. frame.parentNode.insertBefore(newFrame, frame);
  26427. domUtils.remove(frame);
  26428. popup.anchorEl = newFrame;
  26429. popup.showAnchor(popup.anchorEl);
  26430. },
  26431. _updateIframe:function () {
  26432. var frame = editor._iframe = popup.anchorEl;
  26433. if(domUtils.hasClass(frame, 'ueditor_baidumap')) {
  26434. editor.selection.getRange().selectNode(frame).select();
  26435. editor.ui._dialogs.mapDialog.open();
  26436. popup.hide();
  26437. } else {
  26438. editor.ui._dialogs.insertframeDialog.open();
  26439. popup.hide();
  26440. }
  26441. },
  26442. _onRemoveButtonClick:function (cmdName) {
  26443. editor.execCommand(cmdName);
  26444. this.hide();
  26445. },
  26446. queryAutoHide:function (el) {
  26447. if (el && el.ownerDocument == editor.document) {
  26448. if (el.tagName.toLowerCase() == 'img' || domUtils.findParentByTagName(el, 'a', true)) {
  26449. return el !== popup.anchorEl;
  26450. }
  26451. }
  26452. return baidu.editor.ui.Popup.prototype.queryAutoHide.call(this, el);
  26453. }
  26454. });
  26455. popup.render();
  26456. if (editor.options.imagePopup) {
  26457. editor.addListener('mouseover', function (t, evt) {
  26458. evt = evt || window.event;
  26459. var el = evt.target || evt.srcElement;
  26460. if (editor.ui._dialogs.insertframeDialog && /iframe/ig.test(el.tagName)) {
  26461. var html = popup.formatHtml(
  26462. '<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;' +
  26463. ' <span onclick="$$._updateIframe( this);" class="edui-clickable">' + editor.getLang("modify") + '</span></nobr>');
  26464. if (html) {
  26465. popup.getDom('content').innerHTML = html;
  26466. popup.anchorEl = el;
  26467. popup.showAnchor(popup.anchorEl);
  26468. } else {
  26469. popup.hide();
  26470. }
  26471. }
  26472. });
  26473. editor.addListener('selectionchange', function (t, causeByUi) {
  26474. if (!causeByUi) return;
  26475. var html = '', str = "",
  26476. img = editor.selection.getRange().getClosedNode(),
  26477. dialogs = editor.ui._dialogs;
  26478. if (img && img.tagName == 'IMG') {
  26479. return;
  26480. /* var dialogName = 'insertimageDialog';
  26481. if (img.className.indexOf("edui-faked-video") != -1 || img.className.indexOf("edui-upload-video") != -1) {
  26482. dialogName = "insertvideoDialog"
  26483. }
  26484. if (img.className.indexOf("edui-faked-webapp") != -1) {
  26485. dialogName = "webappDialog"
  26486. }
  26487. if (img.src.indexOf("http://api.map.baidu.com") != -1) {
  26488. dialogName = "mapDialog"
  26489. }
  26490. if (img.className.indexOf("edui-faked-music") != -1) {
  26491. dialogName = "musicDialog"
  26492. }
  26493. if (img.src.indexOf("http://maps.google.com/maps/api/staticmap") != -1) {
  26494. dialogName = "gmapDialog"
  26495. }
  26496. if (img.getAttribute("anchorname")) {
  26497. dialogName = "anchorDialog";
  26498. html = popup.formatHtml(
  26499. '<nobr>' + editor.getLang("property") + ': <span onclick=$$._onImgEditButtonClick("anchorDialog") class="edui-clickable">' + editor.getLang("modify") + '</span>&nbsp;&nbsp;' +
  26500. '<span onclick=$$._onRemoveButtonClick(\'anchor\') class="edui-clickable">' + editor.getLang("delete") + '</span></nobr>');
  26501. }
  26502. if (img.getAttribute("word_img")) {
  26503. //todo 放到dialog去做查询
  26504. editor.word_img = [img.getAttribute("word_img")];
  26505. dialogName = "wordimageDialog"
  26506. }
  26507. if(domUtils.hasClass(img, 'loadingclass') || domUtils.hasClass(img, 'loaderrorclass')) {
  26508. dialogName = "";
  26509. }
  26510. if (!dialogs[dialogName]) {
  26511. return;
  26512. }
  26513. str = '<nobr>' + editor.getLang("property") + ': '+
  26514. '<span onclick=$$._onImgSetFloat("none") class="edui-clickable">' + editor.getLang("default") + '</span>&nbsp;&nbsp;' +
  26515. '<span onclick=$$._onImgSetFloat("left") class="edui-clickable">' + editor.getLang("justifyleft") + '</span>&nbsp;&nbsp;' +
  26516. '<span onclick=$$._onImgSetFloat("right") class="edui-clickable">' + editor.getLang("justifyright") + '</span>&nbsp;&nbsp;' +
  26517. '<span onclick=$$._onImgSetFloat("center") class="edui-clickable">' + editor.getLang("justifycenter") + '</span>&nbsp;&nbsp;'+
  26518. '<span onclick="$$._onImgEditButtonClick(\'' + dialogName + '\');" class="edui-clickable">' + editor.getLang("modify") + '</span></nobr>';
  26519. !html && (html = popup.formatHtml(str)) */
  26520. }
  26521. if (editor.ui._dialogs.linkDialog) {
  26522. var link = editor.queryCommandValue('link');
  26523. var url;
  26524. if (link && (url = (link.getAttribute('_href') || link.getAttribute('href', 2)))) {
  26525. var txt = url;
  26526. if (url.length > 30) {
  26527. txt = url.substring(0, 20) + "...";
  26528. }
  26529. if (html) {
  26530. html += '<div style="height:5px;"></div>'
  26531. }
  26532. html += popup.formatHtml(
  26533. '<nobr>' + editor.getLang("anthorMsg") + ': <a target="_blank" href="' + url + '" title="' + url + '" >' + txt + '</a>' +
  26534. ' <span class="edui-clickable" onclick="$$._onEditButtonClick();">' + editor.getLang("modify") + '</span>' +
  26535. ' <span class="edui-clickable" onclick="$$._onRemoveButtonClick(\'unlink\');"> ' + editor.getLang("clear") + '</span></nobr>');
  26536. popup.showAnchor(link);
  26537. }
  26538. }
  26539. if (html) {
  26540. popup.getDom('content').innerHTML = html;
  26541. popup.anchorEl = img || link;
  26542. popup.showAnchor(popup.anchorEl);
  26543. } else {
  26544. popup.hide();
  26545. }
  26546. });
  26547. }
  26548. },
  26549. _initToolbars:function () {
  26550. var editor = this.editor;
  26551. var toolbars = this.toolbars || [];
  26552. var toolbarUis = [];
  26553. for (var i = 0; i < toolbars.length; i++) {
  26554. var toolbar = toolbars[i];
  26555. var toolbarUi = new baidu.editor.ui.Toolbar({theme:editor.options.theme});
  26556. for (var j = 0; j < toolbar.length; j++) {
  26557. var toolbarItem = toolbar[j];
  26558. var toolbarItemUi = null;
  26559. if (typeof toolbarItem == 'string') {
  26560. toolbarItem = toolbarItem.toLowerCase();
  26561. if (toolbarItem == '|') {
  26562. toolbarItem = 'Separator';
  26563. }
  26564. if(toolbarItem == '||'){
  26565. toolbarItem = 'Breakline';
  26566. }
  26567. if (baidu.editor.ui[toolbarItem]) {
  26568. toolbarItemUi = new baidu.editor.ui[toolbarItem](editor);
  26569. }
  26570. //fullscreen这里单独处理一下,放到首行去
  26571. if (toolbarItem == 'fullscreen') {
  26572. if (toolbarUis && toolbarUis[0]) {
  26573. toolbarUis[0].items.splice(0, 0, toolbarItemUi);
  26574. } else {
  26575. toolbarItemUi && toolbarUi.items.splice(0, 0, toolbarItemUi);
  26576. }
  26577. continue;
  26578. }
  26579. } else {
  26580. toolbarItemUi = toolbarItem;
  26581. }
  26582. if (toolbarItemUi && toolbarItemUi.id) {
  26583. toolbarUi.add(toolbarItemUi);
  26584. }
  26585. }
  26586. toolbarUis[i] = toolbarUi;
  26587. }
  26588. //接受外部定制的UI
  26589. utils.each(UE._customizeUI,function(obj,key){
  26590. var itemUI,index;
  26591. if(obj.id && obj.id != editor.key){
  26592. return false;
  26593. }
  26594. itemUI = obj.execFn.call(editor,editor,key);
  26595. if(itemUI){
  26596. index = obj.index;
  26597. if(index === undefined){
  26598. index = toolbarUi.items.length;
  26599. }
  26600. toolbarUi.add(itemUI,index)
  26601. }
  26602. });
  26603. this.toolbars = toolbarUis;
  26604. },
  26605. getHtmlTpl:function () {
  26606. return '<div id="##" class="%%">' +
  26607. '<div id="##_toolbarbox" class="%%-toolbarbox">' +
  26608. (this.toolbars.length ?
  26609. '<div id="##_toolbarboxouter" class="%%-toolbarboxouter"><div class="%%-toolbarboxinner">' +
  26610. this.renderToolbarBoxHtml() +
  26611. '</div></div>' : '') +
  26612. '<div id="##_toolbarmsg" class="%%-toolbarmsg" style="display:none;">' +
  26613. '<div id = "##_upload_dialog" class="%%-toolbarmsg-upload" onclick="$$.showWordImageDialog();">' + this.editor.getLang("clickToUpload") + '</div>' +
  26614. '<div class="%%-toolbarmsg-close" onclick="$$.hideToolbarMsg();">x</div>' +
  26615. '<div id="##_toolbarmsg_label" class="%%-toolbarmsg-label"></div>' +
  26616. '<div style="height:0;overflow:hidden;clear:both;"></div>' +
  26617. '</div>' +
  26618. '<div id="##_message_holder" class="%%-messageholder"></div>' +
  26619. '</div>' +
  26620. '<div id="##_iframeholder" class="%%-iframeholder">' +
  26621. '</div>' +
  26622. //modify wdcount by matao
  26623. '<div id="##_bottombar" class="%%-bottomContainer"><table><tr>' +
  26624. '<td id="##_elementpath" class="%%-bottombar"></td>' +
  26625. '<td id="##_wordcount" class="%%-wordcount"></td>' +
  26626. '<td id="##_scale" class="%%-scale"><div class="%%-icon"></div></td>' +
  26627. '</tr></table></div>' +
  26628. '<div id="##_scalelayer"></div>' +
  26629. '</div>';
  26630. },
  26631. showWordImageDialog:function () {
  26632. this._dialogs['wordimageDialog'].open();
  26633. },
  26634. renderToolbarBoxHtml:function () {
  26635. var buff = [];
  26636. for (var i = 0; i < this.toolbars.length; i++) {
  26637. buff.push(this.toolbars[i].renderHtml());
  26638. }
  26639. return buff.join('');
  26640. },
  26641. setFullScreen:function (fullscreen) {
  26642. var editor = this.editor,
  26643. container = editor.container.parentNode.parentNode;
  26644. if (this._fullscreen != fullscreen) {
  26645. this._fullscreen = fullscreen;
  26646. this.editor.fireEvent('beforefullscreenchange', fullscreen);
  26647. if (baidu.editor.browser.gecko) {
  26648. var bk = editor.selection.getRange().createBookmark();
  26649. }
  26650. if (fullscreen) {
  26651. while (container.tagName != "BODY") {
  26652. var position = baidu.editor.dom.domUtils.getComputedStyle(container, "position");
  26653. nodeStack.push(position);
  26654. container.style.position = "static";
  26655. container = container.parentNode;
  26656. }
  26657. this._bakHtmlOverflow = document.documentElement.style.overflow;
  26658. this._bakBodyOverflow = document.body.style.overflow;
  26659. this._bakAutoHeight = this.editor.autoHeightEnabled;
  26660. this._bakScrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
  26661. this._bakEditorContaninerWidth = editor.iframe.parentNode.offsetWidth;
  26662. if (this._bakAutoHeight) {
  26663. //当全屏时不能执行自动长高
  26664. editor.autoHeightEnabled = false;
  26665. this.editor.disableAutoHeight();
  26666. }
  26667. document.documentElement.style.overflow = 'hidden';
  26668. //修复,滚动条不收起的问题
  26669. window.scrollTo(0,window.scrollY);
  26670. this._bakCssText = this.getDom().style.cssText;
  26671. this._bakCssText1 = this.getDom('iframeholder').style.cssText;
  26672. editor.iframe.parentNode.style.width = '';
  26673. this._updateFullScreen();
  26674. } else {
  26675. while (container.tagName != "BODY") {
  26676. container.style.position = nodeStack.shift();
  26677. container = container.parentNode;
  26678. }
  26679. this.getDom().style.cssText = this._bakCssText;
  26680. this.getDom('iframeholder').style.cssText = this._bakCssText1;
  26681. if (this._bakAutoHeight) {
  26682. editor.autoHeightEnabled = true;
  26683. this.editor.enableAutoHeight();
  26684. }
  26685. document.documentElement.style.overflow = this._bakHtmlOverflow;
  26686. document.body.style.overflow = this._bakBodyOverflow;
  26687. editor.iframe.parentNode.style.width = this._bakEditorContaninerWidth + 'px';
  26688. window.scrollTo(0, this._bakScrollTop);
  26689. }
  26690. if (browser.gecko && editor.body.contentEditable === 'true') {
  26691. var input = document.createElement('input');
  26692. document.body.appendChild(input);
  26693. editor.body.contentEditable = false;
  26694. setTimeout(function () {
  26695. input.focus();
  26696. setTimeout(function () {
  26697. editor.body.contentEditable = true;
  26698. editor.fireEvent('fullscreenchanged', fullscreen);
  26699. editor.selection.getRange().moveToBookmark(bk).select(true);
  26700. baidu.editor.dom.domUtils.remove(input);
  26701. fullscreen && window.scroll(0, 0);
  26702. }, 0)
  26703. }, 0)
  26704. }
  26705. if(editor.body.contentEditable === 'true'){
  26706. this.editor.fireEvent('fullscreenchanged', fullscreen);
  26707. this.triggerLayout();
  26708. }
  26709. }
  26710. },
  26711. _updateFullScreen:function () {
  26712. if (this._fullscreen) {
  26713. var vpRect = uiUtils.getViewportRect();
  26714. 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);
  26715. uiUtils.setViewportOffset(this.getDom(), { left:0, top:this.editor.options.topOffset || 0 });
  26716. this.editor.setHeight(vpRect.height - this.getDom('toolbarbox').offsetHeight - this.getDom('bottombar').offsetHeight - (this.editor.options.topOffset || 0),true);
  26717. //不手动调一下,会导致全屏失效
  26718. if(browser.gecko){
  26719. try{
  26720. window.onresize();
  26721. }catch(e){
  26722. }
  26723. }
  26724. }
  26725. },
  26726. _updateElementPath:function () {
  26727. var bottom = this.getDom('elementpath'), list;
  26728. if (this.elementPathEnabled && (list = this.editor.queryCommandValue('elementpath'))) {
  26729. var buff = [];
  26730. for (var i = 0, ci; ci = list[i]; i++) {
  26731. buff[i] = this.formatHtml('<span unselectable="on" onclick="$$.editor.execCommand(&quot;elementpath&quot;, &quot;' + i + '&quot;);">' + ci + '</span>');
  26732. }
  26733. bottom.innerHTML = '<div class="edui-editor-breadcrumb" onmousedown="return false;">' + this.editor.getLang("elementPathTip") + ': ' + buff.join(' &gt; ') + '</div>';
  26734. } else {
  26735. bottom.style.display = 'none'
  26736. }
  26737. },
  26738. disableElementPath:function () {
  26739. var bottom = this.getDom('elementpath');
  26740. bottom.innerHTML = '';
  26741. bottom.style.display = 'none';
  26742. this.elementPathEnabled = false;
  26743. },
  26744. enableElementPath:function () {
  26745. var bottom = this.getDom('elementpath');
  26746. bottom.style.display = '';
  26747. this.elementPathEnabled = true;
  26748. this._updateElementPath();
  26749. },
  26750. _scale:function () {
  26751. var doc = document,
  26752. editor = this.editor,
  26753. editorHolder = editor.container,
  26754. editorDocument = editor.document,
  26755. toolbarBox = this.getDom("toolbarbox"),
  26756. bottombar = this.getDom("bottombar"),
  26757. scale = this.getDom("scale"),
  26758. scalelayer = this.getDom("scalelayer");
  26759. var isMouseMove = false,
  26760. position = null,
  26761. minEditorHeight = 0,
  26762. minEditorWidth = editor.options.minFrameWidth,
  26763. pageX = 0,
  26764. pageY = 0,
  26765. scaleWidth = 0,
  26766. scaleHeight = 0;
  26767. function down() {
  26768. position = domUtils.getXY(editorHolder);
  26769. if (!minEditorHeight) {
  26770. minEditorHeight = editor.options.minFrameHeight + toolbarBox.offsetHeight + bottombar.offsetHeight;
  26771. }
  26772. 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:"
  26773. + editorHolder.offsetHeight + "px;z-index:" + (editor.options.zIndex + 1);
  26774. domUtils.on(doc, "mousemove", move);
  26775. domUtils.on(editorDocument, "mouseup", up);
  26776. domUtils.on(doc, "mouseup", up);
  26777. }
  26778. var me = this;
  26779. //by xuheng 全屏时关掉缩放
  26780. this.editor.addListener('fullscreenchanged', function (e, fullScreen) {
  26781. if (fullScreen) {
  26782. me.disableScale();
  26783. } else {
  26784. if (me.editor.options.scaleEnabled) {
  26785. me.enableScale();
  26786. var tmpNode = me.editor.document.createElement('span');
  26787. me.editor.body.appendChild(tmpNode);
  26788. me.editor.body.style.height = Math.max(domUtils.getXY(tmpNode).y, me.editor.iframe.offsetHeight - 20) + 'px';
  26789. domUtils.remove(tmpNode)
  26790. }
  26791. }
  26792. });
  26793. function move(event) {
  26794. clearSelection();
  26795. var e = event || window.event;
  26796. pageX = e.pageX || (doc.documentElement.scrollLeft + e.clientX);
  26797. pageY = e.pageY || (doc.documentElement.scrollTop + e.clientY);
  26798. scaleWidth = pageX - position.x;
  26799. scaleHeight = pageY - position.y;
  26800. if (scaleWidth >= minEditorWidth) {
  26801. isMouseMove = true;
  26802. scalelayer.style.width = scaleWidth + 'px';
  26803. }
  26804. if (scaleHeight >= minEditorHeight) {
  26805. isMouseMove = true;
  26806. scalelayer.style.height = scaleHeight + "px";
  26807. }
  26808. }
  26809. function up() {
  26810. if (isMouseMove) {
  26811. isMouseMove = false;
  26812. editor.ui._actualFrameWidth = scalelayer.offsetWidth - 2;
  26813. editorHolder.style.width = editor.ui._actualFrameWidth + 'px';
  26814. editor.setHeight(scalelayer.offsetHeight - bottombar.offsetHeight - toolbarBox.offsetHeight - 2,true);
  26815. }
  26816. if (scalelayer) {
  26817. scalelayer.style.display = "none";
  26818. }
  26819. clearSelection();
  26820. domUtils.un(doc, "mousemove", move);
  26821. domUtils.un(editorDocument, "mouseup", up);
  26822. domUtils.un(doc, "mouseup", up);
  26823. }
  26824. function clearSelection() {
  26825. if (browser.ie)
  26826. doc.selection.clear();
  26827. else
  26828. window.getSelection().removeAllRanges();
  26829. }
  26830. this.enableScale = function () {
  26831. //trace:2868
  26832. if (editor.queryCommandState("source") == 1) return;
  26833. scale.style.display = "";
  26834. this.scaleEnabled = true;
  26835. domUtils.on(scale, "mousedown", down);
  26836. };
  26837. this.disableScale = function () {
  26838. scale.style.display = "none";
  26839. this.scaleEnabled = false;
  26840. domUtils.un(scale, "mousedown", down);
  26841. };
  26842. },
  26843. isFullScreen:function () {
  26844. return this._fullscreen;
  26845. },
  26846. postRender:function () {
  26847. UIBase.prototype.postRender.call(this);
  26848. for (var i = 0; i < this.toolbars.length; i++) {
  26849. this.toolbars[i].postRender();
  26850. }
  26851. var me = this;
  26852. var timerId,
  26853. domUtils = baidu.editor.dom.domUtils,
  26854. updateFullScreenTime = function () {
  26855. clearTimeout(timerId);
  26856. timerId = setTimeout(function () {
  26857. me._updateFullScreen();
  26858. });
  26859. };
  26860. domUtils.on(window, 'resize', updateFullScreenTime);
  26861. me.addListener('destroy', function () {
  26862. domUtils.un(window, 'resize', updateFullScreenTime);
  26863. clearTimeout(timerId);
  26864. })
  26865. },
  26866. showToolbarMsg:function (msg, flag) {
  26867. this.getDom('toolbarmsg_label').innerHTML = msg;
  26868. this.getDom('toolbarmsg').style.display = '';
  26869. //
  26870. if (!flag) {
  26871. var w = this.getDom('upload_dialog');
  26872. w.style.display = 'none';
  26873. }
  26874. },
  26875. hideToolbarMsg:function () {
  26876. this.getDom('toolbarmsg').style.display = 'none';
  26877. },
  26878. mapUrl:function (url) {
  26879. return url ? url.replace('~/', this.editor.options.UEDITOR_HOME_URL || '') : ''
  26880. },
  26881. triggerLayout:function () {
  26882. var dom = this.getDom();
  26883. if (dom.style.zoom == '1') {
  26884. dom.style.zoom = '100%';
  26885. } else {
  26886. dom.style.zoom = '1';
  26887. }
  26888. }
  26889. };
  26890. utils.inherits(EditorUI, baidu.editor.ui.UIBase);
  26891. var instances = {};
  26892. UE.ui.Editor = function (options) {
  26893. var editor = new UE.Editor(options);
  26894. editor.options.editor = editor;
  26895. utils.loadFile(document, {
  26896. href:editor.options.themePath + editor.options.theme + "/css/ueditor.css",
  26897. tag:"link",
  26898. type:"text/css",
  26899. rel:"stylesheet"
  26900. });
  26901. var oldRender = editor.render;
  26902. editor.render = function (holder) {
  26903. if (holder.constructor === String) {
  26904. editor.key = holder;
  26905. instances[holder] = editor;
  26906. }
  26907. utils.domReady(function () {
  26908. editor.langIsReady ? renderUI() : editor.addListener("langReady", renderUI);
  26909. function renderUI() {
  26910. editor.setOpt({
  26911. labelMap:editor.options.labelMap || editor.getLang('labelMap')
  26912. });
  26913. new EditorUI(editor.options);
  26914. if (holder) {
  26915. if (holder.constructor === String) {
  26916. holder = document.getElementById(holder);
  26917. }
  26918. holder && holder.getAttribute('name') && ( editor.options.textarea = holder.getAttribute('name'));
  26919. if (holder && /script|textarea/ig.test(holder.tagName)) {
  26920. var newDiv = document.createElement('div');
  26921. holder.parentNode.insertBefore(newDiv, holder);
  26922. var cont = holder.value || holder.innerHTML;
  26923. editor.options.initialContent = /^[\t\r\n ]*$/.test(cont) ? editor.options.initialContent :
  26924. cont.replace(/>[\n\r\t]+([ ]{4})+/g, '>')
  26925. .replace(/[\n\r\t]+([ ]{4})+</g, '<')
  26926. .replace(/>[\n\r\t]+</g, '><');
  26927. holder.className && (newDiv.className = holder.className);
  26928. holder.style.cssText && (newDiv.style.cssText = holder.style.cssText);
  26929. if (/textarea/i.test(holder.tagName)) {
  26930. editor.textarea = holder;
  26931. editor.textarea.style.display = 'none';
  26932. } else {
  26933. holder.parentNode.removeChild(holder);
  26934. }
  26935. if(holder.id){
  26936. newDiv.id = holder.id;
  26937. domUtils.removeAttributes(holder,'id');
  26938. }
  26939. holder = newDiv;
  26940. holder.innerHTML = '';
  26941. }
  26942. }
  26943. domUtils.addClass(holder, "edui-" + editor.options.theme);
  26944. editor.ui.render(holder);
  26945. var opt = editor.options;
  26946. //给实例添加一个编辑器的容器引用
  26947. editor.container = editor.ui.getDom();
  26948. var parents = domUtils.findParents(holder,true);
  26949. var displays = [];
  26950. for(var i = 0 ,ci;ci=parents[i];i++){
  26951. displays[i] = ci.style.display;
  26952. ci.style.display = 'block'
  26953. }
  26954. if (opt.initialFrameWidth) {
  26955. opt.minFrameWidth = opt.initialFrameWidth;
  26956. } else {
  26957. opt.minFrameWidth = opt.initialFrameWidth = holder.offsetWidth;
  26958. var styleWidth = holder.style.width;
  26959. if(/%$/.test(styleWidth)) {
  26960. opt.initialFrameWidth = styleWidth;
  26961. }
  26962. }
  26963. if (opt.initialFrameHeight) {
  26964. opt.minFrameHeight = opt.initialFrameHeight;
  26965. } else {
  26966. opt.initialFrameHeight = opt.minFrameHeight = holder.offsetHeight;
  26967. }
  26968. for(var i = 0 ,ci;ci=parents[i];i++){
  26969. ci.style.display = displays[i]
  26970. }
  26971. //编辑器最外容器设置了高度,会导致,编辑器不占位
  26972. //todo 先去掉,没有找到原因
  26973. if(holder.style.height){
  26974. holder.style.height = ''
  26975. }
  26976. editor.container.style.width = opt.initialFrameWidth + (/%$/.test(opt.initialFrameWidth) ? '' : 'px');
  26977. editor.container.style.zIndex = opt.zIndex;
  26978. oldRender.call(editor, editor.ui.getDom('iframeholder'));
  26979. editor.fireEvent("afteruiready");
  26980. }
  26981. })
  26982. };
  26983. return editor;
  26984. };
  26985. /**
  26986. * @file
  26987. * @name UE
  26988. * @short UE
  26989. * @desc UEditor的顶部命名空间
  26990. */
  26991. /**
  26992. * @name getEditor
  26993. * @since 1.2.4+
  26994. * @grammar UE.getEditor(id,[opt]) => Editor实例
  26995. * @desc 提供一个全局的方法得到编辑器实例
  26996. *
  26997. * * ''id'' 放置编辑器的容器id, 如果容器下的编辑器已经存在,就直接返回
  26998. * * ''opt'' 编辑器的可选参数
  26999. * @example
  27000. * UE.getEditor('containerId',{onready:function(){//创建一个编辑器实例
  27001. * this.setContent('hello')
  27002. * }});
  27003. * UE.getEditor('containerId'); //返回刚创建的实例
  27004. *
  27005. */
  27006. UE.getEditor = function (id, opt) {
  27007. var editor = instances[id];
  27008. if (!editor) {
  27009. editor = instances[id] = new UE.ui.Editor(opt);
  27010. editor.render(id);
  27011. }
  27012. return editor;
  27013. };
  27014. UE.delEditor = function (id) {
  27015. var editor;
  27016. if (editor = instances[id]) {
  27017. editor.key && editor.destroy();
  27018. delete instances[id]
  27019. }
  27020. };
  27021. UE.registerUI = function(uiName,fn,index,editorId){
  27022. utils.each(uiName.split(/\s+/), function (name) {
  27023. UE._customizeUI[name] = {
  27024. id : editorId,
  27025. execFn:fn,
  27026. index:index
  27027. };
  27028. })
  27029. }
  27030. })();
  27031. // adapter/message.js
  27032. UE.registerUI('message', function(editor) {
  27033. var editorui = baidu.editor.ui;
  27034. var Message = editorui.Message;
  27035. var holder;
  27036. var _messageItems = [];
  27037. var me = editor;
  27038. me.addListener('ready', function(){
  27039. holder = document.getElementById(me.ui.id + '_message_holder');
  27040. updateHolderPos();
  27041. setTimeout(function(){
  27042. updateHolderPos();
  27043. }, 500);
  27044. });
  27045. me.addListener('showmessage', function(type, opt){
  27046. opt = utils.isString(opt) ? {
  27047. 'content': opt
  27048. } : opt;
  27049. var message = new Message({
  27050. 'timeout': opt.timeout,
  27051. 'type': opt.type,
  27052. 'content': opt.content,
  27053. 'keepshow': opt.keepshow,
  27054. 'editor': me
  27055. }),
  27056. mid = opt.id || ('msg_' + (+new Date()).toString(36));
  27057. message.render(holder);
  27058. _messageItems[mid] = message;
  27059. message.reset(opt);
  27060. updateHolderPos();
  27061. return mid;
  27062. });
  27063. me.addListener('updatemessage',function(type, id, opt){
  27064. opt = utils.isString(opt) ? {
  27065. 'content': opt
  27066. } : opt;
  27067. var message = _messageItems[id];
  27068. message.render(holder);
  27069. message && message.reset(opt);
  27070. });
  27071. me.addListener('hidemessage',function(type, id){
  27072. var message = _messageItems[id];
  27073. message && message.hide();
  27074. });
  27075. function updateHolderPos(){
  27076. var toolbarbox = me.ui.getDom('toolbarbox');
  27077. if (toolbarbox) {
  27078. holder.style.top = toolbarbox.offsetHeight + 3 + 'px';
  27079. }
  27080. holder.style.zIndex = Math.max(me.options.zIndex, me.iframe.style.zIndex) + 1;
  27081. }
  27082. });
  27083. // adapter/autosave.js
  27084. UE.registerUI('autosave', function(editor) {
  27085. var timer = null,uid = null;
  27086. editor.on('afterautosave',function(){
  27087. clearTimeout(timer);
  27088. timer = setTimeout(function(){
  27089. if(uid){
  27090. editor.trigger('hidemessage',uid);
  27091. }
  27092. uid = editor.trigger('showmessage',{
  27093. content : editor.getLang('autosave.success'),
  27094. timeout : 2000
  27095. });
  27096. },2000)
  27097. })
  27098. });
  27099. })();