kindeditor-all.js 265 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268
  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2013 kindsoft.net
  4. *
  5. * @author Roddy <luolonghao@gmail.com>
  6. * @website http://www.kindsoft.net/
  7. * @licence http://www.kindsoft.net/license.php
  8. * @version 4.1.10 (2013-11-23)
  9. *******************************************************************************/
  10. (function (window, undefined) {
  11. if (window.KindEditor) {
  12. return;
  13. }
  14. if (!window.console) {
  15. window.console = {};
  16. }
  17. if (!console.log) {
  18. console.log = function () {};
  19. }
  20. var _VERSION = '4.1.10 (2013-11-23)',
  21. _ua = navigator.userAgent.toLowerCase(),
  22. _IE = _ua.indexOf('msie') > -1 && _ua.indexOf('opera') == -1,
  23. _NEWIE = _ua.indexOf('msie') == -1 && _ua.indexOf('trident') > -1,
  24. _GECKO = _ua.indexOf('gecko') > -1 && _ua.indexOf('khtml') == -1,
  25. _WEBKIT = _ua.indexOf('applewebkit') > -1,
  26. _OPERA = _ua.indexOf('opera') > -1,
  27. _MOBILE = _ua.indexOf('mobile') > -1,
  28. _IOS = /ipad|iphone|ipod/.test(_ua),
  29. _QUIRKS = document.compatMode != 'CSS1Compat',
  30. _IERANGE = !window.getSelection,
  31. _matches = /(?:msie|firefox|webkit|opera)[\/:\s](\d+)/.exec(_ua),
  32. _V = _matches ? _matches[1] : '0',
  33. _TIME = new Date().getTime();
  34. function _isArray(val) {
  35. if (!val) {
  36. return false;
  37. }
  38. return Object.prototype.toString.call(val) === '[object Array]';
  39. }
  40. function _isFunction(val) {
  41. if (!val) {
  42. return false;
  43. }
  44. return Object.prototype.toString.call(val) === '[object Function]';
  45. }
  46. function _inArray(val, arr) {
  47. for (var i = 0, len = arr.length; i < len; i++) {
  48. if (val === arr[i]) {
  49. return i;
  50. }
  51. }
  52. return -1;
  53. }
  54. function _each(obj, fn) {
  55. if (_isArray(obj)) {
  56. for (var i = 0, len = obj.length; i < len; i++) {
  57. if (fn.call(obj[i], i, obj[i]) === false) {
  58. break;
  59. }
  60. }
  61. } else {
  62. for (var key in obj) {
  63. if (obj.hasOwnProperty(key)) {
  64. if (fn.call(obj[key], key, obj[key]) === false) {
  65. break;
  66. }
  67. }
  68. }
  69. }
  70. }
  71. function _trim(str) {
  72. return str.replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, '');
  73. }
  74. function _inString(val, str, delimiter) {
  75. delimiter = delimiter === undefined ? ',' : delimiter;
  76. return (delimiter + str + delimiter).indexOf(delimiter + val + delimiter) >= 0;
  77. }
  78. function _addUnit(val, unit) {
  79. unit = unit || 'px';
  80. return val && /^\d+$/.test(val) ? val + unit : val;
  81. }
  82. function _removeUnit(val) {
  83. var match;
  84. return val && (match = /(\d+)/.exec(val)) ? parseInt(match[1], 10) : 0;
  85. }
  86. function _escape(val) {
  87. return val.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  88. }
  89. function _unescape(val) {
  90. return val.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&amp;/g, '&');
  91. }
  92. function _toCamel(str) {
  93. var arr = str.split('-');
  94. str = '';
  95. _each(arr, function(key, val) {
  96. str += (key > 0) ? val.charAt(0).toUpperCase() + val.substr(1) : val;
  97. });
  98. return str;
  99. }
  100. function _toHex(val) {
  101. function hex(d) {
  102. var s = parseInt(d, 10).toString(16).toUpperCase();
  103. return s.length > 1 ? s : '0' + s;
  104. }
  105. return val.replace(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/ig,
  106. function($0, $1, $2, $3) {
  107. return '#' + hex($1) + hex($2) + hex($3);
  108. }
  109. );
  110. }
  111. function _toMap(val, delimiter) {
  112. delimiter = delimiter === undefined ? ',' : delimiter;
  113. var map = {}, arr = _isArray(val) ? val : val.split(delimiter), match;
  114. _each(arr, function(key, val) {
  115. if ((match = /^(\d+)\.\.(\d+)$/.exec(val))) {
  116. for (var i = parseInt(match[1], 10); i <= parseInt(match[2], 10); i++) {
  117. map[i.toString()] = true;
  118. }
  119. } else {
  120. map[val] = true;
  121. }
  122. });
  123. return map;
  124. }
  125. function _toArray(obj, offset) {
  126. return Array.prototype.slice.call(obj, offset || 0);
  127. }
  128. function _undef(val, defaultVal) {
  129. return val === undefined ? defaultVal : val;
  130. }
  131. function _invalidUrl(url) {
  132. return !url || /[<>"]/.test(url);
  133. }
  134. function _addParam(url, param) {
  135. return url.indexOf('?') >= 0 ? url + '&' + param : url + '?' + param;
  136. }
  137. function _extend(child, parent, proto) {
  138. if (!proto) {
  139. proto = parent;
  140. parent = null;
  141. }
  142. var childProto;
  143. if (parent) {
  144. var fn = function () {};
  145. fn.prototype = parent.prototype;
  146. childProto = new fn();
  147. _each(proto, function(key, val) {
  148. childProto[key] = val;
  149. });
  150. } else {
  151. childProto = proto;
  152. }
  153. childProto.constructor = child;
  154. child.prototype = childProto;
  155. child.parent = parent ? parent.prototype : null;
  156. }
  157. function _json(text) {
  158. var match;
  159. if ((match = /\{[\s\S]*\}|\[[\s\S]*\]/.exec(text))) {
  160. text = match[0];
  161. }
  162. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  163. cx.lastIndex = 0;
  164. if (cx.test(text)) {
  165. text = text.replace(cx, function (a) {
  166. return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  167. });
  168. }
  169. if (/^[\],:{}\s]*$/.
  170. test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
  171. replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
  172. replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  173. return eval('(' + text + ')');
  174. }
  175. throw 'JSON parse error';
  176. }
  177. var _round = Math.round;
  178. var K = {
  179. DEBUG : false,
  180. VERSION : _VERSION,
  181. IE : _IE,
  182. GECKO : _GECKO,
  183. WEBKIT : _WEBKIT,
  184. OPERA : _OPERA,
  185. V : _V,
  186. TIME : _TIME,
  187. each : _each,
  188. isArray : _isArray,
  189. isFunction : _isFunction,
  190. inArray : _inArray,
  191. inString : _inString,
  192. trim : _trim,
  193. addUnit : _addUnit,
  194. removeUnit : _removeUnit,
  195. escape : _escape,
  196. unescape : _unescape,
  197. toCamel : _toCamel,
  198. toHex : _toHex,
  199. toMap : _toMap,
  200. toArray : _toArray,
  201. undef : _undef,
  202. invalidUrl : _invalidUrl,
  203. addParam : _addParam,
  204. extend : _extend,
  205. json : _json
  206. };
  207. var _INLINE_TAG_MAP = _toMap('a,abbr,acronym,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,img,input,ins,kbd,label,map,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'),
  208. _BLOCK_TAG_MAP = _toMap('address,applet,blockquote,body,center,dd,dir,div,dl,dt,fieldset,form,frameset,h1,h2,h3,h4,h5,h6,head,hr,html,iframe,ins,isindex,li,map,menu,meta,noframes,noscript,object,ol,p,pre,script,style,table,tbody,td,tfoot,th,thead,title,tr,ul'),
  209. _SINGLE_TAG_MAP = _toMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'),
  210. _STYLE_TAG_MAP = _toMap('b,basefont,big,del,em,font,i,s,small,span,strike,strong,sub,sup,u'),
  211. _CONTROL_TAG_MAP = _toMap('img,table,input,textarea,button'),
  212. _PRE_TAG_MAP = _toMap('pre,style,script'),
  213. _NOSPLIT_TAG_MAP = _toMap('html,head,body,td,tr,table,ol,ul,li'),
  214. _AUTOCLOSE_TAG_MAP = _toMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'),
  215. _FILL_ATTR_MAP = _toMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
  216. _VALUE_TAG_MAP = _toMap('input,button,textarea,select');
  217. function _getBasePath() {
  218. var els = document.getElementsByTagName('script'), src;
  219. for (var i = 0, len = els.length; i < len; i++) {
  220. src = els[i].src || '';
  221. if (/kindeditor[\w\-\.]*\.js/.test(src)) {
  222. return src.substring(0, src.lastIndexOf('/') + 1);
  223. }
  224. }
  225. return '';
  226. }
  227. K.basePath = _getBasePath();
  228. K.options = {
  229. designMode : true,
  230. fullscreenMode : false,
  231. filterMode : true,
  232. wellFormatMode : true,
  233. shadowMode : true,
  234. loadStyleMode : true,
  235. basePath : K.basePath,
  236. themesPath : K.basePath + 'themes/',
  237. langPath : K.basePath + 'lang/',
  238. pluginsPath : K.basePath + 'plugins/',
  239. themeType : 'default',
  240. langType : 'zh_CN',
  241. urlType : '',
  242. newlineTag : 'p',
  243. resizeType : 2,
  244. syncType : 'form',
  245. pasteType : 2,
  246. dialogAlignType : 'page',
  247. useContextmenu : true,
  248. fullscreenShortcut : false,
  249. bodyClass : 'ke-content',
  250. indentChar : '\t',
  251. cssPath : '',
  252. cssData : '',
  253. minWidth : 650,
  254. minHeight : 100,
  255. minChangeSize : 50,
  256. zIndex : 811213,
  257. items : [
  258. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  259. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  260. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  261. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  262. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  263. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  264. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  265. 'anchor', 'link', 'unlink', '|', 'about'
  266. ],
  267. noDisableItems : ['source', 'fullscreen'],
  268. colorTable : [
  269. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  270. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  271. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  272. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  273. ],
  274. fontSizeTable : ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
  275. htmlTags : {
  276. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  277. span : [
  278. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  279. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  280. ],
  281. div : [
  282. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  283. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  284. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  285. ],
  286. table: [
  287. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  288. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  289. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  290. '.width', '.height', '.border-collapse'
  291. ],
  292. 'td,th': [
  293. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  294. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  295. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  296. ],
  297. a : ['id', 'class', 'href', 'target', 'name'],
  298. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  299. img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  300. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  301. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  302. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  303. ],
  304. pre : ['id', 'class'],
  305. hr : ['id', 'class', '.page-break-after'],
  306. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  307. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  308. },
  309. layout : '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  310. };
  311. var _useCapture = false;
  312. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  313. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  314. var _CHANGE_KEY_MAP = {};
  315. _each(_INPUT_KEY_MAP, function(key, val) {
  316. _CHANGE_KEY_MAP[key] = val;
  317. });
  318. _each(_CURSORMOVE_KEY_MAP, function(key, val) {
  319. _CHANGE_KEY_MAP[key] = val;
  320. });
  321. function _bindEvent(el, type, fn) {
  322. if (el.addEventListener){
  323. el.addEventListener(type, fn, _useCapture);
  324. } else if (el.attachEvent){
  325. el.attachEvent('on' + type, fn);
  326. }
  327. }
  328. function _unbindEvent(el, type, fn) {
  329. if (el.removeEventListener){
  330. el.removeEventListener(type, fn, _useCapture);
  331. } else if (el.detachEvent){
  332. el.detachEvent('on' + type, fn);
  333. }
  334. }
  335. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  336. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  337. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  338. function KEvent(el, event) {
  339. this.init(el, event);
  340. }
  341. _extend(KEvent, {
  342. init : function(el, event) {
  343. var self = this, doc = el.ownerDocument || el.document || el;
  344. self.event = event;
  345. _each(_EVENT_PROPS, function(key, val) {
  346. self[val] = event[val];
  347. });
  348. if (!self.target) {
  349. self.target = self.srcElement || doc;
  350. }
  351. if (self.target.nodeType === 3) {
  352. self.target = self.target.parentNode;
  353. }
  354. if (!self.relatedTarget && self.fromElement) {
  355. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  356. }
  357. if (self.pageX == null && self.clientX != null) {
  358. var d = doc.documentElement, body = doc.body;
  359. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  360. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  361. }
  362. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  363. self.which = self.charCode || self.keyCode;
  364. }
  365. if (!self.metaKey && self.ctrlKey) {
  366. self.metaKey = self.ctrlKey;
  367. }
  368. if (!self.which && self.button !== undefined) {
  369. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  370. }
  371. switch (self.which) {
  372. case 186 :
  373. self.which = 59;
  374. break;
  375. case 187 :
  376. case 107 :
  377. case 43 :
  378. self.which = 61;
  379. break;
  380. case 189 :
  381. case 45 :
  382. self.which = 109;
  383. break;
  384. case 42 :
  385. self.which = 106;
  386. break;
  387. case 47 :
  388. self.which = 111;
  389. break;
  390. case 78 :
  391. self.which = 110;
  392. break;
  393. }
  394. if (self.which >= 96 && self.which <= 105) {
  395. self.which -= 48;
  396. }
  397. },
  398. preventDefault : function() {
  399. var ev = this.event;
  400. if (ev.preventDefault) {
  401. ev.preventDefault();
  402. } else {
  403. ev.returnValue = false;
  404. }
  405. },
  406. stopPropagation : function() {
  407. var ev = this.event;
  408. if (ev.stopPropagation) {
  409. ev.stopPropagation();
  410. } else {
  411. ev.cancelBubble = true;
  412. }
  413. },
  414. stop : function() {
  415. this.preventDefault();
  416. this.stopPropagation();
  417. }
  418. });
  419. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  420. function _getId(el) {
  421. return el[_eventExpendo] || null;
  422. }
  423. function _setId(el) {
  424. el[_eventExpendo] = ++_eventId;
  425. return _eventId;
  426. }
  427. function _removeId(el) {
  428. try {
  429. delete el[_eventExpendo];
  430. } catch(e) {
  431. if (el.removeAttribute) {
  432. el.removeAttribute(_eventExpendo);
  433. }
  434. }
  435. }
  436. function _bind(el, type, fn) {
  437. if (type.indexOf(',') >= 0) {
  438. _each(type.split(','), function() {
  439. _bind(el, this, fn);
  440. });
  441. return;
  442. }
  443. var id = _getId(el);
  444. if (!id) {
  445. id = _setId(el);
  446. }
  447. if (_eventData[id] === undefined) {
  448. _eventData[id] = {};
  449. }
  450. var events = _eventData[id][type];
  451. if (events && events.length > 0) {
  452. _unbindEvent(el, type, events[0]);
  453. } else {
  454. _eventData[id][type] = [];
  455. _eventData[id].el = el;
  456. }
  457. events = _eventData[id][type];
  458. if (events.length === 0) {
  459. events[0] = function(e) {
  460. var kevent = e ? new KEvent(el, e) : undefined;
  461. _each(events, function(i, event) {
  462. if (i > 0 && event) {
  463. event.call(el, kevent);
  464. }
  465. });
  466. };
  467. }
  468. if (_inArray(fn, events) < 0) {
  469. events.push(fn);
  470. }
  471. _bindEvent(el, type, events[0]);
  472. }
  473. function _unbind(el, type, fn) {
  474. if (type && type.indexOf(',') >= 0) {
  475. _each(type.split(','), function() {
  476. _unbind(el, this, fn);
  477. });
  478. return;
  479. }
  480. var id = _getId(el);
  481. if (!id) {
  482. return;
  483. }
  484. if (type === undefined) {
  485. if (id in _eventData) {
  486. _each(_eventData[id], function(key, events) {
  487. if (key != 'el' && events.length > 0) {
  488. _unbindEvent(el, key, events[0]);
  489. }
  490. });
  491. delete _eventData[id];
  492. _removeId(el);
  493. }
  494. return;
  495. }
  496. if (!_eventData[id]) {
  497. return;
  498. }
  499. var events = _eventData[id][type];
  500. if (events && events.length > 0) {
  501. if (fn === undefined) {
  502. _unbindEvent(el, type, events[0]);
  503. delete _eventData[id][type];
  504. } else {
  505. _each(events, function(i, event) {
  506. if (i > 0 && event === fn) {
  507. events.splice(i, 1);
  508. }
  509. });
  510. if (events.length == 1) {
  511. _unbindEvent(el, type, events[0]);
  512. delete _eventData[id][type];
  513. }
  514. }
  515. var count = 0;
  516. _each(_eventData[id], function() {
  517. count++;
  518. });
  519. if (count < 2) {
  520. delete _eventData[id];
  521. _removeId(el);
  522. }
  523. }
  524. }
  525. function _fire(el, type) {
  526. if (type.indexOf(',') >= 0) {
  527. _each(type.split(','), function() {
  528. _fire(el, this);
  529. });
  530. return;
  531. }
  532. var id = _getId(el);
  533. if (!id) {
  534. return;
  535. }
  536. var events = _eventData[id][type];
  537. if (_eventData[id] && events && events.length > 0) {
  538. events[0]();
  539. }
  540. }
  541. function _ctrl(el, key, fn) {
  542. var self = this;
  543. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  544. _bind(el, 'keydown', function(e) {
  545. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  546. fn.call(el);
  547. e.stop();
  548. }
  549. });
  550. }
  551. var _readyFinished = false;
  552. function _ready(fn) {
  553. if (_readyFinished) {
  554. fn(KindEditor);
  555. return;
  556. }
  557. var loaded = false;
  558. function readyFunc() {
  559. if (!loaded) {
  560. loaded = true;
  561. fn(KindEditor);
  562. _readyFinished = true;
  563. }
  564. }
  565. function ieReadyFunc() {
  566. if (!loaded) {
  567. try {
  568. document.documentElement.doScroll('left');
  569. } catch(e) {
  570. setTimeout(ieReadyFunc, 100);
  571. return;
  572. }
  573. readyFunc();
  574. }
  575. }
  576. function ieReadyStateFunc() {
  577. if (document.readyState === 'complete') {
  578. readyFunc();
  579. }
  580. }
  581. if (document.addEventListener) {
  582. _bind(document, 'DOMContentLoaded', readyFunc);
  583. } else if (document.attachEvent) {
  584. _bind(document, 'readystatechange', ieReadyStateFunc);
  585. var toplevel = false;
  586. try {
  587. toplevel = window.frameElement == null;
  588. } catch(e) {}
  589. if (document.documentElement.doScroll && toplevel) {
  590. ieReadyFunc();
  591. }
  592. }
  593. _bind(window, 'load', readyFunc);
  594. }
  595. if (_IE) {
  596. window.attachEvent('onunload', function() {
  597. _each(_eventData, function(key, events) {
  598. if (events.el) {
  599. _unbind(events.el);
  600. }
  601. });
  602. });
  603. }
  604. K.ctrl = _ctrl;
  605. K.ready = _ready;
  606. function _getCssList(css) {
  607. var list = {},
  608. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  609. match;
  610. while ((match = reg.exec(css))) {
  611. var key = _trim(match[1].toLowerCase()),
  612. val = _trim(_toHex(match[2]));
  613. list[key] = val;
  614. }
  615. return list;
  616. }
  617. function _getAttrList(tag) {
  618. var list = {},
  619. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  620. match;
  621. while ((match = reg.exec(tag))) {
  622. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  623. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  624. list[key] = val;
  625. }
  626. return list;
  627. }
  628. function _addClassToTag(tag, className) {
  629. if (/\s+class\s*=/.test(tag)) {
  630. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  631. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  632. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  633. } else {
  634. return $0;
  635. }
  636. });
  637. } else {
  638. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  639. }
  640. return tag;
  641. }
  642. function _formatCss(css) {
  643. var str = '';
  644. _each(_getCssList(css), function(key, val) {
  645. str += key + ':' + val + ';';
  646. });
  647. return str;
  648. }
  649. function _formatUrl(url, mode, host, pathname) {
  650. mode = _undef(mode, '').toLowerCase();
  651. if (url.substr(0, 5) != 'data:') {
  652. url = url.replace(/([^:])\/\//g, '$1/');
  653. }
  654. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  655. return url;
  656. }
  657. host = host || location.protocol + '//' + location.host;
  658. if (pathname === undefined) {
  659. var m = location.pathname.match(/^(\/.*)\//);
  660. pathname = m ? m[1] : '';
  661. }
  662. var match;
  663. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  664. if (match[1] !== host) {
  665. return url;
  666. }
  667. } else if (/^\w+:/.test(url)) {
  668. return url;
  669. }
  670. function getRealPath(path) {
  671. var parts = path.split('/'), paths = [];
  672. for (var i = 0, len = parts.length; i < len; i++) {
  673. var part = parts[i];
  674. if (part == '..') {
  675. if (paths.length > 0) {
  676. paths.pop();
  677. }
  678. } else if (part !== '' && part != '.') {
  679. paths.push(part);
  680. }
  681. }
  682. return '/' + paths.join('/');
  683. }
  684. if (/^\//.test(url)) {
  685. url = host + getRealPath(url.substr(1));
  686. } else if (!/^\w+:\/\//.test(url)) {
  687. url = host + getRealPath(pathname + '/' + url);
  688. }
  689. function getRelativePath(path, depth) {
  690. if (url.substr(0, path.length) === path) {
  691. var arr = [];
  692. for (var i = 0; i < depth; i++) {
  693. arr.push('..');
  694. }
  695. var prefix = '.';
  696. if (arr.length > 0) {
  697. prefix += '/' + arr.join('/');
  698. }
  699. if (pathname == '/') {
  700. prefix += '/';
  701. }
  702. return prefix + url.substr(path.length);
  703. } else {
  704. if ((match = /^(.*)\//.exec(path))) {
  705. return getRelativePath(match[1], ++depth);
  706. }
  707. }
  708. }
  709. if (mode === 'relative') {
  710. url = getRelativePath(host + pathname, 0).substr(2);
  711. } else if (mode === 'absolute') {
  712. if (url.substr(0, host.length) === host) {
  713. url = url.substr(host.length);
  714. }
  715. }
  716. return url;
  717. }
  718. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  719. if (html == null) {
  720. html = '';
  721. }
  722. urlType = urlType || '';
  723. wellFormatted = _undef(wellFormatted, false);
  724. indentChar = _undef(indentChar, '\t');
  725. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  726. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  727. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  728. });
  729. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  730. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  731. html = html.replace(/\u200B/g, '');
  732. html = html.replace(/\u00A9/g, '&copy;');
  733. html = html.replace(/\u00AE/g, '&reg;');
  734. /* Knaan@2014-07-23 添加:格式化html时子元素前的两个全角空格替换为&emsp;,防止被trim */
  735. html = html.replace(/\u2003/g, '&emsp;');
  736. html = html.replace(/\u3000/g, '&emsp;');
  737. html = html.replace(/<[^>]+/g, function($0) {
  738. return $0.replace(/\s+/g, ' ');
  739. });
  740. var htmlTagMap = {};
  741. if (htmlTags) {
  742. _each(htmlTags, function(key, val) {
  743. var arr = key.split(',');
  744. for (var i = 0, len = arr.length; i < len; i++) {
  745. htmlTagMap[arr[i]] = _toMap(val);
  746. }
  747. });
  748. if (!htmlTagMap.script) {
  749. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  750. }
  751. if (!htmlTagMap.style) {
  752. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  753. }
  754. }
  755. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  756. var tagStack = [];
  757. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  758. var full = $0,
  759. startNewline = $1 || '',
  760. startSlash = $2 || '',
  761. tagName = $3.toLowerCase(),
  762. attr = $4 || '',
  763. endSlash = $5 ? ' ' + $5 : '',
  764. endNewline = $6 || '';
  765. if (htmlTags && !htmlTagMap[tagName]) {
  766. return '';
  767. }
  768. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  769. endSlash = ' /';
  770. }
  771. if (_INLINE_TAG_MAP[tagName]) {
  772. if (startNewline) {
  773. startNewline = ' ';
  774. }
  775. if (endNewline) {
  776. endNewline = ' ';
  777. }
  778. }
  779. if (_PRE_TAG_MAP[tagName]) {
  780. if (startSlash) {
  781. endNewline = '\n';
  782. } else {
  783. startNewline = '\n';
  784. }
  785. }
  786. if (wellFormatted && tagName == 'br') {
  787. endNewline = '\n';
  788. }
  789. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  790. if (wellFormatted) {
  791. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  792. tagStack.pop();
  793. } else {
  794. tagStack.push(tagName);
  795. }
  796. startNewline = '\n';
  797. endNewline = '\n';
  798. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  799. startNewline += indentChar;
  800. if (!startSlash) {
  801. endNewline += indentChar;
  802. }
  803. }
  804. if (endSlash) {
  805. tagStack.pop();
  806. } else if (!startSlash) {
  807. endNewline += indentChar;
  808. }
  809. } else {
  810. startNewline = endNewline = '';
  811. }
  812. }
  813. if (attr !== '') {
  814. var attrMap = _getAttrList(full);
  815. if (tagName === 'font') {
  816. var fontStyleMap = {}, fontStyle = '';
  817. _each(attrMap, function(key, val) {
  818. if (key === 'color') {
  819. fontStyleMap.color = val;
  820. delete attrMap[key];
  821. }
  822. if (key === 'size') {
  823. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  824. delete attrMap[key];
  825. }
  826. if (key === 'face') {
  827. fontStyleMap['font-family'] = val;
  828. delete attrMap[key];
  829. }
  830. if (key === 'style') {
  831. fontStyle = val;
  832. }
  833. });
  834. if (fontStyle && !/;$/.test(fontStyle)) {
  835. fontStyle += ';';
  836. }
  837. _each(fontStyleMap, function(key, val) {
  838. if (val === '') {
  839. return;
  840. }
  841. if (/\s/.test(val)) {
  842. val = "'" + val + "'";
  843. }
  844. fontStyle += key + ':' + val + ';';
  845. });
  846. attrMap.style = fontStyle;
  847. }
  848. _each(attrMap, function(key, val) {
  849. if (_FILL_ATTR_MAP[key]) {
  850. attrMap[key] = key;
  851. }
  852. if (_inArray(key, ['src', 'href']) >= 0) {
  853. attrMap[key] = _formatUrl(val, urlType);
  854. }
  855. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  856. tagName === 'body' && key === 'contenteditable' ||
  857. /^kindeditor_\d+$/.test(key)) {
  858. delete attrMap[key];
  859. }
  860. if (key === 'style' && val !== '') {
  861. var styleMap = _getCssList(val);
  862. _each(styleMap, function(k, v) {
  863. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  864. delete styleMap[k];
  865. }
  866. });
  867. var style = '';
  868. _each(styleMap, function(k, v) {
  869. style += k + ':' + v + ';';
  870. });
  871. attrMap.style = style;
  872. }
  873. });
  874. attr = '';
  875. _each(attrMap, function(key, val) {
  876. if (key === 'style' && val === '') {
  877. return;
  878. }
  879. val = val.replace(/"/g, '&quot;');
  880. attr += ' ' + key + '="' + val + '"';
  881. });
  882. }
  883. if (tagName === 'font') {
  884. tagName = 'span';
  885. }
  886. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  887. });
  888. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  889. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  890. });
  891. html = html.replace(/\n\s*\n/g, '\n');
  892. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  893. return _trim(html);
  894. }
  895. function _clearMsWord(html, htmlTags) {
  896. html = html.replace(/<meta[\s\S]*?>/ig, '')
  897. .replace(/<![\s\S]*?>/ig, '')
  898. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  899. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  900. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  901. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  902. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  903. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  904. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  905. });
  906. return _formatHtml(html, htmlTags);
  907. }
  908. function _mediaType(src) {
  909. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  910. return 'audio/x-pn-realaudio-plugin';
  911. }
  912. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  913. return 'application/x-shockwave-flash';
  914. }
  915. return 'video/x-ms-asf-plugin';
  916. }
  917. function _mediaClass(type) {
  918. if (/realaudio/i.test(type)) {
  919. return 'ke-rm';
  920. }
  921. if (/flash/i.test(type)) {
  922. return 'ke-flash';
  923. }
  924. return 'ke-media';
  925. }
  926. function _mediaAttrs(srcTag) {
  927. return _getAttrList(unescape(srcTag));
  928. }
  929. function _mediaEmbed(attrs) {
  930. var html = '<embed ';
  931. _each(attrs, function(key, val) {
  932. html += key + '="' + val + '" ';
  933. });
  934. html += '/>';
  935. return html;
  936. }
  937. function _mediaImg(blankPath, attrs) {
  938. var width = attrs.width,
  939. height = attrs.height,
  940. type = attrs.type || _mediaType(attrs.src),
  941. srcTag = _mediaEmbed(attrs),
  942. style = '';
  943. if (/\D/.test(width)) {
  944. style += 'width:' + width + ';';
  945. } else if (width > 0) {
  946. style += 'width:' + width + 'px;';
  947. }
  948. if (/\D/.test(height)) {
  949. style += 'height:' + height + ';';
  950. } else if (height > 0) {
  951. style += 'height:' + height + 'px;';
  952. }
  953. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  954. if (style !== '') {
  955. html += 'style="' + style + '" ';
  956. }
  957. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  958. return html;
  959. }
  960. function _tmpl(str, data) {
  961. var fn = new Function("obj",
  962. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  963. "with(obj){p.push('" +
  964. str.replace(/[\r\t\n]/g, " ")
  965. .split("<%").join("\t")
  966. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  967. .replace(/\t=(.*?)%>/g, "',$1,'")
  968. .split("\t").join("');")
  969. .split("%>").join("p.push('")
  970. .split("\r").join("\\'") + "');}return p.join('');");
  971. return data ? fn(data) : fn;
  972. }
  973. K.formatUrl = _formatUrl;
  974. K.formatHtml = _formatHtml;
  975. K.getCssList = _getCssList;
  976. K.getAttrList = _getAttrList;
  977. K.mediaType = _mediaType;
  978. K.mediaAttrs = _mediaAttrs;
  979. K.mediaEmbed = _mediaEmbed;
  980. K.mediaImg = _mediaImg;
  981. K.clearMsWord = _clearMsWord;
  982. K.tmpl = _tmpl;
  983. function _contains(nodeA, nodeB) {
  984. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  985. return true;
  986. }
  987. while ((nodeB = nodeB.parentNode)) {
  988. if (nodeB == nodeA) {
  989. return true;
  990. }
  991. }
  992. return false;
  993. }
  994. var _getSetAttrDiv = document.createElement('div');
  995. _getSetAttrDiv.setAttribute('className', 't');
  996. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  997. function _getAttr(el, key) {
  998. key = key.toLowerCase();
  999. var val = null;
  1000. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  1001. var div = el.ownerDocument.createElement('div');
  1002. div.appendChild(el.cloneNode(false));
  1003. var list = _getAttrList(_unescape(div.innerHTML));
  1004. if (key in list) {
  1005. val = list[key];
  1006. }
  1007. } else {
  1008. try {
  1009. val = el.getAttribute(key, 2);
  1010. } catch(e) {
  1011. val = el.getAttribute(key, 1);
  1012. }
  1013. }
  1014. if (key === 'style' && val !== null) {
  1015. val = _formatCss(val);
  1016. }
  1017. return val;
  1018. }
  1019. function _queryAll(expr, root) {
  1020. var exprList = expr.split(',');
  1021. if (exprList.length > 1) {
  1022. var mergedResults = [];
  1023. _each(exprList, function() {
  1024. _each(_queryAll(this, root), function() {
  1025. if (_inArray(this, mergedResults) < 0) {
  1026. mergedResults.push(this);
  1027. }
  1028. });
  1029. });
  1030. return mergedResults;
  1031. }
  1032. root = root || document;
  1033. function escape(str) {
  1034. if (typeof str != 'string') {
  1035. return str;
  1036. }
  1037. return str.replace(/([^\w\-])/g, '\\$1');
  1038. }
  1039. function stripslashes(str) {
  1040. return str.replace(/\\/g, '');
  1041. }
  1042. function cmpTag(tagA, tagB) {
  1043. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1044. }
  1045. function byId(id, tag, root) {
  1046. var arr = [],
  1047. doc = root.ownerDocument || root,
  1048. el = doc.getElementById(stripslashes(id));
  1049. if (el) {
  1050. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1051. arr.push(el);
  1052. }
  1053. }
  1054. return arr;
  1055. }
  1056. function byClass(className, tag, root) {
  1057. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1058. if (root.getElementsByClassName) {
  1059. els = root.getElementsByClassName(stripslashes(className));
  1060. for (i = 0, len = els.length; i < len; i++) {
  1061. el = els[i];
  1062. if (cmpTag(tag, el.nodeName)) {
  1063. arr.push(el);
  1064. }
  1065. }
  1066. } else if (doc.querySelectorAll) {
  1067. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1068. for (i = 0, len = els.length; i < len; i++) {
  1069. el = els[i];
  1070. if (_contains(root, el)) {
  1071. arr.push(el);
  1072. }
  1073. }
  1074. } else {
  1075. els = root.getElementsByTagName(tag);
  1076. className = ' ' + className + ' ';
  1077. for (i = 0, len = els.length; i < len; i++) {
  1078. el = els[i];
  1079. if (el.nodeType == 1) {
  1080. var cls = el.className;
  1081. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1082. arr.push(el);
  1083. }
  1084. }
  1085. }
  1086. }
  1087. return arr;
  1088. }
  1089. function byName(name, tag, root) {
  1090. var arr = [], doc = root.ownerDocument || root,
  1091. els = doc.getElementsByName(stripslashes(name)), el;
  1092. for (var i = 0, len = els.length; i < len; i++) {
  1093. el = els[i];
  1094. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1095. if (el.getAttribute('name') !== null) {
  1096. arr.push(el);
  1097. }
  1098. }
  1099. }
  1100. return arr;
  1101. }
  1102. function byAttr(key, val, tag, root) {
  1103. var arr = [], els = root.getElementsByTagName(tag), el;
  1104. for (var i = 0, len = els.length; i < len; i++) {
  1105. el = els[i];
  1106. if (el.nodeType == 1) {
  1107. if (val === null) {
  1108. if (_getAttr(el, key) !== null) {
  1109. arr.push(el);
  1110. }
  1111. } else {
  1112. if (val === escape(_getAttr(el, key))) {
  1113. arr.push(el);
  1114. }
  1115. }
  1116. }
  1117. }
  1118. return arr;
  1119. }
  1120. function select(expr, root) {
  1121. var arr = [], matches;
  1122. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1123. var tag = matches ? matches[1] : '*';
  1124. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1125. arr = byId(matches[1], tag, root);
  1126. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1127. arr = byClass(matches[1], tag, root);
  1128. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1129. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1130. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1131. var key = matches[1].toLowerCase(), val = matches[2];
  1132. if (key === 'id') {
  1133. arr = byId(val, tag, root);
  1134. } else if (key === 'class') {
  1135. arr = byClass(val, tag, root);
  1136. } else if (key === 'name') {
  1137. arr = byName(val, tag, root);
  1138. } else {
  1139. arr = byAttr(key, val, tag, root);
  1140. }
  1141. } else {
  1142. var els = root.getElementsByTagName(tag), el;
  1143. for (var i = 0, len = els.length; i < len; i++) {
  1144. el = els[i];
  1145. if (el.nodeType == 1) {
  1146. arr.push(el);
  1147. }
  1148. }
  1149. }
  1150. return arr;
  1151. }
  1152. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1153. while ((arr = re.exec(expr))) {
  1154. if (arr[1] !== ' ') {
  1155. parts.push(arr[1]);
  1156. }
  1157. }
  1158. var results = [];
  1159. if (parts.length == 1) {
  1160. return select(parts[0], root);
  1161. }
  1162. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1163. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1164. part = parts[i];
  1165. if (part === '>') {
  1166. isChild = true;
  1167. continue;
  1168. }
  1169. if (i > 0) {
  1170. els = [];
  1171. for (j = 0, len = results.length; j < len; j++) {
  1172. val = results[j];
  1173. subResults = select(part, val);
  1174. for (k = 0, l = subResults.length; k < l; k++) {
  1175. v = subResults[k];
  1176. if (isChild) {
  1177. if (val === v.parentNode) {
  1178. els.push(v);
  1179. }
  1180. } else {
  1181. els.push(v);
  1182. }
  1183. }
  1184. }
  1185. results = els;
  1186. } else {
  1187. results = select(part, root);
  1188. }
  1189. if (results.length === 0) {
  1190. return [];
  1191. }
  1192. }
  1193. return results;
  1194. }
  1195. function _query(expr, root) {
  1196. var arr = _queryAll(expr, root);
  1197. return arr.length > 0 ? arr[0] : null;
  1198. }
  1199. K.query = _query;
  1200. K.queryAll = _queryAll;
  1201. function _get(val) {
  1202. return K(val)[0];
  1203. }
  1204. function _getDoc(node) {
  1205. if (!node) {
  1206. return document;
  1207. }
  1208. return node.ownerDocument || node.document || node;
  1209. }
  1210. function _getWin(node) {
  1211. if (!node) {
  1212. return window;
  1213. }
  1214. var doc = _getDoc(node);
  1215. return doc.parentWindow || doc.defaultView;
  1216. }
  1217. function _setHtml(el, html) {
  1218. if (el.nodeType != 1) {
  1219. return;
  1220. }
  1221. var doc = _getDoc(el);
  1222. try {
  1223. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1224. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1225. temp.parentNode.removeChild(temp);
  1226. } catch(e) {
  1227. K(el).empty();
  1228. K('@' + html, doc).each(function() {
  1229. el.appendChild(this);
  1230. });
  1231. }
  1232. }
  1233. function _hasClass(el, cls) {
  1234. return _inString(cls, el.className, ' ');
  1235. }
  1236. function _setAttr(el, key, val) {
  1237. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1238. key = 'className';
  1239. }
  1240. el.setAttribute(key, '' + val);
  1241. }
  1242. function _removeAttr(el, key) {
  1243. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1244. key = 'className';
  1245. }
  1246. _setAttr(el, key, '');
  1247. el.removeAttribute(key);
  1248. }
  1249. function _getNodeName(node) {
  1250. if (!node || !node.nodeName) {
  1251. return '';
  1252. }
  1253. return node.nodeName.toLowerCase();
  1254. }
  1255. function _computedCss(el, key) {
  1256. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1257. if (win.getComputedStyle) {
  1258. var style = win.getComputedStyle(el, null);
  1259. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1260. } else if (el.currentStyle) {
  1261. val = el.currentStyle[camelKey] || el.style[camelKey];
  1262. }
  1263. return val;
  1264. }
  1265. function _hasVal(node) {
  1266. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1267. }
  1268. function _docElement(doc) {
  1269. doc = doc || document;
  1270. return _QUIRKS ? doc.body : doc.documentElement;
  1271. }
  1272. function _docHeight(doc) {
  1273. var el = _docElement(doc);
  1274. return Math.max(el.scrollHeight, el.clientHeight);
  1275. }
  1276. function _docWidth(doc) {
  1277. var el = _docElement(doc);
  1278. return Math.max(el.scrollWidth, el.clientWidth);
  1279. }
  1280. function _getScrollPos(doc) {
  1281. doc = doc || document;
  1282. var x, y;
  1283. if (_IE || _NEWIE || _OPERA) {
  1284. x = _docElement(doc).scrollLeft;
  1285. y = _docElement(doc).scrollTop;
  1286. } else {
  1287. x = _getWin(doc).scrollX;
  1288. y = _getWin(doc).scrollY;
  1289. }
  1290. return {x : x, y : y};
  1291. }
  1292. function KNode(node) {
  1293. this.init(node);
  1294. }
  1295. _extend(KNode, {
  1296. init : function(node) {
  1297. var self = this;
  1298. node = _isArray(node) ? node : [node];
  1299. var length = 0;
  1300. for (var i = 0, len = node.length; i < len; i++) {
  1301. if (node[i]) {
  1302. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1303. length++;
  1304. }
  1305. }
  1306. self.length = length;
  1307. self.doc = _getDoc(self[0]);
  1308. self.name = _getNodeName(self[0]);
  1309. self.type = self.length > 0 ? self[0].nodeType : null;
  1310. self.win = _getWin(self[0]);
  1311. },
  1312. each : function(fn) {
  1313. var self = this;
  1314. for (var i = 0; i < self.length; i++) {
  1315. if (fn.call(self[i], i, self[i]) === false) {
  1316. return self;
  1317. }
  1318. }
  1319. return self;
  1320. },
  1321. bind : function(type, fn) {
  1322. this.each(function() {
  1323. _bind(this, type, fn);
  1324. });
  1325. return this;
  1326. },
  1327. unbind : function(type, fn) {
  1328. this.each(function() {
  1329. _unbind(this, type, fn);
  1330. });
  1331. return this;
  1332. },
  1333. fire : function(type) {
  1334. if (this.length < 1) {
  1335. return this;
  1336. }
  1337. _fire(this[0], type);
  1338. return this;
  1339. },
  1340. hasAttr : function(key) {
  1341. if (this.length < 1) {
  1342. return false;
  1343. }
  1344. return !!_getAttr(this[0], key);
  1345. },
  1346. attr : function(key, val) {
  1347. var self = this;
  1348. if (key === undefined) {
  1349. return _getAttrList(self.outer());
  1350. }
  1351. if (typeof key === 'object') {
  1352. _each(key, function(k, v) {
  1353. self.attr(k, v);
  1354. });
  1355. return self;
  1356. }
  1357. if (val === undefined) {
  1358. val = self.length < 1 ? null : _getAttr(self[0], key);
  1359. return val === null ? '' : val;
  1360. }
  1361. self.each(function() {
  1362. _setAttr(this, key, val);
  1363. });
  1364. return self;
  1365. },
  1366. removeAttr : function(key) {
  1367. this.each(function() {
  1368. _removeAttr(this, key);
  1369. });
  1370. return this;
  1371. },
  1372. get : function(i) {
  1373. if (this.length < 1) {
  1374. return null;
  1375. }
  1376. return this[i || 0];
  1377. },
  1378. eq : function(i) {
  1379. if (this.length < 1) {
  1380. return null;
  1381. }
  1382. return this[i] ? new KNode(this[i]) : null;
  1383. },
  1384. hasClass : function(cls) {
  1385. if (this.length < 1) {
  1386. return false;
  1387. }
  1388. return _hasClass(this[0], cls);
  1389. },
  1390. addClass : function(cls) {
  1391. this.each(function() {
  1392. if (!_hasClass(this, cls)) {
  1393. this.className = _trim(this.className + ' ' + cls);
  1394. }
  1395. });
  1396. return this;
  1397. },
  1398. removeClass : function(cls) {
  1399. this.each(function() {
  1400. if (_hasClass(this, cls)) {
  1401. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1402. }
  1403. });
  1404. return this;
  1405. },
  1406. html : function(val) {
  1407. var self = this;
  1408. if (val === undefined) {
  1409. if (self.length < 1 || self.type != 1) {
  1410. return '';
  1411. }
  1412. return _formatHtml(self[0].innerHTML);
  1413. }
  1414. self.each(function() {
  1415. _setHtml(this, val);
  1416. });
  1417. return self;
  1418. },
  1419. text : function() {
  1420. var self = this;
  1421. if (self.length < 1) {
  1422. return '';
  1423. }
  1424. return _IE ? self[0].innerText : self[0].textContent;
  1425. },
  1426. hasVal : function() {
  1427. if (this.length < 1) {
  1428. return false;
  1429. }
  1430. return _hasVal(this[0]);
  1431. },
  1432. val : function(val) {
  1433. var self = this;
  1434. if (val === undefined) {
  1435. if (self.length < 1) {
  1436. return '';
  1437. }
  1438. return self.hasVal() ? self[0].value : self.attr('value');
  1439. } else {
  1440. self.each(function() {
  1441. if (_hasVal(this)) {
  1442. this.value = val;
  1443. } else {
  1444. _setAttr(this, 'value' , val);
  1445. }
  1446. });
  1447. return self;
  1448. }
  1449. },
  1450. css : function(key, val) {
  1451. var self = this;
  1452. if (key === undefined) {
  1453. return _getCssList(self.attr('style'));
  1454. }
  1455. if (typeof key === 'object') {
  1456. _each(key, function(k, v) {
  1457. self.css(k, v);
  1458. });
  1459. return self;
  1460. }
  1461. if (val === undefined) {
  1462. if (self.length < 1) {
  1463. return '';
  1464. }
  1465. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1466. }
  1467. self.each(function() {
  1468. this.style[_toCamel(key)] = val;
  1469. });
  1470. return self;
  1471. },
  1472. width : function(val) {
  1473. var self = this;
  1474. if (val === undefined) {
  1475. if (self.length < 1) {
  1476. return 0;
  1477. }
  1478. return self[0].offsetWidth;
  1479. }
  1480. return self.css('width', _addUnit(val));
  1481. },
  1482. height : function(val) {
  1483. var self = this;
  1484. if (val === undefined) {
  1485. if (self.length < 1) {
  1486. return 0;
  1487. }
  1488. return self[0].offsetHeight;
  1489. }
  1490. return self.css('height', _addUnit(val));
  1491. },
  1492. opacity : function(val) {
  1493. this.each(function() {
  1494. if (this.style.opacity === undefined) {
  1495. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1496. } else {
  1497. this.style.opacity = val == 1 ? '' : val;
  1498. }
  1499. });
  1500. return this;
  1501. },
  1502. data : function(key, val) {
  1503. var self = this;
  1504. key = 'kindeditor_data_' + key;
  1505. if (val === undefined) {
  1506. if (self.length < 1) {
  1507. return null;
  1508. }
  1509. return self[0][key];
  1510. }
  1511. this.each(function() {
  1512. this[key] = val;
  1513. });
  1514. return self;
  1515. },
  1516. pos : function() {
  1517. var self = this, node = self[0], x = 0, y = 0;
  1518. if (node) {
  1519. if (node.getBoundingClientRect) {
  1520. var box = node.getBoundingClientRect(),
  1521. pos = _getScrollPos(self.doc);
  1522. x = box.left + pos.x;
  1523. y = box.top + pos.y;
  1524. } else {
  1525. while (node) {
  1526. x += node.offsetLeft;
  1527. y += node.offsetTop;
  1528. node = node.offsetParent;
  1529. }
  1530. }
  1531. }
  1532. return {x : _round(x), y : _round(y)};
  1533. },
  1534. clone : function(bool) {
  1535. if (this.length < 1) {
  1536. return new KNode([]);
  1537. }
  1538. return new KNode(this[0].cloneNode(bool));
  1539. },
  1540. append : function(expr) {
  1541. this.each(function() {
  1542. if (this.appendChild) {
  1543. this.appendChild(_get(expr));
  1544. }
  1545. });
  1546. return this;
  1547. },
  1548. appendTo : function(expr) {
  1549. this.each(function() {
  1550. _get(expr).appendChild(this);
  1551. });
  1552. return this;
  1553. },
  1554. before : function(expr) {
  1555. this.each(function() {
  1556. this.parentNode.insertBefore(_get(expr), this);
  1557. });
  1558. return this;
  1559. },
  1560. after : function(expr) {
  1561. this.each(function() {
  1562. if (this.nextSibling) {
  1563. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1564. } else {
  1565. this.parentNode.appendChild(_get(expr));
  1566. }
  1567. });
  1568. return this;
  1569. },
  1570. replaceWith : function(expr) {
  1571. var nodes = [];
  1572. this.each(function(i, node) {
  1573. _unbind(node);
  1574. var newNode = _get(expr);
  1575. node.parentNode.replaceChild(newNode, node);
  1576. nodes.push(newNode);
  1577. });
  1578. return K(nodes);
  1579. },
  1580. empty : function() {
  1581. var self = this;
  1582. self.each(function(i, node) {
  1583. var child = node.firstChild;
  1584. while (child) {
  1585. if (!node.parentNode) {
  1586. return;
  1587. }
  1588. var next = child.nextSibling;
  1589. child.parentNode.removeChild(child);
  1590. child = next;
  1591. }
  1592. });
  1593. return self;
  1594. },
  1595. remove : function(keepChilds) {
  1596. var self = this;
  1597. self.each(function(i, node) {
  1598. if (!node.parentNode) {
  1599. return;
  1600. }
  1601. _unbind(node);
  1602. if (keepChilds) {
  1603. var child = node.firstChild;
  1604. while (child) {
  1605. var next = child.nextSibling;
  1606. node.parentNode.insertBefore(child, node);
  1607. child = next;
  1608. }
  1609. }
  1610. node.parentNode.removeChild(node);
  1611. delete self[i];
  1612. });
  1613. self.length = 0;
  1614. return self;
  1615. },
  1616. show : function(val) {
  1617. var self = this;
  1618. if (val === undefined) {
  1619. val = self._originDisplay || '';
  1620. }
  1621. if (self.css('display') != 'none') {
  1622. return self;
  1623. }
  1624. return self.css('display', val);
  1625. },
  1626. hide : function() {
  1627. var self = this;
  1628. if (self.length < 1) {
  1629. return self;
  1630. }
  1631. self._originDisplay = self[0].style.display;
  1632. return self.css('display', 'none');
  1633. },
  1634. outer : function() {
  1635. var self = this;
  1636. if (self.length < 1) {
  1637. return '';
  1638. }
  1639. var div = self.doc.createElement('div'), html;
  1640. div.appendChild(self[0].cloneNode(true));
  1641. html = _formatHtml(div.innerHTML);
  1642. div = null;
  1643. return html;
  1644. },
  1645. isSingle : function() {
  1646. return !!_SINGLE_TAG_MAP[this.name];
  1647. },
  1648. isInline : function() {
  1649. return !!_INLINE_TAG_MAP[this.name];
  1650. },
  1651. isBlock : function() {
  1652. return !!_BLOCK_TAG_MAP[this.name];
  1653. },
  1654. isStyle : function() {
  1655. return !!_STYLE_TAG_MAP[this.name];
  1656. },
  1657. isControl : function() {
  1658. return !!_CONTROL_TAG_MAP[this.name];
  1659. },
  1660. contains : function(otherNode) {
  1661. if (this.length < 1) {
  1662. return false;
  1663. }
  1664. return _contains(this[0], _get(otherNode));
  1665. },
  1666. parent : function() {
  1667. if (this.length < 1) {
  1668. return null;
  1669. }
  1670. var node = this[0].parentNode;
  1671. return node ? new KNode(node) : null;
  1672. },
  1673. children : function() {
  1674. if (this.length < 1) {
  1675. return new KNode([]);
  1676. }
  1677. var list = [], child = this[0].firstChild;
  1678. while (child) {
  1679. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1680. list.push(child);
  1681. }
  1682. child = child.nextSibling;
  1683. }
  1684. return new KNode(list);
  1685. },
  1686. first : function() {
  1687. var list = this.children();
  1688. return list.length > 0 ? list.eq(0) : null;
  1689. },
  1690. last : function() {
  1691. var list = this.children();
  1692. return list.length > 0 ? list.eq(list.length - 1) : null;
  1693. },
  1694. index : function() {
  1695. if (this.length < 1) {
  1696. return -1;
  1697. }
  1698. var i = -1, sibling = this[0];
  1699. while (sibling) {
  1700. i++;
  1701. sibling = sibling.previousSibling;
  1702. }
  1703. return i;
  1704. },
  1705. prev : function() {
  1706. if (this.length < 1) {
  1707. return null;
  1708. }
  1709. var node = this[0].previousSibling;
  1710. return node ? new KNode(node) : null;
  1711. },
  1712. next : function() {
  1713. if (this.length < 1) {
  1714. return null;
  1715. }
  1716. var node = this[0].nextSibling;
  1717. return node ? new KNode(node) : null;
  1718. },
  1719. scan : function(fn, order) {
  1720. if (this.length < 1) {
  1721. return;
  1722. }
  1723. order = (order === undefined) ? true : order;
  1724. function walk(node) {
  1725. var n = order ? node.firstChild : node.lastChild;
  1726. while (n) {
  1727. var next = order ? n.nextSibling : n.previousSibling;
  1728. if (fn(n) === false) {
  1729. return false;
  1730. }
  1731. if (walk(n) === false) {
  1732. return false;
  1733. }
  1734. n = next;
  1735. }
  1736. }
  1737. walk(this[0]);
  1738. return this;
  1739. }
  1740. });
  1741. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1742. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1743. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1744. KNode.prototype[type] = function(fn) {
  1745. return fn ? this.bind(type, fn) : this.fire(type);
  1746. };
  1747. });
  1748. var _K = K;
  1749. K = function(expr, root) {
  1750. if (expr === undefined || expr === null) {
  1751. return;
  1752. }
  1753. function newNode(node) {
  1754. if (!node[0]) {
  1755. node = [];
  1756. }
  1757. return new KNode(node);
  1758. }
  1759. if (typeof expr === 'string') {
  1760. if (root) {
  1761. root = _get(root);
  1762. }
  1763. var length = expr.length;
  1764. if (expr.charAt(0) === '@') {
  1765. expr = expr.substr(1);
  1766. }
  1767. if (expr.length !== length || /<.+>/.test(expr)) {
  1768. var doc = root ? root.ownerDocument || root : document,
  1769. div = doc.createElement('div'), list = [];
  1770. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1771. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1772. var child = div.childNodes[i];
  1773. if (child.id == '__kindeditor_temp_tag__') {
  1774. continue;
  1775. }
  1776. list.push(child);
  1777. }
  1778. return newNode(list);
  1779. }
  1780. return newNode(_queryAll(expr, root));
  1781. }
  1782. if (expr && expr.constructor === KNode) {
  1783. return expr;
  1784. }
  1785. if (expr.toArray) {
  1786. expr = expr.toArray();
  1787. }
  1788. if (_isArray(expr)) {
  1789. return newNode(expr);
  1790. }
  1791. return newNode(_toArray(arguments));
  1792. };
  1793. _each(_K, function(key, val) {
  1794. K[key] = val;
  1795. });
  1796. K.NodeClass = KNode;
  1797. window.KindEditor = K;
  1798. var _START_TO_START = 0,
  1799. _START_TO_END = 1,
  1800. _END_TO_END = 2,
  1801. _END_TO_START = 3,
  1802. _BOOKMARK_ID = 0;
  1803. function _updateCollapsed(range) {
  1804. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1805. return range;
  1806. }
  1807. function _copyAndDelete(range, isCopy, isDelete) {
  1808. var doc = range.doc, nodeList = [];
  1809. function splitTextNode(node, startOffset, endOffset) {
  1810. var length = node.nodeValue.length, centerNode;
  1811. if (isCopy) {
  1812. var cloneNode = node.cloneNode(true);
  1813. if (startOffset > 0) {
  1814. centerNode = cloneNode.splitText(startOffset);
  1815. } else {
  1816. centerNode = cloneNode;
  1817. }
  1818. if (endOffset < length) {
  1819. centerNode.splitText(endOffset - startOffset);
  1820. }
  1821. }
  1822. if (isDelete) {
  1823. var center = node;
  1824. if (startOffset > 0) {
  1825. center = node.splitText(startOffset);
  1826. range.setStart(node, startOffset);
  1827. }
  1828. if (endOffset < length) {
  1829. var right = center.splitText(endOffset - startOffset);
  1830. range.setEnd(right, 0);
  1831. }
  1832. nodeList.push(center);
  1833. }
  1834. return centerNode;
  1835. }
  1836. function removeNodes() {
  1837. if (isDelete) {
  1838. range.up().collapse(true);
  1839. }
  1840. for (var i = 0, len = nodeList.length; i < len; i++) {
  1841. var node = nodeList[i];
  1842. if (node.parentNode) {
  1843. node.parentNode.removeChild(node);
  1844. }
  1845. }
  1846. }
  1847. var copyRange = range.cloneRange().down();
  1848. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1849. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1850. if (ancestor.nodeType == 3) {
  1851. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1852. if (isCopy) {
  1853. frag.appendChild(textNode);
  1854. }
  1855. removeNodes();
  1856. return isCopy ? frag : range;
  1857. }
  1858. function extractNodes(parent, frag) {
  1859. var node = parent.firstChild, nextNode;
  1860. while (node) {
  1861. var testRange = new KRange(doc).selectNode(node);
  1862. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1863. if (start >= 0 && incStart <= 0) {
  1864. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1865. }
  1866. if (incStart >= 0 && incEnd <= 0) {
  1867. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1868. }
  1869. if (incEnd >= 0 && end <= 0) {
  1870. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1871. }
  1872. if (end >= 0) {
  1873. return false;
  1874. }
  1875. nextNode = node.nextSibling;
  1876. if (start > 0) {
  1877. if (node.nodeType == 1) {
  1878. if (incStart >= 0 && incEnd <= 0) {
  1879. if (isCopy) {
  1880. frag.appendChild(node.cloneNode(true));
  1881. }
  1882. if (isDelete) {
  1883. nodeList.push(node);
  1884. }
  1885. } else {
  1886. var childFlag;
  1887. if (isCopy) {
  1888. childFlag = node.cloneNode(false);
  1889. frag.appendChild(childFlag);
  1890. }
  1891. if (extractNodes(node, childFlag) === false) {
  1892. return false;
  1893. }
  1894. }
  1895. } else if (node.nodeType == 3) {
  1896. var textNode;
  1897. if (node == copyRange.startContainer) {
  1898. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1899. } else if (node == copyRange.endContainer) {
  1900. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1901. } else {
  1902. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1903. }
  1904. if (isCopy) {
  1905. try {
  1906. frag.appendChild(textNode);
  1907. } catch(e) {}
  1908. }
  1909. }
  1910. }
  1911. node = nextNode;
  1912. }
  1913. }
  1914. extractNodes(ancestor, frag);
  1915. if (isDelete) {
  1916. range.up().collapse(true);
  1917. }
  1918. for (var i = 0, len = nodeList.length; i < len; i++) {
  1919. var node = nodeList[i];
  1920. if (node.parentNode) {
  1921. node.parentNode.removeChild(node);
  1922. }
  1923. }
  1924. return isCopy ? frag : range;
  1925. }
  1926. function _moveToElementText(range, el) {
  1927. var node = el;
  1928. while (node) {
  1929. var knode = K(node);
  1930. if (knode.name == 'marquee' || knode.name == 'select') {
  1931. return;
  1932. }
  1933. node = node.parentNode;
  1934. }
  1935. try {
  1936. range.moveToElementText(el);
  1937. } catch(e) {}
  1938. }
  1939. function _getStartEnd(rng, isStart) {
  1940. var doc = rng.parentElement().ownerDocument,
  1941. pointRange = rng.duplicate();
  1942. pointRange.collapse(isStart);
  1943. var parent = pointRange.parentElement(),
  1944. nodes = parent.childNodes;
  1945. if (nodes.length === 0) {
  1946. return {node: parent.parentNode, offset: K(parent).index()};
  1947. }
  1948. var startNode = doc, startPos = 0, cmp = -1;
  1949. var testRange = rng.duplicate();
  1950. _moveToElementText(testRange, parent);
  1951. for (var i = 0, len = nodes.length; i < len; i++) {
  1952. var node = nodes[i];
  1953. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1954. if (cmp === 0) {
  1955. return {node: node.parentNode, offset: i};
  1956. }
  1957. if (node.nodeType == 1) {
  1958. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1959. if (knode.isControl()) {
  1960. dummy = doc.createElement('span');
  1961. knode.after(dummy);
  1962. newNode = dummy;
  1963. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1964. }
  1965. _moveToElementText(nodeRange, newNode);
  1966. testRange.setEndPoint('StartToEnd', nodeRange);
  1967. if (cmp > 0) {
  1968. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1969. } else {
  1970. startPos = 0;
  1971. }
  1972. if (dummy) {
  1973. K(dummy).remove();
  1974. }
  1975. } else if (node.nodeType == 3) {
  1976. testRange.moveStart('character', node.nodeValue.length);
  1977. startPos += node.nodeValue.length;
  1978. }
  1979. if (cmp < 0) {
  1980. startNode = node;
  1981. }
  1982. }
  1983. if (cmp < 0 && startNode.nodeType == 1) {
  1984. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1985. }
  1986. if (cmp > 0) {
  1987. while (startNode.nextSibling && startNode.nodeType == 1) {
  1988. startNode = startNode.nextSibling;
  1989. }
  1990. }
  1991. testRange = rng.duplicate();
  1992. _moveToElementText(testRange, parent);
  1993. testRange.setEndPoint('StartToEnd', pointRange);
  1994. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  1995. if (cmp > 0 && startNode.nodeType == 3) {
  1996. var prevNode = startNode.previousSibling;
  1997. while (prevNode && prevNode.nodeType == 3) {
  1998. startPos -= prevNode.nodeValue.length;
  1999. prevNode = prevNode.previousSibling;
  2000. }
  2001. }
  2002. return {node: startNode, offset: startPos};
  2003. }
  2004. function _getEndRange(node, offset) {
  2005. var doc = node.ownerDocument || node,
  2006. range = doc.body.createTextRange();
  2007. if (doc == node) {
  2008. range.collapse(true);
  2009. return range;
  2010. }
  2011. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2012. var children = node.childNodes, isStart, child;
  2013. if (offset === 0) {
  2014. child = children[0];
  2015. isStart = true;
  2016. } else {
  2017. child = children[offset - 1];
  2018. isStart = false;
  2019. }
  2020. if (!child) {
  2021. return range;
  2022. }
  2023. if (K(child).name === 'head') {
  2024. if (offset === 1) {
  2025. isStart = true;
  2026. }
  2027. if (offset === 2) {
  2028. isStart = false;
  2029. }
  2030. range.collapse(isStart);
  2031. return range;
  2032. }
  2033. if (child.nodeType == 1) {
  2034. var kchild = K(child), span;
  2035. if (kchild.isControl()) {
  2036. span = doc.createElement('span');
  2037. if (isStart) {
  2038. kchild.before(span);
  2039. } else {
  2040. kchild.after(span);
  2041. }
  2042. child = span;
  2043. }
  2044. _moveToElementText(range, child);
  2045. range.collapse(isStart);
  2046. if (span) {
  2047. K(span).remove();
  2048. }
  2049. return range;
  2050. }
  2051. node = child;
  2052. offset = isStart ? 0 : child.nodeValue.length;
  2053. }
  2054. var dummy = doc.createElement('span');
  2055. K(node).before(dummy);
  2056. _moveToElementText(range, dummy);
  2057. range.moveStart('character', offset);
  2058. K(dummy).remove();
  2059. return range;
  2060. }
  2061. function _toRange(rng) {
  2062. var doc, range;
  2063. function tr2td(start) {
  2064. if (K(start.node).name == 'tr') {
  2065. start.node = start.node.cells[start.offset];
  2066. start.offset = 0;
  2067. }
  2068. }
  2069. if (_IERANGE) {
  2070. if (rng.item) {
  2071. doc = _getDoc(rng.item(0));
  2072. range = new KRange(doc);
  2073. range.selectNode(rng.item(0));
  2074. return range;
  2075. }
  2076. doc = rng.parentElement().ownerDocument;
  2077. var start = _getStartEnd(rng, true),
  2078. end = _getStartEnd(rng, false);
  2079. tr2td(start);
  2080. tr2td(end);
  2081. range = new KRange(doc);
  2082. range.setStart(start.node, start.offset);
  2083. range.setEnd(end.node, end.offset);
  2084. return range;
  2085. }
  2086. var startContainer = rng.startContainer;
  2087. doc = startContainer.ownerDocument || startContainer;
  2088. range = new KRange(doc);
  2089. range.setStart(startContainer, rng.startOffset);
  2090. range.setEnd(rng.endContainer, rng.endOffset);
  2091. return range;
  2092. }
  2093. function KRange(doc) {
  2094. this.init(doc);
  2095. }
  2096. _extend(KRange, {
  2097. init : function(doc) {
  2098. var self = this;
  2099. self.startContainer = doc;
  2100. self.startOffset = 0;
  2101. self.endContainer = doc;
  2102. self.endOffset = 0;
  2103. self.collapsed = true;
  2104. self.doc = doc;
  2105. },
  2106. commonAncestor : function() {
  2107. function getParents(node) {
  2108. var parents = [];
  2109. while (node) {
  2110. parents.push(node);
  2111. node = node.parentNode;
  2112. }
  2113. return parents;
  2114. }
  2115. var parentsA = getParents(this.startContainer),
  2116. parentsB = getParents(this.endContainer),
  2117. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2118. while (++i) {
  2119. parentA = parentsA[lenA - i];
  2120. parentB = parentsB[lenB - i];
  2121. if (!parentA || !parentB || parentA !== parentB) {
  2122. break;
  2123. }
  2124. }
  2125. return parentsA[lenA - i + 1];
  2126. },
  2127. setStart : function(node, offset) {
  2128. var self = this, doc = self.doc;
  2129. self.startContainer = node;
  2130. self.startOffset = offset;
  2131. if (self.endContainer === doc) {
  2132. self.endContainer = node;
  2133. self.endOffset = offset;
  2134. }
  2135. return _updateCollapsed(this);
  2136. },
  2137. setEnd : function(node, offset) {
  2138. var self = this, doc = self.doc;
  2139. self.endContainer = node;
  2140. self.endOffset = offset;
  2141. if (self.startContainer === doc) {
  2142. self.startContainer = node;
  2143. self.startOffset = offset;
  2144. }
  2145. return _updateCollapsed(this);
  2146. },
  2147. setStartBefore : function(node) {
  2148. return this.setStart(node.parentNode || this.doc, K(node).index());
  2149. },
  2150. setStartAfter : function(node) {
  2151. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2152. },
  2153. setEndBefore : function(node) {
  2154. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2155. },
  2156. setEndAfter : function(node) {
  2157. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2158. },
  2159. selectNode : function(node) {
  2160. return this.setStartBefore(node).setEndAfter(node);
  2161. },
  2162. selectNodeContents : function(node) {
  2163. var knode = K(node);
  2164. if (knode.type == 3 || knode.isSingle()) {
  2165. return this.selectNode(node);
  2166. }
  2167. var children = knode.children();
  2168. if (children.length > 0) {
  2169. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2170. }
  2171. return this.setStart(node, 0).setEnd(node, 0);
  2172. },
  2173. collapse : function(toStart) {
  2174. if (toStart) {
  2175. return this.setEnd(this.startContainer, this.startOffset);
  2176. }
  2177. return this.setStart(this.endContainer, this.endOffset);
  2178. },
  2179. compareBoundaryPoints : function(how, range) {
  2180. var rangeA = this.get(), rangeB = range.get();
  2181. if (_IERANGE) {
  2182. var arr = {};
  2183. arr[_START_TO_START] = 'StartToStart';
  2184. arr[_START_TO_END] = 'EndToStart';
  2185. arr[_END_TO_END] = 'EndToEnd';
  2186. arr[_END_TO_START] = 'StartToEnd';
  2187. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2188. if (cmp !== 0) {
  2189. return cmp;
  2190. }
  2191. var nodeA, nodeB, nodeC, posA, posB;
  2192. if (how === _START_TO_START || how === _END_TO_START) {
  2193. nodeA = this.startContainer;
  2194. posA = this.startOffset;
  2195. }
  2196. if (how === _START_TO_END || how === _END_TO_END) {
  2197. nodeA = this.endContainer;
  2198. posA = this.endOffset;
  2199. }
  2200. if (how === _START_TO_START || how === _START_TO_END) {
  2201. nodeB = range.startContainer;
  2202. posB = range.startOffset;
  2203. }
  2204. if (how === _END_TO_END || how === _END_TO_START) {
  2205. nodeB = range.endContainer;
  2206. posB = range.endOffset;
  2207. }
  2208. if (nodeA === nodeB) {
  2209. var diff = posA - posB;
  2210. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2211. }
  2212. nodeC = nodeB;
  2213. while (nodeC && nodeC.parentNode !== nodeA) {
  2214. nodeC = nodeC.parentNode;
  2215. }
  2216. if (nodeC) {
  2217. return K(nodeC).index() >= posA ? -1 : 1;
  2218. }
  2219. nodeC = nodeA;
  2220. while (nodeC && nodeC.parentNode !== nodeB) {
  2221. nodeC = nodeC.parentNode;
  2222. }
  2223. if (nodeC) {
  2224. return K(nodeC).index() >= posB ? 1 : -1;
  2225. }
  2226. nodeC = K(nodeB).next();
  2227. if (nodeC && nodeC.contains(nodeA)) {
  2228. return 1;
  2229. }
  2230. nodeC = K(nodeA).next();
  2231. if (nodeC && nodeC.contains(nodeB)) {
  2232. return -1;
  2233. }
  2234. } else {
  2235. return rangeA.compareBoundaryPoints(how, rangeB);
  2236. }
  2237. },
  2238. cloneRange : function() {
  2239. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2240. },
  2241. toString : function() {
  2242. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2243. return str.replace(/\r\n|\n|\r/g, '');
  2244. },
  2245. cloneContents : function() {
  2246. return _copyAndDelete(this, true, false);
  2247. },
  2248. deleteContents : function() {
  2249. return _copyAndDelete(this, false, true);
  2250. },
  2251. extractContents : function() {
  2252. return _copyAndDelete(this, true, true);
  2253. },
  2254. insertNode : function(node) {
  2255. var self = this,
  2256. sc = self.startContainer, so = self.startOffset,
  2257. ec = self.endContainer, eo = self.endOffset,
  2258. firstChild, lastChild, c, nodeCount = 1;
  2259. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2260. firstChild = node.firstChild;
  2261. lastChild = node.lastChild;
  2262. nodeCount = node.childNodes.length;
  2263. }
  2264. if (sc.nodeType == 1) {
  2265. c = sc.childNodes[so];
  2266. if (c) {
  2267. sc.insertBefore(node, c);
  2268. if (sc === ec) {
  2269. eo += nodeCount;
  2270. }
  2271. } else {
  2272. sc.appendChild(node);
  2273. }
  2274. } else if (sc.nodeType == 3) {
  2275. if (so === 0) {
  2276. sc.parentNode.insertBefore(node, sc);
  2277. if (sc.parentNode === ec) {
  2278. eo += nodeCount;
  2279. }
  2280. } else if (so >= sc.nodeValue.length) {
  2281. if (sc.nextSibling) {
  2282. sc.parentNode.insertBefore(node, sc.nextSibling);
  2283. } else {
  2284. sc.parentNode.appendChild(node);
  2285. }
  2286. } else {
  2287. if (so > 0) {
  2288. c = sc.splitText(so);
  2289. } else {
  2290. c = sc;
  2291. }
  2292. sc.parentNode.insertBefore(node, c);
  2293. if (sc === ec) {
  2294. ec = c;
  2295. eo -= so;
  2296. }
  2297. }
  2298. }
  2299. if (firstChild) {
  2300. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2301. } else {
  2302. self.selectNode(node);
  2303. }
  2304. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2305. return self;
  2306. }
  2307. return self.setEnd(ec, eo);
  2308. },
  2309. surroundContents : function(node) {
  2310. node.appendChild(this.extractContents());
  2311. return this.insertNode(node).selectNode(node);
  2312. },
  2313. isControl : function() {
  2314. var self = this,
  2315. sc = self.startContainer, so = self.startOffset,
  2316. ec = self.endContainer, eo = self.endOffset, rng;
  2317. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2318. },
  2319. get : function(hasControlRange) {
  2320. var self = this, doc = self.doc, node, rng;
  2321. if (!_IERANGE) {
  2322. rng = doc.createRange();
  2323. try {
  2324. rng.setStart(self.startContainer, self.startOffset);
  2325. rng.setEnd(self.endContainer, self.endOffset);
  2326. } catch (e) {}
  2327. return rng;
  2328. }
  2329. if (hasControlRange && self.isControl()) {
  2330. rng = doc.body.createControlRange();
  2331. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2332. return rng;
  2333. }
  2334. var range = self.cloneRange().down();
  2335. rng = doc.body.createTextRange();
  2336. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2337. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2338. return rng;
  2339. },
  2340. html : function() {
  2341. return K(this.cloneContents()).outer();
  2342. },
  2343. down : function() {
  2344. var self = this;
  2345. function downPos(node, pos, isStart) {
  2346. if (node.nodeType != 1) {
  2347. return;
  2348. }
  2349. var children = K(node).children();
  2350. if (children.length === 0) {
  2351. return;
  2352. }
  2353. var left, right, child, offset;
  2354. if (pos > 0) {
  2355. left = children.eq(pos - 1);
  2356. }
  2357. if (pos < children.length) {
  2358. right = children.eq(pos);
  2359. }
  2360. if (left && left.type == 3) {
  2361. child = left[0];
  2362. offset = child.nodeValue.length;
  2363. }
  2364. if (right && right.type == 3) {
  2365. child = right[0];
  2366. offset = 0;
  2367. }
  2368. if (!child) {
  2369. return;
  2370. }
  2371. if (isStart) {
  2372. self.setStart(child, offset);
  2373. } else {
  2374. self.setEnd(child, offset);
  2375. }
  2376. }
  2377. downPos(self.startContainer, self.startOffset, true);
  2378. downPos(self.endContainer, self.endOffset, false);
  2379. return self;
  2380. },
  2381. up : function() {
  2382. var self = this;
  2383. function upPos(node, pos, isStart) {
  2384. if (node.nodeType != 3) {
  2385. return;
  2386. }
  2387. if (pos === 0) {
  2388. if (isStart) {
  2389. self.setStartBefore(node);
  2390. } else {
  2391. self.setEndBefore(node);
  2392. }
  2393. } else if (pos == node.nodeValue.length) {
  2394. if (isStart) {
  2395. self.setStartAfter(node);
  2396. } else {
  2397. self.setEndAfter(node);
  2398. }
  2399. }
  2400. }
  2401. upPos(self.startContainer, self.startOffset, true);
  2402. upPos(self.endContainer, self.endOffset, false);
  2403. return self;
  2404. },
  2405. enlarge : function(toBlock) {
  2406. var self = this;
  2407. self.up();
  2408. function enlargePos(node, pos, isStart) {
  2409. var knode = K(node), parent;
  2410. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2411. return;
  2412. }
  2413. if (pos === 0) {
  2414. while (!knode.prev()) {
  2415. parent = knode.parent();
  2416. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2417. break;
  2418. }
  2419. knode = parent;
  2420. }
  2421. if (isStart) {
  2422. self.setStartBefore(knode[0]);
  2423. } else {
  2424. self.setEndBefore(knode[0]);
  2425. }
  2426. } else if (pos == knode.children().length) {
  2427. while (!knode.next()) {
  2428. parent = knode.parent();
  2429. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2430. break;
  2431. }
  2432. knode = parent;
  2433. }
  2434. if (isStart) {
  2435. self.setStartAfter(knode[0]);
  2436. } else {
  2437. self.setEndAfter(knode[0]);
  2438. }
  2439. }
  2440. }
  2441. enlargePos(self.startContainer, self.startOffset, true);
  2442. enlargePos(self.endContainer, self.endOffset, false);
  2443. return self;
  2444. },
  2445. shrink : function() {
  2446. var self = this, child, collapsed = self.collapsed;
  2447. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2448. self.setStart(child, 0);
  2449. }
  2450. if (collapsed) {
  2451. return self.collapse(collapsed);
  2452. }
  2453. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2454. self.setEnd(child, child.childNodes.length);
  2455. }
  2456. return self;
  2457. },
  2458. createBookmark : function(serialize) {
  2459. var self = this, doc = self.doc, endNode,
  2460. startNode = K('<span style="display:none;"></span>', doc)[0];
  2461. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2462. if (!self.collapsed) {
  2463. endNode = startNode.cloneNode(true);
  2464. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2465. }
  2466. if (endNode) {
  2467. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2468. }
  2469. self.insertNode(startNode).setStartAfter(startNode);
  2470. return {
  2471. start : serialize ? '#' + startNode.id : startNode,
  2472. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2473. };
  2474. },
  2475. moveToBookmark : function(bookmark) {
  2476. var self = this, doc = self.doc,
  2477. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2478. if (!start || start.length < 1) {
  2479. return self;
  2480. }
  2481. self.setStartBefore(start[0]);
  2482. start.remove();
  2483. if (end && end.length > 0) {
  2484. self.setEndBefore(end[0]);
  2485. end.remove();
  2486. } else {
  2487. self.collapse(true);
  2488. }
  2489. return self;
  2490. },
  2491. dump : function() {
  2492. console.log('--------------------');
  2493. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2494. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2495. }
  2496. });
  2497. function _range(mixed) {
  2498. if (!mixed.nodeName) {
  2499. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2500. }
  2501. return new KRange(mixed);
  2502. }
  2503. K.RangeClass = KRange;
  2504. K.range = _range;
  2505. K.START_TO_START = _START_TO_START;
  2506. K.START_TO_END = _START_TO_END;
  2507. K.END_TO_END = _END_TO_END;
  2508. K.END_TO_START = _END_TO_START;
  2509. function _nativeCommand(doc, key, val) {
  2510. try {
  2511. doc.execCommand(key, false, val);
  2512. } catch(e) {}
  2513. }
  2514. function _nativeCommandValue(doc, key) {
  2515. var val = '';
  2516. try {
  2517. val = doc.queryCommandValue(key);
  2518. } catch (e) {}
  2519. if (typeof val !== 'string') {
  2520. val = '';
  2521. }
  2522. return val;
  2523. }
  2524. function _getSel(doc) {
  2525. var win = _getWin(doc);
  2526. return _IERANGE ? doc.selection : win.getSelection();
  2527. }
  2528. function _getRng(doc) {
  2529. var sel = _getSel(doc), rng;
  2530. try {
  2531. if (sel.rangeCount > 0) {
  2532. rng = sel.getRangeAt(0);
  2533. } else {
  2534. rng = sel.createRange();
  2535. }
  2536. } catch(e) {}
  2537. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2538. return null;
  2539. }
  2540. return rng;
  2541. }
  2542. function _singleKeyMap(map) {
  2543. var newMap = {}, arr, v;
  2544. _each(map, function(key, val) {
  2545. arr = key.split(',');
  2546. for (var i = 0, len = arr.length; i < len; i++) {
  2547. v = arr[i];
  2548. newMap[v] = val;
  2549. }
  2550. });
  2551. return newMap;
  2552. }
  2553. function _hasAttrOrCss(knode, map) {
  2554. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2555. }
  2556. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2557. mapKey = mapKey || knode.name;
  2558. if (knode.type !== 1) {
  2559. return false;
  2560. }
  2561. var newMap = _singleKeyMap(map);
  2562. if (!newMap[mapKey]) {
  2563. return false;
  2564. }
  2565. var arr = newMap[mapKey].split(',');
  2566. for (var i = 0, len = arr.length; i < len; i++) {
  2567. var key = arr[i];
  2568. if (key === '*') {
  2569. return true;
  2570. }
  2571. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2572. var method = match[1] ? 'css' : 'attr';
  2573. key = match[2];
  2574. var val = match[3] || '';
  2575. if (val === '' && knode[method](key) !== '') {
  2576. return true;
  2577. }
  2578. if (val !== '' && knode[method](key) === val) {
  2579. return true;
  2580. }
  2581. }
  2582. return false;
  2583. }
  2584. function _removeAttrOrCss(knode, map) {
  2585. if (knode.type != 1) {
  2586. return;
  2587. }
  2588. _removeAttrOrCssByKey(knode, map, '*');
  2589. _removeAttrOrCssByKey(knode, map);
  2590. }
  2591. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2592. mapKey = mapKey || knode.name;
  2593. if (knode.type !== 1) {
  2594. return;
  2595. }
  2596. var newMap = _singleKeyMap(map);
  2597. if (!newMap[mapKey]) {
  2598. return;
  2599. }
  2600. var arr = newMap[mapKey].split(','), allFlag = false;
  2601. for (var i = 0, len = arr.length; i < len; i++) {
  2602. var key = arr[i];
  2603. if (key === '*') {
  2604. allFlag = true;
  2605. break;
  2606. }
  2607. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2608. key = match[2];
  2609. if (match[1]) {
  2610. key = _toCamel(key);
  2611. if (knode[0].style[key]) {
  2612. knode[0].style[key] = '';
  2613. }
  2614. } else {
  2615. knode.removeAttr(key);
  2616. }
  2617. }
  2618. if (allFlag) {
  2619. knode.remove(true);
  2620. }
  2621. }
  2622. function _getInnerNode(knode) {
  2623. var inner = knode;
  2624. while (inner.first()) {
  2625. inner = inner.first();
  2626. }
  2627. return inner;
  2628. }
  2629. function _isEmptyNode(knode) {
  2630. if (knode.type != 1 || knode.isSingle()) {
  2631. return false;
  2632. }
  2633. return knode.html().replace(/<[^>]+>/g, '') === '';
  2634. }
  2635. function _mergeWrapper(a, b) {
  2636. a = a.clone(true);
  2637. var lastA = _getInnerNode(a), childA = a, merged = false;
  2638. while (b) {
  2639. while (childA) {
  2640. if (childA.name === b.name) {
  2641. _mergeAttrs(childA, b.attr(), b.css());
  2642. merged = true;
  2643. }
  2644. childA = childA.first();
  2645. }
  2646. if (!merged) {
  2647. lastA.append(b.clone(false));
  2648. }
  2649. merged = false;
  2650. b = b.first();
  2651. }
  2652. return a;
  2653. }
  2654. function _wrapNode(knode, wrapper) {
  2655. wrapper = wrapper.clone(true);
  2656. if (knode.type == 3) {
  2657. _getInnerNode(wrapper).append(knode.clone(false));
  2658. knode.replaceWith(wrapper);
  2659. return wrapper;
  2660. }
  2661. var nodeWrapper = knode, child;
  2662. while ((child = knode.first()) && child.children().length == 1) {
  2663. knode = child;
  2664. }
  2665. child = knode.first();
  2666. var frag = knode.doc.createDocumentFragment();
  2667. while (child) {
  2668. frag.appendChild(child[0]);
  2669. child = child.next();
  2670. }
  2671. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2672. if (frag.firstChild) {
  2673. _getInnerNode(wrapper).append(frag);
  2674. }
  2675. nodeWrapper.replaceWith(wrapper);
  2676. return wrapper;
  2677. }
  2678. function _mergeAttrs(knode, attrs, styles) {
  2679. _each(attrs, function(key, val) {
  2680. if (key !== 'style') {
  2681. knode.attr(key, val);
  2682. }
  2683. });
  2684. _each(styles, function(key, val) {
  2685. knode.css(key, val);
  2686. });
  2687. }
  2688. function _inPreElement(knode) {
  2689. while (knode && knode.name != 'body') {
  2690. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2691. return true;
  2692. }
  2693. knode = knode.parent();
  2694. }
  2695. return false;
  2696. }
  2697. function KCmd(range) {
  2698. this.init(range);
  2699. }
  2700. _extend(KCmd, {
  2701. init : function(range) {
  2702. var self = this, doc = range.doc;
  2703. self.doc = doc;
  2704. self.win = _getWin(doc);
  2705. self.sel = _getSel(doc);
  2706. self.range = range;
  2707. },
  2708. selection : function(forceReset) {
  2709. var self = this, doc = self.doc, rng = _getRng(doc);
  2710. self.sel = _getSel(doc);
  2711. if (rng) {
  2712. self.range = _range(rng);
  2713. if (K(self.range.startContainer).name == 'html') {
  2714. self.range.selectNodeContents(doc.body).collapse(false);
  2715. }
  2716. return self;
  2717. }
  2718. if (forceReset) {
  2719. self.range.selectNodeContents(doc.body).collapse(false);
  2720. }
  2721. return self;
  2722. },
  2723. select : function(hasDummy) {
  2724. hasDummy = _undef(hasDummy, true);
  2725. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2726. sc = range.startContainer, so = range.startOffset,
  2727. ec = range.endContainer, eo = range.endOffset,
  2728. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2729. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2730. if (_IERANGE) {
  2731. var dummy = K('<span>&nbsp;</span>', doc);
  2732. range.insertNode(dummy[0]);
  2733. rng = doc.body.createTextRange();
  2734. try {
  2735. rng.moveToElementText(dummy[0]);
  2736. } catch(ex) {}
  2737. rng.collapse(false);
  2738. rng.select();
  2739. dummy.remove();
  2740. win.focus();
  2741. return self;
  2742. }
  2743. if (_WEBKIT) {
  2744. var children = sc.childNodes;
  2745. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2746. range.insertNode(doc.createTextNode('\u200B'));
  2747. hasU200b = true;
  2748. }
  2749. }
  2750. }
  2751. if (_IERANGE) {
  2752. try {
  2753. rng = range.get(true);
  2754. rng.select();
  2755. } catch(e) {}
  2756. } else {
  2757. if (hasU200b) {
  2758. range.collapse(false);
  2759. }
  2760. rng = range.get(true);
  2761. sel.removeAllRanges();
  2762. sel.addRange(rng);
  2763. if (doc !== document) {
  2764. var pos = K(rng.endContainer).pos();
  2765. win.scrollTo(pos.x, pos.y);
  2766. }
  2767. }
  2768. win.focus();
  2769. return self;
  2770. },
  2771. wrap : function(val) {
  2772. var self = this, doc = self.doc, range = self.range, wrapper;
  2773. wrapper = K(val, doc);
  2774. if (range.collapsed) {
  2775. range.shrink();
  2776. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2777. return self;
  2778. }
  2779. if (wrapper.isBlock()) {
  2780. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2781. while (child.first()) {
  2782. child = child.first();
  2783. }
  2784. child.append(range.extractContents());
  2785. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2786. return self;
  2787. }
  2788. range.enlarge();
  2789. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2790. K(ancestor).scan(function(node) {
  2791. if (!isStart && node == bookmark.start) {
  2792. isStart = true;
  2793. return;
  2794. }
  2795. if (isStart) {
  2796. if (node == bookmark.end) {
  2797. return false;
  2798. }
  2799. var knode = K(node);
  2800. if (_inPreElement(knode)) {
  2801. return;
  2802. }
  2803. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2804. var parent;
  2805. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2806. knode = parent;
  2807. }
  2808. _wrapNode(knode, wrapper);
  2809. }
  2810. }
  2811. });
  2812. range.moveToBookmark(bookmark);
  2813. return self;
  2814. },
  2815. split : function(isStart, map) {
  2816. var range = this.range, doc = range.doc;
  2817. var tempRange = range.cloneRange().collapse(isStart);
  2818. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2819. parent = node.nodeType == 3 ? node.parentNode : node,
  2820. needSplit = false, knode;
  2821. while (parent && parent.parentNode) {
  2822. knode = K(parent);
  2823. if (map) {
  2824. if (!knode.isStyle()) {
  2825. break;
  2826. }
  2827. if (!_hasAttrOrCss(knode, map)) {
  2828. break;
  2829. }
  2830. } else {
  2831. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2832. break;
  2833. }
  2834. }
  2835. needSplit = true;
  2836. parent = parent.parentNode;
  2837. }
  2838. if (needSplit) {
  2839. var dummy = doc.createElement('span');
  2840. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2841. if (isStart) {
  2842. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2843. } else {
  2844. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2845. }
  2846. var frag = tempRange.extractContents(),
  2847. first = frag.firstChild, last = frag.lastChild;
  2848. if (isStart) {
  2849. tempRange.insertNode(frag);
  2850. range.setStartAfter(last).setEndBefore(dummy);
  2851. } else {
  2852. parent.appendChild(frag);
  2853. range.setStartBefore(dummy).setEndBefore(first);
  2854. }
  2855. var dummyParent = dummy.parentNode;
  2856. if (dummyParent == range.endContainer) {
  2857. var prev = K(dummy).prev(), next = K(dummy).next();
  2858. if (prev && next && prev.type == 3 && next.type == 3) {
  2859. range.setEnd(prev[0], prev[0].nodeValue.length);
  2860. } else if (!isStart) {
  2861. range.setEnd(range.endContainer, range.endOffset - 1);
  2862. }
  2863. }
  2864. dummyParent.removeChild(dummy);
  2865. }
  2866. return this;
  2867. },
  2868. remove : function(map) {
  2869. var self = this, doc = self.doc, range = self.range;
  2870. range.enlarge();
  2871. if (range.startOffset === 0) {
  2872. var ksc = K(range.startContainer), parent;
  2873. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2874. ksc = parent;
  2875. }
  2876. range.setStart(ksc[0], 0);
  2877. ksc = K(range.startContainer);
  2878. if (ksc.isBlock()) {
  2879. _removeAttrOrCss(ksc, map);
  2880. }
  2881. var kscp = ksc.parent();
  2882. if (kscp && kscp.isBlock()) {
  2883. _removeAttrOrCss(kscp, map);
  2884. }
  2885. }
  2886. var sc, so;
  2887. if (range.collapsed) {
  2888. self.split(true, map);
  2889. sc = range.startContainer;
  2890. so = range.startOffset;
  2891. if (so > 0) {
  2892. var sb = K(sc.childNodes[so - 1]);
  2893. if (sb && _isEmptyNode(sb)) {
  2894. sb.remove();
  2895. range.setStart(sc, so - 1);
  2896. }
  2897. }
  2898. var sa = K(sc.childNodes[so]);
  2899. if (sa && _isEmptyNode(sa)) {
  2900. sa.remove();
  2901. }
  2902. if (_isEmptyNode(sc)) {
  2903. range.startBefore(sc);
  2904. sc.remove();
  2905. }
  2906. range.collapse(true);
  2907. return self;
  2908. }
  2909. self.split(true, map);
  2910. self.split(false, map);
  2911. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2912. range.cloneRange().collapse(false).insertNode(endDummy);
  2913. range.cloneRange().collapse(true).insertNode(startDummy);
  2914. var nodeList = [], cmpStart = false;
  2915. K(range.commonAncestor()).scan(function(node) {
  2916. if (!cmpStart && node == startDummy) {
  2917. cmpStart = true;
  2918. return;
  2919. }
  2920. if (node == endDummy) {
  2921. return false;
  2922. }
  2923. if (cmpStart) {
  2924. nodeList.push(node);
  2925. }
  2926. });
  2927. K(startDummy).remove();
  2928. K(endDummy).remove();
  2929. sc = range.startContainer;
  2930. so = range.startOffset;
  2931. var ec = range.endContainer, eo = range.endOffset;
  2932. if (so > 0) {
  2933. var startBefore = K(sc.childNodes[so - 1]);
  2934. if (startBefore && _isEmptyNode(startBefore)) {
  2935. startBefore.remove();
  2936. range.setStart(sc, so - 1);
  2937. if (sc == ec) {
  2938. range.setEnd(ec, eo - 1);
  2939. }
  2940. }
  2941. var startAfter = K(sc.childNodes[so]);
  2942. if (startAfter && _isEmptyNode(startAfter)) {
  2943. startAfter.remove();
  2944. if (sc == ec) {
  2945. range.setEnd(ec, eo - 1);
  2946. }
  2947. }
  2948. }
  2949. var endAfter = K(ec.childNodes[range.endOffset]);
  2950. if (endAfter && _isEmptyNode(endAfter)) {
  2951. endAfter.remove();
  2952. }
  2953. var bookmark = range.createBookmark(true);
  2954. _each(nodeList, function(i, node) {
  2955. _removeAttrOrCss(K(node), map);
  2956. });
  2957. range.moveToBookmark(bookmark);
  2958. return self;
  2959. },
  2960. commonNode : function(map) {
  2961. var range = this.range;
  2962. var ec = range.endContainer, eo = range.endOffset,
  2963. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2964. function find(node) {
  2965. var child = node, parent = node;
  2966. while (parent) {
  2967. if (_hasAttrOrCss(K(parent), map)) {
  2968. return K(parent);
  2969. }
  2970. parent = parent.parentNode;
  2971. }
  2972. while (child && (child = child.lastChild)) {
  2973. if (_hasAttrOrCss(K(child), map)) {
  2974. return K(child);
  2975. }
  2976. }
  2977. return null;
  2978. }
  2979. var cNode = find(node);
  2980. if (cNode) {
  2981. return cNode;
  2982. }
  2983. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2984. var prev = K(node).prev();
  2985. if (prev) {
  2986. return find(prev);
  2987. }
  2988. }
  2989. return null;
  2990. },
  2991. commonAncestor : function(tagName) {
  2992. var range = this.range,
  2993. sc = range.startContainer, so = range.startOffset,
  2994. ec = range.endContainer, eo = range.endOffset,
  2995. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  2996. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2997. function find(node) {
  2998. while (node) {
  2999. if (node.nodeType == 1) {
  3000. if (node.tagName.toLowerCase() === tagName) {
  3001. return node;
  3002. }
  3003. }
  3004. node = node.parentNode;
  3005. }
  3006. return null;
  3007. }
  3008. var start = find(startNode), end = find(endNode);
  3009. if (start && end && start === end) {
  3010. return K(start);
  3011. }
  3012. return null;
  3013. },
  3014. state : function(key) {
  3015. var self = this, doc = self.doc, bool = false;
  3016. try {
  3017. bool = doc.queryCommandState(key);
  3018. } catch (e) {}
  3019. return bool;
  3020. },
  3021. val : function(key) {
  3022. var self = this, doc = self.doc, range = self.range;
  3023. function lc(val) {
  3024. return val.toLowerCase();
  3025. }
  3026. key = lc(key);
  3027. var val = '', knode;
  3028. if (key === 'fontfamily' || key === 'fontname') {
  3029. val = _nativeCommandValue(doc, 'fontname');
  3030. val = val.replace(/['"]/g, '');
  3031. return lc(val);
  3032. }
  3033. if (key === 'formatblock') {
  3034. val = _nativeCommandValue(doc, key);
  3035. if (val === '') {
  3036. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3037. if (knode) {
  3038. val = knode.name;
  3039. }
  3040. }
  3041. if (val === 'Normal') {
  3042. val = 'p';
  3043. }
  3044. return lc(val);
  3045. }
  3046. if (key === 'fontsize') {
  3047. knode = self.commonNode({'*' : '.font-size'});
  3048. if (knode) {
  3049. val = knode.css('font-size');
  3050. }
  3051. return lc(val);
  3052. }
  3053. if (key === 'forecolor') {
  3054. knode = self.commonNode({'*' : '.color'});
  3055. if (knode) {
  3056. val = knode.css('color');
  3057. }
  3058. val = _toHex(val);
  3059. if (val === '') {
  3060. val = 'default';
  3061. }
  3062. return lc(val);
  3063. }
  3064. if (key === 'hilitecolor') {
  3065. knode = self.commonNode({'*' : '.background-color'});
  3066. if (knode) {
  3067. val = knode.css('background-color');
  3068. }
  3069. val = _toHex(val);
  3070. if (val === '') {
  3071. val = 'default';
  3072. }
  3073. return lc(val);
  3074. }
  3075. return val;
  3076. },
  3077. toggle : function(wrapper, map) {
  3078. var self = this;
  3079. if (self.commonNode(map)) {
  3080. self.remove(map);
  3081. } else {
  3082. self.wrap(wrapper);
  3083. }
  3084. return self.select();
  3085. },
  3086. bold : function() {
  3087. return this.toggle('<strong></strong>', {
  3088. span : '.font-weight=bold',
  3089. strong : '*',
  3090. b : '*'
  3091. });
  3092. },
  3093. italic : function() {
  3094. return this.toggle('<em></em>', {
  3095. span : '.font-style=italic',
  3096. em : '*',
  3097. i : '*'
  3098. });
  3099. },
  3100. underline : function() {
  3101. return this.toggle('<u></u>', {
  3102. span : '.text-decoration=underline',
  3103. u : '*'
  3104. });
  3105. },
  3106. strikethrough : function() {
  3107. return this.toggle('<s></s>', {
  3108. span : '.text-decoration=line-through',
  3109. s : '*'
  3110. });
  3111. },
  3112. forecolor : function(val) {
  3113. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3114. },
  3115. hilitecolor : function(val) {
  3116. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3117. },
  3118. fontsize : function(val) {
  3119. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3120. },
  3121. fontname : function(val) {
  3122. return this.fontfamily(val);
  3123. },
  3124. fontfamily : function(val) {
  3125. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3126. },
  3127. removeformat : function() {
  3128. var map = {
  3129. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3130. },
  3131. tags = _STYLE_TAG_MAP;
  3132. _each(tags, function(key, val) {
  3133. map[key] = '*';
  3134. });
  3135. this.remove(map);
  3136. return this.select();
  3137. },
  3138. inserthtml : function(val, quickMode) {
  3139. var self = this, range = self.range;
  3140. if (val === '') {
  3141. return self;
  3142. }
  3143. function pasteHtml(range, val) {
  3144. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3145. var rng = range.get();
  3146. if (rng.item) {
  3147. rng.item(0).outerHTML = val;
  3148. } else {
  3149. rng.pasteHTML(val);
  3150. }
  3151. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3152. temp.parentNode.removeChild(temp);
  3153. var newRange = _toRange(rng);
  3154. range.setEnd(newRange.endContainer, newRange.endOffset);
  3155. range.collapse(false);
  3156. self.select(false);
  3157. }
  3158. function insertHtml(range, val) {
  3159. var doc = range.doc,
  3160. frag = doc.createDocumentFragment();
  3161. K('@' + val, doc).each(function() {
  3162. frag.appendChild(this);
  3163. });
  3164. range.deleteContents();
  3165. range.insertNode(frag);
  3166. range.collapse(false);
  3167. self.select(false);
  3168. }
  3169. if (_IERANGE && quickMode) {
  3170. try {
  3171. pasteHtml(range, val);
  3172. } catch(e) {
  3173. insertHtml(range, val);
  3174. }
  3175. return self;
  3176. }
  3177. insertHtml(range, val);
  3178. return self;
  3179. },
  3180. hr : function() {
  3181. return this.inserthtml('<hr />');
  3182. },
  3183. print : function() {
  3184. this.win.print();
  3185. return this;
  3186. },
  3187. insertimage : function(url, title, width, height, border, align) {
  3188. title = _undef(title, '');
  3189. border = _undef(border, 0);
  3190. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3191. if (width) {
  3192. html += 'width="' + _escape(width) + '" ';
  3193. }
  3194. if (height) {
  3195. html += 'height="' + _escape(height) + '" ';
  3196. }
  3197. if (title) {
  3198. html += 'title="' + _escape(title) + '" ';
  3199. }
  3200. if (align) {
  3201. html += 'align="' + _escape(align) + '" ';
  3202. }
  3203. html += 'alt="' + _escape(title) + '" ';
  3204. html += '/>';
  3205. return this.inserthtml(html);
  3206. },
  3207. createlink : function(url, type) {
  3208. var self = this, doc = self.doc, range = self.range;
  3209. self.select();
  3210. var a = self.commonNode({ a : '*' });
  3211. if (a && !range.isControl()) {
  3212. range.selectNode(a.get());
  3213. self.select();
  3214. }
  3215. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3216. if (type) {
  3217. html += ' target="' + _escape(type) + '"';
  3218. }
  3219. if (range.collapsed) {
  3220. html += '>' + _escape(url) + '</a>';
  3221. return self.inserthtml(html);
  3222. }
  3223. if (range.isControl()) {
  3224. var node = K(range.startContainer.childNodes[range.startOffset]);
  3225. html += '></a>';
  3226. node.after(K(html, doc));
  3227. node.next().append(node);
  3228. range.selectNode(node[0]);
  3229. return self.select();
  3230. }
  3231. function setAttr(node, url, type) {
  3232. K(node).attr('href', url).attr('data-ke-src', url);
  3233. if (type) {
  3234. K(node).attr('target', type);
  3235. } else {
  3236. K(node).removeAttr('target');
  3237. }
  3238. }
  3239. var sc = range.startContainer, so = range.startOffset,
  3240. ec = range.endContainer, eo = range.endOffset;
  3241. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3242. var child = sc.childNodes[so];
  3243. if (child.nodeName.toLowerCase() == 'a') {
  3244. setAttr(child, url, type);
  3245. return self;
  3246. }
  3247. }
  3248. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3249. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3250. setAttr(this, url, type);
  3251. });
  3252. return self;
  3253. },
  3254. unlink : function() {
  3255. var self = this, doc = self.doc, range = self.range;
  3256. self.select();
  3257. if (range.collapsed) {
  3258. var a = self.commonNode({ a : '*' });
  3259. if (a) {
  3260. range.selectNode(a.get());
  3261. self.select();
  3262. }
  3263. _nativeCommand(doc, 'unlink', null);
  3264. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3265. var parent = K(range.startContainer).parent();
  3266. if (parent.name === 'a') {
  3267. parent.remove(true);
  3268. }
  3269. }
  3270. } else {
  3271. _nativeCommand(doc, 'unlink', null);
  3272. }
  3273. return self;
  3274. }
  3275. });
  3276. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3277. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3278. KCmd.prototype[name] = function(val) {
  3279. var self = this;
  3280. self.select();
  3281. _nativeCommand(self.doc, name, val);
  3282. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3283. self.selection();
  3284. }
  3285. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3286. self.selection();
  3287. }
  3288. return self;
  3289. };
  3290. });
  3291. _each('cut,copy,paste'.split(','), function(i, name) {
  3292. KCmd.prototype[name] = function() {
  3293. var self = this;
  3294. if (!self.doc.queryCommandSupported(name)) {
  3295. throw 'not supported';
  3296. }
  3297. self.select();
  3298. _nativeCommand(self.doc, name, null);
  3299. return self;
  3300. };
  3301. });
  3302. function _cmd(mixed) {
  3303. if (mixed.nodeName) {
  3304. var doc = _getDoc(mixed);
  3305. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3306. }
  3307. return new KCmd(mixed);
  3308. }
  3309. K.CmdClass = KCmd;
  3310. K.cmd = _cmd;
  3311. function _drag(options) {
  3312. var moveEl = options.moveEl,
  3313. moveFn = options.moveFn,
  3314. clickEl = options.clickEl || moveEl,
  3315. beforeDrag = options.beforeDrag,
  3316. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3317. var docs = [document];
  3318. if (iframeFix) {
  3319. K('iframe').each(function() {
  3320. var src = _formatUrl(this.src || '', 'absolute');
  3321. if (/^https?:\/\//.test(src)) {
  3322. return;
  3323. }
  3324. var doc;
  3325. try {
  3326. doc = _iframeDoc(this);
  3327. } catch(e) {}
  3328. if (doc) {
  3329. var pos = K(this).pos();
  3330. K(doc).data('pos-x', pos.x);
  3331. K(doc).data('pos-y', pos.y);
  3332. docs.push(doc);
  3333. }
  3334. });
  3335. }
  3336. clickEl.mousedown(function(e) {
  3337. e.stopPropagation();
  3338. var self = clickEl.get(),
  3339. x = _removeUnit(moveEl.css('left')),
  3340. y = _removeUnit(moveEl.css('top')),
  3341. width = moveEl.width(),
  3342. height = moveEl.height(),
  3343. pageX = e.pageX,
  3344. pageY = e.pageY;
  3345. if (beforeDrag) {
  3346. beforeDrag();
  3347. }
  3348. function moveListener(e) {
  3349. e.preventDefault();
  3350. var kdoc = K(_getDoc(e.target));
  3351. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3352. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3353. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3354. }
  3355. function selectListener(e) {
  3356. e.preventDefault();
  3357. }
  3358. function upListener(e) {
  3359. e.preventDefault();
  3360. K(docs).unbind('mousemove', moveListener)
  3361. .unbind('mouseup', upListener)
  3362. .unbind('selectstart', selectListener);
  3363. if (self.releaseCapture) {
  3364. self.releaseCapture();
  3365. }
  3366. }
  3367. K(docs).mousemove(moveListener)
  3368. .mouseup(upListener)
  3369. .bind('selectstart', selectListener);
  3370. if (self.setCapture) {
  3371. self.setCapture();
  3372. }
  3373. });
  3374. }
  3375. function KWidget(options) {
  3376. this.init(options);
  3377. }
  3378. _extend(KWidget, {
  3379. init : function(options) {
  3380. var self = this;
  3381. self.name = options.name || '';
  3382. self.doc = options.doc || document;
  3383. self.win = _getWin(self.doc);
  3384. self.x = _addUnit(options.x);
  3385. self.y = _addUnit(options.y);
  3386. self.z = options.z;
  3387. self.width = _addUnit(options.width);
  3388. self.height = _addUnit(options.height);
  3389. self.div = K('<div style="display:block;"></div>');
  3390. self.options = options;
  3391. self._alignEl = options.alignEl;
  3392. if (self.width) {
  3393. self.div.css('width', self.width);
  3394. }
  3395. if (self.height) {
  3396. self.div.css('height', self.height);
  3397. }
  3398. if (self.z) {
  3399. self.div.css({
  3400. position : 'absolute',
  3401. left : self.x,
  3402. top : self.y,
  3403. 'z-index' : self.z
  3404. });
  3405. }
  3406. if (self.z && (self.x === undefined || self.y === undefined)) {
  3407. self.autoPos(self.width, self.height);
  3408. }
  3409. if (options.cls) {
  3410. self.div.addClass(options.cls);
  3411. }
  3412. if (options.shadowMode) {
  3413. self.div.addClass('ke-shadow');
  3414. }
  3415. if (options.css) {
  3416. self.div.css(options.css);
  3417. }
  3418. if (options.src) {
  3419. K(options.src).replaceWith(self.div);
  3420. } else {
  3421. K(self.doc.body).append(self.div);
  3422. }
  3423. if (options.html) {
  3424. self.div.html(options.html);
  3425. }
  3426. if (options.autoScroll) {
  3427. if (_IE && _V < 7 || _QUIRKS) {
  3428. var scrollPos = _getScrollPos();
  3429. K(self.win).bind('scroll', function(e) {
  3430. var pos = _getScrollPos(),
  3431. diffX = pos.x - scrollPos.x,
  3432. diffY = pos.y - scrollPos.y;
  3433. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3434. });
  3435. } else {
  3436. self.div.css('position', 'fixed');
  3437. }
  3438. }
  3439. },
  3440. pos : function(x, y, updateProp) {
  3441. var self = this;
  3442. updateProp = _undef(updateProp, true);
  3443. if (x !== null) {
  3444. x = x < 0 ? 0 : _addUnit(x);
  3445. self.div.css('left', x);
  3446. if (updateProp) {
  3447. self.x = x;
  3448. }
  3449. }
  3450. if (y !== null) {
  3451. y = y < 0 ? 0 : _addUnit(y);
  3452. self.div.css('top', y);
  3453. if (updateProp) {
  3454. self.y = y;
  3455. }
  3456. }
  3457. return self;
  3458. },
  3459. autoPos : function(width, height) {
  3460. var self = this,
  3461. w = _removeUnit(width) || 0,
  3462. h = _removeUnit(height) || 0,
  3463. scrollPos = _getScrollPos();
  3464. if (self._alignEl) {
  3465. var knode = K(self._alignEl),
  3466. pos = knode.pos(),
  3467. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3468. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3469. x = diffX < 0 ? pos.x : pos.x + diffX;
  3470. y = diffY < 0 ? pos.y : pos.y + diffY;
  3471. } else {
  3472. var docEl = _docElement(self.doc);
  3473. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3474. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3475. }
  3476. if (!(_IE && _V < 7 || _QUIRKS)) {
  3477. x -= scrollPos.x;
  3478. y -= scrollPos.y;
  3479. }
  3480. return self.pos(x, y);
  3481. },
  3482. remove : function() {
  3483. var self = this;
  3484. if (_IE && _V < 7 || _QUIRKS) {
  3485. K(self.win).unbind('scroll');
  3486. }
  3487. self.div.remove();
  3488. _each(self, function(i) {
  3489. self[i] = null;
  3490. });
  3491. return this;
  3492. },
  3493. show : function() {
  3494. this.div.show();
  3495. return this;
  3496. },
  3497. hide : function() {
  3498. this.div.hide();
  3499. return this;
  3500. },
  3501. draggable : function(options) {
  3502. var self = this;
  3503. options = options || {};
  3504. options.moveEl = self.div;
  3505. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3506. if ((x = x + diffX) < 0) {
  3507. x = 0;
  3508. }
  3509. if ((y = y + diffY) < 0) {
  3510. y = 0;
  3511. }
  3512. self.pos(x, y);
  3513. };
  3514. _drag(options);
  3515. return self;
  3516. }
  3517. });
  3518. function _widget(options) {
  3519. return new KWidget(options);
  3520. }
  3521. K.WidgetClass = KWidget;
  3522. K.widget = _widget;
  3523. function _iframeDoc(iframe) {
  3524. iframe = _get(iframe);
  3525. return iframe.contentDocument || iframe.contentWindow.document;
  3526. }
  3527. var html, _direction = '';
  3528. if ((html = document.getElementsByTagName('html'))) {
  3529. _direction = html[0].dir;
  3530. }
  3531. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3532. var arr = [
  3533. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3534. '<head><meta charset="utf-8" /><title></title>',
  3535. '<style>',
  3536. 'html {margin:0;padding:0;}',
  3537. 'body {margin:0;padding:5px;}',
  3538. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3539. 'body, p, div {word-wrap: break-word;}',
  3540. 'p {margin:5px 0;}',
  3541. 'table {border-collapse:collapse;}',
  3542. 'img {border:0;}',
  3543. 'noscript {display:none;}',
  3544. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3545. 'img.ke-flash {',
  3546. ' border:1px solid #AAA;',
  3547. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3548. ' background-position:center center;',
  3549. ' background-repeat:no-repeat;',
  3550. ' width:100px;',
  3551. ' height:100px;',
  3552. '}',
  3553. 'img.ke-rm {',
  3554. ' border:1px solid #AAA;',
  3555. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3556. ' background-position:center center;',
  3557. ' background-repeat:no-repeat;',
  3558. ' width:100px;',
  3559. ' height:100px;',
  3560. '}',
  3561. 'img.ke-media {',
  3562. ' border:1px solid #AAA;',
  3563. ' background-image:url(' + themesPath + 'common/media.gif);',
  3564. ' background-position:center center;',
  3565. ' background-repeat:no-repeat;',
  3566. ' width:100px;',
  3567. ' height:100px;',
  3568. '}',
  3569. 'img.ke-anchor {',
  3570. ' border:1px dashed #666;',
  3571. ' width:16px;',
  3572. ' height:16px;',
  3573. '}',
  3574. '.ke-script, .ke-noscript, .ke-display-none {',
  3575. ' display:none;',
  3576. ' font-size:0;',
  3577. ' width:0;',
  3578. ' height:0;',
  3579. '}',
  3580. '.ke-pagebreak {',
  3581. ' border:1px dotted #AAA;',
  3582. ' font-size:0;',
  3583. ' height:2px;',
  3584. '}',
  3585. '</style>'
  3586. ];
  3587. if (!_isArray(cssPath)) {
  3588. cssPath = [cssPath];
  3589. }
  3590. _each(cssPath, function(i, path) {
  3591. if (path) {
  3592. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3593. }
  3594. });
  3595. if (cssData) {
  3596. arr.push('<style>' + cssData + '</style>');
  3597. }
  3598. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3599. return arr.join('\n');
  3600. }
  3601. function _elementVal(knode, val) {
  3602. if (knode.hasVal()) {
  3603. if (val === undefined) {
  3604. var html = knode.val();
  3605. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3606. return html;
  3607. }
  3608. return knode.val(val);
  3609. }
  3610. return knode.html(val);
  3611. }
  3612. function KEdit(options) {
  3613. this.init(options);
  3614. }
  3615. _extend(KEdit, KWidget, {
  3616. init : function(options) {
  3617. var self = this;
  3618. KEdit.parent.init.call(self, options);
  3619. self.srcElement = K(options.srcElement);
  3620. self.div.addClass('ke-edit');
  3621. self.designMode = _undef(options.designMode, true);
  3622. self.beforeGetHtml = options.beforeGetHtml;
  3623. self.beforeSetHtml = options.beforeSetHtml;
  3624. self.afterSetHtml = options.afterSetHtml;
  3625. var themesPath = _undef(options.themesPath, ''),
  3626. bodyClass = options.bodyClass,
  3627. cssPath = options.cssPath,
  3628. cssData = options.cssData,
  3629. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3630. srcScript = ('document.open();' +
  3631. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3632. 'document.close();'),
  3633. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3634. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3635. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3636. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3637. self.iframe.attr('tabindex', self.tabIndex);
  3638. self.textarea.attr('tabindex', self.tabIndex);
  3639. if (self.width) {
  3640. self.setWidth(self.width);
  3641. }
  3642. if (self.height) {
  3643. self.setHeight(self.height);
  3644. }
  3645. if (self.designMode) {
  3646. self.textarea.hide();
  3647. } else {
  3648. self.iframe.hide();
  3649. }
  3650. function ready() {
  3651. var doc = _iframeDoc(self.iframe);
  3652. doc.open();
  3653. if (isDocumentDomain) {
  3654. doc.domain = document.domain;
  3655. }
  3656. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3657. doc.close();
  3658. self.win = self.iframe[0].contentWindow;
  3659. self.doc = doc;
  3660. var cmd = _cmd(doc);
  3661. self.afterChange(function(e) {
  3662. cmd.selection();
  3663. });
  3664. if (_WEBKIT) {
  3665. K(doc).click(function(e) {
  3666. if (K(e.target).name === 'img') {
  3667. cmd.selection(true);
  3668. cmd.range.selectNode(e.target);
  3669. cmd.select();
  3670. }
  3671. });
  3672. }
  3673. if (_IE) {
  3674. self._mousedownHandler = function() {
  3675. var newRange = cmd.range.cloneRange();
  3676. newRange.shrink();
  3677. if (newRange.isControl()) {
  3678. self.blur();
  3679. }
  3680. };
  3681. K(document).mousedown(self._mousedownHandler);
  3682. K(doc).keydown(function(e) {
  3683. if (e.which == 8) {
  3684. cmd.selection();
  3685. var rng = cmd.range;
  3686. if (rng.isControl()) {
  3687. rng.collapse(true);
  3688. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3689. e.preventDefault();
  3690. }
  3691. }
  3692. });
  3693. }
  3694. self.cmd = cmd;
  3695. self.html(_elementVal(self.srcElement));
  3696. if (_IE) {
  3697. doc.body.disabled = true;
  3698. doc.body.contentEditable = true;
  3699. doc.body.removeAttribute('disabled');
  3700. } else {
  3701. doc.designMode = 'on';
  3702. }
  3703. if (options.afterCreate) {
  3704. options.afterCreate.call(self);
  3705. }
  3706. }
  3707. if (isDocumentDomain) {
  3708. self.iframe.bind('load', function(e) {
  3709. self.iframe.unbind('load');
  3710. if (_IE) {
  3711. ready();
  3712. } else {
  3713. setTimeout(ready, 0);
  3714. }
  3715. });
  3716. }
  3717. self.div.append(self.iframe);
  3718. self.div.append(self.textarea);
  3719. self.srcElement.hide();
  3720. !isDocumentDomain && ready();
  3721. },
  3722. setWidth : function(val) {
  3723. var self = this;
  3724. val = _addUnit(val);
  3725. self.width = val;
  3726. self.div.css('width', val);
  3727. return self;
  3728. },
  3729. setHeight : function(val) {
  3730. var self = this;
  3731. val = _addUnit(val);
  3732. self.height = val;
  3733. self.div.css('height', val);
  3734. self.iframe.css('height', val);
  3735. if ((_IE && _V < 8) || _QUIRKS) {
  3736. val = _addUnit(_removeUnit(val) - 2);
  3737. }
  3738. self.textarea.css('height', val);
  3739. return self;
  3740. },
  3741. remove : function() {
  3742. var self = this, doc = self.doc;
  3743. K(doc.body).unbind();
  3744. K(doc).unbind();
  3745. K(self.win).unbind();
  3746. if (self._mousedownHandler) {
  3747. K(document).unbind('mousedown', self._mousedownHandler);
  3748. }
  3749. _elementVal(self.srcElement, self.html());
  3750. self.srcElement.show();
  3751. doc.write('');
  3752. self.iframe.unbind();
  3753. self.textarea.unbind();
  3754. KEdit.parent.remove.call(self);
  3755. },
  3756. html : function(val, isFull) {
  3757. var self = this, doc = self.doc;
  3758. if (self.designMode) {
  3759. var body = doc.body;
  3760. if (val === undefined) {
  3761. if (isFull) {
  3762. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3763. } else {
  3764. val = body.innerHTML;
  3765. }
  3766. if (self.beforeGetHtml) {
  3767. val = self.beforeGetHtml(val);
  3768. }
  3769. if (_GECKO && val == '<br />') {
  3770. val = '';
  3771. }
  3772. return val;
  3773. }
  3774. if (self.beforeSetHtml) {
  3775. val = self.beforeSetHtml(val);
  3776. }
  3777. if (_IE && _V >= 9) {
  3778. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3779. }
  3780. K(body).html(val);
  3781. if (self.afterSetHtml) {
  3782. self.afterSetHtml();
  3783. }
  3784. return self;
  3785. }
  3786. if (val === undefined) {
  3787. return self.textarea.val();
  3788. }
  3789. self.textarea.val(val);
  3790. return self;
  3791. },
  3792. design : function(bool) {
  3793. var self = this, val;
  3794. if (bool === undefined ? !self.designMode : bool) {
  3795. if (!self.designMode) {
  3796. val = self.html();
  3797. self.designMode = true;
  3798. self.html(val);
  3799. self.textarea.hide();
  3800. self.iframe.show();
  3801. }
  3802. } else {
  3803. if (self.designMode) {
  3804. val = self.html();
  3805. self.designMode = false;
  3806. self.html(val);
  3807. self.iframe.hide();
  3808. self.textarea.show();
  3809. }
  3810. }
  3811. return self.focus();
  3812. },
  3813. focus : function() {
  3814. var self = this;
  3815. self.designMode ? self.win.focus() : self.textarea[0].focus();
  3816. return self;
  3817. },
  3818. blur : function() {
  3819. var self = this;
  3820. if (_IE) {
  3821. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3822. self.div.append(input);
  3823. input[0].focus();
  3824. input.remove();
  3825. } else {
  3826. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3827. }
  3828. return self;
  3829. },
  3830. afterChange : function(fn) {
  3831. var self = this, doc = self.doc, body = doc.body;
  3832. K(doc).keyup(function(e) {
  3833. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3834. fn(e);
  3835. }
  3836. });
  3837. K(doc).mouseup(fn).contextmenu(fn);
  3838. K(self.win).blur(fn);
  3839. function timeoutHandler(e) {
  3840. setTimeout(function() {
  3841. fn(e);
  3842. }, 1);
  3843. }
  3844. K(body).bind('paste', timeoutHandler);
  3845. K(body).bind('cut', timeoutHandler);
  3846. return self;
  3847. }
  3848. });
  3849. function _edit(options) {
  3850. return new KEdit(options);
  3851. }
  3852. K.EditClass = KEdit;
  3853. K.edit = _edit;
  3854. K.iframeDoc = _iframeDoc;
  3855. function _selectToolbar(name, fn) {
  3856. var self = this,
  3857. knode = self.get(name);
  3858. if (knode) {
  3859. if (knode.hasClass('ke-disabled')) {
  3860. return;
  3861. }
  3862. fn(knode);
  3863. }
  3864. }
  3865. function KToolbar(options) {
  3866. this.init(options);
  3867. }
  3868. _extend(KToolbar, KWidget, {
  3869. init : function(options) {
  3870. var self = this;
  3871. KToolbar.parent.init.call(self, options);
  3872. self.disableMode = _undef(options.disableMode, false);
  3873. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3874. self._itemMap = {};
  3875. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3876. e.preventDefault();
  3877. }).attr('unselectable', 'on');
  3878. function find(target) {
  3879. var knode = K(target);
  3880. if (knode.hasClass('ke-outline')) {
  3881. return knode;
  3882. }
  3883. if (knode.hasClass('ke-toolbar-icon')) {
  3884. return knode.parent();
  3885. }
  3886. }
  3887. function hover(e, method) {
  3888. var knode = find(e.target);
  3889. if (knode) {
  3890. if (knode.hasClass('ke-disabled')) {
  3891. return;
  3892. }
  3893. if (knode.hasClass('ke-selected')) {
  3894. return;
  3895. }
  3896. knode[method]('ke-on');
  3897. }
  3898. }
  3899. self.div.mouseover(function(e) {
  3900. hover(e, 'addClass');
  3901. })
  3902. .mouseout(function(e) {
  3903. hover(e, 'removeClass');
  3904. })
  3905. .click(function(e) {
  3906. var knode = find(e.target);
  3907. if (knode) {
  3908. if (knode.hasClass('ke-disabled')) {
  3909. return;
  3910. }
  3911. self.options.click.call(this, e, knode.attr('data-name'));
  3912. }
  3913. });
  3914. },
  3915. get : function(name) {
  3916. if (this._itemMap[name]) {
  3917. return this._itemMap[name];
  3918. }
  3919. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3920. },
  3921. select : function(name) {
  3922. _selectToolbar.call(this, name, function(knode) {
  3923. knode.addClass('ke-selected');
  3924. });
  3925. return self;
  3926. },
  3927. unselect : function(name) {
  3928. _selectToolbar.call(this, name, function(knode) {
  3929. knode.removeClass('ke-selected').removeClass('ke-on');
  3930. });
  3931. return self;
  3932. },
  3933. enable : function(name) {
  3934. var self = this,
  3935. knode = name.get ? name : self.get(name);
  3936. if (knode) {
  3937. knode.removeClass('ke-disabled');
  3938. knode.opacity(1);
  3939. }
  3940. return self;
  3941. },
  3942. disable : function(name) {
  3943. var self = this,
  3944. knode = name.get ? name : self.get(name);
  3945. if (knode) {
  3946. knode.removeClass('ke-selected').addClass('ke-disabled');
  3947. knode.opacity(0.5);
  3948. }
  3949. return self;
  3950. },
  3951. disableAll : function(bool, noDisableItems) {
  3952. var self = this, map = self.noDisableItemMap, item;
  3953. if (noDisableItems) {
  3954. map = _toMap(noDisableItems);
  3955. }
  3956. if (bool === undefined ? !self.disableMode : bool) {
  3957. K('span.ke-outline', self.div).each(function() {
  3958. var knode = K(this),
  3959. name = knode[0].getAttribute('data-name', 2);
  3960. if (!map[name]) {
  3961. self.disable(knode);
  3962. }
  3963. });
  3964. self.disableMode = true;
  3965. } else {
  3966. K('span.ke-outline', self.div).each(function() {
  3967. var knode = K(this),
  3968. name = knode[0].getAttribute('data-name', 2);
  3969. if (!map[name]) {
  3970. self.enable(knode);
  3971. }
  3972. });
  3973. self.disableMode = false;
  3974. }
  3975. return self;
  3976. }
  3977. });
  3978. function _toolbar(options) {
  3979. return new KToolbar(options);
  3980. }
  3981. K.ToolbarClass = KToolbar;
  3982. K.toolbar = _toolbar;
  3983. function KMenu(options) {
  3984. this.init(options);
  3985. }
  3986. _extend(KMenu, KWidget, {
  3987. init : function(options) {
  3988. var self = this;
  3989. options.z = options.z || 811213;
  3990. KMenu.parent.init.call(self, options);
  3991. self.centerLineMode = _undef(options.centerLineMode, true);
  3992. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  3993. e.stopPropagation();
  3994. }).attr('unselectable', 'on');
  3995. },
  3996. addItem : function(item) {
  3997. var self = this;
  3998. if (item.title === '-') {
  3999. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4000. return;
  4001. }
  4002. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4003. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4004. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4005. height = _addUnit(item.height),
  4006. iconClass = _undef(item.iconClass, '');
  4007. self.div.append(itemDiv);
  4008. if (height) {
  4009. itemDiv.css('height', height);
  4010. rightDiv.css('line-height', height);
  4011. }
  4012. var centerDiv;
  4013. if (self.centerLineMode) {
  4014. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4015. if (height) {
  4016. centerDiv.css('height', height);
  4017. }
  4018. }
  4019. itemDiv.mouseover(function(e) {
  4020. K(this).addClass('ke-menu-item-on');
  4021. if (centerDiv) {
  4022. centerDiv.addClass('ke-menu-item-center-on');
  4023. }
  4024. })
  4025. .mouseout(function(e) {
  4026. K(this).removeClass('ke-menu-item-on');
  4027. if (centerDiv) {
  4028. centerDiv.removeClass('ke-menu-item-center-on');
  4029. }
  4030. })
  4031. .click(function(e) {
  4032. item.click.call(K(this));
  4033. e.stopPropagation();
  4034. })
  4035. .append(leftDiv);
  4036. if (centerDiv) {
  4037. itemDiv.append(centerDiv);
  4038. }
  4039. itemDiv.append(rightDiv);
  4040. if (item.checked) {
  4041. iconClass = 'ke-icon-checked';
  4042. }
  4043. if (iconClass !== '') {
  4044. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4045. }
  4046. rightDiv.html(item.title);
  4047. return self;
  4048. },
  4049. remove : function() {
  4050. var self = this;
  4051. if (self.options.beforeRemove) {
  4052. self.options.beforeRemove.call(self);
  4053. }
  4054. K('.ke-menu-item', self.div[0]).unbind();
  4055. KMenu.parent.remove.call(self);
  4056. return self;
  4057. }
  4058. });
  4059. function _menu(options) {
  4060. return new KMenu(options);
  4061. }
  4062. K.MenuClass = KMenu;
  4063. K.menu = _menu;
  4064. function KColorPicker(options) {
  4065. this.init(options);
  4066. }
  4067. _extend(KColorPicker, KWidget, {
  4068. init : function(options) {
  4069. var self = this;
  4070. options.z = options.z || 811213;
  4071. KColorPicker.parent.init.call(self, options);
  4072. var colors = options.colors || [
  4073. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4074. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4075. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4076. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4077. ];
  4078. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4079. self._cells = [];
  4080. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4081. e.stopPropagation();
  4082. }).attr('unselectable', 'on');
  4083. var table = self.doc.createElement('table');
  4084. self.div.append(table);
  4085. table.className = 'ke-colorpicker-table';
  4086. table.cellPadding = 0;
  4087. table.cellSpacing = 0;
  4088. table.border = 0;
  4089. var row = table.insertRow(0), cell = row.insertCell(0);
  4090. cell.colSpan = colors[0].length;
  4091. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4092. for (var i = 0; i < colors.length; i++) {
  4093. row = table.insertRow(i + 1);
  4094. for (var j = 0; j < colors[i].length; j++) {
  4095. cell = row.insertCell(j);
  4096. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4097. }
  4098. }
  4099. },
  4100. _addAttr : function(cell, color, cls) {
  4101. var self = this;
  4102. cell = K(cell).addClass(cls);
  4103. if (self.selectedColor === color.toLowerCase()) {
  4104. cell.addClass('ke-colorpicker-cell-selected');
  4105. }
  4106. cell.attr('title', color || self.options.noColor);
  4107. cell.mouseover(function(e) {
  4108. K(this).addClass('ke-colorpicker-cell-on');
  4109. });
  4110. cell.mouseout(function(e) {
  4111. K(this).removeClass('ke-colorpicker-cell-on');
  4112. });
  4113. cell.click(function(e) {
  4114. e.stop();
  4115. self.options.click.call(K(this), color);
  4116. });
  4117. if (color) {
  4118. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4119. } else {
  4120. cell.html(self.options.noColor);
  4121. }
  4122. K(cell).attr('unselectable', 'on');
  4123. self._cells.push(cell);
  4124. },
  4125. remove : function() {
  4126. var self = this;
  4127. _each(self._cells, function() {
  4128. this.unbind();
  4129. });
  4130. KColorPicker.parent.remove.call(self);
  4131. return self;
  4132. }
  4133. });
  4134. function _colorpicker(options) {
  4135. return new KColorPicker(options);
  4136. }
  4137. K.ColorPickerClass = KColorPicker;
  4138. K.colorpicker = _colorpicker;
  4139. function KUploadButton(options) {
  4140. this.init(options);
  4141. }
  4142. _extend(KUploadButton, {
  4143. init : function(options) {
  4144. var self = this,
  4145. button = K(options.button),
  4146. fieldName = options.fieldName || 'file',
  4147. url = options.url || '',
  4148. title = button.val(),
  4149. extraParams = options.extraParams || {},
  4150. cls = button[0].className || '',
  4151. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4152. options.afterError = options.afterError || function(str) {
  4153. alert(str);
  4154. };
  4155. var hiddenElements = [];
  4156. for(var k in extraParams){
  4157. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  4158. }
  4159. var html = [
  4160. '<div class="ke-inline-block ' + cls + '">',
  4161. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4162. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4163. '<span class="ke-button-common">',
  4164. hiddenElements.join(''),
  4165. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4166. '</span>',
  4167. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4168. (options.form ? '</div>' : '</form>'),
  4169. '</div>'].join('');
  4170. var div = K(html, button.doc);
  4171. button.hide();
  4172. button.before(div);
  4173. self.div = div;
  4174. self.button = button;
  4175. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4176. self.form = options.form ? K(options.form) : K('form', div);
  4177. self.fileBox = K('.ke-upload-file', div);
  4178. var width = options.width || K('.ke-button-common', div).width();
  4179. K('.ke-upload-area', div).width(width);
  4180. self.options = options;
  4181. },
  4182. submit : function() {
  4183. var self = this,
  4184. iframe = self.iframe;
  4185. iframe.bind('load', function() {
  4186. iframe.unbind();
  4187. var tempForm = document.createElement('form');
  4188. self.fileBox.before(tempForm);
  4189. K(tempForm).append(self.fileBox);
  4190. tempForm.reset();
  4191. K(tempForm).remove(true);
  4192. var doc = K.iframeDoc(iframe),
  4193. pre = doc.getElementsByTagName('pre')[0],
  4194. str = '', data;
  4195. if (pre) {
  4196. str = pre.innerHTML;
  4197. } else {
  4198. str = doc.body.innerHTML;
  4199. }
  4200. str = _unescape(str);
  4201. iframe[0].src = 'javascript:false';
  4202. try {
  4203. data = K.json(str);
  4204. } catch (e) {
  4205. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4206. }
  4207. if (data) {
  4208. self.options.afterUpload.call(self, data);
  4209. }
  4210. });
  4211. self.form[0].submit();
  4212. return self;
  4213. },
  4214. remove : function() {
  4215. var self = this;
  4216. if (self.fileBox) {
  4217. self.fileBox.unbind();
  4218. }
  4219. self.iframe.remove();
  4220. self.div.remove();
  4221. self.button.show();
  4222. return self;
  4223. }
  4224. });
  4225. function _uploadbutton(options) {
  4226. return new KUploadButton(options);
  4227. }
  4228. K.UploadButtonClass = KUploadButton;
  4229. K.uploadbutton = _uploadbutton;
  4230. function _createButton(arg) {
  4231. arg = arg || {};
  4232. var name = arg.name || '',
  4233. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4234. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4235. if (arg.click) {
  4236. btn.click(arg.click);
  4237. }
  4238. span.append(btn);
  4239. return span;
  4240. }
  4241. function KDialog(options) {
  4242. this.init(options);
  4243. }
  4244. _extend(KDialog, KWidget, {
  4245. init : function(options) {
  4246. var self = this;
  4247. var shadowMode = _undef(options.shadowMode, true);
  4248. options.z = options.z || 811213;
  4249. options.shadowMode = false;
  4250. options.autoScroll = _undef(options.autoScroll, true);
  4251. KDialog.parent.init.call(self, options);
  4252. var title = options.title,
  4253. body = K(options.body, self.doc),
  4254. previewBtn = options.previewBtn,
  4255. yesBtn = options.yesBtn,
  4256. noBtn = options.noBtn,
  4257. closeBtn = options.closeBtn,
  4258. showMask = _undef(options.showMask, true);
  4259. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4260. e.stopPropagation();
  4261. });
  4262. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4263. if (_IE && _V < 7) {
  4264. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4265. } else if (shadowMode) {
  4266. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4267. }
  4268. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4269. contentDiv.append(headerDiv);
  4270. headerDiv.html(title);
  4271. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4272. headerDiv.append(self.closeIcon);
  4273. self.draggable({
  4274. clickEl : headerDiv,
  4275. beforeDrag : options.beforeDrag
  4276. });
  4277. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4278. contentDiv.append(bodyDiv);
  4279. bodyDiv.append(body);
  4280. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4281. if (previewBtn || yesBtn || noBtn) {
  4282. contentDiv.append(footerDiv);
  4283. }
  4284. _each([
  4285. { btn : previewBtn, name : 'preview' },
  4286. { btn : yesBtn, name : 'yes' },
  4287. { btn : noBtn, name : 'no' }
  4288. ], function() {
  4289. if (this.btn) {
  4290. var button = _createButton(this.btn);
  4291. button.addClass('ke-dialog-' + this.name);
  4292. footerDiv.append(button);
  4293. }
  4294. });
  4295. if (self.height) {
  4296. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4297. }
  4298. self.div.width(self.div.width());
  4299. self.div.height(self.div.height());
  4300. self.mask = null;
  4301. if (showMask) {
  4302. var docEl = _docElement(self.doc),
  4303. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4304. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4305. self.mask = _widget({
  4306. x : 0,
  4307. y : 0,
  4308. z : self.z - 1,
  4309. cls : 'ke-dialog-mask',
  4310. width : docWidth,
  4311. height : docHeight
  4312. });
  4313. }
  4314. self.autoPos(self.div.width(), self.div.height());
  4315. self.footerDiv = footerDiv;
  4316. self.bodyDiv = bodyDiv;
  4317. self.headerDiv = headerDiv;
  4318. self.isLoading = false;
  4319. },
  4320. setMaskIndex : function(z) {
  4321. var self = this;
  4322. self.mask.div.css('z-index', z);
  4323. },
  4324. showLoading : function(msg) {
  4325. msg = _undef(msg, '');
  4326. var self = this, body = self.bodyDiv;
  4327. self.loading = K('<div class="ke-dialog-loading"><div class="ke-inline-block ke-dialog-loading-content" style="margin-top:' + Math.round(body.height() / 3) + 'px;">' + msg + '</div></div>')
  4328. .width(body.width()).height(body.height())
  4329. .css('top', self.headerDiv.height() + 'px');
  4330. body.css('visibility', 'hidden').after(self.loading);
  4331. self.isLoading = true;
  4332. return self;
  4333. },
  4334. hideLoading : function() {
  4335. this.loading && this.loading.remove();
  4336. this.bodyDiv.css('visibility', 'visible');
  4337. this.isLoading = false;
  4338. return this;
  4339. },
  4340. remove : function() {
  4341. var self = this;
  4342. if (self.options.beforeRemove) {
  4343. self.options.beforeRemove.call(self);
  4344. }
  4345. self.mask && self.mask.remove();
  4346. self.iframeMask && self.iframeMask.remove();
  4347. self.closeIcon.unbind();
  4348. K('input', self.div).unbind();
  4349. K('button', self.div).unbind();
  4350. self.footerDiv.unbind();
  4351. self.bodyDiv.unbind();
  4352. self.headerDiv.unbind();
  4353. K('iframe', self.div).each(function() {
  4354. K(this).remove();
  4355. });
  4356. KDialog.parent.remove.call(self);
  4357. return self;
  4358. }
  4359. });
  4360. function _dialog(options) {
  4361. return new KDialog(options);
  4362. }
  4363. K.DialogClass = KDialog;
  4364. K.dialog = _dialog;
  4365. function _tabs(options) {
  4366. var self = _widget(options),
  4367. remove = self.remove,
  4368. afterSelect = options.afterSelect,
  4369. div = self.div,
  4370. liList = [];
  4371. div.addClass('ke-tabs')
  4372. .bind('contextmenu,mousedown,mousemove', function(e) {
  4373. e.preventDefault();
  4374. });
  4375. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4376. div.append(ul);
  4377. self.add = function(tab) {
  4378. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4379. li.data('tab', tab);
  4380. liList.push(li);
  4381. ul.append(li);
  4382. };
  4383. self.selectedIndex = 0;
  4384. self.select = function(index) {
  4385. self.selectedIndex = index;
  4386. _each(liList, function(i, li) {
  4387. li.unbind();
  4388. if (i === index) {
  4389. li.addClass('ke-tabs-li-selected');
  4390. K(li.data('tab').panel).show('');
  4391. } else {
  4392. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4393. .mouseover(function() {
  4394. K(this).addClass('ke-tabs-li-on');
  4395. })
  4396. .mouseout(function() {
  4397. K(this).removeClass('ke-tabs-li-on');
  4398. })
  4399. .click(function() {
  4400. self.select(i);
  4401. });
  4402. K(li.data('tab').panel).hide();
  4403. }
  4404. });
  4405. if (afterSelect) {
  4406. afterSelect.call(self, index);
  4407. }
  4408. };
  4409. self.remove = function() {
  4410. _each(liList, function() {
  4411. this.remove();
  4412. });
  4413. ul.remove();
  4414. remove.call(self);
  4415. };
  4416. return self;
  4417. }
  4418. K.tabs = _tabs;
  4419. function _loadScript(url, fn) {
  4420. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4421. script = document.createElement('script');
  4422. head.appendChild(script);
  4423. script.src = url;
  4424. script.charset = 'utf-8';
  4425. script.onload = script.onreadystatechange = function() {
  4426. if (!this.readyState || this.readyState === 'loaded') {
  4427. if (fn) {
  4428. fn();
  4429. }
  4430. script.onload = script.onreadystatechange = null;
  4431. head.removeChild(script);
  4432. }
  4433. };
  4434. }
  4435. function _chopQuery(url) {
  4436. var index = url.indexOf('?');
  4437. return index > 0 ? url.substr(0, index) : url;
  4438. }
  4439. function _loadStyle(url) {
  4440. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4441. link = document.createElement('link'),
  4442. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4443. var links = K('link[rel="stylesheet"]', head);
  4444. for (var i = 0, len = links.length; i < len; i++) {
  4445. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4446. return;
  4447. }
  4448. }
  4449. head.appendChild(link);
  4450. link.href = url;
  4451. link.rel = 'stylesheet';
  4452. }
  4453. function _ajax(url, fn, method, param, dataType) {
  4454. method = method || 'GET';
  4455. dataType = dataType || 'json';
  4456. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4457. xhr.open(method, url, true);
  4458. xhr.onreadystatechange = function () {
  4459. if (xhr.readyState == 4 && xhr.status == 200) {
  4460. if (fn) {
  4461. var data = _trim(xhr.responseText);
  4462. if (dataType == 'json') {
  4463. data = _json(data);
  4464. }
  4465. fn(data);
  4466. }
  4467. }
  4468. };
  4469. if (method == 'POST') {
  4470. var params = [];
  4471. _each(param, function(key, val) {
  4472. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4473. });
  4474. try {
  4475. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4476. } catch (e) {}
  4477. xhr.send(params.join('&'));
  4478. } else {
  4479. xhr.send(null);
  4480. }
  4481. }
  4482. K.loadScript = _loadScript;
  4483. K.loadStyle = _loadStyle;
  4484. K.ajax = _ajax;
  4485. var _plugins = {};
  4486. function _plugin(name, fn) {
  4487. if (name === undefined) {
  4488. return _plugins;
  4489. }
  4490. if (!fn) {
  4491. return _plugins[name];
  4492. }
  4493. _plugins[name] = fn;
  4494. }
  4495. var _language = {};
  4496. function _parseLangKey(key) {
  4497. var match, ns = 'core';
  4498. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4499. ns = match[1];
  4500. key = match[2];
  4501. }
  4502. return { ns : ns, key : key };
  4503. }
  4504. function _lang(mixed, langType) {
  4505. langType = langType === undefined ? K.options.langType : langType;
  4506. if (typeof mixed === 'string') {
  4507. if (!_language[langType]) {
  4508. return 'no language';
  4509. }
  4510. var pos = mixed.length - 1;
  4511. if (mixed.substr(pos) === '.') {
  4512. return _language[langType][mixed.substr(0, pos)];
  4513. }
  4514. var obj = _parseLangKey(mixed);
  4515. return _language[langType][obj.ns][obj.key];
  4516. }
  4517. _each(mixed, function(key, val) {
  4518. var obj = _parseLangKey(key);
  4519. if (!_language[langType]) {
  4520. _language[langType] = {};
  4521. }
  4522. if (!_language[langType][obj.ns]) {
  4523. _language[langType][obj.ns] = {};
  4524. }
  4525. _language[langType][obj.ns][obj.key] = val;
  4526. });
  4527. }
  4528. function _getImageFromRange(range, fn) {
  4529. if (range.collapsed) {
  4530. return;
  4531. }
  4532. range = range.cloneRange().up();
  4533. var sc = range.startContainer, so = range.startOffset;
  4534. if (!_WEBKIT && !range.isControl()) {
  4535. return;
  4536. }
  4537. var img = K(sc.childNodes[so]);
  4538. if (!img || img.name != 'img') {
  4539. return;
  4540. }
  4541. if (fn(img)) {
  4542. return img;
  4543. }
  4544. }
  4545. function _bindContextmenuEvent() {
  4546. var self = this, doc = self.edit.doc;
  4547. K(doc).contextmenu(function(e) {
  4548. if (self.menu) {
  4549. self.hideMenu();
  4550. }
  4551. if (!self.useContextmenu) {
  4552. e.preventDefault();
  4553. return;
  4554. }
  4555. if (self._contextmenus.length === 0) {
  4556. return;
  4557. }
  4558. var maxWidth = 0, items = [];
  4559. _each(self._contextmenus, function() {
  4560. if (this.title == '-') {
  4561. items.push(this);
  4562. return;
  4563. }
  4564. if (this.cond && this.cond()) {
  4565. items.push(this);
  4566. if (this.width && this.width > maxWidth) {
  4567. maxWidth = this.width;
  4568. }
  4569. }
  4570. });
  4571. while (items.length > 0 && items[0].title == '-') {
  4572. items.shift();
  4573. }
  4574. while (items.length > 0 && items[items.length - 1].title == '-') {
  4575. items.pop();
  4576. }
  4577. var prevItem = null;
  4578. _each(items, function(i) {
  4579. if (this.title == '-' && prevItem.title == '-') {
  4580. delete items[i];
  4581. }
  4582. prevItem = this;
  4583. });
  4584. if (items.length > 0) {
  4585. e.preventDefault();
  4586. var pos = K(self.edit.iframe).pos(),
  4587. menu = _menu({
  4588. x : pos.x + e.clientX,
  4589. y : pos.y + e.clientY,
  4590. width : maxWidth,
  4591. css : { visibility: 'hidden' },
  4592. shadowMode : self.shadowMode
  4593. });
  4594. _each(items, function() {
  4595. if (this.title) {
  4596. menu.addItem(this);
  4597. }
  4598. });
  4599. var docEl = _docElement(menu.doc),
  4600. menuHeight = menu.div.height();
  4601. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4602. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4603. }
  4604. menu.div.css('visibility', 'visible');
  4605. self.menu = menu;
  4606. }
  4607. });
  4608. }
  4609. function _bindNewlineEvent() {
  4610. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4611. if (_IE && newlineTag !== 'br') {
  4612. return;
  4613. }
  4614. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4615. return;
  4616. }
  4617. if (_OPERA && _V < 9) {
  4618. return;
  4619. }
  4620. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4621. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4622. function getAncestorTagName(range) {
  4623. var ancestor = K(range.commonAncestor());
  4624. while (ancestor) {
  4625. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4626. break;
  4627. }
  4628. ancestor = ancestor.parent();
  4629. }
  4630. return ancestor.name;
  4631. }
  4632. K(doc).keydown(function(e) {
  4633. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4634. return;
  4635. }
  4636. self.cmd.selection();
  4637. var tagName = getAncestorTagName(self.cmd.range);
  4638. if (tagName == 'marquee' || tagName == 'select') {
  4639. return;
  4640. }
  4641. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4642. e.preventDefault();
  4643. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4644. return;
  4645. }
  4646. if (!pSkipTagMap[tagName]) {
  4647. _nativeCommand(doc, 'formatblock', '<p>');
  4648. }
  4649. });
  4650. K(doc).keyup(function(e) {
  4651. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4652. return;
  4653. }
  4654. if (newlineTag == 'br') {
  4655. return;
  4656. }
  4657. if (_GECKO) {
  4658. var root = self.cmd.commonAncestor('p');
  4659. var a = self.cmd.commonAncestor('a');
  4660. if (a && a.text() == '') {
  4661. a.remove(true);
  4662. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4663. self.cmd.select();
  4664. }
  4665. return;
  4666. }
  4667. self.cmd.selection();
  4668. var tagName = getAncestorTagName(self.cmd.range);
  4669. if (tagName == 'marquee' || tagName == 'select') {
  4670. return;
  4671. }
  4672. if (!pSkipTagMap[tagName]) {
  4673. _nativeCommand(doc, 'formatblock', '<p>');
  4674. }
  4675. var div = self.cmd.commonAncestor('div');
  4676. if (div) {
  4677. var p = K('<p></p>'),
  4678. child = div[0].firstChild;
  4679. while (child) {
  4680. var next = child.nextSibling;
  4681. p.append(child);
  4682. child = next;
  4683. }
  4684. div.before(p);
  4685. div.remove();
  4686. self.cmd.range.selectNodeContents(p[0]);
  4687. self.cmd.select();
  4688. }
  4689. });
  4690. }
  4691. function _bindTabEvent() {
  4692. var self = this, doc = self.edit.doc;
  4693. K(doc).keydown(function(e) {
  4694. if (e.which == 9) {
  4695. e.preventDefault();
  4696. if (self.afterTab) {
  4697. self.afterTab.call(self, e);
  4698. return;
  4699. }
  4700. var cmd = self.cmd, range = cmd.range;
  4701. range.shrink();
  4702. if (range.collapsed && range.startContainer.nodeType == 1) {
  4703. range.insertNode(K('@&nbsp;', doc)[0]);
  4704. cmd.select();
  4705. }
  4706. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4707. }
  4708. });
  4709. }
  4710. function _bindFocusEvent() {
  4711. var self = this;
  4712. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4713. if (self.afterFocus) {
  4714. self.afterFocus.call(self, e);
  4715. }
  4716. }).blur(function(e) {
  4717. if (self.afterBlur) {
  4718. self.afterBlur.call(self, e);
  4719. }
  4720. });
  4721. }
  4722. function _removeBookmarkTag(html) {
  4723. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4724. }
  4725. function _removeTempTag(html) {
  4726. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4727. }
  4728. function _addBookmarkToStack(stack, bookmark) {
  4729. if (stack.length === 0) {
  4730. stack.push(bookmark);
  4731. return;
  4732. }
  4733. var prev = stack[stack.length - 1];
  4734. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4735. stack.push(bookmark);
  4736. }
  4737. }
  4738. function _undoToRedo(fromStack, toStack) {
  4739. var self = this, edit = self.edit,
  4740. body = edit.doc.body,
  4741. range, bookmark;
  4742. if (fromStack.length === 0) {
  4743. return self;
  4744. }
  4745. if (edit.designMode) {
  4746. range = self.cmd.range;
  4747. bookmark = range.createBookmark(true);
  4748. bookmark.html = body.innerHTML;
  4749. } else {
  4750. bookmark = {
  4751. html : body.innerHTML
  4752. };
  4753. }
  4754. _addBookmarkToStack(toStack, bookmark);
  4755. var prev = fromStack.pop();
  4756. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4757. prev = fromStack.pop();
  4758. }
  4759. if (edit.designMode) {
  4760. edit.html(prev.html);
  4761. if (prev.start) {
  4762. range.moveToBookmark(prev);
  4763. self.select();
  4764. }
  4765. } else {
  4766. K(body).html(_removeBookmarkTag(prev.html));
  4767. }
  4768. return self;
  4769. }
  4770. function KEditor(options) {
  4771. var self = this;
  4772. self.options = {};
  4773. function setOption(key, val) {
  4774. if (KEditor.prototype[key] === undefined) {
  4775. self[key] = val;
  4776. }
  4777. self.options[key] = val;
  4778. }
  4779. _each(options, function(key, val) {
  4780. setOption(key, options[key]);
  4781. });
  4782. _each(K.options, function(key, val) {
  4783. if (self[key] === undefined) {
  4784. setOption(key, val);
  4785. }
  4786. });
  4787. var se = K(self.srcElement || '<textarea/>');
  4788. if (!self.width) {
  4789. self.width = se[0].style.width || se.width();
  4790. }
  4791. if (!self.height) {
  4792. self.height = se[0].style.height || se.height();
  4793. }
  4794. setOption('width', _undef(self.width, self.minWidth));
  4795. setOption('height', _undef(self.height, self.minHeight));
  4796. setOption('width', _addUnit(self.width));
  4797. setOption('height', _addUnit(self.height));
  4798. if (_MOBILE && (!_IOS || _V < 534)) {
  4799. self.designMode = false;
  4800. }
  4801. self.srcElement = se;
  4802. self.initContent = '';
  4803. self.plugin = {};
  4804. self.isCreated = false;
  4805. self._handlers = {};
  4806. self._contextmenus = [];
  4807. self._undoStack = [];
  4808. self._redoStack = [];
  4809. self._firstAddBookmark = true;
  4810. self.menu = self.contextmenu = null;
  4811. self.dialogs = [];
  4812. }
  4813. KEditor.prototype = {
  4814. lang : function(mixed) {
  4815. return _lang(mixed, this.langType);
  4816. },
  4817. loadPlugin : function(name, fn) {
  4818. var self = this;
  4819. if (_plugins[name]) {
  4820. if (!_isFunction(_plugins[name])) {
  4821. setTimeout(function() {
  4822. self.loadPlugin(name, fn);
  4823. }, 100);
  4824. return self;
  4825. }
  4826. _plugins[name].call(self, KindEditor);
  4827. if (fn) {
  4828. fn.call(self);
  4829. }
  4830. return self;
  4831. }
  4832. _plugins[name] = 'loading';
  4833. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4834. setTimeout(function() {
  4835. if (_plugins[name]) {
  4836. self.loadPlugin(name, fn);
  4837. }
  4838. }, 0);
  4839. });
  4840. return self;
  4841. },
  4842. handler : function(key, fn) {
  4843. var self = this;
  4844. if (!self._handlers[key]) {
  4845. self._handlers[key] = [];
  4846. }
  4847. if (_isFunction(fn)) {
  4848. self._handlers[key].push(fn);
  4849. return self;
  4850. }
  4851. _each(self._handlers[key], function() {
  4852. fn = this.call(self, fn);
  4853. });
  4854. return fn;
  4855. },
  4856. clickToolbar : function(name, fn) {
  4857. var self = this, key = 'clickToolbar' + name;
  4858. if (fn === undefined) {
  4859. if (self._handlers[key]) {
  4860. return self.handler(key);
  4861. }
  4862. self.loadPlugin(name, function() {
  4863. self.handler(key);
  4864. });
  4865. return self;
  4866. }
  4867. return self.handler(key, fn);
  4868. },
  4869. updateState : function() {
  4870. var self = this;
  4871. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4872. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4873. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4874. });
  4875. return self;
  4876. },
  4877. addContextmenu : function(item) {
  4878. this._contextmenus.push(item);
  4879. return this;
  4880. },
  4881. afterCreate : function(fn) {
  4882. return this.handler('afterCreate', fn);
  4883. },
  4884. beforeRemove : function(fn) {
  4885. return this.handler('beforeRemove', fn);
  4886. },
  4887. beforeGetHtml : function(fn) {
  4888. return this.handler('beforeGetHtml', fn);
  4889. },
  4890. beforeSetHtml : function(fn) {
  4891. return this.handler('beforeSetHtml', fn);
  4892. },
  4893. afterSetHtml : function(fn) {
  4894. return this.handler('afterSetHtml', fn);
  4895. },
  4896. create : function() {
  4897. var self = this, fullscreenMode = self.fullscreenMode;
  4898. if (self.isCreated) {
  4899. return self;
  4900. }
  4901. if (self.srcElement.data('kindeditor')) {
  4902. return self;
  4903. }
  4904. self.srcElement.data('kindeditor', 'true');
  4905. if (fullscreenMode) {
  4906. _docElement().style.overflow = 'hidden';
  4907. } else {
  4908. _docElement().style.overflow = '';
  4909. }
  4910. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4911. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4912. if ((_IE && _V < 8) || _QUIRKS) {
  4913. height = _addUnit(_removeUnit(height) + 2);
  4914. }
  4915. var container = self.container = K(self.layout);
  4916. if (fullscreenMode) {
  4917. K(document.body).append(container);
  4918. } else {
  4919. self.srcElement.before(container);
  4920. }
  4921. var toolbarDiv = K('.toolbar', container),
  4922. editDiv = K('.edit', container),
  4923. statusbar = self.statusbar = K('.statusbar', container);
  4924. container.removeClass('container')
  4925. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4926. if (fullscreenMode) {
  4927. container.css({
  4928. position : 'absolute',
  4929. left : 0,
  4930. top : 0,
  4931. 'z-index' : 811211
  4932. });
  4933. if (!_GECKO) {
  4934. self._scrollPos = _getScrollPos();
  4935. }
  4936. window.scrollTo(0, 0);
  4937. K(document.body).css({
  4938. 'height' : '1px',
  4939. 'overflow' : 'hidden'
  4940. });
  4941. K(document.body.parentNode).css('overflow', 'hidden');
  4942. self._fullscreenExecuted = true;
  4943. } else {
  4944. if (self._fullscreenExecuted) {
  4945. K(document.body).css({
  4946. 'height' : '',
  4947. 'overflow' : ''
  4948. });
  4949. K(document.body.parentNode).css('overflow', '');
  4950. }
  4951. if (self._scrollPos) {
  4952. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  4953. }
  4954. }
  4955. var htmlList = [];
  4956. K.each(self.items, function(i, name) {
  4957. if (name == '|') {
  4958. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  4959. } else if (name == '/') {
  4960. htmlList.push('<div class="ke-hr"></div>');
  4961. } else {
  4962. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  4963. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  4964. }
  4965. });
  4966. var toolbar = self.toolbar = _toolbar({
  4967. src : toolbarDiv,
  4968. html : htmlList.join(''),
  4969. noDisableItems : self.noDisableItems,
  4970. click : function(e, name) {
  4971. e.stop();
  4972. if (self.menu) {
  4973. var menuName = self.menu.name;
  4974. self.hideMenu();
  4975. if (menuName === name) {
  4976. return;
  4977. }
  4978. }
  4979. self.clickToolbar(name);
  4980. }
  4981. });
  4982. var editHeight = _removeUnit(height) - toolbar.div.height();
  4983. var edit = self.edit = _edit({
  4984. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  4985. src : editDiv,
  4986. srcElement : self.srcElement,
  4987. designMode : self.designMode,
  4988. themesPath : self.themesPath,
  4989. bodyClass : self.bodyClass,
  4990. cssPath : self.cssPath,
  4991. cssData : self.cssData,
  4992. beforeGetHtml : function(html) {
  4993. html = self.beforeGetHtml(html);
  4994. html = _removeBookmarkTag(_removeTempTag(html));
  4995. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  4996. },
  4997. beforeSetHtml : function(html) {
  4998. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  4999. return self.beforeSetHtml(html);
  5000. },
  5001. afterSetHtml : function() {
  5002. self.edit = edit = this;
  5003. self.afterSetHtml();
  5004. },
  5005. afterCreate : function() {
  5006. self.edit = edit = this;
  5007. self.cmd = edit.cmd;
  5008. self._docMousedownFn = function(e) {
  5009. if (self.menu) {
  5010. self.hideMenu();
  5011. }
  5012. };
  5013. K(edit.doc, document).mousedown(self._docMousedownFn);
  5014. _bindContextmenuEvent.call(self);
  5015. _bindNewlineEvent.call(self);
  5016. _bindTabEvent.call(self);
  5017. _bindFocusEvent.call(self);
  5018. edit.afterChange(function(e) {
  5019. if (!edit.designMode) {
  5020. return;
  5021. }
  5022. self.updateState();
  5023. self.addBookmark();
  5024. if (self.options.afterChange) {
  5025. self.options.afterChange.call(self);
  5026. }
  5027. });
  5028. edit.textarea.keyup(function(e) {
  5029. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5030. if (self.options.afterChange) {
  5031. self.options.afterChange.call(self);
  5032. }
  5033. }
  5034. });
  5035. if (self.readonlyMode) {
  5036. self.readonly();
  5037. }
  5038. self.isCreated = true;
  5039. if (self.initContent === '') {
  5040. self.initContent = self.html();
  5041. }
  5042. if (self._undoStack.length > 0) {
  5043. var prev = self._undoStack.pop();
  5044. if (prev.start) {
  5045. self.html(prev.html);
  5046. edit.cmd.range.moveToBookmark(prev);
  5047. self.select();
  5048. }
  5049. }
  5050. self.afterCreate();
  5051. if (self.options.afterCreate) {
  5052. self.options.afterCreate.call(self);
  5053. }
  5054. }
  5055. });
  5056. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5057. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5058. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5059. if (self._fullscreenResizeHandler) {
  5060. K(window).unbind('resize', self._fullscreenResizeHandler);
  5061. self._fullscreenResizeHandler = null;
  5062. }
  5063. function initResize() {
  5064. if (statusbar.height() === 0) {
  5065. setTimeout(initResize, 100);
  5066. return;
  5067. }
  5068. self.resize(width, height, false);
  5069. }
  5070. initResize();
  5071. if (fullscreenMode) {
  5072. self._fullscreenResizeHandler = function(e) {
  5073. if (self.isCreated) {
  5074. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5075. }
  5076. };
  5077. K(window).bind('resize', self._fullscreenResizeHandler);
  5078. toolbar.select('fullscreen');
  5079. statusbar.first().css('visibility', 'hidden');
  5080. statusbar.last().css('visibility', 'hidden');
  5081. } else {
  5082. if (_GECKO) {
  5083. K(window).bind('scroll', function(e) {
  5084. self._scrollPos = _getScrollPos();
  5085. });
  5086. }
  5087. if (self.resizeType > 0) {
  5088. _drag({
  5089. moveEl : container,
  5090. clickEl : statusbar,
  5091. moveFn : function(x, y, width, height, diffX, diffY) {
  5092. height += diffY;
  5093. self.resize(null, height);
  5094. }
  5095. });
  5096. } else {
  5097. statusbar.first().css('visibility', 'hidden');
  5098. }
  5099. if (self.resizeType === 2) {
  5100. _drag({
  5101. moveEl : container,
  5102. clickEl : statusbar.last(),
  5103. moveFn : function(x, y, width, height, diffX, diffY) {
  5104. width += diffX;
  5105. height += diffY;
  5106. self.resize(width, height);
  5107. }
  5108. });
  5109. } else {
  5110. statusbar.last().css('visibility', 'hidden');
  5111. }
  5112. }
  5113. return self;
  5114. },
  5115. remove : function() {
  5116. var self = this;
  5117. if (!self.isCreated) {
  5118. return self;
  5119. }
  5120. self.beforeRemove();
  5121. self.srcElement.data('kindeditor', '');
  5122. if (self.menu) {
  5123. self.hideMenu();
  5124. }
  5125. _each(self.dialogs, function() {
  5126. self.hideDialog();
  5127. });
  5128. K(document).unbind('mousedown', self._docMousedownFn);
  5129. self.toolbar.remove();
  5130. self.edit.remove();
  5131. self.statusbar.last().unbind();
  5132. self.statusbar.unbind();
  5133. self.container.remove();
  5134. self.container = self.toolbar = self.edit = self.menu = null;
  5135. self.dialogs = [];
  5136. self.isCreated = false;
  5137. return self;
  5138. },
  5139. resize : function(width, height, updateProp) {
  5140. var self = this;
  5141. updateProp = _undef(updateProp, true);
  5142. if (width) {
  5143. if (!/%/.test(width)) {
  5144. width = _removeUnit(width);
  5145. width = width < self.minWidth ? self.minWidth : width;
  5146. }
  5147. self.container.css('width', _addUnit(width));
  5148. if (updateProp) {
  5149. self.width = _addUnit(width);
  5150. }
  5151. }
  5152. if (height) {
  5153. height = _removeUnit(height);
  5154. editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5155. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5156. self.edit.setHeight(editHeight);
  5157. if (updateProp) {
  5158. self.height = _addUnit(height);
  5159. }
  5160. }
  5161. return self;
  5162. },
  5163. select : function() {
  5164. this.isCreated && this.cmd.select();
  5165. return this;
  5166. },
  5167. html : function(val) {
  5168. var self = this;
  5169. if (val === undefined) {
  5170. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5171. }
  5172. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5173. if (self.isCreated) {
  5174. self.cmd.selection();
  5175. }
  5176. return self;
  5177. },
  5178. fullHtml : function() {
  5179. return this.isCreated ? this.edit.html(undefined, true) : '';
  5180. },
  5181. text : function(val) {
  5182. var self = this;
  5183. if (val === undefined) {
  5184. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5185. } else {
  5186. return self.html(_escape(val));
  5187. }
  5188. },
  5189. isEmpty : function() {
  5190. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5191. },
  5192. isDirty : function() {
  5193. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5194. },
  5195. selectedHtml : function() {
  5196. var val = this.isCreated ? this.cmd.range.html() : '';
  5197. val = _removeBookmarkTag(_removeTempTag(val));
  5198. return val;
  5199. },
  5200. count : function(mode) {
  5201. var self = this;
  5202. mode = (mode || 'html').toLowerCase();
  5203. if (mode === 'html') {
  5204. return self.html().length;
  5205. }
  5206. if (mode === 'text') {
  5207. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5208. }
  5209. return 0;
  5210. },
  5211. exec : function(key) {
  5212. key = key.toLowerCase();
  5213. var self = this, cmd = self.cmd,
  5214. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5215. if (changeFlag) {
  5216. self.addBookmark(false);
  5217. }
  5218. cmd[key].apply(cmd, _toArray(arguments, 1));
  5219. if (changeFlag) {
  5220. self.updateState();
  5221. self.addBookmark(false);
  5222. if (self.options.afterChange) {
  5223. self.options.afterChange.call(self);
  5224. }
  5225. }
  5226. return self;
  5227. },
  5228. insertHtml : function(val, quickMode) {
  5229. if (!this.isCreated) {
  5230. return this;
  5231. }
  5232. val = this.beforeSetHtml(val);
  5233. this.exec('inserthtml', val, quickMode);
  5234. return this;
  5235. },
  5236. appendHtml : function(val) {
  5237. this.html(this.html() + val);
  5238. if (this.isCreated) {
  5239. var cmd = this.cmd;
  5240. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5241. cmd.select();
  5242. }
  5243. return this;
  5244. },
  5245. sync : function() {
  5246. _elementVal(this.srcElement, this.html());
  5247. return this;
  5248. },
  5249. focus : function() {
  5250. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5251. return this;
  5252. },
  5253. blur : function() {
  5254. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5255. return this;
  5256. },
  5257. addBookmark : function(checkSize) {
  5258. checkSize = _undef(checkSize, true);
  5259. var self = this, edit = self.edit,
  5260. body = edit.doc.body,
  5261. html = _removeTempTag(body.innerHTML), bookmark;
  5262. if (checkSize && self._undoStack.length > 0) {
  5263. var prev = self._undoStack[self._undoStack.length - 1];
  5264. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5265. return self;
  5266. }
  5267. }
  5268. if (edit.designMode && !self._firstAddBookmark) {
  5269. var range = self.cmd.range;
  5270. bookmark = range.createBookmark(true);
  5271. bookmark.html = _removeTempTag(body.innerHTML);
  5272. range.moveToBookmark(bookmark);
  5273. } else {
  5274. bookmark = {
  5275. html : html
  5276. };
  5277. }
  5278. self._firstAddBookmark = false;
  5279. _addBookmarkToStack(self._undoStack, bookmark);
  5280. return self;
  5281. },
  5282. undo : function() {
  5283. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5284. },
  5285. redo : function() {
  5286. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5287. },
  5288. fullscreen : function(bool) {
  5289. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5290. this.addBookmark(false);
  5291. return this.remove().create();
  5292. },
  5293. readonly : function(isReadonly) {
  5294. isReadonly = _undef(isReadonly, true);
  5295. var self = this, edit = self.edit, doc = edit.doc;
  5296. if (self.designMode) {
  5297. self.toolbar.disableAll(isReadonly, []);
  5298. } else {
  5299. _each(self.noDisableItems, function() {
  5300. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5301. });
  5302. }
  5303. if (_IE) {
  5304. doc.body.contentEditable = !isReadonly;
  5305. } else {
  5306. doc.designMode = isReadonly ? 'off' : 'on';
  5307. }
  5308. edit.textarea[0].disabled = isReadonly;
  5309. },
  5310. createMenu : function(options) {
  5311. var self = this,
  5312. name = options.name,
  5313. knode = self.toolbar.get(name),
  5314. pos = knode.pos();
  5315. options.x = pos.x;
  5316. options.y = pos.y + knode.height();
  5317. options.z = self.options.zIndex;
  5318. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5319. if (options.selectedColor !== undefined) {
  5320. options.cls = 'ke-colorpicker-' + self.themeType;
  5321. options.noColor = self.lang('noColor');
  5322. self.menu = _colorpicker(options);
  5323. } else {
  5324. options.cls = 'ke-menu-' + self.themeType;
  5325. options.centerLineMode = false;
  5326. self.menu = _menu(options);
  5327. }
  5328. return self.menu;
  5329. },
  5330. hideMenu : function() {
  5331. this.menu.remove();
  5332. this.menu = null;
  5333. return this;
  5334. },
  5335. hideContextmenu : function() {
  5336. this.contextmenu.remove();
  5337. this.contextmenu = null;
  5338. return this;
  5339. },
  5340. createDialog : function(options) {
  5341. var self = this, name = options.name;
  5342. options.z = self.options.zIndex;
  5343. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5344. options.closeBtn = _undef(options.closeBtn, {
  5345. name : self.lang('close'),
  5346. click : function(e) {
  5347. self.hideDialog();
  5348. if (_IE && self.cmd) {
  5349. self.cmd.select();
  5350. }
  5351. }
  5352. });
  5353. options.noBtn = _undef(options.noBtn, {
  5354. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5355. click : function(e) {
  5356. self.hideDialog();
  5357. if (_IE && self.cmd) {
  5358. self.cmd.select();
  5359. }
  5360. }
  5361. });
  5362. if (self.dialogAlignType != 'page') {
  5363. options.alignEl = self.container;
  5364. }
  5365. options.cls = 'ke-dialog-' + self.themeType;
  5366. if (self.dialogs.length > 0) {
  5367. var firstDialog = self.dialogs[0],
  5368. parentDialog = self.dialogs[self.dialogs.length - 1];
  5369. firstDialog.setMaskIndex(parentDialog.z + 2);
  5370. options.z = parentDialog.z + 3;
  5371. options.showMask = false;
  5372. }
  5373. var dialog = _dialog(options);
  5374. self.dialogs.push(dialog);
  5375. return dialog;
  5376. },
  5377. hideDialog : function() {
  5378. var self = this;
  5379. if (self.dialogs.length > 0) {
  5380. self.dialogs.pop().remove();
  5381. }
  5382. if (self.dialogs.length > 0) {
  5383. var firstDialog = self.dialogs[0],
  5384. parentDialog = self.dialogs[self.dialogs.length - 1];
  5385. firstDialog.setMaskIndex(parentDialog.z - 1);
  5386. }
  5387. return self;
  5388. },
  5389. errorDialog : function(html) {
  5390. var self = this;
  5391. var dialog = self.createDialog({
  5392. width : 750,
  5393. title : self.lang('uploadError'),
  5394. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5395. });
  5396. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5397. doc.open();
  5398. doc.write(html);
  5399. doc.close();
  5400. K(doc.body).css('background-color', '#FFF');
  5401. iframe[0].contentWindow.focus();
  5402. return self;
  5403. }
  5404. };
  5405. function _editor(options) {
  5406. return new KEditor(options);
  5407. }
  5408. _instances = [];
  5409. function _create(expr, options) {
  5410. options = options || {};
  5411. options.basePath = _undef(options.basePath, K.basePath);
  5412. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5413. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5414. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5415. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5416. var themeType = _undef(options.themeType, K.options.themeType);
  5417. _loadStyle(options.themesPath + 'default/default.css');
  5418. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5419. }
  5420. function create(editor) {
  5421. _each(_plugins, function(name, fn) {
  5422. if (_isFunction(fn)) {
  5423. fn.call(editor, KindEditor);
  5424. }
  5425. });
  5426. return editor.create();
  5427. }
  5428. var knode = K(expr);
  5429. if (!knode || knode.length === 0) {
  5430. return;
  5431. }
  5432. if (knode.length > 1) {
  5433. knode.each(function() {
  5434. _create(this, options);
  5435. });
  5436. return _instances[0];
  5437. }
  5438. options.srcElement = knode[0];
  5439. var editor = new KEditor(options);
  5440. _instances.push(editor);
  5441. if (_language[editor.langType]) {
  5442. return create(editor);
  5443. }
  5444. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5445. create(editor);
  5446. });
  5447. return editor;
  5448. }
  5449. function _eachEditor(expr, fn) {
  5450. K(expr).each(function(i, el) {
  5451. K.each(_instances, function(j, editor) {
  5452. if (editor && editor.srcElement[0] == el) {
  5453. fn.call(editor, j);
  5454. return false;
  5455. }
  5456. });
  5457. });
  5458. }
  5459. K.remove = function(expr) {
  5460. _eachEditor(expr, function(i) {
  5461. this.remove();
  5462. _instances.splice(i, 1);
  5463. });
  5464. };
  5465. K.sync = function(expr) {
  5466. _eachEditor(expr, function() {
  5467. this.sync();
  5468. });
  5469. };
  5470. K.html = function(expr, val) {
  5471. _eachEditor(expr, function() {
  5472. this.html(val);
  5473. });
  5474. };
  5475. K.insertHtml = function(expr, val) {
  5476. _eachEditor(expr, function() {
  5477. this.insertHtml(val);
  5478. });
  5479. };
  5480. K.appendHtml = function(expr, val) {
  5481. _eachEditor(expr, function() {
  5482. this.appendHtml(val);
  5483. });
  5484. };
  5485. if (_IE && _V < 7) {
  5486. _nativeCommand(document, 'BackgroundImageCache', true);
  5487. }
  5488. K.EditorClass = KEditor;
  5489. K.editor = _editor;
  5490. K.create = _create;
  5491. K.instances = _instances;
  5492. K.plugin = _plugin;
  5493. K.lang = _lang;
  5494. _plugin('core', function(K) {
  5495. var self = this,
  5496. shortcutKeys = {
  5497. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5498. };
  5499. self.afterSetHtml(function() {
  5500. if (self.options.afterChange) {
  5501. self.options.afterChange.call(self);
  5502. }
  5503. });
  5504. self.afterCreate(function() {
  5505. if (self.syncType != 'form') {
  5506. return;
  5507. }
  5508. var el = K(self.srcElement), hasForm = false;
  5509. while ((el = el.parent())) {
  5510. if (el.name == 'form') {
  5511. hasForm = true;
  5512. break;
  5513. }
  5514. }
  5515. if (hasForm) {
  5516. el.bind('submit', function(e) {
  5517. self.sync();
  5518. K(window).bind('unload', function() {
  5519. self.edit.textarea.remove();
  5520. });
  5521. });
  5522. var resetBtn = K('[type="reset"]', el);
  5523. resetBtn.click(function() {
  5524. self.html(self.initContent);
  5525. self.cmd.selection();
  5526. });
  5527. self.beforeRemove(function() {
  5528. el.unbind();
  5529. resetBtn.unbind();
  5530. });
  5531. }
  5532. });
  5533. self.clickToolbar('source', function() {
  5534. if (self.edit.designMode) {
  5535. self.toolbar.disableAll(true);
  5536. self.edit.design(false);
  5537. self.toolbar.select('source');
  5538. } else {
  5539. self.toolbar.disableAll(false);
  5540. self.edit.design(true);
  5541. self.toolbar.unselect('source');
  5542. if (_GECKO) {
  5543. setTimeout(function() {
  5544. self.cmd.selection();
  5545. }, 0);
  5546. } else {
  5547. self.cmd.selection();
  5548. }
  5549. }
  5550. self.designMode = self.edit.designMode;
  5551. });
  5552. self.afterCreate(function() {
  5553. if (!self.designMode) {
  5554. self.toolbar.disableAll(true).select('source');
  5555. }
  5556. });
  5557. self.clickToolbar('fullscreen', function() {
  5558. self.fullscreen();
  5559. });
  5560. if (self.fullscreenShortcut) {
  5561. var loaded = false;
  5562. self.afterCreate(function() {
  5563. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5564. if (e.which == 27) {
  5565. setTimeout(function() {
  5566. self.fullscreen();
  5567. }, 0);
  5568. }
  5569. });
  5570. if (loaded) {
  5571. if (_IE && !self.designMode) {
  5572. return;
  5573. }
  5574. self.focus();
  5575. }
  5576. if (!loaded) {
  5577. loaded = true;
  5578. }
  5579. });
  5580. }
  5581. _each('undo,redo'.split(','), function(i, name) {
  5582. if (shortcutKeys[name]) {
  5583. self.afterCreate(function() {
  5584. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5585. self.clickToolbar(name);
  5586. });
  5587. });
  5588. }
  5589. self.clickToolbar(name, function() {
  5590. self[name]();
  5591. });
  5592. });
  5593. self.clickToolbar('formatblock', function() {
  5594. var blocks = self.lang('formatblock.formatBlock'),
  5595. heights = {
  5596. h1 : 28,
  5597. h2 : 24,
  5598. h3 : 18,
  5599. H4 : 14,
  5600. p : 12
  5601. },
  5602. curVal = self.cmd.val('formatblock'),
  5603. menu = self.createMenu({
  5604. name : 'formatblock',
  5605. width : self.langType == 'en' ? 200 : 150
  5606. });
  5607. _each(blocks, function(key, val) {
  5608. var style = 'font-size:' + heights[key] + 'px;';
  5609. if (key.charAt(0) === 'h') {
  5610. style += 'font-weight:bold;';
  5611. }
  5612. menu.addItem({
  5613. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5614. height : heights[key] + 12,
  5615. checked : (curVal === key || curVal === val),
  5616. click : function() {
  5617. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5618. }
  5619. });
  5620. });
  5621. });
  5622. self.clickToolbar('fontname', function() {
  5623. var curVal = self.cmd.val('fontname'),
  5624. menu = self.createMenu({
  5625. name : 'fontname',
  5626. width : 150
  5627. });
  5628. _each(self.lang('fontname.fontName'), function(key, val) {
  5629. menu.addItem({
  5630. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5631. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5632. click : function() {
  5633. self.exec('fontname', key).hideMenu();
  5634. }
  5635. });
  5636. });
  5637. });
  5638. self.clickToolbar('fontsize', function() {
  5639. var curVal = self.cmd.val('fontsize'),
  5640. menu = self.createMenu({
  5641. name : 'fontsize',
  5642. width : 150
  5643. });
  5644. _each(self.fontSizeTable, function(i, val) {
  5645. menu.addItem({
  5646. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5647. height : _removeUnit(val) + 12,
  5648. checked : curVal === val,
  5649. click : function() {
  5650. self.exec('fontsize', val).hideMenu();
  5651. }
  5652. });
  5653. });
  5654. });
  5655. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5656. self.clickToolbar(name, function() {
  5657. self.createMenu({
  5658. name : name,
  5659. selectedColor : self.cmd.val(name) || 'default',
  5660. colors : self.colorTable,
  5661. click : function(color) {
  5662. self.exec(name, color).hideMenu();
  5663. }
  5664. });
  5665. });
  5666. });
  5667. _each(('cut,copy,paste').split(','), function(i, name) {
  5668. self.clickToolbar(name, function() {
  5669. self.focus();
  5670. try {
  5671. self.exec(name, null);
  5672. } catch(e) {
  5673. alert(self.lang(name + 'Error'));
  5674. }
  5675. });
  5676. });
  5677. self.clickToolbar('about', function() {
  5678. var html = '<div style="margin:20px;">' +
  5679. '<div>KindEditor ' + _VERSION + '</div>' +
  5680. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5681. '</div>';
  5682. self.createDialog({
  5683. name : 'about',
  5684. width : 350,
  5685. title : self.lang('about'),
  5686. body : html
  5687. });
  5688. });
  5689. self.plugin.getSelectedLink = function() {
  5690. return self.cmd.commonAncestor('a');
  5691. };
  5692. self.plugin.getSelectedImage = function() {
  5693. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5694. return !/^ke-\w+$/i.test(img[0].className);
  5695. });
  5696. };
  5697. self.plugin.getSelectedFlash = function() {
  5698. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5699. return img[0].className == 'ke-flash';
  5700. });
  5701. };
  5702. self.plugin.getSelectedMedia = function() {
  5703. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5704. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5705. });
  5706. };
  5707. self.plugin.getSelectedAnchor = function() {
  5708. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5709. return img[0].className == 'ke-anchor';
  5710. });
  5711. };
  5712. _each('link,image,flash,media,anchor'.split(','), function(i, name) {
  5713. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5714. _each('edit,delete'.split(','), function(j, val) {
  5715. self.addContextmenu({
  5716. title : self.lang(val + uName),
  5717. click : function() {
  5718. self.loadPlugin(name, function() {
  5719. self.plugin[name][val]();
  5720. self.hideMenu();
  5721. });
  5722. },
  5723. cond : self.plugin['getSelected' + uName],
  5724. width : 150,
  5725. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5726. });
  5727. });
  5728. self.addContextmenu({ title : '-' });
  5729. });
  5730. self.plugin.getSelectedTable = function() {
  5731. return self.cmd.commonAncestor('table');
  5732. };
  5733. self.plugin.getSelectedRow = function() {
  5734. return self.cmd.commonAncestor('tr');
  5735. };
  5736. self.plugin.getSelectedCell = function() {
  5737. return self.cmd.commonAncestor('td');
  5738. };
  5739. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5740. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5741. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5742. self.addContextmenu({
  5743. title : self.lang('table' + val),
  5744. click : function() {
  5745. self.loadPlugin('table', function() {
  5746. self.plugin.table[val]();
  5747. self.hideMenu();
  5748. });
  5749. },
  5750. cond : cond,
  5751. width : 170,
  5752. iconClass : 'ke-icon-table' + val
  5753. });
  5754. });
  5755. self.addContextmenu({ title : '-' });
  5756. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5757. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5758. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5759. if (shortcutKeys[name]) {
  5760. self.afterCreate(function() {
  5761. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5762. self.cmd.selection();
  5763. self.clickToolbar(name);
  5764. });
  5765. });
  5766. }
  5767. self.clickToolbar(name, function() {
  5768. self.focus().exec(name, null);
  5769. });
  5770. });
  5771. self.afterCreate(function() {
  5772. var doc = self.edit.doc, cmd, bookmark, div,
  5773. cls = '__kindeditor_paste__', pasting = false;
  5774. function movePastedData() {
  5775. cmd.range.moveToBookmark(bookmark);
  5776. cmd.select();
  5777. if (_WEBKIT) {
  5778. K('div.' + cls, div).each(function() {
  5779. K(this).after('<br />').remove(true);
  5780. });
  5781. K('span.Apple-style-span', div).remove(true);
  5782. K('span.Apple-tab-span', div).remove(true);
  5783. K('span[style]', div).each(function() {
  5784. if (K(this).css('white-space') == 'nowrap') {
  5785. K(this).remove(true);
  5786. }
  5787. });
  5788. K('meta', div).remove();
  5789. }
  5790. var html = div[0].innerHTML;
  5791. div.remove();
  5792. if (html === '') {
  5793. return;
  5794. }
  5795. if (_WEBKIT) {
  5796. html = html.replace(/(<br>)\1/ig, '$1');
  5797. }
  5798. if (self.pasteType === 2) {
  5799. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5800. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5801. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5802. } else {
  5803. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5804. html = self.beforeSetHtml(html);
  5805. }
  5806. }
  5807. if (self.pasteType === 1) {
  5808. html = html.replace(/&nbsp;/ig, ' ');
  5809. html = html.replace(/\n\s*\n/g, '\n');
  5810. html = html.replace(/<br[^>]*>/ig, '\n');
  5811. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5812. html = html.replace(/<[^>]+>/g, '');
  5813. html = html.replace(/ {2}/g, ' &nbsp;');
  5814. if (self.newlineTag == 'p') {
  5815. if (/\n/.test(html)) {
  5816. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5817. }
  5818. } else {
  5819. html = html.replace(/\n/g, '<br />$&');
  5820. }
  5821. }
  5822. self.insertHtml(html, true);
  5823. }
  5824. K(doc.body).bind('paste', function(e){
  5825. if (self.pasteType === 0) {
  5826. e.stop();
  5827. return;
  5828. }
  5829. if (pasting) {
  5830. return;
  5831. }
  5832. pasting = true;
  5833. K('div.' + cls, doc).remove();
  5834. cmd = self.cmd.selection();
  5835. bookmark = cmd.range.createBookmark();
  5836. div = K('<div class="' + cls + '"></div>', doc).css({
  5837. position : 'absolute',
  5838. width : '1px',
  5839. height : '1px',
  5840. overflow : 'hidden',
  5841. left : '-1981px',
  5842. top : K(bookmark.start).pos().y + 'px',
  5843. 'white-space' : 'nowrap'
  5844. });
  5845. K(doc.body).append(div);
  5846. if (_IE) {
  5847. var rng = cmd.range.get(true);
  5848. rng.moveToElementText(div[0]);
  5849. rng.select();
  5850. rng.execCommand('paste');
  5851. e.preventDefault();
  5852. } else {
  5853. cmd.range.selectNodeContents(div[0]);
  5854. cmd.select();
  5855. }
  5856. setTimeout(function() {
  5857. movePastedData();
  5858. pasting = false;
  5859. }, 0);
  5860. });
  5861. });
  5862. self.beforeGetHtml(function(html) {
  5863. if (_IE && _V <= 8) {
  5864. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  5865. return unescape(tag);
  5866. });
  5867. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  5868. if (!/\s+type="[^"]+"/i.test($0)) {
  5869. return $1 + ' type="text"' + $2;
  5870. }
  5871. return $0;
  5872. });
  5873. }
  5874. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  5875. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  5876. })
  5877. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  5878. var imgAttrs = _getAttrList(full);
  5879. var styles = _getCssList(imgAttrs.style || '');
  5880. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  5881. var width = _undef(styles.width, '');
  5882. var height = _undef(styles.height, '');
  5883. if (/px/i.test(width)) {
  5884. width = _removeUnit(width);
  5885. }
  5886. if (/px/i.test(height)) {
  5887. height = _removeUnit(height);
  5888. }
  5889. attrs.width = _undef(imgAttrs.width, width);
  5890. attrs.height = _undef(imgAttrs.height, height);
  5891. return _mediaEmbed(attrs);
  5892. })
  5893. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  5894. var imgAttrs = _getAttrList(full);
  5895. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  5896. })
  5897. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  5898. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  5899. })
  5900. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  5901. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  5902. })
  5903. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  5904. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  5905. return $1 + _unescape(src) + $2;
  5906. });
  5907. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  5908. return full;
  5909. })
  5910. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  5911. return start + end;
  5912. });
  5913. });
  5914. self.beforeSetHtml(function(html) {
  5915. if (_IE && _V <= 8) {
  5916. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  5917. var attrs = _getAttrList(full);
  5918. var styles = _getCssList(attrs.style || '');
  5919. if (styles.display == 'none') {
  5920. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  5921. }
  5922. return full;
  5923. });
  5924. }
  5925. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  5926. var attrs = _getAttrList(full);
  5927. attrs.src = _undef(attrs.src, '');
  5928. attrs.width = _undef(attrs.width, 0);
  5929. attrs.height = _undef(attrs.height, 0);
  5930. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  5931. })
  5932. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  5933. var attrs = _getAttrList(full);
  5934. if (attrs.href !== undefined) {
  5935. return full;
  5936. }
  5937. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  5938. })
  5939. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  5940. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5941. })
  5942. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  5943. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5944. })
  5945. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  5946. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  5947. return full;
  5948. }
  5949. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  5950. return full;
  5951. })
  5952. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  5953. return start + 'data-ke-' + end;
  5954. })
  5955. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  5956. if (full.indexOf('ke-zeroborder') >= 0) {
  5957. return full;
  5958. }
  5959. return _addClassToTag(full, 'ke-zeroborder');
  5960. });
  5961. });
  5962. });
  5963. })(window);
  5964. /*******************************************************************************
  5965. * KindEditor - WYSIWYG HTML Editor for Internet
  5966. * Copyright (C) 2006-2011 kindsoft.net
  5967. *
  5968. * @author Roddy <luolonghao@gmail.com>
  5969. * @site http://www.kindsoft.net/
  5970. * @licence http://www.kindsoft.net/license.php
  5971. *******************************************************************************/
  5972. KindEditor.lang({
  5973. source : 'HTML代码',
  5974. preview : '预览',
  5975. undo : '后退(Ctrl+Z)',
  5976. redo : '前进(Ctrl+Y)',
  5977. cut : '剪切(Ctrl+X)',
  5978. copy : '复制(Ctrl+C)',
  5979. paste : '粘贴(Ctrl+V)',
  5980. plainpaste : '粘贴为无格式文本',
  5981. wordpaste : '从Word粘贴',
  5982. selectall : '全选(Ctrl+A)',
  5983. justifyleft : '左对齐',
  5984. justifycenter : '居中',
  5985. justifyright : '右对齐',
  5986. justifyfull : '两端对齐',
  5987. insertorderedlist : '编号',
  5988. insertunorderedlist : '项目符号',
  5989. indent : '增加缩进',
  5990. outdent : '减少缩进',
  5991. subscript : '下标',
  5992. superscript : '上标',
  5993. formatblock : '段落',
  5994. fontname : '字体',
  5995. fontsize : '文字大小',
  5996. forecolor : '文字颜色',
  5997. hilitecolor : '文字背景',
  5998. bold : '粗体(Ctrl+B)',
  5999. italic : '斜体(Ctrl+I)',
  6000. underline : '下划线(Ctrl+U)',
  6001. strikethrough : '删除线',
  6002. removeformat : '删除格式',
  6003. image : '图片',
  6004. multiimage : '批量图片上传',
  6005. flash : 'Flash',
  6006. media : '视音频',
  6007. table : '表格',
  6008. tablecell : '单元格',
  6009. hr : '插入横线',
  6010. emoticons : '插入表情',
  6011. link : '超级链接',
  6012. unlink : '取消超级链接',
  6013. fullscreen : '全屏显示',
  6014. about : '关于',
  6015. print : '打印(Ctrl+P)',
  6016. filemanager : '文件空间',
  6017. code : '插入程序代码',
  6018. map : 'Google地图',
  6019. baidumap : '百度地图',
  6020. lineheight : '行距',
  6021. clearhtml : '清理HTML代码',
  6022. pagebreak : '插入分页符',
  6023. quickformat : '一键排版',
  6024. insertfile : '插入文件',
  6025. template : '插入模板',
  6026. anchor : '锚点',
  6027. yes : '确定',
  6028. no : '取消',
  6029. close : '关闭',
  6030. editImage : '图片属性',
  6031. deleteImage : '删除图片',
  6032. editFlash : 'Flash属性',
  6033. deleteFlash : '删除Flash',
  6034. editMedia : '视音频属性',
  6035. deleteMedia : '删除视音频',
  6036. editLink : '超级链接属性',
  6037. deleteLink : '取消超级链接',
  6038. editAnchor : '锚点属性',
  6039. deleteAnchor : '删除锚点',
  6040. tableprop : '表格属性',
  6041. tablecellprop : '单元格属性',
  6042. tableinsert : '插入表格',
  6043. tabledelete : '删除表格',
  6044. tablecolinsertleft : '左侧插入列',
  6045. tablecolinsertright : '右侧插入列',
  6046. tablerowinsertabove : '上方插入行',
  6047. tablerowinsertbelow : '下方插入行',
  6048. tablerowmerge : '向下合并单元格',
  6049. tablecolmerge : '向右合并单元格',
  6050. tablerowsplit : '拆分行',
  6051. tablecolsplit : '拆分列',
  6052. tablecoldelete : '删除列',
  6053. tablerowdelete : '删除行',
  6054. noColor : '无颜色',
  6055. pleaseSelectFile : '请选择文件。',
  6056. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6057. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6058. invalidWidth : "宽度必须为数字。",
  6059. invalidHeight : "高度必须为数字。",
  6060. invalidBorder : "边框必须为数字。",
  6061. invalidUrl : "请输入有效的URL地址。",
  6062. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6063. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6064. invalidPadding : '边距必须为数字。',
  6065. invalidSpacing : '间距必须为数字。',
  6066. invalidJson : '服务器发生故障。',
  6067. uploadSuccess : '上传成功。',
  6068. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6069. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6070. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6071. ajaxLoading : '加载中,请稍候 ...',
  6072. uploadLoading : '上传中,请稍候 ...',
  6073. uploadError : '上传错误',
  6074. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6075. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6076. 'code.pleaseInput' : '请输入程序代码。',
  6077. 'link.url' : 'URL',
  6078. 'link.linkType' : '打开类型',
  6079. 'link.newWindow' : '新窗口',
  6080. 'link.selfWindow' : '当前窗口',
  6081. 'flash.url' : 'URL',
  6082. 'flash.width' : '宽度',
  6083. 'flash.height' : '高度',
  6084. 'flash.upload' : '上传',
  6085. 'flash.viewServer' : '文件空间',
  6086. 'media.url' : 'URL',
  6087. 'media.width' : '宽度',
  6088. 'media.height' : '高度',
  6089. 'media.autostart' : '自动播放',
  6090. 'media.upload' : '上传',
  6091. 'media.viewServer' : '文件空间',
  6092. 'image.remoteImage' : '网络图片',
  6093. 'image.localImage' : '本地上传',
  6094. 'image.remoteUrl' : '图片地址',
  6095. 'image.localUrl' : '上传文件',
  6096. 'image.size' : '图片大小',
  6097. 'image.width' : '宽',
  6098. 'image.height' : '高',
  6099. 'image.resetSize' : '重置大小',
  6100. 'image.align' : '对齐方式',
  6101. 'image.defaultAlign' : '默认方式',
  6102. 'image.leftAlign' : '左对齐',
  6103. 'image.rightAlign' : '右对齐',
  6104. 'image.imgTitle' : '图片说明',
  6105. 'image.upload' : '浏览...',
  6106. 'image.viewServer' : '图片空间',
  6107. 'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6108. 'multiimage.startUpload' : '开始上传',
  6109. 'multiimage.clearAll' : '全部清空',
  6110. 'multiimage.insertAll' : '全部插入',
  6111. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6112. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6113. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6114. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6115. 'multiimage.unknownError' : '发生异常,无法上传。',
  6116. 'multiimage.pending' : '等待上传',
  6117. 'multiimage.uploadError' : '上传失败',
  6118. 'filemanager.emptyFolder' : '空文件夹',
  6119. 'filemanager.moveup' : '移到上一级文件夹',
  6120. 'filemanager.viewType' : '显示方式:',
  6121. 'filemanager.viewImage' : '缩略图',
  6122. 'filemanager.listImage' : '详细信息',
  6123. 'filemanager.orderType' : '排序方式:',
  6124. 'filemanager.fileName' : '名称',
  6125. 'filemanager.fileSize' : '大小',
  6126. 'filemanager.fileType' : '类型',
  6127. 'insertfile.url' : 'URL',
  6128. 'insertfile.title' : '文件说明',
  6129. 'insertfile.upload' : '上传',
  6130. 'insertfile.viewServer' : '文件空间',
  6131. 'table.cells' : '单元格数',
  6132. 'table.rows' : '行数',
  6133. 'table.cols' : '列数',
  6134. 'table.size' : '大小',
  6135. 'table.width' : '宽度',
  6136. 'table.height' : '高度',
  6137. 'table.percent' : '%',
  6138. 'table.px' : 'px',
  6139. 'table.space' : '边距间距',
  6140. 'table.padding' : '边距',
  6141. 'table.spacing' : '间距',
  6142. 'table.align' : '对齐方式',
  6143. 'table.textAlign' : '水平对齐',
  6144. 'table.verticalAlign' : '垂直对齐',
  6145. 'table.alignDefault' : '默认',
  6146. 'table.alignLeft' : '左对齐',
  6147. 'table.alignCenter' : '居中',
  6148. 'table.alignRight' : '右对齐',
  6149. 'table.alignTop' : '顶部',
  6150. 'table.alignMiddle' : '中部',
  6151. 'table.alignBottom' : '底部',
  6152. 'table.alignBaseline' : '基线',
  6153. 'table.border' : '边框',
  6154. 'table.borderWidth' : '边框',
  6155. 'table.borderColor' : '颜色',
  6156. 'table.backgroundColor' : '背景颜色',
  6157. 'map.address' : '地址: ',
  6158. 'map.search' : '搜索',
  6159. 'baidumap.address' : '地址: ',
  6160. 'baidumap.search' : '搜索',
  6161. 'baidumap.insertDynamicMap' : '插入动态地图',
  6162. 'anchor.name' : '锚点名称',
  6163. 'formatblock.formatBlock' : {
  6164. h1 : '标题 1',
  6165. h2 : '标题 2',
  6166. h3 : '标题 3',
  6167. h4 : '标题 4',
  6168. p : '正 文'
  6169. },
  6170. 'fontname.fontName' : {
  6171. 'SimSun' : '宋体',
  6172. 'NSimSun' : '新宋体',
  6173. 'FangSong_GB2312' : '仿宋_GB2312',
  6174. 'KaiTi_GB2312' : '楷体_GB2312',
  6175. 'SimHei' : '黑体',
  6176. 'Microsoft YaHei' : '微软雅黑',
  6177. 'Arial' : 'Arial',
  6178. 'Arial Black' : 'Arial Black',
  6179. 'Times New Roman' : 'Times New Roman',
  6180. 'Courier New' : 'Courier New',
  6181. 'Tahoma' : 'Tahoma',
  6182. 'Verdana' : 'Verdana'
  6183. },
  6184. 'lineheight.lineHeight' : [
  6185. {'1' : '单倍行距'},
  6186. {'1.5' : '1.5倍行距'},
  6187. {'2' : '2倍行距'},
  6188. {'2.5' : '2.5倍行距'},
  6189. {'3' : '3倍行距'}
  6190. ],
  6191. 'template.selectTemplate' : '可选模板',
  6192. 'template.replaceContent' : '替换当前内容',
  6193. 'template.fileList' : {
  6194. '1.html' : '图片和文字',
  6195. '2.html' : '表格',
  6196. '3.html' : '项目编号'
  6197. }
  6198. }, 'zh_CN');
  6199. /*******************************************************************************
  6200. * KindEditor - WYSIWYG HTML Editor for Internet
  6201. * Copyright (C) 2006-2011 kindsoft.net
  6202. *
  6203. * @author Roddy <luolonghao@gmail.com>
  6204. * @site http://www.kindsoft.net/
  6205. * @licence http://www.kindsoft.net/license.php
  6206. *******************************************************************************/
  6207. KindEditor.plugin('anchor', function(K) {
  6208. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6209. self.plugin.anchor = {
  6210. edit : function() {
  6211. var html = ['<div style="padding:20px;">',
  6212. '<div class="ke-dialog-row">',
  6213. '<label for="keName">' + lang.name + '</label>',
  6214. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6215. '</div>',
  6216. '</div>'].join('');
  6217. var dialog = self.createDialog({
  6218. name : name,
  6219. width : 300,
  6220. title : self.lang(name),
  6221. body : html,
  6222. yesBtn : {
  6223. name : self.lang('yes'),
  6224. click : function(e) {
  6225. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6226. }
  6227. }
  6228. });
  6229. var div = dialog.div,
  6230. nameBox = K('input[name="name"]', div);
  6231. var img = self.plugin.getSelectedAnchor();
  6232. if (img) {
  6233. nameBox.val(unescape(img.attr('data-ke-name')));
  6234. }
  6235. nameBox[0].focus();
  6236. nameBox[0].select();
  6237. },
  6238. 'delete' : function() {
  6239. self.plugin.getSelectedAnchor().remove();
  6240. }
  6241. };
  6242. self.clickToolbar(name, self.plugin.anchor.edit);
  6243. });
  6244. /*******************************************************************************
  6245. * KindEditor - WYSIWYG HTML Editor for Internet
  6246. * Copyright (C) 2006-2011 kindsoft.net
  6247. *
  6248. * @author Roddy <luolonghao@gmail.com>
  6249. * @site http://www.kindsoft.net/
  6250. * @licence http://www.kindsoft.net/license.php
  6251. *******************************************************************************/
  6252. KindEditor.plugin('autoheight', function(K) {
  6253. var self = this;
  6254. if (!self.autoHeightMode) {
  6255. return;
  6256. }
  6257. var minHeight;
  6258. function hideScroll() {
  6259. var edit = self.edit;
  6260. var body = edit.doc.body;
  6261. edit.iframe[0].scroll = 'no';
  6262. body.style.overflowY = 'hidden';
  6263. }
  6264. function resetHeight() {
  6265. var edit = self.edit;
  6266. var body = edit.doc.body;
  6267. edit.iframe.height(minHeight);
  6268. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6269. }
  6270. function init() {
  6271. minHeight = K.removeUnit(self.height);
  6272. self.edit.afterChange(resetHeight);
  6273. hideScroll();
  6274. resetHeight();
  6275. }
  6276. if (self.isCreated) {
  6277. init();
  6278. } else {
  6279. self.afterCreate(init);
  6280. }
  6281. });
  6282. /*
  6283. * 如何实现真正的自动高度?
  6284. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6285. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6286. * 由此就实现了真正的自动高度
  6287. * 测试:chrome、firefox、IE9、IE8
  6288. * */
  6289. /*******************************************************************************
  6290. * KindEditor - WYSIWYG HTML Editor for Internet
  6291. * Copyright (C) 2006-2011 kindsoft.net
  6292. *
  6293. * @author Roddy <luolonghao@gmail.com>
  6294. * @site http://www.kindsoft.net/
  6295. * @licence http://www.kindsoft.net/license.php
  6296. *******************************************************************************/
  6297. // Baidu Maps: http://dev.baidu.com/wiki/map/index.php?title=%E9%A6%96%E9%A1%B5
  6298. KindEditor.plugin('baidumap', function(K) {
  6299. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6300. var mapWidth = K.undef(self.mapWidth, 558);
  6301. var mapHeight = K.undef(self.mapHeight, 360);
  6302. self.clickToolbar(name, function() {
  6303. var html = ['<div style="padding:10px 20px;">',
  6304. '<div class="ke-header">',
  6305. // left start
  6306. '<div class="ke-left">',
  6307. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6308. '<span class="ke-button-common ke-button-outer">',
  6309. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6310. '</span>',
  6311. '</div>',
  6312. // right start
  6313. '<div class="ke-right">',
  6314. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6315. '</div>',
  6316. '<div class="ke-clearfix"></div>',
  6317. '</div>',
  6318. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6319. '</div>'].join('');
  6320. var dialog = self.createDialog({
  6321. name : name,
  6322. width : mapWidth + 42,
  6323. title : self.lang(name),
  6324. body : html,
  6325. yesBtn : {
  6326. name : self.lang('yes'),
  6327. click : function(e) {
  6328. var map = win.map;
  6329. var centerObj = map.getCenter();
  6330. var center = centerObj.lng + ',' + centerObj.lat;
  6331. var zoom = map.getZoom();
  6332. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6333. '?center=' + encodeURIComponent(center),
  6334. '&zoom=' + encodeURIComponent(zoom),
  6335. '&width=' + mapWidth,
  6336. '&height=' + mapHeight,
  6337. '&markers=' + encodeURIComponent(center),
  6338. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6339. if (checkbox[0].checked) {
  6340. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6341. } else {
  6342. self.exec('insertimage', url);
  6343. }
  6344. self.hideDialog().focus();
  6345. }
  6346. },
  6347. beforeRemove : function() {
  6348. searchBtn.remove();
  6349. if (doc) {
  6350. doc.write('');
  6351. }
  6352. iframe.remove();
  6353. }
  6354. });
  6355. var div = dialog.div,
  6356. addressBox = K('[name="address"]', div),
  6357. searchBtn = K('[name="searchBtn"]', div),
  6358. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6359. win, doc;
  6360. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6361. function ready() {
  6362. win = iframe[0].contentWindow;
  6363. doc = K.iframeDoc(iframe);
  6364. }
  6365. iframe.bind('load', function() {
  6366. iframe.unbind('load');
  6367. if (K.IE) {
  6368. ready();
  6369. } else {
  6370. setTimeout(ready, 0);
  6371. }
  6372. });
  6373. K('.ke-map', div).replaceWith(iframe);
  6374. // search map
  6375. searchBtn.click(function() {
  6376. win.search(addressBox.val());
  6377. });
  6378. });
  6379. });
  6380. /*******************************************************************************
  6381. * KindEditor - WYSIWYG HTML Editor for Internet
  6382. * Copyright (C) 2006-2011 kindsoft.net
  6383. *
  6384. * @author Roddy <luolonghao@gmail.com>
  6385. * @site http://www.kindsoft.net/
  6386. * @licence http://www.kindsoft.net/license.php
  6387. *******************************************************************************/
  6388. KindEditor.plugin('clearhtml', function(K) {
  6389. var self = this, name = 'clearhtml';
  6390. self.clickToolbar(name, function() {
  6391. self.focus();
  6392. var html = self.html();
  6393. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6394. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6395. html = K.formatHtml(html, {
  6396. a : ['href', 'target'],
  6397. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6398. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6399. table : ['border'],
  6400. 'td,th' : ['rowspan', 'colspan'],
  6401. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6402. });
  6403. /* Knaan@2014-07-23 添加:清除格式时去除标签前的两个全角空格 */
  6404. html = html.replace(/(<[^>]*>)(&emsp;&emsp;)+/ig, function($0) {
  6405. return $0.replace(/&emsp;/g, '');
  6406. });
  6407. html = K.trim(html);
  6408. self.html(html);
  6409. self.cmd.selection(true);
  6410. self.addBookmark();
  6411. });
  6412. });
  6413. /*******************************************************************************
  6414. * KindEditor - WYSIWYG HTML Editor for Internet
  6415. * Copyright (C) 2006-2011 kindsoft.net
  6416. *
  6417. * @author Roddy <luolonghao@gmail.com>
  6418. * @site http://www.kindsoft.net/
  6419. * @licence http://www.kindsoft.net/license.php
  6420. *******************************************************************************/
  6421. // google code prettify: http://google-code-prettify.googlecode.com/
  6422. // http://google-code-prettify.googlecode.com/
  6423. KindEditor.plugin('code', function(K) {
  6424. var self = this, name = 'code';
  6425. self.clickToolbar(name, function() {
  6426. var lang = self.lang(name + '.'),
  6427. html = ['<div style="padding:10px 20px;">',
  6428. '<div class="ke-dialog-row">',
  6429. '<select class="ke-code-type">',
  6430. '<option value="js">JavaScript</option>',
  6431. '<option value="html">HTML</option>',
  6432. '<option value="css">CSS</option>',
  6433. '<option value="php">PHP</option>',
  6434. '<option value="pl">Perl</option>',
  6435. '<option value="py">Python</option>',
  6436. '<option value="rb">Ruby</option>',
  6437. '<option value="java">Java</option>',
  6438. '<option value="vb">ASP/VB</option>',
  6439. '<option value="cpp">C/C++</option>',
  6440. '<option value="cs">C#</option>',
  6441. '<option value="xml">XML</option>',
  6442. '<option value="bsh">Shell</option>',
  6443. '<option value="">Other</option>',
  6444. '</select>',
  6445. '</div>',
  6446. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6447. '</div>'].join(''),
  6448. dialog = self.createDialog({
  6449. name : name,
  6450. width : 450,
  6451. title : self.lang(name),
  6452. body : html,
  6453. yesBtn : {
  6454. name : self.lang('yes'),
  6455. click : function(e) {
  6456. var type = K('.ke-code-type', dialog.div).val(),
  6457. code = textarea.val(),
  6458. cls = type === '' ? '' : ' lang-' + type,
  6459. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6460. if (K.trim(code) === '') {
  6461. alert(lang.pleaseInput);
  6462. textarea[0].focus();
  6463. return;
  6464. }
  6465. self.insertHtml(html).hideDialog().focus();
  6466. }
  6467. }
  6468. }),
  6469. textarea = K('textarea', dialog.div);
  6470. textarea[0].focus();
  6471. });
  6472. });
  6473. /*******************************************************************************
  6474. * KindEditor - WYSIWYG HTML Editor for Internet
  6475. * Copyright (C) 2006-2011 kindsoft.net
  6476. *
  6477. * @author Roddy <luolonghao@gmail.com>
  6478. * @site http://www.kindsoft.net/
  6479. * @licence http://www.kindsoft.net/license.php
  6480. *******************************************************************************/
  6481. KindEditor.plugin('emoticons', function(K) {
  6482. var self = this, name = 'emoticons',
  6483. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6484. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6485. currentPageNum = 1;
  6486. self.clickToolbar(name, function() {
  6487. var rows = 5, cols = 9, total = 135, startNum = 0,
  6488. cells = rows * cols, pages = Math.ceil(total / cells),
  6489. colsHalf = Math.floor(cols / 2),
  6490. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6491. elements = [],
  6492. menu = self.createMenu({
  6493. name : name,
  6494. beforeRemove : function() {
  6495. removeEvent();
  6496. }
  6497. });
  6498. menu.div.append(wrapperDiv);
  6499. var previewDiv, previewImg;
  6500. if (allowPreview) {
  6501. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6502. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6503. wrapperDiv.append(previewDiv);
  6504. previewDiv.append(previewImg);
  6505. }
  6506. function bindCellEvent(cell, j, num) {
  6507. if (previewDiv) {
  6508. cell.mouseover(function() {
  6509. if (j > colsHalf) {
  6510. previewDiv.css('left', 0);
  6511. previewDiv.css('right', '');
  6512. } else {
  6513. previewDiv.css('left', '');
  6514. previewDiv.css('right', 0);
  6515. }
  6516. previewImg.attr('src', path + num + '.gif');
  6517. K(this).addClass('ke-on');
  6518. });
  6519. } else {
  6520. cell.mouseover(function() {
  6521. K(this).addClass('ke-on');
  6522. });
  6523. }
  6524. cell.mouseout(function() {
  6525. K(this).removeClass('ke-on');
  6526. });
  6527. cell.click(function(e) {
  6528. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6529. e.stop();
  6530. });
  6531. }
  6532. function createEmoticonsTable(pageNum, parentDiv) {
  6533. var table = document.createElement('table');
  6534. parentDiv.append(table);
  6535. if (previewDiv) {
  6536. K(table).mouseover(function() {
  6537. previewDiv.show('block');
  6538. });
  6539. K(table).mouseout(function() {
  6540. previewDiv.hide();
  6541. });
  6542. elements.push(K(table));
  6543. }
  6544. table.className = 'ke-table';
  6545. table.cellPadding = 0;
  6546. table.cellSpacing = 0;
  6547. table.border = 0;
  6548. var num = (pageNum - 1) * cells + startNum;
  6549. for (var i = 0; i < rows; i++) {
  6550. var row = table.insertRow(i);
  6551. for (var j = 0; j < cols; j++) {
  6552. var cell = K(row.insertCell(j));
  6553. cell.addClass('ke-cell');
  6554. bindCellEvent(cell, j, num);
  6555. var span = K('<span class="ke-img"></span>')
  6556. .css('background-position', '-' + (24 * num) + 'px 0px')
  6557. .css('background-image', 'url(' + path + 'static.gif)');
  6558. cell.append(span);
  6559. elements.push(cell);
  6560. num++;
  6561. }
  6562. }
  6563. return table;
  6564. }
  6565. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6566. function removeEvent() {
  6567. K.each(elements, function() {
  6568. this.unbind();
  6569. });
  6570. }
  6571. var pageDiv;
  6572. function bindPageEvent(el, pageNum) {
  6573. el.click(function(e) {
  6574. removeEvent();
  6575. table.parentNode.removeChild(table);
  6576. pageDiv.remove();
  6577. table = createEmoticonsTable(pageNum, wrapperDiv);
  6578. createPageTable(pageNum);
  6579. currentPageNum = pageNum;
  6580. e.stop();
  6581. });
  6582. }
  6583. function createPageTable(currentPageNum) {
  6584. pageDiv = K('<div class="ke-page"></div>');
  6585. wrapperDiv.append(pageDiv);
  6586. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6587. if (currentPageNum !== pageNum) {
  6588. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6589. bindPageEvent(a, pageNum);
  6590. pageDiv.append(a);
  6591. elements.push(a);
  6592. } else {
  6593. pageDiv.append(K('@[' + pageNum + ']'));
  6594. }
  6595. pageDiv.append(K('@&nbsp;'));
  6596. }
  6597. }
  6598. createPageTable(currentPageNum);
  6599. });
  6600. });
  6601. /*******************************************************************************
  6602. * KindEditor - WYSIWYG HTML Editor for Internet
  6603. * Copyright (C) 2006-2011 kindsoft.net
  6604. *
  6605. * @author Roddy <luolonghao@gmail.com>
  6606. * @site http://www.kindsoft.net/
  6607. * @licence http://www.kindsoft.net/license.php
  6608. *******************************************************************************/
  6609. KindEditor.plugin('filemanager', function(K) {
  6610. var self = this, name = 'filemanager',
  6611. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6612. imgPath = self.pluginsPath + name + '/images/',
  6613. lang = self.lang(name + '.');
  6614. function makeFileTitle(filename, filesize, datetime) {
  6615. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6616. }
  6617. function bindTitle(el, data) {
  6618. if (data.is_dir) {
  6619. el.attr('title', data.filename);
  6620. } else {
  6621. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6622. }
  6623. }
  6624. self.plugin.filemanagerDialog = function(options) {
  6625. var width = K.undef(options.width, 650),
  6626. height = K.undef(options.height, 510),
  6627. dirName = K.undef(options.dirName, ''),
  6628. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(), // "LIST" or "VIEW"
  6629. clickFn = options.clickFn;
  6630. var html = [
  6631. '<div style="padding:10px 20px;">',
  6632. // header start
  6633. '<div class="ke-plugin-filemanager-header">',
  6634. // left start
  6635. '<div class="ke-left">',
  6636. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6637. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6638. '</div>',
  6639. // right start
  6640. '<div class="ke-right">',
  6641. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6642. '<option value="VIEW">' + lang.viewImage + '</option>',
  6643. '<option value="LIST">' + lang.listImage + '</option>',
  6644. '</select> ',
  6645. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6646. '<option value="NAME">' + lang.fileName + '</option>',
  6647. '<option value="SIZE">' + lang.fileSize + '</option>',
  6648. '<option value="TYPE">' + lang.fileType + '</option>',
  6649. '</select>',
  6650. '</div>',
  6651. '<div class="ke-clearfix"></div>',
  6652. '</div>',
  6653. // body start
  6654. '<div class="ke-plugin-filemanager-body"></div>',
  6655. '</div>'
  6656. ].join('');
  6657. var dialog = self.createDialog({
  6658. name : name,
  6659. width : width,
  6660. height : height,
  6661. title : self.lang(name),
  6662. body : html
  6663. }),
  6664. div = dialog.div,
  6665. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6666. moveupImg = K('[name="moveupImg"]', div),
  6667. moveupLink = K('[name="moveupLink"]', div),
  6668. viewServerBtn = K('[name="viewServer"]', div),
  6669. viewTypeBox = K('[name="viewType"]', div),
  6670. orderTypeBox = K('[name="orderType"]', div);
  6671. function reloadPage(path, order, func) {
  6672. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6673. dialog.showLoading(self.lang('ajaxLoading'));
  6674. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6675. dialog.hideLoading();
  6676. func(data);
  6677. });
  6678. }
  6679. var elList = [];
  6680. function bindEvent(el, result, data, createFunc) {
  6681. //var fileUrl = K.formatUrl(result.current_url + data.filename, 'absolute'),
  6682. /*K'naan 修改图片url地址为相对路径(后台传回路径)*/
  6683. var fileUrl = result.current_url + data.filename,
  6684. dirPath = encodeURIComponent(result.current_dir_path + data.filename + '/');
  6685. if (data.is_dir) {
  6686. el.click(function(e) {
  6687. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6688. });
  6689. } else if (data.is_photo) {
  6690. el.click(function(e) {
  6691. clickFn.call(this, fileUrl, data.filename);
  6692. });
  6693. } else {
  6694. el.click(function(e) {
  6695. clickFn.call(this, fileUrl, data.filename);
  6696. });
  6697. }
  6698. elList.push(el);
  6699. }
  6700. function createCommon(result, createFunc) {
  6701. // remove events
  6702. K.each(elList, function() {
  6703. this.unbind();
  6704. });
  6705. moveupLink.unbind();
  6706. viewTypeBox.unbind();
  6707. orderTypeBox.unbind();
  6708. // add events
  6709. if (result.current_dir_path) {
  6710. moveupLink.click(function(e) {
  6711. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  6712. });
  6713. }
  6714. function changeFunc() {
  6715. if (viewTypeBox.val() == 'VIEW') {
  6716. reloadPage(result.current_dir_path, orderTypeBox.val(), createView);
  6717. } else {
  6718. reloadPage(result.current_dir_path, orderTypeBox.val(), createList);
  6719. }
  6720. }
  6721. viewTypeBox.change(changeFunc);
  6722. orderTypeBox.change(changeFunc);
  6723. bodyDiv.html('');
  6724. }
  6725. function createList(result) {
  6726. createCommon(result, createList);
  6727. var table = document.createElement('table');
  6728. table.className = 'ke-table';
  6729. table.cellPadding = 0;
  6730. table.cellSpacing = 0;
  6731. table.border = 0;
  6732. bodyDiv.append(table);
  6733. var fileList = result.file_list;
  6734. for (var i = 0, len = fileList.length; i < len; i++) {
  6735. var data = fileList[i], row = K(table.insertRow(i));
  6736. row.mouseover(function(e) {
  6737. K(this).addClass('ke-on');
  6738. })
  6739. .mouseout(function(e) {
  6740. K(this).removeClass('ke-on');
  6741. });
  6742. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  6743. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  6744. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  6745. if (!data.is_dir || data.has_file) {
  6746. row.css('cursor', 'pointer');
  6747. cell0.attr('title', data.filename);
  6748. bindEvent(cell0, result, data, createList);
  6749. } else {
  6750. cell0.attr('title', lang.emptyFolder);
  6751. }
  6752. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  6753. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  6754. }
  6755. }
  6756. function createView(result) {
  6757. createCommon(result, createView);
  6758. var fileList = result.file_list;
  6759. for (var i = 0, len = fileList.length; i < len; i++) {
  6760. var data = fileList[i],
  6761. div = K('<div class="ke-inline-block ke-item"></div>');
  6762. bodyDiv.append(div);
  6763. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  6764. .mouseover(function(e) {
  6765. K(this).addClass('ke-on');
  6766. })
  6767. .mouseout(function(e) {
  6768. K(this).removeClass('ke-on');
  6769. });
  6770. div.append(photoDiv);
  6771. var fileUrl = result.current_url + data.filename,
  6772. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  6773. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  6774. if (!data.is_dir || data.has_file) {
  6775. photoDiv.css('cursor', 'pointer');
  6776. bindTitle(photoDiv, data);
  6777. bindEvent(photoDiv, result, data, createView);
  6778. } else {
  6779. photoDiv.attr('title', lang.emptyFolder);
  6780. }
  6781. photoDiv.append(img);
  6782. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  6783. }
  6784. }
  6785. viewTypeBox.val(viewType);
  6786. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  6787. return dialog;
  6788. }
  6789. });
  6790. /*******************************************************************************
  6791. * KindEditor - WYSIWYG HTML Editor for Internet
  6792. * Copyright (C) 2006-2011 kindsoft.net
  6793. *
  6794. * @author Roddy <luolonghao@gmail.com>
  6795. * @site http://www.kindsoft.net/
  6796. * @licence http://www.kindsoft.net/license.php
  6797. *******************************************************************************/
  6798. KindEditor.plugin('flash', function(K) {
  6799. var self = this, name = 'flash', lang = self.lang(name + '.'),
  6800. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  6801. allowFileManager = K.undef(self.allowFileManager, false),
  6802. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  6803. extraParams = K.undef(self.extraFileUploadParams, {}),
  6804. filePostName = K.undef(self.filePostName, 'imgFile'),
  6805. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  6806. self.plugin.flash = {
  6807. edit : function() {
  6808. var html = [
  6809. '<div style="padding:20px;">',
  6810. //url
  6811. '<div class="ke-dialog-row">',
  6812. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  6813. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  6814. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  6815. '<span class="ke-button-common ke-button-outer">',
  6816. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  6817. '</span>',
  6818. '</div>',
  6819. //width
  6820. '<div class="ke-dialog-row">',
  6821. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  6822. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  6823. '</div>',
  6824. //height
  6825. '<div class="ke-dialog-row">',
  6826. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  6827. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  6828. '</div>',
  6829. '</div>'
  6830. ].join('');
  6831. var dialog = self.createDialog({
  6832. name : name,
  6833. width : 450,
  6834. title : self.lang(name),
  6835. body : html,
  6836. yesBtn : {
  6837. name : self.lang('yes'),
  6838. click : function(e) {
  6839. var url = K.trim(urlBox.val()),
  6840. width = widthBox.val(),
  6841. height = heightBox.val();
  6842. if (url == 'http://' || K.invalidUrl(url)) {
  6843. alert(self.lang('invalidUrl'));
  6844. urlBox[0].focus();
  6845. return;
  6846. }
  6847. if (!/^\d*$/.test(width)) {
  6848. alert(self.lang('invalidWidth'));
  6849. widthBox[0].focus();
  6850. return;
  6851. }
  6852. if (!/^\d*$/.test(height)) {
  6853. alert(self.lang('invalidHeight'));
  6854. heightBox[0].focus();
  6855. return;
  6856. }
  6857. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  6858. src : url,
  6859. type : K.mediaType('.swf'),
  6860. width : width,
  6861. height : height,
  6862. quality : 'high'
  6863. });
  6864. self.insertHtml(html).hideDialog().focus();
  6865. }
  6866. }
  6867. }),
  6868. div = dialog.div,
  6869. urlBox = K('[name="url"]', div),
  6870. viewServerBtn = K('[name="viewServer"]', div),
  6871. widthBox = K('[name="width"]', div),
  6872. heightBox = K('[name="height"]', div);
  6873. urlBox.val('http://');
  6874. if (allowFlashUpload) {
  6875. var uploadbutton = K.uploadbutton({
  6876. button : K('.ke-upload-button', div)[0],
  6877. fieldName : filePostName,
  6878. extraParams : extraParams,
  6879. url : K.addParam(uploadJson, 'dir=flash'),
  6880. afterUpload : function(data) {
  6881. dialog.hideLoading();
  6882. if (data.error === 0) {
  6883. var url = data.url;
  6884. if (formatUploadUrl) {
  6885. url = K.formatUrl(url, 'absolute');
  6886. }
  6887. urlBox.val(url);
  6888. if (self.afterUpload) {
  6889. self.afterUpload.call(self, url, data, name);
  6890. }
  6891. alert(self.lang('uploadSuccess'));
  6892. } else {
  6893. alert(data.message);
  6894. }
  6895. },
  6896. afterError : function(html) {
  6897. dialog.hideLoading();
  6898. self.errorDialog(html);
  6899. }
  6900. });
  6901. uploadbutton.fileBox.change(function(e) {
  6902. dialog.showLoading(self.lang('uploadLoading'));
  6903. uploadbutton.submit();
  6904. });
  6905. } else {
  6906. K('.ke-upload-button', div).hide();
  6907. }
  6908. if (allowFileManager) {
  6909. viewServerBtn.click(function(e) {
  6910. self.loadPlugin('filemanager', function() {
  6911. self.plugin.filemanagerDialog({
  6912. viewType : 'LIST',
  6913. dirName : 'flash',
  6914. clickFn : function(url, title) {
  6915. if (self.dialogs.length > 1) {
  6916. K('[name="url"]', div).val(url);
  6917. if (self.afterSelectFile) {
  6918. self.afterSelectFile.call(self, url);
  6919. }
  6920. self.hideDialog();
  6921. }
  6922. }
  6923. });
  6924. });
  6925. });
  6926. } else {
  6927. viewServerBtn.hide();
  6928. }
  6929. var img = self.plugin.getSelectedFlash();
  6930. if (img) {
  6931. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  6932. urlBox.val(attrs.src);
  6933. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  6934. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  6935. }
  6936. urlBox[0].focus();
  6937. urlBox[0].select();
  6938. },
  6939. 'delete' : function() {
  6940. self.plugin.getSelectedFlash().remove();
  6941. // [IE] 删除图片后立即点击图片按钮出错
  6942. self.addBookmark();
  6943. }
  6944. };
  6945. self.clickToolbar(name, self.plugin.flash.edit);
  6946. });
  6947. /*******************************************************************************
  6948. * KindEditor - WYSIWYG HTML Editor for Internet
  6949. * Copyright (C) 2006-2011 kindsoft.net
  6950. *
  6951. * @author Roddy <luolonghao@gmail.com>
  6952. * @site http://www.kindsoft.net/
  6953. * @licence http://www.kindsoft.net/license.php
  6954. *******************************************************************************/
  6955. KindEditor.plugin('image', function(K) {
  6956. var self = this, name = 'image',
  6957. allowImageUpload = K.undef(self.allowImageUpload, true),
  6958. allowImageRemote = K.undef(self.allowImageRemote, true),
  6959. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  6960. allowFileManager = K.undef(self.allowFileManager, false),
  6961. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  6962. imageTabIndex = K.undef(self.imageTabIndex, 0),
  6963. imgPath = self.pluginsPath + 'image/images/',
  6964. extraParams = K.undef(self.extraFileUploadParams, {}),
  6965. filePostName = K.undef(self.filePostName, 'imgFile'),
  6966. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  6967. lang = self.lang(name + '.');
  6968. self.plugin.imageDialog = function(options) {
  6969. var imageUrl = options.imageUrl,
  6970. imageWidth = K.undef(options.imageWidth, ''),
  6971. imageHeight = K.undef(options.imageHeight, ''),
  6972. imageTitle = K.undef(options.imageTitle, ''),
  6973. imageAlign = K.undef(options.imageAlign, ''),
  6974. showRemote = K.undef(options.showRemote, true),
  6975. showLocal = K.undef(options.showLocal, true),
  6976. tabIndex = K.undef(options.tabIndex, 0),
  6977. clickFn = options.clickFn;
  6978. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  6979. var hiddenElements = [];
  6980. for(var k in extraParams){
  6981. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  6982. }
  6983. var html = [
  6984. '<div style="padding:20px;">',
  6985. //tabs
  6986. '<div class="tabs"></div>',
  6987. //remote image - start
  6988. '<div class="tab1" style="display:none;">',
  6989. //url
  6990. '<div class="ke-dialog-row">',
  6991. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  6992. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  6993. '<span class="ke-button-common ke-button-outer">',
  6994. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  6995. '</span>',
  6996. '</div>',
  6997. //size
  6998. '<div class="ke-dialog-row">',
  6999. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  7000. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  7001. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  7002. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  7003. '</div>',
  7004. //align
  7005. '<div class="ke-dialog-row">',
  7006. '<label style="width:60px;">' + lang.align + '</label>',
  7007. '<input type="radio" name="align" class="ke-inline-block" value="" checked="checked" /> <img name="defaultImg" src="' + imgPath + 'align_top.gif" width="23" height="25" alt="" />',
  7008. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  7009. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7010. '</div>',
  7011. //title
  7012. '<div class="ke-dialog-row">',
  7013. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7014. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7015. '</div>',
  7016. '</div>',
  7017. //remote image - end
  7018. //local upload - start
  7019. '<div class="tab2" style="display:none;">',
  7020. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7021. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7022. //file
  7023. '<div class="ke-dialog-row">',
  7024. hiddenElements.join(''),
  7025. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7026. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7027. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7028. '</div>',
  7029. '</form>',
  7030. '</div>',
  7031. //local upload - end
  7032. '</div>'
  7033. ].join('');
  7034. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7035. dialogHeight = showLocal && showRemote ? 300 : 250;
  7036. var dialog = self.createDialog({
  7037. name : name,
  7038. width : dialogWidth,
  7039. height : dialogHeight,
  7040. title : self.lang(name),
  7041. body : html,
  7042. yesBtn : {
  7043. name : self.lang('yes'),
  7044. click : function(e) {
  7045. // Bugfix: http://code.google.com/p/kindeditor/issues/detail?id=319
  7046. if (dialog.isLoading) {
  7047. return;
  7048. }
  7049. // insert local image
  7050. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7051. if (uploadbutton.fileBox.val() == '') {
  7052. alert(self.lang('pleaseSelectFile'));
  7053. return;
  7054. }
  7055. dialog.showLoading(self.lang('uploadLoading'));
  7056. uploadbutton.submit();
  7057. localUrlBox.val('');
  7058. return;
  7059. }
  7060. // insert remote image
  7061. var url = K.trim(urlBox.val()),
  7062. width = widthBox.val(),
  7063. height = heightBox.val(),
  7064. title = titleBox.val(),
  7065. align = '';
  7066. alignBox.each(function() {
  7067. if (this.checked) {
  7068. align = this.value;
  7069. return false;
  7070. }
  7071. });
  7072. if (url == 'http://' || K.invalidUrl(url)) {
  7073. alert(self.lang('invalidUrl'));
  7074. urlBox[0].focus();
  7075. return;
  7076. }
  7077. if (!/^\d*$/.test(width)) {
  7078. alert(self.lang('invalidWidth'));
  7079. widthBox[0].focus();
  7080. return;
  7081. }
  7082. if (!/^\d*$/.test(height)) {
  7083. alert(self.lang('invalidHeight'));
  7084. heightBox[0].focus();
  7085. return;
  7086. }
  7087. clickFn.call(self, url, title, width, height, 0, align);
  7088. }
  7089. },
  7090. beforeRemove : function() {
  7091. viewServerBtn.unbind();
  7092. widthBox.unbind();
  7093. heightBox.unbind();
  7094. refreshBtn.unbind();
  7095. }
  7096. }),
  7097. div = dialog.div;
  7098. var urlBox = K('[name="url"]', div),
  7099. localUrlBox = K('[name="localUrl"]', div),
  7100. viewServerBtn = K('[name="viewServer"]', div),
  7101. widthBox = K('.tab1 [name="width"]', div),
  7102. heightBox = K('.tab1 [name="height"]', div),
  7103. refreshBtn = K('.ke-refresh-btn', div),
  7104. titleBox = K('.tab1 [name="title"]', div),
  7105. alignBox = K('.tab1 [name="align"]', div);
  7106. var tabs;
  7107. if (showRemote && showLocal) {
  7108. tabs = K.tabs({
  7109. src : K('.tabs', div),
  7110. afterSelect : function(i) {}
  7111. });
  7112. tabs.add({
  7113. title : lang.remoteImage,
  7114. panel : K('.tab1', div)
  7115. });
  7116. tabs.add({
  7117. title : lang.localImage,
  7118. panel : K('.tab2', div)
  7119. });
  7120. tabs.select(tabIndex);
  7121. } else if (showRemote) {
  7122. K('.tab1', div).show();
  7123. } else if (showLocal) {
  7124. K('.tab2', div).show();
  7125. }
  7126. var uploadbutton = K.uploadbutton({
  7127. button : K('.ke-upload-button', div)[0],
  7128. fieldName : filePostName,
  7129. form : K('.ke-form', div),
  7130. target : target,
  7131. width: 60,
  7132. afterUpload : function(data) {
  7133. dialog.hideLoading();
  7134. if (data.error === 0) {
  7135. var url = data.url;
  7136. if (formatUploadUrl) {
  7137. url = K.formatUrl(url, 'absolute');
  7138. }
  7139. if (self.afterUpload) {
  7140. self.afterUpload.call(self, url, data, name);
  7141. }
  7142. if (!fillDescAfterUploadImage) {
  7143. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7144. } else {
  7145. K(".ke-dialog-row #remoteUrl", div).val(url);
  7146. K(".ke-tabs-li", div)[0].click();
  7147. K(".ke-refresh-btn", div).click();
  7148. }
  7149. } else {
  7150. alert(data.message);
  7151. }
  7152. },
  7153. afterError : function(html) {
  7154. dialog.hideLoading();
  7155. self.errorDialog(html);
  7156. }
  7157. });
  7158. uploadbutton.fileBox.change(function(e) {
  7159. localUrlBox.val(uploadbutton.fileBox.val());
  7160. });
  7161. if (allowFileManager) {
  7162. viewServerBtn.click(function(e) {
  7163. self.loadPlugin('filemanager', function() {
  7164. self.plugin.filemanagerDialog({
  7165. viewType : 'VIEW',
  7166. dirName : 'image',
  7167. clickFn : function(url, title) {
  7168. if (self.dialogs.length > 1) {
  7169. K('[name="url"]', div).val(url);
  7170. if (self.afterSelectFile) {
  7171. self.afterSelectFile.call(self, url);
  7172. }
  7173. self.hideDialog();
  7174. }
  7175. }
  7176. });
  7177. });
  7178. });
  7179. } else {
  7180. viewServerBtn.hide();
  7181. }
  7182. var originalWidth = 0, originalHeight = 0;
  7183. function setSize(width, height) {
  7184. widthBox.val(width);
  7185. heightBox.val(height);
  7186. originalWidth = width;
  7187. originalHeight = height;
  7188. }
  7189. refreshBtn.click(function(e) {
  7190. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7191. position : 'absolute',
  7192. visibility : 'hidden',
  7193. top : 0,
  7194. left : '-1000px'
  7195. });
  7196. tempImg.bind('load', function() {
  7197. setSize(tempImg.width(), tempImg.height());
  7198. tempImg.remove();
  7199. });
  7200. K(document.body).append(tempImg);
  7201. });
  7202. widthBox.change(function(e) {
  7203. if (originalWidth > 0) {
  7204. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7205. }
  7206. });
  7207. heightBox.change(function(e) {
  7208. if (originalHeight > 0) {
  7209. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7210. }
  7211. });
  7212. urlBox.val(options.imageUrl);
  7213. setSize(options.imageWidth, options.imageHeight);
  7214. titleBox.val(options.imageTitle);
  7215. alignBox.each(function() {
  7216. if (this.value === options.imageAlign) {
  7217. this.checked = true;
  7218. return false;
  7219. }
  7220. });
  7221. if (showRemote && tabIndex === 0) {
  7222. urlBox[0].focus();
  7223. urlBox[0].select();
  7224. }
  7225. return dialog;
  7226. };
  7227. self.plugin.image = {
  7228. edit : function() {
  7229. var img = self.plugin.getSelectedImage();
  7230. self.plugin.imageDialog({
  7231. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7232. imageWidth : img ? img.width() : '',
  7233. imageHeight : img ? img.height() : '',
  7234. imageTitle : img ? img.attr('title') : '',
  7235. imageAlign : img ? img.attr('align') : '',
  7236. showRemote : allowImageRemote,
  7237. showLocal : allowImageUpload,
  7238. tabIndex: img ? 0 : imageTabIndex,
  7239. clickFn : function(url, title, width, height, border, align) {
  7240. if (img) {
  7241. img.attr('src', url);
  7242. img.attr('data-ke-src', url);
  7243. img.attr('width', width);
  7244. img.attr('height', height);
  7245. img.attr('title', title);
  7246. img.attr('align', align);
  7247. img.attr('alt', title);
  7248. } else {
  7249. self.exec('insertimage', url, title, width, height, border, align);
  7250. }
  7251. // Bugfix: [Firefox] 上传图片后,总是出现正在加载的样式,需要延迟执行hideDialog
  7252. setTimeout(function() {
  7253. self.hideDialog().focus();
  7254. }, 0);
  7255. //K'naan@2014-03-03 20:17 增加自定义函数(用于上传或选择图片并插入成功后--取得该图片的url)
  7256. if (self.X_afterSelect) {
  7257. self.X_afterSelect.call(self, url);
  7258. }
  7259. }
  7260. });
  7261. },
  7262. 'delete' : function() {
  7263. var target = self.plugin.getSelectedImage();
  7264. if (target.parent().name == 'a') {
  7265. target = target.parent();
  7266. }
  7267. target.remove();
  7268. // [IE] 删除图片后立即点击图片按钮出错
  7269. self.addBookmark();
  7270. }
  7271. };
  7272. self.clickToolbar(name, self.plugin.image.edit);
  7273. });
  7274. /*******************************************************************************
  7275. * KindEditor - WYSIWYG HTML Editor for Internet
  7276. * Copyright (C) 2006-2011 kindsoft.net
  7277. *
  7278. * @author Roddy <luolonghao@gmail.com>
  7279. * @site http://www.kindsoft.net/
  7280. * @licence http://www.kindsoft.net/license.php
  7281. *******************************************************************************/
  7282. KindEditor.plugin('insertfile', function(K) {
  7283. var self = this, name = 'insertfile',
  7284. allowFileUpload = K.undef(self.allowFileUpload, true),
  7285. allowFileManager = K.undef(self.allowFileManager, false),
  7286. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7287. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7288. extraParams = K.undef(self.extraFileUploadParams, {}),
  7289. filePostName = K.undef(self.filePostName, 'imgFile'),
  7290. lang = self.lang(name + '.');
  7291. self.plugin.fileDialog = function(options) {
  7292. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7293. fileTitle = K.undef(options.fileTitle, ''),
  7294. clickFn = options.clickFn;
  7295. var html = [
  7296. '<div style="padding:20px;">',
  7297. '<div class="ke-dialog-row">',
  7298. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7299. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7300. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7301. '<span class="ke-button-common ke-button-outer">',
  7302. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7303. '</span>',
  7304. '</div>',
  7305. //title
  7306. '<div class="ke-dialog-row">',
  7307. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7308. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7309. '</div>',
  7310. //form end
  7311. '</form>',
  7312. '</div>'
  7313. ].join('');
  7314. var dialog = self.createDialog({
  7315. name : name,
  7316. width : 450,
  7317. title : self.lang(name),
  7318. body : html,
  7319. yesBtn : {
  7320. name : self.lang('yes'),
  7321. click : function(e) {
  7322. var url = K.trim(urlBox.val()),
  7323. title = titleBox.val();
  7324. if (url == 'http://' || K.invalidUrl(url)) {
  7325. alert(self.lang('invalidUrl'));
  7326. urlBox[0].focus();
  7327. return;
  7328. }
  7329. if (K.trim(title) === '') {
  7330. title = url;
  7331. }
  7332. clickFn.call(self, url, title);
  7333. }
  7334. }
  7335. }),
  7336. div = dialog.div;
  7337. var urlBox = K('[name="url"]', div),
  7338. viewServerBtn = K('[name="viewServer"]', div),
  7339. titleBox = K('[name="title"]', div);
  7340. if (allowFileUpload) {
  7341. var uploadbutton = K.uploadbutton({
  7342. button : K('.ke-upload-button', div)[0],
  7343. fieldName : filePostName,
  7344. url : K.addParam(uploadJson, 'dir=file'),
  7345. extraParams : extraParams,
  7346. afterUpload : function(data) {
  7347. dialog.hideLoading();
  7348. if (data.error === 0) {
  7349. var url = data.url;
  7350. if (formatUploadUrl) {
  7351. url = K.formatUrl(url, 'absolute');
  7352. }
  7353. urlBox.val(url);
  7354. if (data.origin_name) titleBox.val(data.origin_name);
  7355. if (self.afterUpload) {
  7356. self.afterUpload.call(self, url, data, name);
  7357. }
  7358. alert(self.lang('uploadSuccess'));
  7359. } else {
  7360. alert(data.message);
  7361. }
  7362. },
  7363. afterError : function(html) {
  7364. dialog.hideLoading();
  7365. self.errorDialog(html);
  7366. }
  7367. });
  7368. uploadbutton.fileBox.change(function(e) {
  7369. dialog.showLoading(self.lang('uploadLoading'));
  7370. uploadbutton.submit();
  7371. });
  7372. } else {
  7373. K('.ke-upload-button', div).hide();
  7374. }
  7375. if (allowFileManager) {
  7376. viewServerBtn.click(function(e) {
  7377. self.loadPlugin('filemanager', function() {
  7378. self.plugin.filemanagerDialog({
  7379. viewType : 'LIST',
  7380. dirName : 'file',
  7381. clickFn : function(url, title) {
  7382. if (self.dialogs.length > 1) {
  7383. K('[name="url"]', div).val(url);
  7384. if (self.afterSelectFile) {
  7385. self.afterSelectFile.call(self, url);
  7386. }
  7387. self.hideDialog();
  7388. }
  7389. }
  7390. });
  7391. });
  7392. });
  7393. } else {
  7394. viewServerBtn.hide();
  7395. }
  7396. urlBox.val(fileUrl);
  7397. titleBox.val(fileTitle);
  7398. urlBox[0].focus();
  7399. urlBox[0].select();
  7400. };
  7401. self.clickToolbar(name, function() {
  7402. self.plugin.fileDialog({
  7403. clickFn : function(url, title) {
  7404. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7405. self.insertHtml(html).hideDialog().focus();
  7406. }
  7407. });
  7408. });
  7409. });
  7410. /*******************************************************************************
  7411. * KindEditor - WYSIWYG HTML Editor for Internet
  7412. * Copyright (C) 2006-2011 kindsoft.net
  7413. *
  7414. * @author Roddy <luolonghao@gmail.com>
  7415. * @site http://www.kindsoft.net/
  7416. * @licence http://www.kindsoft.net/license.php
  7417. *******************************************************************************/
  7418. KindEditor.plugin('lineheight', function(K) {
  7419. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7420. self.clickToolbar(name, function() {
  7421. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7422. if (commonNode) {
  7423. curVal = commonNode.css('line-height');
  7424. }
  7425. var menu = self.createMenu({
  7426. name : name,
  7427. width : 150
  7428. });
  7429. K.each(lang.lineHeight, function(i, row) {
  7430. K.each(row, function(key, val) {
  7431. menu.addItem({
  7432. title : val,
  7433. checked : curVal === key,
  7434. click : function() {
  7435. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7436. span : '.line-height=' + key
  7437. });
  7438. self.updateState();
  7439. self.addBookmark();
  7440. self.hideMenu();
  7441. }
  7442. });
  7443. });
  7444. });
  7445. });
  7446. });
  7447. /*******************************************************************************
  7448. * KindEditor - WYSIWYG HTML Editor for Internet
  7449. * Copyright (C) 2006-2011 kindsoft.net
  7450. *
  7451. * @author Roddy <luolonghao@gmail.com>
  7452. * @site http://www.kindsoft.net/
  7453. * @licence http://www.kindsoft.net/license.php
  7454. *******************************************************************************/
  7455. KindEditor.plugin('link', function(K) {
  7456. var self = this, name = 'link';
  7457. self.plugin.link = {
  7458. edit : function() {
  7459. var lang = self.lang(name + '.'),
  7460. html = '<div style="padding:20px;">' +
  7461. //url
  7462. '<div class="ke-dialog-row">' +
  7463. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7464. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7465. //type
  7466. '<div class="ke-dialog-row"">' +
  7467. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7468. '<select id="keType" name="type"></select>' +
  7469. '</div>' +
  7470. '</div>',
  7471. dialog = self.createDialog({
  7472. name : name,
  7473. width : 450,
  7474. title : self.lang(name),
  7475. body : html,
  7476. yesBtn : {
  7477. name : self.lang('yes'),
  7478. click : function(e) {
  7479. var url = K.trim(urlBox.val());
  7480. if (url == 'http://' || K.invalidUrl(url)) {
  7481. alert(self.lang('invalidUrl'));
  7482. urlBox[0].focus();
  7483. return;
  7484. }
  7485. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7486. }
  7487. }
  7488. }),
  7489. div = dialog.div,
  7490. urlBox = K('input[name="url"]', div),
  7491. typeBox = K('select[name="type"]', div);
  7492. urlBox.val('http://');
  7493. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7494. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7495. self.cmd.selection();
  7496. var a = self.plugin.getSelectedLink();
  7497. if (a) {
  7498. self.cmd.range.selectNode(a[0]);
  7499. self.cmd.select();
  7500. urlBox.val(a.attr('data-ke-src'));
  7501. typeBox.val(a.attr('target'));
  7502. }
  7503. urlBox[0].focus();
  7504. urlBox[0].select();
  7505. },
  7506. 'delete' : function() {
  7507. self.exec('unlink', null);
  7508. }
  7509. };
  7510. self.clickToolbar(name, self.plugin.link.edit);
  7511. });
  7512. /*******************************************************************************
  7513. * KindEditor - WYSIWYG HTML Editor for Internet
  7514. * Copyright (C) 2006-2011 kindsoft.net
  7515. *
  7516. * @author Roddy <luolonghao@gmail.com>
  7517. * @site http://www.kindsoft.net/
  7518. * @licence http://www.kindsoft.net/license.php
  7519. *******************************************************************************/
  7520. // Google Maps: http://code.google.com/apis/maps/index.html
  7521. KindEditor.plugin('map', function(K) {
  7522. var self = this, name = 'map', lang = self.lang(name + '.');
  7523. self.clickToolbar(name, function() {
  7524. var html = ['<div style="padding:10px 20px;">',
  7525. '<div class="ke-dialog-row">',
  7526. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  7527. '<span class="ke-button-common ke-button-outer">',
  7528. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  7529. '</span>',
  7530. '</div>',
  7531. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  7532. '</div>'].join('');
  7533. var dialog = self.createDialog({
  7534. name : name,
  7535. width : 600,
  7536. title : self.lang(name),
  7537. body : html,
  7538. yesBtn : {
  7539. name : self.lang('yes'),
  7540. click : function(e) {
  7541. var geocoder = win.geocoder,
  7542. map = win.map,
  7543. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  7544. zoom = map.getZoom(),
  7545. maptype = map.getMapTypeId(),
  7546. url = 'http://maps.googleapis.com/maps/api/staticmap';
  7547. url += '?center=' + encodeURIComponent(center);
  7548. url += '&zoom=' + encodeURIComponent(zoom);
  7549. url += '&size=558x360';
  7550. url += '&maptype=' + encodeURIComponent(maptype);
  7551. url += '&markers=' + encodeURIComponent(center);
  7552. url += '&language=' + self.langType;
  7553. url += '&sensor=false';
  7554. self.exec('insertimage', url).hideDialog().focus();
  7555. }
  7556. },
  7557. beforeRemove : function() {
  7558. searchBtn.remove();
  7559. if (doc) {
  7560. doc.write('');
  7561. }
  7562. iframe.remove();
  7563. }
  7564. });
  7565. var div = dialog.div,
  7566. addressBox = K('[name="address"]', div),
  7567. searchBtn = K('[name="searchBtn"]', div),
  7568. win, doc;
  7569. var iframeHtml = ['<!doctype html><html><head>',
  7570. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  7571. '<style>',
  7572. ' html { height: 100% }',
  7573. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  7574. ' #map_canvas { height: 100% }',
  7575. '</style>',
  7576. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  7577. '<script>',
  7578. 'var map, geocoder;',
  7579. 'function initialize() {',
  7580. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  7581. ' var options = {',
  7582. ' zoom: 11,',
  7583. ' center: latlng,',
  7584. ' disableDefaultUI: true,',
  7585. ' panControl: true,',
  7586. ' zoomControl: true,',
  7587. ' mapTypeControl: true,',
  7588. ' scaleControl: true,',
  7589. ' streetViewControl: false,',
  7590. ' overviewMapControl: true,',
  7591. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  7592. ' };',
  7593. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  7594. ' geocoder = new google.maps.Geocoder();',
  7595. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  7596. ' if (status == google.maps.GeocoderStatus.OK) {',
  7597. ' if (results[3]) {',
  7598. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  7599. ' }',
  7600. ' }',
  7601. ' });',
  7602. '}',
  7603. 'function search(address) {',
  7604. ' if (!map) return;',
  7605. ' geocoder.geocode({address : address}, function(results, status) {',
  7606. ' if (status == google.maps.GeocoderStatus.OK) {',
  7607. ' map.setZoom(11);',
  7608. ' map.setCenter(results[0].geometry.location);',
  7609. ' var marker = new google.maps.Marker({',
  7610. ' map: map,',
  7611. ' position: results[0].geometry.location',
  7612. ' });',
  7613. ' } else {',
  7614. ' alert("Invalid address: " + address);',
  7615. ' }',
  7616. ' });',
  7617. '}',
  7618. '</script>',
  7619. '</head>',
  7620. '<body onload="initialize();">',
  7621. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  7622. '</body></html>'].join('\n');
  7623. // TODO:用doc.write(iframeHtml)方式加载时,在IE6上第一次加载报错,暂时使用src方式
  7624. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  7625. function ready() {
  7626. win = iframe[0].contentWindow;
  7627. doc = K.iframeDoc(iframe);
  7628. //doc.open();
  7629. //doc.write(iframeHtml);
  7630. //doc.close();
  7631. }
  7632. iframe.bind('load', function() {
  7633. iframe.unbind('load');
  7634. if (K.IE) {
  7635. ready();
  7636. } else {
  7637. setTimeout(ready, 0);
  7638. }
  7639. });
  7640. K('.ke-map', div).replaceWith(iframe);
  7641. // search map
  7642. searchBtn.click(function() {
  7643. win.search(addressBox.val());
  7644. });
  7645. });
  7646. });
  7647. /*******************************************************************************
  7648. * KindEditor - WYSIWYG HTML Editor for Internet
  7649. * Copyright (C) 2006-2011 kindsoft.net
  7650. *
  7651. * @author Roddy <luolonghao@gmail.com>
  7652. * @site http://www.kindsoft.net/
  7653. * @licence http://www.kindsoft.net/license.php
  7654. *******************************************************************************/
  7655. KindEditor.plugin('media', function(K) {
  7656. var self = this, name = 'media', lang = self.lang(name + '.'),
  7657. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7658. allowFileManager = K.undef(self.allowFileManager, false),
  7659. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7660. extraParams = K.undef(self.extraFileUploadParams, {}),
  7661. filePostName = K.undef(self.filePostName, 'imgFile'),
  7662. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7663. self.plugin.media = {
  7664. edit : function() {
  7665. var html = [
  7666. '<div style="padding:20px;">',
  7667. //url
  7668. '<div class="ke-dialog-row">',
  7669. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7670. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7671. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7672. '<span class="ke-button-common ke-button-outer">',
  7673. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7674. '</span>',
  7675. '</div>',
  7676. //width
  7677. '<div class="ke-dialog-row">',
  7678. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7679. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" />',
  7680. '</div>',
  7681. //height
  7682. '<div class="ke-dialog-row">',
  7683. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7684. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" />',
  7685. '</div>',
  7686. //autostart
  7687. '<div class="ke-dialog-row">',
  7688. '<label for="keAutostart">' + lang.autostart + '</label>',
  7689. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7690. '</div>',
  7691. '</div>'
  7692. ].join('');
  7693. var dialog = self.createDialog({
  7694. name : name,
  7695. width : 450,
  7696. height : 230,
  7697. title : self.lang(name),
  7698. body : html,
  7699. yesBtn : {
  7700. name : self.lang('yes'),
  7701. click : function(e) {
  7702. var url = K.trim(urlBox.val()),
  7703. width = widthBox.val(),
  7704. height = heightBox.val();
  7705. if (url == 'http://' || K.invalidUrl(url)) {
  7706. alert(self.lang('invalidUrl'));
  7707. urlBox[0].focus();
  7708. return;
  7709. }
  7710. if (!/^\d*$/.test(width)) {
  7711. alert(self.lang('invalidWidth'));
  7712. widthBox[0].focus();
  7713. return;
  7714. }
  7715. if (!/^\d*$/.test(height)) {
  7716. alert(self.lang('invalidHeight'));
  7717. heightBox[0].focus();
  7718. return;
  7719. }
  7720. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7721. src : url,
  7722. type : K.mediaType(url),
  7723. width : width,
  7724. height : height,
  7725. autostart : autostartBox[0].checked ? 'true' : 'false',
  7726. loop : 'true'
  7727. });
  7728. self.insertHtml(html).hideDialog().focus();
  7729. }
  7730. }
  7731. }),
  7732. div = dialog.div,
  7733. urlBox = K('[name="url"]', div),
  7734. viewServerBtn = K('[name="viewServer"]', div),
  7735. widthBox = K('[name="width"]', div),
  7736. heightBox = K('[name="height"]', div),
  7737. autostartBox = K('[name="autostart"]', div);
  7738. urlBox.val('http://');
  7739. if (allowMediaUpload) {
  7740. var uploadbutton = K.uploadbutton({
  7741. button : K('.ke-upload-button', div)[0],
  7742. fieldName : filePostName,
  7743. extraParams : extraParams,
  7744. url : K.addParam(uploadJson, 'dir=media'),
  7745. afterUpload : function(data) {
  7746. dialog.hideLoading();
  7747. if (data.error === 0) {
  7748. var url = data.url;
  7749. if (formatUploadUrl) {
  7750. url = K.formatUrl(url, 'absolute');
  7751. }
  7752. urlBox.val(url);
  7753. if (self.afterUpload) {
  7754. self.afterUpload.call(self, url, data, name);
  7755. }
  7756. alert(self.lang('uploadSuccess'));
  7757. } else {
  7758. alert(data.message);
  7759. }
  7760. },
  7761. afterError : function(html) {
  7762. dialog.hideLoading();
  7763. self.errorDialog(html);
  7764. }
  7765. });
  7766. uploadbutton.fileBox.change(function(e) {
  7767. dialog.showLoading(self.lang('uploadLoading'));
  7768. uploadbutton.submit();
  7769. });
  7770. } else {
  7771. K('.ke-upload-button', div).hide();
  7772. }
  7773. if (allowFileManager) {
  7774. viewServerBtn.click(function(e) {
  7775. self.loadPlugin('filemanager', function() {
  7776. self.plugin.filemanagerDialog({
  7777. viewType : 'LIST',
  7778. dirName : 'media',
  7779. clickFn : function(url, title) {
  7780. if (self.dialogs.length > 1) {
  7781. K('[name="url"]', div).val(url);
  7782. if (self.afterSelectFile) {
  7783. self.afterSelectFile.call(self, url);
  7784. }
  7785. self.hideDialog();
  7786. }
  7787. }
  7788. });
  7789. });
  7790. });
  7791. } else {
  7792. viewServerBtn.hide();
  7793. }
  7794. var img = self.plugin.getSelectedMedia();
  7795. if (img) {
  7796. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7797. urlBox.val(attrs.src);
  7798. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7799. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7800. autostartBox[0].checked = (attrs.autostart === 'true');
  7801. }
  7802. urlBox[0].focus();
  7803. urlBox[0].select();
  7804. },
  7805. 'delete' : function() {
  7806. self.plugin.getSelectedMedia().remove();
  7807. // [IE] 删除图片后立即点击图片按钮出错
  7808. self.addBookmark();
  7809. }
  7810. };
  7811. self.clickToolbar(name, self.plugin.media.edit);
  7812. });
  7813. /*******************************************************************************
  7814. * KindEditor - WYSIWYG HTML Editor for Internet
  7815. * Copyright (C) 2006-2011 kindsoft.net
  7816. *
  7817. * @author Roddy <luolonghao@gmail.com>
  7818. * @site http://www.kindsoft.net/
  7819. * @licence http://www.kindsoft.net/license.php
  7820. *******************************************************************************/
  7821. (function(K) {
  7822. function KSWFUpload(options) {
  7823. this.init(options);
  7824. }
  7825. K.extend(KSWFUpload, {
  7826. init : function(options) {
  7827. var self = this;
  7828. options.afterError = options.afterError || function(str) {
  7829. alert(str);
  7830. };
  7831. self.options = options;
  7832. self.progressbars = {};
  7833. // template
  7834. self.div = K(options.container).html([
  7835. '<div class="ke-swfupload">',
  7836. '<div class="ke-swfupload-top">',
  7837. '<div class="ke-inline-block ke-swfupload-button">',
  7838. '<input type="button" value="Browse" />',
  7839. '</div>',
  7840. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  7841. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  7842. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  7843. '</span>',
  7844. '</div>',
  7845. '<div class="ke-swfupload-body"></div>',
  7846. '</div>'
  7847. ].join(''));
  7848. self.bodyDiv = K('.ke-swfupload-body', self.div);
  7849. function showError(itemDiv, msg) {
  7850. K('.ke-status > div', itemDiv).hide();
  7851. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  7852. }
  7853. var settings = {
  7854. debug : false,
  7855. upload_url : options.uploadUrl,
  7856. flash_url : options.flashUrl,
  7857. file_post_name : options.filePostName,
  7858. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  7859. button_image_url: options.buttonImageUrl,
  7860. button_width: options.buttonWidth,
  7861. button_height: options.buttonHeight,
  7862. button_cursor : SWFUpload.CURSOR.HAND,
  7863. file_types : options.fileTypes,
  7864. file_types_description : options.fileTypesDesc,
  7865. file_upload_limit : options.fileUploadLimit,
  7866. file_size_limit : options.fileSizeLimit,
  7867. post_params : options.postParams,
  7868. file_queued_handler : function(file) {
  7869. file.url = self.options.fileIconUrl;
  7870. self.appendFile(file);
  7871. },
  7872. file_queue_error_handler : function(file, errorCode, message) {
  7873. var errorName = '';
  7874. switch (errorCode) {
  7875. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  7876. errorName = options.queueLimitExceeded;
  7877. break;
  7878. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  7879. errorName = options.fileExceedsSizeLimit;
  7880. break;
  7881. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  7882. errorName = options.zeroByteFile;
  7883. break;
  7884. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  7885. errorName = options.invalidFiletype;
  7886. break;
  7887. default:
  7888. errorName = options.unknownError;
  7889. break;
  7890. }
  7891. K.DEBUG && alert(errorName);
  7892. },
  7893. upload_start_handler : function(file) {
  7894. var self = this;
  7895. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  7896. K('.ke-status > div', itemDiv).hide();
  7897. K('.ke-progressbar', itemDiv).show();
  7898. },
  7899. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  7900. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  7901. var progressbar = self.progressbars[file.id];
  7902. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  7903. progressbar.percent.html(percent + '%');
  7904. },
  7905. upload_error_handler : function(file, errorCode, message) {
  7906. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  7907. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7908. showError(itemDiv, self.options.errorMessage);
  7909. }
  7910. },
  7911. upload_success_handler : function(file, serverData) {
  7912. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7913. var data = {};
  7914. try {
  7915. data = K.json(serverData);
  7916. } catch (e) {
  7917. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  7918. }
  7919. if (data.error !== 0) {
  7920. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  7921. return;
  7922. }
  7923. file.url = data.url;
  7924. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  7925. K('.ke-status > div', itemDiv).hide();
  7926. }
  7927. };
  7928. self.swfu = new SWFUpload(settings);
  7929. K('.ke-swfupload-startupload input', self.div).click(function() {
  7930. self.swfu.startUpload();
  7931. });
  7932. },
  7933. getUrlList : function() {
  7934. var list = [];
  7935. K('.ke-img', self.bodyDiv).each(function() {
  7936. var img = K(this);
  7937. var status = img.attr('data-status');
  7938. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  7939. list.push(img.data('data'));
  7940. }
  7941. });
  7942. return list;
  7943. },
  7944. removeFile : function(fileId) {
  7945. var self = this;
  7946. self.swfu.cancelUpload(fileId);
  7947. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  7948. K('.ke-photo', itemDiv).unbind();
  7949. K('.ke-delete', itemDiv).unbind();
  7950. itemDiv.remove();
  7951. },
  7952. removeFiles : function() {
  7953. var self = this;
  7954. K('.ke-item', self.bodyDiv).each(function() {
  7955. self.removeFile(K(this).attr('data-id'));
  7956. });
  7957. },
  7958. appendFile : function(file) {
  7959. var self = this;
  7960. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  7961. self.bodyDiv.append(itemDiv);
  7962. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7963. .mouseover(function(e) {
  7964. K(this).addClass('ke-on');
  7965. })
  7966. .mouseout(function(e) {
  7967. K(this).removeClass('ke-on');
  7968. });
  7969. itemDiv.append(photoDiv);
  7970. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  7971. photoDiv.append(img);
  7972. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  7973. self.removeFile(file.id);
  7974. });
  7975. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  7976. // progressbar
  7977. K(['<div class="ke-progressbar">',
  7978. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  7979. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  7980. // message
  7981. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  7982. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  7983. self.progressbars[file.id] = {
  7984. bar : K('.ke-progressbar-bar-inner', photoDiv),
  7985. percent : K('.ke-progressbar-percent', photoDiv)
  7986. };
  7987. },
  7988. remove : function() {
  7989. this.removeFiles();
  7990. this.swfu.destroy();
  7991. this.div.html('');
  7992. }
  7993. });
  7994. K.swfupload = function(element, options) {
  7995. return new KSWFUpload(element, options);
  7996. };
  7997. })(KindEditor);
  7998. KindEditor.plugin('multiimage', function(K) {
  7999. var self = this, name = 'multiimage',
  8000. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  8001. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  8002. imgPath = self.pluginsPath + 'multiimage/images/',
  8003. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  8004. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  8005. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  8006. filePostName = K.undef(self.filePostName, 'imgFile'),
  8007. lang = self.lang(name + '.');
  8008. self.plugin.multiImageDialog = function(options) {
  8009. var clickFn = options.clickFn,
  8010. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  8011. var html = [
  8012. '<div style="padding:20px;">',
  8013. '<div class="swfupload">',
  8014. '</div>',
  8015. '</div>'
  8016. ].join('');
  8017. var dialog = self.createDialog({
  8018. name : name,
  8019. width : 650,
  8020. height : 510,
  8021. title : self.lang(name),
  8022. body : html,
  8023. previewBtn : {
  8024. name : lang.insertAll,
  8025. click : function(e) {
  8026. clickFn.call(self, swfupload.getUrlList());
  8027. }
  8028. },
  8029. yesBtn : {
  8030. name : lang.clearAll,
  8031. click : function(e) {
  8032. swfupload.removeFiles();
  8033. }
  8034. },
  8035. beforeRemove : function() {
  8036. // IE9 bugfix: https://github.com/kindsoft/kindeditor/issues/72
  8037. if (!K.IE || K.V <= 8) {
  8038. swfupload.remove();
  8039. }
  8040. }
  8041. }),
  8042. div = dialog.div;
  8043. var swfupload = K.swfupload({
  8044. container : K('.swfupload', div),
  8045. buttonImageUrl : imgPath + (self.langType == 'zh_CN' ? 'select-files-zh_CN.png' : 'select-files-en.png'),
  8046. buttonWidth : self.langType == 'zh_CN' ? 72 : 88,
  8047. buttonHeight : 23,
  8048. fileIconUrl : imgPath + 'image.png',
  8049. uploadDesc : uploadDesc,
  8050. startButtonValue : lang.startUpload,
  8051. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  8052. flashUrl : imgPath + 'swfupload.swf',
  8053. filePostName : filePostName,
  8054. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8055. fileTypesDesc : 'Image Files',
  8056. fileUploadLimit : imageUploadLimit,
  8057. fileSizeLimit : imageSizeLimit,
  8058. postParams : K.undef(self.extraFileUploadParams, {}),
  8059. queueLimitExceeded : lang.queueLimitExceeded,
  8060. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  8061. zeroByteFile : lang.zeroByteFile,
  8062. invalidFiletype : lang.invalidFiletype,
  8063. unknownError : lang.unknownError,
  8064. pendingMessage : lang.pending,
  8065. errorMessage : lang.uploadError,
  8066. afterError : function(html) {
  8067. self.errorDialog(html);
  8068. }
  8069. });
  8070. return dialog;
  8071. };
  8072. self.clickToolbar(name, function() {
  8073. self.plugin.multiImageDialog({
  8074. clickFn : function (urlList) {
  8075. if (urlList.length === 0) {
  8076. return;
  8077. }
  8078. K.each(urlList, function(i, data) {
  8079. if (self.afterUpload) {
  8080. self.afterUpload.call(self, data.url, data, 'multiimage');
  8081. }
  8082. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8083. });
  8084. // Bugfix: [Firefox] 上传图片后,总是出现正在加载的样式,需要延迟执行hideDialog
  8085. setTimeout(function() {
  8086. self.hideDialog().focus();
  8087. }, 0);
  8088. }
  8089. });
  8090. });
  8091. });
  8092. (function() {
  8093. /*
  8094. Queue Plug-in
  8095. Features:
  8096. *Adds a cancelQueue() method for cancelling the entire queue.
  8097. *All queued files are uploaded when startUpload() is called.
  8098. *If false is returned from uploadComplete then the queue upload is stopped.
  8099. If false is not returned (strict comparison) then the queue upload is continued.
  8100. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  8101. Set the event handler with the queue_complete_handler setting.
  8102. */
  8103. if (typeof(SWFUpload) === "function") {
  8104. SWFUpload.queue = {};
  8105. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  8106. return function () {
  8107. if (typeof(oldInitSettings) === "function") {
  8108. oldInitSettings.call(this);
  8109. }
  8110. this.queueSettings = {};
  8111. this.queueSettings.queue_cancelled_flag = false;
  8112. this.queueSettings.queue_upload_count = 0;
  8113. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  8114. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  8115. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  8116. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  8117. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  8118. };
  8119. })(SWFUpload.prototype.initSettings);
  8120. SWFUpload.prototype.startUpload = function (fileID) {
  8121. this.queueSettings.queue_cancelled_flag = false;
  8122. this.callFlash("StartUpload", [fileID]);
  8123. };
  8124. SWFUpload.prototype.cancelQueue = function () {
  8125. this.queueSettings.queue_cancelled_flag = true;
  8126. this.stopUpload();
  8127. var stats = this.getStats();
  8128. while (stats.files_queued > 0) {
  8129. this.cancelUpload();
  8130. stats = this.getStats();
  8131. }
  8132. };
  8133. SWFUpload.queue.uploadStartHandler = function (file) {
  8134. var returnValue;
  8135. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  8136. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  8137. }
  8138. // To prevent upload a real "FALSE" value must be returned, otherwise default to a real "TRUE" value.
  8139. returnValue = (returnValue === false) ? false : true;
  8140. this.queueSettings.queue_cancelled_flag = !returnValue;
  8141. return returnValue;
  8142. };
  8143. SWFUpload.queue.uploadCompleteHandler = function (file) {
  8144. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  8145. var continueUpload;
  8146. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  8147. this.queueSettings.queue_upload_count++;
  8148. }
  8149. if (typeof(user_upload_complete_handler) === "function") {
  8150. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  8151. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  8152. // If the file was stopped and re-queued don't restart the upload
  8153. continueUpload = false;
  8154. } else {
  8155. continueUpload = true;
  8156. }
  8157. if (continueUpload) {
  8158. var stats = this.getStats();
  8159. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  8160. this.startUpload();
  8161. } else if (this.queueSettings.queue_cancelled_flag === false) {
  8162. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  8163. this.queueSettings.queue_upload_count = 0;
  8164. } else {
  8165. this.queueSettings.queue_cancelled_flag = false;
  8166. this.queueSettings.queue_upload_count = 0;
  8167. }
  8168. }
  8169. };
  8170. }
  8171. })();
  8172. /*******************************************************************************
  8173. * KindEditor - WYSIWYG HTML Editor for Internet
  8174. * Copyright (C) 2006-2011 kindsoft.net
  8175. *
  8176. * @author Roddy <luolonghao@gmail.com>
  8177. * @site http://www.kindsoft.net/
  8178. * @licence http://www.kindsoft.net/license.php
  8179. *******************************************************************************/
  8180. KindEditor.plugin('pagebreak', function(K) {
  8181. var self = this;
  8182. var name = 'pagebreak';
  8183. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  8184. self.clickToolbar(name, function() {
  8185. var cmd = self.cmd, range = cmd.range;
  8186. self.focus();
  8187. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  8188. self.insertHtml(pagebreakHtml + tail);
  8189. if (tail !== '') {
  8190. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  8191. range.selectNodeContents(p[0]);
  8192. p.removeAttr('id');
  8193. cmd.select();
  8194. }
  8195. });
  8196. });
  8197. /*******************************************************************************
  8198. * KindEditor - WYSIWYG HTML Editor for Internet
  8199. * Copyright (C) 2006-2011 kindsoft.net
  8200. *
  8201. * @author Roddy <luolonghao@gmail.com>
  8202. * @site http://www.kindsoft.net/
  8203. * @licence http://www.kindsoft.net/license.php
  8204. *******************************************************************************/
  8205. KindEditor.plugin('plainpaste', function(K) {
  8206. var self = this, name = 'plainpaste';
  8207. self.clickToolbar(name, function() {
  8208. var lang = self.lang(name + '.'),
  8209. html = '<div style="padding:10px 20px;">' +
  8210. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  8211. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  8212. '</div>',
  8213. dialog = self.createDialog({
  8214. name : name,
  8215. width : 450,
  8216. title : self.lang(name),
  8217. body : html,
  8218. yesBtn : {
  8219. name : self.lang('yes'),
  8220. click : function(e) {
  8221. var html = textarea.val();
  8222. html = K.escape(html);
  8223. html = html.replace(/ {2}/g, ' &nbsp;');
  8224. if (self.newlineTag == 'p') {
  8225. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  8226. } else {
  8227. html = html.replace(/\n/g, '<br />$&');
  8228. }
  8229. self.insertHtml(html).hideDialog().focus();
  8230. }
  8231. }
  8232. }),
  8233. textarea = K('textarea', dialog.div);
  8234. textarea[0].focus();
  8235. });
  8236. });
  8237. /*******************************************************************************
  8238. * KindEditor - WYSIWYG HTML Editor for Internet
  8239. * Copyright (C) 2006-2011 kindsoft.net
  8240. *
  8241. * @author Roddy <luolonghao@gmail.com>
  8242. * @site http://www.kindsoft.net/
  8243. * @licence http://www.kindsoft.net/license.php
  8244. *******************************************************************************/
  8245. KindEditor.plugin('preview', function(K) {
  8246. var self = this, name = 'preview', undefined;
  8247. self.clickToolbar(name, function() {
  8248. var lang = self.lang(name + '.'),
  8249. html = '<div style="padding:10px 20px;">' +
  8250. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  8251. '</div>',
  8252. dialog = self.createDialog({
  8253. name : name,
  8254. width : 750,
  8255. title : self.lang(name),
  8256. body : html
  8257. }),
  8258. iframe = K('iframe', dialog.div),
  8259. doc = K.iframeDoc(iframe);
  8260. doc.open();
  8261. doc.write(self.fullHtml());
  8262. doc.close();
  8263. K(doc.body).css('background-color', '#FFF');
  8264. iframe[0].contentWindow.focus();
  8265. });
  8266. });
  8267. /*******************************************************************************
  8268. * KindEditor - WYSIWYG HTML Editor for Internet
  8269. * Copyright (C) 2006-2011 kindsoft.net
  8270. *
  8271. * @author Roddy <luolonghao@gmail.com>
  8272. * @site http://www.kindsoft.net/
  8273. * @licence http://www.kindsoft.net/license.php
  8274. *******************************************************************************/
  8275. KindEditor.plugin('quickformat', function(K) {
  8276. var self = this, name = 'quickformat',
  8277. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  8278. function getFirstChild(knode) {
  8279. var child = knode.first();
  8280. while (child && child.first()) {
  8281. child = child.first();
  8282. }
  8283. return child;
  8284. }
  8285. self.clickToolbar(name, function() {
  8286. self.focus();
  8287. var doc = self.edit.doc,
  8288. range = self.cmd.range,
  8289. child = K(doc.body).first(), next,
  8290. nodeList = [], subList = [],
  8291. bookmark = range.createBookmark(true);
  8292. while(child) {
  8293. next = child.next();
  8294. var firstChild = getFirstChild(child);
  8295. if (!firstChild || firstChild.name != 'img') {
  8296. if (blockMap[child.name]) {
  8297. child.html(child.html().replace(/^(\s|&nbsp;|)+/ig, ''));
  8298. /* Knaan@2014-07-23 修改:格式化html时子元素前空两个全角空格 */
  8299. var html = child.html();
  8300. if (html.indexOf('&emsp;&emsp;') != 0)
  8301. child.html('  '+ child.html());
  8302. } else {
  8303. subList.push(child);
  8304. }
  8305. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  8306. if (subList.length > 0) {
  8307. nodeList.push(subList);
  8308. }
  8309. subList = [];
  8310. }
  8311. }
  8312. child = next;
  8313. }
  8314. K.each(nodeList, function(i, subList) {
  8315. //var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  8316. var wrapper = K('<p></p>', doc);
  8317. subList[0].before(wrapper);
  8318. K.each(subList, function(i, knode) {
  8319. wrapper.append(knode);
  8320. });
  8321. });
  8322. range.moveToBookmark(bookmark);
  8323. self.addBookmark();
  8324. });
  8325. });
  8326. /**
  8327. --------------------------
  8328. abcd<br />
  8329. 1234<br />
  8330. to
  8331. <p style="text-indent:2em;">
  8332. abcd<br />
  8333. 1234<br />
  8334. </p>
  8335. --------------------------
  8336. &nbsp; abcd<img>1233
  8337. <p>1234</p>
  8338. to
  8339. <p style="text-indent:2em;">abcd<img>1233</p>
  8340. <p style="text-indent:2em;">1234</p>
  8341. --------------------------
  8342. *//*******************************************************************************
  8343. * KindEditor - WYSIWYG HTML Editor for Internet
  8344. * Copyright (C) 2006-2011 kindsoft.net
  8345. *
  8346. * @author Roddy <luolonghao@gmail.com>
  8347. * @site http://www.kindsoft.net/
  8348. * @licence http://www.kindsoft.net/license.php
  8349. *******************************************************************************/
  8350. KindEditor.plugin('table', function(K) {
  8351. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  8352. // 设置颜色
  8353. function _setColor(box, color) {
  8354. color = color.toUpperCase();
  8355. box.css('background-color', color);
  8356. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  8357. box.html(color);
  8358. }
  8359. // 初始化取色器
  8360. var pickerList = [];
  8361. function _initColorPicker(dialogDiv, colorBox) {
  8362. colorBox.bind('click,mousedown', function(e){
  8363. e.stopPropagation();
  8364. });
  8365. function removePicker() {
  8366. K.each(pickerList, function() {
  8367. this.remove();
  8368. });
  8369. pickerList = [];
  8370. K(document).unbind('click,mousedown', removePicker);
  8371. dialogDiv.unbind('click,mousedown', removePicker);
  8372. }
  8373. colorBox.click(function(e) {
  8374. removePicker();
  8375. var box = K(this),
  8376. pos = box.pos();
  8377. var picker = K.colorpicker({
  8378. x : pos.x,
  8379. y : pos.y + box.height(),
  8380. z : 811214,
  8381. selectedColor : K(this).html(),
  8382. colors : self.colorTable,
  8383. noColor : self.lang('noColor'),
  8384. shadowMode : self.shadowMode,
  8385. click : function(color) {
  8386. _setColor(box, color);
  8387. removePicker();
  8388. }
  8389. });
  8390. pickerList.push(picker);
  8391. K(document).bind('click,mousedown', removePicker);
  8392. dialogDiv.bind('click,mousedown', removePicker);
  8393. });
  8394. }
  8395. // 取得下一行cell的index
  8396. function _getCellIndex(table, row, cell) {
  8397. var rowSpanCount = 0;
  8398. for (var i = 0, len = row.cells.length; i < len; i++) {
  8399. if (row.cells[i] == cell) {
  8400. break;
  8401. }
  8402. rowSpanCount += row.cells[i].rowSpan - 1;
  8403. }
  8404. return cell.cellIndex - rowSpanCount;
  8405. }
  8406. self.plugin.table = {
  8407. //insert or modify table
  8408. prop : function(isInsert) {
  8409. var html = [
  8410. '<div style="padding:20px;">',
  8411. //rows, cols
  8412. '<div class="ke-dialog-row">',
  8413. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  8414. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  8415. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  8416. '</div>',
  8417. //width, height
  8418. '<div class="ke-dialog-row">',
  8419. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  8420. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  8421. '<select name="widthType">',
  8422. '<option value="%">' + lang.percent + '</option>',
  8423. '<option value="px">' + lang.px + '</option>',
  8424. '</select> &nbsp; ',
  8425. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  8426. '<select name="heightType">',
  8427. '<option value="%">' + lang.percent + '</option>',
  8428. '<option value="px">' + lang.px + '</option>',
  8429. '</select>',
  8430. '</div>',
  8431. //space, padding
  8432. '<div class="ke-dialog-row">',
  8433. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  8434. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  8435. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  8436. '</div>',
  8437. //align
  8438. '<div class="ke-dialog-row">',
  8439. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  8440. '<select id="keAlign" name="align">',
  8441. '<option value="">' + lang.alignDefault + '</option>',
  8442. '<option value="left">' + lang.alignLeft + '</option>',
  8443. '<option value="center">' + lang.alignCenter + '</option>',
  8444. '<option value="right">' + lang.alignRight + '</option>',
  8445. '</select>',
  8446. '</div>',
  8447. //border
  8448. '<div class="ke-dialog-row">',
  8449. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  8450. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  8451. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  8452. '</div>',
  8453. //background color
  8454. '<div class="ke-dialog-row">',
  8455. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  8456. '<span class="ke-inline-block ke-input-color"></span>',
  8457. '</div>',
  8458. '</div>'
  8459. ].join('');
  8460. var bookmark = self.cmd.range.createBookmark();
  8461. var dialog = self.createDialog({
  8462. name : name,
  8463. width : 500,
  8464. title : self.lang(name),
  8465. body : html,
  8466. beforeRemove : function() {
  8467. colorBox.unbind();
  8468. },
  8469. yesBtn : {
  8470. name : self.lang('yes'),
  8471. click : function(e) {
  8472. var rows = rowsBox.val(),
  8473. cols = colsBox.val(),
  8474. width = widthBox.val(),
  8475. height = heightBox.val(),
  8476. widthType = widthTypeBox.val(),
  8477. heightType = heightTypeBox.val(),
  8478. padding = paddingBox.val(),
  8479. spacing = spacingBox.val(),
  8480. align = alignBox.val(),
  8481. border = borderBox.val(),
  8482. borderColor = K(colorBox[0]).html() || '',
  8483. bgColor = K(colorBox[1]).html() || '';
  8484. if (rows == 0 || !/^\d+$/.test(rows)) {
  8485. alert(self.lang('invalidRows'));
  8486. rowsBox[0].focus();
  8487. return;
  8488. }
  8489. if (cols == 0 || !/^\d+$/.test(cols)) {
  8490. alert(self.lang('invalidRows'));
  8491. colsBox[0].focus();
  8492. return;
  8493. }
  8494. if (!/^\d*$/.test(width)) {
  8495. alert(self.lang('invalidWidth'));
  8496. widthBox[0].focus();
  8497. return;
  8498. }
  8499. if (!/^\d*$/.test(height)) {
  8500. alert(self.lang('invalidHeight'));
  8501. heightBox[0].focus();
  8502. return;
  8503. }
  8504. if (!/^\d*$/.test(padding)) {
  8505. alert(self.lang('invalidPadding'));
  8506. paddingBox[0].focus();
  8507. return;
  8508. }
  8509. if (!/^\d*$/.test(spacing)) {
  8510. alert(self.lang('invalidSpacing'));
  8511. spacingBox[0].focus();
  8512. return;
  8513. }
  8514. if (!/^\d*$/.test(border)) {
  8515. alert(self.lang('invalidBorder'));
  8516. borderBox[0].focus();
  8517. return;
  8518. }
  8519. //modify table
  8520. if (table) {
  8521. if (width !== '') {
  8522. table.width(width + widthType);
  8523. } else {
  8524. table.css('width', '');
  8525. }
  8526. if (table[0].width !== undefined) {
  8527. table.removeAttr('width');
  8528. }
  8529. if (height !== '') {
  8530. table.height(height + heightType);
  8531. } else {
  8532. table.css('height', '');
  8533. }
  8534. if (table[0].height !== undefined) {
  8535. table.removeAttr('height');
  8536. }
  8537. table.css('background-color', bgColor);
  8538. if (table[0].bgColor !== undefined) {
  8539. table.removeAttr('bgColor');
  8540. }
  8541. if (padding !== '') {
  8542. table[0].cellPadding = padding;
  8543. } else {
  8544. table.removeAttr('cellPadding');
  8545. }
  8546. if (spacing !== '') {
  8547. table[0].cellSpacing = spacing;
  8548. } else {
  8549. table.removeAttr('cellSpacing');
  8550. }
  8551. if (align !== '') {
  8552. table[0].align = align;
  8553. } else {
  8554. table.removeAttr('align');
  8555. }
  8556. if (border !== '') {
  8557. table.attr('border', border);
  8558. } else {
  8559. table.removeAttr('border');
  8560. }
  8561. if (border === '' || border === '0') {
  8562. table.addClass(zeroborder);
  8563. } else {
  8564. table.removeClass(zeroborder);
  8565. }
  8566. if (borderColor !== '') {
  8567. table.attr('borderColor', borderColor);
  8568. } else {
  8569. table.removeAttr('borderColor');
  8570. }
  8571. self.hideDialog().focus();
  8572. self.cmd.range.moveToBookmark(bookmark);
  8573. self.cmd.select();
  8574. self.addBookmark();
  8575. return;
  8576. }
  8577. //insert new table
  8578. var style = '';
  8579. if (width !== '') {
  8580. style += 'width:' + width + widthType + ';';
  8581. }
  8582. if (height !== '') {
  8583. style += 'height:' + height + heightType + ';';
  8584. }
  8585. if (bgColor !== '') {
  8586. style += 'background-color:' + bgColor + ';';
  8587. }
  8588. var html = '<table';
  8589. if (style !== '') {
  8590. html += ' style="' + style + '"';
  8591. }
  8592. if (padding !== '') {
  8593. html += ' cellpadding="' + padding + '"';
  8594. }
  8595. if (spacing !== '') {
  8596. html += ' cellspacing="' + spacing + '"';
  8597. }
  8598. if (align !== '') {
  8599. html += ' align="' + align + '"';
  8600. }
  8601. if (border !== '') {
  8602. html += ' border="' + border + '"';
  8603. }
  8604. if (border === '' || border === '0') {
  8605. html += ' class="' + zeroborder + '"';
  8606. }
  8607. if (borderColor !== '') {
  8608. html += ' bordercolor="' + borderColor + '"';
  8609. }
  8610. html += '>';
  8611. for (var i = 0; i < rows; i++) {
  8612. html += '<tr>';
  8613. for (var j = 0; j < cols; j++) {
  8614. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  8615. }
  8616. html += '</tr>';
  8617. }
  8618. html += '</table>';
  8619. if (!K.IE) {
  8620. html += '<br />';
  8621. }
  8622. self.insertHtml(html);
  8623. self.select().hideDialog().focus();
  8624. self.addBookmark();
  8625. }
  8626. }
  8627. }),
  8628. div = dialog.div,
  8629. rowsBox = K('[name="rows"]', div).val(3),
  8630. colsBox = K('[name="cols"]', div).val(2),
  8631. widthBox = K('[name="width"]', div).val(100),
  8632. heightBox = K('[name="height"]', div),
  8633. widthTypeBox = K('[name="widthType"]', div),
  8634. heightTypeBox = K('[name="heightType"]', div),
  8635. paddingBox = K('[name="padding"]', div).val(2),
  8636. spacingBox = K('[name="spacing"]', div).val(0),
  8637. alignBox = K('[name="align"]', div),
  8638. borderBox = K('[name="border"]', div).val(1),
  8639. colorBox = K('.ke-input-color', div);
  8640. _initColorPicker(div, colorBox.eq(0));
  8641. _initColorPicker(div, colorBox.eq(1));
  8642. _setColor(colorBox.eq(0), '#000000');
  8643. _setColor(colorBox.eq(1), '');
  8644. // foucs and select
  8645. rowsBox[0].focus();
  8646. rowsBox[0].select();
  8647. var table;
  8648. if (isInsert) {
  8649. return;
  8650. }
  8651. //get selected table node
  8652. table = self.plugin.getSelectedTable();
  8653. if (table) {
  8654. rowsBox.val(table[0].rows.length);
  8655. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  8656. rowsBox.attr('disabled', true);
  8657. colsBox.attr('disabled', true);
  8658. var match,
  8659. tableWidth = table[0].style.width || table[0].width,
  8660. tableHeight = table[0].style.height || table[0].height;
  8661. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  8662. widthBox.val(match[1]);
  8663. widthTypeBox.val(match[2]);
  8664. } else {
  8665. widthBox.val('');
  8666. }
  8667. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  8668. heightBox.val(match[1]);
  8669. heightTypeBox.val(match[2]);
  8670. }
  8671. paddingBox.val(table[0].cellPadding || '');
  8672. spacingBox.val(table[0].cellSpacing || '');
  8673. alignBox.val(table[0].align || '');
  8674. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  8675. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  8676. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  8677. widthBox[0].focus();
  8678. widthBox[0].select();
  8679. }
  8680. },
  8681. //modify cell
  8682. cellprop : function() {
  8683. var html = [
  8684. '<div style="padding:20px;">',
  8685. //width, height
  8686. '<div class="ke-dialog-row">',
  8687. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  8688. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  8689. '<select name="widthType">',
  8690. '<option value="%">' + lang.percent + '</option>',
  8691. '<option value="px">' + lang.px + '</option>',
  8692. '</select> &nbsp; ',
  8693. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  8694. '<select name="heightType">',
  8695. '<option value="%">' + lang.percent + '</option>',
  8696. '<option value="px">' + lang.px + '</option>',
  8697. '</select>',
  8698. '</div>',
  8699. //align
  8700. '<div class="ke-dialog-row">',
  8701. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  8702. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  8703. '<option value="">' + lang.alignDefault + '</option>',
  8704. '<option value="left">' + lang.alignLeft + '</option>',
  8705. '<option value="center">' + lang.alignCenter + '</option>',
  8706. '<option value="right">' + lang.alignRight + '</option>',
  8707. '</select> ',
  8708. lang.verticalAlign + ' <select name="verticalAlign">',
  8709. '<option value="">' + lang.alignDefault + '</option>',
  8710. '<option value="top">' + lang.alignTop + '</option>',
  8711. '<option value="middle">' + lang.alignMiddle + '</option>',
  8712. '<option value="bottom">' + lang.alignBottom + '</option>',
  8713. '<option value="baseline">' + lang.alignBaseline + '</option>',
  8714. '</select>',
  8715. '</div>',
  8716. //border
  8717. '<div class="ke-dialog-row">',
  8718. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  8719. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  8720. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  8721. '</div>',
  8722. //background color
  8723. '<div class="ke-dialog-row">',
  8724. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  8725. '<span class="ke-inline-block ke-input-color"></span>',
  8726. '</div>',
  8727. '</div>'
  8728. ].join('');
  8729. var bookmark = self.cmd.range.createBookmark();
  8730. var dialog = self.createDialog({
  8731. name : name,
  8732. width : 500,
  8733. title : self.lang('tablecell'),
  8734. body : html,
  8735. beforeRemove : function() {
  8736. colorBox.unbind();
  8737. },
  8738. yesBtn : {
  8739. name : self.lang('yes'),
  8740. click : function(e) {
  8741. var width = widthBox.val(),
  8742. height = heightBox.val(),
  8743. widthType = widthTypeBox.val(),
  8744. heightType = heightTypeBox.val(),
  8745. padding = paddingBox.val(),
  8746. spacing = spacingBox.val(),
  8747. textAlign = textAlignBox.val(),
  8748. verticalAlign = verticalAlignBox.val(),
  8749. border = borderBox.val(),
  8750. borderColor = K(colorBox[0]).html() || '',
  8751. bgColor = K(colorBox[1]).html() || '';
  8752. if (!/^\d*$/.test(width)) {
  8753. alert(self.lang('invalidWidth'));
  8754. widthBox[0].focus();
  8755. return;
  8756. }
  8757. if (!/^\d*$/.test(height)) {
  8758. alert(self.lang('invalidHeight'));
  8759. heightBox[0].focus();
  8760. return;
  8761. }
  8762. if (!/^\d*$/.test(border)) {
  8763. alert(self.lang('invalidBorder'));
  8764. borderBox[0].focus();
  8765. return;
  8766. }
  8767. cell.css({
  8768. width : width !== '' ? (width + widthType) : '',
  8769. height : height !== '' ? (height + heightType) : '',
  8770. 'background-color' : bgColor,
  8771. 'text-align' : textAlign,
  8772. 'vertical-align' : verticalAlign,
  8773. 'border-width' : border,
  8774. 'border-style' : border !== '' ? 'solid' : '',
  8775. 'border-color' : borderColor
  8776. });
  8777. self.hideDialog().focus();
  8778. self.cmd.range.moveToBookmark(bookmark);
  8779. self.cmd.select();
  8780. self.addBookmark();
  8781. }
  8782. }
  8783. }),
  8784. div = dialog.div,
  8785. widthBox = K('[name="width"]', div).val(100),
  8786. heightBox = K('[name="height"]', div),
  8787. widthTypeBox = K('[name="widthType"]', div),
  8788. heightTypeBox = K('[name="heightType"]', div),
  8789. paddingBox = K('[name="padding"]', div).val(2),
  8790. spacingBox = K('[name="spacing"]', div).val(0),
  8791. textAlignBox = K('[name="textAlign"]', div),
  8792. verticalAlignBox = K('[name="verticalAlign"]', div),
  8793. borderBox = K('[name="border"]', div).val(1),
  8794. colorBox = K('.ke-input-color', div);
  8795. _initColorPicker(div, colorBox.eq(0));
  8796. _initColorPicker(div, colorBox.eq(1));
  8797. _setColor(colorBox.eq(0), '#000000');
  8798. _setColor(colorBox.eq(1), '');
  8799. // foucs and select
  8800. widthBox[0].focus();
  8801. widthBox[0].select();
  8802. // get selected cell
  8803. var cell = self.plugin.getSelectedCell();
  8804. var match,
  8805. cellWidth = cell[0].style.width || cell[0].width || '',
  8806. cellHeight = cell[0].style.height || cell[0].height || '';
  8807. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  8808. widthBox.val(match[1]);
  8809. widthTypeBox.val(match[2]);
  8810. } else {
  8811. widthBox.val('');
  8812. }
  8813. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  8814. heightBox.val(match[1]);
  8815. heightTypeBox.val(match[2]);
  8816. }
  8817. textAlignBox.val(cell[0].style.textAlign || '');
  8818. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  8819. var border = cell[0].style.borderWidth || '';
  8820. if (border) {
  8821. border = parseInt(border);
  8822. }
  8823. borderBox.val(border);
  8824. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  8825. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  8826. widthBox[0].focus();
  8827. widthBox[0].select();
  8828. },
  8829. insert : function() {
  8830. this.prop(true);
  8831. },
  8832. 'delete' : function() {
  8833. var table = self.plugin.getSelectedTable();
  8834. self.cmd.range.setStartBefore(table[0]).collapse(true);
  8835. self.cmd.select();
  8836. table.remove();
  8837. self.addBookmark();
  8838. },
  8839. colinsert : function(offset) {
  8840. var table = self.plugin.getSelectedTable()[0],
  8841. row = self.plugin.getSelectedRow()[0],
  8842. cell = self.plugin.getSelectedCell()[0],
  8843. index = cell.cellIndex + offset;
  8844. // 取得第一行的index
  8845. index += table.rows[0].cells.length - row.cells.length;
  8846. for (var i = 0, len = table.rows.length; i < len; i++) {
  8847. var newRow = table.rows[i],
  8848. newCell = newRow.insertCell(index);
  8849. newCell.innerHTML = K.IE ? '' : '<br />';
  8850. // 调整下一行的单元格index
  8851. index = _getCellIndex(table, newRow, newCell);
  8852. }
  8853. self.cmd.range.selectNodeContents(cell).collapse(true);
  8854. self.cmd.select();
  8855. self.addBookmark();
  8856. },
  8857. colinsertleft : function() {
  8858. this.colinsert(0);
  8859. },
  8860. colinsertright : function() {
  8861. this.colinsert(1);
  8862. },
  8863. rowinsert : function(offset) {
  8864. var table = self.plugin.getSelectedTable()[0],
  8865. row = self.plugin.getSelectedRow()[0],
  8866. cell = self.plugin.getSelectedCell()[0];
  8867. var rowIndex = row.rowIndex;
  8868. if (offset === 1) {
  8869. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  8870. }
  8871. var newRow = table.insertRow(rowIndex);
  8872. for (var i = 0, len = row.cells.length; i < len; i++) {
  8873. // 调整cell个数
  8874. if (row.cells[i].rowSpan > 1) {
  8875. len -= row.cells[i].rowSpan - 1;
  8876. }
  8877. var newCell = newRow.insertCell(i);
  8878. // copy colspan
  8879. if (offset === 1 && row.cells[i].colSpan > 1) {
  8880. newCell.colSpan = row.cells[i].colSpan;
  8881. }
  8882. newCell.innerHTML = K.IE ? '' : '<br />';
  8883. }
  8884. // 调整rowspan
  8885. for (var j = rowIndex; j >= 0; j--) {
  8886. var cells = table.rows[j].cells;
  8887. if (cells.length > i) {
  8888. for (var k = cell.cellIndex; k >= 0; k--) {
  8889. if (cells[k].rowSpan > 1) {
  8890. cells[k].rowSpan += 1;
  8891. }
  8892. }
  8893. break;
  8894. }
  8895. }
  8896. self.cmd.range.selectNodeContents(cell).collapse(true);
  8897. self.cmd.select();
  8898. self.addBookmark();
  8899. },
  8900. rowinsertabove : function() {
  8901. this.rowinsert(0);
  8902. },
  8903. rowinsertbelow : function() {
  8904. this.rowinsert(1);
  8905. },
  8906. rowmerge : function() {
  8907. var table = self.plugin.getSelectedTable()[0],
  8908. row = self.plugin.getSelectedRow()[0],
  8909. cell = self.plugin.getSelectedCell()[0],
  8910. rowIndex = row.rowIndex, // 当前行的index
  8911. nextRowIndex = rowIndex + cell.rowSpan, // 下一行的index
  8912. nextRow = table.rows[nextRowIndex]; // 下一行
  8913. // 最后一行不能合并
  8914. if (table.rows.length <= nextRowIndex) {
  8915. return;
  8916. }
  8917. var cellIndex = cell.cellIndex; // 下一行单元格的index
  8918. if (nextRow.cells.length <= cellIndex) {
  8919. return;
  8920. }
  8921. var nextCell = nextRow.cells[cellIndex]; // 下一行单元格
  8922. // 上下行的colspan不一致时不能合并
  8923. if (cell.colSpan !== nextCell.colSpan) {
  8924. return;
  8925. }
  8926. cell.rowSpan += nextCell.rowSpan;
  8927. nextRow.deleteCell(cellIndex);
  8928. self.cmd.range.selectNodeContents(cell).collapse(true);
  8929. self.cmd.select();
  8930. self.addBookmark();
  8931. },
  8932. colmerge : function() {
  8933. var table = self.plugin.getSelectedTable()[0],
  8934. row = self.plugin.getSelectedRow()[0],
  8935. cell = self.plugin.getSelectedCell()[0],
  8936. rowIndex = row.rowIndex, // 当前行的index
  8937. cellIndex = cell.cellIndex,
  8938. nextCellIndex = cellIndex + 1;
  8939. // 最后一列不能合并
  8940. if (row.cells.length <= nextCellIndex) {
  8941. return;
  8942. }
  8943. var nextCell = row.cells[nextCellIndex];
  8944. // 左右列的rowspan不一致时不能合并
  8945. if (cell.rowSpan !== nextCell.rowSpan) {
  8946. return;
  8947. }
  8948. cell.colSpan += nextCell.colSpan;
  8949. row.deleteCell(nextCellIndex);
  8950. self.cmd.range.selectNodeContents(cell).collapse(true);
  8951. self.cmd.select();
  8952. self.addBookmark();
  8953. },
  8954. rowsplit : function() {
  8955. var table = self.plugin.getSelectedTable()[0],
  8956. row = self.plugin.getSelectedRow()[0],
  8957. cell = self.plugin.getSelectedCell()[0],
  8958. rowIndex = row.rowIndex;
  8959. // 不是可分割单元格
  8960. if (cell.rowSpan === 1) {
  8961. return;
  8962. }
  8963. var cellIndex = _getCellIndex(table, row, cell);
  8964. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  8965. var newRow = table.rows[rowIndex + i],
  8966. newCell = newRow.insertCell(cellIndex);
  8967. if (cell.colSpan > 1) {
  8968. newCell.colSpan = cell.colSpan;
  8969. }
  8970. newCell.innerHTML = K.IE ? '' : '<br />';
  8971. // 调整下一行的单元格index
  8972. cellIndex = _getCellIndex(table, newRow, newCell);
  8973. }
  8974. K(cell).removeAttr('rowSpan');
  8975. self.cmd.range.selectNodeContents(cell).collapse(true);
  8976. self.cmd.select();
  8977. self.addBookmark();
  8978. },
  8979. colsplit : function() {
  8980. var table = self.plugin.getSelectedTable()[0],
  8981. row = self.plugin.getSelectedRow()[0],
  8982. cell = self.plugin.getSelectedCell()[0],
  8983. cellIndex = cell.cellIndex;
  8984. // 不是可分割单元格
  8985. if (cell.colSpan === 1) {
  8986. return;
  8987. }
  8988. for (var i = 1, len = cell.colSpan; i < len; i++) {
  8989. var newCell = row.insertCell(cellIndex + i);
  8990. if (cell.rowSpan > 1) {
  8991. newCell.rowSpan = cell.rowSpan;
  8992. }
  8993. newCell.innerHTML = K.IE ? '' : '<br />';
  8994. }
  8995. K(cell).removeAttr('colSpan');
  8996. self.cmd.range.selectNodeContents(cell).collapse(true);
  8997. self.cmd.select();
  8998. self.addBookmark();
  8999. },
  9000. coldelete : function() {
  9001. var table = self.plugin.getSelectedTable()[0],
  9002. row = self.plugin.getSelectedRow()[0],
  9003. cell = self.plugin.getSelectedCell()[0],
  9004. index = cell.cellIndex;
  9005. for (var i = 0, len = table.rows.length; i < len; i++) {
  9006. var newRow = table.rows[i],
  9007. newCell = newRow.cells[index];
  9008. if (newCell.colSpan > 1) {
  9009. newCell.colSpan -= 1;
  9010. if (newCell.colSpan === 1) {
  9011. K(newCell).removeAttr('colSpan');
  9012. }
  9013. } else {
  9014. newRow.deleteCell(index);
  9015. }
  9016. // 跳过不需要删除的行
  9017. if (newCell.rowSpan > 1) {
  9018. i += newCell.rowSpan - 1;
  9019. }
  9020. }
  9021. if (row.cells.length === 0) {
  9022. self.cmd.range.setStartBefore(table).collapse(true);
  9023. self.cmd.select();
  9024. K(table).remove();
  9025. } else {
  9026. self.cmd.selection(true);
  9027. }
  9028. self.addBookmark();
  9029. },
  9030. rowdelete : function() {
  9031. var table = self.plugin.getSelectedTable()[0],
  9032. row = self.plugin.getSelectedRow()[0],
  9033. cell = self.plugin.getSelectedCell()[0],
  9034. rowIndex = row.rowIndex;
  9035. // 从下到上删除
  9036. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9037. table.deleteRow(rowIndex + i);
  9038. }
  9039. if (table.rows.length === 0) {
  9040. self.cmd.range.setStartBefore(table).collapse(true);
  9041. self.cmd.select();
  9042. K(table).remove();
  9043. } else {
  9044. self.cmd.selection(true);
  9045. }
  9046. self.addBookmark();
  9047. }
  9048. };
  9049. self.clickToolbar(name, self.plugin.table.prop);
  9050. });
  9051. /*******************************************************************************
  9052. * KindEditor - WYSIWYG HTML Editor for Internet
  9053. * Copyright (C) 2006-2011 kindsoft.net
  9054. *
  9055. * @author Roddy <luolonghao@gmail.com>
  9056. * @site http://www.kindsoft.net/
  9057. * @licence http://www.kindsoft.net/license.php
  9058. *******************************************************************************/
  9059. KindEditor.plugin('template', function(K) {
  9060. var self = this, name = 'template', lang = self.lang(name + '.'),
  9061. htmlPath = self.pluginsPath + name + '/html/';
  9062. function getFilePath(fileName) {
  9063. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9064. }
  9065. self.clickToolbar(name, function() {
  9066. var lang = self.lang(name + '.'),
  9067. arr = ['<div style="padding:10px 20px;">',
  9068. '<div class="ke-header">',
  9069. // left start
  9070. '<div class="ke-left">',
  9071. lang. selectTemplate + ' <select>'];
  9072. K.each(lang.fileList, function(key, val) {
  9073. arr.push('<option value="' + key + '">' + val + '</option>');
  9074. });
  9075. html = [arr.join(''),
  9076. '</select></div>',
  9077. // right start
  9078. '<div class="ke-right">',
  9079. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9080. '</div>',
  9081. '<div class="ke-clearfix"></div>',
  9082. '</div>',
  9083. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9084. '</div>'].join('');
  9085. var dialog = self.createDialog({
  9086. name : name,
  9087. width : 500,
  9088. title : self.lang(name),
  9089. body : html,
  9090. yesBtn : {
  9091. name : self.lang('yes'),
  9092. click : function(e) {
  9093. var doc = K.iframeDoc(iframe);
  9094. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9095. }
  9096. }
  9097. });
  9098. var selectBox = K('select', dialog.div),
  9099. checkbox = K('[name="replaceFlag"]', dialog.div),
  9100. iframe = K('iframe', dialog.div);
  9101. checkbox[0].checked = true;
  9102. iframe.attr('src', getFilePath(selectBox.val()));
  9103. selectBox.change(function() {
  9104. iframe.attr('src', getFilePath(this.value));
  9105. });
  9106. });
  9107. });
  9108. /*******************************************************************************
  9109. * KindEditor - WYSIWYG HTML Editor for Internet
  9110. * Copyright (C) 2006-2011 kindsoft.net
  9111. *
  9112. * @author Roddy <luolonghao@gmail.com>
  9113. * @site http://www.kindsoft.net/
  9114. * @licence http://www.kindsoft.net/license.php
  9115. *******************************************************************************/
  9116. KindEditor.plugin('wordpaste', function(K) {
  9117. var self = this, name = 'wordpaste';
  9118. self.clickToolbar(name, function() {
  9119. var lang = self.lang(name + '.'),
  9120. html = '<div style="padding:10px 20px;">' +
  9121. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9122. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  9123. '</div>',
  9124. dialog = self.createDialog({
  9125. name : name,
  9126. width : 450,
  9127. title : self.lang(name),
  9128. body : html,
  9129. yesBtn : {
  9130. name : self.lang('yes'),
  9131. click : function(e) {
  9132. var str = doc.body.innerHTML;
  9133. var htmltag = {
  9134. font : [],
  9135. span : [],
  9136. div : [],
  9137. table: ['align', 'width'],
  9138. 'td,th': ['align', 'valign', 'width', 'height', 'colspan', 'rowspan'],
  9139. a : ['href', 'target', 'name'],
  9140. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  9141. img : ['src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  9142. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [],
  9143. pre : ['class'],
  9144. hr : ['class', '.page-break-after'],
  9145. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : []
  9146. };
  9147. //str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  9148. /*K'naan@2014-04-11 过滤html*/
  9149. str = K.clearMsWord(str, htmltag);
  9150. /*K'naan@2014-04-12 替换div为p*/
  9151. str = str.replace(/<div>/gi, '<p>').replace(/<\/div>/gi, '</p>');
  9152. self.insertHtml(str).hideDialog().focus();
  9153. }
  9154. }
  9155. }),
  9156. div = dialog.div,
  9157. iframe = K('iframe', div),
  9158. doc = K.iframeDoc(iframe);
  9159. if (!K.IE) {
  9160. doc.designMode = 'on';
  9161. }
  9162. doc.open();
  9163. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  9164. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  9165. if (!K.IE) {
  9166. doc.write('<br />');
  9167. }
  9168. doc.write('</body></html>');
  9169. doc.close();
  9170. if (K.IE) {
  9171. doc.body.contentEditable = 'true';
  9172. }
  9173. iframe[0].contentWindow.focus();
  9174. });
  9175. });