kindeditor-all-min.js 296 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089
  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2017 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.12 (2017-04-12)
  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.12 (2017-04-12)',
  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+(?:\.\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. index : 0,
  230. designMode : true,
  231. fullscreenMode : false,
  232. filterMode : true,
  233. wellFormatMode : true,
  234. shadowMode : true,
  235. loadStyleMode : true,
  236. basePath : K.basePath,
  237. themesPath : K.basePath + 'themes/',
  238. langPath : K.basePath + 'lang/',
  239. pluginsPath : K.basePath + 'plugins/',
  240. themeType : 'default',
  241. langType : 'zh-CN',
  242. urlType : '',
  243. newlineTag : 'p',
  244. resizeType : 2,
  245. syncType : 'form',
  246. pasteType : 2,
  247. dialogAlignType : 'page',
  248. useContextmenu : true,
  249. fullscreenShortcut : false,
  250. bodyClass : 'ke-content',
  251. indentChar : '\t',
  252. cssPath : '',
  253. cssData : '',
  254. minWidth : 650,
  255. minHeight : 100,
  256. minChangeSize : 50,
  257. zIndex : 811213,
  258. items : [
  259. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  260. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  261. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  262. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  263. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  264. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  265. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  266. 'anchor', 'link', 'unlink', '|', 'about'
  267. ],
  268. noDisableItems : ['source', 'fullscreen'],
  269. colorTable : [
  270. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  271. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  272. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  273. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  274. ],
  275. fontSizeTable : ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
  276. htmlTags : {
  277. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  278. span : [
  279. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  280. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  281. ],
  282. div : [
  283. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  284. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  285. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  286. ],
  287. table: [
  288. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  289. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  290. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  291. '.width', '.height', '.border-collapse'
  292. ],
  293. 'td,th': [
  294. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  295. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  296. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  297. ],
  298. a : ['id', 'class', 'href', 'target', 'name'],
  299. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', 'wmode'],
  300. img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  301. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  302. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  303. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  304. ],
  305. pre : ['id', 'class'],
  306. hr : ['id', 'class', '.page-break-after'],
  307. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  308. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  309. },
  310. layout : '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  311. };
  312. var _useCapture = false;
  313. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  314. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  315. var _CHANGE_KEY_MAP = {};
  316. _each(_INPUT_KEY_MAP, function(key, val) {
  317. _CHANGE_KEY_MAP[key] = val;
  318. });
  319. _each(_CURSORMOVE_KEY_MAP, function(key, val) {
  320. _CHANGE_KEY_MAP[key] = val;
  321. });
  322. function _bindEvent(el, type, fn) {
  323. if (el.addEventListener){
  324. el.addEventListener(type, fn, _useCapture);
  325. } else if (el.attachEvent){
  326. el.attachEvent('on' + type, fn);
  327. }
  328. }
  329. function _unbindEvent(el, type, fn) {
  330. if (el.removeEventListener){
  331. el.removeEventListener(type, fn, _useCapture);
  332. } else if (el.detachEvent){
  333. el.detachEvent('on' + type, fn);
  334. }
  335. }
  336. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  337. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  338. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  339. function KEvent(el, event) {
  340. this.init(el, event);
  341. }
  342. _extend(KEvent, {
  343. init : function(el, event) {
  344. var self = this, doc = el.ownerDocument || el.document || el;
  345. self.event = event;
  346. _each(_EVENT_PROPS, function(key, val) {
  347. self[val] = event[val];
  348. });
  349. if (!self.target) {
  350. self.target = self.srcElement || doc;
  351. }
  352. if (self.target.nodeType === 3) {
  353. self.target = self.target.parentNode;
  354. }
  355. if (!self.relatedTarget && self.fromElement) {
  356. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  357. }
  358. if (self.pageX == null && self.clientX != null) {
  359. var d = doc.documentElement, body = doc.body;
  360. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  361. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  362. }
  363. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  364. self.which = self.charCode || self.keyCode;
  365. }
  366. if (!self.metaKey && self.ctrlKey) {
  367. self.metaKey = self.ctrlKey;
  368. }
  369. if (!self.which && self.button !== undefined) {
  370. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  371. }
  372. switch (self.which) {
  373. case 186 :
  374. self.which = 59;
  375. break;
  376. case 187 :
  377. case 107 :
  378. case 43 :
  379. self.which = 61;
  380. break;
  381. case 189 :
  382. case 45 :
  383. self.which = 109;
  384. break;
  385. case 42 :
  386. self.which = 106;
  387. break;
  388. case 47 :
  389. self.which = 111;
  390. break;
  391. case 78 :
  392. self.which = 110;
  393. break;
  394. }
  395. if (self.which >= 96 && self.which <= 105) {
  396. self.which -= 48;
  397. }
  398. },
  399. preventDefault : function() {
  400. var ev = this.event;
  401. if (ev.preventDefault) {
  402. ev.preventDefault();
  403. } else {
  404. ev.returnValue = false;
  405. }
  406. },
  407. stopPropagation : function() {
  408. var ev = this.event;
  409. if (ev.stopPropagation) {
  410. ev.stopPropagation();
  411. } else {
  412. ev.cancelBubble = true;
  413. }
  414. },
  415. stop : function() {
  416. this.preventDefault();
  417. this.stopPropagation();
  418. }
  419. });
  420. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  421. function _getId(el) {
  422. return el[_eventExpendo] || null;
  423. }
  424. function _setId(el) {
  425. el[_eventExpendo] = ++_eventId;
  426. return _eventId;
  427. }
  428. function _removeId(el) {
  429. try {
  430. delete el[_eventExpendo];
  431. } catch(e) {
  432. if (el.removeAttribute) {
  433. el.removeAttribute(_eventExpendo);
  434. }
  435. }
  436. }
  437. function _bind(el, type, fn) {
  438. if (type.indexOf(',') >= 0) {
  439. _each(type.split(','), function() {
  440. _bind(el, this, fn);
  441. });
  442. return;
  443. }
  444. var id = _getId(el);
  445. if (!id) {
  446. id = _setId(el);
  447. }
  448. if (_eventData[id] === undefined) {
  449. _eventData[id] = {};
  450. }
  451. var events = _eventData[id][type];
  452. if (events && events.length > 0) {
  453. _unbindEvent(el, type, events[0]);
  454. } else {
  455. _eventData[id][type] = [];
  456. _eventData[id].el = el;
  457. }
  458. events = _eventData[id][type];
  459. if (events.length === 0) {
  460. events[0] = function(e) {
  461. var kevent = e ? new KEvent(el, e) : undefined;
  462. _each(events, function(i, event) {
  463. if (i > 0 && event) {
  464. event.call(el, kevent);
  465. }
  466. });
  467. };
  468. }
  469. if (_inArray(fn, events) < 0) {
  470. events.push(fn);
  471. }
  472. _bindEvent(el, type, events[0]);
  473. }
  474. function _unbind(el, type, fn) {
  475. if (type && type.indexOf(',') >= 0) {
  476. _each(type.split(','), function() {
  477. _unbind(el, this, fn);
  478. });
  479. return;
  480. }
  481. var id = _getId(el);
  482. if (!id) {
  483. return;
  484. }
  485. if (type === undefined) {
  486. if (id in _eventData) {
  487. _each(_eventData[id], function(key, events) {
  488. if (key != 'el' && events.length > 0) {
  489. _unbindEvent(el, key, events[0]);
  490. }
  491. });
  492. delete _eventData[id];
  493. _removeId(el);
  494. }
  495. return;
  496. }
  497. if (!_eventData[id]) {
  498. return;
  499. }
  500. var events = _eventData[id][type];
  501. if (events && events.length > 0) {
  502. if (fn === undefined) {
  503. _unbindEvent(el, type, events[0]);
  504. delete _eventData[id][type];
  505. } else {
  506. _each(events, function(i, event) {
  507. if (i > 0 && event === fn) {
  508. events.splice(i, 1);
  509. }
  510. });
  511. if (events.length == 1) {
  512. _unbindEvent(el, type, events[0]);
  513. delete _eventData[id][type];
  514. }
  515. }
  516. var count = 0;
  517. _each(_eventData[id], function() {
  518. count++;
  519. });
  520. if (count < 2) {
  521. delete _eventData[id];
  522. _removeId(el);
  523. }
  524. }
  525. }
  526. function _fire(el, type) {
  527. if (type.indexOf(',') >= 0) {
  528. _each(type.split(','), function() {
  529. _fire(el, this);
  530. });
  531. return;
  532. }
  533. var id = _getId(el);
  534. if (!id) {
  535. return;
  536. }
  537. var events = _eventData[id][type];
  538. if (_eventData[id] && events && events.length > 0) {
  539. events[0]();
  540. }
  541. }
  542. function _ctrl(el, key, fn) {
  543. var self = this;
  544. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  545. _bind(el, 'keydown', function(e) {
  546. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  547. fn.call(el);
  548. e.stop();
  549. }
  550. });
  551. }
  552. var _readyFinished = false;
  553. function _ready(fn) {
  554. if (_readyFinished) {
  555. fn(KindEditor);
  556. return;
  557. }
  558. var loaded = false;
  559. function readyFunc() {
  560. if (!loaded) {
  561. loaded = true;
  562. fn(KindEditor);
  563. _readyFinished = true;
  564. }
  565. }
  566. function ieReadyFunc() {
  567. if (!loaded) {
  568. try {
  569. document.documentElement.doScroll('left');
  570. } catch(e) {
  571. setTimeout(ieReadyFunc, 100);
  572. return;
  573. }
  574. readyFunc();
  575. }
  576. }
  577. function ieReadyStateFunc() {
  578. if (document.readyState === 'complete') {
  579. readyFunc();
  580. }
  581. }
  582. if (document.addEventListener) {
  583. _bind(document, 'DOMContentLoaded', readyFunc);
  584. } else if (document.attachEvent) {
  585. _bind(document, 'readystatechange', ieReadyStateFunc);
  586. var toplevel = false;
  587. try {
  588. toplevel = window.frameElement == null;
  589. } catch(e) {}
  590. if (document.documentElement.doScroll && toplevel) {
  591. ieReadyFunc();
  592. }
  593. }
  594. _bind(window, 'load', readyFunc);
  595. }
  596. if (window.attachEvent) {
  597. window.attachEvent('onunload', function() {
  598. _each(_eventData, function(key, events) {
  599. if (events.el) {
  600. _unbind(events.el);
  601. }
  602. });
  603. });
  604. }
  605. K.ctrl = _ctrl;
  606. K.ready = _ready;
  607. function _getCssList(css) {
  608. css = css.replace(/&quot;/g, '"');
  609. var list = {},
  610. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  611. match;
  612. while ((match = reg.exec(css))) {
  613. var key = _trim(match[1].toLowerCase()),
  614. val = _trim(_toHex(match[2]));
  615. list[key] = val;
  616. }
  617. return list;
  618. }
  619. function _getAttrList(tag) {
  620. var list = {},
  621. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  622. match;
  623. while ((match = reg.exec(tag))) {
  624. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  625. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  626. list[key] = val;
  627. }
  628. return list;
  629. }
  630. function _addClassToTag(tag, className) {
  631. if (/\s+class\s*=/.test(tag)) {
  632. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  633. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  634. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  635. } else {
  636. return $0;
  637. }
  638. });
  639. } else {
  640. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  641. }
  642. return tag;
  643. }
  644. function _formatCss(css) {
  645. var str = '';
  646. _each(_getCssList(css), function(key, val) {
  647. str += key + ':' + val + ';';
  648. });
  649. return str;
  650. }
  651. function _formatUrl(url, mode, host, pathname) {
  652. return url;
  653. mode = _undef(mode, '').toLowerCase();
  654. if (url.substr(0, 5) != 'data:') {
  655. url = url.replace(/([^:])\/\//g, '$1/');
  656. }
  657. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  658. return url;
  659. }
  660. host = host || location.protocol + '//' + location.host;
  661. if (pathname === undefined) {
  662. var m = location.pathname.match(/^(\/.*)\//);
  663. pathname = m ? m[1] : '';
  664. }
  665. var match;
  666. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  667. if (match[1] !== host) {
  668. return url;
  669. }
  670. } else if (/^\w+:/.test(url)) {
  671. return url;
  672. }
  673. function getRealPath(path) {
  674. var parts = path.split('/'), paths = [];
  675. for (var i = 0, len = parts.length; i < len; i++) {
  676. var part = parts[i];
  677. if (part == '..') {
  678. if (paths.length > 0) {
  679. paths.pop();
  680. }
  681. } else if (part !== '' && part != '.') {
  682. paths.push(part);
  683. }
  684. }
  685. return '/' + paths.join('/');
  686. }
  687. if (/^\//.test(url)) {
  688. url = host + getRealPath(url.substr(1));
  689. } else if (!/^\w+:\/\//.test(url)) {
  690. url = host + getRealPath(pathname + '/' + url);
  691. }
  692. function getRelativePath(path, depth) {
  693. if (url.substr(0, path.length) === path) {
  694. var arr = [];
  695. for (var i = 0; i < depth; i++) {
  696. arr.push('..');
  697. }
  698. var prefix = '.';
  699. if (arr.length > 0) {
  700. prefix += '/' + arr.join('/');
  701. }
  702. if (pathname == '/') {
  703. prefix += '/';
  704. }
  705. return prefix + url.substr(path.length);
  706. } else {
  707. if ((match = /^(.*)\//.exec(path))) {
  708. return getRelativePath(match[1], ++depth);
  709. }
  710. }
  711. }
  712. if (mode === 'relative') {
  713. url = getRelativePath(host + pathname, 0).substr(2);
  714. } else if (mode === 'absolute') {
  715. if (url.substr(0, host.length) === host) {
  716. url = url.substr(host.length);
  717. }
  718. }
  719. return url;
  720. }
  721. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  722. if (html == null) {
  723. html = '';
  724. }
  725. urlType = urlType || '';
  726. wellFormatted = _undef(wellFormatted, false);
  727. indentChar = _undef(indentChar, '\t');
  728. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  729. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  730. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  731. });
  732. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  733. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  734. html = html.replace(/\u200B/g, '');
  735. html = html.replace(/\u00A9/g, '&copy;');
  736. html = html.replace(/\u00AE/g, '&reg;');
  737. html = html.replace(/\u2003/g, '&emsp;');
  738. html = html.replace(/\u3000/g, '&emsp;');
  739. html = html.replace(/<[^>]+/g, function($0) {
  740. return $0.replace(/\s+/g, ' ');
  741. });
  742. var htmlTagMap = {};
  743. if (htmlTags) {
  744. _each(htmlTags, function(key, val) {
  745. var arr = key.split(',');
  746. for (var i = 0, len = arr.length; i < len; i++) {
  747. htmlTagMap[arr[i]] = _toMap(val);
  748. }
  749. });
  750. if (!htmlTagMap.script) {
  751. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  752. }
  753. if (!htmlTagMap.style) {
  754. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  755. }
  756. }
  757. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  758. var tagStack = [];
  759. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  760. var full = $0,
  761. startNewline = $1 || '',
  762. startSlash = $2 || '',
  763. tagName = $3.toLowerCase(),
  764. attr = $4 || '',
  765. endSlash = $5 ? ' ' + $5 : '',
  766. endNewline = $6 || '';
  767. if (htmlTags && !htmlTagMap[tagName]) {
  768. return '';
  769. }
  770. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  771. endSlash = ' /';
  772. }
  773. if (_INLINE_TAG_MAP[tagName]) {
  774. if (startNewline) {
  775. startNewline = ' ';
  776. }
  777. if (endNewline) {
  778. endNewline = ' ';
  779. }
  780. }
  781. if (_PRE_TAG_MAP[tagName]) {
  782. if (startSlash) {
  783. endNewline = '\n';
  784. } else {
  785. startNewline = '\n';
  786. }
  787. }
  788. if (wellFormatted && tagName == 'br') {
  789. endNewline = '\n';
  790. }
  791. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  792. if (wellFormatted) {
  793. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  794. tagStack.pop();
  795. } else {
  796. tagStack.push(tagName);
  797. }
  798. startNewline = '\n';
  799. endNewline = '\n';
  800. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  801. startNewline += indentChar;
  802. if (!startSlash) {
  803. endNewline += indentChar;
  804. }
  805. }
  806. if (endSlash) {
  807. tagStack.pop();
  808. } else if (!startSlash) {
  809. endNewline += indentChar;
  810. }
  811. } else {
  812. startNewline = endNewline = '';
  813. }
  814. }
  815. if (attr !== '') {
  816. var attrMap = _getAttrList(full);
  817. if (tagName === 'font') {
  818. var fontStyleMap = {}, fontStyle = '';
  819. _each(attrMap, function(key, val) {
  820. if (key === 'color') {
  821. fontStyleMap.color = val;
  822. delete attrMap[key];
  823. }
  824. if (key === 'size') {
  825. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  826. delete attrMap[key];
  827. }
  828. if (key === 'face') {
  829. fontStyleMap['font-family'] = val;
  830. delete attrMap[key];
  831. }
  832. if (key === 'style') {
  833. fontStyle = val;
  834. }
  835. });
  836. if (fontStyle && !/;$/.test(fontStyle)) {
  837. fontStyle += ';';
  838. }
  839. _each(fontStyleMap, function(key, val) {
  840. if (val === '') {
  841. return;
  842. }
  843. if (/\s/.test(val)) {
  844. val = "'" + val + "'";
  845. }
  846. fontStyle += key + ':' + val + ';';
  847. });
  848. attrMap.style = fontStyle;
  849. }
  850. _each(attrMap, function(key, val) {
  851. if (_FILL_ATTR_MAP[key]) {
  852. attrMap[key] = key;
  853. }
  854. if (_inArray(key, ['src', 'href']) >= 0) {
  855. attrMap[key] = _formatUrl(val, urlType);
  856. }
  857. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  858. tagName === 'body' && key === 'contenteditable' ||
  859. /^kindeditor_\d+$/.test(key)) {
  860. delete attrMap[key];
  861. }
  862. if (key === 'style' && val !== '') {
  863. var styleMap = _getCssList(val);
  864. _each(styleMap, function(k, v) {
  865. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  866. delete styleMap[k];
  867. }
  868. });
  869. var style = '';
  870. _each(styleMap, function(k, v) {
  871. style += k + ':' + v + ';';
  872. });
  873. attrMap.style = style;
  874. }
  875. });
  876. attr = '';
  877. _each(attrMap, function(key, val) {
  878. if (key === 'style' && val === '') {
  879. return;
  880. }
  881. val = val.replace(/"/g, '&quot;');
  882. attr += ' ' + key + '="' + val + '"';
  883. });
  884. }
  885. if (tagName === 'font') {
  886. tagName = 'span';
  887. }
  888. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  889. });
  890. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  891. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  892. });
  893. html = html.replace(/\n\s*\n/g, '\n');
  894. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  895. return _trim(html);
  896. }
  897. function _clearMsWord(html, htmlTags) {
  898. html = html.replace(/<meta[\s\S]*?>/ig, '')
  899. .replace(/<![\s\S]*?>/ig, '')
  900. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  901. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  902. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  903. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  904. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  905. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  906. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  907. });
  908. return _formatHtml(html, htmlTags);
  909. }
  910. function _mediaType(src) {
  911. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  912. return 'audio/x-pn-realaudio-plugin';
  913. }
  914. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  915. return 'application/x-shockwave-flash';
  916. }
  917. return 'video/x-ms-asf-plugin';
  918. }
  919. function _mediaClass(type) {
  920. if (/realaudio/i.test(type)) {
  921. return 'ke-rm';
  922. }
  923. if (/flash/i.test(type)) {
  924. return 'ke-flash';
  925. }
  926. return 'ke-media';
  927. }
  928. function _mediaAttrs(srcTag) {
  929. return _getAttrList(unescape(srcTag));
  930. }
  931. function _mediaEmbed(attrs) {
  932. var html = '<embed ';
  933. _each(attrs, function(key, val) {
  934. html += key + '="' + val + '" ';
  935. });
  936. html += '/>';
  937. return html;
  938. }
  939. function _mediaImg(blankPath, attrs) {
  940. var width = attrs.width,
  941. height = attrs.height,
  942. type = attrs.type || _mediaType(attrs.src),
  943. srcTag = _mediaEmbed(attrs),
  944. style = '';
  945. if (/\D/.test(width)) {
  946. style += 'width:' + width + ';';
  947. } else if (width > 0) {
  948. style += 'width:' + width + 'px;';
  949. }
  950. if (/\D/.test(height)) {
  951. style += 'height:' + height + ';';
  952. } else if (height > 0) {
  953. style += 'height:' + height + 'px;';
  954. }
  955. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  956. if (style !== '') {
  957. html += 'style="' + style + '" ';
  958. }
  959. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  960. return html;
  961. }
  962. function _tmpl(str, data) {
  963. var fn = new Function("obj",
  964. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  965. "with(obj){p.push('" +
  966. str.replace(/[\r\t\n]/g, " ")
  967. .split("<%").join("\t")
  968. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  969. .replace(/\t=(.*?)%>/g, "',$1,'")
  970. .split("\t").join("');")
  971. .split("%>").join("p.push('")
  972. .split("\r").join("\\'") + "');}return p.join('');");
  973. return data ? fn(data) : fn;
  974. }
  975. K.formatUrl = _formatUrl;
  976. K.formatHtml = _formatHtml;
  977. K.getCssList = _getCssList;
  978. K.getAttrList = _getAttrList;
  979. K.mediaType = _mediaType;
  980. K.mediaAttrs = _mediaAttrs;
  981. K.mediaEmbed = _mediaEmbed;
  982. K.mediaImg = _mediaImg;
  983. K.clearMsWord = _clearMsWord;
  984. K.tmpl = _tmpl;
  985. function _contains(nodeA, nodeB) {
  986. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  987. return true;
  988. }
  989. while ((nodeB = nodeB.parentNode)) {
  990. if (nodeB == nodeA) {
  991. return true;
  992. }
  993. }
  994. return false;
  995. }
  996. var _getSetAttrDiv = document.createElement('div');
  997. _getSetAttrDiv.setAttribute('className', 't');
  998. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  999. function _getAttr(el, key) {
  1000. key = key.toLowerCase();
  1001. var val = null;
  1002. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  1003. var div = el.ownerDocument.createElement('div');
  1004. div.appendChild(el.cloneNode(false));
  1005. var list = _getAttrList(_unescape(div.innerHTML));
  1006. if (key in list) {
  1007. val = list[key];
  1008. }
  1009. } else {
  1010. try {
  1011. val = el.getAttribute(key, 2);
  1012. } catch(e) {
  1013. val = el.getAttribute(key, 1);
  1014. }
  1015. }
  1016. if (key === 'style' && val !== null) {
  1017. val = _formatCss(val);
  1018. }
  1019. return val;
  1020. }
  1021. function _queryAll(expr, root) {
  1022. var exprList = expr.split(',');
  1023. if (exprList.length > 1) {
  1024. var mergedResults = [];
  1025. _each(exprList, function() {
  1026. _each(_queryAll(this, root), function() {
  1027. if (_inArray(this, mergedResults) < 0) {
  1028. mergedResults.push(this);
  1029. }
  1030. });
  1031. });
  1032. return mergedResults;
  1033. }
  1034. root = root || document;
  1035. function escape(str) {
  1036. if (typeof str != 'string') {
  1037. return str;
  1038. }
  1039. return str.replace(/([^\w\-])/g, '\\$1');
  1040. }
  1041. function stripslashes(str) {
  1042. return str.replace(/\\/g, '');
  1043. }
  1044. function cmpTag(tagA, tagB) {
  1045. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1046. }
  1047. function byId(id, tag, root) {
  1048. var arr = [],
  1049. doc = root.ownerDocument || root,
  1050. el = doc.getElementById(stripslashes(id));
  1051. if (el) {
  1052. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1053. arr.push(el);
  1054. }
  1055. }
  1056. return arr;
  1057. }
  1058. function byClass(className, tag, root) {
  1059. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1060. if (root.getElementsByClassName) {
  1061. els = root.getElementsByClassName(stripslashes(className));
  1062. for (i = 0, len = els.length; i < len; i++) {
  1063. el = els[i];
  1064. if (cmpTag(tag, el.nodeName)) {
  1065. arr.push(el);
  1066. }
  1067. }
  1068. } else if (doc.querySelectorAll) {
  1069. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1070. for (i = 0, len = els.length; i < len; i++) {
  1071. el = els[i];
  1072. if (_contains(root, el)) {
  1073. arr.push(el);
  1074. }
  1075. }
  1076. } else {
  1077. els = root.getElementsByTagName(tag);
  1078. className = ' ' + className + ' ';
  1079. for (i = 0, len = els.length; i < len; i++) {
  1080. el = els[i];
  1081. if (el.nodeType == 1) {
  1082. var cls = el.className;
  1083. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1084. arr.push(el);
  1085. }
  1086. }
  1087. }
  1088. }
  1089. return arr;
  1090. }
  1091. function byName(name, tag, root) {
  1092. var arr = [], doc = root.ownerDocument || root,
  1093. els = doc.getElementsByName(stripslashes(name)), el;
  1094. for (var i = 0, len = els.length; i < len; i++) {
  1095. el = els[i];
  1096. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1097. if (el.getAttribute('name') !== null) {
  1098. arr.push(el);
  1099. }
  1100. }
  1101. }
  1102. return arr;
  1103. }
  1104. function byAttr(key, val, tag, root) {
  1105. var arr = [], els = root.getElementsByTagName(tag), el;
  1106. for (var i = 0, len = els.length; i < len; i++) {
  1107. el = els[i];
  1108. if (el.nodeType == 1) {
  1109. if (val === null) {
  1110. if (_getAttr(el, key) !== null) {
  1111. arr.push(el);
  1112. }
  1113. } else {
  1114. if (val === escape(_getAttr(el, key))) {
  1115. arr.push(el);
  1116. }
  1117. }
  1118. }
  1119. }
  1120. return arr;
  1121. }
  1122. function select(expr, root) {
  1123. var arr = [], matches;
  1124. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1125. var tag = matches ? matches[1] : '*';
  1126. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1127. arr = byId(matches[1], tag, root);
  1128. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1129. arr = byClass(matches[1], tag, root);
  1130. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1131. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1132. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1133. var key = matches[1].toLowerCase(), val = matches[2];
  1134. if (key === 'id') {
  1135. arr = byId(val, tag, root);
  1136. } else if (key === 'class') {
  1137. arr = byClass(val, tag, root);
  1138. } else if (key === 'name') {
  1139. arr = byName(val, tag, root);
  1140. } else {
  1141. arr = byAttr(key, val, tag, root);
  1142. }
  1143. } else {
  1144. var els = root.getElementsByTagName(tag), el;
  1145. for (var i = 0, len = els.length; i < len; i++) {
  1146. el = els[i];
  1147. if (el.nodeType == 1) {
  1148. arr.push(el);
  1149. }
  1150. }
  1151. }
  1152. return arr;
  1153. }
  1154. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1155. while ((arr = re.exec(expr))) {
  1156. if (arr[1] !== ' ') {
  1157. parts.push(arr[1]);
  1158. }
  1159. }
  1160. var results = [];
  1161. if (parts.length == 1) {
  1162. return select(parts[0], root);
  1163. }
  1164. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1165. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1166. part = parts[i];
  1167. if (part === '>') {
  1168. isChild = true;
  1169. continue;
  1170. }
  1171. if (i > 0) {
  1172. els = [];
  1173. for (j = 0, len = results.length; j < len; j++) {
  1174. val = results[j];
  1175. subResults = select(part, val);
  1176. for (k = 0, l = subResults.length; k < l; k++) {
  1177. v = subResults[k];
  1178. if (isChild) {
  1179. if (val === v.parentNode) {
  1180. els.push(v);
  1181. }
  1182. } else {
  1183. els.push(v);
  1184. }
  1185. }
  1186. }
  1187. results = els;
  1188. } else {
  1189. results = select(part, root);
  1190. }
  1191. if (results.length === 0) {
  1192. return [];
  1193. }
  1194. }
  1195. return results;
  1196. }
  1197. function _query(expr, root) {
  1198. var arr = _queryAll(expr, root);
  1199. return arr.length > 0 ? arr[0] : null;
  1200. }
  1201. K.query = _query;
  1202. K.queryAll = _queryAll;
  1203. function _get(val) {
  1204. return K(val)[0];
  1205. }
  1206. function _getDoc(node) {
  1207. if (!node) {
  1208. return document;
  1209. }
  1210. return node.ownerDocument || node.document || node;
  1211. }
  1212. function _getWin(node) {
  1213. if (!node) {
  1214. return window;
  1215. }
  1216. var doc = _getDoc(node);
  1217. return doc.parentWindow || doc.defaultView;
  1218. }
  1219. function _setHtml(el, html) {
  1220. if (el.nodeType != 1) {
  1221. return;
  1222. }
  1223. var doc = _getDoc(el);
  1224. try {
  1225. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1226. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1227. temp.parentNode.removeChild(temp);
  1228. } catch(e) {
  1229. K(el).empty();
  1230. K('@' + html, doc).each(function() {
  1231. el.appendChild(this);
  1232. });
  1233. }
  1234. }
  1235. function _hasClass(el, cls) {
  1236. return _inString(cls, el.className, ' ');
  1237. }
  1238. function _setAttr(el, key, val) {
  1239. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1240. key = 'className';
  1241. }
  1242. el.setAttribute(key, '' + val);
  1243. }
  1244. function _removeAttr(el, key) {
  1245. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1246. key = 'className';
  1247. }
  1248. _setAttr(el, key, '');
  1249. el.removeAttribute(key);
  1250. }
  1251. function _getNodeName(node) {
  1252. if (!node || !node.nodeName) {
  1253. return '';
  1254. }
  1255. return node.nodeName.toLowerCase();
  1256. }
  1257. function _computedCss(el, key) {
  1258. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1259. if (win.getComputedStyle) {
  1260. var style = win.getComputedStyle(el, null);
  1261. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1262. } else if (el.currentStyle) {
  1263. val = el.currentStyle[camelKey] || el.style[camelKey];
  1264. }
  1265. return val;
  1266. }
  1267. function _hasVal(node) {
  1268. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1269. }
  1270. function _docElement(doc) {
  1271. doc = doc || document;
  1272. return _QUIRKS ? doc.body : doc.documentElement;
  1273. }
  1274. function _docHeight(doc) {
  1275. var el = _docElement(doc);
  1276. return Math.max(el.scrollHeight, el.clientHeight);
  1277. }
  1278. function _docWidth(doc) {
  1279. var el = _docElement(doc);
  1280. return Math.max(el.scrollWidth, el.clientWidth);
  1281. }
  1282. function _getScrollPos(doc) {
  1283. doc = doc || document;
  1284. var x, y;
  1285. if (_IE || _NEWIE || _OPERA) {
  1286. x = _docElement(doc).scrollLeft;
  1287. y = _docElement(doc).scrollTop;
  1288. } else {
  1289. x = _getWin(doc).scrollX;
  1290. y = _getWin(doc).scrollY;
  1291. }
  1292. return {x : x, y : y};
  1293. }
  1294. function KNode(node) {
  1295. this.init(node);
  1296. }
  1297. _extend(KNode, {
  1298. init : function(node) {
  1299. var self = this;
  1300. node = _isArray(node) ? node : [node];
  1301. var length = 0;
  1302. for (var i = 0, len = node.length; i < len; i++) {
  1303. if (node[i]) {
  1304. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1305. length++;
  1306. }
  1307. }
  1308. self.length = length;
  1309. self.doc = _getDoc(self[0]);
  1310. self.name = _getNodeName(self[0]);
  1311. self.type = self.length > 0 ? self[0].nodeType : null;
  1312. self.win = _getWin(self[0]);
  1313. },
  1314. each : function(fn) {
  1315. var self = this;
  1316. for (var i = 0; i < self.length; i++) {
  1317. if (fn.call(self[i], i, self[i]) === false) {
  1318. return self;
  1319. }
  1320. }
  1321. return self;
  1322. },
  1323. bind : function(type, fn) {
  1324. this.each(function() {
  1325. _bind(this, type, fn);
  1326. });
  1327. return this;
  1328. },
  1329. unbind : function(type, fn) {
  1330. this.each(function() {
  1331. _unbind(this, type, fn);
  1332. });
  1333. return this;
  1334. },
  1335. fire : function(type) {
  1336. if (this.length < 1) {
  1337. return this;
  1338. }
  1339. _fire(this[0], type);
  1340. return this;
  1341. },
  1342. hasAttr : function(key) {
  1343. if (this.length < 1) {
  1344. return false;
  1345. }
  1346. return !!_getAttr(this[0], key);
  1347. },
  1348. attr : function(key, val) {
  1349. var self = this;
  1350. if (key === undefined) {
  1351. return _getAttrList(self.outer());
  1352. }
  1353. if (typeof key === 'object') {
  1354. _each(key, function(k, v) {
  1355. self.attr(k, v);
  1356. });
  1357. return self;
  1358. }
  1359. if (val === undefined) {
  1360. val = self.length < 1 ? null : _getAttr(self[0], key);
  1361. return val === null ? '' : val;
  1362. }
  1363. self.each(function() {
  1364. _setAttr(this, key, val);
  1365. });
  1366. return self;
  1367. },
  1368. removeAttr : function(key) {
  1369. this.each(function() {
  1370. _removeAttr(this, key);
  1371. });
  1372. return this;
  1373. },
  1374. get : function(i) {
  1375. if (this.length < 1) {
  1376. return null;
  1377. }
  1378. return this[i || 0];
  1379. },
  1380. eq : function(i) {
  1381. if (this.length < 1) {
  1382. return null;
  1383. }
  1384. return this[i] ? new KNode(this[i]) : null;
  1385. },
  1386. hasClass : function(cls) {
  1387. if (this.length < 1) {
  1388. return false;
  1389. }
  1390. return _hasClass(this[0], cls);
  1391. },
  1392. addClass : function(cls) {
  1393. this.each(function() {
  1394. if (!_hasClass(this, cls)) {
  1395. this.className = _trim(this.className + ' ' + cls);
  1396. }
  1397. });
  1398. return this;
  1399. },
  1400. removeClass : function(cls) {
  1401. this.each(function() {
  1402. if (_hasClass(this, cls)) {
  1403. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1404. }
  1405. });
  1406. return this;
  1407. },
  1408. html : function(val) {
  1409. var self = this;
  1410. if (val === undefined) {
  1411. if (self.length < 1 || self.type != 1) {
  1412. return '';
  1413. }
  1414. return _formatHtml(self[0].innerHTML);
  1415. }
  1416. self.each(function() {
  1417. _setHtml(this, val);
  1418. });
  1419. return self;
  1420. },
  1421. text : function() {
  1422. var self = this;
  1423. if (self.length < 1) {
  1424. return '';
  1425. }
  1426. return _IE ? self[0].innerText : self[0].textContent;
  1427. },
  1428. hasVal : function() {
  1429. if (this.length < 1) {
  1430. return false;
  1431. }
  1432. return _hasVal(this[0]);
  1433. },
  1434. val : function(val) {
  1435. var self = this;
  1436. if (val === undefined) {
  1437. if (self.length < 1) {
  1438. return '';
  1439. }
  1440. return self.hasVal() ? self[0].value : self.attr('value');
  1441. } else {
  1442. self.each(function() {
  1443. if (_hasVal(this)) {
  1444. this.value = val;
  1445. } else {
  1446. _setAttr(this, 'value' , val);
  1447. }
  1448. });
  1449. return self;
  1450. }
  1451. },
  1452. css : function(key, val) {
  1453. var self = this;
  1454. if (key === undefined) {
  1455. return _getCssList(self.attr('style'));
  1456. }
  1457. if (typeof key === 'object') {
  1458. _each(key, function(k, v) {
  1459. self.css(k, v);
  1460. });
  1461. return self;
  1462. }
  1463. if (val === undefined) {
  1464. if (self.length < 1) {
  1465. return '';
  1466. }
  1467. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1468. }
  1469. self.each(function() {
  1470. this.style[_toCamel(key)] = val;
  1471. });
  1472. return self;
  1473. },
  1474. width : function(val) {
  1475. var self = this;
  1476. if (val === undefined) {
  1477. if (self.length < 1) {
  1478. return 0;
  1479. }
  1480. return self[0].offsetWidth;
  1481. }
  1482. return self.css('width', _addUnit(val));
  1483. },
  1484. height : function(val) {
  1485. var self = this;
  1486. if (val === undefined) {
  1487. if (self.length < 1) {
  1488. return 0;
  1489. }
  1490. return self[0].offsetHeight;
  1491. }
  1492. return self.css('height', _addUnit(val));
  1493. },
  1494. opacity : function(val) {
  1495. this.each(function() {
  1496. if (this.style.opacity === undefined) {
  1497. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1498. } else {
  1499. this.style.opacity = val == 1 ? '' : val;
  1500. }
  1501. });
  1502. return this;
  1503. },
  1504. data : function(key, val) {
  1505. var self = this;
  1506. key = 'kindeditor_data_' + key;
  1507. if (val === undefined) {
  1508. if (self.length < 1) {
  1509. return null;
  1510. }
  1511. return self[0][key];
  1512. }
  1513. this.each(function() {
  1514. this[key] = val;
  1515. });
  1516. return self;
  1517. },
  1518. pos : function() {
  1519. var self = this, node = self[0], x = 0, y = 0;
  1520. if (node) {
  1521. if (node.getBoundingClientRect) {
  1522. var box = node.getBoundingClientRect(),
  1523. pos = _getScrollPos(self.doc);
  1524. x = box.left + pos.x;
  1525. y = box.top + pos.y;
  1526. } else {
  1527. while (node) {
  1528. x += node.offsetLeft;
  1529. y += node.offsetTop;
  1530. node = node.offsetParent;
  1531. }
  1532. }
  1533. }
  1534. return {x : _round(x), y : _round(y)};
  1535. },
  1536. clone : function(bool) {
  1537. if (this.length < 1) {
  1538. return new KNode([]);
  1539. }
  1540. return new KNode(this[0].cloneNode(bool));
  1541. },
  1542. append : function(expr) {
  1543. this.each(function() {
  1544. if (this.appendChild) {
  1545. this.appendChild(_get(expr));
  1546. }
  1547. });
  1548. return this;
  1549. },
  1550. appendTo : function(expr) {
  1551. this.each(function() {
  1552. _get(expr).appendChild(this);
  1553. });
  1554. return this;
  1555. },
  1556. before : function(expr) {
  1557. this.each(function() {
  1558. this.parentNode.insertBefore(_get(expr), this);
  1559. });
  1560. return this;
  1561. },
  1562. after : function(expr) {
  1563. this.each(function() {
  1564. if (this.nextSibling) {
  1565. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1566. } else {
  1567. this.parentNode.appendChild(_get(expr));
  1568. }
  1569. });
  1570. return this;
  1571. },
  1572. replaceWith : function(expr) {
  1573. var nodes = [];
  1574. this.each(function(i, node) {
  1575. _unbind(node);
  1576. var newNode = _get(expr);
  1577. node.parentNode.replaceChild(newNode, node);
  1578. nodes.push(newNode);
  1579. });
  1580. return K(nodes);
  1581. },
  1582. empty : function() {
  1583. var self = this;
  1584. self.each(function(i, node) {
  1585. var child = node.firstChild;
  1586. while (child) {
  1587. if (!node.parentNode) {
  1588. return;
  1589. }
  1590. var next = child.nextSibling;
  1591. child.parentNode.removeChild(child);
  1592. child = next;
  1593. }
  1594. });
  1595. return self;
  1596. },
  1597. remove : function(keepChilds) {
  1598. var self = this;
  1599. self.each(function(i, node) {
  1600. if (!node.parentNode) {
  1601. return;
  1602. }
  1603. _unbind(node);
  1604. if (keepChilds) {
  1605. var child = node.firstChild;
  1606. while (child) {
  1607. var next = child.nextSibling;
  1608. node.parentNode.insertBefore(child, node);
  1609. child = next;
  1610. }
  1611. }
  1612. node.parentNode.removeChild(node);
  1613. delete self[i];
  1614. });
  1615. self.length = 0;
  1616. return self;
  1617. },
  1618. show : function(val) {
  1619. var self = this;
  1620. if (val === undefined) {
  1621. val = self._originDisplay || '';
  1622. }
  1623. if (self.css('display') != 'none') {
  1624. return self;
  1625. }
  1626. return self.css('display', val);
  1627. },
  1628. hide : function() {
  1629. var self = this;
  1630. if (self.length < 1) {
  1631. return self;
  1632. }
  1633. self._originDisplay = self[0].style.display;
  1634. return self.css('display', 'none');
  1635. },
  1636. outer : function() {
  1637. var self = this;
  1638. if (self.length < 1) {
  1639. return '';
  1640. }
  1641. var div = self.doc.createElement('div'), html;
  1642. div.appendChild(self[0].cloneNode(true));
  1643. html = _formatHtml(div.innerHTML);
  1644. div = null;
  1645. return html;
  1646. },
  1647. isSingle : function() {
  1648. return !!_SINGLE_TAG_MAP[this.name];
  1649. },
  1650. isInline : function() {
  1651. return !!_INLINE_TAG_MAP[this.name];
  1652. },
  1653. isBlock : function() {
  1654. return !!_BLOCK_TAG_MAP[this.name];
  1655. },
  1656. isStyle : function() {
  1657. return !!_STYLE_TAG_MAP[this.name];
  1658. },
  1659. isControl : function() {
  1660. return !!_CONTROL_TAG_MAP[this.name];
  1661. },
  1662. contains : function(otherNode) {
  1663. if (this.length < 1) {
  1664. return false;
  1665. }
  1666. return _contains(this[0], _get(otherNode));
  1667. },
  1668. parent : function() {
  1669. if (this.length < 1) {
  1670. return null;
  1671. }
  1672. var node = this[0].parentNode;
  1673. return node ? new KNode(node) : null;
  1674. },
  1675. children : function() {
  1676. if (this.length < 1) {
  1677. return new KNode([]);
  1678. }
  1679. var list = [], child = this[0].firstChild;
  1680. while (child) {
  1681. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1682. list.push(child);
  1683. }
  1684. child = child.nextSibling;
  1685. }
  1686. return new KNode(list);
  1687. },
  1688. first : function() {
  1689. var list = this.children();
  1690. return list.length > 0 ? list.eq(0) : null;
  1691. },
  1692. last : function() {
  1693. var list = this.children();
  1694. return list.length > 0 ? list.eq(list.length - 1) : null;
  1695. },
  1696. index : function() {
  1697. if (this.length < 1) {
  1698. return -1;
  1699. }
  1700. var i = -1, sibling = this[0];
  1701. while (sibling) {
  1702. i++;
  1703. sibling = sibling.previousSibling;
  1704. }
  1705. return i;
  1706. },
  1707. prev : function() {
  1708. if (this.length < 1) {
  1709. return null;
  1710. }
  1711. var node = this[0].previousSibling;
  1712. return node ? new KNode(node) : null;
  1713. },
  1714. next : function() {
  1715. if (this.length < 1) {
  1716. return null;
  1717. }
  1718. var node = this[0].nextSibling;
  1719. return node ? new KNode(node) : null;
  1720. },
  1721. scan : function(fn, order) {
  1722. if (this.length < 1) {
  1723. return;
  1724. }
  1725. order = (order === undefined) ? true : order;
  1726. function walk(node) {
  1727. var n = order ? node.firstChild : node.lastChild;
  1728. while (n) {
  1729. var next = order ? n.nextSibling : n.previousSibling;
  1730. if (fn(n) === false) {
  1731. return false;
  1732. }
  1733. if (walk(n) === false) {
  1734. return false;
  1735. }
  1736. n = next;
  1737. }
  1738. }
  1739. walk(this[0]);
  1740. return this;
  1741. }
  1742. });
  1743. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1744. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1745. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1746. KNode.prototype[type] = function(fn) {
  1747. return fn ? this.bind(type, fn) : this.fire(type);
  1748. };
  1749. });
  1750. var _K = K;
  1751. K = function(expr, root) {
  1752. if (expr === undefined || expr === null) {
  1753. return;
  1754. }
  1755. function newNode(node) {
  1756. if (!node[0]) {
  1757. node = [];
  1758. }
  1759. return new KNode(node);
  1760. }
  1761. if (typeof expr === 'string') {
  1762. if (root) {
  1763. root = _get(root);
  1764. }
  1765. var length = expr.length;
  1766. if (expr.charAt(0) === '@') {
  1767. expr = expr.substr(1);
  1768. }
  1769. if (expr.length !== length || /<.+>/.test(expr)) {
  1770. var doc = root ? root.ownerDocument || root : document,
  1771. div = doc.createElement('div'), list = [];
  1772. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1773. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1774. var child = div.childNodes[i];
  1775. if (child.id == '__kindeditor_temp_tag__') {
  1776. continue;
  1777. }
  1778. list.push(child);
  1779. }
  1780. return newNode(list);
  1781. }
  1782. return newNode(_queryAll(expr, root));
  1783. }
  1784. if (expr && expr.constructor === KNode) {
  1785. return expr;
  1786. }
  1787. if (expr.toArray) {
  1788. expr = expr.toArray();
  1789. }
  1790. if (_isArray(expr)) {
  1791. return newNode(expr);
  1792. }
  1793. return newNode(_toArray(arguments));
  1794. };
  1795. _each(_K, function(key, val) {
  1796. K[key] = val;
  1797. });
  1798. K.NodeClass = KNode;
  1799. window.KindEditor = K;
  1800. var _START_TO_START = 0,
  1801. _START_TO_END = 1,
  1802. _END_TO_END = 2,
  1803. _END_TO_START = 3,
  1804. _BOOKMARK_ID = 0;
  1805. function _updateCollapsed(range) {
  1806. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1807. return range;
  1808. }
  1809. function _copyAndDelete(range, isCopy, isDelete) {
  1810. var doc = range.doc, nodeList = [];
  1811. function splitTextNode(node, startOffset, endOffset) {
  1812. var length = node.nodeValue.length, centerNode;
  1813. if (isCopy) {
  1814. var cloneNode = node.cloneNode(true);
  1815. if (startOffset > 0) {
  1816. centerNode = cloneNode.splitText(startOffset);
  1817. } else {
  1818. centerNode = cloneNode;
  1819. }
  1820. if (endOffset < length) {
  1821. centerNode.splitText(endOffset - startOffset);
  1822. }
  1823. }
  1824. if (isDelete) {
  1825. var center = node;
  1826. if (startOffset > 0) {
  1827. center = node.splitText(startOffset);
  1828. range.setStart(node, startOffset);
  1829. }
  1830. if (endOffset < length) {
  1831. var right = center.splitText(endOffset - startOffset);
  1832. range.setEnd(right, 0);
  1833. }
  1834. nodeList.push(center);
  1835. }
  1836. return centerNode;
  1837. }
  1838. function removeNodes() {
  1839. if (isDelete) {
  1840. range.up().collapse(true);
  1841. }
  1842. for (var i = 0, len = nodeList.length; i < len; i++) {
  1843. var node = nodeList[i];
  1844. if (node.parentNode) {
  1845. node.parentNode.removeChild(node);
  1846. }
  1847. }
  1848. }
  1849. var copyRange = range.cloneRange().down();
  1850. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1851. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1852. if (ancestor.nodeType == 3) {
  1853. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1854. if (isCopy) {
  1855. frag.appendChild(textNode);
  1856. }
  1857. removeNodes();
  1858. return isCopy ? frag : range;
  1859. }
  1860. function extractNodes(parent, frag) {
  1861. var node = parent.firstChild, nextNode;
  1862. while (node) {
  1863. var testRange = new KRange(doc).selectNode(node);
  1864. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1865. if (start >= 0 && incStart <= 0) {
  1866. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1867. }
  1868. if (incStart >= 0 && incEnd <= 0) {
  1869. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1870. }
  1871. if (incEnd >= 0 && end <= 0) {
  1872. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1873. }
  1874. if (end >= 0) {
  1875. return false;
  1876. }
  1877. nextNode = node.nextSibling;
  1878. if (start > 0) {
  1879. if (node.nodeType == 1) {
  1880. if (incStart >= 0 && incEnd <= 0) {
  1881. if (isCopy) {
  1882. frag.appendChild(node.cloneNode(true));
  1883. }
  1884. if (isDelete) {
  1885. nodeList.push(node);
  1886. }
  1887. } else {
  1888. var childFlag;
  1889. if (isCopy) {
  1890. childFlag = node.cloneNode(false);
  1891. frag.appendChild(childFlag);
  1892. }
  1893. if (extractNodes(node, childFlag) === false) {
  1894. return false;
  1895. }
  1896. }
  1897. } else if (node.nodeType == 3) {
  1898. var textNode;
  1899. if (node == copyRange.startContainer) {
  1900. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1901. } else if (node == copyRange.endContainer) {
  1902. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1903. } else {
  1904. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1905. }
  1906. if (isCopy) {
  1907. try {
  1908. frag.appendChild(textNode);
  1909. } catch(e) {}
  1910. }
  1911. }
  1912. }
  1913. node = nextNode;
  1914. }
  1915. }
  1916. extractNodes(ancestor, frag);
  1917. if (isDelete) {
  1918. range.up().collapse(true);
  1919. }
  1920. for (var i = 0, len = nodeList.length; i < len; i++) {
  1921. var node = nodeList[i];
  1922. if (node.parentNode) {
  1923. node.parentNode.removeChild(node);
  1924. }
  1925. }
  1926. return isCopy ? frag : range;
  1927. }
  1928. function _moveToElementText(range, el) {
  1929. var node = el;
  1930. while (node) {
  1931. var knode = K(node);
  1932. if (knode.name == 'marquee' || knode.name == 'select') {
  1933. return;
  1934. }
  1935. node = node.parentNode;
  1936. }
  1937. try {
  1938. range.moveToElementText(el);
  1939. } catch(e) {}
  1940. }
  1941. function _getStartEnd(rng, isStart) {
  1942. var doc = rng.parentElement().ownerDocument,
  1943. pointRange = rng.duplicate();
  1944. pointRange.collapse(isStart);
  1945. var parent = pointRange.parentElement(),
  1946. nodes = parent.childNodes;
  1947. if (nodes.length === 0) {
  1948. return {node: parent.parentNode, offset: K(parent).index()};
  1949. }
  1950. var startNode = doc, startPos = 0, cmp = -1;
  1951. var testRange = rng.duplicate();
  1952. _moveToElementText(testRange, parent);
  1953. for (var i = 0, len = nodes.length; i < len; i++) {
  1954. var node = nodes[i];
  1955. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1956. if (cmp === 0) {
  1957. return {node: node.parentNode, offset: i};
  1958. }
  1959. if (node.nodeType == 1) {
  1960. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1961. if (knode.isControl()) {
  1962. dummy = doc.createElement('span');
  1963. knode.after(dummy);
  1964. newNode = dummy;
  1965. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1966. }
  1967. _moveToElementText(nodeRange, newNode);
  1968. testRange.setEndPoint('StartToEnd', nodeRange);
  1969. if (cmp > 0) {
  1970. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1971. } else {
  1972. startPos = 0;
  1973. }
  1974. if (dummy) {
  1975. K(dummy).remove();
  1976. }
  1977. } else if (node.nodeType == 3) {
  1978. testRange.moveStart('character', node.nodeValue.length);
  1979. startPos += node.nodeValue.length;
  1980. }
  1981. if (cmp < 0) {
  1982. startNode = node;
  1983. }
  1984. }
  1985. if (cmp < 0 && startNode.nodeType == 1) {
  1986. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1987. }
  1988. if (cmp > 0) {
  1989. while (startNode.nextSibling && startNode.nodeType == 1) {
  1990. startNode = startNode.nextSibling;
  1991. }
  1992. }
  1993. testRange = rng.duplicate();
  1994. _moveToElementText(testRange, parent);
  1995. testRange.setEndPoint('StartToEnd', pointRange);
  1996. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  1997. if (cmp > 0 && startNode.nodeType == 3) {
  1998. var prevNode = startNode.previousSibling;
  1999. while (prevNode && prevNode.nodeType == 3) {
  2000. startPos -= prevNode.nodeValue.length;
  2001. prevNode = prevNode.previousSibling;
  2002. }
  2003. }
  2004. return {node: startNode, offset: startPos};
  2005. }
  2006. function _getEndRange(node, offset) {
  2007. var doc = node.ownerDocument || node,
  2008. range = doc.body.createTextRange();
  2009. if (doc == node) {
  2010. range.collapse(true);
  2011. return range;
  2012. }
  2013. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2014. var children = node.childNodes, isStart, child;
  2015. if (offset === 0) {
  2016. child = children[0];
  2017. isStart = true;
  2018. } else {
  2019. child = children[offset - 1];
  2020. isStart = false;
  2021. }
  2022. if (!child) {
  2023. return range;
  2024. }
  2025. if (K(child).name === 'head') {
  2026. if (offset === 1) {
  2027. isStart = true;
  2028. }
  2029. if (offset === 2) {
  2030. isStart = false;
  2031. }
  2032. range.collapse(isStart);
  2033. return range;
  2034. }
  2035. if (child.nodeType == 1) {
  2036. var kchild = K(child), span;
  2037. if (kchild.isControl()) {
  2038. span = doc.createElement('span');
  2039. if (isStart) {
  2040. kchild.before(span);
  2041. } else {
  2042. kchild.after(span);
  2043. }
  2044. child = span;
  2045. }
  2046. _moveToElementText(range, child);
  2047. range.collapse(isStart);
  2048. if (span) {
  2049. K(span).remove();
  2050. }
  2051. return range;
  2052. }
  2053. node = child;
  2054. offset = isStart ? 0 : child.nodeValue.length;
  2055. }
  2056. var dummy = doc.createElement('span');
  2057. K(node).before(dummy);
  2058. _moveToElementText(range, dummy);
  2059. range.moveStart('character', offset);
  2060. K(dummy).remove();
  2061. return range;
  2062. }
  2063. function _toRange(rng) {
  2064. var doc, range;
  2065. function tr2td(start) {
  2066. if (K(start.node).name == 'tr') {
  2067. start.node = start.node.cells[start.offset];
  2068. start.offset = 0;
  2069. }
  2070. }
  2071. if (_IERANGE) {
  2072. if (rng.item) {
  2073. doc = _getDoc(rng.item(0));
  2074. range = new KRange(doc);
  2075. range.selectNode(rng.item(0));
  2076. return range;
  2077. }
  2078. doc = rng.parentElement().ownerDocument;
  2079. var start = _getStartEnd(rng, true),
  2080. end = _getStartEnd(rng, false);
  2081. tr2td(start);
  2082. tr2td(end);
  2083. range = new KRange(doc);
  2084. range.setStart(start.node, start.offset);
  2085. range.setEnd(end.node, end.offset);
  2086. return range;
  2087. }
  2088. var startContainer = rng.startContainer;
  2089. doc = startContainer.ownerDocument || startContainer;
  2090. range = new KRange(doc);
  2091. range.setStart(startContainer, rng.startOffset);
  2092. range.setEnd(rng.endContainer, rng.endOffset);
  2093. return range;
  2094. }
  2095. function KRange(doc) {
  2096. this.init(doc);
  2097. }
  2098. _extend(KRange, {
  2099. init : function(doc) {
  2100. var self = this;
  2101. self.startContainer = doc;
  2102. self.startOffset = 0;
  2103. self.endContainer = doc;
  2104. self.endOffset = 0;
  2105. self.collapsed = true;
  2106. self.doc = doc;
  2107. },
  2108. commonAncestor : function() {
  2109. function getParents(node) {
  2110. var parents = [];
  2111. while (node) {
  2112. parents.push(node);
  2113. node = node.parentNode;
  2114. }
  2115. return parents;
  2116. }
  2117. var parentsA = getParents(this.startContainer),
  2118. parentsB = getParents(this.endContainer),
  2119. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2120. while (++i) {
  2121. parentA = parentsA[lenA - i];
  2122. parentB = parentsB[lenB - i];
  2123. if (!parentA || !parentB || parentA !== parentB) {
  2124. break;
  2125. }
  2126. }
  2127. return parentsA[lenA - i + 1];
  2128. },
  2129. setStart : function(node, offset) {
  2130. var self = this, doc = self.doc;
  2131. self.startContainer = node;
  2132. self.startOffset = offset;
  2133. if (self.endContainer === doc) {
  2134. self.endContainer = node;
  2135. self.endOffset = offset;
  2136. }
  2137. return _updateCollapsed(this);
  2138. },
  2139. setEnd : function(node, offset) {
  2140. var self = this, doc = self.doc;
  2141. self.endContainer = node;
  2142. self.endOffset = offset;
  2143. if (self.startContainer === doc) {
  2144. self.startContainer = node;
  2145. self.startOffset = offset;
  2146. }
  2147. return _updateCollapsed(this);
  2148. },
  2149. setStartBefore : function(node) {
  2150. return this.setStart(node.parentNode || this.doc, K(node).index());
  2151. },
  2152. setStartAfter : function(node) {
  2153. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2154. },
  2155. setEndBefore : function(node) {
  2156. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2157. },
  2158. setEndAfter : function(node) {
  2159. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2160. },
  2161. selectNode : function(node) {
  2162. return this.setStartBefore(node).setEndAfter(node);
  2163. },
  2164. selectNodeContents : function(node) {
  2165. var knode = K(node);
  2166. if (knode.type == 3 || knode.isSingle()) {
  2167. return this.selectNode(node);
  2168. }
  2169. var children = knode.children();
  2170. if (children.length > 0) {
  2171. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2172. }
  2173. return this.setStart(node, 0).setEnd(node, 0);
  2174. },
  2175. collapse : function(toStart) {
  2176. if (toStart) {
  2177. return this.setEnd(this.startContainer, this.startOffset);
  2178. }
  2179. return this.setStart(this.endContainer, this.endOffset);
  2180. },
  2181. compareBoundaryPoints : function(how, range) {
  2182. var rangeA = this.get(), rangeB = range.get();
  2183. if (_IERANGE) {
  2184. var arr = {};
  2185. arr[_START_TO_START] = 'StartToStart';
  2186. arr[_START_TO_END] = 'EndToStart';
  2187. arr[_END_TO_END] = 'EndToEnd';
  2188. arr[_END_TO_START] = 'StartToEnd';
  2189. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2190. if (cmp !== 0) {
  2191. return cmp;
  2192. }
  2193. var nodeA, nodeB, nodeC, posA, posB;
  2194. if (how === _START_TO_START || how === _END_TO_START) {
  2195. nodeA = this.startContainer;
  2196. posA = this.startOffset;
  2197. }
  2198. if (how === _START_TO_END || how === _END_TO_END) {
  2199. nodeA = this.endContainer;
  2200. posA = this.endOffset;
  2201. }
  2202. if (how === _START_TO_START || how === _START_TO_END) {
  2203. nodeB = range.startContainer;
  2204. posB = range.startOffset;
  2205. }
  2206. if (how === _END_TO_END || how === _END_TO_START) {
  2207. nodeB = range.endContainer;
  2208. posB = range.endOffset;
  2209. }
  2210. if (nodeA === nodeB) {
  2211. var diff = posA - posB;
  2212. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2213. }
  2214. nodeC = nodeB;
  2215. while (nodeC && nodeC.parentNode !== nodeA) {
  2216. nodeC = nodeC.parentNode;
  2217. }
  2218. if (nodeC) {
  2219. return K(nodeC).index() >= posA ? -1 : 1;
  2220. }
  2221. nodeC = nodeA;
  2222. while (nodeC && nodeC.parentNode !== nodeB) {
  2223. nodeC = nodeC.parentNode;
  2224. }
  2225. if (nodeC) {
  2226. return K(nodeC).index() >= posB ? 1 : -1;
  2227. }
  2228. nodeC = K(nodeB).next();
  2229. if (nodeC && nodeC.contains(nodeA)) {
  2230. return 1;
  2231. }
  2232. nodeC = K(nodeA).next();
  2233. if (nodeC && nodeC.contains(nodeB)) {
  2234. return -1;
  2235. }
  2236. } else {
  2237. return rangeA.compareBoundaryPoints(how, rangeB);
  2238. }
  2239. },
  2240. cloneRange : function() {
  2241. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2242. },
  2243. toString : function() {
  2244. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2245. return str.replace(/\r\n|\n|\r/g, '');
  2246. },
  2247. cloneContents : function() {
  2248. return _copyAndDelete(this, true, false);
  2249. },
  2250. deleteContents : function() {
  2251. return _copyAndDelete(this, false, true);
  2252. },
  2253. extractContents : function() {
  2254. return _copyAndDelete(this, true, true);
  2255. },
  2256. insertNode : function(node) {
  2257. var self = this,
  2258. sc = self.startContainer, so = self.startOffset,
  2259. ec = self.endContainer, eo = self.endOffset,
  2260. firstChild, lastChild, c, nodeCount = 1;
  2261. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2262. firstChild = node.firstChild;
  2263. lastChild = node.lastChild;
  2264. nodeCount = node.childNodes.length;
  2265. }
  2266. if (sc.nodeType == 1) {
  2267. c = sc.childNodes[so];
  2268. if (c) {
  2269. sc.insertBefore(node, c);
  2270. if (sc === ec) {
  2271. eo += nodeCount;
  2272. }
  2273. } else {
  2274. sc.appendChild(node);
  2275. }
  2276. } else if (sc.nodeType == 3) {
  2277. if (so === 0) {
  2278. sc.parentNode.insertBefore(node, sc);
  2279. if (sc.parentNode === ec) {
  2280. eo += nodeCount;
  2281. }
  2282. } else if (so >= sc.nodeValue.length) {
  2283. if (sc.nextSibling) {
  2284. sc.parentNode.insertBefore(node, sc.nextSibling);
  2285. } else {
  2286. sc.parentNode.appendChild(node);
  2287. }
  2288. } else {
  2289. if (so > 0) {
  2290. c = sc.splitText(so);
  2291. } else {
  2292. c = sc;
  2293. }
  2294. sc.parentNode.insertBefore(node, c);
  2295. if (sc === ec) {
  2296. ec = c;
  2297. eo -= so;
  2298. }
  2299. }
  2300. }
  2301. if (firstChild) {
  2302. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2303. } else {
  2304. self.selectNode(node);
  2305. }
  2306. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2307. return self;
  2308. }
  2309. return self.setEnd(ec, eo);
  2310. },
  2311. surroundContents : function(node) {
  2312. node.appendChild(this.extractContents());
  2313. return this.insertNode(node).selectNode(node);
  2314. },
  2315. isControl : function() {
  2316. var self = this,
  2317. sc = self.startContainer, so = self.startOffset,
  2318. ec = self.endContainer, eo = self.endOffset, rng;
  2319. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2320. },
  2321. get : function(hasControlRange) {
  2322. var self = this, doc = self.doc, node, rng;
  2323. if (!_IERANGE) {
  2324. rng = doc.createRange();
  2325. try {
  2326. rng.setStart(self.startContainer, self.startOffset);
  2327. rng.setEnd(self.endContainer, self.endOffset);
  2328. } catch (e) {}
  2329. return rng;
  2330. }
  2331. if (hasControlRange && self.isControl()) {
  2332. rng = doc.body.createControlRange();
  2333. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2334. return rng;
  2335. }
  2336. var range = self.cloneRange().down();
  2337. rng = doc.body.createTextRange();
  2338. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2339. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2340. return rng;
  2341. },
  2342. html : function() {
  2343. return K(this.cloneContents()).outer();
  2344. },
  2345. down : function() {
  2346. var self = this;
  2347. function downPos(node, pos, isStart) {
  2348. if (node.nodeType != 1) {
  2349. return;
  2350. }
  2351. var children = K(node).children();
  2352. if (children.length === 0) {
  2353. return;
  2354. }
  2355. var left, right, child, offset;
  2356. if (pos > 0) {
  2357. left = children.eq(pos - 1);
  2358. }
  2359. if (pos < children.length) {
  2360. right = children.eq(pos);
  2361. }
  2362. if (left && left.type == 3) {
  2363. child = left[0];
  2364. offset = child.nodeValue.length;
  2365. }
  2366. if (right && right.type == 3) {
  2367. child = right[0];
  2368. offset = 0;
  2369. }
  2370. if (!child) {
  2371. return;
  2372. }
  2373. if (isStart) {
  2374. self.setStart(child, offset);
  2375. } else {
  2376. self.setEnd(child, offset);
  2377. }
  2378. }
  2379. downPos(self.startContainer, self.startOffset, true);
  2380. downPos(self.endContainer, self.endOffset, false);
  2381. return self;
  2382. },
  2383. up : function() {
  2384. var self = this;
  2385. function upPos(node, pos, isStart) {
  2386. if (node.nodeType != 3) {
  2387. return;
  2388. }
  2389. if (pos === 0) {
  2390. if (isStart) {
  2391. self.setStartBefore(node);
  2392. } else {
  2393. self.setEndBefore(node);
  2394. }
  2395. } else if (pos == node.nodeValue.length) {
  2396. if (isStart) {
  2397. self.setStartAfter(node);
  2398. } else {
  2399. self.setEndAfter(node);
  2400. }
  2401. }
  2402. }
  2403. upPos(self.startContainer, self.startOffset, true);
  2404. upPos(self.endContainer, self.endOffset, false);
  2405. return self;
  2406. },
  2407. enlarge : function(toBlock) {
  2408. var self = this;
  2409. self.up();
  2410. function enlargePos(node, pos, isStart) {
  2411. var knode = K(node), parent;
  2412. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2413. return;
  2414. }
  2415. if (pos === 0) {
  2416. while (!knode.prev()) {
  2417. parent = knode.parent();
  2418. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2419. break;
  2420. }
  2421. knode = parent;
  2422. }
  2423. if (isStart) {
  2424. self.setStartBefore(knode[0]);
  2425. } else {
  2426. self.setEndBefore(knode[0]);
  2427. }
  2428. } else if (pos == knode.children().length) {
  2429. while (!knode.next()) {
  2430. parent = knode.parent();
  2431. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2432. break;
  2433. }
  2434. knode = parent;
  2435. }
  2436. if (isStart) {
  2437. self.setStartAfter(knode[0]);
  2438. } else {
  2439. self.setEndAfter(knode[0]);
  2440. }
  2441. }
  2442. }
  2443. enlargePos(self.startContainer, self.startOffset, true);
  2444. enlargePos(self.endContainer, self.endOffset, false);
  2445. return self;
  2446. },
  2447. shrink : function() {
  2448. var self = this, child, collapsed = self.collapsed;
  2449. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2450. self.setStart(child, 0);
  2451. }
  2452. if (collapsed) {
  2453. return self.collapse(collapsed);
  2454. }
  2455. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2456. self.setEnd(child, child.childNodes.length);
  2457. }
  2458. return self;
  2459. },
  2460. createBookmark : function(serialize) {
  2461. var self = this, doc = self.doc, endNode,
  2462. startNode = K('<span style="display:none;"></span>', doc)[0];
  2463. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2464. if (!self.collapsed) {
  2465. endNode = startNode.cloneNode(true);
  2466. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2467. }
  2468. if (endNode) {
  2469. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2470. }
  2471. self.insertNode(startNode).setStartAfter(startNode);
  2472. return {
  2473. start : serialize ? '#' + startNode.id : startNode,
  2474. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2475. };
  2476. },
  2477. moveToBookmark : function(bookmark) {
  2478. var self = this, doc = self.doc,
  2479. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2480. if (!start || start.length < 1) {
  2481. return self;
  2482. }
  2483. self.setStartBefore(start[0]);
  2484. start.remove();
  2485. if (end && end.length > 0) {
  2486. self.setEndBefore(end[0]);
  2487. end.remove();
  2488. } else {
  2489. self.collapse(true);
  2490. }
  2491. return self;
  2492. },
  2493. dump : function() {
  2494. console.log('--------------------');
  2495. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2496. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2497. }
  2498. });
  2499. function _range(mixed) {
  2500. if (!mixed.nodeName) {
  2501. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2502. }
  2503. return new KRange(mixed);
  2504. }
  2505. K.RangeClass = KRange;
  2506. K.range = _range;
  2507. K.START_TO_START = _START_TO_START;
  2508. K.START_TO_END = _START_TO_END;
  2509. K.END_TO_END = _END_TO_END;
  2510. K.END_TO_START = _END_TO_START;
  2511. function _nativeCommand(doc, key, val) {
  2512. try {
  2513. doc.execCommand(key, false, val);
  2514. } catch(e) {}
  2515. }
  2516. function _nativeCommandValue(doc, key) {
  2517. var val = '';
  2518. try {
  2519. val = doc.queryCommandValue(key);
  2520. } catch (e) {}
  2521. if (typeof val !== 'string') {
  2522. val = '';
  2523. }
  2524. return val;
  2525. }
  2526. function _getSel(doc) {
  2527. var win = _getWin(doc);
  2528. return _IERANGE ? doc.selection : win.getSelection();
  2529. }
  2530. function _getRng(doc) {
  2531. var sel = _getSel(doc), rng;
  2532. try {
  2533. if (sel.rangeCount > 0) {
  2534. rng = sel.getRangeAt(0);
  2535. } else {
  2536. rng = sel.createRange();
  2537. }
  2538. } catch(e) {}
  2539. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2540. return null;
  2541. }
  2542. return rng;
  2543. }
  2544. function _singleKeyMap(map) {
  2545. var newMap = {}, arr, v;
  2546. _each(map, function(key, val) {
  2547. arr = key.split(',');
  2548. for (var i = 0, len = arr.length; i < len; i++) {
  2549. v = arr[i];
  2550. newMap[v] = val;
  2551. }
  2552. });
  2553. return newMap;
  2554. }
  2555. function _hasAttrOrCss(knode, map) {
  2556. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2557. }
  2558. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2559. mapKey = mapKey || knode.name;
  2560. if (knode.type !== 1) {
  2561. return false;
  2562. }
  2563. var newMap = _singleKeyMap(map);
  2564. if (!newMap[mapKey]) {
  2565. return false;
  2566. }
  2567. var arr = newMap[mapKey].split(',');
  2568. for (var i = 0, len = arr.length; i < len; i++) {
  2569. var key = arr[i];
  2570. if (key === '*') {
  2571. return true;
  2572. }
  2573. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2574. var method = match[1] ? 'css' : 'attr';
  2575. key = match[2];
  2576. var val = match[3] || '';
  2577. if (val === '' && knode[method](key) !== '') {
  2578. return true;
  2579. }
  2580. if (val !== '' && knode[method](key) === val) {
  2581. return true;
  2582. }
  2583. }
  2584. return false;
  2585. }
  2586. function _removeAttrOrCss(knode, map) {
  2587. if (knode.type != 1) {
  2588. return;
  2589. }
  2590. _removeAttrOrCssByKey(knode, map, '*');
  2591. _removeAttrOrCssByKey(knode, map);
  2592. }
  2593. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2594. mapKey = mapKey || knode.name;
  2595. if (knode.type !== 1) {
  2596. return;
  2597. }
  2598. var newMap = _singleKeyMap(map);
  2599. if (!newMap[mapKey]) {
  2600. return;
  2601. }
  2602. var arr = newMap[mapKey].split(','), allFlag = false;
  2603. for (var i = 0, len = arr.length; i < len; i++) {
  2604. var key = arr[i];
  2605. if (key === '*') {
  2606. allFlag = true;
  2607. break;
  2608. }
  2609. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2610. key = match[2];
  2611. if (match[1]) {
  2612. key = _toCamel(key);
  2613. if (knode[0].style[key]) {
  2614. knode[0].style[key] = '';
  2615. }
  2616. } else {
  2617. knode.removeAttr(key);
  2618. }
  2619. }
  2620. if (allFlag) {
  2621. knode.remove(true);
  2622. }
  2623. }
  2624. function _getInnerNode(knode) {
  2625. var inner = knode;
  2626. while (inner.first()) {
  2627. inner = inner.first();
  2628. }
  2629. return inner;
  2630. }
  2631. function _isEmptyNode(knode) {
  2632. if (knode.type != 1 || knode.isSingle()) {
  2633. return false;
  2634. }
  2635. return knode.html().replace(/<[^>]+>/g, '') === '';
  2636. }
  2637. function _mergeWrapper(a, b) {
  2638. a = a.clone(true);
  2639. var lastA = _getInnerNode(a), childA = a, merged = false;
  2640. while (b) {
  2641. while (childA) {
  2642. if (childA.name === b.name) {
  2643. _mergeAttrs(childA, b.attr(), b.css());
  2644. merged = true;
  2645. }
  2646. childA = childA.first();
  2647. }
  2648. if (!merged) {
  2649. lastA.append(b.clone(false));
  2650. }
  2651. merged = false;
  2652. b = b.first();
  2653. }
  2654. return a;
  2655. }
  2656. function _wrapNode(knode, wrapper) {
  2657. wrapper = wrapper.clone(true);
  2658. if (knode.type == 3) {
  2659. _getInnerNode(wrapper).append(knode.clone(false));
  2660. knode.replaceWith(wrapper);
  2661. return wrapper;
  2662. }
  2663. var nodeWrapper = knode, child;
  2664. while ((child = knode.first()) && child.children().length == 1) {
  2665. knode = child;
  2666. }
  2667. child = knode.first();
  2668. var frag = knode.doc.createDocumentFragment();
  2669. while (child) {
  2670. frag.appendChild(child[0]);
  2671. child = child.next();
  2672. }
  2673. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2674. if (frag.firstChild) {
  2675. _getInnerNode(wrapper).append(frag);
  2676. }
  2677. nodeWrapper.replaceWith(wrapper);
  2678. return wrapper;
  2679. }
  2680. function _mergeAttrs(knode, attrs, styles) {
  2681. _each(attrs, function(key, val) {
  2682. if (key !== 'style') {
  2683. knode.attr(key, val);
  2684. }
  2685. });
  2686. _each(styles, function(key, val) {
  2687. knode.css(key, val);
  2688. });
  2689. }
  2690. function _inPreElement(knode) {
  2691. while (knode && knode.name != 'body') {
  2692. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2693. return true;
  2694. }
  2695. knode = knode.parent();
  2696. }
  2697. return false;
  2698. }
  2699. function KCmd(range) {
  2700. this.init(range);
  2701. }
  2702. _extend(KCmd, {
  2703. init : function(range) {
  2704. var self = this, doc = range.doc;
  2705. self.doc = doc;
  2706. self.win = _getWin(doc);
  2707. self.sel = _getSel(doc);
  2708. self.range = range;
  2709. },
  2710. selection : function(forceReset) {
  2711. var self = this, doc = self.doc, rng = _getRng(doc);
  2712. self.sel = _getSel(doc);
  2713. if (rng) {
  2714. self.range = _range(rng);
  2715. if (K(self.range.startContainer).name == 'html') {
  2716. self.range.selectNodeContents(doc.body).collapse(false);
  2717. }
  2718. return self;
  2719. }
  2720. if (forceReset) {
  2721. self.range.selectNodeContents(doc.body).collapse(false);
  2722. }
  2723. return self;
  2724. },
  2725. select : function(hasDummy) {
  2726. hasDummy = _undef(hasDummy, true);
  2727. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2728. sc = range.startContainer, so = range.startOffset,
  2729. ec = range.endContainer, eo = range.endOffset,
  2730. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2731. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2732. if (_IERANGE) {
  2733. var dummy = K('<span>&nbsp;</span>', doc);
  2734. range.insertNode(dummy[0]);
  2735. rng = doc.body.createTextRange();
  2736. try {
  2737. rng.moveToElementText(dummy[0]);
  2738. } catch(ex) {}
  2739. rng.collapse(false);
  2740. rng.select();
  2741. dummy.remove();
  2742. win.focus();
  2743. return self;
  2744. }
  2745. if (_WEBKIT) {
  2746. var children = sc.childNodes;
  2747. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2748. range.insertNode(doc.createTextNode('\u200B'));
  2749. hasU200b = true;
  2750. }
  2751. }
  2752. }
  2753. if (_IERANGE) {
  2754. try {
  2755. rng = range.get(true);
  2756. rng.select();
  2757. } catch(e) {}
  2758. } else {
  2759. if (hasU200b) {
  2760. range.collapse(false);
  2761. }
  2762. rng = range.get(true);
  2763. sel.removeAllRanges();
  2764. sel.addRange(rng);
  2765. if (doc !== document) {
  2766. var pos = K(rng.endContainer).pos();
  2767. win.scrollTo(pos.x, pos.y);
  2768. }
  2769. }
  2770. win.focus();
  2771. return self;
  2772. },
  2773. wrap : function(val) {
  2774. var self = this, doc = self.doc, range = self.range, wrapper;
  2775. wrapper = K(val, doc);
  2776. if (range.collapsed) {
  2777. range.shrink();
  2778. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2779. return self;
  2780. }
  2781. if (wrapper.isBlock()) {
  2782. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2783. while (child.first()) {
  2784. child = child.first();
  2785. }
  2786. child.append(range.extractContents());
  2787. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2788. return self;
  2789. }
  2790. range.enlarge();
  2791. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2792. K(ancestor).scan(function(node) {
  2793. if (!isStart && node == bookmark.start) {
  2794. isStart = true;
  2795. return;
  2796. }
  2797. if (isStart) {
  2798. if (node == bookmark.end) {
  2799. return false;
  2800. }
  2801. var knode = K(node);
  2802. if (_inPreElement(knode)) {
  2803. return;
  2804. }
  2805. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2806. var parent;
  2807. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2808. knode = parent;
  2809. }
  2810. _wrapNode(knode, wrapper);
  2811. }
  2812. }
  2813. });
  2814. range.moveToBookmark(bookmark);
  2815. return self;
  2816. },
  2817. split : function(isStart, map) {
  2818. var range = this.range, doc = range.doc;
  2819. var tempRange = range.cloneRange().collapse(isStart);
  2820. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2821. parent = node.nodeType == 3 ? node.parentNode : node,
  2822. needSplit = false, knode;
  2823. while (parent && parent.parentNode) {
  2824. knode = K(parent);
  2825. if (map) {
  2826. if (!knode.isStyle()) {
  2827. break;
  2828. }
  2829. if (!_hasAttrOrCss(knode, map)) {
  2830. break;
  2831. }
  2832. } else {
  2833. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2834. break;
  2835. }
  2836. }
  2837. needSplit = true;
  2838. parent = parent.parentNode;
  2839. }
  2840. if (needSplit) {
  2841. var dummy = doc.createElement('span');
  2842. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2843. if (isStart) {
  2844. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2845. } else {
  2846. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2847. }
  2848. var frag = tempRange.extractContents(),
  2849. first = frag.firstChild, last = frag.lastChild;
  2850. if (isStart) {
  2851. tempRange.insertNode(frag);
  2852. range.setStartAfter(last).setEndBefore(dummy);
  2853. } else {
  2854. parent.appendChild(frag);
  2855. range.setStartBefore(dummy).setEndBefore(first);
  2856. }
  2857. var dummyParent = dummy.parentNode;
  2858. if (dummyParent == range.endContainer) {
  2859. var prev = K(dummy).prev(), next = K(dummy).next();
  2860. if (prev && next && prev.type == 3 && next.type == 3) {
  2861. range.setEnd(prev[0], prev[0].nodeValue.length);
  2862. } else if (!isStart) {
  2863. range.setEnd(range.endContainer, range.endOffset - 1);
  2864. }
  2865. }
  2866. dummyParent.removeChild(dummy);
  2867. }
  2868. return this;
  2869. },
  2870. remove : function(map) {
  2871. var self = this, doc = self.doc, range = self.range;
  2872. range.enlarge();
  2873. if (range.startOffset === 0) {
  2874. var ksc = K(range.startContainer), parent;
  2875. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2876. ksc = parent;
  2877. }
  2878. range.setStart(ksc[0], 0);
  2879. ksc = K(range.startContainer);
  2880. if (ksc.isBlock()) {
  2881. _removeAttrOrCss(ksc, map);
  2882. }
  2883. var kscp = ksc.parent();
  2884. if (kscp && kscp.isBlock()) {
  2885. _removeAttrOrCss(kscp, map);
  2886. }
  2887. }
  2888. var sc, so;
  2889. if (range.collapsed) {
  2890. self.split(true, map);
  2891. sc = range.startContainer;
  2892. so = range.startOffset;
  2893. if (so > 0) {
  2894. var sb = K(sc.childNodes[so - 1]);
  2895. if (sb && _isEmptyNode(sb)) {
  2896. sb.remove();
  2897. range.setStart(sc, so - 1);
  2898. }
  2899. }
  2900. var sa = K(sc.childNodes[so]);
  2901. if (sa && _isEmptyNode(sa)) {
  2902. sa.remove();
  2903. }
  2904. if (_isEmptyNode(sc)) {
  2905. range.startBefore(sc);
  2906. sc.remove();
  2907. }
  2908. range.collapse(true);
  2909. return self;
  2910. }
  2911. self.split(true, map);
  2912. self.split(false, map);
  2913. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2914. range.cloneRange().collapse(false).insertNode(endDummy);
  2915. range.cloneRange().collapse(true).insertNode(startDummy);
  2916. var nodeList = [], cmpStart = false;
  2917. K(range.commonAncestor()).scan(function(node) {
  2918. if (!cmpStart && node == startDummy) {
  2919. cmpStart = true;
  2920. return;
  2921. }
  2922. if (node == endDummy) {
  2923. return false;
  2924. }
  2925. if (cmpStart) {
  2926. nodeList.push(node);
  2927. }
  2928. });
  2929. K(startDummy).remove();
  2930. K(endDummy).remove();
  2931. sc = range.startContainer;
  2932. so = range.startOffset;
  2933. var ec = range.endContainer, eo = range.endOffset;
  2934. if (so > 0) {
  2935. var startBefore = K(sc.childNodes[so - 1]);
  2936. if (startBefore && _isEmptyNode(startBefore)) {
  2937. startBefore.remove();
  2938. range.setStart(sc, so - 1);
  2939. if (sc == ec) {
  2940. range.setEnd(ec, eo - 1);
  2941. }
  2942. }
  2943. var startAfter = K(sc.childNodes[so]);
  2944. if (startAfter && _isEmptyNode(startAfter)) {
  2945. startAfter.remove();
  2946. if (sc == ec) {
  2947. range.setEnd(ec, eo - 1);
  2948. }
  2949. }
  2950. }
  2951. var endAfter = K(ec.childNodes[range.endOffset]);
  2952. if (endAfter && _isEmptyNode(endAfter)) {
  2953. endAfter.remove();
  2954. }
  2955. var bookmark = range.createBookmark(true);
  2956. _each(nodeList, function(i, node) {
  2957. _removeAttrOrCss(K(node), map);
  2958. });
  2959. range.moveToBookmark(bookmark);
  2960. return self;
  2961. },
  2962. commonNode : function(map) {
  2963. var range = this.range;
  2964. var ec = range.endContainer, eo = range.endOffset,
  2965. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2966. function find(node) {
  2967. var child = node, parent = node;
  2968. while (parent) {
  2969. if (_hasAttrOrCss(K(parent), map)) {
  2970. return K(parent);
  2971. }
  2972. parent = parent.parentNode;
  2973. }
  2974. while (child && (child = child.lastChild)) {
  2975. if (_hasAttrOrCss(K(child), map)) {
  2976. return K(child);
  2977. }
  2978. }
  2979. return null;
  2980. }
  2981. var cNode = find(node);
  2982. if (cNode) {
  2983. return cNode;
  2984. }
  2985. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2986. var prev = K(node).prev();
  2987. if (prev) {
  2988. return find(prev);
  2989. }
  2990. }
  2991. return null;
  2992. },
  2993. commonAncestor : function(tagName) {
  2994. var range = this.range,
  2995. sc = range.startContainer, so = range.startOffset,
  2996. ec = range.endContainer, eo = range.endOffset,
  2997. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  2998. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2999. function find(node) {
  3000. while (node) {
  3001. if (node.nodeType == 1) {
  3002. if (node.tagName.toLowerCase() === tagName) {
  3003. return node;
  3004. }
  3005. }
  3006. node = node.parentNode;
  3007. }
  3008. return null;
  3009. }
  3010. var start = find(startNode), end = find(endNode);
  3011. if (start && end && start === end) {
  3012. return K(start);
  3013. }
  3014. return null;
  3015. },
  3016. state : function(key) {
  3017. var self = this, doc = self.doc, bool = false;
  3018. try {
  3019. bool = doc.queryCommandState(key);
  3020. } catch (e) {}
  3021. return bool;
  3022. },
  3023. val : function(key) {
  3024. var self = this, doc = self.doc, range = self.range;
  3025. function lc(val) {
  3026. return val.toLowerCase();
  3027. }
  3028. key = lc(key);
  3029. var val = '', knode;
  3030. if (key === 'fontfamily' || key === 'fontname') {
  3031. val = _nativeCommandValue(doc, 'fontname');
  3032. val = val.replace(/['"]/g, '');
  3033. return lc(val);
  3034. }
  3035. if (key === 'formatblock') {
  3036. val = _nativeCommandValue(doc, key);
  3037. if (val === '') {
  3038. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3039. if (knode) {
  3040. val = knode.name;
  3041. }
  3042. }
  3043. if (val === 'Normal') {
  3044. val = 'p';
  3045. }
  3046. return lc(val);
  3047. }
  3048. if (key === 'fontsize') {
  3049. knode = self.commonNode({'*' : '.font-size'});
  3050. if (knode) {
  3051. val = knode.css('font-size');
  3052. }
  3053. return lc(val);
  3054. }
  3055. if (key === 'forecolor') {
  3056. knode = self.commonNode({'*' : '.color'});
  3057. if (knode) {
  3058. val = knode.css('color');
  3059. }
  3060. val = _toHex(val);
  3061. if (val === '') {
  3062. val = 'default';
  3063. }
  3064. return lc(val);
  3065. }
  3066. if (key === 'hilitecolor') {
  3067. knode = self.commonNode({'*' : '.background-color'});
  3068. if (knode) {
  3069. val = knode.css('background-color');
  3070. }
  3071. val = _toHex(val);
  3072. if (val === '') {
  3073. val = 'default';
  3074. }
  3075. return lc(val);
  3076. }
  3077. return val;
  3078. },
  3079. toggle : function(wrapper, map) {
  3080. var self = this;
  3081. if (self.commonNode(map)) {
  3082. self.remove(map);
  3083. } else {
  3084. self.wrap(wrapper);
  3085. }
  3086. return self.select();
  3087. },
  3088. bold : function() {
  3089. return this.toggle('<strong></strong>', {
  3090. span : '.font-weight=bold',
  3091. strong : '*',
  3092. b : '*'
  3093. });
  3094. },
  3095. italic : function() {
  3096. return this.toggle('<em></em>', {
  3097. span : '.font-style=italic',
  3098. em : '*',
  3099. i : '*'
  3100. });
  3101. },
  3102. underline : function() {
  3103. return this.toggle('<u></u>', {
  3104. span : '.text-decoration=underline',
  3105. u : '*'
  3106. });
  3107. },
  3108. strikethrough : function() {
  3109. return this.toggle('<s></s>', {
  3110. span : '.text-decoration=line-through',
  3111. s : '*'
  3112. });
  3113. },
  3114. forecolor : function(val) {
  3115. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3116. },
  3117. hilitecolor : function(val) {
  3118. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3119. },
  3120. fontsize : function(val) {
  3121. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3122. },
  3123. fontname : function(val) {
  3124. return this.fontfamily(val);
  3125. },
  3126. fontfamily : function(val) {
  3127. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3128. },
  3129. removeformat : function() {
  3130. var map = {
  3131. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3132. },
  3133. tags = _STYLE_TAG_MAP;
  3134. _each(tags, function(key, val) {
  3135. map[key] = '*';
  3136. });
  3137. this.remove(map);
  3138. return this.select();
  3139. },
  3140. inserthtml : function(val, quickMode) {
  3141. var self = this, range = self.range;
  3142. if (val === '') {
  3143. return self;
  3144. }
  3145. function pasteHtml(range, val) {
  3146. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3147. var rng = range.get();
  3148. if (rng.item) {
  3149. rng.item(0).outerHTML = val;
  3150. } else {
  3151. rng.pasteHTML(val);
  3152. }
  3153. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3154. temp.parentNode.removeChild(temp);
  3155. var newRange = _toRange(rng);
  3156. range.setEnd(newRange.endContainer, newRange.endOffset);
  3157. range.collapse(false);
  3158. self.select(false);
  3159. }
  3160. function insertHtml(range, val) {
  3161. var doc = range.doc,
  3162. frag = doc.createDocumentFragment();
  3163. K('@' + val, doc).each(function() {
  3164. frag.appendChild(this);
  3165. });
  3166. range.deleteContents();
  3167. range.insertNode(frag);
  3168. range.collapse(false);
  3169. self.select(false);
  3170. }
  3171. if (_IERANGE && quickMode) {
  3172. try {
  3173. pasteHtml(range, val);
  3174. } catch(e) {
  3175. insertHtml(range, val);
  3176. }
  3177. return self;
  3178. }
  3179. insertHtml(range, val);
  3180. return self;
  3181. },
  3182. hr : function() {
  3183. return this.inserthtml('<hr />');
  3184. },
  3185. print : function() {
  3186. this.win.print();
  3187. return this;
  3188. },
  3189. insertimage : function(url, title, width, height, border, align) {
  3190. title = _undef(title, '');
  3191. border = _undef(border, 0);
  3192. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3193. if (width) {
  3194. html += 'width="' + _escape(width) + '" ';
  3195. }
  3196. if (height) {
  3197. html += 'height="' + _escape(height) + '" ';
  3198. }
  3199. if (title) {
  3200. html += 'title="' + _escape(title) + '" ';
  3201. }
  3202. if (align) {
  3203. html += 'align="' + _escape(align) + '" ';
  3204. }
  3205. html += 'alt="' + _escape(title) + '" ';
  3206. html += '/>';
  3207. return this.inserthtml(html);
  3208. },
  3209. createlink : function(url, type) {
  3210. var self = this, doc = self.doc, range = self.range;
  3211. self.select();
  3212. var a = self.commonNode({ a : '*' });
  3213. if (a && !range.isControl()) {
  3214. range.selectNode(a.get());
  3215. self.select();
  3216. }
  3217. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3218. if (type) {
  3219. html += ' target="' + _escape(type) + '"';
  3220. }
  3221. if (range.collapsed) {
  3222. html += '>' + _escape(url) + '</a>';
  3223. return self.inserthtml(html);
  3224. }
  3225. if (range.isControl()) {
  3226. var node = K(range.startContainer.childNodes[range.startOffset]);
  3227. html += '></a>';
  3228. node.after(K(html, doc));
  3229. node.next().append(node);
  3230. range.selectNode(node[0]);
  3231. return self.select();
  3232. }
  3233. function setAttr(node, url, type) {
  3234. K(node).attr('href', url).attr('data-ke-src', url);
  3235. if (type) {
  3236. K(node).attr('target', type);
  3237. } else {
  3238. K(node).removeAttr('target');
  3239. }
  3240. }
  3241. var sc = range.startContainer, so = range.startOffset,
  3242. ec = range.endContainer, eo = range.endOffset;
  3243. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3244. var child = sc.childNodes[so];
  3245. if (child.nodeName.toLowerCase() == 'a') {
  3246. setAttr(child, url, type);
  3247. return self;
  3248. }
  3249. }
  3250. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3251. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3252. setAttr(this, url, type);
  3253. });
  3254. return self;
  3255. },
  3256. unlink : function() {
  3257. var self = this, doc = self.doc, range = self.range;
  3258. self.select();
  3259. if (range.collapsed) {
  3260. var a = self.commonNode({ a : '*' });
  3261. if (a) {
  3262. range.selectNode(a.get());
  3263. self.select();
  3264. }
  3265. _nativeCommand(doc, 'unlink', null);
  3266. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3267. var parent = K(range.startContainer).parent();
  3268. if (parent.name === 'a') {
  3269. parent.remove(true);
  3270. }
  3271. }
  3272. } else {
  3273. _nativeCommand(doc, 'unlink', null);
  3274. }
  3275. return self;
  3276. }
  3277. });
  3278. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3279. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3280. KCmd.prototype[name] = function(val) {
  3281. var self = this;
  3282. self.select();
  3283. _nativeCommand(self.doc, name, val);
  3284. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3285. self.selection();
  3286. }
  3287. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3288. self.selection();
  3289. }
  3290. return self;
  3291. };
  3292. });
  3293. _each('cut,copy,paste'.split(','), function(i, name) {
  3294. KCmd.prototype[name] = function() {
  3295. var self = this;
  3296. if (!self.doc.queryCommandSupported(name)) {
  3297. throw 'not supported';
  3298. }
  3299. self.select();
  3300. _nativeCommand(self.doc, name, null);
  3301. return self;
  3302. };
  3303. });
  3304. function _cmd(mixed) {
  3305. if (mixed.nodeName) {
  3306. var doc = _getDoc(mixed);
  3307. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3308. }
  3309. return new KCmd(mixed);
  3310. }
  3311. K.CmdClass = KCmd;
  3312. K.cmd = _cmd;
  3313. function _drag(options) {
  3314. var moveEl = options.moveEl,
  3315. moveFn = options.moveFn,
  3316. clickEl = options.clickEl || moveEl,
  3317. beforeDrag = options.beforeDrag,
  3318. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3319. var docs = [document];
  3320. if (iframeFix) {
  3321. K('iframe').each(function() {
  3322. var src = _formatUrl(this.src || '', 'absolute');
  3323. if (/^https?:\/\//.test(src)) {
  3324. return;
  3325. }
  3326. var doc;
  3327. try {
  3328. doc = _iframeDoc(this);
  3329. } catch(e) {}
  3330. if (doc) {
  3331. var pos = K(this).pos();
  3332. K(doc).data('pos-x', pos.x);
  3333. K(doc).data('pos-y', pos.y);
  3334. docs.push(doc);
  3335. }
  3336. });
  3337. }
  3338. clickEl.mousedown(function(e) {
  3339. if(e.button !== 0 && e.button !== 1) {
  3340. return;
  3341. }
  3342. e.stopPropagation();
  3343. var self = clickEl.get(),
  3344. x = _removeUnit(moveEl.css('left')),
  3345. y = _removeUnit(moveEl.css('top')),
  3346. width = moveEl.width(),
  3347. height = moveEl.height(),
  3348. pageX = e.pageX,
  3349. pageY = e.pageY;
  3350. if (beforeDrag) {
  3351. beforeDrag();
  3352. }
  3353. function moveListener(e) {
  3354. e.preventDefault();
  3355. var kdoc = K(_getDoc(e.target));
  3356. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3357. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3358. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3359. }
  3360. function selectListener(e) {
  3361. e.preventDefault();
  3362. }
  3363. function upListener(e) {
  3364. e.preventDefault();
  3365. K(docs).unbind('mousemove', moveListener)
  3366. .unbind('mouseup', upListener)
  3367. .unbind('selectstart', selectListener);
  3368. if (self.releaseCapture) {
  3369. self.releaseCapture();
  3370. }
  3371. }
  3372. K(docs).mousemove(moveListener)
  3373. .mouseup(upListener)
  3374. .bind('selectstart', selectListener);
  3375. if (self.setCapture) {
  3376. self.setCapture();
  3377. }
  3378. });
  3379. }
  3380. function KWidget(options) {
  3381. this.init(options);
  3382. }
  3383. _extend(KWidget, {
  3384. init : function(options) {
  3385. var self = this;
  3386. self.name = options.name || '';
  3387. self.doc = options.doc || document;
  3388. self.win = _getWin(self.doc);
  3389. self.x = _addUnit(options.x);
  3390. self.y = _addUnit(options.y);
  3391. self.z = options.z;
  3392. self.width = _addUnit(options.width);
  3393. self.height = _addUnit(options.height);
  3394. self.index = _addUnit(options.index);
  3395. self.div = K('<div style="display:block;"></div>');
  3396. self.options = options;
  3397. self._alignEl = options.alignEl;
  3398. if (self.width) {
  3399. self.div.css('width', self.width);
  3400. }
  3401. if (self.height) {
  3402. self.div.css('height', self.height);
  3403. }
  3404. if (self.z) {
  3405. self.div.css({
  3406. position : 'absolute',
  3407. left : self.x,
  3408. top : self.y,
  3409. 'z-index' : self.z
  3410. });
  3411. }
  3412. if (self.z && (self.x === undefined || self.y === undefined)) {
  3413. self.autoPos(self.width, self.height);
  3414. }
  3415. if (options.cls) {
  3416. self.div.addClass(options.cls);
  3417. }
  3418. if (options.shadowMode) {
  3419. self.div.addClass('ke-shadow');
  3420. }
  3421. if (options.css) {
  3422. self.div.css(options.css);
  3423. }
  3424. if (options.src) {
  3425. K(options.src).replaceWith(self.div);
  3426. } else {
  3427. K(self.doc.body).append(self.div);
  3428. }
  3429. if (options.html) {
  3430. self.div.html(options.html);
  3431. }
  3432. if (options.autoScroll) {
  3433. if (_IE && _V < 7 || _QUIRKS) {
  3434. var scrollPos = _getScrollPos();
  3435. K(self.win).bind('scroll', function(e) {
  3436. var pos = _getScrollPos(),
  3437. diffX = pos.x - scrollPos.x,
  3438. diffY = pos.y - scrollPos.y;
  3439. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3440. });
  3441. } else {
  3442. self.div.css('position', 'fixed');
  3443. }
  3444. }
  3445. },
  3446. pos : function(x, y, updateProp) {
  3447. var self = this;
  3448. updateProp = _undef(updateProp, true);
  3449. if (x !== null) {
  3450. x = x < 0 ? 0 : _addUnit(x);
  3451. self.div.css('left', x);
  3452. if (updateProp) {
  3453. self.x = x;
  3454. }
  3455. }
  3456. if (y !== null) {
  3457. y = y < 0 ? 0 : _addUnit(y);
  3458. self.div.css('top', y);
  3459. if (updateProp) {
  3460. self.y = y;
  3461. }
  3462. }
  3463. return self;
  3464. },
  3465. autoPos : function(width, height) {
  3466. var x, y, self = this,
  3467. w = _removeUnit(width) || 0,
  3468. h = _removeUnit(height) || 0,
  3469. scrollPos = _getScrollPos();
  3470. if (self._alignEl) {
  3471. var knode = K(self._alignEl),
  3472. pos = knode.pos(),
  3473. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3474. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3475. x = diffX < 0 ? pos.x : pos.x + diffX;
  3476. y = diffY < 0 ? pos.y : pos.y + diffY;
  3477. } else {
  3478. var docEl = _docElement(self.doc);
  3479. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3480. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3481. }
  3482. if (!(_IE && _V < 7 || _QUIRKS)) {
  3483. x -= scrollPos.x;
  3484. y -= scrollPos.y;
  3485. }
  3486. return self.pos(x, y);
  3487. },
  3488. remove : function() {
  3489. var self = this;
  3490. if (_IE && _V < 7 || _QUIRKS) {
  3491. K(self.win).unbind('scroll');
  3492. }
  3493. self.div.remove();
  3494. _each(self, function(i) {
  3495. self[i] = null;
  3496. });
  3497. return this;
  3498. },
  3499. show : function() {
  3500. this.div.show();
  3501. return this;
  3502. },
  3503. hide : function() {
  3504. this.div.hide();
  3505. return this;
  3506. },
  3507. draggable : function(options) {
  3508. var self = this;
  3509. options = options || {};
  3510. options.moveEl = self.div;
  3511. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3512. if ((x = x + diffX) < 0) {
  3513. x = 0;
  3514. }
  3515. if ((y = y + diffY) < 0) {
  3516. y = 0;
  3517. }
  3518. self.pos(x, y);
  3519. };
  3520. _drag(options);
  3521. return self;
  3522. }
  3523. });
  3524. function _widget(options) {
  3525. return new KWidget(options);
  3526. }
  3527. K.WidgetClass = KWidget;
  3528. K.widget = _widget;
  3529. function _iframeDoc(iframe) {
  3530. iframe = _get(iframe);
  3531. return iframe.contentDocument || iframe.contentWindow.document;
  3532. }
  3533. var html, _direction = '';
  3534. if ((html = document.getElementsByTagName('html'))) {
  3535. _direction = html[0].dir;
  3536. }
  3537. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3538. var arr = [
  3539. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3540. '<head><meta charset="utf-8" /><title></title>',
  3541. '<style>',
  3542. 'html {margin:0;padding:0;}',
  3543. 'body {margin:0;padding:5px;}',
  3544. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3545. 'body, p, div {word-wrap: break-word;}',
  3546. 'p {margin:5px 0;}',
  3547. 'table {border-collapse:collapse;}',
  3548. 'img {border:0;}',
  3549. 'noscript {display:none;}',
  3550. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3551. 'img.ke-flash {',
  3552. ' border:1px solid #AAA;',
  3553. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3554. ' background-position:center center;',
  3555. ' background-repeat:no-repeat;',
  3556. ' width:100px;',
  3557. ' height:100px;',
  3558. '}',
  3559. 'img.ke-rm {',
  3560. ' border:1px solid #AAA;',
  3561. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3562. ' background-position:center center;',
  3563. ' background-repeat:no-repeat;',
  3564. ' width:100px;',
  3565. ' height:100px;',
  3566. '}',
  3567. 'img.ke-media {',
  3568. ' border:1px solid #AAA;',
  3569. ' background-image:url(' + themesPath + 'common/media.gif);',
  3570. ' background-position:center center;',
  3571. ' background-repeat:no-repeat;',
  3572. ' width:100px;',
  3573. ' height:100px;',
  3574. '}',
  3575. 'img.ke-anchor {',
  3576. ' border:1px dashed #666;',
  3577. ' width:16px;',
  3578. ' height:16px;',
  3579. '}',
  3580. '.ke-script, .ke-noscript, .ke-display-none {',
  3581. ' display:none;',
  3582. ' font-size:0;',
  3583. ' width:0;',
  3584. ' height:0;',
  3585. '}',
  3586. '.ke-pagebreak {',
  3587. ' border:1px dotted #AAA;',
  3588. ' font-size:0;',
  3589. ' height:2px;',
  3590. '}',
  3591. '</style>'
  3592. ];
  3593. if (!_isArray(cssPath)) {
  3594. cssPath = [cssPath];
  3595. }
  3596. _each(cssPath, function(i, path) {
  3597. if (path) {
  3598. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3599. }
  3600. });
  3601. if (cssData) {
  3602. arr.push('<style>' + cssData + '</style>');
  3603. }
  3604. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3605. return arr.join('\n');
  3606. }
  3607. function _elementVal(knode, val) {
  3608. if (knode.hasVal()) {
  3609. if (val === undefined) {
  3610. var html = knode.val();
  3611. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3612. return html;
  3613. }
  3614. return knode.val(val);
  3615. }
  3616. return knode.html(val);
  3617. }
  3618. function KEdit(options) {
  3619. this.init(options);
  3620. }
  3621. _extend(KEdit, KWidget, {
  3622. init : function(options) {
  3623. var self = this;
  3624. KEdit.parent.init.call(self, options);
  3625. self.srcElement = K(options.srcElement);
  3626. self.div.addClass('ke-edit');
  3627. self.designMode = _undef(options.designMode, true);
  3628. self.beforeGetHtml = options.beforeGetHtml;
  3629. self.beforeSetHtml = options.beforeSetHtml;
  3630. self.afterSetHtml = options.afterSetHtml;
  3631. var themesPath = _undef(options.themesPath, ''),
  3632. bodyClass = options.bodyClass,
  3633. cssPath = options.cssPath,
  3634. cssData = options.cssData,
  3635. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3636. srcScript = ('document.open();' +
  3637. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3638. 'document.close();'),
  3639. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3640. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3641. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3642. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3643. self.iframe.attr('tabindex', self.tabIndex);
  3644. self.textarea.attr('tabindex', self.tabIndex);
  3645. if (self.width) {
  3646. self.setWidth(self.width);
  3647. }
  3648. if (self.height) {
  3649. self.setHeight(self.height);
  3650. }
  3651. if (self.designMode) {
  3652. self.textarea.hide();
  3653. } else {
  3654. self.iframe.hide();
  3655. }
  3656. function ready() {
  3657. var doc = _iframeDoc(self.iframe);
  3658. doc.open();
  3659. if (isDocumentDomain) {
  3660. doc.domain = document.domain;
  3661. }
  3662. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3663. doc.close();
  3664. self.win = self.iframe[0].contentWindow;
  3665. self.doc = doc;
  3666. var cmd = _cmd(doc);
  3667. self.afterChange(function(e) {
  3668. cmd.selection();
  3669. });
  3670. if (_WEBKIT) {
  3671. K(doc).click(function(e) {
  3672. if (K(e.target).name === 'img') {
  3673. cmd.selection(true);
  3674. cmd.range.selectNode(e.target);
  3675. cmd.select();
  3676. }
  3677. });
  3678. }
  3679. if (_IE) {
  3680. self._mousedownHandler = function() {
  3681. var newRange = cmd.range.cloneRange();
  3682. newRange.shrink();
  3683. if (newRange.isControl()) {
  3684. self.blur();
  3685. }
  3686. };
  3687. K(document).mousedown(self._mousedownHandler);
  3688. K(doc).keydown(function(e) {
  3689. if (e.which == 8) {
  3690. cmd.selection();
  3691. var rng = cmd.range;
  3692. if (rng.isControl()) {
  3693. rng.collapse(true);
  3694. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3695. e.preventDefault();
  3696. }
  3697. }
  3698. });
  3699. }
  3700. self.cmd = cmd;
  3701. self.html(_elementVal(self.srcElement));
  3702. if (_IE) {
  3703. doc.body.disabled = true;
  3704. doc.body.contentEditable = true;
  3705. doc.body.removeAttribute('disabled');
  3706. } else {
  3707. doc.designMode = 'on';
  3708. }
  3709. if (options.afterCreate) {
  3710. options.afterCreate.call(self);
  3711. }
  3712. }
  3713. if (isDocumentDomain) {
  3714. self.iframe.bind('load', function(e) {
  3715. self.iframe.unbind('load');
  3716. if (_IE) {
  3717. ready();
  3718. } else {
  3719. setTimeout(ready, 0);
  3720. }
  3721. });
  3722. }
  3723. self.div.append(self.iframe);
  3724. self.div.append(self.textarea);
  3725. self.srcElement.hide();
  3726. !isDocumentDomain && ready();
  3727. },
  3728. setWidth : function(val) {
  3729. var self = this;
  3730. val = _addUnit(val);
  3731. self.width = val;
  3732. self.div.css('width', val);
  3733. return self;
  3734. },
  3735. setHeight : function(val) {
  3736. var self = this;
  3737. val = _addUnit(val);
  3738. self.height = val;
  3739. self.div.css('height', val);
  3740. self.iframe.css('height', val);
  3741. if ((_IE && _V < 8) || _QUIRKS) {
  3742. val = _addUnit(_removeUnit(val) - 2);
  3743. }
  3744. self.textarea.css('height', val);
  3745. return self;
  3746. },
  3747. remove : function() {
  3748. var self = this, doc = self.doc;
  3749. K(doc.body).unbind();
  3750. K(doc).unbind();
  3751. K(self.win).unbind();
  3752. if (self._mousedownHandler) {
  3753. K(document).unbind('mousedown', self._mousedownHandler);
  3754. }
  3755. _elementVal(self.srcElement, self.html());
  3756. self.srcElement.show();
  3757. self.iframe.unbind();
  3758. self.textarea.unbind();
  3759. KEdit.parent.remove.call(self);
  3760. },
  3761. html : function(val, isFull) {
  3762. var self = this, doc = self.doc;
  3763. if (self.designMode) {
  3764. var body = doc.body;
  3765. if (val === undefined) {
  3766. if (isFull) {
  3767. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3768. } else {
  3769. val = body.innerHTML;
  3770. }
  3771. if (self.beforeGetHtml) {
  3772. val = self.beforeGetHtml(val);
  3773. }
  3774. if (_GECKO && val == '<br />') {
  3775. val = '';
  3776. }
  3777. return val;
  3778. }
  3779. if (self.beforeSetHtml) {
  3780. val = self.beforeSetHtml(val);
  3781. }
  3782. if (_IE && _V >= 9) {
  3783. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3784. }
  3785. K(body).html(val);
  3786. if (self.afterSetHtml) {
  3787. self.afterSetHtml();
  3788. }
  3789. return self;
  3790. }
  3791. if (val === undefined) {
  3792. return self.textarea.val();
  3793. }
  3794. self.textarea.val(val);
  3795. return self;
  3796. },
  3797. design : function(bool) {
  3798. var self = this, val;
  3799. if (bool === undefined ? !self.designMode : bool) {
  3800. if (!self.designMode) {
  3801. val = self.html();
  3802. self.designMode = true;
  3803. self.textarea.hide();
  3804. self.html(val);
  3805. var iframe = self.iframe;
  3806. var height = _removeUnit(self.height);
  3807. iframe.height(height - 2);
  3808. iframe.show();
  3809. setTimeout(function() {
  3810. iframe.height(height);
  3811. }, 0);
  3812. }
  3813. } else {
  3814. if (self.designMode) {
  3815. val = self.html();
  3816. self.designMode = false;
  3817. self.html(val);
  3818. self.iframe.hide();
  3819. self.textarea.show();
  3820. }
  3821. }
  3822. return self.focus();
  3823. },
  3824. focus : function() {
  3825. var self = this;
  3826. self.designMode ? self.win.focus() : self.textarea[0].focus();
  3827. return self;
  3828. },
  3829. blur : function() {
  3830. var self = this;
  3831. if (_IE) {
  3832. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3833. self.div.append(input);
  3834. input[0].focus();
  3835. input.remove();
  3836. } else {
  3837. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3838. }
  3839. return self;
  3840. },
  3841. afterChange : function(fn) {
  3842. var self = this, doc = self.doc, body = doc.body;
  3843. K(doc).keyup(function(e) {
  3844. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3845. fn(e);
  3846. }
  3847. });
  3848. K(doc).mouseup(fn).contextmenu(fn);
  3849. K(self.win).blur(fn);
  3850. function timeoutHandler(e) {
  3851. setTimeout(function() {
  3852. fn(e);
  3853. }, 1);
  3854. }
  3855. K(body).bind('paste', timeoutHandler);
  3856. K(body).bind('cut', timeoutHandler);
  3857. return self;
  3858. }
  3859. });
  3860. function _edit(options) {
  3861. return new KEdit(options);
  3862. }
  3863. K.EditClass = KEdit;
  3864. K.edit = _edit;
  3865. K.iframeDoc = _iframeDoc;
  3866. function _selectToolbar(name, fn) {
  3867. var self = this,
  3868. knode = self.get(name);
  3869. if (knode) {
  3870. if (knode.hasClass('ke-disabled')) {
  3871. return;
  3872. }
  3873. fn(knode);
  3874. }
  3875. }
  3876. function KToolbar(options) {
  3877. this.init(options);
  3878. }
  3879. _extend(KToolbar, KWidget, {
  3880. init : function(options) {
  3881. var self = this;
  3882. KToolbar.parent.init.call(self, options);
  3883. self.disableMode = _undef(options.disableMode, false);
  3884. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3885. self._itemMap = {};
  3886. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3887. e.preventDefault();
  3888. }).attr('unselectable', 'on');
  3889. function find(target) {
  3890. var knode = K(target);
  3891. if (knode.hasClass('ke-outline')) {
  3892. return knode;
  3893. }
  3894. if (knode.hasClass('ke-toolbar-icon')) {
  3895. return knode.parent();
  3896. }
  3897. }
  3898. function hover(e, method) {
  3899. var knode = find(e.target);
  3900. if (knode) {
  3901. if (knode.hasClass('ke-disabled')) {
  3902. return;
  3903. }
  3904. if (knode.hasClass('ke-selected')) {
  3905. return;
  3906. }
  3907. knode[method]('ke-on');
  3908. }
  3909. }
  3910. self.div.mouseover(function(e) {
  3911. hover(e, 'addClass');
  3912. })
  3913. .mouseout(function(e) {
  3914. hover(e, 'removeClass');
  3915. })
  3916. .click(function(e) {
  3917. var knode = find(e.target);
  3918. if (knode) {
  3919. if (knode.hasClass('ke-disabled')) {
  3920. return;
  3921. }
  3922. self.options.click.call(this, e, knode.attr('data-name'));
  3923. }
  3924. });
  3925. },
  3926. get : function(name) {
  3927. if (this._itemMap[name]) {
  3928. return this._itemMap[name];
  3929. }
  3930. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3931. },
  3932. select : function(name) {
  3933. _selectToolbar.call(this, name, function(knode) {
  3934. knode.addClass('ke-selected');
  3935. });
  3936. return self;
  3937. },
  3938. unselect : function(name) {
  3939. _selectToolbar.call(this, name, function(knode) {
  3940. knode.removeClass('ke-selected').removeClass('ke-on');
  3941. });
  3942. return self;
  3943. },
  3944. enable : function(name) {
  3945. var self = this,
  3946. knode = name.get ? name : self.get(name);
  3947. if (knode) {
  3948. knode.removeClass('ke-disabled');
  3949. knode.opacity(1);
  3950. }
  3951. return self;
  3952. },
  3953. disable : function(name) {
  3954. var self = this,
  3955. knode = name.get ? name : self.get(name);
  3956. if (knode) {
  3957. knode.removeClass('ke-selected').addClass('ke-disabled');
  3958. knode.opacity(0.5);
  3959. }
  3960. return self;
  3961. },
  3962. disableAll : function(bool, noDisableItems) {
  3963. var self = this, map = self.noDisableItemMap, item;
  3964. if (noDisableItems) {
  3965. map = _toMap(noDisableItems);
  3966. }
  3967. if (bool === undefined ? !self.disableMode : bool) {
  3968. K('span.ke-outline', self.div).each(function() {
  3969. var knode = K(this),
  3970. name = knode[0].getAttribute('data-name', 2);
  3971. if (!map[name]) {
  3972. self.disable(knode);
  3973. }
  3974. });
  3975. self.disableMode = true;
  3976. } else {
  3977. K('span.ke-outline', self.div).each(function() {
  3978. var knode = K(this),
  3979. name = knode[0].getAttribute('data-name', 2);
  3980. if (!map[name]) {
  3981. self.enable(knode);
  3982. }
  3983. });
  3984. self.disableMode = false;
  3985. }
  3986. return self;
  3987. }
  3988. });
  3989. function _toolbar(options) {
  3990. return new KToolbar(options);
  3991. }
  3992. K.ToolbarClass = KToolbar;
  3993. K.toolbar = _toolbar;
  3994. function KMenu(options) {
  3995. this.init(options);
  3996. }
  3997. _extend(KMenu, KWidget, {
  3998. init : function(options) {
  3999. var self = this;
  4000. options.z = options.z || 811213;
  4001. KMenu.parent.init.call(self, options);
  4002. self.centerLineMode = _undef(options.centerLineMode, true);
  4003. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  4004. e.stopPropagation();
  4005. }).attr('unselectable', 'on');
  4006. },
  4007. addItem : function(item) {
  4008. var self = this;
  4009. if (item.title === '-') {
  4010. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4011. return;
  4012. }
  4013. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4014. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4015. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4016. height = _addUnit(item.height),
  4017. iconClass = _undef(item.iconClass, '');
  4018. self.div.append(itemDiv);
  4019. if (height) {
  4020. itemDiv.css('height', height);
  4021. rightDiv.css('line-height', height);
  4022. }
  4023. var centerDiv;
  4024. if (self.centerLineMode) {
  4025. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4026. if (height) {
  4027. centerDiv.css('height', height);
  4028. }
  4029. }
  4030. itemDiv.mouseover(function(e) {
  4031. K(this).addClass('ke-menu-item-on');
  4032. if (centerDiv) {
  4033. centerDiv.addClass('ke-menu-item-center-on');
  4034. }
  4035. })
  4036. .mouseout(function(e) {
  4037. K(this).removeClass('ke-menu-item-on');
  4038. if (centerDiv) {
  4039. centerDiv.removeClass('ke-menu-item-center-on');
  4040. }
  4041. })
  4042. .click(function(e) {
  4043. item.click.call(K(this));
  4044. e.stopPropagation();
  4045. })
  4046. .append(leftDiv);
  4047. if (centerDiv) {
  4048. itemDiv.append(centerDiv);
  4049. }
  4050. itemDiv.append(rightDiv);
  4051. if (item.checked) {
  4052. iconClass = 'ke-icon-checked';
  4053. }
  4054. if (iconClass !== '') {
  4055. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4056. }
  4057. rightDiv.html(item.title);
  4058. return self;
  4059. },
  4060. remove : function() {
  4061. var self = this;
  4062. if (self.options.beforeRemove) {
  4063. self.options.beforeRemove.call(self);
  4064. }
  4065. K('.ke-menu-item', self.div[0]).unbind();
  4066. KMenu.parent.remove.call(self);
  4067. return self;
  4068. }
  4069. });
  4070. function _menu(options) {
  4071. return new KMenu(options);
  4072. }
  4073. K.MenuClass = KMenu;
  4074. K.menu = _menu;
  4075. function KColorPicker(options) {
  4076. this.init(options);
  4077. }
  4078. _extend(KColorPicker, KWidget, {
  4079. init : function(options) {
  4080. var self = this;
  4081. options.z = options.z || 811213;
  4082. KColorPicker.parent.init.call(self, options);
  4083. var colors = options.colors || [
  4084. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4085. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4086. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4087. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4088. ];
  4089. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4090. self._cells = [];
  4091. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4092. e.stopPropagation();
  4093. }).attr('unselectable', 'on');
  4094. var table = self.doc.createElement('table');
  4095. self.div.append(table);
  4096. table.className = 'ke-colorpicker-table';
  4097. table.cellPadding = 0;
  4098. table.cellSpacing = 0;
  4099. table.border = 0;
  4100. var row = table.insertRow(0), cell = row.insertCell(0);
  4101. cell.colSpan = colors[0].length;
  4102. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4103. for (var i = 0; i < colors.length; i++) {
  4104. row = table.insertRow(i + 1);
  4105. for (var j = 0; j < colors[i].length; j++) {
  4106. cell = row.insertCell(j);
  4107. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4108. }
  4109. }
  4110. },
  4111. _addAttr : function(cell, color, cls) {
  4112. var self = this;
  4113. cell = K(cell).addClass(cls);
  4114. if (self.selectedColor === color.toLowerCase()) {
  4115. cell.addClass('ke-colorpicker-cell-selected');
  4116. }
  4117. cell.attr('title', color || self.options.noColor);
  4118. cell.mouseover(function(e) {
  4119. K(this).addClass('ke-colorpicker-cell-on');
  4120. });
  4121. cell.mouseout(function(e) {
  4122. K(this).removeClass('ke-colorpicker-cell-on');
  4123. });
  4124. cell.click(function(e) {
  4125. e.stop();
  4126. self.options.click.call(K(this), color);
  4127. });
  4128. if (color) {
  4129. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4130. } else {
  4131. cell.html(self.options.noColor);
  4132. }
  4133. K(cell).attr('unselectable', 'on');
  4134. self._cells.push(cell);
  4135. },
  4136. remove : function() {
  4137. var self = this;
  4138. _each(self._cells, function() {
  4139. this.unbind();
  4140. });
  4141. KColorPicker.parent.remove.call(self);
  4142. return self;
  4143. }
  4144. });
  4145. function _colorpicker(options) {
  4146. return new KColorPicker(options);
  4147. }
  4148. K.ColorPickerClass = KColorPicker;
  4149. K.colorpicker = _colorpicker;
  4150. function KUploadButton(options) {
  4151. this.init(options);
  4152. }
  4153. _extend(KUploadButton, {
  4154. init : function(options) {
  4155. var self = this,
  4156. button = K(options.button),
  4157. fieldName = options.fieldName || 'file',
  4158. url = options.url || '',
  4159. title = button.val(),
  4160. extraParams = options.extraParams || {},
  4161. cls = button[0].className || '',
  4162. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4163. options.afterError = options.afterError || function(str) {
  4164. alert(str);
  4165. };
  4166. var hiddenElements = [];
  4167. for(var k in extraParams){
  4168. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  4169. }
  4170. var html = [
  4171. '<div class="ke-inline-block ' + cls + '">',
  4172. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4173. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4174. '<span class="ke-button-common">',
  4175. hiddenElements.join(''),
  4176. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4177. '</span>',
  4178. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4179. (options.form ? '</div>' : '</form>'),
  4180. '</div>'].join('');
  4181. var div = K(html, button.doc);
  4182. button.hide();
  4183. button.before(div);
  4184. self.div = div;
  4185. self.button = button;
  4186. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4187. self.form = options.form ? K(options.form) : K('form', div);
  4188. self.fileBox = K('.ke-upload-file', div);
  4189. var width = options.width || K('.ke-button-common', div).width();
  4190. K('.ke-upload-area', div).width(width);
  4191. self.options = options;
  4192. },
  4193. submit : function() {
  4194. var self = this,
  4195. iframe = self.iframe;
  4196. iframe.bind('load', function() {
  4197. iframe.unbind();
  4198. var tempForm = document.createElement('form');
  4199. self.fileBox.before(tempForm);
  4200. K(tempForm).append(self.fileBox);
  4201. tempForm.reset();
  4202. K(tempForm).remove(true);
  4203. var doc = K.iframeDoc(iframe),
  4204. pre = doc.getElementsByTagName('pre')[0],
  4205. str = '', data;
  4206. if (pre) {
  4207. str = pre.innerHTML;
  4208. } else {
  4209. str = doc.body.innerHTML;
  4210. }
  4211. str = _unescape(str);
  4212. iframe[0].src = 'javascript:false';
  4213. try {
  4214. data = K.json(str);
  4215. } catch (e) {
  4216. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4217. }
  4218. if (data) {
  4219. self.options.afterUpload.call(self, data);
  4220. }
  4221. });
  4222. self.form[0].submit();
  4223. return self;
  4224. },
  4225. remove : function() {
  4226. var self = this;
  4227. if (self.fileBox) {
  4228. self.fileBox.unbind();
  4229. }
  4230. self.iframe.remove();
  4231. self.div.remove();
  4232. self.button.show();
  4233. return self;
  4234. }
  4235. });
  4236. function _uploadbutton(options) {
  4237. return new KUploadButton(options);
  4238. }
  4239. K.UploadButtonClass = KUploadButton;
  4240. K.uploadbutton = _uploadbutton;
  4241. function _createButton(arg) {
  4242. arg = arg || {};
  4243. var name = arg.name || '',
  4244. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4245. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4246. if (arg.click) {
  4247. btn.click(arg.click);
  4248. }
  4249. span.append(btn);
  4250. return span;
  4251. }
  4252. function KDialog(options) {
  4253. this.init(options);
  4254. }
  4255. _extend(KDialog, KWidget, {
  4256. init : function(options) {
  4257. var self = this;
  4258. var shadowMode = _undef(options.shadowMode, true);
  4259. options.z = options.z || 811213;
  4260. options.shadowMode = false;
  4261. options.autoScroll = _undef(options.autoScroll, true);
  4262. KDialog.parent.init.call(self, options);
  4263. var title = options.title,
  4264. body = K(options.body, self.doc),
  4265. previewBtn = options.previewBtn,
  4266. yesBtn = options.yesBtn,
  4267. noBtn = options.noBtn,
  4268. closeBtn = options.closeBtn,
  4269. showMask = _undef(options.showMask, true);
  4270. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4271. e.stopPropagation();
  4272. });
  4273. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4274. if (_IE && _V < 7) {
  4275. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4276. } else if (shadowMode) {
  4277. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4278. }
  4279. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4280. contentDiv.append(headerDiv);
  4281. headerDiv.html(title);
  4282. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4283. headerDiv.append(self.closeIcon);
  4284. self.draggable({
  4285. clickEl : headerDiv,
  4286. beforeDrag : options.beforeDrag
  4287. });
  4288. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4289. contentDiv.append(bodyDiv);
  4290. bodyDiv.append(body);
  4291. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4292. if (previewBtn || yesBtn || noBtn) {
  4293. contentDiv.append(footerDiv);
  4294. }
  4295. _each([
  4296. { btn : previewBtn, name : 'preview' },
  4297. { btn : yesBtn, name : 'yes' },
  4298. { btn : noBtn, name : 'no' }
  4299. ], function() {
  4300. if (this.btn) {
  4301. var button = _createButton(this.btn);
  4302. button.addClass('ke-dialog-' + this.name);
  4303. footerDiv.append(button);
  4304. }
  4305. });
  4306. if (self.height) {
  4307. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4308. }
  4309. self.div.width(self.div.width());
  4310. self.div.height(self.div.height());
  4311. self.mask = null;
  4312. if (showMask) {
  4313. var docEl = _docElement(self.doc),
  4314. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4315. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4316. self.mask = _widget({
  4317. x : 0,
  4318. y : 0,
  4319. z : self.z - 1,
  4320. cls : 'ke-dialog-mask',
  4321. width : docWidth,
  4322. height : docHeight
  4323. });
  4324. }
  4325. self.autoPos(self.div.width(), self.div.height());
  4326. self.footerDiv = footerDiv;
  4327. self.bodyDiv = bodyDiv;
  4328. self.headerDiv = headerDiv;
  4329. self.isLoading = false;
  4330. },
  4331. setMaskIndex : function(z) {
  4332. var self = this;
  4333. self.mask.div.css('z-index', z);
  4334. },
  4335. showLoading : function(msg) {
  4336. msg = _undef(msg, '');
  4337. var self = this, body = self.bodyDiv;
  4338. 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>')
  4339. .width(body.width()).height(body.height())
  4340. .css('top', self.headerDiv.height() + 'px');
  4341. body.css('visibility', 'hidden').after(self.loading);
  4342. self.isLoading = true;
  4343. return self;
  4344. },
  4345. hideLoading : function() {
  4346. this.loading && this.loading.remove();
  4347. this.bodyDiv.css('visibility', 'visible');
  4348. this.isLoading = false;
  4349. return this;
  4350. },
  4351. remove : function() {
  4352. var self = this;
  4353. if (self.options.beforeRemove) {
  4354. self.options.beforeRemove.call(self);
  4355. }
  4356. self.mask && self.mask.remove();
  4357. self.iframeMask && self.iframeMask.remove();
  4358. self.closeIcon.unbind();
  4359. K('input', self.div).unbind();
  4360. K('button', self.div).unbind();
  4361. self.footerDiv.unbind();
  4362. self.bodyDiv.unbind();
  4363. self.headerDiv.unbind();
  4364. K('iframe', self.div).each(function() {
  4365. K(this).remove();
  4366. });
  4367. KDialog.parent.remove.call(self);
  4368. return self;
  4369. }
  4370. });
  4371. function _dialog(options) {
  4372. return new KDialog(options);
  4373. }
  4374. K.DialogClass = KDialog;
  4375. K.dialog = _dialog;
  4376. function _tabs(options) {
  4377. var self = _widget(options),
  4378. remove = self.remove,
  4379. afterSelect = options.afterSelect,
  4380. div = self.div,
  4381. liList = [];
  4382. div.addClass('ke-tabs')
  4383. .bind('contextmenu,mousedown,mousemove', function(e) {
  4384. e.preventDefault();
  4385. });
  4386. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4387. div.append(ul);
  4388. self.add = function(tab) {
  4389. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4390. li.data('tab', tab);
  4391. liList.push(li);
  4392. ul.append(li);
  4393. };
  4394. self.selectedIndex = 0;
  4395. self.select = function(index) {
  4396. self.selectedIndex = index;
  4397. _each(liList, function(i, li) {
  4398. li.unbind();
  4399. if (i === index) {
  4400. li.addClass('ke-tabs-li-selected');
  4401. K(li.data('tab').panel).show('');
  4402. } else {
  4403. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4404. .mouseover(function() {
  4405. K(this).addClass('ke-tabs-li-on');
  4406. })
  4407. .mouseout(function() {
  4408. K(this).removeClass('ke-tabs-li-on');
  4409. })
  4410. .click(function() {
  4411. self.select(i);
  4412. });
  4413. K(li.data('tab').panel).hide();
  4414. }
  4415. });
  4416. if (afterSelect) {
  4417. afterSelect.call(self, index);
  4418. }
  4419. };
  4420. self.remove = function() {
  4421. _each(liList, function() {
  4422. this.remove();
  4423. });
  4424. ul.remove();
  4425. remove.call(self);
  4426. };
  4427. return self;
  4428. }
  4429. K.tabs = _tabs;
  4430. function _loadScript(url, fn) {
  4431. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4432. script = document.createElement('script');
  4433. head.appendChild(script);
  4434. script.src = url;
  4435. script.charset = 'utf-8';
  4436. script.onload = script.onreadystatechange = function() {
  4437. if (!this.readyState || this.readyState === 'loaded') {
  4438. if (fn) {
  4439. fn();
  4440. }
  4441. script.onload = script.onreadystatechange = null;
  4442. head.removeChild(script);
  4443. }
  4444. };
  4445. }
  4446. function _chopQuery(url) {
  4447. var index = url.indexOf('?');
  4448. return index > 0 ? url.substr(0, index) : url;
  4449. }
  4450. function _loadStyle(url) {
  4451. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4452. link = document.createElement('link'),
  4453. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4454. var links = K('link[rel="stylesheet"]', head);
  4455. for (var i = 0, len = links.length; i < len; i++) {
  4456. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4457. return;
  4458. }
  4459. }
  4460. head.appendChild(link);
  4461. link.href = url;
  4462. link.rel = 'stylesheet';
  4463. }
  4464. function _ajax(url, fn, method, param, dataType) {
  4465. method = method || 'GET';
  4466. dataType = dataType || 'json';
  4467. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4468. xhr.open(method, url, true);
  4469. xhr.onreadystatechange = function () {
  4470. if (xhr.readyState == 4 && xhr.status == 200) {
  4471. if (fn) {
  4472. var data = _trim(xhr.responseText);
  4473. if (dataType == 'json') {
  4474. data = _json(data);
  4475. }
  4476. fn(data);
  4477. }
  4478. }
  4479. };
  4480. if (method == 'POST') {
  4481. var params = [];
  4482. _each(param, function(key, val) {
  4483. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4484. });
  4485. try {
  4486. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4487. } catch (e) {}
  4488. xhr.send(params.join('&'));
  4489. } else {
  4490. xhr.send(null);
  4491. }
  4492. }
  4493. K.loadScript = _loadScript;
  4494. K.loadStyle = _loadStyle;
  4495. K.ajax = _ajax;
  4496. var _plugins = {};
  4497. function _plugin(name, fn) {
  4498. if (name === undefined) {
  4499. return _plugins;
  4500. }
  4501. if (!fn) {
  4502. return _plugins[name];
  4503. }
  4504. _plugins[name] = fn;
  4505. }
  4506. var _language = {};
  4507. function _parseLangKey(key) {
  4508. var match, ns = 'core';
  4509. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4510. ns = match[1];
  4511. key = match[2];
  4512. }
  4513. return { ns : ns, key : key };
  4514. }
  4515. function _lang(mixed, langType) {
  4516. langType = langType === undefined ? K.options.langType : langType;
  4517. if (typeof mixed === 'string') {
  4518. if (!_language[langType]) {
  4519. return 'no language';
  4520. }
  4521. var pos = mixed.length - 1;
  4522. if (mixed.substr(pos) === '.') {
  4523. return _language[langType][mixed.substr(0, pos)];
  4524. }
  4525. var obj = _parseLangKey(mixed);
  4526. return _language[langType][obj.ns][obj.key];
  4527. }
  4528. _each(mixed, function(key, val) {
  4529. var obj = _parseLangKey(key);
  4530. if (!_language[langType]) {
  4531. _language[langType] = {};
  4532. }
  4533. if (!_language[langType][obj.ns]) {
  4534. _language[langType][obj.ns] = {};
  4535. }
  4536. _language[langType][obj.ns][obj.key] = val;
  4537. });
  4538. }
  4539. function _getImageFromRange(range, fn) {
  4540. if (range.collapsed) {
  4541. return;
  4542. }
  4543. range = range.cloneRange().up();
  4544. var sc = range.startContainer, so = range.startOffset;
  4545. if (!_WEBKIT && !range.isControl()) {
  4546. return;
  4547. }
  4548. var img = K(sc.childNodes[so]);
  4549. if (!img || img.name != 'img') {
  4550. return;
  4551. }
  4552. if (fn(img)) {
  4553. return img;
  4554. }
  4555. }
  4556. function _bindContextmenuEvent() {
  4557. var self = this, doc = self.edit.doc;
  4558. K(doc).contextmenu(function(e) {
  4559. if (self.menu) {
  4560. self.hideMenu();
  4561. }
  4562. if (!self.useContextmenu) {
  4563. e.preventDefault();
  4564. return;
  4565. }
  4566. if (self._contextmenus.length === 0) {
  4567. return;
  4568. }
  4569. var maxWidth = 0, items = [];
  4570. _each(self._contextmenus, function() {
  4571. if (this.title == '-') {
  4572. items.push(this);
  4573. return;
  4574. }
  4575. if (this.cond && this.cond()) {
  4576. items.push(this);
  4577. if (this.width && this.width > maxWidth) {
  4578. maxWidth = this.width;
  4579. }
  4580. }
  4581. });
  4582. while (items.length > 0 && items[0].title == '-') {
  4583. items.shift();
  4584. }
  4585. while (items.length > 0 && items[items.length - 1].title == '-') {
  4586. items.pop();
  4587. }
  4588. var prevItem = null;
  4589. _each(items, function(i) {
  4590. if (this.title == '-' && prevItem.title == '-') {
  4591. delete items[i];
  4592. }
  4593. prevItem = this;
  4594. });
  4595. if (items.length > 0) {
  4596. e.preventDefault();
  4597. var pos = K(self.edit.iframe).pos(),
  4598. menu = _menu({
  4599. x : pos.x + e.clientX,
  4600. y : pos.y + e.clientY,
  4601. width : maxWidth,
  4602. css : { visibility: 'hidden' },
  4603. shadowMode : self.shadowMode
  4604. });
  4605. _each(items, function() {
  4606. if (this.title) {
  4607. menu.addItem(this);
  4608. }
  4609. });
  4610. var docEl = _docElement(menu.doc),
  4611. menuHeight = menu.div.height();
  4612. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4613. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4614. }
  4615. menu.div.css('visibility', 'visible');
  4616. self.menu = menu;
  4617. }
  4618. });
  4619. }
  4620. function _bindNewlineEvent() {
  4621. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4622. if (_IE && newlineTag !== 'br') {
  4623. return;
  4624. }
  4625. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4626. return;
  4627. }
  4628. if (_OPERA && _V < 9) {
  4629. return;
  4630. }
  4631. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4632. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4633. function getAncestorTagName(range) {
  4634. var ancestor = K(range.commonAncestor());
  4635. while (ancestor) {
  4636. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4637. break;
  4638. }
  4639. ancestor = ancestor.parent();
  4640. }
  4641. return ancestor.name;
  4642. }
  4643. K(doc).keydown(function(e) {
  4644. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4645. autoImg(self);
  4646. return;
  4647. }
  4648. self.cmd.selection();
  4649. var tagName = getAncestorTagName(self.cmd.range);
  4650. if (tagName == 'marquee' || tagName == 'select') {
  4651. return;
  4652. }
  4653. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4654. e.preventDefault();
  4655. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4656. return;
  4657. }
  4658. if (!pSkipTagMap[tagName]) {
  4659. _nativeCommand(doc, 'formatblock', '<p>');
  4660. }
  4661. });
  4662. K(doc).keyup(function(e) {
  4663. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4664. return;
  4665. }
  4666. if (newlineTag == 'br') {
  4667. return;
  4668. }
  4669. if (_GECKO) {
  4670. var root = self.cmd.commonAncestor('p');
  4671. var a = self.cmd.commonAncestor('a');
  4672. if (a && a.text() == '') {
  4673. a.remove(true);
  4674. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4675. self.cmd.select();
  4676. }
  4677. return;
  4678. }
  4679. self.cmd.selection();
  4680. var tagName = getAncestorTagName(self.cmd.range);
  4681. if (tagName == 'marquee' || tagName == 'select') {
  4682. return;
  4683. }
  4684. if (!pSkipTagMap[tagName]) {
  4685. _nativeCommand(doc, 'formatblock', '<p>');
  4686. }
  4687. var div = self.cmd.commonAncestor('div');
  4688. if (div) {
  4689. var p = K('<p></p>'),
  4690. child = div[0].firstChild;
  4691. while (child) {
  4692. var next = child.nextSibling;
  4693. p.append(child);
  4694. child = next;
  4695. }
  4696. div.before(p);
  4697. div.remove();
  4698. self.cmd.range.selectNodeContents(p[0]);
  4699. self.cmd.select();
  4700. }
  4701. });
  4702. }
  4703. function _bindTabEvent() {
  4704. var self = this, doc = self.edit.doc;
  4705. K(doc).keydown(function(e) {
  4706. if (e.which == 9) {
  4707. e.preventDefault();
  4708. if (self.afterTab) {
  4709. self.afterTab.call(self, e);
  4710. return;
  4711. }
  4712. var cmd = self.cmd, range = cmd.range;
  4713. range.shrink();
  4714. if (range.collapsed && range.startContainer.nodeType == 1) {
  4715. range.insertNode(K('@&nbsp;', doc)[0]);
  4716. cmd.select();
  4717. }
  4718. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4719. }
  4720. });
  4721. }
  4722. function _bindFocusEvent() {
  4723. var self = this;
  4724. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4725. if (self.afterFocus) {
  4726. self.afterFocus.call(self, e);
  4727. }
  4728. }).blur(function(e) {
  4729. if (self.afterBlur) {
  4730. self.afterBlur.call(self, e);
  4731. }
  4732. });
  4733. }
  4734. function _removeBookmarkTag(html) {
  4735. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4736. }
  4737. function _removeTempTag(html) {
  4738. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4739. }
  4740. function _addBookmarkToStack(stack, bookmark) {
  4741. if (stack.length === 0) {
  4742. stack.push(bookmark);
  4743. return;
  4744. }
  4745. var prev = stack[stack.length - 1];
  4746. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4747. stack.push(bookmark);
  4748. }
  4749. }
  4750. function _undoToRedo(fromStack, toStack) {
  4751. var self = this, edit = self.edit,
  4752. body = edit.doc.body,
  4753. range, bookmark;
  4754. if (fromStack.length === 0) {
  4755. return self;
  4756. }
  4757. if (edit.designMode) {
  4758. range = self.cmd.range;
  4759. bookmark = range.createBookmark(true);
  4760. bookmark.html = body.innerHTML;
  4761. } else {
  4762. bookmark = {
  4763. html : body.innerHTML
  4764. };
  4765. }
  4766. _addBookmarkToStack(toStack, bookmark);
  4767. var prev = fromStack.pop();
  4768. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4769. prev = fromStack.pop();
  4770. }
  4771. if (edit.designMode) {
  4772. edit.html(prev.html);
  4773. if (prev.start) {
  4774. range.moveToBookmark(prev);
  4775. self.select();
  4776. }
  4777. } else {
  4778. K(body).html(_removeBookmarkTag(prev.html));
  4779. }
  4780. return self;
  4781. }
  4782. function KEditor(options) {
  4783. var self = this;
  4784. self.options = {};
  4785. function setOption(key, val) {
  4786. if (KEditor.prototype[key] === undefined) {
  4787. self[key] = val;
  4788. }
  4789. self.options[key] = val;
  4790. }
  4791. _each(options, function(key, val) {
  4792. setOption(key, options[key]);
  4793. });
  4794. _each(K.options, function(key, val) {
  4795. if (self[key] === undefined) {
  4796. setOption(key, val);
  4797. }
  4798. });
  4799. var se = K(self.srcElement || '<textarea/>');
  4800. if (!self.width) {
  4801. self.width = se[0].style.width || se.width();
  4802. }
  4803. if (!self.height) {
  4804. self.height = se[0].style.height || se.height();
  4805. }
  4806. setOption('width', _undef(self.width, self.minWidth));
  4807. setOption('height', _undef(self.height, self.minHeight));
  4808. setOption('width', _addUnit(self.width));
  4809. setOption('height', _addUnit(self.height));
  4810. if (_MOBILE && (!_IOS || _V < 534)) {
  4811. self.designMode = false;
  4812. }
  4813. self.srcElement = se;
  4814. self.initContent = '';
  4815. self.plugin = {};
  4816. self.isCreated = false;
  4817. self._handlers = {};
  4818. self._contextmenus = [];
  4819. self._undoStack = [];
  4820. self._redoStack = [];
  4821. self._firstAddBookmark = true;
  4822. self.menu = self.contextmenu = null;
  4823. self.dialogs = [];
  4824. }
  4825. KEditor.prototype = {
  4826. lang : function(mixed) {
  4827. return _lang(mixed, this.langType);
  4828. },
  4829. loadPlugin : function(name, fn) {
  4830. var self = this;
  4831. var _pluginStatus = this._pluginStatus;
  4832. if (!_pluginStatus) {
  4833. _pluginStatus = this._pluginStatus = {};
  4834. }
  4835. if (_plugins[name]) {
  4836. if (!_isFunction(_plugins[name])) {
  4837. setTimeout(function() {
  4838. self.loadPlugin(name, fn);
  4839. }, 100);
  4840. return self;
  4841. }
  4842. if(!_pluginStatus[name]) {
  4843. _plugins[name].call(self, KindEditor);
  4844. _pluginStatus[name] = 'inited';
  4845. }
  4846. if (fn) {
  4847. fn.call(self);
  4848. }
  4849. return self;
  4850. }
  4851. _plugins[name] = 'loading';
  4852. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4853. setTimeout(function() {
  4854. if (_plugins[name]) {
  4855. self.loadPlugin(name, fn);
  4856. }
  4857. }, 0);
  4858. });
  4859. return self;
  4860. },
  4861. handler : function(key, fn) {
  4862. var self = this;
  4863. if (!self._handlers[key]) {
  4864. self._handlers[key] = [];
  4865. }
  4866. if (_isFunction(fn)) {
  4867. self._handlers[key].push(fn);
  4868. return self;
  4869. }
  4870. _each(self._handlers[key], function() {
  4871. fn = this.call(self, fn);
  4872. });
  4873. return fn;
  4874. },
  4875. clickToolbar : function(name, fn) {
  4876. var self = this, key = 'clickToolbar' + name;
  4877. if (fn === undefined) {
  4878. if (self._handlers[key]) {
  4879. return self.handler(key);
  4880. }
  4881. self.loadPlugin(name, function() {
  4882. self.handler(key);
  4883. });
  4884. return self;
  4885. }
  4886. return self.handler(key, fn);
  4887. },
  4888. updateState : function() {
  4889. var self = this;
  4890. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4891. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4892. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4893. });
  4894. return self;
  4895. },
  4896. addContextmenu : function(item) {
  4897. this._contextmenus.push(item);
  4898. return this;
  4899. },
  4900. afterCreate : function(fn) {
  4901. return this.handler('afterCreate', fn);
  4902. },
  4903. beforeRemove : function(fn) {
  4904. return this.handler('beforeRemove', fn);
  4905. },
  4906. beforeGetHtml : function(fn) {
  4907. return this.handler('beforeGetHtml', fn);
  4908. },
  4909. beforeSetHtml : function(fn) {
  4910. return this.handler('beforeSetHtml', fn);
  4911. },
  4912. afterSetHtml : function(fn) {
  4913. return this.handler('afterSetHtml', fn);
  4914. },
  4915. create : function() {
  4916. var self = this, fullscreenMode = self.fullscreenMode;
  4917. if (self.isCreated) {
  4918. return self;
  4919. }
  4920. if (self.srcElement.data('kindeditor')) {
  4921. return self;
  4922. }
  4923. self.srcElement.data('kindeditor', 'true');
  4924. if (fullscreenMode) {
  4925. _docElement().style.overflow = 'hidden';
  4926. } else {
  4927. _docElement().style.overflow = '';
  4928. }
  4929. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4930. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4931. if ((_IE && _V < 8) || _QUIRKS) {
  4932. height = _addUnit(_removeUnit(height) + 2);
  4933. }
  4934. var container = self.container = K(self.layout);
  4935. if (fullscreenMode) {
  4936. K(document.body).append(container);
  4937. } else {
  4938. self.srcElement.before(container);
  4939. }
  4940. var toolbarDiv = K('.toolbar', container),
  4941. editDiv = K('.edit', container),
  4942. statusbar = self.statusbar = K('.statusbar', container);
  4943. container.removeClass('container')
  4944. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4945. if (fullscreenMode) {
  4946. container.css({
  4947. position : 'absolute',
  4948. left : 0,
  4949. top : 0,
  4950. 'z-index' : 811211
  4951. });
  4952. if (!_GECKO) {
  4953. self._scrollPos = _getScrollPos();
  4954. }
  4955. window.scrollTo(0, 0);
  4956. K(document.body).css({
  4957. 'height' : '1px',
  4958. 'overflow' : 'hidden'
  4959. });
  4960. K(document.body.parentNode).css('overflow', 'hidden');
  4961. self._fullscreenExecuted = true;
  4962. } else {
  4963. if (self._fullscreenExecuted) {
  4964. K(document.body).css({
  4965. 'height' : '',
  4966. 'overflow' : ''
  4967. });
  4968. K(document.body.parentNode).css('overflow', '');
  4969. }
  4970. if (self._scrollPos) {
  4971. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  4972. }
  4973. }
  4974. var htmlList = [];
  4975. K.each(self.items, function(i, name) {
  4976. if (name == '|') {
  4977. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  4978. } else if (name == '/') {
  4979. htmlList.push('<div class="ke-hr"></div>');
  4980. } else {
  4981. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  4982. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  4983. }
  4984. });
  4985. var toolbar = self.toolbar = _toolbar({
  4986. src : toolbarDiv,
  4987. html : htmlList.join(''),
  4988. noDisableItems : self.noDisableItems,
  4989. click : function(e, name) {
  4990. e.stop();
  4991. if (self.menu) {
  4992. var menuName = self.menu.name;
  4993. self.hideMenu();
  4994. if (menuName === name) {
  4995. return;
  4996. }
  4997. }
  4998. self.clickToolbar(name);
  4999. }
  5000. });
  5001. var editHeight = _removeUnit(height) - toolbar.div.height();
  5002. var edit = self.edit = _edit({
  5003. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  5004. src : editDiv,
  5005. srcElement : self.srcElement,
  5006. designMode : self.designMode,
  5007. themesPath : self.themesPath,
  5008. bodyClass : self.bodyClass,
  5009. cssPath : self.cssPath,
  5010. cssData : self.cssData,
  5011. beforeGetHtml : function(html) {
  5012. html = self.beforeGetHtml(html);
  5013. html = _removeBookmarkTag(_removeTempTag(html));
  5014. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  5015. },
  5016. beforeSetHtml : function(html) {
  5017. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  5018. return self.beforeSetHtml(html);
  5019. },
  5020. afterSetHtml : function() {
  5021. self.edit = edit = this;
  5022. self.afterSetHtml();
  5023. },
  5024. afterCreate : function() {
  5025. self.edit = edit = this;
  5026. self.cmd = edit.cmd;
  5027. self._docMousedownFn = function(e) {
  5028. if (self.menu) {
  5029. self.hideMenu();
  5030. }
  5031. };
  5032. K(edit.doc, document).mousedown(self._docMousedownFn);
  5033. _bindContextmenuEvent.call(self);
  5034. _bindNewlineEvent.call(self);
  5035. _bindTabEvent.call(self);
  5036. _bindFocusEvent.call(self);
  5037. edit.afterChange(function(e) {
  5038. if (!edit.designMode) {
  5039. return;
  5040. }
  5041. self.updateState();
  5042. self.addBookmark();
  5043. if (self.options.afterChange) {
  5044. self.options.afterChange.call(self);
  5045. }
  5046. });
  5047. edit.textarea.keyup(function(e) {
  5048. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5049. if (self.options.afterChange) {
  5050. self.options.afterChange.call(self);
  5051. }
  5052. }
  5053. });
  5054. if (self.readonlyMode) {
  5055. self.readonly();
  5056. }
  5057. self.isCreated = true;
  5058. if (self.initContent === '') {
  5059. self.initContent = self.html();
  5060. }
  5061. if (self._undoStack.length > 0) {
  5062. var prev = self._undoStack.pop();
  5063. if (prev.start) {
  5064. self.html(prev.html);
  5065. edit.cmd.range.moveToBookmark(prev);
  5066. self.select();
  5067. }
  5068. }
  5069. self.afterCreate();
  5070. if (self.options.afterCreate) {
  5071. self.options.afterCreate.call(self);
  5072. }
  5073. }
  5074. });
  5075. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5076. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5077. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5078. if (self._fullscreenResizeHandler) {
  5079. K(window).unbind('resize', self._fullscreenResizeHandler);
  5080. self._fullscreenResizeHandler = null;
  5081. }
  5082. function initResize() {
  5083. if (statusbar.height() === 0) {
  5084. setTimeout(initResize, 100);
  5085. return;
  5086. }
  5087. self.resize(width, height, false);
  5088. }
  5089. initResize();
  5090. if (fullscreenMode) {
  5091. self._fullscreenResizeHandler = function(e) {
  5092. if (self.isCreated) {
  5093. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5094. }
  5095. };
  5096. K(window).bind('resize', self._fullscreenResizeHandler);
  5097. toolbar.select('fullscreen');
  5098. statusbar.first().css('visibility', 'hidden');
  5099. statusbar.last().css('visibility', 'hidden');
  5100. } else {
  5101. if (_GECKO) {
  5102. K(window).bind('scroll', function(e) {
  5103. self._scrollPos = _getScrollPos();
  5104. });
  5105. }
  5106. if (self.resizeType > 0) {
  5107. _drag({
  5108. moveEl : container,
  5109. clickEl : statusbar,
  5110. moveFn : function(x, y, width, height, diffX, diffY) {
  5111. height += diffY;
  5112. self.resize(null, height);
  5113. }
  5114. });
  5115. } else {
  5116. statusbar.first().css('visibility', 'hidden');
  5117. }
  5118. if (self.resizeType === 2) {
  5119. _drag({
  5120. moveEl : container,
  5121. clickEl : statusbar.last(),
  5122. moveFn : function(x, y, width, height, diffX, diffY) {
  5123. width += diffX;
  5124. height += diffY;
  5125. self.resize(width, height);
  5126. }
  5127. });
  5128. } else {
  5129. statusbar.last().css('visibility', 'hidden');
  5130. }
  5131. }
  5132. return self;
  5133. },
  5134. remove : function() {
  5135. var self = this;
  5136. if (!self.isCreated) {
  5137. return self;
  5138. }
  5139. self.beforeRemove();
  5140. self.srcElement.data('kindeditor', '');
  5141. if (self.menu) {
  5142. self.hideMenu();
  5143. }
  5144. _each(self.dialogs, function() {
  5145. self.hideDialog();
  5146. });
  5147. K(document).unbind('mousedown', self._docMousedownFn);
  5148. self.toolbar.remove();
  5149. self.edit.remove();
  5150. self.statusbar.last().unbind();
  5151. self.statusbar.unbind();
  5152. self.container.remove();
  5153. self.container = self.toolbar = self.edit = self.menu = null;
  5154. self.dialogs = [];
  5155. self.isCreated = false;
  5156. return self;
  5157. },
  5158. resize : function(width, height, updateProp) {
  5159. var self = this;
  5160. updateProp = _undef(updateProp, true);
  5161. if (width) {
  5162. if (!/%/.test(width)) {
  5163. width = _removeUnit(width);
  5164. width = width < self.minWidth ? self.minWidth : width;
  5165. }
  5166. self.container.css('width', _addUnit(width));
  5167. if (updateProp) {
  5168. self.width = _addUnit(width);
  5169. }
  5170. }
  5171. if (height) {
  5172. height = _removeUnit(height);
  5173. var editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5174. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5175. self.edit.setHeight(editHeight);
  5176. if (updateProp) {
  5177. self.height = _addUnit(height);
  5178. }
  5179. }
  5180. return self;
  5181. },
  5182. select : function() {
  5183. this.isCreated && this.cmd.select();
  5184. return this;
  5185. },
  5186. html : function(val) {
  5187. var self = this;
  5188. if (val === undefined) {
  5189. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5190. }
  5191. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5192. if (self.isCreated) {
  5193. self.cmd.selection();
  5194. }
  5195. return self;
  5196. },
  5197. fullHtml : function() {
  5198. return this.isCreated ? this.edit.html(undefined, true) : '';
  5199. },
  5200. text : function(val) {
  5201. var self = this;
  5202. if (val === undefined) {
  5203. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5204. } else {
  5205. return self.html(_escape(val));
  5206. }
  5207. },
  5208. isEmpty : function() {
  5209. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5210. },
  5211. isDirty : function() {
  5212. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5213. },
  5214. selectedHtml : function() {
  5215. var val = this.isCreated ? this.cmd.range.html() : '';
  5216. val = _removeBookmarkTag(_removeTempTag(val));
  5217. return val;
  5218. },
  5219. count : function(mode) {
  5220. var self = this;
  5221. mode = (mode || 'html').toLowerCase();
  5222. if (mode === 'html') {
  5223. return self.html().length;
  5224. }
  5225. if (mode === 'text') {
  5226. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5227. }
  5228. return 0;
  5229. },
  5230. exec : function(key) {
  5231. key = key.toLowerCase();
  5232. var self = this, cmd = self.cmd,
  5233. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5234. if (changeFlag) {
  5235. self.addBookmark(false);
  5236. }
  5237. cmd[key].apply(cmd, _toArray(arguments, 1));
  5238. if (changeFlag) {
  5239. self.updateState();
  5240. self.addBookmark(false);
  5241. if (self.options.afterChange) {
  5242. self.options.afterChange.call(self);
  5243. }
  5244. }
  5245. return self;
  5246. },
  5247. insertHtml : function(val, quickMode) {
  5248. if (!this.isCreated) {
  5249. return this;
  5250. }
  5251. val = this.beforeSetHtml(val);
  5252. this.exec('inserthtml', val, quickMode);
  5253. return this;
  5254. },
  5255. appendHtml : function(val) {
  5256. this.html(this.html() + val);
  5257. if (this.isCreated) {
  5258. var cmd = this.cmd;
  5259. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5260. cmd.select();
  5261. }
  5262. return this;
  5263. },
  5264. sync : function() {
  5265. _elementVal(this.srcElement, this.html());
  5266. return this;
  5267. },
  5268. focus : function() {
  5269. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5270. return this;
  5271. },
  5272. blur : function() {
  5273. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5274. return this;
  5275. },
  5276. addBookmark : function(checkSize) {
  5277. checkSize = _undef(checkSize, true);
  5278. var self = this, edit = self.edit,
  5279. body = edit.doc.body,
  5280. html = _removeTempTag(body.innerHTML), bookmark;
  5281. if (checkSize && self._undoStack.length > 0) {
  5282. var prev = self._undoStack[self._undoStack.length - 1];
  5283. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5284. return self;
  5285. }
  5286. }
  5287. if (edit.designMode && !self._firstAddBookmark) {
  5288. var range = self.cmd.range;
  5289. bookmark = range.createBookmark(true);
  5290. bookmark.html = _removeTempTag(body.innerHTML);
  5291. range.moveToBookmark(bookmark);
  5292. } else {
  5293. bookmark = {
  5294. html : html
  5295. };
  5296. }
  5297. self._firstAddBookmark = false;
  5298. _addBookmarkToStack(self._undoStack, bookmark);
  5299. return self;
  5300. },
  5301. undo : function() {
  5302. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5303. },
  5304. redo : function() {
  5305. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5306. },
  5307. fullscreen : function(bool) {
  5308. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5309. this.addBookmark(false);
  5310. return this.remove().create();
  5311. },
  5312. readonly : function(isReadonly) {
  5313. isReadonly = _undef(isReadonly, true);
  5314. var self = this, edit = self.edit, doc = edit.doc;
  5315. if (self.designMode) {
  5316. self.toolbar.disableAll(isReadonly, []);
  5317. } else {
  5318. _each(self.noDisableItems, function() {
  5319. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5320. });
  5321. }
  5322. if (_IE) {
  5323. doc.body.contentEditable = !isReadonly;
  5324. } else {
  5325. doc.designMode = isReadonly ? 'off' : 'on';
  5326. }
  5327. edit.textarea[0].disabled = isReadonly;
  5328. },
  5329. createMenu : function(options) {
  5330. var self = this,
  5331. name = options.name,
  5332. knode = self.toolbar.get(name),
  5333. pos = knode.pos();
  5334. options.x = pos.x;
  5335. options.y = pos.y + knode.height();
  5336. options.z = self.options.zIndex;
  5337. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5338. if (options.selectedColor !== undefined) {
  5339. options.cls = 'ke-colorpicker-' + self.themeType;
  5340. options.noColor = self.lang('noColor');
  5341. self.menu = _colorpicker(options);
  5342. } else {
  5343. options.cls = 'ke-menu-' + self.themeType;
  5344. options.centerLineMode = false;
  5345. self.menu = _menu(options);
  5346. }
  5347. return self.menu;
  5348. },
  5349. hideMenu : function() {
  5350. this.menu.remove();
  5351. this.menu = null;
  5352. return this;
  5353. },
  5354. hideContextmenu : function() {
  5355. this.contextmenu.remove();
  5356. this.contextmenu = null;
  5357. return this;
  5358. },
  5359. createDialog : function(options) {
  5360. var self = this, name = options.name;
  5361. options.z = self.options.zIndex;
  5362. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5363. options.closeBtn = _undef(options.closeBtn, {
  5364. name : self.lang('close'),
  5365. click : function(e) {
  5366. self.hideDialog();
  5367. if (_IE && self.cmd) {
  5368. self.cmd.select();
  5369. }
  5370. }
  5371. });
  5372. options.noBtn = _undef(options.noBtn, {
  5373. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5374. click : function(e) {
  5375. self.hideDialog();
  5376. if (_IE && self.cmd) {
  5377. self.cmd.select();
  5378. }
  5379. }
  5380. });
  5381. if (self.dialogAlignType != 'page') {
  5382. options.alignEl = self.container;
  5383. }
  5384. options.cls = 'ke-dialog-' + self.themeType;
  5385. if (self.dialogs.length > 0) {
  5386. var firstDialog = self.dialogs[0],
  5387. parentDialog = self.dialogs[self.dialogs.length - 1];
  5388. firstDialog.setMaskIndex(parentDialog.z + 2);
  5389. options.z = parentDialog.z + 3;
  5390. options.showMask = false;
  5391. }
  5392. var dialog = _dialog(options);
  5393. self.dialogs.push(dialog);
  5394. return dialog;
  5395. },
  5396. hideDialog : function() {
  5397. var self = this;
  5398. if (self.dialogs.length > 0) {
  5399. self.dialogs.pop().remove();
  5400. }
  5401. if (self.dialogs.length > 0) {
  5402. var firstDialog = self.dialogs[0],
  5403. parentDialog = self.dialogs[self.dialogs.length - 1];
  5404. firstDialog.setMaskIndex(parentDialog.z - 1);
  5405. }
  5406. return self;
  5407. },
  5408. errorDialog : function(html) {
  5409. var self = this;
  5410. var dialog = self.createDialog({
  5411. width : 750,
  5412. title : self.lang('uploadError'),
  5413. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5414. });
  5415. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5416. doc.open();
  5417. doc.write(html);
  5418. doc.close();
  5419. K(doc.body).css('background-color', '#FFF');
  5420. iframe[0].contentWindow.focus();
  5421. return self;
  5422. }
  5423. };
  5424. function _editor(options) {
  5425. return new KEditor(options);
  5426. }
  5427. var _instances = [];
  5428. function _create(expr, options) {
  5429. options = options || {};
  5430. options.basePath = _undef(options.basePath, K.basePath);
  5431. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5432. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5433. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5434. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5435. var themeType = _undef(options.themeType, K.options.themeType);
  5436. _loadStyle(options.themesPath + 'default/default.css');
  5437. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5438. }
  5439. function create(editor) {
  5440. _each(_plugins, function(name, fn) {
  5441. if (_isFunction(fn)) {
  5442. fn.call(editor, KindEditor);
  5443. if (!editor._pluginStatus) {
  5444. editor._pluginStatus = {};
  5445. }
  5446. editor._pluginStatus[name] = 'inited';
  5447. }
  5448. });
  5449. return editor.create();
  5450. }
  5451. var knode = K(expr);
  5452. if (!knode || knode.length === 0) {
  5453. return;
  5454. }
  5455. if (knode.length > 1) {
  5456. knode.each(function() {
  5457. _create(this, options);
  5458. });
  5459. return _instances[0];
  5460. }
  5461. options.srcElement = knode[0];
  5462. var editor = new KEditor(options);
  5463. _instances.push(editor);
  5464. if (_language[editor.langType]) {
  5465. return create(editor);
  5466. }
  5467. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5468. create(editor);
  5469. });
  5470. return editor;
  5471. }
  5472. function _eachEditor(expr, fn) {
  5473. K(expr).each(function(i, el) {
  5474. K.each(_instances, function(j, editor) {
  5475. if (editor && editor.srcElement[0] == el) {
  5476. fn.call(editor, j);
  5477. return false;
  5478. }
  5479. });
  5480. });
  5481. }
  5482. K.remove = function(expr) {
  5483. _eachEditor(expr, function(i) {
  5484. this.remove();
  5485. _instances.splice(i, 1);
  5486. });
  5487. };
  5488. K.sync = function(expr) {
  5489. _eachEditor(expr, function() {
  5490. this.sync();
  5491. });
  5492. };
  5493. K.html = function(expr, val) {
  5494. _eachEditor(expr, function() {
  5495. this.html(val);
  5496. });
  5497. };
  5498. K.insertHtml = function(expr, val) {
  5499. _eachEditor(expr, function() {
  5500. this.insertHtml(val);
  5501. });
  5502. };
  5503. K.appendHtml = function(expr, val) {
  5504. _eachEditor(expr, function() {
  5505. this.appendHtml(val);
  5506. });
  5507. };
  5508. if (_IE && _V < 7) {
  5509. _nativeCommand(document, 'BackgroundImageCache', true);
  5510. }
  5511. K.EditorClass = KEditor;
  5512. K.editor = _editor;
  5513. K.create = _create;
  5514. K.instances = _instances;
  5515. K.plugin = _plugin;
  5516. K.lang = _lang;
  5517. _plugin('core', function(K) {
  5518. var self = this,
  5519. shortcutKeys = {
  5520. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5521. };
  5522. self.afterSetHtml(function() {
  5523. if (self.options.afterChange) {
  5524. self.options.afterChange.call(self);
  5525. }
  5526. });
  5527. self.afterCreate(function() {
  5528. if (self.syncType != 'form') {
  5529. return;
  5530. }
  5531. var el = K(self.srcElement), hasForm = false;
  5532. while ((el = el.parent())) {
  5533. if (el.name == 'form') {
  5534. hasForm = true;
  5535. break;
  5536. }
  5537. }
  5538. if (hasForm) {
  5539. el.bind('submit', function(e) {
  5540. self.sync();
  5541. K(window).bind('unload', function() {
  5542. self.edit.textarea.remove();
  5543. });
  5544. });
  5545. var resetBtn = K('[type="reset"]', el);
  5546. resetBtn.click(function() {
  5547. self.html(self.initContent);
  5548. self.cmd.selection();
  5549. });
  5550. self.beforeRemove(function() {
  5551. el.unbind();
  5552. resetBtn.unbind();
  5553. });
  5554. }
  5555. });
  5556. self.clickToolbar('source', function() {
  5557. if (self.edit.designMode) {
  5558. self.toolbar.disableAll(true);
  5559. self.edit.design(false);
  5560. self.toolbar.select('source');
  5561. } else {
  5562. self.toolbar.disableAll(false);
  5563. self.edit.design(true);
  5564. self.toolbar.unselect('source');
  5565. if (_GECKO) {
  5566. setTimeout(function() {
  5567. self.cmd.selection();
  5568. }, 0);
  5569. } else {
  5570. self.cmd.selection();
  5571. }
  5572. }
  5573. self.designMode = self.edit.designMode;
  5574. });
  5575. self.afterCreate(function() {
  5576. if (!self.designMode) {
  5577. self.toolbar.disableAll(true).select('source');
  5578. }
  5579. });
  5580. self.clickToolbar('fullscreen', function() {
  5581. self.fullscreen();
  5582. });
  5583. if (self.fullscreenShortcut) {
  5584. var loaded = false;
  5585. self.afterCreate(function() {
  5586. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5587. if (e.which == 27) {
  5588. setTimeout(function() {
  5589. self.fullscreen();
  5590. }, 0);
  5591. }
  5592. });
  5593. if (loaded) {
  5594. if (_IE && !self.designMode) {
  5595. return;
  5596. }
  5597. self.focus();
  5598. }
  5599. if (!loaded) {
  5600. loaded = true;
  5601. }
  5602. });
  5603. }
  5604. _each('undo,redo'.split(','), function(i, name) {
  5605. if (shortcutKeys[name]) {
  5606. self.afterCreate(function() {
  5607. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5608. self.clickToolbar(name);
  5609. });
  5610. });
  5611. }
  5612. self.clickToolbar(name, function() {
  5613. self[name]();
  5614. });
  5615. });
  5616. self.clickToolbar('formatblock', function() {
  5617. var blocks = self.lang('formatblock.formatBlock'),
  5618. heights = {
  5619. h1 : 28,
  5620. h2 : 24,
  5621. h3 : 18,
  5622. H4 : 14,
  5623. p : 12
  5624. },
  5625. curVal = self.cmd.val('formatblock'),
  5626. menu = self.createMenu({
  5627. name : 'formatblock',
  5628. width : self.langType == 'en' ? 200 : 150
  5629. });
  5630. _each(blocks, function(key, val) {
  5631. var style = 'font-size:' + heights[key] + 'px;';
  5632. if (key.charAt(0) === 'h') {
  5633. style += 'font-weight:bold;';
  5634. }
  5635. menu.addItem({
  5636. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5637. height : heights[key] + 12,
  5638. checked : (curVal === key || curVal === val),
  5639. click : function() {
  5640. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5641. }
  5642. });
  5643. });
  5644. });
  5645. self.clickToolbar('fontname', function() {
  5646. var curVal = self.cmd.val('fontname'),
  5647. menu = self.createMenu({
  5648. name : 'fontname',
  5649. width : 150
  5650. });
  5651. _each(self.lang('fontname.fontName'), function(key, val) {
  5652. menu.addItem({
  5653. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5654. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5655. click : function() {
  5656. self.exec('fontname', key).hideMenu();
  5657. }
  5658. });
  5659. });
  5660. });
  5661. self.clickToolbar('fontsize', function() {
  5662. var curVal = self.cmd.val('fontsize'),
  5663. menu = self.createMenu({
  5664. name : 'fontsize',
  5665. width : 150
  5666. });
  5667. _each(self.fontSizeTable, function(i, val) {
  5668. menu.addItem({
  5669. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5670. height : _removeUnit(val) + 12,
  5671. checked : curVal === val,
  5672. click : function() {
  5673. self.exec('fontsize', val).hideMenu();
  5674. }
  5675. });
  5676. });
  5677. });
  5678. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5679. self.clickToolbar(name, function() {
  5680. self.createMenu({
  5681. name : name,
  5682. selectedColor : self.cmd.val(name) || 'default',
  5683. colors : self.colorTable,
  5684. click : function(color) {
  5685. self.exec(name, color).hideMenu();
  5686. }
  5687. });
  5688. });
  5689. });
  5690. _each(('cut,copy,paste').split(','), function(i, name) {
  5691. self.clickToolbar(name, function() {
  5692. self.focus();
  5693. try {
  5694. self.exec(name, null);
  5695. } catch(e) {
  5696. alert(self.lang(name + 'Error'));
  5697. }
  5698. });
  5699. });
  5700. self.clickToolbar('about', function() {
  5701. var html = '<div style="margin:20px;">' +
  5702. '<div>KindEditor ' + _VERSION + '</div>' +
  5703. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5704. '</div>';
  5705. self.createDialog({
  5706. name : 'about',
  5707. width : 350,
  5708. title : self.lang('about'),
  5709. body : html
  5710. });
  5711. });
  5712. self.plugin.getSelectedLink = function() {
  5713. return self.cmd.commonAncestor('a');
  5714. };
  5715. self.plugin.getSelectedImage = function() {
  5716. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5717. return !/^ke-\w+$/i.test(img[0].className);
  5718. });
  5719. };
  5720. self.plugin.getSelectedFlash = function() {
  5721. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5722. return img[0].className == 'ke-flash';
  5723. });
  5724. };
  5725. self.plugin.getSelectedMedia = function() {
  5726. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5727. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5728. });
  5729. };
  5730. self.plugin.getSelectedAnchor = function() {
  5731. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5732. return img[0].className == 'ke-anchor';
  5733. });
  5734. };
  5735. _each('link,image,flash,media,anchor'.split(','), function(i, name) {
  5736. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5737. _each('edit,delete'.split(','), function(j, val) {
  5738. self.addContextmenu({
  5739. title : self.lang(val + uName),
  5740. click : function() {
  5741. self.loadPlugin(name, function() {
  5742. self.plugin[name][val]();
  5743. self.hideMenu();
  5744. });
  5745. },
  5746. cond : self.plugin['getSelected' + uName],
  5747. width : 150,
  5748. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5749. });
  5750. });
  5751. self.addContextmenu({ title : '-' });
  5752. });
  5753. self.plugin.getSelectedTable = function() {
  5754. return self.cmd.commonAncestor('table');
  5755. };
  5756. self.plugin.getSelectedRow = function() {
  5757. return self.cmd.commonAncestor('tr');
  5758. };
  5759. self.plugin.getSelectedCell = function() {
  5760. return self.cmd.commonAncestor('td');
  5761. };
  5762. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5763. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5764. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5765. self.addContextmenu({
  5766. title : self.lang('table' + val),
  5767. click : function() {
  5768. self.loadPlugin('table', function() {
  5769. self.plugin.table[val]();
  5770. self.hideMenu();
  5771. });
  5772. },
  5773. cond : cond,
  5774. width : 170,
  5775. iconClass : 'ke-icon-table' + val
  5776. });
  5777. });
  5778. self.addContextmenu({ title : '-' });
  5779. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5780. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5781. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5782. if (shortcutKeys[name]) {
  5783. self.afterCreate(function() {
  5784. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5785. self.cmd.selection();
  5786. self.clickToolbar(name);
  5787. });
  5788. });
  5789. }
  5790. self.clickToolbar(name, function() {
  5791. self.focus().exec(name, null);
  5792. });
  5793. });
  5794. self.afterCreate(function() {
  5795. var doc = self.edit.doc, cmd, bookmark, div,
  5796. cls = '__kindeditor_paste__', pasting = false;
  5797. function movePastedData() {
  5798. cmd.range.moveToBookmark(bookmark);
  5799. cmd.select();
  5800. if (_WEBKIT) {
  5801. K('div.' + cls, div).each(function() {
  5802. K(this).after('<br />').remove(true);
  5803. });
  5804. K('span.Apple-style-span', div).remove(true);
  5805. K('span.Apple-tab-span', div).remove(true);
  5806. K('span[style]', div).each(function() {
  5807. if (K(this).css('white-space') == 'nowrap') {
  5808. K(this).remove(true);
  5809. }
  5810. });
  5811. K('meta', div).remove();
  5812. }
  5813. var html = div[0].innerHTML;
  5814. div.remove();
  5815. if (html === '') {
  5816. return;
  5817. }
  5818. if (_WEBKIT) {
  5819. html = html.replace(/(<br>)\1/ig, '$1');
  5820. }
  5821. if (self.pasteType === 2) {
  5822. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5823. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5824. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5825. } else {
  5826. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5827. html = self.beforeSetHtml(html);
  5828. }
  5829. }
  5830. if (self.pasteType === 1) {
  5831. html = html.replace(/&nbsp;/ig, ' ');
  5832. html = html.replace(/\n\s*\n/g, '\n');
  5833. html = html.replace(/<br[^>]*>/ig, '\n');
  5834. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5835. html = html.replace(/<[^>]+>/g, '');
  5836. html = html.replace(/ {2}/g, ' &nbsp;');
  5837. if (self.newlineTag == 'p') {
  5838. if (/\n/.test(html)) {
  5839. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5840. }
  5841. } else {
  5842. html = html.replace(/\n/g, '<br />$&');
  5843. }
  5844. }
  5845. self.insertHtml(html, true);
  5846. }
  5847. K(doc.body).bind('paste', function(e){
  5848. //处理IE11,Chrome粘贴图片上传
  5849. function dopasteImg() {
  5850. //debugger;
  5851. var file = null;
  5852. if (window.clipboardData) {//ie
  5853. if (clipboardData.files && clipboardData.files.length)//IE11
  5854. file = clipboardData.files[0];
  5855. else if (!clipboardData.getData("text") && !clipboardData.getData("url")) {
  5856. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5857. return true;
  5858. }
  5859. } else {
  5860. if (e.event.clipboardData.items)//chrome
  5861. for (var i = 0; i < e.event.clipboardData.items.length; i++) {
  5862. if (e.event.clipboardData.items[i].kind === "file") {
  5863. file = e.event.clipboardData.items[i];
  5864. break;
  5865. }
  5866. }
  5867. if (file == null) {
  5868. if (!e.event.clipboardData.getData("url") && !e.event.clipboardData.getData("text")) {
  5869. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5870. return true;
  5871. }
  5872. }
  5873. }
  5874. if (file) {
  5875. if (!K.undef(self.allowImageUpload, true)) {
  5876. alert("编辑器禁止上传图片,请与有关人员联系!");
  5877. return true;
  5878. }
  5879. //获取File Blob
  5880. //debugger;
  5881. var blb;
  5882. if (file.getAsFile) {//Chrome
  5883. blb = file.getAsFile();
  5884. if (blb.size === 0) {
  5885. alert("不能获取剪切板中的" + (file.type.indexOf("image/") === 0 ? "图像" : "文件")
  5886. +"\n如果是从OutLook中复制的,请换其他程序,如Word");
  5887. return true;
  5888. }
  5889. sendfile(blb, file.type);
  5890. } else {
  5891. var fr = new FileReader();
  5892. if (fr.readAsArrayBuffer) {//ie
  5893. fr.onloadend = function (evt) {
  5894. blb = evt.target.result;
  5895. sendfile(blb, file.type);
  5896. }
  5897. fr.readAsArrayBuffer(file);
  5898. }
  5899. }
  5900. function sendfile(b, t) {
  5901. var xhr = new XMLHttpRequest();
  5902. var formData = new FormData();
  5903. var isImg = t.indexOf("image/") === 0;
  5904. //formData.append('imgFile', file,"untitled." + t.split('/')[1]);
  5905. //formData.append('imgFile', b);
  5906. var myBlob = new Blob([b], { "type": t });
  5907. formData.append(self.filePostName, myBlob, "untitled." + t.split('/')[1]);
  5908. //formData.append('imgFile', b);
  5909. formData.append('dir', isImg ? 'image' : 'file');
  5910. xhr.open('POST', self.uploadJson);
  5911. xhr.onreadystatechange = function () {
  5912. if (xhr.readyState == 4&&xhr.status == 200) {
  5913. // if (fn) {
  5914. var data = _trim(xhr.responseText);
  5915. //if (dataType == 'json') {
  5916. data = _json(data);
  5917. if (data.error) {
  5918. if (typeof ($) !== "undefined" && $.messager && $.messager.alert) {
  5919. $.messager.alert('Error', data.message, 'warning');
  5920. } else {
  5921. alert(data.message);
  5922. }
  5923. } else {
  5924. //self.exec('insertimage', url, title, width, height, border, align);
  5925. if(K.undef(self.formatUploadUrl, true))
  5926. data.url =K.formatUrl(data.url, 'absolute');
  5927. self.exec('insertimage', data.url, "from clipboard", undefined, undefined, undefined, undefined);
  5928. }
  5929. //}
  5930. // fn(data);
  5931. // }
  5932. }
  5933. }
  5934. xhr.send(formData);
  5935. }
  5936. return true;
  5937. }
  5938. }
  5939. //debugger;
  5940. if (dopasteImg())
  5941. e.stop();
  5942. //处理粘贴结束5825
  5943. if (self.pasteType === 0) {
  5944. e.stop();
  5945. return;
  5946. }
  5947. if (pasting) {
  5948. return;
  5949. }
  5950. pasting = true;
  5951. K('div.' + cls, doc).remove();
  5952. cmd = self.cmd.selection();
  5953. bookmark = cmd.range.createBookmark();
  5954. div = K('<div class="' + cls + '"></div>', doc).css({
  5955. position : 'absolute',
  5956. width : '1px',
  5957. height : '1px',
  5958. overflow : 'hidden',
  5959. left : '-1981px',
  5960. top : K(bookmark.start).pos().y + 'px',
  5961. 'white-space' : 'nowrap'
  5962. });
  5963. K(doc.body).append(div);
  5964. if (_IE) {
  5965. var rng = cmd.range.get(true);
  5966. rng.moveToElementText(div[0]);
  5967. rng.select();
  5968. rng.execCommand('paste');
  5969. e.preventDefault();
  5970. } else {
  5971. cmd.range.selectNodeContents(div[0]);
  5972. cmd.select();
  5973. div[0].tabIndex = -1;
  5974. div[0].focus();
  5975. }
  5976. setTimeout(function() {
  5977. movePastedData();
  5978. pasting = false;
  5979. }, 0);
  5980. });
  5981. });
  5982. self.beforeGetHtml(function(html) {
  5983. if (_IE && _V <= 8) {
  5984. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  5985. return unescape(tag);
  5986. });
  5987. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  5988. if (!/\s+type="[^"]+"/i.test($0)) {
  5989. return $1 + ' type="text"' + $2;
  5990. }
  5991. return $0;
  5992. });
  5993. }
  5994. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  5995. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  5996. })
  5997. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  5998. var imgAttrs = _getAttrList(full);
  5999. var styles = _getCssList(imgAttrs.style || '');
  6000. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  6001. var width = _undef(styles.width, '');
  6002. var height = _undef(styles.height, '');
  6003. if (/px/i.test(width)) {
  6004. width = _removeUnit(width);
  6005. }
  6006. if (/px/i.test(height)) {
  6007. height = _removeUnit(height);
  6008. }
  6009. attrs.width = _undef(imgAttrs.width, width);
  6010. attrs.height = _undef(imgAttrs.height, height);
  6011. return _mediaEmbed(attrs);
  6012. })
  6013. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  6014. var imgAttrs = _getAttrList(full);
  6015. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  6016. })
  6017. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6018. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  6019. })
  6020. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6021. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  6022. })
  6023. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  6024. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  6025. return $1 + _unescape(src) + $2;
  6026. });
  6027. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  6028. return full;
  6029. })
  6030. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6031. return start + end;
  6032. });
  6033. });
  6034. self.beforeSetHtml(function(html) {
  6035. if (_IE && _V <= 8) {
  6036. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  6037. var attrs = _getAttrList(full);
  6038. var styles = _getCssList(attrs.style || '');
  6039. if (styles.display == 'none') {
  6040. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  6041. }
  6042. return full;
  6043. });
  6044. }
  6045. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  6046. var attrs = _getAttrList(full);
  6047. attrs.src = _undef(attrs.src, '');
  6048. attrs.width = _undef(attrs.width, 0);
  6049. attrs.height = _undef(attrs.height, 0);
  6050. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  6051. })
  6052. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  6053. var attrs = _getAttrList(full);
  6054. if (attrs.href !== undefined) {
  6055. return full;
  6056. }
  6057. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  6058. })
  6059. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  6060. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6061. })
  6062. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  6063. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6064. })
  6065. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  6066. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  6067. return full;
  6068. }
  6069. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  6070. return full;
  6071. })
  6072. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6073. return start + 'data-ke-' + end;
  6074. })
  6075. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  6076. if (full.indexOf('ke-zeroborder') >= 0) {
  6077. return full;
  6078. }
  6079. return _addClassToTag(full, 'ke-zeroborder');
  6080. });
  6081. });
  6082. });
  6083. })(window);
  6084. /*******************************************************************************
  6085. * KindEditor - WYSIWYG HTML Editor for Internet
  6086. * Copyright (C) 2006-2011 kindsoft.net
  6087. *
  6088. * @author Roddy <luolonghao@gmail.com>
  6089. * @site http://www.kindsoft.net/
  6090. * @licence http://www.kindsoft.net/license.php
  6091. *******************************************************************************/
  6092. KindEditor.lang({
  6093. source : 'HTML代码',
  6094. preview : '预览',
  6095. undo : '后退(Ctrl+Z)',
  6096. redo : '前进(Ctrl+Y)',
  6097. cut : '剪切(Ctrl+X)',
  6098. copy : '复制(Ctrl+C)',
  6099. paste : '粘贴(Ctrl+V)',
  6100. plainpaste : '粘贴为无格式文本',
  6101. wordpaste : '从Word粘贴',
  6102. selectall : '全选(Ctrl+A)',
  6103. justifyleft : '左对齐',
  6104. justifycenter : '居中',
  6105. justifyright : '右对齐',
  6106. justifyfull : '两端对齐',
  6107. insertorderedlist : '编号',
  6108. insertunorderedlist : '项目符号',
  6109. indent : '增加缩进',
  6110. outdent : '减少缩进',
  6111. subscript : '下标',
  6112. superscript : '上标',
  6113. formatblock : '段落',
  6114. fontname : '字体',
  6115. fontsize : '文字大小',
  6116. forecolor : '文字颜色',
  6117. hilitecolor : '文字背景',
  6118. bold : '粗体(Ctrl+B)',
  6119. italic : '斜体(Ctrl+I)',
  6120. underline : '下划线(Ctrl+U)',
  6121. strikethrough : '删除线',
  6122. removeformat : '删除格式',
  6123. image : '图片',
  6124. multiimage : '批量图片上传',
  6125. flash : 'Flash',
  6126. media : '视音频',
  6127. table : '表格',
  6128. tablecell : '单元格',
  6129. hr : '插入横线',
  6130. emoticons : '插入表情',
  6131. link : '超级链接',
  6132. unlink : '取消超级链接',
  6133. fullscreen : '全屏显示',
  6134. about : '关于',
  6135. print : '打印(Ctrl+P)',
  6136. filemanager : '文件空间',
  6137. code : '插入程序代码',
  6138. map : 'Google地图',
  6139. baidumap : '百度地图',
  6140. lineheight : '行距',
  6141. clearhtml : '清理HTML代码',
  6142. pagebreak : '插入分页符',
  6143. quickformat : '一键排版',
  6144. insertfile : '插入文件',
  6145. template : '插入模板',
  6146. anchor : '锚点',
  6147. yes : '确定',
  6148. no : '取消',
  6149. close : '关闭',
  6150. editImage : '图片属性',
  6151. deleteImage : '删除图片',
  6152. editFlash : 'Flash属性',
  6153. deleteFlash : '删除Flash',
  6154. editMedia : '视音频属性',
  6155. deleteMedia : '删除视音频',
  6156. editLink : '超级链接属性',
  6157. deleteLink : '取消超级链接',
  6158. editAnchor : '锚点属性',
  6159. deleteAnchor : '删除锚点',
  6160. tableprop : '表格属性',
  6161. tablecellprop : '单元格属性',
  6162. tableinsert : '插入表格',
  6163. tabledelete : '删除表格',
  6164. tablecolinsertleft : '左侧插入列',
  6165. tablecolinsertright : '右侧插入列',
  6166. tablerowinsertabove : '上方插入行',
  6167. tablerowinsertbelow : '下方插入行',
  6168. tablerowmerge : '向下合并单元格',
  6169. tablecolmerge : '向右合并单元格',
  6170. tablerowsplit : '拆分行',
  6171. tablecolsplit : '拆分列',
  6172. tablecoldelete : '删除列',
  6173. tablerowdelete : '删除行',
  6174. noColor : '无颜色',
  6175. pleaseSelectFile : '请选择文件。',
  6176. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6177. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6178. invalidWidth : "宽度必须为数字。",
  6179. invalidHeight : "高度必须为数字。",
  6180. invalidBorder : "边框必须为数字。",
  6181. invalidUrl : "请输入有效的URL地址。",
  6182. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6183. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6184. invalidPadding : '边距必须为数字。',
  6185. invalidSpacing : '间距必须为数字。',
  6186. invalidJson : '服务器发生故障。',
  6187. uploadSuccess : '上传成功。',
  6188. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6189. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6190. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6191. ajaxLoading : '加载中,请稍候 ...',
  6192. uploadLoading : '上传中,请稍候 ...',
  6193. uploadError : '上传错误',
  6194. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6195. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6196. 'code.pleaseInput' : '请输入程序代码。',
  6197. 'link.url' : 'URL',
  6198. 'link.linkType' : '打开类型',
  6199. 'link.newWindow' : '新窗口',
  6200. 'link.selfWindow' : '当前窗口',
  6201. 'flash.url' : 'URL',
  6202. 'flash.width' : '宽度',
  6203. 'flash.height' : '高度',
  6204. 'flash.upload' : '上传',
  6205. 'flash.viewServer' : '文件空间',
  6206. 'media.url' : 'URL',
  6207. 'media.width' : '宽度',
  6208. 'media.height' : '高度',
  6209. 'media.autostart' : '自动播放',
  6210. 'media.upload' : '上传',
  6211. 'media.viewServer' : '文件空间',
  6212. 'image.remoteImage' : '网络图片',
  6213. 'image.localImage' : '本地上传',
  6214. 'image.remoteUrl' : '图片地址',
  6215. 'image.localUrl' : '上传文件',
  6216. 'image.size' : '图片大小',
  6217. 'image.width' : '宽',
  6218. 'image.height' : '高',
  6219. 'image.resetSize' : '重置大小',
  6220. 'image.align' : '对齐方式',
  6221. 'image.defaultAlign' : '默认方式',
  6222. 'image.leftAlign' : '左对齐',
  6223. 'image.rightAlign' : '右对齐',
  6224. 'image.imgTitle' : '图片说明',
  6225. 'image.upload' : '浏览...',
  6226. 'image.viewServer' : '图片空间',
  6227. 'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6228. 'multiimage.startUpload' : '开始上传',
  6229. 'multiimage.clearAll' : '全部清空',
  6230. 'multiimage.insertAll' : '全部插入',
  6231. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6232. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6233. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6234. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6235. 'multiimage.unknownError' : '发生异常,无法上传。',
  6236. 'multiimage.pending' : '等待上传',
  6237. 'multiimage.uploadError' : '上传失败',
  6238. 'filemanager.emptyFolder' : '空文件夹',
  6239. 'filemanager.moveup' : '移到上一级文件夹',
  6240. 'filemanager.viewType' : '显示方式:',
  6241. 'filemanager.viewImage' : '缩略图',
  6242. 'filemanager.listImage' : '详细信息',
  6243. 'filemanager.orderType' : '排序方式:',
  6244. 'filemanager.fileName' : '名称',
  6245. 'filemanager.fileSize' : '大小',
  6246. 'filemanager.fileType' : '类型',
  6247. 'insertfile.url' : 'URL',
  6248. 'insertfile.title' : '文件说明',
  6249. 'insertfile.upload' : '上传',
  6250. 'insertfile.viewServer' : '文件空间',
  6251. 'table.cells' : '单元格数',
  6252. 'table.rows' : '行数',
  6253. 'table.cols' : '列数',
  6254. 'table.size' : '大小',
  6255. 'table.width' : '宽度',
  6256. 'table.height' : '高度',
  6257. 'table.percent' : '%',
  6258. 'table.px' : 'px',
  6259. 'table.space' : '边距间距',
  6260. 'table.padding' : '边距',
  6261. 'table.spacing' : '间距',
  6262. 'table.align' : '对齐方式',
  6263. 'table.textAlign' : '水平对齐',
  6264. 'table.verticalAlign' : '垂直对齐',
  6265. 'table.alignDefault' : '默认',
  6266. 'table.alignLeft' : '左对齐',
  6267. 'table.alignCenter' : '居中',
  6268. 'table.alignRight' : '右对齐',
  6269. 'table.alignTop' : '顶部',
  6270. 'table.alignMiddle' : '中部',
  6271. 'table.alignBottom' : '底部',
  6272. 'table.alignBaseline' : '基线',
  6273. 'table.border' : '边框',
  6274. 'table.borderWidth' : '边框',
  6275. 'table.borderColor' : '颜色',
  6276. 'table.backgroundColor' : '背景颜色',
  6277. 'map.address' : '地址: ',
  6278. 'map.search' : '搜索',
  6279. 'baidumap.address' : '地址: ',
  6280. 'baidumap.search' : '搜索',
  6281. 'baidumap.insertDynamicMap' : '插入动态地图',
  6282. 'anchor.name' : '锚点名称',
  6283. 'formatblock.formatBlock' : {
  6284. h1 : '标题 1',
  6285. h2 : '标题 2',
  6286. h3 : '标题 3',
  6287. h4 : '标题 4',
  6288. p : '正 文'
  6289. },
  6290. 'fontname.fontName' : {
  6291. 'SimSun' : '宋体',
  6292. 'NSimSun' : '新宋体',
  6293. 'FangSong_GB2312' : '仿宋_GB2312',
  6294. 'KaiTi_GB2312' : '楷体_GB2312',
  6295. 'SimHei' : '黑体',
  6296. 'Microsoft YaHei' : '微软雅黑',
  6297. 'Arial' : 'Arial',
  6298. 'Arial Black' : 'Arial Black',
  6299. 'Times New Roman' : 'Times New Roman',
  6300. 'Courier New' : 'Courier New',
  6301. 'Tahoma' : 'Tahoma',
  6302. 'Verdana' : 'Verdana'
  6303. },
  6304. 'lineheight.lineHeight' : [
  6305. {'1' : '单倍行距'},
  6306. {'1.5' : '1.5倍行距'},
  6307. {'2' : '2倍行距'},
  6308. {'2.5' : '2.5倍行距'},
  6309. {'3' : '3倍行距'}
  6310. ],
  6311. 'template.selectTemplate' : '可选模板',
  6312. 'template.replaceContent' : '替换当前内容',
  6313. 'template.fileList' : {
  6314. '1.html' : '图片和文字',
  6315. '2.html' : '表格',
  6316. '3.html' : '项目编号'
  6317. }
  6318. }, 'zh-CN');
  6319. KindEditor.options.langType = 'zh-CN';
  6320. /*******************************************************************************
  6321. * KindEditor - WYSIWYG HTML Editor for Internet
  6322. * Copyright (C) 2006-2011 kindsoft.net
  6323. *
  6324. * @author Roddy <luolonghao@gmail.com>
  6325. * @site http://www.kindsoft.net/
  6326. * @licence http://www.kindsoft.net/license.php
  6327. *******************************************************************************/
  6328. KindEditor.plugin('anchor', function(K) {
  6329. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6330. self.plugin.anchor = {
  6331. edit : function() {
  6332. var html = ['<div style="padding:20px;">',
  6333. '<div class="ke-dialog-row">',
  6334. '<label for="keName">' + lang.name + '</label>',
  6335. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6336. '</div>',
  6337. '</div>'].join('');
  6338. var dialog = self.createDialog({
  6339. name : name,
  6340. width : 300,
  6341. title : self.lang(name),
  6342. body : html,
  6343. yesBtn : {
  6344. name : self.lang('yes'),
  6345. click : function(e) {
  6346. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6347. }
  6348. }
  6349. });
  6350. var div = dialog.div,
  6351. nameBox = K('input[name="name"]', div);
  6352. var img = self.plugin.getSelectedAnchor();
  6353. if (img) {
  6354. nameBox.val(unescape(img.attr('data-ke-name')));
  6355. }
  6356. nameBox[0].focus();
  6357. nameBox[0].select();
  6358. },
  6359. 'delete' : function() {
  6360. self.plugin.getSelectedAnchor().remove();
  6361. }
  6362. };
  6363. self.clickToolbar(name, self.plugin.anchor.edit);
  6364. });
  6365. /*******************************************************************************
  6366. * KindEditor - WYSIWYG HTML Editor for Internet
  6367. * Copyright (C) 2006-2011 kindsoft.net
  6368. *
  6369. * @author Roddy <luolonghao@gmail.com>
  6370. * @site http://www.kindsoft.net/
  6371. * @licence http://www.kindsoft.net/license.php
  6372. *******************************************************************************/
  6373. KindEditor.plugin('autoheight', function(K) {
  6374. var self = this;
  6375. if (!self.autoHeightMode) {
  6376. return;
  6377. }
  6378. var minHeight;
  6379. function hideScroll() {
  6380. var edit = self.edit;
  6381. var body = edit.doc.body;
  6382. edit.iframe[0].scroll = 'no';
  6383. body.style.overflowY = 'hidden';
  6384. }
  6385. function resetHeight() {
  6386. if(self.fullscreenMode){
  6387. return;
  6388. }
  6389. var edit = self.edit;
  6390. var body = edit.doc.body;
  6391. edit.iframe.height(minHeight);
  6392. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6393. }
  6394. function init() {
  6395. minHeight = K.removeUnit(self.height);
  6396. self.edit.afterChange(resetHeight);
  6397. if(!self.fullscreenMode){
  6398. hideScroll();
  6399. }
  6400. resetHeight();
  6401. }
  6402. if (self.isCreated) {
  6403. init();
  6404. } else {
  6405. self.afterCreate(init);
  6406. }
  6407. });
  6408. /*
  6409. * 如何实现真正的自动高度?
  6410. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6411. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6412. * 由此就实现了真正的自动高度
  6413. * 测试:chrome、firefox、IE9、IE8
  6414. * */
  6415. /*******************************************************************************
  6416. * KindEditor - WYSIWYG HTML Editor for Internet
  6417. * Copyright (C) 2006-2011 kindsoft.net
  6418. *
  6419. * @author Roddy <luolonghao@gmail.com>
  6420. * @site http://www.kindsoft.net/
  6421. * @licence http://www.kindsoft.net/license.php
  6422. *******************************************************************************/
  6423. KindEditor.plugin('baidumap', function(K) {
  6424. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6425. var mapWidth = K.undef(self.mapWidth, 558);
  6426. var mapHeight = K.undef(self.mapHeight, 360);
  6427. self.clickToolbar(name, function() {
  6428. var html = ['<div style="padding:10px 20px;">',
  6429. '<div class="ke-header">',
  6430. '<div class="ke-left">',
  6431. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6432. '<span class="ke-button-common ke-button-outer">',
  6433. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6434. '</span>',
  6435. '</div>',
  6436. '<div class="ke-right">',
  6437. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6438. '</div>',
  6439. '<div class="ke-clearfix"></div>',
  6440. '</div>',
  6441. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6442. '</div>'].join('');
  6443. var dialog = self.createDialog({
  6444. name : name,
  6445. width : mapWidth + 42,
  6446. title : self.lang(name),
  6447. body : html,
  6448. yesBtn : {
  6449. name : self.lang('yes'),
  6450. click : function(e) {
  6451. var map = win.map;
  6452. var centerObj = map.getCenter();
  6453. var center = centerObj.lng + ',' + centerObj.lat;
  6454. var zoom = map.getZoom();
  6455. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6456. '?center=' + encodeURIComponent(center),
  6457. '&zoom=' + encodeURIComponent(zoom),
  6458. '&width=' + mapWidth,
  6459. '&height=' + mapHeight,
  6460. '&markers=' + encodeURIComponent(center),
  6461. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6462. if (checkbox[0].checked) {
  6463. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6464. } else {
  6465. self.exec('insertimage', url);
  6466. }
  6467. self.hideDialog().focus();
  6468. }
  6469. },
  6470. beforeRemove : function() {
  6471. searchBtn.remove();
  6472. if (doc) {
  6473. doc.write('');
  6474. }
  6475. iframe.remove();
  6476. }
  6477. });
  6478. var div = dialog.div,
  6479. addressBox = K('[name="address"]', div),
  6480. searchBtn = K('[name="searchBtn"]', div),
  6481. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6482. win, doc;
  6483. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6484. function ready() {
  6485. win = iframe[0].contentWindow;
  6486. doc = K.iframeDoc(iframe);
  6487. }
  6488. iframe.bind('load', function() {
  6489. iframe.unbind('load');
  6490. if (K.IE) {
  6491. ready();
  6492. } else {
  6493. setTimeout(ready, 0);
  6494. }
  6495. });
  6496. K('.ke-map', div).replaceWith(iframe);
  6497. searchBtn.click(function() {
  6498. win.search(addressBox.val());
  6499. });
  6500. });
  6501. });
  6502. /*******************************************************************************
  6503. * KindEditor - WYSIWYG HTML Editor for Internet
  6504. * Copyright (C) 2006-2011 kindsoft.net
  6505. *
  6506. * @author Roddy <luolonghao@gmail.com>
  6507. * @site http://www.kindsoft.net/
  6508. * @licence http://www.kindsoft.net/license.php
  6509. *******************************************************************************/
  6510. KindEditor.plugin('map', function(K) {
  6511. var self = this, name = 'map', lang = self.lang(name + '.');
  6512. self.clickToolbar(name, function() {
  6513. var html = ['<div style="padding:10px 20px;">',
  6514. '<div class="ke-dialog-row">',
  6515. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6516. '<span class="ke-button-common ke-button-outer">',
  6517. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6518. '</span>',
  6519. '</div>',
  6520. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  6521. '</div>'].join('');
  6522. var dialog = self.createDialog({
  6523. name : name,
  6524. width : 600,
  6525. title : self.lang(name),
  6526. body : html,
  6527. yesBtn : {
  6528. name : self.lang('yes'),
  6529. click : function(e) {
  6530. var geocoder = win.geocoder,
  6531. map = win.map,
  6532. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  6533. zoom = map.getZoom(),
  6534. maptype = map.getMapTypeId(),
  6535. url = 'http://maps.googleapis.com/maps/api/staticmap';
  6536. url += '?center=' + encodeURIComponent(center);
  6537. url += '&zoom=' + encodeURIComponent(zoom);
  6538. url += '&size=558x360';
  6539. url += '&maptype=' + encodeURIComponent(maptype);
  6540. url += '&markers=' + encodeURIComponent(center);
  6541. url += '&language=' + self.langType;
  6542. url += '&sensor=false';
  6543. self.exec('insertimage', url).hideDialog().focus();
  6544. }
  6545. },
  6546. beforeRemove : function() {
  6547. searchBtn.remove();
  6548. if (doc) {
  6549. doc.write('');
  6550. }
  6551. iframe.remove();
  6552. }
  6553. });
  6554. var div = dialog.div,
  6555. addressBox = K('[name="address"]', div),
  6556. searchBtn = K('[name="searchBtn"]', div),
  6557. win, doc;
  6558. var iframeHtml = ['<!doctype html><html><head>',
  6559. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  6560. '<style>',
  6561. ' html { height: 100% }',
  6562. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  6563. ' #map_canvas { height: 100% }',
  6564. '</style>',
  6565. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  6566. '<script>',
  6567. 'var map, geocoder;',
  6568. 'function initialize() {',
  6569. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  6570. ' var options = {',
  6571. ' zoom: 11,',
  6572. ' center: latlng,',
  6573. ' disableDefaultUI: true,',
  6574. ' panControl: true,',
  6575. ' zoomControl: true,',
  6576. ' mapTypeControl: true,',
  6577. ' scaleControl: true,',
  6578. ' streetViewControl: false,',
  6579. ' overviewMapControl: true,',
  6580. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  6581. ' };',
  6582. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  6583. ' geocoder = new google.maps.Geocoder();',
  6584. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  6585. ' if (status == google.maps.GeocoderStatus.OK) {',
  6586. ' if (results[3]) {',
  6587. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  6588. ' }',
  6589. ' }',
  6590. ' });',
  6591. '}',
  6592. 'function search(address) {',
  6593. ' if (!map) return;',
  6594. ' geocoder.geocode({address : address}, function(results, status) {',
  6595. ' if (status == google.maps.GeocoderStatus.OK) {',
  6596. ' map.setZoom(11);',
  6597. ' map.setCenter(results[0].geometry.location);',
  6598. ' var marker = new google.maps.Marker({',
  6599. ' map: map,',
  6600. ' position: results[0].geometry.location',
  6601. ' });',
  6602. ' } else {',
  6603. ' alert("Invalid address: " + address);',
  6604. ' }',
  6605. ' });',
  6606. '}',
  6607. '</script>',
  6608. '</head>',
  6609. '<body onload="initialize();">',
  6610. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  6611. '</body></html>'].join('\n');
  6612. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  6613. function ready() {
  6614. win = iframe[0].contentWindow;
  6615. doc = K.iframeDoc(iframe);
  6616. }
  6617. iframe.bind('load', function() {
  6618. iframe.unbind('load');
  6619. if (K.IE) {
  6620. ready();
  6621. } else {
  6622. setTimeout(ready, 0);
  6623. }
  6624. });
  6625. K('.ke-map', div).replaceWith(iframe);
  6626. searchBtn.click(function() {
  6627. win.search(addressBox.val());
  6628. });
  6629. });
  6630. });
  6631. /*******************************************************************************
  6632. * KindEditor - WYSIWYG HTML Editor for Internet
  6633. * Copyright (C) 2006-2011 kindsoft.net
  6634. *
  6635. * @author Roddy <luolonghao@gmail.com>
  6636. * @site http://www.kindsoft.net/
  6637. * @licence http://www.kindsoft.net/license.php
  6638. *******************************************************************************/
  6639. KindEditor.plugin('clearhtml', function(K) {
  6640. var self = this, name = 'clearhtml';
  6641. self.clickToolbar(name, function() {
  6642. self.focus();
  6643. var html = self.html();
  6644. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6645. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6646. html = K.formatHtml(html, {
  6647. a : ['href', 'target'],
  6648. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6649. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6650. table : ['border'],
  6651. 'td,th' : ['rowspan', 'colspan'],
  6652. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6653. });
  6654. self.html(html);
  6655. self.cmd.selection(true);
  6656. self.addBookmark();
  6657. });
  6658. });
  6659. /*******************************************************************************
  6660. * KindEditor - WYSIWYG HTML Editor for Internet
  6661. * Copyright (C) 2006-2011 kindsoft.net
  6662. *
  6663. * @author Roddy <luolonghao@gmail.com>
  6664. * @site http://www.kindsoft.net/
  6665. * @licence http://www.kindsoft.net/license.php
  6666. *******************************************************************************/
  6667. KindEditor.plugin('code', function(K) {
  6668. var self = this, name = 'code';
  6669. self.clickToolbar(name, function() {
  6670. var lang = self.lang(name + '.'),
  6671. html = ['<div style="padding:10px 20px;">',
  6672. '<div class="ke-dialog-row">',
  6673. '<select class="ke-code-type">',
  6674. '<option value="js">JavaScript</option>',
  6675. '<option value="html">HTML</option>',
  6676. '<option value="css">CSS</option>',
  6677. '<option value="php">PHP</option>',
  6678. '<option value="pl">Perl</option>',
  6679. '<option value="py">Python</option>',
  6680. '<option value="rb">Ruby</option>',
  6681. '<option value="java">Java</option>',
  6682. '<option value="vb">ASP/VB</option>',
  6683. '<option value="cpp">C/C++</option>',
  6684. '<option value="cs">C#</option>',
  6685. '<option value="xml">XML</option>',
  6686. '<option value="bsh">Shell</option>',
  6687. '<option value="">Other</option>',
  6688. '</select>',
  6689. '</div>',
  6690. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6691. '</div>'].join(''),
  6692. dialog = self.createDialog({
  6693. name : name,
  6694. width : 450,
  6695. title : self.lang(name),
  6696. body : html,
  6697. yesBtn : {
  6698. name : self.lang('yes'),
  6699. click : function(e) {
  6700. var type = K('.ke-code-type', dialog.div).val(),
  6701. code = textarea.val(),
  6702. cls = type === '' ? '' : ' lang-' + type,
  6703. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6704. if (K.trim(code) === '') {
  6705. alert(lang.pleaseInput);
  6706. textarea[0].focus();
  6707. return;
  6708. }
  6709. self.insertHtml(html).hideDialog().focus();
  6710. }
  6711. }
  6712. }),
  6713. textarea = K('textarea', dialog.div);
  6714. textarea[0].focus();
  6715. });
  6716. });
  6717. /*******************************************************************************
  6718. * KindEditor - WYSIWYG HTML Editor for Internet
  6719. * Copyright (C) 2006-2011 kindsoft.net
  6720. *
  6721. * @author Roddy <luolonghao@gmail.com>
  6722. * @site http://www.kindsoft.net/
  6723. * @licence http://www.kindsoft.net/license.php
  6724. *******************************************************************************/
  6725. KindEditor.plugin('emoticons', function(K) {
  6726. var self = this, name = 'emoticons',
  6727. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6728. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6729. currentPageNum = 1;
  6730. self.clickToolbar(name, function() {
  6731. var rows = 5, cols = 9, total = 135, startNum = 0,
  6732. cells = rows * cols, pages = Math.ceil(total / cells),
  6733. colsHalf = Math.floor(cols / 2),
  6734. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6735. elements = [],
  6736. menu = self.createMenu({
  6737. name : name,
  6738. beforeRemove : function() {
  6739. removeEvent();
  6740. }
  6741. });
  6742. menu.div.append(wrapperDiv);
  6743. var previewDiv, previewImg;
  6744. if (allowPreview) {
  6745. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6746. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6747. wrapperDiv.append(previewDiv);
  6748. previewDiv.append(previewImg);
  6749. }
  6750. function bindCellEvent(cell, j, num) {
  6751. if (previewDiv) {
  6752. cell.mouseover(function() {
  6753. if (j > colsHalf) {
  6754. previewDiv.css('left', 0);
  6755. previewDiv.css('right', '');
  6756. } else {
  6757. previewDiv.css('left', '');
  6758. previewDiv.css('right', 0);
  6759. }
  6760. previewImg.attr('src', path + num + '.gif');
  6761. K(this).addClass('ke-on');
  6762. });
  6763. } else {
  6764. cell.mouseover(function() {
  6765. K(this).addClass('ke-on');
  6766. });
  6767. }
  6768. cell.mouseout(function() {
  6769. K(this).removeClass('ke-on');
  6770. });
  6771. cell.click(function(e) {
  6772. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6773. e.stop();
  6774. });
  6775. }
  6776. function createEmoticonsTable(pageNum, parentDiv) {
  6777. var table = document.createElement('table');
  6778. parentDiv.append(table);
  6779. if (previewDiv) {
  6780. K(table).mouseover(function() {
  6781. previewDiv.show('block');
  6782. });
  6783. K(table).mouseout(function() {
  6784. previewDiv.hide();
  6785. });
  6786. elements.push(K(table));
  6787. }
  6788. table.className = 'ke-table';
  6789. table.cellPadding = 0;
  6790. table.cellSpacing = 0;
  6791. table.border = 0;
  6792. var num = (pageNum - 1) * cells + startNum;
  6793. for (var i = 0; i < rows; i++) {
  6794. var row = table.insertRow(i);
  6795. for (var j = 0; j < cols; j++) {
  6796. var cell = K(row.insertCell(j));
  6797. cell.addClass('ke-cell');
  6798. bindCellEvent(cell, j, num);
  6799. var span = K('<span class="ke-img"></span>')
  6800. .css('background-position', '-' + (24 * num) + 'px 0px')
  6801. .css('background-image', 'url(' + path + 'static.gif)');
  6802. cell.append(span);
  6803. elements.push(cell);
  6804. num++;
  6805. }
  6806. }
  6807. return table;
  6808. }
  6809. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6810. function removeEvent() {
  6811. K.each(elements, function() {
  6812. this.unbind();
  6813. });
  6814. }
  6815. var pageDiv;
  6816. function bindPageEvent(el, pageNum) {
  6817. el.click(function(e) {
  6818. removeEvent();
  6819. table.parentNode.removeChild(table);
  6820. pageDiv.remove();
  6821. table = createEmoticonsTable(pageNum, wrapperDiv);
  6822. createPageTable(pageNum);
  6823. currentPageNum = pageNum;
  6824. e.stop();
  6825. });
  6826. }
  6827. function createPageTable(currentPageNum) {
  6828. pageDiv = K('<div class="ke-page"></div>');
  6829. wrapperDiv.append(pageDiv);
  6830. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6831. if (currentPageNum !== pageNum) {
  6832. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6833. bindPageEvent(a, pageNum);
  6834. pageDiv.append(a);
  6835. elements.push(a);
  6836. } else {
  6837. pageDiv.append(K('@[' + pageNum + ']'));
  6838. }
  6839. pageDiv.append(K('@&nbsp;'));
  6840. }
  6841. }
  6842. createPageTable(currentPageNum);
  6843. });
  6844. });
  6845. /*******************************************************************************
  6846. * KindEditor - WYSIWYG HTML Editor for Internet
  6847. * Copyright (C) 2006-2011 kindsoft.net
  6848. *
  6849. * @author Roddy <luolonghao@gmail.com>
  6850. * @site http://www.kindsoft.net/
  6851. * @licence http://www.kindsoft.net/license.php
  6852. *******************************************************************************/
  6853. KindEditor.plugin('filemanager', function(K) {
  6854. var self = this, name = 'filemanager',
  6855. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6856. imgPath = self.pluginsPath + name + '/images/',
  6857. lang = self.lang(name + '.');
  6858. function makeFileTitle(filename, filesize, datetime) {
  6859. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6860. }
  6861. function bindTitle(el, data) {
  6862. if (data.is_dir) {
  6863. el.attr('title', data.filename);
  6864. } else {
  6865. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6866. }
  6867. }
  6868. self.plugin.filemanagerDialog = function(options) {
  6869. var width = K.undef(options.width, 650),
  6870. height = K.undef(options.height, 510),
  6871. dirName = K.undef(options.dirName, ''),
  6872. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(),
  6873. clickFn = options.clickFn;
  6874. var html = [
  6875. '<div style="padding:10px 20px;">',
  6876. '<div class="ke-plugin-filemanager-header">',
  6877. '<div class="ke-left">',
  6878. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6879. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6880. '</div>',
  6881. '<div class="ke-right">',
  6882. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6883. '<option value="VIEW">' + lang.viewImage + '</option>',
  6884. '<option value="LIST">' + lang.listImage + '</option>',
  6885. '</select> ',
  6886. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6887. '<option value="NAME">' + lang.fileName + '</option>',
  6888. '<option value="SIZE">' + lang.fileSize + '</option>',
  6889. '<option value="TYPE">' + lang.fileType + '</option>',
  6890. '</select>',
  6891. '</div>',
  6892. '<div class="ke-clearfix"></div>',
  6893. '</div>',
  6894. '<div class="ke-plugin-filemanager-body"></div>',
  6895. '</div>'
  6896. ].join('');
  6897. var dialog = self.createDialog({
  6898. name : name,
  6899. width : width,
  6900. height : height,
  6901. title : self.lang(name),
  6902. body : html
  6903. }),
  6904. div = dialog.div,
  6905. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6906. moveupImg = K('[name="moveupImg"]', div),
  6907. moveupLink = K('[name="moveupLink"]', div),
  6908. viewServerBtn = K('[name="viewServer"]', div),
  6909. viewTypeBox = K('[name="viewType"]', div),
  6910. orderTypeBox = K('[name="orderType"]', div);
  6911. function reloadPage(path, order, func) {
  6912. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6913. dialog.showLoading(self.lang('ajaxLoading'));
  6914. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6915. dialog.hideLoading();
  6916. func(data);
  6917. });
  6918. }
  6919. var elList = [];
  6920. function bindEvent(el, result, data, createFunc) {
  6921. var fileUrl = K.formatUrl(result.current_url + data.filename, 'absolute'),
  6922. dirPath = encodeURIComponent(result.current_dir_path + data.filename + '/');
  6923. if (data.is_dir) {
  6924. el.click(function(e) {
  6925. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6926. });
  6927. } else if (data.is_photo) {
  6928. el.click(function(e) {
  6929. clickFn.call(this, fileUrl, data.filename);
  6930. });
  6931. } else {
  6932. el.click(function(e) {
  6933. clickFn.call(this, fileUrl, data.filename);
  6934. });
  6935. }
  6936. elList.push(el);
  6937. }
  6938. function createCommon(result, createFunc) {
  6939. K.each(elList, function() {
  6940. this.unbind();
  6941. });
  6942. moveupLink.unbind();
  6943. viewTypeBox.unbind();
  6944. orderTypeBox.unbind();
  6945. if (result.current_dir_path) {
  6946. moveupLink.click(function(e) {
  6947. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  6948. });
  6949. }
  6950. function changeFunc() {
  6951. if (viewTypeBox.val() == 'VIEW') {
  6952. reloadPage(result.current_dir_path, orderTypeBox.val(), createView);
  6953. } else {
  6954. reloadPage(result.current_dir_path, orderTypeBox.val(), createList);
  6955. }
  6956. }
  6957. viewTypeBox.change(changeFunc);
  6958. orderTypeBox.change(changeFunc);
  6959. bodyDiv.html('');
  6960. }
  6961. function createList(result) {
  6962. createCommon(result, createList);
  6963. var table = document.createElement('table');
  6964. table.className = 'ke-table';
  6965. table.cellPadding = 0;
  6966. table.cellSpacing = 0;
  6967. table.border = 0;
  6968. bodyDiv.append(table);
  6969. var fileList = result.file_list;
  6970. for (var i = 0, len = fileList.length; i < len; i++) {
  6971. var data = fileList[i], row = K(table.insertRow(i));
  6972. row.mouseover(function(e) {
  6973. K(this).addClass('ke-on');
  6974. })
  6975. .mouseout(function(e) {
  6976. K(this).removeClass('ke-on');
  6977. });
  6978. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  6979. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  6980. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  6981. if (!data.is_dir || data.has_file) {
  6982. row.css('cursor', 'pointer');
  6983. cell0.attr('title', data.filename);
  6984. bindEvent(cell0, result, data, createList);
  6985. } else {
  6986. cell0.attr('title', lang.emptyFolder);
  6987. }
  6988. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  6989. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  6990. }
  6991. }
  6992. function createView(result) {
  6993. createCommon(result, createView);
  6994. var fileList = result.file_list;
  6995. for (var i = 0, len = fileList.length; i < len; i++) {
  6996. var data = fileList[i],
  6997. div = K('<div class="ke-inline-block ke-item"></div>');
  6998. bodyDiv.append(div);
  6999. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7000. .mouseover(function(e) {
  7001. K(this).addClass('ke-on');
  7002. })
  7003. .mouseout(function(e) {
  7004. K(this).removeClass('ke-on');
  7005. });
  7006. div.append(photoDiv);
  7007. var fileUrl = result.current_url + data.filename,
  7008. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  7009. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  7010. if (!data.is_dir || data.has_file) {
  7011. photoDiv.css('cursor', 'pointer');
  7012. bindTitle(photoDiv, data);
  7013. bindEvent(photoDiv, result, data, createView);
  7014. } else {
  7015. photoDiv.attr('title', lang.emptyFolder);
  7016. }
  7017. photoDiv.append(img);
  7018. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  7019. }
  7020. }
  7021. viewTypeBox.val(viewType);
  7022. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  7023. return dialog;
  7024. }
  7025. });
  7026. /*******************************************************************************
  7027. * KindEditor - WYSIWYG HTML Editor for Internet
  7028. * Copyright (C) 2006-2011 kindsoft.net
  7029. *
  7030. * @author Roddy <luolonghao@gmail.com>
  7031. * @site http://www.kindsoft.net/
  7032. * @licence http://www.kindsoft.net/license.php
  7033. *******************************************************************************/
  7034. KindEditor.plugin('flash', function(K) {
  7035. var self = this, name = 'flash', lang = self.lang(name + '.'),
  7036. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  7037. allowFileManager = K.undef(self.allowFileManager, false),
  7038. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7039. extraParams = K.undef(self.extraFileUploadParams, {}),
  7040. filePostName = K.undef(self.filePostName, 'imgFile'),
  7041. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7042. self.plugin.flash = {
  7043. edit : function() {
  7044. var html = [
  7045. '<div style="padding:20px;">',
  7046. '<div class="ke-dialog-row">',
  7047. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7048. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7049. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7050. '<span class="ke-button-common ke-button-outer">',
  7051. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7052. '</span>',
  7053. '</div>',
  7054. '<div class="ke-dialog-row">',
  7055. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7056. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  7057. '</div>',
  7058. '<div class="ke-dialog-row">',
  7059. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7060. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  7061. '</div>',
  7062. '</div>'
  7063. ].join('');
  7064. var dialog = self.createDialog({
  7065. name : name,
  7066. width : 450,
  7067. title : self.lang(name),
  7068. body : html,
  7069. yesBtn : {
  7070. name : self.lang('yes'),
  7071. click : function(e) {
  7072. var url = K.trim(urlBox.val()),
  7073. width = widthBox.val(),
  7074. height = heightBox.val();
  7075. if (url == 'http://' || K.invalidUrl(url)) {
  7076. alert(self.lang('invalidUrl'));
  7077. urlBox[0].focus();
  7078. return;
  7079. }
  7080. if (!/^\d*$/.test(width)) {
  7081. alert(self.lang('invalidWidth'));
  7082. widthBox[0].focus();
  7083. return;
  7084. }
  7085. if (!/^\d*$/.test(height)) {
  7086. alert(self.lang('invalidHeight'));
  7087. heightBox[0].focus();
  7088. return;
  7089. }
  7090. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7091. src : url,
  7092. type : K.mediaType('.swf'),
  7093. width : width,
  7094. height : height,
  7095. quality : 'high'
  7096. });
  7097. self.insertHtml(html).hideDialog().focus();
  7098. }
  7099. }
  7100. }),
  7101. div = dialog.div,
  7102. urlBox = K('[name="url"]', div),
  7103. viewServerBtn = K('[name="viewServer"]', div),
  7104. widthBox = K('[name="width"]', div),
  7105. heightBox = K('[name="height"]', div);
  7106. urlBox.val('http://');
  7107. if (allowFlashUpload) {
  7108. var uploadbutton = K.uploadbutton({
  7109. button : K('.ke-upload-button', div)[0],
  7110. fieldName : filePostName,
  7111. extraParams : extraParams,
  7112. url : K.addParam(uploadJson, 'dir=flash'),
  7113. afterUpload : function(data) {
  7114. dialog.hideLoading();
  7115. if (data.error === 0) {
  7116. var url = data.url;
  7117. if (formatUploadUrl) {
  7118. url = K.formatUrl(url, 'absolute');
  7119. }
  7120. urlBox.val(url);
  7121. if (self.afterUpload) {
  7122. self.afterUpload.call(self, url, data, name);
  7123. }
  7124. alert(self.lang('uploadSuccess'));
  7125. } else {
  7126. alert(data.message);
  7127. }
  7128. },
  7129. afterError : function(html) {
  7130. dialog.hideLoading();
  7131. self.errorDialog(html);
  7132. }
  7133. });
  7134. uploadbutton.fileBox.change(function(e) {
  7135. dialog.showLoading(self.lang('uploadLoading'));
  7136. uploadbutton.submit();
  7137. });
  7138. } else {
  7139. K('.ke-upload-button', div).hide();
  7140. }
  7141. if (allowFileManager) {
  7142. viewServerBtn.click(function(e) {
  7143. self.loadPlugin('filemanager', function() {
  7144. self.plugin.filemanagerDialog({
  7145. viewType : 'LIST',
  7146. dirName : 'flash',
  7147. clickFn : function(url, title) {
  7148. if (self.dialogs.length > 1) {
  7149. K('[name="url"]', div).val(url);
  7150. if (self.afterSelectFile) {
  7151. self.afterSelectFile.call(self, url);
  7152. }
  7153. self.hideDialog();
  7154. }
  7155. }
  7156. });
  7157. });
  7158. });
  7159. } else {
  7160. viewServerBtn.hide();
  7161. }
  7162. var img = self.plugin.getSelectedFlash();
  7163. if (img) {
  7164. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7165. urlBox.val(attrs.src);
  7166. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7167. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7168. }
  7169. urlBox[0].focus();
  7170. urlBox[0].select();
  7171. },
  7172. 'delete' : function() {
  7173. self.plugin.getSelectedFlash().remove();
  7174. self.addBookmark();
  7175. }
  7176. };
  7177. self.clickToolbar(name, self.plugin.flash.edit);
  7178. });
  7179. /*******************************************************************************
  7180. * KindEditor - WYSIWYG HTML Editor for Internet
  7181. * Copyright (C) 2006-2011 kindsoft.net
  7182. *
  7183. * @author Roddy <luolonghao@gmail.com>
  7184. * @site http://www.kindsoft.net/
  7185. * @licence http://www.kindsoft.net/license.php
  7186. *******************************************************************************/
  7187. KindEditor.plugin('image', function(K) {
  7188. var self = this, name = 'image',
  7189. allowImageUpload = K.undef(self.allowImageUpload, true),
  7190. allowImageRemote = K.undef(self.allowImageRemote, true),
  7191. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7192. allowFileManager = K.undef(self.allowFileManager, false),
  7193. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7194. imageTabIndex = K.undef(self.imageTabIndex, 0),
  7195. imgPath = self.pluginsPath + 'image/images/',
  7196. extraParams = K.undef(self.extraFileUploadParams, {}),
  7197. filePostName = K.undef(self.filePostName, 'imgFile'),
  7198. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  7199. lang = self.lang(name + '.');
  7200. self.plugin.imageDialog = function(options) {
  7201. var imageUrl = options.imageUrl,
  7202. imageWidth = K.undef(options.imageWidth, ''),
  7203. imageHeight = K.undef(options.imageHeight, ''),
  7204. imageTitle = K.undef(options.imageTitle, ''),
  7205. imageAlign = K.undef(options.imageAlign, ''),
  7206. showRemote = K.undef(options.showRemote, true),
  7207. showLocal = K.undef(options.showLocal, true),
  7208. tabIndex = K.undef(options.tabIndex, 0),
  7209. clickFn = options.clickFn;
  7210. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  7211. var hiddenElements = [];
  7212. for(var k in extraParams){
  7213. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  7214. }
  7215. var html = [
  7216. '<div style="padding:20px;">',
  7217. '<div class="tabs"></div>',
  7218. '<div class="tab1" style="display:none;">',
  7219. '<div class="ke-dialog-row">',
  7220. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  7221. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  7222. '<span class="ke-button-common ke-button-outer">',
  7223. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7224. '</span>',
  7225. '</div>',
  7226. '<div class="ke-dialog-row">',
  7227. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  7228. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  7229. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  7230. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  7231. '</div>',
  7232. '<div class="ke-dialog-row">',
  7233. '<label style="width:60px;">' + lang.align + '</label>',
  7234. '<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="" />',
  7235. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  7236. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7237. '</div>',
  7238. '<div class="ke-dialog-row">',
  7239. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7240. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7241. '</div>',
  7242. '</div>',
  7243. '<div class="tab2" style="display:none;">',
  7244. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7245. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7246. '<div class="ke-dialog-row">',
  7247. hiddenElements.join(''),
  7248. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7249. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7250. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7251. '</div>',
  7252. '</form>',
  7253. '</div>',
  7254. '</div>'
  7255. ].join('');
  7256. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7257. dialogHeight = showLocal && showRemote ? 300 : 250;
  7258. var dialog = self.createDialog({
  7259. name : name,
  7260. width : dialogWidth,
  7261. height : dialogHeight,
  7262. title : self.lang(name),
  7263. body : html,
  7264. yesBtn : {
  7265. name : self.lang('yes'),
  7266. click : function(e) {
  7267. if (dialog.isLoading) {
  7268. return;
  7269. }
  7270. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7271. if (uploadbutton.fileBox.val() == '') {
  7272. alert(self.lang('pleaseSelectFile'));
  7273. return;
  7274. }
  7275. dialog.showLoading(self.lang('uploadLoading'));
  7276. uploadbutton.submit();
  7277. localUrlBox.val('');
  7278. return;
  7279. }
  7280. var url = K.trim(urlBox.val()),
  7281. width = widthBox.val(),
  7282. height = heightBox.val(),
  7283. title = titleBox.val(),
  7284. align = '';
  7285. alignBox.each(function() {
  7286. if (this.checked) {
  7287. align = this.value;
  7288. return false;
  7289. }
  7290. });
  7291. if (url == 'http://' || K.invalidUrl(url)) {
  7292. alert(self.lang('invalidUrl'));
  7293. urlBox[0].focus();
  7294. return;
  7295. }
  7296. if (!/^\d*$/.test(width)) {
  7297. alert(self.lang('invalidWidth'));
  7298. widthBox[0].focus();
  7299. return;
  7300. }
  7301. if (!/^\d*$/.test(height)) {
  7302. alert(self.lang('invalidHeight'));
  7303. heightBox[0].focus();
  7304. return;
  7305. }
  7306. clickFn.call(self, url, title, width, height, 0, align);
  7307. }
  7308. },
  7309. beforeRemove : function() {
  7310. viewServerBtn.unbind();
  7311. widthBox.unbind();
  7312. heightBox.unbind();
  7313. refreshBtn.unbind();
  7314. }
  7315. }),
  7316. div = dialog.div;
  7317. var urlBox = K('[name="url"]', div),
  7318. localUrlBox = K('[name="localUrl"]', div),
  7319. viewServerBtn = K('[name="viewServer"]', div),
  7320. widthBox = K('.tab1 [name="width"]', div),
  7321. heightBox = K('.tab1 [name="height"]', div),
  7322. refreshBtn = K('.ke-refresh-btn', div),
  7323. titleBox = K('.tab1 [name="title"]', div),
  7324. alignBox = K('.tab1 [name="align"]', div);
  7325. var tabs;
  7326. if (showRemote && showLocal) {
  7327. tabs = K.tabs({
  7328. src : K('.tabs', div),
  7329. afterSelect : function(i) {}
  7330. });
  7331. tabs.add({
  7332. title : lang.remoteImage,
  7333. panel : K('.tab1', div)
  7334. });
  7335. tabs.add({
  7336. title : lang.localImage,
  7337. panel : K('.tab2', div)
  7338. });
  7339. tabs.select(tabIndex);
  7340. } else if (showRemote) {
  7341. K('.tab1', div).show();
  7342. } else if (showLocal) {
  7343. K('.tab2', div).show();
  7344. }
  7345. var uploadbutton = K.uploadbutton({
  7346. button : K('.ke-upload-button', div)[0],
  7347. fieldName : filePostName,
  7348. form : K('.ke-form', div),
  7349. target : target,
  7350. width: 60,
  7351. afterUpload : function(data) {
  7352. dialog.hideLoading();
  7353. if (data.error === 0) {
  7354. var url = data.url;
  7355. if (formatUploadUrl) {
  7356. url = K.formatUrl(url, 'absolute');
  7357. }
  7358. if (self.afterUpload) {
  7359. self.afterUpload.call(self, url, data, name);
  7360. }
  7361. if (!fillDescAfterUploadImage) {
  7362. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7363. } else {
  7364. K(".ke-dialog-row #remoteUrl", div).val(url);
  7365. K(".ke-tabs-li", div)[0].click();
  7366. K(".ke-refresh-btn", div).click();
  7367. }
  7368. } else {
  7369. alert(data.message);
  7370. }
  7371. },
  7372. afterError : function(html) {
  7373. dialog.hideLoading();
  7374. self.errorDialog(html);
  7375. }
  7376. });
  7377. uploadbutton.fileBox.change(function(e) {
  7378. localUrlBox.val(uploadbutton.fileBox.val());
  7379. });
  7380. if (allowFileManager) {
  7381. viewServerBtn.click(function(e) {
  7382. self.loadPlugin('filemanager', function() {
  7383. self.plugin.filemanagerDialog({
  7384. viewType : 'VIEW',
  7385. dirName : 'image',
  7386. clickFn : function(url, title) {
  7387. if (self.dialogs.length > 1) {
  7388. K('[name="url"]', div).val(url);
  7389. if (self.afterSelectFile) {
  7390. self.afterSelectFile.call(self, url);
  7391. }
  7392. self.hideDialog();
  7393. }
  7394. }
  7395. });
  7396. });
  7397. });
  7398. } else {
  7399. viewServerBtn.hide();
  7400. }
  7401. var originalWidth = 0, originalHeight = 0;
  7402. function setSize(width, height) {
  7403. widthBox.val(width);
  7404. heightBox.val(height);
  7405. originalWidth = width;
  7406. originalHeight = height;
  7407. }
  7408. refreshBtn.click(function(e) {
  7409. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7410. position : 'absolute',
  7411. visibility : 'hidden',
  7412. top : 0,
  7413. left : '-1000px'
  7414. });
  7415. tempImg.bind('load', function() {
  7416. setSize(tempImg.width(), tempImg.height());
  7417. tempImg.remove();
  7418. });
  7419. K(document.body).append(tempImg);
  7420. });
  7421. widthBox.change(function(e) {
  7422. if (originalWidth > 0) {
  7423. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7424. }
  7425. });
  7426. heightBox.change(function(e) {
  7427. if (originalHeight > 0) {
  7428. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7429. }
  7430. });
  7431. urlBox.val(options.imageUrl);
  7432. setSize(options.imageWidth, options.imageHeight);
  7433. titleBox.val(options.imageTitle);
  7434. alignBox.each(function() {
  7435. if (this.value === options.imageAlign) {
  7436. this.checked = true;
  7437. return false;
  7438. }
  7439. });
  7440. if (showRemote && tabIndex === 0) {
  7441. urlBox[0].focus();
  7442. urlBox[0].select();
  7443. }
  7444. return dialog;
  7445. };
  7446. self.plugin.image = {
  7447. edit : function() {
  7448. var img = self.plugin.getSelectedImage();
  7449. self.plugin.imageDialog({
  7450. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7451. imageWidth : img ? img.width() : '',
  7452. imageHeight : img ? img.height() : '',
  7453. imageTitle : img ? img.attr('title') : '',
  7454. imageAlign : img ? img.attr('align') : '',
  7455. showRemote : allowImageRemote,
  7456. showLocal : allowImageUpload,
  7457. tabIndex: img ? 0 : imageTabIndex,
  7458. clickFn : function(url, title, width, height, border, align) {
  7459. if (img) {
  7460. img.attr('src', url);
  7461. img.attr('data-ke-src', url);
  7462. img.attr('width', width);
  7463. img.attr('height', height);
  7464. img.attr('title', title);
  7465. img.attr('align', align);
  7466. img.attr('alt', title);
  7467. } else {
  7468. self.exec('insertimage', url, title, width, height, border, align);
  7469. }
  7470. setTimeout(function() {
  7471. self.hideDialog().focus();
  7472. }, 0);
  7473. }
  7474. });
  7475. },
  7476. 'delete' : function() {
  7477. var target = self.plugin.getSelectedImage();
  7478. if (target.parent().name == 'a') {
  7479. target = target.parent();
  7480. }
  7481. target.remove();
  7482. self.addBookmark();
  7483. }
  7484. };
  7485. self.clickToolbar(name, self.plugin.image.edit);
  7486. });
  7487. /*******************************************************************************
  7488. * KindEditor - WYSIWYG HTML Editor for Internet
  7489. * Copyright (C) 2006-2011 kindsoft.net
  7490. *
  7491. * @author Roddy <luolonghao@gmail.com>
  7492. * @site http://www.kindsoft.net/
  7493. * @licence http://www.kindsoft.net/license.php
  7494. *******************************************************************************/
  7495. KindEditor.plugin('insertfile', function(K) {
  7496. var self = this, name = 'insertfile',
  7497. allowFileUpload = K.undef(self.allowFileUpload, true),
  7498. allowFileManager = K.undef(self.allowFileManager, false),
  7499. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7500. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7501. extraParams = K.undef(self.extraFileUploadParams, {}),
  7502. filePostName = K.undef(self.filePostName, 'imgFile'),
  7503. lang = self.lang(name + '.');
  7504. self.plugin.fileDialog = function(options) {
  7505. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7506. fileTitle = K.undef(options.fileTitle, ''),
  7507. clickFn = options.clickFn;
  7508. var html = [
  7509. '<div style="padding:20px;">',
  7510. '<div class="ke-dialog-row">',
  7511. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7512. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7513. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7514. '<span class="ke-button-common ke-button-outer">',
  7515. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7516. '</span>',
  7517. '</div>',
  7518. '<div class="ke-dialog-row">',
  7519. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7520. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7521. '</div>',
  7522. '</form>',
  7523. '</div>'
  7524. ].join('');
  7525. var dialog = self.createDialog({
  7526. name : name,
  7527. width : 450,
  7528. title : self.lang(name),
  7529. body : html,
  7530. yesBtn : {
  7531. name : self.lang('yes'),
  7532. click : function(e) {
  7533. var url = K.trim(urlBox.val()),
  7534. title = titleBox.val();
  7535. if (url == 'http://' || K.invalidUrl(url)) {
  7536. alert(self.lang('invalidUrl'));
  7537. urlBox[0].focus();
  7538. return;
  7539. }
  7540. if (K.trim(title) === '') {
  7541. title = url;
  7542. }
  7543. clickFn.call(self, url, title);
  7544. }
  7545. }
  7546. }),
  7547. div = dialog.div;
  7548. var urlBox = K('[name="url"]', div),
  7549. viewServerBtn = K('[name="viewServer"]', div),
  7550. titleBox = K('[name="title"]', div);
  7551. if (allowFileUpload) {
  7552. var uploadbutton = K.uploadbutton({
  7553. button : K('.ke-upload-button', div)[0],
  7554. fieldName : filePostName,
  7555. url : K.addParam(uploadJson, 'dir=file'),
  7556. extraParams : extraParams,
  7557. afterUpload : function(data) {
  7558. dialog.hideLoading();
  7559. if (data.error === 0) {
  7560. var url = data.url;
  7561. if (formatUploadUrl) {
  7562. url = K.formatUrl(url, 'absolute');
  7563. }
  7564. urlBox.val(url);
  7565. if (self.afterUpload) {
  7566. self.afterUpload.call(self, url, data, name);
  7567. }
  7568. alert(self.lang('uploadSuccess'));
  7569. } else {
  7570. alert(data.message);
  7571. }
  7572. },
  7573. afterError : function(html) {
  7574. dialog.hideLoading();
  7575. self.errorDialog(html);
  7576. }
  7577. });
  7578. uploadbutton.fileBox.change(function(e) {
  7579. dialog.showLoading(self.lang('uploadLoading'));
  7580. uploadbutton.submit();
  7581. });
  7582. } else {
  7583. K('.ke-upload-button', div).hide();
  7584. }
  7585. if (allowFileManager) {
  7586. viewServerBtn.click(function(e) {
  7587. self.loadPlugin('filemanager', function() {
  7588. self.plugin.filemanagerDialog({
  7589. viewType : 'LIST',
  7590. dirName : 'file',
  7591. clickFn : function(url, title) {
  7592. if (self.dialogs.length > 1) {
  7593. K('[name="url"]', div).val(url);
  7594. if (self.afterSelectFile) {
  7595. self.afterSelectFile.call(self, url);
  7596. }
  7597. self.hideDialog();
  7598. }
  7599. }
  7600. });
  7601. });
  7602. });
  7603. } else {
  7604. viewServerBtn.hide();
  7605. }
  7606. urlBox.val(fileUrl);
  7607. titleBox.val(fileTitle);
  7608. urlBox[0].focus();
  7609. urlBox[0].select();
  7610. };
  7611. self.clickToolbar(name, function() {
  7612. self.plugin.fileDialog({
  7613. clickFn : function(url, title) {
  7614. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7615. self.insertHtml(html).hideDialog().focus();
  7616. }
  7617. });
  7618. });
  7619. });
  7620. /*******************************************************************************
  7621. * KindEditor - WYSIWYG HTML Editor for Internet
  7622. * Copyright (C) 2006-2011 kindsoft.net
  7623. *
  7624. * @author Roddy <luolonghao@gmail.com>
  7625. * @site http://www.kindsoft.net/
  7626. * @licence http://www.kindsoft.net/license.php
  7627. *******************************************************************************/
  7628. KindEditor.plugin('lineheight', function(K) {
  7629. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7630. self.clickToolbar(name, function() {
  7631. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7632. if (commonNode) {
  7633. curVal = commonNode.css('line-height');
  7634. }
  7635. var menu = self.createMenu({
  7636. name : name,
  7637. width : 150
  7638. });
  7639. K.each(lang.lineHeight, function(i, row) {
  7640. K.each(row, function(key, val) {
  7641. menu.addItem({
  7642. title : val,
  7643. checked : curVal === key,
  7644. click : function() {
  7645. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7646. span : '.line-height=' + key
  7647. });
  7648. self.updateState();
  7649. self.addBookmark();
  7650. self.hideMenu();
  7651. }
  7652. });
  7653. });
  7654. });
  7655. });
  7656. });
  7657. /*******************************************************************************
  7658. * KindEditor - WYSIWYG HTML Editor for Internet
  7659. * Copyright (C) 2006-2011 kindsoft.net
  7660. *
  7661. * @author Roddy <luolonghao@gmail.com>
  7662. * @site http://www.kindsoft.net/
  7663. * @licence http://www.kindsoft.net/license.php
  7664. *******************************************************************************/
  7665. KindEditor.plugin('link', function(K) {
  7666. var self = this, name = 'link';
  7667. self.plugin.link = {
  7668. edit : function() {
  7669. var lang = self.lang(name + '.'),
  7670. html = '<div style="padding:20px;">' +
  7671. '<div class="ke-dialog-row">' +
  7672. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7673. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7674. '<div class="ke-dialog-row"">' +
  7675. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7676. '<select id="keType" name="type"></select>' +
  7677. '</div>' +
  7678. '</div>',
  7679. dialog = self.createDialog({
  7680. name : name,
  7681. width : 450,
  7682. title : self.lang(name),
  7683. body : html,
  7684. yesBtn : {
  7685. name : self.lang('yes'),
  7686. click : function(e) {
  7687. var url = K.trim(urlBox.val());
  7688. if (url == 'http://' || K.invalidUrl(url)) {
  7689. alert(self.lang('invalidUrl'));
  7690. urlBox[0].focus();
  7691. return;
  7692. }
  7693. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7694. }
  7695. }
  7696. }),
  7697. div = dialog.div,
  7698. urlBox = K('input[name="url"]', div),
  7699. typeBox = K('select[name="type"]', div);
  7700. urlBox.val('http://');
  7701. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7702. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7703. self.cmd.selection();
  7704. var a = self.plugin.getSelectedLink();
  7705. if (a) {
  7706. self.cmd.range.selectNode(a[0]);
  7707. self.cmd.select();
  7708. urlBox.val(a.attr('data-ke-src'));
  7709. typeBox.val(a.attr('target'));
  7710. }
  7711. urlBox[0].focus();
  7712. urlBox[0].select();
  7713. },
  7714. 'delete' : function() {
  7715. self.exec('unlink', null);
  7716. }
  7717. };
  7718. self.clickToolbar(name, self.plugin.link.edit);
  7719. });
  7720. /*******************************************************************************
  7721. * KindEditor - WYSIWYG HTML Editor for Internet
  7722. * Copyright (C) 2006-2011 kindsoft.net
  7723. *
  7724. * @author Roddy <luolonghao@gmail.com>
  7725. * @site http://www.kindsoft.net/
  7726. * @licence http://www.kindsoft.net/license.php
  7727. *******************************************************************************/
  7728. KindEditor.plugin('media', function(K) {
  7729. var self = this, name = 'media', lang = self.lang(name + '.'),
  7730. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7731. allowFileManager = K.undef(self.allowFileManager, false),
  7732. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7733. extraParams = K.undef(self.extraFileUploadParams, {}),
  7734. filePostName = K.undef(self.filePostName, 'imgFile'),
  7735. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7736. self.plugin.media = {
  7737. edit : function() {
  7738. var html = [
  7739. '<div style="padding:20px;">',
  7740. '<div class="ke-dialog-row">',
  7741. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7742. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7743. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7744. '<span class="ke-button-common ke-button-outer">',
  7745. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7746. '</span>',
  7747. '</div>',
  7748. '<div class="ke-dialog-row">',
  7749. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7750. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" />',
  7751. '</div>',
  7752. '<div class="ke-dialog-row">',
  7753. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7754. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" />',
  7755. '</div>',
  7756. '<div class="ke-dialog-row">',
  7757. '<label for="keAutostart">' + lang.autostart + '</label>',
  7758. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7759. '</div>',
  7760. '</div>'
  7761. ].join('');
  7762. var dialog = self.createDialog({
  7763. name : name,
  7764. width : 450,
  7765. height : 230,
  7766. title : self.lang(name),
  7767. body : html,
  7768. yesBtn : {
  7769. name : self.lang('yes'),
  7770. click : function(e) {
  7771. var url = K.trim(urlBox.val()),
  7772. width = widthBox.val(),
  7773. height = heightBox.val();
  7774. if (url == 'http://' || K.invalidUrl(url)) {
  7775. alert(self.lang('invalidUrl'));
  7776. urlBox[0].focus();
  7777. return;
  7778. }
  7779. if (!/^\d*$/.test(width)) {
  7780. alert(self.lang('invalidWidth'));
  7781. widthBox[0].focus();
  7782. return;
  7783. }
  7784. if (!/^\d*$/.test(height)) {
  7785. alert(self.lang('invalidHeight'));
  7786. heightBox[0].focus();
  7787. return;
  7788. }
  7789. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7790. src : url,
  7791. type : K.mediaType(url),
  7792. width : width,
  7793. height : height,
  7794. autostart : autostartBox[0].checked ? 'true' : 'false',
  7795. loop : 'true'
  7796. });
  7797. self.insertHtml(html).hideDialog().focus();
  7798. }
  7799. }
  7800. }),
  7801. div = dialog.div,
  7802. urlBox = K('[name="url"]', div),
  7803. viewServerBtn = K('[name="viewServer"]', div),
  7804. widthBox = K('[name="width"]', div),
  7805. heightBox = K('[name="height"]', div),
  7806. autostartBox = K('[name="autostart"]', div);
  7807. urlBox.val('http://');
  7808. if (allowMediaUpload) {
  7809. var uploadbutton = K.uploadbutton({
  7810. button : K('.ke-upload-button', div)[0],
  7811. fieldName : filePostName,
  7812. extraParams : extraParams,
  7813. url : K.addParam(uploadJson, 'dir=media'),
  7814. afterUpload : function(data) {
  7815. dialog.hideLoading();
  7816. if (data.error === 0) {
  7817. var url = data.url;
  7818. if (formatUploadUrl) {
  7819. url = K.formatUrl(url, 'absolute');
  7820. }
  7821. urlBox.val(url);
  7822. if (self.afterUpload) {
  7823. self.afterUpload.call(self, url, data, name);
  7824. }
  7825. alert(self.lang('uploadSuccess'));
  7826. } else {
  7827. alert(data.message);
  7828. }
  7829. },
  7830. afterError : function(html) {
  7831. dialog.hideLoading();
  7832. self.errorDialog(html);
  7833. }
  7834. });
  7835. uploadbutton.fileBox.change(function(e) {
  7836. dialog.showLoading(self.lang('uploadLoading'));
  7837. uploadbutton.submit();
  7838. });
  7839. } else {
  7840. K('.ke-upload-button', div).hide();
  7841. }
  7842. if (allowFileManager) {
  7843. viewServerBtn.click(function(e) {
  7844. self.loadPlugin('filemanager', function() {
  7845. self.plugin.filemanagerDialog({
  7846. viewType : 'LIST',
  7847. dirName : 'media',
  7848. clickFn : function(url, title) {
  7849. if (self.dialogs.length > 1) {
  7850. K('[name="url"]', div).val(url);
  7851. if (self.afterSelectFile) {
  7852. self.afterSelectFile.call(self, url);
  7853. }
  7854. self.hideDialog();
  7855. }
  7856. }
  7857. });
  7858. });
  7859. });
  7860. } else {
  7861. viewServerBtn.hide();
  7862. }
  7863. var img = self.plugin.getSelectedMedia();
  7864. if (img) {
  7865. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7866. urlBox.val(attrs.src);
  7867. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7868. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7869. autostartBox[0].checked = (attrs.autostart === 'true');
  7870. }
  7871. urlBox[0].focus();
  7872. urlBox[0].select();
  7873. },
  7874. 'delete' : function() {
  7875. self.plugin.getSelectedMedia().remove();
  7876. self.addBookmark();
  7877. }
  7878. };
  7879. self.clickToolbar(name, self.plugin.media.edit);
  7880. });
  7881. /*******************************************************************************
  7882. * KindEditor - WYSIWYG HTML Editor for Internet
  7883. * Copyright (C) 2006-2011 kindsoft.net
  7884. *
  7885. * @author Roddy <luolonghao@gmail.com>
  7886. * @site http://www.kindsoft.net/
  7887. * @licence http://www.kindsoft.net/license.php
  7888. *******************************************************************************/
  7889. (function(K) {
  7890. function KSWFUpload(options) {
  7891. this.init(options);
  7892. }
  7893. K.extend(KSWFUpload, {
  7894. init : function(options) {
  7895. var self = this;
  7896. options.afterError = options.afterError || function(str) {
  7897. alert(str);
  7898. };
  7899. self.options = options;
  7900. self.progressbars = {};
  7901. self.div = K(options.container).html([
  7902. '<div class="ke-swfupload">',
  7903. '<div class="ke-swfupload-top">',
  7904. '<div class="ke-inline-block ke-swfupload-button">',
  7905. '<input type="button" value="Browse" />',
  7906. '</div>',
  7907. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  7908. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  7909. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  7910. '</span>',
  7911. '</div>',
  7912. '<div class="ke-swfupload-body"></div>',
  7913. '</div>'
  7914. ].join(''));
  7915. self.bodyDiv = K('.ke-swfupload-body', self.div);
  7916. function showError(itemDiv, msg) {
  7917. K('.ke-status > div', itemDiv).hide();
  7918. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  7919. }
  7920. var settings = {
  7921. debug : false,
  7922. upload_url : options.uploadUrl,
  7923. flash_url : options.flashUrl,
  7924. file_post_name : options.filePostName,
  7925. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  7926. button_image_url: options.buttonImageUrl,
  7927. button_width: options.buttonWidth,
  7928. button_height: options.buttonHeight,
  7929. button_cursor : SWFUpload.CURSOR.HAND,
  7930. file_types : options.fileTypes,
  7931. file_types_description : options.fileTypesDesc,
  7932. file_upload_limit : options.fileUploadLimit,
  7933. file_size_limit : options.fileSizeLimit,
  7934. post_params : options.postParams,
  7935. file_queued_handler : function(file) {
  7936. file.url = self.options.fileIconUrl;
  7937. self.appendFile(file);
  7938. },
  7939. file_queue_error_handler : function(file, errorCode, message) {
  7940. var errorName = '';
  7941. switch (errorCode) {
  7942. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  7943. errorName = options.queueLimitExceeded;
  7944. break;
  7945. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  7946. errorName = options.fileExceedsSizeLimit;
  7947. break;
  7948. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  7949. errorName = options.zeroByteFile;
  7950. break;
  7951. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  7952. errorName = options.invalidFiletype;
  7953. break;
  7954. default:
  7955. errorName = options.unknownError;
  7956. break;
  7957. }
  7958. K.DEBUG && alert(errorName);
  7959. },
  7960. upload_start_handler : function(file) {
  7961. var self = this;
  7962. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  7963. K('.ke-status > div', itemDiv).hide();
  7964. K('.ke-progressbar', itemDiv).show();
  7965. },
  7966. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  7967. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  7968. var progressbar = self.progressbars[file.id];
  7969. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  7970. progressbar.percent.html(percent + '%');
  7971. },
  7972. upload_error_handler : function(file, errorCode, message) {
  7973. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  7974. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7975. showError(itemDiv, self.options.errorMessage);
  7976. }
  7977. },
  7978. upload_success_handler : function(file, serverData) {
  7979. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7980. var data = {};
  7981. try {
  7982. data = K.json(serverData);
  7983. } catch (e) {
  7984. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  7985. }
  7986. if (data.error !== 0) {
  7987. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  7988. return;
  7989. }
  7990. file.url = data.url;
  7991. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  7992. K('.ke-status > div', itemDiv).hide();
  7993. }
  7994. };
  7995. self.swfu = new SWFUpload(settings);
  7996. K('.ke-swfupload-startupload input', self.div).click(function() {
  7997. self.swfu.startUpload();
  7998. });
  7999. },
  8000. getUrlList : function() {
  8001. var list = [];
  8002. K('.ke-img', self.bodyDiv).each(function() {
  8003. var img = K(this);
  8004. var status = img.attr('data-status');
  8005. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  8006. list.push(img.data('data'));
  8007. }
  8008. });
  8009. return list;
  8010. },
  8011. removeFile : function(fileId) {
  8012. var self = this;
  8013. self.swfu.cancelUpload(fileId);
  8014. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  8015. K('.ke-photo', itemDiv).unbind();
  8016. K('.ke-delete', itemDiv).unbind();
  8017. itemDiv.remove();
  8018. },
  8019. removeFiles : function() {
  8020. var self = this;
  8021. K('.ke-item', self.bodyDiv).each(function() {
  8022. self.removeFile(K(this).attr('data-id'));
  8023. });
  8024. },
  8025. appendFile : function(file) {
  8026. var self = this;
  8027. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  8028. self.bodyDiv.append(itemDiv);
  8029. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  8030. .mouseover(function(e) {
  8031. K(this).addClass('ke-on');
  8032. })
  8033. .mouseout(function(e) {
  8034. K(this).removeClass('ke-on');
  8035. });
  8036. itemDiv.append(photoDiv);
  8037. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  8038. photoDiv.append(img);
  8039. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  8040. self.removeFile(file.id);
  8041. });
  8042. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  8043. K(['<div class="ke-progressbar">',
  8044. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  8045. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  8046. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  8047. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  8048. self.progressbars[file.id] = {
  8049. bar : K('.ke-progressbar-bar-inner', photoDiv),
  8050. percent : K('.ke-progressbar-percent', photoDiv)
  8051. };
  8052. },
  8053. remove : function() {
  8054. this.removeFiles();
  8055. this.swfu.destroy();
  8056. this.div.html('');
  8057. }
  8058. });
  8059. K.swfupload = function(element, options) {
  8060. return new KSWFUpload(element, options);
  8061. };
  8062. })(KindEditor);
  8063. KindEditor.plugin('multiimage', function(K) {
  8064. var self = this, name = 'multiimage',
  8065. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  8066. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  8067. imgPath = self.pluginsPath + 'multiimage/images/',
  8068. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  8069. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  8070. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  8071. filePostName = K.undef(self.filePostName, 'imgFile'),
  8072. lang = self.lang(name + '.');
  8073. self.plugin.multiImageDialog = function(options) {
  8074. var clickFn = options.clickFn,
  8075. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  8076. var html = [
  8077. '<div style="padding:20px;">',
  8078. '<div class="swfupload">',
  8079. '</div>',
  8080. '</div>'
  8081. ].join('');
  8082. var dialog = self.createDialog({
  8083. name : name,
  8084. width : 650,
  8085. height : 510,
  8086. title : self.lang(name),
  8087. body : html,
  8088. previewBtn : {
  8089. name : lang.insertAll,
  8090. click : function(e) {
  8091. clickFn.call(self, swfupload.getUrlList());
  8092. }
  8093. },
  8094. yesBtn : {
  8095. name : lang.clearAll,
  8096. click : function(e) {
  8097. swfupload.removeFiles();
  8098. }
  8099. },
  8100. beforeRemove : function() {
  8101. if (!K.IE || K.V <= 8) {
  8102. swfupload.remove();
  8103. }
  8104. }
  8105. }),
  8106. div = dialog.div;
  8107. var swfupload = K.swfupload({
  8108. container : K('.swfupload', div),
  8109. buttonImageUrl : imgPath + (self.langType == 'zh-CN' ? 'select-files-zh-CN.png' : 'select-files-en.png'),
  8110. buttonWidth : self.langType == 'zh-CN' ? 72 : 88,
  8111. buttonHeight : 23,
  8112. fileIconUrl : imgPath + 'image.png',
  8113. uploadDesc : uploadDesc,
  8114. startButtonValue : lang.startUpload,
  8115. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  8116. flashUrl : imgPath + 'swfupload.swf',
  8117. filePostName : filePostName,
  8118. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8119. fileTypesDesc : 'Image Files',
  8120. fileUploadLimit : imageUploadLimit,
  8121. fileSizeLimit : imageSizeLimit,
  8122. postParams : K.undef(self.extraFileUploadParams, {}),
  8123. queueLimitExceeded : lang.queueLimitExceeded,
  8124. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  8125. zeroByteFile : lang.zeroByteFile,
  8126. invalidFiletype : lang.invalidFiletype,
  8127. unknownError : lang.unknownError,
  8128. pendingMessage : lang.pending,
  8129. errorMessage : lang.uploadError,
  8130. afterError : function(html) {
  8131. self.errorDialog(html);
  8132. }
  8133. });
  8134. return dialog;
  8135. };
  8136. self.clickToolbar(name, function() {
  8137. self.plugin.multiImageDialog({
  8138. clickFn : function (urlList) {
  8139. if (urlList.length === 0) {
  8140. return;
  8141. }
  8142. K.each(urlList, function(i, data) {
  8143. if (self.afterUpload) {
  8144. self.afterUpload.call(self, data.url, data, 'multiimage');
  8145. }
  8146. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8147. });
  8148. setTimeout(function() {
  8149. self.hideDialog().focus();
  8150. }, 0);
  8151. }
  8152. });
  8153. });
  8154. });
  8155. /* ******************* */
  8156. /* Constructor & Init */
  8157. /* ******************* */
  8158. (function() {
  8159. window.SWFUpload = function (settings) {
  8160. this.initSWFUpload(settings);
  8161. };
  8162. SWFUpload.prototype.initSWFUpload = function (settings) {
  8163. try {
  8164. this.customSettings = {};
  8165. this.settings = settings;
  8166. this.eventQueue = [];
  8167. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8168. this.movieElement = null;
  8169. SWFUpload.instances[this.movieName] = this;
  8170. this.initSettings();
  8171. this.loadFlash();
  8172. this.displayDebugInfo();
  8173. } catch (ex) {
  8174. delete SWFUpload.instances[this.movieName];
  8175. throw ex;
  8176. }
  8177. };
  8178. /* *************** */
  8179. /* Static Members */
  8180. /* *************** */
  8181. SWFUpload.instances = {};
  8182. SWFUpload.movieCount = 0;
  8183. SWFUpload.version = "2.2.0 2009-03-25";
  8184. SWFUpload.QUEUE_ERROR = {
  8185. QUEUE_LIMIT_EXCEEDED : -100,
  8186. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8187. ZERO_BYTE_FILE : -120,
  8188. INVALID_FILETYPE : -130
  8189. };
  8190. SWFUpload.UPLOAD_ERROR = {
  8191. HTTP_ERROR : -200,
  8192. MISSING_UPLOAD_URL : -210,
  8193. IO_ERROR : -220,
  8194. SECURITY_ERROR : -230,
  8195. UPLOAD_LIMIT_EXCEEDED : -240,
  8196. UPLOAD_FAILED : -250,
  8197. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8198. FILE_VALIDATION_FAILED : -270,
  8199. FILE_CANCELLED : -280,
  8200. UPLOAD_STOPPED : -290
  8201. };
  8202. SWFUpload.FILE_STATUS = {
  8203. QUEUED : -1,
  8204. IN_PROGRESS : -2,
  8205. ERROR : -3,
  8206. COMPLETE : -4,
  8207. CANCELLED : -5
  8208. };
  8209. SWFUpload.BUTTON_ACTION = {
  8210. SELECT_FILE : -100,
  8211. SELECT_FILES : -110,
  8212. START_UPLOAD : -120
  8213. };
  8214. SWFUpload.CURSOR = {
  8215. ARROW : -1,
  8216. HAND : -2
  8217. };
  8218. SWFUpload.WINDOW_MODE = {
  8219. WINDOW : "window",
  8220. TRANSPARENT : "transparent",
  8221. OPAQUE : "opaque"
  8222. };
  8223. SWFUpload.completeURL = function(url) {
  8224. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8225. return url;
  8226. }
  8227. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8228. var indexSlash = window.location.pathname.lastIndexOf("/");
  8229. var path;
  8230. if (indexSlash <= 0) {
  8231. path = "/";
  8232. } else {
  8233. path = window.location.pathname.substr(0, indexSlash) + "/";
  8234. }
  8235. return /*currentURL +*/ path + url;
  8236. };
  8237. /* ******************** */
  8238. /* Instance Members */
  8239. /* ******************** */
  8240. SWFUpload.prototype.initSettings = function () {
  8241. this.ensureDefault = function (settingName, defaultValue) {
  8242. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8243. };
  8244. this.ensureDefault("upload_url", "");
  8245. this.ensureDefault("preserve_relative_urls", false);
  8246. this.ensureDefault("file_post_name", "Filedata");
  8247. this.ensureDefault("post_params", {});
  8248. this.ensureDefault("use_query_string", false);
  8249. this.ensureDefault("requeue_on_error", false);
  8250. this.ensureDefault("http_success", []);
  8251. this.ensureDefault("assume_success_timeout", 0);
  8252. this.ensureDefault("file_types", "*.*");
  8253. this.ensureDefault("file_types_description", "All Files");
  8254. this.ensureDefault("file_size_limit", 0);
  8255. this.ensureDefault("file_upload_limit", 0);
  8256. this.ensureDefault("file_queue_limit", 0);
  8257. this.ensureDefault("flash_url", "swfupload.swf");
  8258. this.ensureDefault("prevent_swf_caching", true);
  8259. this.ensureDefault("button_image_url", "");
  8260. this.ensureDefault("button_width", 1);
  8261. this.ensureDefault("button_height", 1);
  8262. this.ensureDefault("button_text", "");
  8263. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8264. this.ensureDefault("button_text_top_padding", 0);
  8265. this.ensureDefault("button_text_left_padding", 0);
  8266. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8267. this.ensureDefault("button_disabled", false);
  8268. this.ensureDefault("button_placeholder_id", "");
  8269. this.ensureDefault("button_placeholder", null);
  8270. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8271. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8272. this.ensureDefault("debug", false);
  8273. this.settings.debug_enabled = this.settings.debug;
  8274. this.settings.return_upload_start_handler = this.returnUploadStart;
  8275. this.ensureDefault("swfupload_loaded_handler", null);
  8276. this.ensureDefault("file_dialog_start_handler", null);
  8277. this.ensureDefault("file_queued_handler", null);
  8278. this.ensureDefault("file_queue_error_handler", null);
  8279. this.ensureDefault("file_dialog_complete_handler", null);
  8280. this.ensureDefault("upload_start_handler", null);
  8281. this.ensureDefault("upload_progress_handler", null);
  8282. this.ensureDefault("upload_error_handler", null);
  8283. this.ensureDefault("upload_success_handler", null);
  8284. this.ensureDefault("upload_complete_handler", null);
  8285. this.ensureDefault("debug_handler", this.debugMessage);
  8286. this.ensureDefault("custom_settings", {});
  8287. this.customSettings = this.settings.custom_settings;
  8288. if (!!this.settings.prevent_swf_caching) {
  8289. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8290. }
  8291. if (!this.settings.preserve_relative_urls) {
  8292. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8293. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8294. }
  8295. delete this.ensureDefault;
  8296. };
  8297. SWFUpload.prototype.loadFlash = function () {
  8298. var targetElement, tempParent;
  8299. if (document.getElementById(this.movieName) !== null) {
  8300. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8301. }
  8302. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8303. if (targetElement == undefined) {
  8304. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8305. }
  8306. tempParent = document.createElement("div");
  8307. tempParent.innerHTML = this.getFlashHTML();
  8308. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8309. if (window[this.movieName] == undefined) {
  8310. window[this.movieName] = this.getMovieElement();
  8311. }
  8312. };
  8313. SWFUpload.prototype.getFlashHTML = function () {
  8314. var classid = '';
  8315. if (KindEditor.IE && KindEditor.V > 8) {
  8316. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8317. }
  8318. return ['<object id="', this.movieName, '"' + classid + ' type="application/x-shockwave-flash" data="', this.settings.flash_url, '" width="', this.settings.button_width, '" height="', this.settings.button_height, '" class="swfupload">',
  8319. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8320. '<param name="movie" value="', this.settings.flash_url, '" />',
  8321. '<param name="quality" value="high" />',
  8322. '<param name="menu" value="false" />',
  8323. '<param name="allowScriptAccess" value="always" />',
  8324. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8325. '</object>'].join("");
  8326. };
  8327. SWFUpload.prototype.getFlashVars = function () {
  8328. var paramString = this.buildParamString();
  8329. var httpSuccessString = this.settings.http_success.join(",");
  8330. return ["movieName=", encodeURIComponent(this.movieName),
  8331. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8332. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8333. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8334. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8335. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8336. "&amp;params=", encodeURIComponent(paramString),
  8337. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8338. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8339. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8340. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8341. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8342. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8343. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8344. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8345. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8346. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8347. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8348. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8349. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8350. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8351. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8352. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8353. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8354. ].join("");
  8355. };
  8356. SWFUpload.prototype.getMovieElement = function () {
  8357. if (this.movieElement == undefined) {
  8358. this.movieElement = document.getElementById(this.movieName);
  8359. }
  8360. if (this.movieElement === null) {
  8361. throw "Could not find Flash element";
  8362. }
  8363. return this.movieElement;
  8364. };
  8365. SWFUpload.prototype.buildParamString = function () {
  8366. var postParams = this.settings.post_params;
  8367. var paramStringPairs = [];
  8368. if (typeof(postParams) === "object") {
  8369. for (var name in postParams) {
  8370. if (postParams.hasOwnProperty(name)) {
  8371. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8372. }
  8373. }
  8374. }
  8375. return paramStringPairs.join("&amp;");
  8376. };
  8377. SWFUpload.prototype.destroy = function () {
  8378. try {
  8379. this.cancelUpload(null, false);
  8380. var movieElement = null;
  8381. movieElement = this.getMovieElement();
  8382. if (movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8383. for (var i in movieElement) {
  8384. try {
  8385. if (typeof(movieElement[i]) === "function") {
  8386. movieElement[i] = null;
  8387. }
  8388. } catch (ex1) {}
  8389. }
  8390. try {
  8391. movieElement.parentNode.removeChild(movieElement);
  8392. } catch (ex) {}
  8393. }
  8394. window[this.movieName] = null;
  8395. SWFUpload.instances[this.movieName] = null;
  8396. delete SWFUpload.instances[this.movieName];
  8397. this.movieElement = null;
  8398. this.settings = null;
  8399. this.customSettings = null;
  8400. this.eventQueue = null;
  8401. this.movieName = null;
  8402. return true;
  8403. } catch (ex2) {
  8404. return false;
  8405. }
  8406. };
  8407. SWFUpload.prototype.displayDebugInfo = function () {
  8408. this.debug(
  8409. [
  8410. "---SWFUpload Instance Info---\n",
  8411. "Version: ", SWFUpload.version, "\n",
  8412. "Movie Name: ", this.movieName, "\n",
  8413. "Settings:\n",
  8414. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8415. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8416. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8417. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8418. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8419. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8420. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8421. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8422. "\t", "file_types: ", this.settings.file_types, "\n",
  8423. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8424. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8425. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8426. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8427. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8428. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8429. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8430. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8431. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8432. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8433. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8434. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8435. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8436. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8437. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8438. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8439. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8440. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8441. "Event Handlers:\n",
  8442. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8443. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8444. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8445. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8446. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8447. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8448. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8449. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8450. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8451. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8452. ].join("")
  8453. );
  8454. };
  8455. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8456. the maintain v2 API compatibility
  8457. */
  8458. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8459. if (value == undefined) {
  8460. return (this.settings[name] = default_value);
  8461. } else {
  8462. return (this.settings[name] = value);
  8463. }
  8464. };
  8465. SWFUpload.prototype.getSetting = function (name) {
  8466. if (this.settings[name] != undefined) {
  8467. return this.settings[name];
  8468. }
  8469. return "";
  8470. };
  8471. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8472. argumentArray = argumentArray || [];
  8473. var movieElement = this.getMovieElement();
  8474. var returnValue, returnString;
  8475. try {
  8476. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8477. returnValue = eval(returnString);
  8478. } catch (ex) {
  8479. throw "Call to " + functionName + " failed";
  8480. }
  8481. if (returnValue != undefined && typeof returnValue.post === "object") {
  8482. returnValue = this.unescapeFilePostParams(returnValue);
  8483. }
  8484. return returnValue;
  8485. };
  8486. /* *****************************
  8487. -- Flash control methods --
  8488. Your UI should use these
  8489. to operate SWFUpload
  8490. ***************************** */
  8491. SWFUpload.prototype.selectFile = function () {
  8492. this.callFlash("SelectFile");
  8493. };
  8494. SWFUpload.prototype.selectFiles = function () {
  8495. this.callFlash("SelectFiles");
  8496. };
  8497. SWFUpload.prototype.startUpload = function (fileID) {
  8498. this.callFlash("StartUpload", [fileID]);
  8499. };
  8500. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8501. if (triggerErrorEvent !== false) {
  8502. triggerErrorEvent = true;
  8503. }
  8504. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8505. };
  8506. SWFUpload.prototype.stopUpload = function () {
  8507. this.callFlash("StopUpload");
  8508. };
  8509. /* ************************
  8510. * Settings methods
  8511. * These methods change the SWFUpload settings.
  8512. * SWFUpload settings should not be changed directly on the settings object
  8513. * since many of the settings need to be passed to Flash in order to take
  8514. * effect.
  8515. * *********************** */
  8516. SWFUpload.prototype.getStats = function () {
  8517. return this.callFlash("GetStats");
  8518. };
  8519. SWFUpload.prototype.setStats = function (statsObject) {
  8520. this.callFlash("SetStats", [statsObject]);
  8521. };
  8522. SWFUpload.prototype.getFile = function (fileID) {
  8523. if (typeof(fileID) === "number") {
  8524. return this.callFlash("GetFileByIndex", [fileID]);
  8525. } else {
  8526. return this.callFlash("GetFile", [fileID]);
  8527. }
  8528. };
  8529. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8530. return this.callFlash("AddFileParam", [fileID, name, value]);
  8531. };
  8532. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8533. this.callFlash("RemoveFileParam", [fileID, name]);
  8534. };
  8535. SWFUpload.prototype.setUploadURL = function (url) {
  8536. this.settings.upload_url = url.toString();
  8537. this.callFlash("SetUploadURL", [url]);
  8538. };
  8539. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8540. this.settings.post_params = paramsObject;
  8541. this.callFlash("SetPostParams", [paramsObject]);
  8542. };
  8543. SWFUpload.prototype.addPostParam = function (name, value) {
  8544. this.settings.post_params[name] = value;
  8545. this.callFlash("SetPostParams", [this.settings.post_params]);
  8546. };
  8547. SWFUpload.prototype.removePostParam = function (name) {
  8548. delete this.settings.post_params[name];
  8549. this.callFlash("SetPostParams", [this.settings.post_params]);
  8550. };
  8551. SWFUpload.prototype.setFileTypes = function (types, description) {
  8552. this.settings.file_types = types;
  8553. this.settings.file_types_description = description;
  8554. this.callFlash("SetFileTypes", [types, description]);
  8555. };
  8556. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8557. this.settings.file_size_limit = fileSizeLimit;
  8558. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8559. };
  8560. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8561. this.settings.file_upload_limit = fileUploadLimit;
  8562. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8563. };
  8564. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8565. this.settings.file_queue_limit = fileQueueLimit;
  8566. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8567. };
  8568. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8569. this.settings.file_post_name = filePostName;
  8570. this.callFlash("SetFilePostName", [filePostName]);
  8571. };
  8572. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8573. this.settings.use_query_string = useQueryString;
  8574. this.callFlash("SetUseQueryString", [useQueryString]);
  8575. };
  8576. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8577. this.settings.requeue_on_error = requeueOnError;
  8578. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8579. };
  8580. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8581. if (typeof http_status_codes === "string") {
  8582. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8583. }
  8584. this.settings.http_success = http_status_codes;
  8585. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8586. };
  8587. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8588. this.settings.assume_success_timeout = timeout_seconds;
  8589. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8590. };
  8591. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8592. this.settings.debug_enabled = debugEnabled;
  8593. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8594. };
  8595. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8596. if (buttonImageURL == undefined) {
  8597. buttonImageURL = "";
  8598. }
  8599. this.settings.button_image_url = buttonImageURL;
  8600. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8601. };
  8602. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8603. this.settings.button_width = width;
  8604. this.settings.button_height = height;
  8605. var movie = this.getMovieElement();
  8606. if (movie != undefined) {
  8607. movie.style.width = width + "px";
  8608. movie.style.height = height + "px";
  8609. }
  8610. this.callFlash("SetButtonDimensions", [width, height]);
  8611. };
  8612. SWFUpload.prototype.setButtonText = function (html) {
  8613. this.settings.button_text = html;
  8614. this.callFlash("SetButtonText", [html]);
  8615. };
  8616. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8617. this.settings.button_text_top_padding = top;
  8618. this.settings.button_text_left_padding = left;
  8619. this.callFlash("SetButtonTextPadding", [left, top]);
  8620. };
  8621. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8622. this.settings.button_text_style = css;
  8623. this.callFlash("SetButtonTextStyle", [css]);
  8624. };
  8625. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8626. this.settings.button_disabled = isDisabled;
  8627. this.callFlash("SetButtonDisabled", [isDisabled]);
  8628. };
  8629. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8630. this.settings.button_action = buttonAction;
  8631. this.callFlash("SetButtonAction", [buttonAction]);
  8632. };
  8633. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8634. this.settings.button_cursor = cursor;
  8635. this.callFlash("SetButtonCursor", [cursor]);
  8636. };
  8637. /* *******************************
  8638. Flash Event Interfaces
  8639. These functions are used by Flash to trigger the various
  8640. events.
  8641. All these functions a Private.
  8642. Because the ExternalInterface library is buggy the event calls
  8643. are added to a queue and the queue then executed by a setTimeout.
  8644. This ensures that events are executed in a determinate order and that
  8645. the ExternalInterface bugs are avoided.
  8646. ******************************* */
  8647. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8648. if (argumentArray == undefined) {
  8649. argumentArray = [];
  8650. } else if (!(argumentArray instanceof Array)) {
  8651. argumentArray = [argumentArray];
  8652. }
  8653. var self = this;
  8654. if (typeof this.settings[handlerName] === "function") {
  8655. this.eventQueue.push(function () {
  8656. this.settings[handlerName].apply(this, argumentArray);
  8657. });
  8658. setTimeout(function () {
  8659. self.executeNextEvent();
  8660. }, 0);
  8661. } else if (this.settings[handlerName] !== null) {
  8662. throw "Event handler " + handlerName + " is unknown or is not a function";
  8663. }
  8664. };
  8665. SWFUpload.prototype.executeNextEvent = function () {
  8666. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8667. if (typeof(f) === "function") {
  8668. f.apply(this);
  8669. }
  8670. };
  8671. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8672. var reg = /[$]([0-9a-f]{4})/i;
  8673. var unescapedPost = {};
  8674. var uk;
  8675. if (file != undefined) {
  8676. for (var k in file.post) {
  8677. if (file.post.hasOwnProperty(k)) {
  8678. uk = k;
  8679. var match;
  8680. while ((match = reg.exec(uk)) !== null) {
  8681. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8682. }
  8683. unescapedPost[uk] = file.post[k];
  8684. }
  8685. }
  8686. file.post = unescapedPost;
  8687. }
  8688. return file;
  8689. };
  8690. SWFUpload.prototype.testExternalInterface = function () {
  8691. try {
  8692. return this.callFlash("TestExternalInterface");
  8693. } catch (ex) {
  8694. return false;
  8695. }
  8696. };
  8697. SWFUpload.prototype.flashReady = function () {
  8698. var movieElement = this.getMovieElement();
  8699. if (!movieElement) {
  8700. this.debug("Flash called back ready but the flash movie can't be found.");
  8701. return;
  8702. }
  8703. this.cleanUp(movieElement);
  8704. this.queueEvent("swfupload_loaded_handler");
  8705. };
  8706. SWFUpload.prototype.cleanUp = function (movieElement) {
  8707. try {
  8708. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8709. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8710. for (var key in movieElement) {
  8711. try {
  8712. if (typeof(movieElement[key]) === "function") {
  8713. movieElement[key] = null;
  8714. }
  8715. } catch (ex) {
  8716. }
  8717. }
  8718. }
  8719. } catch (ex1) {
  8720. }
  8721. window["__flash__removeCallback"] = function (instance, name) {
  8722. try {
  8723. if (instance) {
  8724. instance[name] = null;
  8725. }
  8726. } catch (flashEx) {
  8727. }
  8728. };
  8729. };
  8730. /* This is a chance to do something before the browse window opens */
  8731. SWFUpload.prototype.fileDialogStart = function () {
  8732. this.queueEvent("file_dialog_start_handler");
  8733. };
  8734. /* Called when a file is successfully added to the queue. */
  8735. SWFUpload.prototype.fileQueued = function (file) {
  8736. file = this.unescapeFilePostParams(file);
  8737. this.queueEvent("file_queued_handler", file);
  8738. };
  8739. /* Handle errors that occur when an attempt to queue a file fails. */
  8740. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  8741. file = this.unescapeFilePostParams(file);
  8742. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  8743. };
  8744. /* Called after the file dialog has closed and the selected files have been queued.
  8745. You could call startUpload here if you want the queued files to begin uploading immediately. */
  8746. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  8747. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  8748. };
  8749. SWFUpload.prototype.uploadStart = function (file) {
  8750. file = this.unescapeFilePostParams(file);
  8751. this.queueEvent("return_upload_start_handler", file);
  8752. };
  8753. SWFUpload.prototype.returnUploadStart = function (file) {
  8754. var returnValue;
  8755. if (typeof this.settings.upload_start_handler === "function") {
  8756. file = this.unescapeFilePostParams(file);
  8757. returnValue = this.settings.upload_start_handler.call(this, file);
  8758. } else if (this.settings.upload_start_handler != undefined) {
  8759. throw "upload_start_handler must be a function";
  8760. }
  8761. if (returnValue === undefined) {
  8762. returnValue = true;
  8763. }
  8764. returnValue = !!returnValue;
  8765. this.callFlash("ReturnUploadStart", [returnValue]);
  8766. };
  8767. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  8768. file = this.unescapeFilePostParams(file);
  8769. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  8770. };
  8771. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  8772. file = this.unescapeFilePostParams(file);
  8773. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  8774. };
  8775. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  8776. file = this.unescapeFilePostParams(file);
  8777. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  8778. };
  8779. SWFUpload.prototype.uploadComplete = function (file) {
  8780. file = this.unescapeFilePostParams(file);
  8781. this.queueEvent("upload_complete_handler", file);
  8782. };
  8783. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  8784. internal debug console. You can override this event and have messages written where you want. */
  8785. SWFUpload.prototype.debug = function (message) {
  8786. this.queueEvent("debug_handler", message);
  8787. };
  8788. /* **********************************
  8789. Debug Console
  8790. The debug console is a self contained, in page location
  8791. for debug message to be sent. The Debug Console adds
  8792. itself to the body if necessary.
  8793. The console is automatically scrolled as messages appear.
  8794. If you are using your own debug handler or when you deploy to production and
  8795. have debug disabled you can remove these functions to reduce the file size
  8796. and complexity.
  8797. ********************************** */
  8798. SWFUpload.prototype.debugMessage = function (message) {
  8799. if (this.settings.debug) {
  8800. var exceptionMessage, exceptionValues = [];
  8801. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  8802. for (var key in message) {
  8803. if (message.hasOwnProperty(key)) {
  8804. exceptionValues.push(key + ": " + message[key]);
  8805. }
  8806. }
  8807. exceptionMessage = exceptionValues.join("\n") || "";
  8808. exceptionValues = exceptionMessage.split("\n");
  8809. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  8810. SWFUpload.Console.writeLine(exceptionMessage);
  8811. } else {
  8812. SWFUpload.Console.writeLine(message);
  8813. }
  8814. }
  8815. };
  8816. SWFUpload.Console = {};
  8817. SWFUpload.Console.writeLine = function (message) {
  8818. var console, documentForm;
  8819. try {
  8820. console = document.getElementById("SWFUpload_Console");
  8821. if (!console) {
  8822. documentForm = document.createElement("form");
  8823. document.getElementsByTagName("body")[0].appendChild(documentForm);
  8824. console = document.createElement("textarea");
  8825. console.id = "SWFUpload_Console";
  8826. console.style.fontFamily = "monospace";
  8827. console.setAttribute("wrap", "off");
  8828. console.wrap = "off";
  8829. console.style.overflow = "auto";
  8830. console.style.width = "700px";
  8831. console.style.height = "350px";
  8832. console.style.margin = "5px";
  8833. documentForm.appendChild(console);
  8834. }
  8835. console.value += message + "\n";
  8836. console.scrollTop = console.scrollHeight - console.clientHeight;
  8837. } catch (ex) {
  8838. alert("Exception: " + ex.name + " Message: " + ex.message);
  8839. }
  8840. };
  8841. })();
  8842. (function() {
  8843. /*
  8844. Queue Plug-in
  8845. Features:
  8846. *Adds a cancelQueue() method for cancelling the entire queue.
  8847. *All queued files are uploaded when startUpload() is called.
  8848. *If false is returned from uploadComplete then the queue upload is stopped.
  8849. If false is not returned (strict comparison) then the queue upload is continued.
  8850. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  8851. Set the event handler with the queue_complete_handler setting.
  8852. */
  8853. if (typeof(SWFUpload) === "function") {
  8854. SWFUpload.queue = {};
  8855. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  8856. return function () {
  8857. if (typeof(oldInitSettings) === "function") {
  8858. oldInitSettings.call(this);
  8859. }
  8860. this.queueSettings = {};
  8861. this.queueSettings.queue_cancelled_flag = false;
  8862. this.queueSettings.queue_upload_count = 0;
  8863. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  8864. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  8865. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  8866. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  8867. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  8868. };
  8869. })(SWFUpload.prototype.initSettings);
  8870. SWFUpload.prototype.startUpload = function (fileID) {
  8871. this.queueSettings.queue_cancelled_flag = false;
  8872. this.callFlash("StartUpload", [fileID]);
  8873. };
  8874. SWFUpload.prototype.cancelQueue = function () {
  8875. this.queueSettings.queue_cancelled_flag = true;
  8876. this.stopUpload();
  8877. var stats = this.getStats();
  8878. while (stats.files_queued > 0) {
  8879. this.cancelUpload();
  8880. stats = this.getStats();
  8881. }
  8882. };
  8883. SWFUpload.queue.uploadStartHandler = function (file) {
  8884. var returnValue;
  8885. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  8886. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  8887. }
  8888. returnValue = (returnValue === false) ? false : true;
  8889. this.queueSettings.queue_cancelled_flag = !returnValue;
  8890. return returnValue;
  8891. };
  8892. SWFUpload.queue.uploadCompleteHandler = function (file) {
  8893. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  8894. var continueUpload;
  8895. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  8896. this.queueSettings.queue_upload_count++;
  8897. }
  8898. if (typeof(user_upload_complete_handler) === "function") {
  8899. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  8900. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  8901. continueUpload = false;
  8902. } else {
  8903. continueUpload = true;
  8904. }
  8905. if (continueUpload) {
  8906. var stats = this.getStats();
  8907. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  8908. this.startUpload();
  8909. } else if (this.queueSettings.queue_cancelled_flag === false) {
  8910. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  8911. this.queueSettings.queue_upload_count = 0;
  8912. } else {
  8913. this.queueSettings.queue_cancelled_flag = false;
  8914. this.queueSettings.queue_upload_count = 0;
  8915. }
  8916. }
  8917. };
  8918. }
  8919. })();
  8920. /*******************************************************************************
  8921. * KindEditor - WYSIWYG HTML Editor for Internet
  8922. * Copyright (C) 2006-2011 kindsoft.net
  8923. *
  8924. * @author Roddy <luolonghao@gmail.com>
  8925. * @site http://www.kindsoft.net/
  8926. * @licence http://www.kindsoft.net/license.php
  8927. *******************************************************************************/
  8928. KindEditor.plugin('pagebreak', function(K) {
  8929. var self = this;
  8930. var name = 'pagebreak';
  8931. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  8932. self.clickToolbar(name, function() {
  8933. var cmd = self.cmd, range = cmd.range;
  8934. self.focus();
  8935. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  8936. self.insertHtml(pagebreakHtml + tail);
  8937. if (tail !== '') {
  8938. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  8939. range.selectNodeContents(p[0]);
  8940. p.removeAttr('id');
  8941. cmd.select();
  8942. }
  8943. });
  8944. });
  8945. /*******************************************************************************
  8946. * KindEditor - WYSIWYG HTML Editor for Internet
  8947. * Copyright (C) 2006-2011 kindsoft.net
  8948. *
  8949. * @author Roddy <luolonghao@gmail.com>
  8950. * @site http://www.kindsoft.net/
  8951. * @licence http://www.kindsoft.net/license.php
  8952. *******************************************************************************/
  8953. KindEditor.plugin('plainpaste', function(K) {
  8954. var self = this, name = 'plainpaste';
  8955. self.clickToolbar(name, function() {
  8956. var lang = self.lang(name + '.'),
  8957. html = '<div style="padding:10px 20px;">' +
  8958. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  8959. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  8960. '</div>',
  8961. dialog = self.createDialog({
  8962. name : name,
  8963. width : 450,
  8964. title : self.lang(name),
  8965. body : html,
  8966. yesBtn : {
  8967. name : self.lang('yes'),
  8968. click : function(e) {
  8969. var html = textarea.val();
  8970. html = K.escape(html);
  8971. html = html.replace(/ {2}/g, ' &nbsp;');
  8972. if (self.newlineTag == 'p') {
  8973. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  8974. } else {
  8975. html = html.replace(/\n/g, '<br />$&');
  8976. }
  8977. self.insertHtml(html).hideDialog().focus();
  8978. }
  8979. }
  8980. }),
  8981. textarea = K('textarea', dialog.div);
  8982. textarea[0].focus();
  8983. });
  8984. });
  8985. /*******************************************************************************
  8986. * KindEditor - WYSIWYG HTML Editor for Internet
  8987. * Copyright (C) 2006-2011 kindsoft.net
  8988. *
  8989. * @author Roddy <luolonghao@gmail.com>
  8990. * @site http://www.kindsoft.net/
  8991. * @licence http://www.kindsoft.net/license.php
  8992. *******************************************************************************/
  8993. KindEditor.plugin('preview', function(K) {
  8994. var self = this, name = 'preview', undefined;
  8995. self.clickToolbar(name, function() {
  8996. var lang = self.lang(name + '.'),
  8997. html = '<div style="padding:10px 20px;">' +
  8998. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  8999. '</div>',
  9000. dialog = self.createDialog({
  9001. name : name,
  9002. width : 750,
  9003. title : self.lang(name),
  9004. body : html
  9005. }),
  9006. iframe = K('iframe', dialog.div),
  9007. doc = K.iframeDoc(iframe);
  9008. doc.open();
  9009. doc.write(self.fullHtml());
  9010. doc.close();
  9011. K(doc.body).css('background-color', '#FFF');
  9012. iframe[0].contentWindow.focus();
  9013. });
  9014. });
  9015. /*******************************************************************************
  9016. * KindEditor - WYSIWYG HTML Editor for Internet
  9017. * Copyright (C) 2006-2011 kindsoft.net
  9018. *
  9019. * @author Roddy <luolonghao@gmail.com>
  9020. * @site http://www.kindsoft.net/
  9021. * @licence http://www.kindsoft.net/license.php
  9022. *******************************************************************************/
  9023. KindEditor.plugin('quickformat', function(K) {
  9024. var self = this, name = 'quickformat',
  9025. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  9026. function getFirstChild(knode) {
  9027. var child = knode.first();
  9028. while (child && child.first()) {
  9029. child = child.first();
  9030. }
  9031. return child;
  9032. }
  9033. self.clickToolbar(name, function() {
  9034. self.focus();
  9035. var doc = self.edit.doc,
  9036. range = self.cmd.range,
  9037. child = K(doc.body).first(), next,
  9038. nodeList = [], subList = [],
  9039. bookmark = range.createBookmark(true);
  9040. while(child) {
  9041. next = child.next();
  9042. var firstChild = getFirstChild(child);
  9043. if (!firstChild || firstChild.name != 'img') {
  9044. if (blockMap[child.name]) {
  9045. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  9046. child.css('text-indent', '2em');
  9047. } else {
  9048. subList.push(child);
  9049. }
  9050. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  9051. if (subList.length > 0) {
  9052. nodeList.push(subList);
  9053. }
  9054. subList = [];
  9055. }
  9056. }
  9057. child = next;
  9058. }
  9059. K.each(nodeList, function(i, subList) {
  9060. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  9061. subList[0].before(wrapper);
  9062. K.each(subList, function(i, knode) {
  9063. wrapper.append(knode);
  9064. });
  9065. });
  9066. range.moveToBookmark(bookmark);
  9067. self.addBookmark();
  9068. });
  9069. });
  9070. /*******************************************************************************
  9071. * KindEditor - WYSIWYG HTML Editor for Internet
  9072. * Copyright (C) 2006-2011 kindsoft.net
  9073. *
  9074. * @author Roddy <luolonghao@gmail.com>
  9075. * @site http://www.kindsoft.net/
  9076. * @licence http://www.kindsoft.net/license.php
  9077. *******************************************************************************/
  9078. KindEditor.plugin('table', function(K) {
  9079. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  9080. function _setColor(box, color) {
  9081. color = color.toUpperCase();
  9082. box.css('background-color', color);
  9083. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  9084. box.html(color);
  9085. }
  9086. var pickerList = [];
  9087. function _initColorPicker(dialogDiv, colorBox) {
  9088. colorBox.bind('click,mousedown', function(e){
  9089. e.stopPropagation();
  9090. });
  9091. function removePicker() {
  9092. K.each(pickerList, function() {
  9093. this.remove();
  9094. });
  9095. pickerList = [];
  9096. K(document).unbind('click,mousedown', removePicker);
  9097. dialogDiv.unbind('click,mousedown', removePicker);
  9098. }
  9099. colorBox.click(function(e) {
  9100. removePicker();
  9101. var box = K(this),
  9102. pos = box.pos();
  9103. var picker = K.colorpicker({
  9104. x : pos.x,
  9105. y : pos.y + box.height(),
  9106. z : 811214,
  9107. selectedColor : K(this).html(),
  9108. colors : self.colorTable,
  9109. noColor : self.lang('noColor'),
  9110. shadowMode : self.shadowMode,
  9111. click : function(color) {
  9112. _setColor(box, color);
  9113. removePicker();
  9114. }
  9115. });
  9116. pickerList.push(picker);
  9117. K(document).bind('click,mousedown', removePicker);
  9118. dialogDiv.bind('click,mousedown', removePicker);
  9119. });
  9120. }
  9121. function _getCellIndex(table, row, cell) {
  9122. var rowSpanCount = 0;
  9123. for (var i = 0, len = row.cells.length; i < len; i++) {
  9124. if (row.cells[i] == cell) {
  9125. break;
  9126. }
  9127. rowSpanCount += row.cells[i].rowSpan - 1;
  9128. }
  9129. return cell.cellIndex - rowSpanCount;
  9130. }
  9131. self.plugin.table = {
  9132. prop : function(isInsert) {
  9133. var html = [
  9134. '<div style="padding:20px;">',
  9135. '<div class="ke-dialog-row">',
  9136. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9137. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9138. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9139. '</div>',
  9140. '<div class="ke-dialog-row">',
  9141. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9142. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9143. '<select name="widthType">',
  9144. '<option value="%">' + lang.percent + '</option>',
  9145. '<option value="px">' + lang.px + '</option>',
  9146. '</select> &nbsp; ',
  9147. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9148. '<select name="heightType">',
  9149. '<option value="%">' + lang.percent + '</option>',
  9150. '<option value="px">' + lang.px + '</option>',
  9151. '</select>',
  9152. '</div>',
  9153. '<div class="ke-dialog-row">',
  9154. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9155. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9156. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9157. '</div>',
  9158. '<div class="ke-dialog-row">',
  9159. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9160. '<select id="keAlign" name="align">',
  9161. '<option value="">' + lang.alignDefault + '</option>',
  9162. '<option value="left">' + lang.alignLeft + '</option>',
  9163. '<option value="center">' + lang.alignCenter + '</option>',
  9164. '<option value="right">' + lang.alignRight + '</option>',
  9165. '</select>',
  9166. '</div>',
  9167. '<div class="ke-dialog-row">',
  9168. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9169. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9170. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9171. '</div>',
  9172. '<div class="ke-dialog-row">',
  9173. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9174. '<span class="ke-inline-block ke-input-color"></span>',
  9175. '</div>',
  9176. '</div>'
  9177. ].join('');
  9178. var bookmark = self.cmd.range.createBookmark();
  9179. var dialog = self.createDialog({
  9180. name : name,
  9181. width : 500,
  9182. title : self.lang(name),
  9183. body : html,
  9184. beforeRemove : function() {
  9185. colorBox.unbind();
  9186. },
  9187. yesBtn : {
  9188. name : self.lang('yes'),
  9189. click : function(e) {
  9190. var rows = rowsBox.val(),
  9191. cols = colsBox.val(),
  9192. width = widthBox.val(),
  9193. height = heightBox.val(),
  9194. widthType = widthTypeBox.val(),
  9195. heightType = heightTypeBox.val(),
  9196. padding = paddingBox.val(),
  9197. spacing = spacingBox.val(),
  9198. align = alignBox.val(),
  9199. border = borderBox.val(),
  9200. borderColor = K(colorBox[0]).html() || '',
  9201. bgColor = K(colorBox[1]).html() || '';
  9202. if (rows == 0 || !/^\d+$/.test(rows)) {
  9203. alert(self.lang('invalidRows'));
  9204. rowsBox[0].focus();
  9205. return;
  9206. }
  9207. if (cols == 0 || !/^\d+$/.test(cols)) {
  9208. alert(self.lang('invalidRows'));
  9209. colsBox[0].focus();
  9210. return;
  9211. }
  9212. if (!/^\d*$/.test(width)) {
  9213. alert(self.lang('invalidWidth'));
  9214. widthBox[0].focus();
  9215. return;
  9216. }
  9217. if (!/^\d*$/.test(height)) {
  9218. alert(self.lang('invalidHeight'));
  9219. heightBox[0].focus();
  9220. return;
  9221. }
  9222. if (!/^\d*$/.test(padding)) {
  9223. alert(self.lang('invalidPadding'));
  9224. paddingBox[0].focus();
  9225. return;
  9226. }
  9227. if (!/^\d*$/.test(spacing)) {
  9228. alert(self.lang('invalidSpacing'));
  9229. spacingBox[0].focus();
  9230. return;
  9231. }
  9232. if (!/^\d*$/.test(border)) {
  9233. alert(self.lang('invalidBorder'));
  9234. borderBox[0].focus();
  9235. return;
  9236. }
  9237. if (table) {
  9238. if (width !== '') {
  9239. table.width(width + widthType);
  9240. } else {
  9241. table.css('width', '');
  9242. }
  9243. if (table[0].width !== undefined) {
  9244. table.removeAttr('width');
  9245. }
  9246. if (height !== '') {
  9247. table.height(height + heightType);
  9248. } else {
  9249. table.css('height', '');
  9250. }
  9251. if (table[0].height !== undefined) {
  9252. table.removeAttr('height');
  9253. }
  9254. table.css('background-color', bgColor);
  9255. if (table[0].bgColor !== undefined) {
  9256. table.removeAttr('bgColor');
  9257. }
  9258. if (padding !== '') {
  9259. table[0].cellPadding = padding;
  9260. } else {
  9261. table.removeAttr('cellPadding');
  9262. }
  9263. if (spacing !== '') {
  9264. table[0].cellSpacing = spacing;
  9265. } else {
  9266. table.removeAttr('cellSpacing');
  9267. }
  9268. if (align !== '') {
  9269. table[0].align = align;
  9270. } else {
  9271. table.removeAttr('align');
  9272. }
  9273. if (border !== '') {
  9274. table.attr('border', border);
  9275. } else {
  9276. table.removeAttr('border');
  9277. }
  9278. if (border === '' || border === '0') {
  9279. table.addClass(zeroborder);
  9280. } else {
  9281. table.removeClass(zeroborder);
  9282. }
  9283. if (borderColor !== '') {
  9284. table.attr('borderColor', borderColor);
  9285. } else {
  9286. table.removeAttr('borderColor');
  9287. }
  9288. self.hideDialog().focus();
  9289. self.cmd.range.moveToBookmark(bookmark);
  9290. self.cmd.select();
  9291. self.addBookmark();
  9292. return;
  9293. }
  9294. var style = '';
  9295. if (width !== '') {
  9296. style += 'width:' + width + widthType + ';';
  9297. }
  9298. if (height !== '') {
  9299. style += 'height:' + height + heightType + ';';
  9300. }
  9301. if (bgColor !== '') {
  9302. style += 'background-color:' + bgColor + ';';
  9303. }
  9304. var html = '<table';
  9305. if (style !== '') {
  9306. html += ' style="' + style + '"';
  9307. }
  9308. if (padding !== '') {
  9309. html += ' cellpadding="' + padding + '"';
  9310. }
  9311. if (spacing !== '') {
  9312. html += ' cellspacing="' + spacing + '"';
  9313. }
  9314. if (align !== '') {
  9315. html += ' align="' + align + '"';
  9316. }
  9317. if (border !== '') {
  9318. html += ' border="' + border + '"';
  9319. }
  9320. if (border === '' || border === '0') {
  9321. html += ' class="' + zeroborder + '"';
  9322. }
  9323. if (borderColor !== '') {
  9324. html += ' bordercolor="' + borderColor + '"';
  9325. }
  9326. html += '>';
  9327. for (var i = 0; i < rows; i++) {
  9328. html += '<tr>';
  9329. for (var j = 0; j < cols; j++) {
  9330. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9331. }
  9332. html += '</tr>';
  9333. }
  9334. html += '</table>';
  9335. if (!K.IE) {
  9336. html += '<br />';
  9337. }
  9338. self.insertHtml(html);
  9339. self.select().hideDialog().focus();
  9340. self.addBookmark();
  9341. }
  9342. }
  9343. }),
  9344. div = dialog.div,
  9345. rowsBox = K('[name="rows"]', div).val(3),
  9346. colsBox = K('[name="cols"]', div).val(2),
  9347. widthBox = K('[name="width"]', div).val(100),
  9348. heightBox = K('[name="height"]', div),
  9349. widthTypeBox = K('[name="widthType"]', div),
  9350. heightTypeBox = K('[name="heightType"]', div),
  9351. paddingBox = K('[name="padding"]', div).val(2),
  9352. spacingBox = K('[name="spacing"]', div).val(0),
  9353. alignBox = K('[name="align"]', div),
  9354. borderBox = K('[name="border"]', div).val(1),
  9355. colorBox = K('.ke-input-color', div);
  9356. _initColorPicker(div, colorBox.eq(0));
  9357. _initColorPicker(div, colorBox.eq(1));
  9358. _setColor(colorBox.eq(0), '#000000');
  9359. _setColor(colorBox.eq(1), '');
  9360. rowsBox[0].focus();
  9361. rowsBox[0].select();
  9362. var table;
  9363. if (isInsert) {
  9364. return;
  9365. }
  9366. table = self.plugin.getSelectedTable();
  9367. if (table) {
  9368. rowsBox.val(table[0].rows.length);
  9369. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9370. rowsBox.attr('disabled', true);
  9371. colsBox.attr('disabled', true);
  9372. var match,
  9373. tableWidth = table[0].style.width || table[0].width,
  9374. tableHeight = table[0].style.height || table[0].height;
  9375. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9376. widthBox.val(match[1]);
  9377. widthTypeBox.val(match[2]);
  9378. } else {
  9379. widthBox.val('');
  9380. }
  9381. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9382. heightBox.val(match[1]);
  9383. heightTypeBox.val(match[2]);
  9384. }
  9385. paddingBox.val(table[0].cellPadding || '');
  9386. spacingBox.val(table[0].cellSpacing || '');
  9387. alignBox.val(table[0].align || '');
  9388. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9389. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9390. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9391. widthBox[0].focus();
  9392. widthBox[0].select();
  9393. }
  9394. },
  9395. cellprop : function() {
  9396. var html = [
  9397. '<div style="padding:20px;">',
  9398. '<div class="ke-dialog-row">',
  9399. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9400. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9401. '<select name="widthType">',
  9402. '<option value="%">' + lang.percent + '</option>',
  9403. '<option value="px">' + lang.px + '</option>',
  9404. '</select> &nbsp; ',
  9405. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9406. '<select name="heightType">',
  9407. '<option value="%">' + lang.percent + '</option>',
  9408. '<option value="px">' + lang.px + '</option>',
  9409. '</select>',
  9410. '</div>',
  9411. '<div class="ke-dialog-row">',
  9412. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9413. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9414. '<option value="">' + lang.alignDefault + '</option>',
  9415. '<option value="left">' + lang.alignLeft + '</option>',
  9416. '<option value="center">' + lang.alignCenter + '</option>',
  9417. '<option value="right">' + lang.alignRight + '</option>',
  9418. '</select> ',
  9419. lang.verticalAlign + ' <select name="verticalAlign">',
  9420. '<option value="">' + lang.alignDefault + '</option>',
  9421. '<option value="top">' + lang.alignTop + '</option>',
  9422. '<option value="middle">' + lang.alignMiddle + '</option>',
  9423. '<option value="bottom">' + lang.alignBottom + '</option>',
  9424. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9425. '</select>',
  9426. '</div>',
  9427. '<div class="ke-dialog-row">',
  9428. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9429. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9430. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9431. '</div>',
  9432. '<div class="ke-dialog-row">',
  9433. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9434. '<span class="ke-inline-block ke-input-color"></span>',
  9435. '</div>',
  9436. '</div>'
  9437. ].join('');
  9438. var bookmark = self.cmd.range.createBookmark();
  9439. var dialog = self.createDialog({
  9440. name : name,
  9441. width : 500,
  9442. title : self.lang('tablecell'),
  9443. body : html,
  9444. beforeRemove : function() {
  9445. colorBox.unbind();
  9446. },
  9447. yesBtn : {
  9448. name : self.lang('yes'),
  9449. click : function(e) {
  9450. var width = widthBox.val(),
  9451. height = heightBox.val(),
  9452. widthType = widthTypeBox.val(),
  9453. heightType = heightTypeBox.val(),
  9454. padding = paddingBox.val(),
  9455. spacing = spacingBox.val(),
  9456. textAlign = textAlignBox.val(),
  9457. verticalAlign = verticalAlignBox.val(),
  9458. border = borderBox.val(),
  9459. borderColor = K(colorBox[0]).html() || '',
  9460. bgColor = K(colorBox[1]).html() || '';
  9461. if (!/^\d*$/.test(width)) {
  9462. alert(self.lang('invalidWidth'));
  9463. widthBox[0].focus();
  9464. return;
  9465. }
  9466. if (!/^\d*$/.test(height)) {
  9467. alert(self.lang('invalidHeight'));
  9468. heightBox[0].focus();
  9469. return;
  9470. }
  9471. if (!/^\d*$/.test(border)) {
  9472. alert(self.lang('invalidBorder'));
  9473. borderBox[0].focus();
  9474. return;
  9475. }
  9476. cell.css({
  9477. width : width !== '' ? (width + widthType) : '',
  9478. height : height !== '' ? (height + heightType) : '',
  9479. 'background-color' : bgColor,
  9480. 'text-align' : textAlign,
  9481. 'vertical-align' : verticalAlign,
  9482. 'border-width' : border,
  9483. 'border-style' : border !== '' ? 'solid' : '',
  9484. 'border-color' : borderColor
  9485. });
  9486. self.hideDialog().focus();
  9487. self.cmd.range.moveToBookmark(bookmark);
  9488. self.cmd.select();
  9489. self.addBookmark();
  9490. }
  9491. }
  9492. }),
  9493. div = dialog.div,
  9494. widthBox = K('[name="width"]', div).val(100),
  9495. heightBox = K('[name="height"]', div),
  9496. widthTypeBox = K('[name="widthType"]', div),
  9497. heightTypeBox = K('[name="heightType"]', div),
  9498. paddingBox = K('[name="padding"]', div).val(2),
  9499. spacingBox = K('[name="spacing"]', div).val(0),
  9500. textAlignBox = K('[name="textAlign"]', div),
  9501. verticalAlignBox = K('[name="verticalAlign"]', div),
  9502. borderBox = K('[name="border"]', div).val(1),
  9503. colorBox = K('.ke-input-color', div);
  9504. _initColorPicker(div, colorBox.eq(0));
  9505. _initColorPicker(div, colorBox.eq(1));
  9506. _setColor(colorBox.eq(0), '#000000');
  9507. _setColor(colorBox.eq(1), '');
  9508. widthBox[0].focus();
  9509. widthBox[0].select();
  9510. var cell = self.plugin.getSelectedCell();
  9511. var match,
  9512. cellWidth = cell[0].style.width || cell[0].width || '',
  9513. cellHeight = cell[0].style.height || cell[0].height || '';
  9514. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9515. widthBox.val(match[1]);
  9516. widthTypeBox.val(match[2]);
  9517. } else {
  9518. widthBox.val('');
  9519. }
  9520. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9521. heightBox.val(match[1]);
  9522. heightTypeBox.val(match[2]);
  9523. }
  9524. textAlignBox.val(cell[0].style.textAlign || '');
  9525. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9526. var border = cell[0].style.borderWidth || '';
  9527. if (border) {
  9528. border = parseInt(border);
  9529. }
  9530. borderBox.val(border);
  9531. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9532. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9533. widthBox[0].focus();
  9534. widthBox[0].select();
  9535. },
  9536. insert : function() {
  9537. this.prop(true);
  9538. },
  9539. 'delete' : function() {
  9540. var table = self.plugin.getSelectedTable();
  9541. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9542. self.cmd.select();
  9543. table.remove();
  9544. self.addBookmark();
  9545. },
  9546. colinsert : function(offset) {
  9547. var table = self.plugin.getSelectedTable()[0],
  9548. row = self.plugin.getSelectedRow()[0],
  9549. cell = self.plugin.getSelectedCell()[0],
  9550. index = cell.cellIndex + offset;
  9551. index += table.rows[0].cells.length - row.cells.length;
  9552. for (var i = 0, len = table.rows.length; i < len; i++) {
  9553. var newRow = table.rows[i],
  9554. newCell = newRow.insertCell(index);
  9555. newCell.innerHTML = K.IE ? '' : '<br />';
  9556. index = _getCellIndex(table, newRow, newCell);
  9557. }
  9558. self.cmd.range.selectNodeContents(cell).collapse(true);
  9559. self.cmd.select();
  9560. self.addBookmark();
  9561. },
  9562. colinsertleft : function() {
  9563. this.colinsert(0);
  9564. },
  9565. colinsertright : function() {
  9566. this.colinsert(1);
  9567. },
  9568. rowinsert : function(offset) {
  9569. var table = self.plugin.getSelectedTable()[0],
  9570. row = self.plugin.getSelectedRow()[0],
  9571. cell = self.plugin.getSelectedCell()[0];
  9572. var rowIndex = row.rowIndex;
  9573. if (offset === 1) {
  9574. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9575. }
  9576. var newRow = table.insertRow(rowIndex);
  9577. for (var i = 0, len = row.cells.length; i < len; i++) {
  9578. if (row.cells[i].rowSpan > 1) {
  9579. len -= row.cells[i].rowSpan - 1;
  9580. }
  9581. var newCell = newRow.insertCell(i);
  9582. if (offset === 1 && row.cells[i].colSpan > 1) {
  9583. newCell.colSpan = row.cells[i].colSpan;
  9584. }
  9585. newCell.innerHTML = K.IE ? '' : '<br />';
  9586. }
  9587. for (var j = rowIndex; j >= 0; j--) {
  9588. var cells = table.rows[j].cells;
  9589. if (cells.length > i) {
  9590. for (var k = cell.cellIndex; k >= 0; k--) {
  9591. if (cells[k].rowSpan > 1) {
  9592. cells[k].rowSpan += 1;
  9593. }
  9594. }
  9595. break;
  9596. }
  9597. }
  9598. self.cmd.range.selectNodeContents(cell).collapse(true);
  9599. self.cmd.select();
  9600. self.addBookmark();
  9601. },
  9602. rowinsertabove : function() {
  9603. this.rowinsert(0);
  9604. },
  9605. rowinsertbelow : function() {
  9606. this.rowinsert(1);
  9607. },
  9608. rowmerge : function() {
  9609. var table = self.plugin.getSelectedTable()[0],
  9610. row = self.plugin.getSelectedRow()[0],
  9611. cell = self.plugin.getSelectedCell()[0],
  9612. rowIndex = row.rowIndex,
  9613. nextRowIndex = rowIndex + cell.rowSpan,
  9614. nextRow = table.rows[nextRowIndex];
  9615. if (table.rows.length <= nextRowIndex) {
  9616. return;
  9617. }
  9618. var cellIndex = cell.cellIndex;
  9619. if (nextRow.cells.length <= cellIndex) {
  9620. return;
  9621. }
  9622. var nextCell = nextRow.cells[cellIndex];
  9623. if (cell.colSpan !== nextCell.colSpan) {
  9624. return;
  9625. }
  9626. cell.rowSpan += nextCell.rowSpan;
  9627. nextRow.deleteCell(cellIndex);
  9628. self.cmd.range.selectNodeContents(cell).collapse(true);
  9629. self.cmd.select();
  9630. self.addBookmark();
  9631. },
  9632. colmerge : function() {
  9633. var table = self.plugin.getSelectedTable()[0],
  9634. row = self.plugin.getSelectedRow()[0],
  9635. cell = self.plugin.getSelectedCell()[0],
  9636. rowIndex = row.rowIndex,
  9637. cellIndex = cell.cellIndex,
  9638. nextCellIndex = cellIndex + 1;
  9639. if (row.cells.length <= nextCellIndex) {
  9640. return;
  9641. }
  9642. var nextCell = row.cells[nextCellIndex];
  9643. if (cell.rowSpan !== nextCell.rowSpan) {
  9644. return;
  9645. }
  9646. cell.colSpan += nextCell.colSpan;
  9647. row.deleteCell(nextCellIndex);
  9648. self.cmd.range.selectNodeContents(cell).collapse(true);
  9649. self.cmd.select();
  9650. self.addBookmark();
  9651. },
  9652. rowsplit : function() {
  9653. var table = self.plugin.getSelectedTable()[0],
  9654. row = self.plugin.getSelectedRow()[0],
  9655. cell = self.plugin.getSelectedCell()[0],
  9656. rowIndex = row.rowIndex;
  9657. if (cell.rowSpan === 1) {
  9658. return;
  9659. }
  9660. var cellIndex = _getCellIndex(table, row, cell);
  9661. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9662. var newRow = table.rows[rowIndex + i],
  9663. newCell = newRow.insertCell(cellIndex);
  9664. if (cell.colSpan > 1) {
  9665. newCell.colSpan = cell.colSpan;
  9666. }
  9667. newCell.innerHTML = K.IE ? '' : '<br />';
  9668. cellIndex = _getCellIndex(table, newRow, newCell);
  9669. }
  9670. K(cell).removeAttr('rowSpan');
  9671. self.cmd.range.selectNodeContents(cell).collapse(true);
  9672. self.cmd.select();
  9673. self.addBookmark();
  9674. },
  9675. colsplit : function() {
  9676. var table = self.plugin.getSelectedTable()[0],
  9677. row = self.plugin.getSelectedRow()[0],
  9678. cell = self.plugin.getSelectedCell()[0],
  9679. cellIndex = cell.cellIndex;
  9680. if (cell.colSpan === 1) {
  9681. return;
  9682. }
  9683. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9684. var newCell = row.insertCell(cellIndex + i);
  9685. if (cell.rowSpan > 1) {
  9686. newCell.rowSpan = cell.rowSpan;
  9687. }
  9688. newCell.innerHTML = K.IE ? '' : '<br />';
  9689. }
  9690. K(cell).removeAttr('colSpan');
  9691. self.cmd.range.selectNodeContents(cell).collapse(true);
  9692. self.cmd.select();
  9693. self.addBookmark();
  9694. },
  9695. coldelete : function() {
  9696. var table = self.plugin.getSelectedTable()[0],
  9697. row = self.plugin.getSelectedRow()[0],
  9698. cell = self.plugin.getSelectedCell()[0],
  9699. index = cell.cellIndex;
  9700. for (var i = 0, len = table.rows.length; i < len; i++) {
  9701. var newRow = table.rows[i],
  9702. newCell = newRow.cells[index];
  9703. if (newCell.colSpan > 1) {
  9704. newCell.colSpan -= 1;
  9705. if (newCell.colSpan === 1) {
  9706. K(newCell).removeAttr('colSpan');
  9707. }
  9708. } else {
  9709. newRow.deleteCell(index);
  9710. }
  9711. if (newCell.rowSpan > 1) {
  9712. i += newCell.rowSpan - 1;
  9713. }
  9714. }
  9715. if (row.cells.length === 0) {
  9716. self.cmd.range.setStartBefore(table).collapse(true);
  9717. self.cmd.select();
  9718. K(table).remove();
  9719. } else {
  9720. self.cmd.selection(true);
  9721. }
  9722. self.addBookmark();
  9723. },
  9724. rowdelete : function() {
  9725. var table = self.plugin.getSelectedTable()[0],
  9726. row = self.plugin.getSelectedRow()[0],
  9727. cell = self.plugin.getSelectedCell()[0],
  9728. rowIndex = row.rowIndex;
  9729. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9730. table.deleteRow(rowIndex + i);
  9731. }
  9732. if (table.rows.length === 0) {
  9733. self.cmd.range.setStartBefore(table).collapse(true);
  9734. self.cmd.select();
  9735. K(table).remove();
  9736. } else {
  9737. self.cmd.selection(true);
  9738. }
  9739. self.addBookmark();
  9740. }
  9741. };
  9742. self.clickToolbar(name, self.plugin.table.prop);
  9743. });
  9744. /*******************************************************************************
  9745. * KindEditor - WYSIWYG HTML Editor for Internet
  9746. * Copyright (C) 2006-2011 kindsoft.net
  9747. *
  9748. * @author Roddy <luolonghao@gmail.com>
  9749. * @site http://www.kindsoft.net/
  9750. * @licence http://www.kindsoft.net/license.php
  9751. *******************************************************************************/
  9752. KindEditor.plugin('template', function(K) {
  9753. var self = this, name = 'template', lang = self.lang(name + '.'),
  9754. htmlPath = self.pluginsPath + name + '/html/';
  9755. function getFilePath(fileName) {
  9756. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9757. }
  9758. self.clickToolbar(name, function() {
  9759. var lang = self.lang(name + '.'),
  9760. arr = ['<div style="padding:10px 20px;">',
  9761. '<div class="ke-header">',
  9762. '<div class="ke-left">',
  9763. lang. selectTemplate + ' <select>'];
  9764. K.each(lang.fileList, function(key, val) {
  9765. arr.push('<option value="' + key + '">' + val + '</option>');
  9766. });
  9767. html = [arr.join(''),
  9768. '</select></div>',
  9769. '<div class="ke-right">',
  9770. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9771. '</div>',
  9772. '<div class="ke-clearfix"></div>',
  9773. '</div>',
  9774. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9775. '</div>'].join('');
  9776. var dialog = self.createDialog({
  9777. name : name,
  9778. width : 500,
  9779. title : self.lang(name),
  9780. body : html,
  9781. yesBtn : {
  9782. name : self.lang('yes'),
  9783. click : function(e) {
  9784. var doc = K.iframeDoc(iframe);
  9785. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9786. }
  9787. }
  9788. });
  9789. var selectBox = K('select', dialog.div),
  9790. checkbox = K('[name="replaceFlag"]', dialog.div),
  9791. iframe = K('iframe', dialog.div);
  9792. checkbox[0].checked = true;
  9793. iframe.attr('src', getFilePath(selectBox.val()));
  9794. selectBox.change(function() {
  9795. iframe.attr('src', getFilePath(this.value));
  9796. });
  9797. });
  9798. });
  9799. /*******************************************************************************
  9800. * KindEditor - WYSIWYG HTML Editor for Internet
  9801. * Copyright (C) 2006-2011 kindsoft.net
  9802. *
  9803. * @author Roddy <luolonghao@gmail.com>
  9804. * @site http://www.kindsoft.net/
  9805. * @licence http://www.kindsoft.net/license.php
  9806. *******************************************************************************/
  9807. KindEditor.plugin('wordpaste', function(K) {
  9808. var self = this, name = 'wordpaste';
  9809. self.clickToolbar(name, function() {
  9810. var lang = self.lang(name + '.'),
  9811. html = '<div style="padding:10px 20px;">' +
  9812. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9813. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  9814. '</div>',
  9815. dialog = self.createDialog({
  9816. name : name,
  9817. width : 450,
  9818. title : self.lang(name),
  9819. body : html,
  9820. yesBtn : {
  9821. name : self.lang('yes'),
  9822. click : function(e) {
  9823. var str = doc.body.innerHTML;
  9824. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  9825. self.insertHtml(str).hideDialog().focus();
  9826. }
  9827. }
  9828. }),
  9829. div = dialog.div,
  9830. iframe = K('iframe', div),
  9831. doc = K.iframeDoc(iframe);
  9832. if (!K.IE) {
  9833. doc.designMode = 'on';
  9834. }
  9835. doc.open();
  9836. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  9837. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  9838. if (!K.IE) {
  9839. doc.write('<br />');
  9840. }
  9841. doc.write('</body></html>');
  9842. doc.close();
  9843. if (K.IE) {
  9844. doc.body.contentEditable = 'true';
  9845. }
  9846. iframe[0].contentWindow.focus();
  9847. });
  9848. });
  9849. KindEditor.plugin('fixtoolbar', function (K) {
  9850. var self = this;
  9851. if (!self.fixToolBar) {
  9852. return;
  9853. }
  9854. function init() {
  9855. var toolbar = K('.ke-toolbar');
  9856. var originY = toolbar.pos().y;
  9857. K(window).bind('scroll', function () {
  9858. if (toolbar.css('position') == 'fixed') {
  9859. if(document.body.scrollTop - originY < 0){
  9860. toolbar.css('position', 'static');
  9861. toolbar.css('top', 'auto');
  9862. }
  9863. } else {
  9864. if (toolbar.pos().y - document.body.scrollTop < 0) {
  9865. toolbar.css('position', 'fixed');
  9866. toolbar.css('top', 0);
  9867. }
  9868. }
  9869. });
  9870. }
  9871. if (self.isCreated) {
  9872. init();
  9873. } else {
  9874. self.afterCreate(init);
  9875. }
  9876. });
  9877. function autoImg(self) {
  9878. var index = self.index;
  9879. var haspicContainer = document.getElementById("has_pic_" + index);
  9880. if (haspicContainer == null) {
  9881. haspicContainer = document.createElement("div");
  9882. haspicContainer.id = "has_pic_" + index;
  9883. haspicContainer.innerHTML = "<input type='text' id='piclist_"+index+"' value='' style='display:none;'/><div id='upload_"+index+"'><b>您有图片需要上传到服务器</b>&nbsp;&nbsp;<a href='javascript:uploadpic(\""+self.uploadJson+"\", \""+self.filePostName+"\", \""+index+"\");' >上传</a></div><div id='confirm_"+index+"'></div>";
  9884. $(".ke-toolbar").eq(index).after(haspicContainer);
  9885. }
  9886. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  9887. var piccount = 0;
  9888. var sstr = '';
  9889. $(img).each(function (i) {
  9890. var that = $(this);
  9891. var host = gethost(self.uploadJson);
  9892. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  9893. var n = gethost(that.attr("src"));
  9894. if (host != n) {
  9895. piccount++;
  9896. if (i == $(img).length - 1)
  9897. sstr += that.attr("src");
  9898. else
  9899. sstr += that.attr("src") + ",";
  9900. }
  9901. }
  9902. });
  9903. $("#piclist_" + index).val(encodeURIComponent(sstr));
  9904. document.getElementById("has_pic_" + index).style.display = (piccount > 0) ? "block" : "none";
  9905. }
  9906. function closeupload(index) {
  9907. $("#has_pic_" + index).hide();
  9908. $("#upload_" + index).show();
  9909. }
  9910. function uploadpic(url, name, index) {
  9911. var piclist = encodeURI($("#piclist_" + index).val());
  9912. if (piclist.length == 0) return false;
  9913. $.ajax({
  9914. url: url.replace('kindeditor', 'copys') + '&json=1',
  9915. data: name + "=" + piclist,
  9916. type: "POST",
  9917. dataType: "json",
  9918. beforeSend: function () {
  9919. $("#upload_" + index).hide();
  9920. $("#confirm_" + index).text("正在上传中...");
  9921. },
  9922. success: function (msg) {
  9923. var url = msg.data;
  9924. if (url !== "") {
  9925. var str = new Array();
  9926. str = url.split(',');
  9927. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  9928. $(img).each(function (i) {
  9929. var that = $(this);
  9930. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  9931. that.attr("src", str[i]);
  9932. that.attr("data-ke-src", str[i]);
  9933. }
  9934. });
  9935. $("#confirm_" + index).html(img.length + "张图片已经上传成功!&nbsp;&nbsp;<a href='javascript:closeupload("+index+");'>关闭</a>");
  9936. }
  9937. else $("#confirm_" + index).text("上传失败!");
  9938. }
  9939. });
  9940. }
  9941. function gethost(url){
  9942. var reg = /^http(s)?:\/\/(.*?)\//;
  9943. return reg.exec(url)[2];
  9944. }