kindeditor-all.js 298 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852
  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2016 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.11 (2016-03-31)
  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.11 (2016-03-31)',
  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. designMode : true,
  230. fullscreenMode : false,
  231. filterMode : true,
  232. wellFormatMode : true,
  233. shadowMode : true,
  234. loadStyleMode : true,
  235. basePath : K.basePath,
  236. themesPath : K.basePath + 'themes/',
  237. langPath : K.basePath + 'lang/',
  238. pluginsPath : K.basePath + 'plugins/',
  239. themeType : 'default',
  240. langType : 'zh-CN',
  241. urlType : '',
  242. newlineTag : 'p',
  243. resizeType : 2,
  244. syncType : 'form',
  245. pasteType : 2,
  246. dialogAlignType : 'page',
  247. useContextmenu : true,
  248. fullscreenShortcut : false,
  249. bodyClass : 'ke-content',
  250. indentChar : '\t',
  251. cssPath : '',
  252. cssData : '',
  253. minWidth : 650,
  254. minHeight : 100,
  255. minChangeSize : 50,
  256. zIndex : 811213,
  257. items : [
  258. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  259. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  260. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  261. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  262. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  263. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  264. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  265. 'anchor', 'link', 'unlink', '|', 'about'
  266. ],
  267. noDisableItems : ['source', 'fullscreen'],
  268. colorTable : [
  269. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  270. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  271. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  272. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  273. ],
  274. fontSizeTable : ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
  275. htmlTags : {
  276. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  277. span : [
  278. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  279. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  280. ],
  281. div : [
  282. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  283. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  284. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  285. ],
  286. table: [
  287. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  288. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  289. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  290. '.width', '.height', '.border-collapse'
  291. ],
  292. 'td,th': [
  293. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  294. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  295. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  296. ],
  297. a : ['id', 'class', 'href', 'target', 'name'],
  298. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', 'wmode'],
  299. img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  300. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  301. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  302. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  303. ],
  304. pre : ['id', 'class'],
  305. hr : ['id', 'class', '.page-break-after'],
  306. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  307. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  308. },
  309. layout : '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  310. };
  311. var _useCapture = false;
  312. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  313. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  314. var _CHANGE_KEY_MAP = {};
  315. _each(_INPUT_KEY_MAP, function(key, val) {
  316. _CHANGE_KEY_MAP[key] = val;
  317. });
  318. _each(_CURSORMOVE_KEY_MAP, function(key, val) {
  319. _CHANGE_KEY_MAP[key] = val;
  320. });
  321. function _bindEvent(el, type, fn) {
  322. if (el.addEventListener){
  323. el.addEventListener(type, fn, _useCapture);
  324. } else if (el.attachEvent){
  325. el.attachEvent('on' + type, fn);
  326. }
  327. }
  328. function _unbindEvent(el, type, fn) {
  329. if (el.removeEventListener){
  330. el.removeEventListener(type, fn, _useCapture);
  331. } else if (el.detachEvent){
  332. el.detachEvent('on' + type, fn);
  333. }
  334. }
  335. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  336. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  337. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  338. function KEvent(el, event) {
  339. this.init(el, event);
  340. }
  341. _extend(KEvent, {
  342. init : function(el, event) {
  343. var self = this, doc = el.ownerDocument || el.document || el;
  344. self.event = event;
  345. _each(_EVENT_PROPS, function(key, val) {
  346. self[val] = event[val];
  347. });
  348. if (!self.target) {
  349. self.target = self.srcElement || doc;
  350. }
  351. if (self.target.nodeType === 3) {
  352. self.target = self.target.parentNode;
  353. }
  354. if (!self.relatedTarget && self.fromElement) {
  355. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  356. }
  357. if (self.pageX == null && self.clientX != null) {
  358. var d = doc.documentElement, body = doc.body;
  359. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  360. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  361. }
  362. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  363. self.which = self.charCode || self.keyCode;
  364. }
  365. if (!self.metaKey && self.ctrlKey) {
  366. self.metaKey = self.ctrlKey;
  367. }
  368. if (!self.which && self.button !== undefined) {
  369. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  370. }
  371. switch (self.which) {
  372. case 186 :
  373. self.which = 59;
  374. break;
  375. case 187 :
  376. case 107 :
  377. case 43 :
  378. self.which = 61;
  379. break;
  380. case 189 :
  381. case 45 :
  382. self.which = 109;
  383. break;
  384. case 42 :
  385. self.which = 106;
  386. break;
  387. case 47 :
  388. self.which = 111;
  389. break;
  390. case 78 :
  391. self.which = 110;
  392. break;
  393. }
  394. if (self.which >= 96 && self.which <= 105) {
  395. self.which -= 48;
  396. }
  397. },
  398. preventDefault : function() {
  399. var ev = this.event;
  400. if (ev.preventDefault) {
  401. ev.preventDefault();
  402. } else {
  403. ev.returnValue = false;
  404. }
  405. },
  406. stopPropagation : function() {
  407. var ev = this.event;
  408. if (ev.stopPropagation) {
  409. ev.stopPropagation();
  410. } else {
  411. ev.cancelBubble = true;
  412. }
  413. },
  414. stop : function() {
  415. this.preventDefault();
  416. this.stopPropagation();
  417. }
  418. });
  419. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  420. function _getId(el) {
  421. return el[_eventExpendo] || null;
  422. }
  423. function _setId(el) {
  424. el[_eventExpendo] = ++_eventId;
  425. return _eventId;
  426. }
  427. function _removeId(el) {
  428. try {
  429. delete el[_eventExpendo];
  430. } catch(e) {
  431. if (el.removeAttribute) {
  432. el.removeAttribute(_eventExpendo);
  433. }
  434. }
  435. }
  436. function _bind(el, type, fn) {
  437. if (type.indexOf(',') >= 0) {
  438. _each(type.split(','), function() {
  439. _bind(el, this, fn);
  440. });
  441. return;
  442. }
  443. var id = _getId(el);
  444. if (!id) {
  445. id = _setId(el);
  446. }
  447. if (_eventData[id] === undefined) {
  448. _eventData[id] = {};
  449. }
  450. var events = _eventData[id][type];
  451. if (events && events.length > 0) {
  452. _unbindEvent(el, type, events[0]);
  453. } else {
  454. _eventData[id][type] = [];
  455. _eventData[id].el = el;
  456. }
  457. events = _eventData[id][type];
  458. if (events.length === 0) {
  459. events[0] = function(e) {
  460. var kevent = e ? new KEvent(el, e) : undefined;
  461. _each(events, function(i, event) {
  462. if (i > 0 && event) {
  463. event.call(el, kevent);
  464. }
  465. });
  466. };
  467. }
  468. if (_inArray(fn, events) < 0) {
  469. events.push(fn);
  470. }
  471. _bindEvent(el, type, events[0]);
  472. }
  473. function _unbind(el, type, fn) {
  474. if (type && type.indexOf(',') >= 0) {
  475. _each(type.split(','), function() {
  476. _unbind(el, this, fn);
  477. });
  478. return;
  479. }
  480. var id = _getId(el);
  481. if (!id) {
  482. return;
  483. }
  484. if (type === undefined) {
  485. if (id in _eventData) {
  486. _each(_eventData[id], function(key, events) {
  487. if (key != 'el' && events.length > 0) {
  488. _unbindEvent(el, key, events[0]);
  489. }
  490. });
  491. delete _eventData[id];
  492. _removeId(el);
  493. }
  494. return;
  495. }
  496. if (!_eventData[id]) {
  497. return;
  498. }
  499. var events = _eventData[id][type];
  500. if (events && events.length > 0) {
  501. if (fn === undefined) {
  502. _unbindEvent(el, type, events[0]);
  503. delete _eventData[id][type];
  504. } else {
  505. _each(events, function(i, event) {
  506. if (i > 0 && event === fn) {
  507. events.splice(i, 1);
  508. }
  509. });
  510. if (events.length == 1) {
  511. _unbindEvent(el, type, events[0]);
  512. delete _eventData[id][type];
  513. }
  514. }
  515. var count = 0;
  516. _each(_eventData[id], function() {
  517. count++;
  518. });
  519. if (count < 2) {
  520. delete _eventData[id];
  521. _removeId(el);
  522. }
  523. }
  524. }
  525. function _fire(el, type) {
  526. if (type.indexOf(',') >= 0) {
  527. _each(type.split(','), function() {
  528. _fire(el, this);
  529. });
  530. return;
  531. }
  532. var id = _getId(el);
  533. if (!id) {
  534. return;
  535. }
  536. var events = _eventData[id][type];
  537. if (_eventData[id] && events && events.length > 0) {
  538. events[0]();
  539. }
  540. }
  541. function _ctrl(el, key, fn) {
  542. var self = this;
  543. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  544. _bind(el, 'keydown', function(e) {
  545. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  546. fn.call(el);
  547. e.stop();
  548. }
  549. });
  550. }
  551. var _readyFinished = false;
  552. function _ready(fn) {
  553. if (_readyFinished) {
  554. fn(KindEditor);
  555. return;
  556. }
  557. var loaded = false;
  558. function readyFunc() {
  559. if (!loaded) {
  560. loaded = true;
  561. fn(KindEditor);
  562. _readyFinished = true;
  563. }
  564. }
  565. function ieReadyFunc() {
  566. if (!loaded) {
  567. try {
  568. document.documentElement.doScroll('left');
  569. } catch(e) {
  570. setTimeout(ieReadyFunc, 100);
  571. return;
  572. }
  573. readyFunc();
  574. }
  575. }
  576. function ieReadyStateFunc() {
  577. if (document.readyState === 'complete') {
  578. readyFunc();
  579. }
  580. }
  581. if (document.addEventListener) {
  582. _bind(document, 'DOMContentLoaded', readyFunc);
  583. } else if (document.attachEvent) {
  584. _bind(document, 'readystatechange', ieReadyStateFunc);
  585. var toplevel = false;
  586. try {
  587. toplevel = window.frameElement == null;
  588. } catch(e) {}
  589. if (document.documentElement.doScroll && toplevel) {
  590. ieReadyFunc();
  591. }
  592. }
  593. _bind(window, 'load', readyFunc);
  594. }
  595. if (window.attachEvent) {
  596. window.attachEvent('onunload', function() {
  597. _each(_eventData, function(key, events) {
  598. if (events.el) {
  599. _unbind(events.el);
  600. }
  601. });
  602. });
  603. }
  604. K.ctrl = _ctrl;
  605. K.ready = _ready;
  606. function _getCssList(css) {
  607. var list = {},
  608. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  609. match;
  610. while ((match = reg.exec(css))) {
  611. var key = _trim(match[1].toLowerCase()),
  612. val = _trim(_toHex(match[2]));
  613. list[key] = val;
  614. }
  615. return list;
  616. }
  617. function _getAttrList(tag) {
  618. var list = {},
  619. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  620. match;
  621. while ((match = reg.exec(tag))) {
  622. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  623. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  624. list[key] = val;
  625. }
  626. return list;
  627. }
  628. function _addClassToTag(tag, className) {
  629. if (/\s+class\s*=/.test(tag)) {
  630. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  631. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  632. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  633. } else {
  634. return $0;
  635. }
  636. });
  637. } else {
  638. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  639. }
  640. return tag;
  641. }
  642. function _formatCss(css) {
  643. var str = '';
  644. _each(_getCssList(css), function(key, val) {
  645. str += key + ':' + val + ';';
  646. });
  647. return str;
  648. }
  649. function _formatUrl(url, mode, host, pathname) {
  650. mode = _undef(mode, '').toLowerCase();
  651. if (url.substr(0, 5) != 'data:') {
  652. url = url.replace(/([^:])\/\//g, '$1/');
  653. }
  654. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  655. return url;
  656. }
  657. host = host || location.protocol + '//' + location.host;
  658. if (pathname === undefined) {
  659. var m = location.pathname.match(/^(\/.*)\//);
  660. pathname = m ? m[1] : '';
  661. }
  662. var match;
  663. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  664. if (match[1] !== host) {
  665. return url;
  666. }
  667. } else if (/^\w+:/.test(url)) {
  668. return url;
  669. }
  670. function getRealPath(path) {
  671. var parts = path.split('/'), paths = [];
  672. for (var i = 0, len = parts.length; i < len; i++) {
  673. var part = parts[i];
  674. if (part == '..') {
  675. if (paths.length > 0) {
  676. paths.pop();
  677. }
  678. } else if (part !== '' && part != '.') {
  679. paths.push(part);
  680. }
  681. }
  682. return '/' + paths.join('/');
  683. }
  684. if (/^\//.test(url)) {
  685. url = host + getRealPath(url.substr(1));
  686. } else if (!/^\w+:\/\//.test(url)) {
  687. url = host + getRealPath(pathname + '/' + url);
  688. }
  689. function getRelativePath(path, depth) {
  690. if (url.substr(0, path.length) === path) {
  691. var arr = [];
  692. for (var i = 0; i < depth; i++) {
  693. arr.push('..');
  694. }
  695. var prefix = '.';
  696. if (arr.length > 0) {
  697. prefix += '/' + arr.join('/');
  698. }
  699. if (pathname == '/') {
  700. prefix += '/';
  701. }
  702. return prefix + url.substr(path.length);
  703. } else {
  704. if ((match = /^(.*)\//.exec(path))) {
  705. return getRelativePath(match[1], ++depth);
  706. }
  707. }
  708. }
  709. if (mode === 'relative') {
  710. url = getRelativePath(host + pathname, 0).substr(2);
  711. } else if (mode === 'absolute') {
  712. if (url.substr(0, host.length) === host) {
  713. url = url.substr(host.length);
  714. }
  715. }
  716. return url;
  717. }
  718. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  719. if (html == null) {
  720. html = '';
  721. }
  722. urlType = urlType || '';
  723. wellFormatted = _undef(wellFormatted, false);
  724. indentChar = _undef(indentChar, '\t');
  725. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  726. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  727. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  728. });
  729. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  730. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  731. html = html.replace(/\u200B/g, '');
  732. html = html.replace(/\u00A9/g, '&copy;');
  733. html = html.replace(/\u00AE/g, '&reg;');
  734. html = html.replace(/\u2003/g, '&emsp;');
  735. html = html.replace(/\u3000/g, '&emsp;');
  736. html = html.replace(/<[^>]+/g, function($0) {
  737. return $0.replace(/\s+/g, ' ');
  738. });
  739. var htmlTagMap = {};
  740. if (htmlTags) {
  741. _each(htmlTags, function(key, val) {
  742. var arr = key.split(',');
  743. for (var i = 0, len = arr.length; i < len; i++) {
  744. htmlTagMap[arr[i]] = _toMap(val);
  745. }
  746. });
  747. if (!htmlTagMap.script) {
  748. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  749. }
  750. if (!htmlTagMap.style) {
  751. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  752. }
  753. }
  754. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  755. var tagStack = [];
  756. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  757. var full = $0,
  758. startNewline = $1 || '',
  759. startSlash = $2 || '',
  760. tagName = $3.toLowerCase(),
  761. attr = $4 || '',
  762. endSlash = $5 ? ' ' + $5 : '',
  763. endNewline = $6 || '';
  764. if (htmlTags && !htmlTagMap[tagName]) {
  765. return '';
  766. }
  767. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  768. endSlash = ' /';
  769. }
  770. if (_INLINE_TAG_MAP[tagName]) {
  771. if (startNewline) {
  772. startNewline = ' ';
  773. }
  774. if (endNewline) {
  775. endNewline = ' ';
  776. }
  777. }
  778. if (_PRE_TAG_MAP[tagName]) {
  779. if (startSlash) {
  780. endNewline = '\n';
  781. } else {
  782. startNewline = '\n';
  783. }
  784. }
  785. if (wellFormatted && tagName == 'br') {
  786. endNewline = '\n';
  787. }
  788. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  789. if (wellFormatted) {
  790. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  791. tagStack.pop();
  792. } else {
  793. tagStack.push(tagName);
  794. }
  795. startNewline = '\n';
  796. endNewline = '\n';
  797. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  798. startNewline += indentChar;
  799. if (!startSlash) {
  800. endNewline += indentChar;
  801. }
  802. }
  803. if (endSlash) {
  804. tagStack.pop();
  805. } else if (!startSlash) {
  806. endNewline += indentChar;
  807. }
  808. } else {
  809. startNewline = endNewline = '';
  810. }
  811. }
  812. if (attr !== '') {
  813. var attrMap = _getAttrList(full);
  814. if (tagName === 'font') {
  815. var fontStyleMap = {}, fontStyle = '';
  816. _each(attrMap, function(key, val) {
  817. if (key === 'color') {
  818. fontStyleMap.color = val;
  819. delete attrMap[key];
  820. }
  821. if (key === 'size') {
  822. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  823. delete attrMap[key];
  824. }
  825. if (key === 'face') {
  826. fontStyleMap['font-family'] = val;
  827. delete attrMap[key];
  828. }
  829. if (key === 'style') {
  830. fontStyle = val;
  831. }
  832. });
  833. if (fontStyle && !/;$/.test(fontStyle)) {
  834. fontStyle += ';';
  835. }
  836. _each(fontStyleMap, function(key, val) {
  837. if (val === '') {
  838. return;
  839. }
  840. if (/\s/.test(val)) {
  841. val = "'" + val + "'";
  842. }
  843. fontStyle += key + ':' + val + ';';
  844. });
  845. attrMap.style = fontStyle;
  846. }
  847. _each(attrMap, function(key, val) {
  848. if (_FILL_ATTR_MAP[key]) {
  849. attrMap[key] = key;
  850. }
  851. if (_inArray(key, ['src', 'href']) >= 0) {
  852. attrMap[key] = _formatUrl(val, urlType);
  853. }
  854. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  855. tagName === 'body' && key === 'contenteditable' ||
  856. /^kindeditor_\d+$/.test(key)) {
  857. delete attrMap[key];
  858. }
  859. if (key === 'style' && val !== '') {
  860. var styleMap = _getCssList(val);
  861. _each(styleMap, function(k, v) {
  862. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  863. delete styleMap[k];
  864. }
  865. });
  866. var style = '';
  867. _each(styleMap, function(k, v) {
  868. style += k + ':' + v + ';';
  869. });
  870. attrMap.style = style;
  871. }
  872. });
  873. attr = '';
  874. _each(attrMap, function(key, val) {
  875. if (key === 'style' && val === '') {
  876. return;
  877. }
  878. val = val.replace(/"/g, '&quot;');
  879. attr += ' ' + key + '="' + val + '"';
  880. });
  881. }
  882. if (tagName === 'font') {
  883. tagName = 'span';
  884. }
  885. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  886. });
  887. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  888. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  889. });
  890. html = html.replace(/\n\s*\n/g, '\n');
  891. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  892. return _trim(html);
  893. }
  894. function _clearMsWord(html, htmlTags) {
  895. html = html.replace(/<meta[\s\S]*?>/ig, '')
  896. .replace(/<![\s\S]*?>/ig, '')
  897. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  898. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  899. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  900. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  901. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  902. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  903. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  904. });
  905. return _formatHtml(html, htmlTags);
  906. }
  907. function _mediaType(src) {
  908. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  909. return 'audio/x-pn-realaudio-plugin';
  910. }
  911. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  912. return 'application/x-shockwave-flash';
  913. }
  914. return 'video/x-ms-asf-plugin';
  915. }
  916. function _mediaClass(type) {
  917. if (/realaudio/i.test(type)) {
  918. return 'ke-rm';
  919. }
  920. if (/flash/i.test(type)) {
  921. return 'ke-flash';
  922. }
  923. return 'ke-media';
  924. }
  925. function _mediaAttrs(srcTag) {
  926. return _getAttrList(unescape(srcTag));
  927. }
  928. function _mediaEmbed(attrs) {
  929. var html = '<embed ';
  930. _each(attrs, function(key, val) {
  931. html += key + '="' + val + '" ';
  932. });
  933. html += '/>';
  934. return html;
  935. }
  936. function _mediaImg(blankPath, attrs) {
  937. var width = attrs.width,
  938. height = attrs.height,
  939. type = attrs.type || _mediaType(attrs.src),
  940. srcTag = _mediaEmbed(attrs),
  941. style = '';
  942. if (/\D/.test(width)) {
  943. style += 'width:' + width + ';';
  944. } else if (width > 0) {
  945. style += 'width:' + width + 'px;';
  946. }
  947. if (/\D/.test(height)) {
  948. style += 'height:' + height + ';';
  949. } else if (height > 0) {
  950. style += 'height:' + height + 'px;';
  951. }
  952. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  953. if (style !== '') {
  954. html += 'style="' + style + '" ';
  955. }
  956. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  957. return html;
  958. }
  959. function _tmpl(str, data) {
  960. var fn = new Function("obj",
  961. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  962. "with(obj){p.push('" +
  963. str.replace(/[\r\t\n]/g, " ")
  964. .split("<%").join("\t")
  965. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  966. .replace(/\t=(.*?)%>/g, "',$1,'")
  967. .split("\t").join("');")
  968. .split("%>").join("p.push('")
  969. .split("\r").join("\\'") + "');}return p.join('');");
  970. return data ? fn(data) : fn;
  971. }
  972. K.formatUrl = _formatUrl;
  973. K.formatHtml = _formatHtml;
  974. K.getCssList = _getCssList;
  975. K.getAttrList = _getAttrList;
  976. K.mediaType = _mediaType;
  977. K.mediaAttrs = _mediaAttrs;
  978. K.mediaEmbed = _mediaEmbed;
  979. K.mediaImg = _mediaImg;
  980. K.clearMsWord = _clearMsWord;
  981. K.tmpl = _tmpl;
  982. function _contains(nodeA, nodeB) {
  983. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  984. return true;
  985. }
  986. while ((nodeB = nodeB.parentNode)) {
  987. if (nodeB == nodeA) {
  988. return true;
  989. }
  990. }
  991. return false;
  992. }
  993. var _getSetAttrDiv = document.createElement('div');
  994. _getSetAttrDiv.setAttribute('className', 't');
  995. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  996. function _getAttr(el, key) {
  997. key = key.toLowerCase();
  998. var val = null;
  999. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  1000. var div = el.ownerDocument.createElement('div');
  1001. div.appendChild(el.cloneNode(false));
  1002. var list = _getAttrList(_unescape(div.innerHTML));
  1003. if (key in list) {
  1004. val = list[key];
  1005. }
  1006. } else {
  1007. try {
  1008. val = el.getAttribute(key, 2);
  1009. } catch(e) {
  1010. val = el.getAttribute(key, 1);
  1011. }
  1012. }
  1013. if (key === 'style' && val !== null) {
  1014. val = _formatCss(val);
  1015. }
  1016. return val;
  1017. }
  1018. function _queryAll(expr, root) {
  1019. var exprList = expr.split(',');
  1020. if (exprList.length > 1) {
  1021. var mergedResults = [];
  1022. _each(exprList, function() {
  1023. _each(_queryAll(this, root), function() {
  1024. if (_inArray(this, mergedResults) < 0) {
  1025. mergedResults.push(this);
  1026. }
  1027. });
  1028. });
  1029. return mergedResults;
  1030. }
  1031. root = root || document;
  1032. function escape(str) {
  1033. if (typeof str != 'string') {
  1034. return str;
  1035. }
  1036. return str.replace(/([^\w\-])/g, '\\$1');
  1037. }
  1038. function stripslashes(str) {
  1039. return str.replace(/\\/g, '');
  1040. }
  1041. function cmpTag(tagA, tagB) {
  1042. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1043. }
  1044. function byId(id, tag, root) {
  1045. var arr = [],
  1046. doc = root.ownerDocument || root,
  1047. el = doc.getElementById(stripslashes(id));
  1048. if (el) {
  1049. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1050. arr.push(el);
  1051. }
  1052. }
  1053. return arr;
  1054. }
  1055. function byClass(className, tag, root) {
  1056. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1057. if (root.getElementsByClassName) {
  1058. els = root.getElementsByClassName(stripslashes(className));
  1059. for (i = 0, len = els.length; i < len; i++) {
  1060. el = els[i];
  1061. if (cmpTag(tag, el.nodeName)) {
  1062. arr.push(el);
  1063. }
  1064. }
  1065. } else if (doc.querySelectorAll) {
  1066. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1067. for (i = 0, len = els.length; i < len; i++) {
  1068. el = els[i];
  1069. if (_contains(root, el)) {
  1070. arr.push(el);
  1071. }
  1072. }
  1073. } else {
  1074. els = root.getElementsByTagName(tag);
  1075. className = ' ' + className + ' ';
  1076. for (i = 0, len = els.length; i < len; i++) {
  1077. el = els[i];
  1078. if (el.nodeType == 1) {
  1079. var cls = el.className;
  1080. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1081. arr.push(el);
  1082. }
  1083. }
  1084. }
  1085. }
  1086. return arr;
  1087. }
  1088. function byName(name, tag, root) {
  1089. var arr = [], doc = root.ownerDocument || root,
  1090. els = doc.getElementsByName(stripslashes(name)), el;
  1091. for (var i = 0, len = els.length; i < len; i++) {
  1092. el = els[i];
  1093. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1094. if (el.getAttribute('name') !== null) {
  1095. arr.push(el);
  1096. }
  1097. }
  1098. }
  1099. return arr;
  1100. }
  1101. function byAttr(key, val, tag, root) {
  1102. var arr = [], els = root.getElementsByTagName(tag), el;
  1103. for (var i = 0, len = els.length; i < len; i++) {
  1104. el = els[i];
  1105. if (el.nodeType == 1) {
  1106. if (val === null) {
  1107. if (_getAttr(el, key) !== null) {
  1108. arr.push(el);
  1109. }
  1110. } else {
  1111. if (val === escape(_getAttr(el, key))) {
  1112. arr.push(el);
  1113. }
  1114. }
  1115. }
  1116. }
  1117. return arr;
  1118. }
  1119. function select(expr, root) {
  1120. var arr = [], matches;
  1121. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1122. var tag = matches ? matches[1] : '*';
  1123. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1124. arr = byId(matches[1], tag, root);
  1125. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1126. arr = byClass(matches[1], tag, root);
  1127. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1128. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1129. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1130. var key = matches[1].toLowerCase(), val = matches[2];
  1131. if (key === 'id') {
  1132. arr = byId(val, tag, root);
  1133. } else if (key === 'class') {
  1134. arr = byClass(val, tag, root);
  1135. } else if (key === 'name') {
  1136. arr = byName(val, tag, root);
  1137. } else {
  1138. arr = byAttr(key, val, tag, root);
  1139. }
  1140. } else {
  1141. var els = root.getElementsByTagName(tag), el;
  1142. for (var i = 0, len = els.length; i < len; i++) {
  1143. el = els[i];
  1144. if (el.nodeType == 1) {
  1145. arr.push(el);
  1146. }
  1147. }
  1148. }
  1149. return arr;
  1150. }
  1151. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1152. while ((arr = re.exec(expr))) {
  1153. if (arr[1] !== ' ') {
  1154. parts.push(arr[1]);
  1155. }
  1156. }
  1157. var results = [];
  1158. if (parts.length == 1) {
  1159. return select(parts[0], root);
  1160. }
  1161. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1162. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1163. part = parts[i];
  1164. if (part === '>') {
  1165. isChild = true;
  1166. continue;
  1167. }
  1168. if (i > 0) {
  1169. els = [];
  1170. for (j = 0, len = results.length; j < len; j++) {
  1171. val = results[j];
  1172. subResults = select(part, val);
  1173. for (k = 0, l = subResults.length; k < l; k++) {
  1174. v = subResults[k];
  1175. if (isChild) {
  1176. if (val === v.parentNode) {
  1177. els.push(v);
  1178. }
  1179. } else {
  1180. els.push(v);
  1181. }
  1182. }
  1183. }
  1184. results = els;
  1185. } else {
  1186. results = select(part, root);
  1187. }
  1188. if (results.length === 0) {
  1189. return [];
  1190. }
  1191. }
  1192. return results;
  1193. }
  1194. function _query(expr, root) {
  1195. var arr = _queryAll(expr, root);
  1196. return arr.length > 0 ? arr[0] : null;
  1197. }
  1198. K.query = _query;
  1199. K.queryAll = _queryAll;
  1200. function _get(val) {
  1201. return K(val)[0];
  1202. }
  1203. function _getDoc(node) {
  1204. if (!node) {
  1205. return document;
  1206. }
  1207. return node.ownerDocument || node.document || node;
  1208. }
  1209. function _getWin(node) {
  1210. if (!node) {
  1211. return window;
  1212. }
  1213. var doc = _getDoc(node);
  1214. return doc.parentWindow || doc.defaultView;
  1215. }
  1216. function _setHtml(el, html) {
  1217. if (el.nodeType != 1) {
  1218. return;
  1219. }
  1220. var doc = _getDoc(el);
  1221. try {
  1222. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1223. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1224. temp.parentNode.removeChild(temp);
  1225. } catch(e) {
  1226. K(el).empty();
  1227. K('@' + html, doc).each(function() {
  1228. el.appendChild(this);
  1229. });
  1230. }
  1231. }
  1232. function _hasClass(el, cls) {
  1233. return _inString(cls, el.className, ' ');
  1234. }
  1235. function _setAttr(el, key, val) {
  1236. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1237. key = 'className';
  1238. }
  1239. el.setAttribute(key, '' + val);
  1240. }
  1241. function _removeAttr(el, key) {
  1242. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1243. key = 'className';
  1244. }
  1245. _setAttr(el, key, '');
  1246. el.removeAttribute(key);
  1247. }
  1248. function _getNodeName(node) {
  1249. if (!node || !node.nodeName) {
  1250. return '';
  1251. }
  1252. return node.nodeName.toLowerCase();
  1253. }
  1254. function _computedCss(el, key) {
  1255. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1256. if (win.getComputedStyle) {
  1257. var style = win.getComputedStyle(el, null);
  1258. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1259. } else if (el.currentStyle) {
  1260. val = el.currentStyle[camelKey] || el.style[camelKey];
  1261. }
  1262. return val;
  1263. }
  1264. function _hasVal(node) {
  1265. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1266. }
  1267. function _docElement(doc) {
  1268. doc = doc || document;
  1269. return _QUIRKS ? doc.body : doc.documentElement;
  1270. }
  1271. function _docHeight(doc) {
  1272. var el = _docElement(doc);
  1273. return Math.max(el.scrollHeight, el.clientHeight);
  1274. }
  1275. function _docWidth(doc) {
  1276. var el = _docElement(doc);
  1277. return Math.max(el.scrollWidth, el.clientWidth);
  1278. }
  1279. function _getScrollPos(doc) {
  1280. doc = doc || document;
  1281. var x, y;
  1282. if (_IE || _NEWIE || _OPERA) {
  1283. x = _docElement(doc).scrollLeft;
  1284. y = _docElement(doc).scrollTop;
  1285. } else {
  1286. x = _getWin(doc).scrollX;
  1287. y = _getWin(doc).scrollY;
  1288. }
  1289. return {x : x, y : y};
  1290. }
  1291. function KNode(node) {
  1292. this.init(node);
  1293. }
  1294. _extend(KNode, {
  1295. init : function(node) {
  1296. var self = this;
  1297. node = _isArray(node) ? node : [node];
  1298. var length = 0;
  1299. for (var i = 0, len = node.length; i < len; i++) {
  1300. if (node[i]) {
  1301. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1302. length++;
  1303. }
  1304. }
  1305. self.length = length;
  1306. self.doc = _getDoc(self[0]);
  1307. self.name = _getNodeName(self[0]);
  1308. self.type = self.length > 0 ? self[0].nodeType : null;
  1309. self.win = _getWin(self[0]);
  1310. },
  1311. each : function(fn) {
  1312. var self = this;
  1313. for (var i = 0; i < self.length; i++) {
  1314. if (fn.call(self[i], i, self[i]) === false) {
  1315. return self;
  1316. }
  1317. }
  1318. return self;
  1319. },
  1320. bind : function(type, fn) {
  1321. this.each(function() {
  1322. _bind(this, type, fn);
  1323. });
  1324. return this;
  1325. },
  1326. unbind : function(type, fn) {
  1327. this.each(function() {
  1328. _unbind(this, type, fn);
  1329. });
  1330. return this;
  1331. },
  1332. fire : function(type) {
  1333. if (this.length < 1) {
  1334. return this;
  1335. }
  1336. _fire(this[0], type);
  1337. return this;
  1338. },
  1339. hasAttr : function(key) {
  1340. if (this.length < 1) {
  1341. return false;
  1342. }
  1343. return !!_getAttr(this[0], key);
  1344. },
  1345. attr : function(key, val) {
  1346. var self = this;
  1347. if (key === undefined) {
  1348. return _getAttrList(self.outer());
  1349. }
  1350. if (typeof key === 'object') {
  1351. _each(key, function(k, v) {
  1352. self.attr(k, v);
  1353. });
  1354. return self;
  1355. }
  1356. if (val === undefined) {
  1357. val = self.length < 1 ? null : _getAttr(self[0], key);
  1358. return val === null ? '' : val;
  1359. }
  1360. self.each(function() {
  1361. _setAttr(this, key, val);
  1362. });
  1363. return self;
  1364. },
  1365. removeAttr : function(key) {
  1366. this.each(function() {
  1367. _removeAttr(this, key);
  1368. });
  1369. return this;
  1370. },
  1371. get : function(i) {
  1372. if (this.length < 1) {
  1373. return null;
  1374. }
  1375. return this[i || 0];
  1376. },
  1377. eq : function(i) {
  1378. if (this.length < 1) {
  1379. return null;
  1380. }
  1381. return this[i] ? new KNode(this[i]) : null;
  1382. },
  1383. hasClass : function(cls) {
  1384. if (this.length < 1) {
  1385. return false;
  1386. }
  1387. return _hasClass(this[0], cls);
  1388. },
  1389. addClass : function(cls) {
  1390. this.each(function() {
  1391. if (!_hasClass(this, cls)) {
  1392. this.className = _trim(this.className + ' ' + cls);
  1393. }
  1394. });
  1395. return this;
  1396. },
  1397. removeClass : function(cls) {
  1398. this.each(function() {
  1399. if (_hasClass(this, cls)) {
  1400. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1401. }
  1402. });
  1403. return this;
  1404. },
  1405. html : function(val) {
  1406. var self = this;
  1407. if (val === undefined) {
  1408. if (self.length < 1 || self.type != 1) {
  1409. return '';
  1410. }
  1411. return _formatHtml(self[0].innerHTML);
  1412. }
  1413. self.each(function() {
  1414. _setHtml(this, val);
  1415. });
  1416. return self;
  1417. },
  1418. text : function() {
  1419. var self = this;
  1420. if (self.length < 1) {
  1421. return '';
  1422. }
  1423. return _IE ? self[0].innerText : self[0].textContent;
  1424. },
  1425. hasVal : function() {
  1426. if (this.length < 1) {
  1427. return false;
  1428. }
  1429. return _hasVal(this[0]);
  1430. },
  1431. val : function(val) {
  1432. var self = this;
  1433. if (val === undefined) {
  1434. if (self.length < 1) {
  1435. return '';
  1436. }
  1437. return self.hasVal() ? self[0].value : self.attr('value');
  1438. } else {
  1439. self.each(function() {
  1440. if (_hasVal(this)) {
  1441. this.value = val;
  1442. } else {
  1443. _setAttr(this, 'value' , val);
  1444. }
  1445. });
  1446. return self;
  1447. }
  1448. },
  1449. css : function(key, val) {
  1450. var self = this;
  1451. if (key === undefined) {
  1452. return _getCssList(self.attr('style'));
  1453. }
  1454. if (typeof key === 'object') {
  1455. _each(key, function(k, v) {
  1456. self.css(k, v);
  1457. });
  1458. return self;
  1459. }
  1460. if (val === undefined) {
  1461. if (self.length < 1) {
  1462. return '';
  1463. }
  1464. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1465. }
  1466. self.each(function() {
  1467. this.style[_toCamel(key)] = val;
  1468. });
  1469. return self;
  1470. },
  1471. width : function(val) {
  1472. var self = this;
  1473. if (val === undefined) {
  1474. if (self.length < 1) {
  1475. return 0;
  1476. }
  1477. return self[0].offsetWidth;
  1478. }
  1479. return self.css('width', _addUnit(val));
  1480. },
  1481. height : function(val) {
  1482. var self = this;
  1483. if (val === undefined) {
  1484. if (self.length < 1) {
  1485. return 0;
  1486. }
  1487. return self[0].offsetHeight;
  1488. }
  1489. return self.css('height', _addUnit(val));
  1490. },
  1491. opacity : function(val) {
  1492. this.each(function() {
  1493. if (this.style.opacity === undefined) {
  1494. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1495. } else {
  1496. this.style.opacity = val == 1 ? '' : val;
  1497. }
  1498. });
  1499. return this;
  1500. },
  1501. data : function(key, val) {
  1502. var self = this;
  1503. key = 'kindeditor_data_' + key;
  1504. if (val === undefined) {
  1505. if (self.length < 1) {
  1506. return null;
  1507. }
  1508. return self[0][key];
  1509. }
  1510. this.each(function() {
  1511. this[key] = val;
  1512. });
  1513. return self;
  1514. },
  1515. pos : function() {
  1516. var self = this, node = self[0], x = 0, y = 0;
  1517. if (node) {
  1518. if (node.getBoundingClientRect) {
  1519. var box = node.getBoundingClientRect(),
  1520. pos = _getScrollPos(self.doc);
  1521. x = box.left + pos.x;
  1522. y = box.top + pos.y;
  1523. } else {
  1524. while (node) {
  1525. x += node.offsetLeft;
  1526. y += node.offsetTop;
  1527. node = node.offsetParent;
  1528. }
  1529. }
  1530. }
  1531. return {x : _round(x), y : _round(y)};
  1532. },
  1533. clone : function(bool) {
  1534. if (this.length < 1) {
  1535. return new KNode([]);
  1536. }
  1537. return new KNode(this[0].cloneNode(bool));
  1538. },
  1539. append : function(expr) {
  1540. this.each(function() {
  1541. if (this.appendChild) {
  1542. this.appendChild(_get(expr));
  1543. }
  1544. });
  1545. return this;
  1546. },
  1547. appendTo : function(expr) {
  1548. this.each(function() {
  1549. _get(expr).appendChild(this);
  1550. });
  1551. return this;
  1552. },
  1553. before : function(expr) {
  1554. this.each(function() {
  1555. this.parentNode.insertBefore(_get(expr), this);
  1556. });
  1557. return this;
  1558. },
  1559. after : function(expr) {
  1560. this.each(function() {
  1561. if (this.nextSibling) {
  1562. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1563. } else {
  1564. this.parentNode.appendChild(_get(expr));
  1565. }
  1566. });
  1567. return this;
  1568. },
  1569. replaceWith : function(expr) {
  1570. var nodes = [];
  1571. this.each(function(i, node) {
  1572. _unbind(node);
  1573. var newNode = _get(expr);
  1574. node.parentNode.replaceChild(newNode, node);
  1575. nodes.push(newNode);
  1576. });
  1577. return K(nodes);
  1578. },
  1579. empty : function() {
  1580. var self = this;
  1581. self.each(function(i, node) {
  1582. var child = node.firstChild;
  1583. while (child) {
  1584. if (!node.parentNode) {
  1585. return;
  1586. }
  1587. var next = child.nextSibling;
  1588. child.parentNode.removeChild(child);
  1589. child = next;
  1590. }
  1591. });
  1592. return self;
  1593. },
  1594. remove : function(keepChilds) {
  1595. var self = this;
  1596. self.each(function(i, node) {
  1597. if (!node.parentNode) {
  1598. return;
  1599. }
  1600. _unbind(node);
  1601. if (keepChilds) {
  1602. var child = node.firstChild;
  1603. while (child) {
  1604. var next = child.nextSibling;
  1605. node.parentNode.insertBefore(child, node);
  1606. child = next;
  1607. }
  1608. }
  1609. node.parentNode.removeChild(node);
  1610. delete self[i];
  1611. });
  1612. self.length = 0;
  1613. return self;
  1614. },
  1615. show : function(val) {
  1616. var self = this;
  1617. if (val === undefined) {
  1618. val = self._originDisplay || '';
  1619. }
  1620. if (self.css('display') != 'none') {
  1621. return self;
  1622. }
  1623. return self.css('display', val);
  1624. },
  1625. hide : function() {
  1626. var self = this;
  1627. if (self.length < 1) {
  1628. return self;
  1629. }
  1630. self._originDisplay = self[0].style.display;
  1631. return self.css('display', 'none');
  1632. },
  1633. outer : function() {
  1634. var self = this;
  1635. if (self.length < 1) {
  1636. return '';
  1637. }
  1638. var div = self.doc.createElement('div'), html;
  1639. div.appendChild(self[0].cloneNode(true));
  1640. html = _formatHtml(div.innerHTML);
  1641. div = null;
  1642. return html;
  1643. },
  1644. isSingle : function() {
  1645. return !!_SINGLE_TAG_MAP[this.name];
  1646. },
  1647. isInline : function() {
  1648. return !!_INLINE_TAG_MAP[this.name];
  1649. },
  1650. isBlock : function() {
  1651. return !!_BLOCK_TAG_MAP[this.name];
  1652. },
  1653. isStyle : function() {
  1654. return !!_STYLE_TAG_MAP[this.name];
  1655. },
  1656. isControl : function() {
  1657. return !!_CONTROL_TAG_MAP[this.name];
  1658. },
  1659. contains : function(otherNode) {
  1660. if (this.length < 1) {
  1661. return false;
  1662. }
  1663. return _contains(this[0], _get(otherNode));
  1664. },
  1665. parent : function() {
  1666. if (this.length < 1) {
  1667. return null;
  1668. }
  1669. var node = this[0].parentNode;
  1670. return node ? new KNode(node) : null;
  1671. },
  1672. children : function() {
  1673. if (this.length < 1) {
  1674. return new KNode([]);
  1675. }
  1676. var list = [], child = this[0].firstChild;
  1677. while (child) {
  1678. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1679. list.push(child);
  1680. }
  1681. child = child.nextSibling;
  1682. }
  1683. return new KNode(list);
  1684. },
  1685. first : function() {
  1686. var list = this.children();
  1687. return list.length > 0 ? list.eq(0) : null;
  1688. },
  1689. last : function() {
  1690. var list = this.children();
  1691. return list.length > 0 ? list.eq(list.length - 1) : null;
  1692. },
  1693. index : function() {
  1694. if (this.length < 1) {
  1695. return -1;
  1696. }
  1697. var i = -1, sibling = this[0];
  1698. while (sibling) {
  1699. i++;
  1700. sibling = sibling.previousSibling;
  1701. }
  1702. return i;
  1703. },
  1704. prev : function() {
  1705. if (this.length < 1) {
  1706. return null;
  1707. }
  1708. var node = this[0].previousSibling;
  1709. return node ? new KNode(node) : null;
  1710. },
  1711. next : function() {
  1712. if (this.length < 1) {
  1713. return null;
  1714. }
  1715. var node = this[0].nextSibling;
  1716. return node ? new KNode(node) : null;
  1717. },
  1718. scan : function(fn, order) {
  1719. if (this.length < 1) {
  1720. return;
  1721. }
  1722. order = (order === undefined) ? true : order;
  1723. function walk(node) {
  1724. var n = order ? node.firstChild : node.lastChild;
  1725. while (n) {
  1726. var next = order ? n.nextSibling : n.previousSibling;
  1727. if (fn(n) === false) {
  1728. return false;
  1729. }
  1730. if (walk(n) === false) {
  1731. return false;
  1732. }
  1733. n = next;
  1734. }
  1735. }
  1736. walk(this[0]);
  1737. return this;
  1738. }
  1739. });
  1740. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1741. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1742. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1743. KNode.prototype[type] = function(fn) {
  1744. return fn ? this.bind(type, fn) : this.fire(type);
  1745. };
  1746. });
  1747. var _K = K;
  1748. K = function(expr, root) {
  1749. if (expr === undefined || expr === null) {
  1750. return;
  1751. }
  1752. function newNode(node) {
  1753. if (!node[0]) {
  1754. node = [];
  1755. }
  1756. return new KNode(node);
  1757. }
  1758. if (typeof expr === 'string') {
  1759. if (root) {
  1760. root = _get(root);
  1761. }
  1762. var length = expr.length;
  1763. if (expr.charAt(0) === '@') {
  1764. expr = expr.substr(1);
  1765. }
  1766. if (expr.length !== length || /<.+>/.test(expr)) {
  1767. var doc = root ? root.ownerDocument || root : document,
  1768. div = doc.createElement('div'), list = [];
  1769. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1770. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1771. var child = div.childNodes[i];
  1772. if (child.id == '__kindeditor_temp_tag__') {
  1773. continue;
  1774. }
  1775. list.push(child);
  1776. }
  1777. return newNode(list);
  1778. }
  1779. return newNode(_queryAll(expr, root));
  1780. }
  1781. if (expr && expr.constructor === KNode) {
  1782. return expr;
  1783. }
  1784. if (expr.toArray) {
  1785. expr = expr.toArray();
  1786. }
  1787. if (_isArray(expr)) {
  1788. return newNode(expr);
  1789. }
  1790. return newNode(_toArray(arguments));
  1791. };
  1792. _each(_K, function(key, val) {
  1793. K[key] = val;
  1794. });
  1795. K.NodeClass = KNode;
  1796. window.KindEditor = K;
  1797. var _START_TO_START = 0,
  1798. _START_TO_END = 1,
  1799. _END_TO_END = 2,
  1800. _END_TO_START = 3,
  1801. _BOOKMARK_ID = 0;
  1802. function _updateCollapsed(range) {
  1803. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1804. return range;
  1805. }
  1806. function _copyAndDelete(range, isCopy, isDelete) {
  1807. var doc = range.doc, nodeList = [];
  1808. function splitTextNode(node, startOffset, endOffset) {
  1809. var length = node.nodeValue.length, centerNode;
  1810. if (isCopy) {
  1811. var cloneNode = node.cloneNode(true);
  1812. if (startOffset > 0) {
  1813. centerNode = cloneNode.splitText(startOffset);
  1814. } else {
  1815. centerNode = cloneNode;
  1816. }
  1817. if (endOffset < length) {
  1818. centerNode.splitText(endOffset - startOffset);
  1819. }
  1820. }
  1821. if (isDelete) {
  1822. var center = node;
  1823. if (startOffset > 0) {
  1824. center = node.splitText(startOffset);
  1825. range.setStart(node, startOffset);
  1826. }
  1827. if (endOffset < length) {
  1828. var right = center.splitText(endOffset - startOffset);
  1829. range.setEnd(right, 0);
  1830. }
  1831. nodeList.push(center);
  1832. }
  1833. return centerNode;
  1834. }
  1835. function removeNodes() {
  1836. if (isDelete) {
  1837. range.up().collapse(true);
  1838. }
  1839. for (var i = 0, len = nodeList.length; i < len; i++) {
  1840. var node = nodeList[i];
  1841. if (node.parentNode) {
  1842. node.parentNode.removeChild(node);
  1843. }
  1844. }
  1845. }
  1846. var copyRange = range.cloneRange().down();
  1847. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1848. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1849. if (ancestor.nodeType == 3) {
  1850. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1851. if (isCopy) {
  1852. frag.appendChild(textNode);
  1853. }
  1854. removeNodes();
  1855. return isCopy ? frag : range;
  1856. }
  1857. function extractNodes(parent, frag) {
  1858. var node = parent.firstChild, nextNode;
  1859. while (node) {
  1860. var testRange = new KRange(doc).selectNode(node);
  1861. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1862. if (start >= 0 && incStart <= 0) {
  1863. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1864. }
  1865. if (incStart >= 0 && incEnd <= 0) {
  1866. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1867. }
  1868. if (incEnd >= 0 && end <= 0) {
  1869. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1870. }
  1871. if (end >= 0) {
  1872. return false;
  1873. }
  1874. nextNode = node.nextSibling;
  1875. if (start > 0) {
  1876. if (node.nodeType == 1) {
  1877. if (incStart >= 0 && incEnd <= 0) {
  1878. if (isCopy) {
  1879. frag.appendChild(node.cloneNode(true));
  1880. }
  1881. if (isDelete) {
  1882. nodeList.push(node);
  1883. }
  1884. } else {
  1885. var childFlag;
  1886. if (isCopy) {
  1887. childFlag = node.cloneNode(false);
  1888. frag.appendChild(childFlag);
  1889. }
  1890. if (extractNodes(node, childFlag) === false) {
  1891. return false;
  1892. }
  1893. }
  1894. } else if (node.nodeType == 3) {
  1895. var textNode;
  1896. if (node == copyRange.startContainer) {
  1897. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1898. } else if (node == copyRange.endContainer) {
  1899. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1900. } else {
  1901. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1902. }
  1903. if (isCopy) {
  1904. try {
  1905. frag.appendChild(textNode);
  1906. } catch(e) {}
  1907. }
  1908. }
  1909. }
  1910. node = nextNode;
  1911. }
  1912. }
  1913. extractNodes(ancestor, frag);
  1914. if (isDelete) {
  1915. range.up().collapse(true);
  1916. }
  1917. for (var i = 0, len = nodeList.length; i < len; i++) {
  1918. var node = nodeList[i];
  1919. if (node.parentNode) {
  1920. node.parentNode.removeChild(node);
  1921. }
  1922. }
  1923. return isCopy ? frag : range;
  1924. }
  1925. function _moveToElementText(range, el) {
  1926. var node = el;
  1927. while (node) {
  1928. var knode = K(node);
  1929. if (knode.name == 'marquee' || knode.name == 'select') {
  1930. return;
  1931. }
  1932. node = node.parentNode;
  1933. }
  1934. try {
  1935. range.moveToElementText(el);
  1936. } catch(e) {}
  1937. }
  1938. function _getStartEnd(rng, isStart) {
  1939. var doc = rng.parentElement().ownerDocument,
  1940. pointRange = rng.duplicate();
  1941. pointRange.collapse(isStart);
  1942. var parent = pointRange.parentElement(),
  1943. nodes = parent.childNodes;
  1944. if (nodes.length === 0) {
  1945. return {node: parent.parentNode, offset: K(parent).index()};
  1946. }
  1947. var startNode = doc, startPos = 0, cmp = -1;
  1948. var testRange = rng.duplicate();
  1949. _moveToElementText(testRange, parent);
  1950. for (var i = 0, len = nodes.length; i < len; i++) {
  1951. var node = nodes[i];
  1952. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1953. if (cmp === 0) {
  1954. return {node: node.parentNode, offset: i};
  1955. }
  1956. if (node.nodeType == 1) {
  1957. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1958. if (knode.isControl()) {
  1959. dummy = doc.createElement('span');
  1960. knode.after(dummy);
  1961. newNode = dummy;
  1962. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1963. }
  1964. _moveToElementText(nodeRange, newNode);
  1965. testRange.setEndPoint('StartToEnd', nodeRange);
  1966. if (cmp > 0) {
  1967. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1968. } else {
  1969. startPos = 0;
  1970. }
  1971. if (dummy) {
  1972. K(dummy).remove();
  1973. }
  1974. } else if (node.nodeType == 3) {
  1975. testRange.moveStart('character', node.nodeValue.length);
  1976. startPos += node.nodeValue.length;
  1977. }
  1978. if (cmp < 0) {
  1979. startNode = node;
  1980. }
  1981. }
  1982. if (cmp < 0 && startNode.nodeType == 1) {
  1983. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1984. }
  1985. if (cmp > 0) {
  1986. while (startNode.nextSibling && startNode.nodeType == 1) {
  1987. startNode = startNode.nextSibling;
  1988. }
  1989. }
  1990. testRange = rng.duplicate();
  1991. _moveToElementText(testRange, parent);
  1992. testRange.setEndPoint('StartToEnd', pointRange);
  1993. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  1994. if (cmp > 0 && startNode.nodeType == 3) {
  1995. var prevNode = startNode.previousSibling;
  1996. while (prevNode && prevNode.nodeType == 3) {
  1997. startPos -= prevNode.nodeValue.length;
  1998. prevNode = prevNode.previousSibling;
  1999. }
  2000. }
  2001. return {node: startNode, offset: startPos};
  2002. }
  2003. function _getEndRange(node, offset) {
  2004. var doc = node.ownerDocument || node,
  2005. range = doc.body.createTextRange();
  2006. if (doc == node) {
  2007. range.collapse(true);
  2008. return range;
  2009. }
  2010. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2011. var children = node.childNodes, isStart, child;
  2012. if (offset === 0) {
  2013. child = children[0];
  2014. isStart = true;
  2015. } else {
  2016. child = children[offset - 1];
  2017. isStart = false;
  2018. }
  2019. if (!child) {
  2020. return range;
  2021. }
  2022. if (K(child).name === 'head') {
  2023. if (offset === 1) {
  2024. isStart = true;
  2025. }
  2026. if (offset === 2) {
  2027. isStart = false;
  2028. }
  2029. range.collapse(isStart);
  2030. return range;
  2031. }
  2032. if (child.nodeType == 1) {
  2033. var kchild = K(child), span;
  2034. if (kchild.isControl()) {
  2035. span = doc.createElement('span');
  2036. if (isStart) {
  2037. kchild.before(span);
  2038. } else {
  2039. kchild.after(span);
  2040. }
  2041. child = span;
  2042. }
  2043. _moveToElementText(range, child);
  2044. range.collapse(isStart);
  2045. if (span) {
  2046. K(span).remove();
  2047. }
  2048. return range;
  2049. }
  2050. node = child;
  2051. offset = isStart ? 0 : child.nodeValue.length;
  2052. }
  2053. var dummy = doc.createElement('span');
  2054. K(node).before(dummy);
  2055. _moveToElementText(range, dummy);
  2056. range.moveStart('character', offset);
  2057. K(dummy).remove();
  2058. return range;
  2059. }
  2060. function _toRange(rng) {
  2061. var doc, range;
  2062. function tr2td(start) {
  2063. if (K(start.node).name == 'tr') {
  2064. start.node = start.node.cells[start.offset];
  2065. start.offset = 0;
  2066. }
  2067. }
  2068. if (_IERANGE) {
  2069. if (rng.item) {
  2070. doc = _getDoc(rng.item(0));
  2071. range = new KRange(doc);
  2072. range.selectNode(rng.item(0));
  2073. return range;
  2074. }
  2075. doc = rng.parentElement().ownerDocument;
  2076. var start = _getStartEnd(rng, true),
  2077. end = _getStartEnd(rng, false);
  2078. tr2td(start);
  2079. tr2td(end);
  2080. range = new KRange(doc);
  2081. range.setStart(start.node, start.offset);
  2082. range.setEnd(end.node, end.offset);
  2083. return range;
  2084. }
  2085. var startContainer = rng.startContainer;
  2086. doc = startContainer.ownerDocument || startContainer;
  2087. range = new KRange(doc);
  2088. range.setStart(startContainer, rng.startOffset);
  2089. range.setEnd(rng.endContainer, rng.endOffset);
  2090. return range;
  2091. }
  2092. function KRange(doc) {
  2093. this.init(doc);
  2094. }
  2095. _extend(KRange, {
  2096. init : function(doc) {
  2097. var self = this;
  2098. self.startContainer = doc;
  2099. self.startOffset = 0;
  2100. self.endContainer = doc;
  2101. self.endOffset = 0;
  2102. self.collapsed = true;
  2103. self.doc = doc;
  2104. },
  2105. commonAncestor : function() {
  2106. function getParents(node) {
  2107. var parents = [];
  2108. while (node) {
  2109. parents.push(node);
  2110. node = node.parentNode;
  2111. }
  2112. return parents;
  2113. }
  2114. var parentsA = getParents(this.startContainer),
  2115. parentsB = getParents(this.endContainer),
  2116. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2117. while (++i) {
  2118. parentA = parentsA[lenA - i];
  2119. parentB = parentsB[lenB - i];
  2120. if (!parentA || !parentB || parentA !== parentB) {
  2121. break;
  2122. }
  2123. }
  2124. return parentsA[lenA - i + 1];
  2125. },
  2126. setStart : function(node, offset) {
  2127. var self = this, doc = self.doc;
  2128. self.startContainer = node;
  2129. self.startOffset = offset;
  2130. if (self.endContainer === doc) {
  2131. self.endContainer = node;
  2132. self.endOffset = offset;
  2133. }
  2134. return _updateCollapsed(this);
  2135. },
  2136. setEnd : function(node, offset) {
  2137. var self = this, doc = self.doc;
  2138. self.endContainer = node;
  2139. self.endOffset = offset;
  2140. if (self.startContainer === doc) {
  2141. self.startContainer = node;
  2142. self.startOffset = offset;
  2143. }
  2144. return _updateCollapsed(this);
  2145. },
  2146. setStartBefore : function(node) {
  2147. return this.setStart(node.parentNode || this.doc, K(node).index());
  2148. },
  2149. setStartAfter : function(node) {
  2150. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2151. },
  2152. setEndBefore : function(node) {
  2153. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2154. },
  2155. setEndAfter : function(node) {
  2156. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2157. },
  2158. selectNode : function(node) {
  2159. return this.setStartBefore(node).setEndAfter(node);
  2160. },
  2161. selectNodeContents : function(node) {
  2162. var knode = K(node);
  2163. if (knode.type == 3 || knode.isSingle()) {
  2164. return this.selectNode(node);
  2165. }
  2166. var children = knode.children();
  2167. if (children.length > 0) {
  2168. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2169. }
  2170. return this.setStart(node, 0).setEnd(node, 0);
  2171. },
  2172. collapse : function(toStart) {
  2173. if (toStart) {
  2174. return this.setEnd(this.startContainer, this.startOffset);
  2175. }
  2176. return this.setStart(this.endContainer, this.endOffset);
  2177. },
  2178. compareBoundaryPoints : function(how, range) {
  2179. var rangeA = this.get(), rangeB = range.get();
  2180. if (_IERANGE) {
  2181. var arr = {};
  2182. arr[_START_TO_START] = 'StartToStart';
  2183. arr[_START_TO_END] = 'EndToStart';
  2184. arr[_END_TO_END] = 'EndToEnd';
  2185. arr[_END_TO_START] = 'StartToEnd';
  2186. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2187. if (cmp !== 0) {
  2188. return cmp;
  2189. }
  2190. var nodeA, nodeB, nodeC, posA, posB;
  2191. if (how === _START_TO_START || how === _END_TO_START) {
  2192. nodeA = this.startContainer;
  2193. posA = this.startOffset;
  2194. }
  2195. if (how === _START_TO_END || how === _END_TO_END) {
  2196. nodeA = this.endContainer;
  2197. posA = this.endOffset;
  2198. }
  2199. if (how === _START_TO_START || how === _START_TO_END) {
  2200. nodeB = range.startContainer;
  2201. posB = range.startOffset;
  2202. }
  2203. if (how === _END_TO_END || how === _END_TO_START) {
  2204. nodeB = range.endContainer;
  2205. posB = range.endOffset;
  2206. }
  2207. if (nodeA === nodeB) {
  2208. var diff = posA - posB;
  2209. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2210. }
  2211. nodeC = nodeB;
  2212. while (nodeC && nodeC.parentNode !== nodeA) {
  2213. nodeC = nodeC.parentNode;
  2214. }
  2215. if (nodeC) {
  2216. return K(nodeC).index() >= posA ? -1 : 1;
  2217. }
  2218. nodeC = nodeA;
  2219. while (nodeC && nodeC.parentNode !== nodeB) {
  2220. nodeC = nodeC.parentNode;
  2221. }
  2222. if (nodeC) {
  2223. return K(nodeC).index() >= posB ? 1 : -1;
  2224. }
  2225. nodeC = K(nodeB).next();
  2226. if (nodeC && nodeC.contains(nodeA)) {
  2227. return 1;
  2228. }
  2229. nodeC = K(nodeA).next();
  2230. if (nodeC && nodeC.contains(nodeB)) {
  2231. return -1;
  2232. }
  2233. } else {
  2234. return rangeA.compareBoundaryPoints(how, rangeB);
  2235. }
  2236. },
  2237. cloneRange : function() {
  2238. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2239. },
  2240. toString : function() {
  2241. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2242. return str.replace(/\r\n|\n|\r/g, '');
  2243. },
  2244. cloneContents : function() {
  2245. return _copyAndDelete(this, true, false);
  2246. },
  2247. deleteContents : function() {
  2248. return _copyAndDelete(this, false, true);
  2249. },
  2250. extractContents : function() {
  2251. return _copyAndDelete(this, true, true);
  2252. },
  2253. insertNode : function(node) {
  2254. var self = this,
  2255. sc = self.startContainer, so = self.startOffset,
  2256. ec = self.endContainer, eo = self.endOffset,
  2257. firstChild, lastChild, c, nodeCount = 1;
  2258. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2259. firstChild = node.firstChild;
  2260. lastChild = node.lastChild;
  2261. nodeCount = node.childNodes.length;
  2262. }
  2263. if (sc.nodeType == 1) {
  2264. c = sc.childNodes[so];
  2265. if (c) {
  2266. sc.insertBefore(node, c);
  2267. if (sc === ec) {
  2268. eo += nodeCount;
  2269. }
  2270. } else {
  2271. sc.appendChild(node);
  2272. }
  2273. } else if (sc.nodeType == 3) {
  2274. if (so === 0) {
  2275. sc.parentNode.insertBefore(node, sc);
  2276. if (sc.parentNode === ec) {
  2277. eo += nodeCount;
  2278. }
  2279. } else if (so >= sc.nodeValue.length) {
  2280. if (sc.nextSibling) {
  2281. sc.parentNode.insertBefore(node, sc.nextSibling);
  2282. } else {
  2283. sc.parentNode.appendChild(node);
  2284. }
  2285. } else {
  2286. if (so > 0) {
  2287. c = sc.splitText(so);
  2288. } else {
  2289. c = sc;
  2290. }
  2291. sc.parentNode.insertBefore(node, c);
  2292. if (sc === ec) {
  2293. ec = c;
  2294. eo -= so;
  2295. }
  2296. }
  2297. }
  2298. if (firstChild) {
  2299. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2300. } else {
  2301. self.selectNode(node);
  2302. }
  2303. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2304. return self;
  2305. }
  2306. return self.setEnd(ec, eo);
  2307. },
  2308. surroundContents : function(node) {
  2309. node.appendChild(this.extractContents());
  2310. return this.insertNode(node).selectNode(node);
  2311. },
  2312. isControl : function() {
  2313. var self = this,
  2314. sc = self.startContainer, so = self.startOffset,
  2315. ec = self.endContainer, eo = self.endOffset, rng;
  2316. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2317. },
  2318. get : function(hasControlRange) {
  2319. var self = this, doc = self.doc, node, rng;
  2320. if (!_IERANGE) {
  2321. rng = doc.createRange();
  2322. try {
  2323. rng.setStart(self.startContainer, self.startOffset);
  2324. rng.setEnd(self.endContainer, self.endOffset);
  2325. } catch (e) {}
  2326. return rng;
  2327. }
  2328. if (hasControlRange && self.isControl()) {
  2329. rng = doc.body.createControlRange();
  2330. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2331. return rng;
  2332. }
  2333. var range = self.cloneRange().down();
  2334. rng = doc.body.createTextRange();
  2335. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2336. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2337. return rng;
  2338. },
  2339. html : function() {
  2340. return K(this.cloneContents()).outer();
  2341. },
  2342. down : function() {
  2343. var self = this;
  2344. function downPos(node, pos, isStart) {
  2345. if (node.nodeType != 1) {
  2346. return;
  2347. }
  2348. var children = K(node).children();
  2349. if (children.length === 0) {
  2350. return;
  2351. }
  2352. var left, right, child, offset;
  2353. if (pos > 0) {
  2354. left = children.eq(pos - 1);
  2355. }
  2356. if (pos < children.length) {
  2357. right = children.eq(pos);
  2358. }
  2359. if (left && left.type == 3) {
  2360. child = left[0];
  2361. offset = child.nodeValue.length;
  2362. }
  2363. if (right && right.type == 3) {
  2364. child = right[0];
  2365. offset = 0;
  2366. }
  2367. if (!child) {
  2368. return;
  2369. }
  2370. if (isStart) {
  2371. self.setStart(child, offset);
  2372. } else {
  2373. self.setEnd(child, offset);
  2374. }
  2375. }
  2376. downPos(self.startContainer, self.startOffset, true);
  2377. downPos(self.endContainer, self.endOffset, false);
  2378. return self;
  2379. },
  2380. up : function() {
  2381. var self = this;
  2382. function upPos(node, pos, isStart) {
  2383. if (node.nodeType != 3) {
  2384. return;
  2385. }
  2386. if (pos === 0) {
  2387. if (isStart) {
  2388. self.setStartBefore(node);
  2389. } else {
  2390. self.setEndBefore(node);
  2391. }
  2392. } else if (pos == node.nodeValue.length) {
  2393. if (isStart) {
  2394. self.setStartAfter(node);
  2395. } else {
  2396. self.setEndAfter(node);
  2397. }
  2398. }
  2399. }
  2400. upPos(self.startContainer, self.startOffset, true);
  2401. upPos(self.endContainer, self.endOffset, false);
  2402. return self;
  2403. },
  2404. enlarge : function(toBlock) {
  2405. var self = this;
  2406. self.up();
  2407. function enlargePos(node, pos, isStart) {
  2408. var knode = K(node), parent;
  2409. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2410. return;
  2411. }
  2412. if (pos === 0) {
  2413. while (!knode.prev()) {
  2414. parent = knode.parent();
  2415. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2416. break;
  2417. }
  2418. knode = parent;
  2419. }
  2420. if (isStart) {
  2421. self.setStartBefore(knode[0]);
  2422. } else {
  2423. self.setEndBefore(knode[0]);
  2424. }
  2425. } else if (pos == knode.children().length) {
  2426. while (!knode.next()) {
  2427. parent = knode.parent();
  2428. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2429. break;
  2430. }
  2431. knode = parent;
  2432. }
  2433. if (isStart) {
  2434. self.setStartAfter(knode[0]);
  2435. } else {
  2436. self.setEndAfter(knode[0]);
  2437. }
  2438. }
  2439. }
  2440. enlargePos(self.startContainer, self.startOffset, true);
  2441. enlargePos(self.endContainer, self.endOffset, false);
  2442. return self;
  2443. },
  2444. shrink : function() {
  2445. var self = this, child, collapsed = self.collapsed;
  2446. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2447. self.setStart(child, 0);
  2448. }
  2449. if (collapsed) {
  2450. return self.collapse(collapsed);
  2451. }
  2452. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2453. self.setEnd(child, child.childNodes.length);
  2454. }
  2455. return self;
  2456. },
  2457. createBookmark : function(serialize) {
  2458. var self = this, doc = self.doc, endNode,
  2459. startNode = K('<span style="display:none;"></span>', doc)[0];
  2460. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2461. if (!self.collapsed) {
  2462. endNode = startNode.cloneNode(true);
  2463. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2464. }
  2465. if (endNode) {
  2466. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2467. }
  2468. self.insertNode(startNode).setStartAfter(startNode);
  2469. return {
  2470. start : serialize ? '#' + startNode.id : startNode,
  2471. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2472. };
  2473. },
  2474. moveToBookmark : function(bookmark) {
  2475. var self = this, doc = self.doc,
  2476. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2477. if (!start || start.length < 1) {
  2478. return self;
  2479. }
  2480. self.setStartBefore(start[0]);
  2481. start.remove();
  2482. if (end && end.length > 0) {
  2483. self.setEndBefore(end[0]);
  2484. end.remove();
  2485. } else {
  2486. self.collapse(true);
  2487. }
  2488. return self;
  2489. },
  2490. dump : function() {
  2491. console.log('--------------------');
  2492. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2493. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2494. }
  2495. });
  2496. function _range(mixed) {
  2497. if (!mixed.nodeName) {
  2498. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2499. }
  2500. return new KRange(mixed);
  2501. }
  2502. K.RangeClass = KRange;
  2503. K.range = _range;
  2504. K.START_TO_START = _START_TO_START;
  2505. K.START_TO_END = _START_TO_END;
  2506. K.END_TO_END = _END_TO_END;
  2507. K.END_TO_START = _END_TO_START;
  2508. function _nativeCommand(doc, key, val) {
  2509. try {
  2510. doc.execCommand(key, false, val);
  2511. } catch(e) {}
  2512. }
  2513. function _nativeCommandValue(doc, key) {
  2514. var val = '';
  2515. try {
  2516. val = doc.queryCommandValue(key);
  2517. } catch (e) {}
  2518. if (typeof val !== 'string') {
  2519. val = '';
  2520. }
  2521. return val;
  2522. }
  2523. function _getSel(doc) {
  2524. var win = _getWin(doc);
  2525. return _IERANGE ? doc.selection : win.getSelection();
  2526. }
  2527. function _getRng(doc) {
  2528. var sel = _getSel(doc), rng;
  2529. try {
  2530. if (sel.rangeCount > 0) {
  2531. rng = sel.getRangeAt(0);
  2532. } else {
  2533. rng = sel.createRange();
  2534. }
  2535. } catch(e) {}
  2536. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2537. return null;
  2538. }
  2539. return rng;
  2540. }
  2541. function _singleKeyMap(map) {
  2542. var newMap = {}, arr, v;
  2543. _each(map, function(key, val) {
  2544. arr = key.split(',');
  2545. for (var i = 0, len = arr.length; i < len; i++) {
  2546. v = arr[i];
  2547. newMap[v] = val;
  2548. }
  2549. });
  2550. return newMap;
  2551. }
  2552. function _hasAttrOrCss(knode, map) {
  2553. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2554. }
  2555. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2556. mapKey = mapKey || knode.name;
  2557. if (knode.type !== 1) {
  2558. return false;
  2559. }
  2560. var newMap = _singleKeyMap(map);
  2561. if (!newMap[mapKey]) {
  2562. return false;
  2563. }
  2564. var arr = newMap[mapKey].split(',');
  2565. for (var i = 0, len = arr.length; i < len; i++) {
  2566. var key = arr[i];
  2567. if (key === '*') {
  2568. return true;
  2569. }
  2570. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2571. var method = match[1] ? 'css' : 'attr';
  2572. key = match[2];
  2573. var val = match[3] || '';
  2574. if (val === '' && knode[method](key) !== '') {
  2575. return true;
  2576. }
  2577. if (val !== '' && knode[method](key) === val) {
  2578. return true;
  2579. }
  2580. }
  2581. return false;
  2582. }
  2583. function _removeAttrOrCss(knode, map) {
  2584. if (knode.type != 1) {
  2585. return;
  2586. }
  2587. _removeAttrOrCssByKey(knode, map, '*');
  2588. _removeAttrOrCssByKey(knode, map);
  2589. }
  2590. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2591. mapKey = mapKey || knode.name;
  2592. if (knode.type !== 1) {
  2593. return;
  2594. }
  2595. var newMap = _singleKeyMap(map);
  2596. if (!newMap[mapKey]) {
  2597. return;
  2598. }
  2599. var arr = newMap[mapKey].split(','), allFlag = false;
  2600. for (var i = 0, len = arr.length; i < len; i++) {
  2601. var key = arr[i];
  2602. if (key === '*') {
  2603. allFlag = true;
  2604. break;
  2605. }
  2606. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2607. key = match[2];
  2608. if (match[1]) {
  2609. key = _toCamel(key);
  2610. if (knode[0].style[key]) {
  2611. knode[0].style[key] = '';
  2612. }
  2613. } else {
  2614. knode.removeAttr(key);
  2615. }
  2616. }
  2617. if (allFlag) {
  2618. knode.remove(true);
  2619. }
  2620. }
  2621. function _getInnerNode(knode) {
  2622. var inner = knode;
  2623. while (inner.first()) {
  2624. inner = inner.first();
  2625. }
  2626. return inner;
  2627. }
  2628. function _isEmptyNode(knode) {
  2629. if (knode.type != 1 || knode.isSingle()) {
  2630. return false;
  2631. }
  2632. return knode.html().replace(/<[^>]+>/g, '') === '';
  2633. }
  2634. function _mergeWrapper(a, b) {
  2635. a = a.clone(true);
  2636. var lastA = _getInnerNode(a), childA = a, merged = false;
  2637. while (b) {
  2638. while (childA) {
  2639. if (childA.name === b.name) {
  2640. _mergeAttrs(childA, b.attr(), b.css());
  2641. merged = true;
  2642. }
  2643. childA = childA.first();
  2644. }
  2645. if (!merged) {
  2646. lastA.append(b.clone(false));
  2647. }
  2648. merged = false;
  2649. b = b.first();
  2650. }
  2651. return a;
  2652. }
  2653. function _wrapNode(knode, wrapper) {
  2654. wrapper = wrapper.clone(true);
  2655. if (knode.type == 3) {
  2656. _getInnerNode(wrapper).append(knode.clone(false));
  2657. knode.replaceWith(wrapper);
  2658. return wrapper;
  2659. }
  2660. var nodeWrapper = knode, child;
  2661. while ((child = knode.first()) && child.children().length == 1) {
  2662. knode = child;
  2663. }
  2664. child = knode.first();
  2665. var frag = knode.doc.createDocumentFragment();
  2666. while (child) {
  2667. frag.appendChild(child[0]);
  2668. child = child.next();
  2669. }
  2670. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2671. if (frag.firstChild) {
  2672. _getInnerNode(wrapper).append(frag);
  2673. }
  2674. nodeWrapper.replaceWith(wrapper);
  2675. return wrapper;
  2676. }
  2677. function _mergeAttrs(knode, attrs, styles) {
  2678. _each(attrs, function(key, val) {
  2679. if (key !== 'style') {
  2680. knode.attr(key, val);
  2681. }
  2682. });
  2683. _each(styles, function(key, val) {
  2684. knode.css(key, val);
  2685. });
  2686. }
  2687. function _inPreElement(knode) {
  2688. while (knode && knode.name != 'body') {
  2689. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2690. return true;
  2691. }
  2692. knode = knode.parent();
  2693. }
  2694. return false;
  2695. }
  2696. function KCmd(range) {
  2697. this.init(range);
  2698. }
  2699. _extend(KCmd, {
  2700. init : function(range) {
  2701. var self = this, doc = range.doc;
  2702. self.doc = doc;
  2703. self.win = _getWin(doc);
  2704. self.sel = _getSel(doc);
  2705. self.range = range;
  2706. },
  2707. selection : function(forceReset) {
  2708. var self = this, doc = self.doc, rng = _getRng(doc);
  2709. self.sel = _getSel(doc);
  2710. if (rng) {
  2711. self.range = _range(rng);
  2712. if (K(self.range.startContainer).name == 'html') {
  2713. self.range.selectNodeContents(doc.body).collapse(false);
  2714. }
  2715. return self;
  2716. }
  2717. if (forceReset) {
  2718. self.range.selectNodeContents(doc.body).collapse(false);
  2719. }
  2720. return self;
  2721. },
  2722. select : function(hasDummy) {
  2723. hasDummy = _undef(hasDummy, true);
  2724. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2725. sc = range.startContainer, so = range.startOffset,
  2726. ec = range.endContainer, eo = range.endOffset,
  2727. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2728. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2729. if (_IERANGE) {
  2730. var dummy = K('<span>&nbsp;</span>', doc);
  2731. range.insertNode(dummy[0]);
  2732. rng = doc.body.createTextRange();
  2733. try {
  2734. rng.moveToElementText(dummy[0]);
  2735. } catch(ex) {}
  2736. rng.collapse(false);
  2737. rng.select();
  2738. dummy.remove();
  2739. win.focus();
  2740. return self;
  2741. }
  2742. if (_WEBKIT) {
  2743. var children = sc.childNodes;
  2744. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2745. range.insertNode(doc.createTextNode('\u200B'));
  2746. hasU200b = true;
  2747. }
  2748. }
  2749. }
  2750. if (_IERANGE) {
  2751. try {
  2752. rng = range.get(true);
  2753. rng.select();
  2754. } catch(e) {}
  2755. } else {
  2756. if (hasU200b) {
  2757. range.collapse(false);
  2758. }
  2759. rng = range.get(true);
  2760. sel.removeAllRanges();
  2761. sel.addRange(rng);
  2762. if (doc !== document) {
  2763. var pos = K(rng.endContainer).pos();
  2764. win.scrollTo(pos.x, pos.y);
  2765. }
  2766. }
  2767. win.focus();
  2768. return self;
  2769. },
  2770. wrap : function(val) {
  2771. var self = this, doc = self.doc, range = self.range, wrapper;
  2772. wrapper = K(val, doc);
  2773. if (range.collapsed) {
  2774. range.shrink();
  2775. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2776. return self;
  2777. }
  2778. if (wrapper.isBlock()) {
  2779. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2780. while (child.first()) {
  2781. child = child.first();
  2782. }
  2783. child.append(range.extractContents());
  2784. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2785. return self;
  2786. }
  2787. range.enlarge();
  2788. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2789. K(ancestor).scan(function(node) {
  2790. if (!isStart && node == bookmark.start) {
  2791. isStart = true;
  2792. return;
  2793. }
  2794. if (isStart) {
  2795. if (node == bookmark.end) {
  2796. return false;
  2797. }
  2798. var knode = K(node);
  2799. if (_inPreElement(knode)) {
  2800. return;
  2801. }
  2802. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2803. var parent;
  2804. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2805. knode = parent;
  2806. }
  2807. _wrapNode(knode, wrapper);
  2808. }
  2809. }
  2810. });
  2811. range.moveToBookmark(bookmark);
  2812. return self;
  2813. },
  2814. split : function(isStart, map) {
  2815. var range = this.range, doc = range.doc;
  2816. var tempRange = range.cloneRange().collapse(isStart);
  2817. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2818. parent = node.nodeType == 3 ? node.parentNode : node,
  2819. needSplit = false, knode;
  2820. while (parent && parent.parentNode) {
  2821. knode = K(parent);
  2822. if (map) {
  2823. if (!knode.isStyle()) {
  2824. break;
  2825. }
  2826. if (!_hasAttrOrCss(knode, map)) {
  2827. break;
  2828. }
  2829. } else {
  2830. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2831. break;
  2832. }
  2833. }
  2834. needSplit = true;
  2835. parent = parent.parentNode;
  2836. }
  2837. if (needSplit) {
  2838. var dummy = doc.createElement('span');
  2839. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2840. if (isStart) {
  2841. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2842. } else {
  2843. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2844. }
  2845. var frag = tempRange.extractContents(),
  2846. first = frag.firstChild, last = frag.lastChild;
  2847. if (isStart) {
  2848. tempRange.insertNode(frag);
  2849. range.setStartAfter(last).setEndBefore(dummy);
  2850. } else {
  2851. parent.appendChild(frag);
  2852. range.setStartBefore(dummy).setEndBefore(first);
  2853. }
  2854. var dummyParent = dummy.parentNode;
  2855. if (dummyParent == range.endContainer) {
  2856. var prev = K(dummy).prev(), next = K(dummy).next();
  2857. if (prev && next && prev.type == 3 && next.type == 3) {
  2858. range.setEnd(prev[0], prev[0].nodeValue.length);
  2859. } else if (!isStart) {
  2860. range.setEnd(range.endContainer, range.endOffset - 1);
  2861. }
  2862. }
  2863. dummyParent.removeChild(dummy);
  2864. }
  2865. return this;
  2866. },
  2867. remove : function(map) {
  2868. var self = this, doc = self.doc, range = self.range;
  2869. range.enlarge();
  2870. if (range.startOffset === 0) {
  2871. var ksc = K(range.startContainer), parent;
  2872. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2873. ksc = parent;
  2874. }
  2875. range.setStart(ksc[0], 0);
  2876. ksc = K(range.startContainer);
  2877. if (ksc.isBlock()) {
  2878. _removeAttrOrCss(ksc, map);
  2879. }
  2880. var kscp = ksc.parent();
  2881. if (kscp && kscp.isBlock()) {
  2882. _removeAttrOrCss(kscp, map);
  2883. }
  2884. }
  2885. var sc, so;
  2886. if (range.collapsed) {
  2887. self.split(true, map);
  2888. sc = range.startContainer;
  2889. so = range.startOffset;
  2890. if (so > 0) {
  2891. var sb = K(sc.childNodes[so - 1]);
  2892. if (sb && _isEmptyNode(sb)) {
  2893. sb.remove();
  2894. range.setStart(sc, so - 1);
  2895. }
  2896. }
  2897. var sa = K(sc.childNodes[so]);
  2898. if (sa && _isEmptyNode(sa)) {
  2899. sa.remove();
  2900. }
  2901. if (_isEmptyNode(sc)) {
  2902. range.startBefore(sc);
  2903. sc.remove();
  2904. }
  2905. range.collapse(true);
  2906. return self;
  2907. }
  2908. self.split(true, map);
  2909. self.split(false, map);
  2910. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2911. range.cloneRange().collapse(false).insertNode(endDummy);
  2912. range.cloneRange().collapse(true).insertNode(startDummy);
  2913. var nodeList = [], cmpStart = false;
  2914. K(range.commonAncestor()).scan(function(node) {
  2915. if (!cmpStart && node == startDummy) {
  2916. cmpStart = true;
  2917. return;
  2918. }
  2919. if (node == endDummy) {
  2920. return false;
  2921. }
  2922. if (cmpStart) {
  2923. nodeList.push(node);
  2924. }
  2925. });
  2926. K(startDummy).remove();
  2927. K(endDummy).remove();
  2928. sc = range.startContainer;
  2929. so = range.startOffset;
  2930. var ec = range.endContainer, eo = range.endOffset;
  2931. if (so > 0) {
  2932. var startBefore = K(sc.childNodes[so - 1]);
  2933. if (startBefore && _isEmptyNode(startBefore)) {
  2934. startBefore.remove();
  2935. range.setStart(sc, so - 1);
  2936. if (sc == ec) {
  2937. range.setEnd(ec, eo - 1);
  2938. }
  2939. }
  2940. var startAfter = K(sc.childNodes[so]);
  2941. if (startAfter && _isEmptyNode(startAfter)) {
  2942. startAfter.remove();
  2943. if (sc == ec) {
  2944. range.setEnd(ec, eo - 1);
  2945. }
  2946. }
  2947. }
  2948. var endAfter = K(ec.childNodes[range.endOffset]);
  2949. if (endAfter && _isEmptyNode(endAfter)) {
  2950. endAfter.remove();
  2951. }
  2952. var bookmark = range.createBookmark(true);
  2953. _each(nodeList, function(i, node) {
  2954. _removeAttrOrCss(K(node), map);
  2955. });
  2956. range.moveToBookmark(bookmark);
  2957. return self;
  2958. },
  2959. commonNode : function(map) {
  2960. var range = this.range;
  2961. var ec = range.endContainer, eo = range.endOffset,
  2962. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2963. function find(node) {
  2964. var child = node, parent = node;
  2965. while (parent) {
  2966. if (_hasAttrOrCss(K(parent), map)) {
  2967. return K(parent);
  2968. }
  2969. parent = parent.parentNode;
  2970. }
  2971. while (child && (child = child.lastChild)) {
  2972. if (_hasAttrOrCss(K(child), map)) {
  2973. return K(child);
  2974. }
  2975. }
  2976. return null;
  2977. }
  2978. var cNode = find(node);
  2979. if (cNode) {
  2980. return cNode;
  2981. }
  2982. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2983. var prev = K(node).prev();
  2984. if (prev) {
  2985. return find(prev);
  2986. }
  2987. }
  2988. return null;
  2989. },
  2990. commonAncestor : function(tagName) {
  2991. var range = this.range,
  2992. sc = range.startContainer, so = range.startOffset,
  2993. ec = range.endContainer, eo = range.endOffset,
  2994. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  2995. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2996. function find(node) {
  2997. while (node) {
  2998. if (node.nodeType == 1) {
  2999. if (node.tagName.toLowerCase() === tagName) {
  3000. return node;
  3001. }
  3002. }
  3003. node = node.parentNode;
  3004. }
  3005. return null;
  3006. }
  3007. var start = find(startNode), end = find(endNode);
  3008. if (start && end && start === end) {
  3009. return K(start);
  3010. }
  3011. return null;
  3012. },
  3013. state : function(key) {
  3014. var self = this, doc = self.doc, bool = false;
  3015. try {
  3016. bool = doc.queryCommandState(key);
  3017. } catch (e) {}
  3018. return bool;
  3019. },
  3020. val : function(key) {
  3021. var self = this, doc = self.doc, range = self.range;
  3022. function lc(val) {
  3023. return val.toLowerCase();
  3024. }
  3025. key = lc(key);
  3026. var val = '', knode;
  3027. if (key === 'fontfamily' || key === 'fontname') {
  3028. val = _nativeCommandValue(doc, 'fontname');
  3029. val = val.replace(/['"]/g, '');
  3030. return lc(val);
  3031. }
  3032. if (key === 'formatblock') {
  3033. val = _nativeCommandValue(doc, key);
  3034. if (val === '') {
  3035. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3036. if (knode) {
  3037. val = knode.name;
  3038. }
  3039. }
  3040. if (val === 'Normal') {
  3041. val = 'p';
  3042. }
  3043. return lc(val);
  3044. }
  3045. if (key === 'fontsize') {
  3046. knode = self.commonNode({'*' : '.font-size'});
  3047. if (knode) {
  3048. val = knode.css('font-size');
  3049. }
  3050. return lc(val);
  3051. }
  3052. if (key === 'forecolor') {
  3053. knode = self.commonNode({'*' : '.color'});
  3054. if (knode) {
  3055. val = knode.css('color');
  3056. }
  3057. val = _toHex(val);
  3058. if (val === '') {
  3059. val = 'default';
  3060. }
  3061. return lc(val);
  3062. }
  3063. if (key === 'hilitecolor') {
  3064. knode = self.commonNode({'*' : '.background-color'});
  3065. if (knode) {
  3066. val = knode.css('background-color');
  3067. }
  3068. val = _toHex(val);
  3069. if (val === '') {
  3070. val = 'default';
  3071. }
  3072. return lc(val);
  3073. }
  3074. return val;
  3075. },
  3076. toggle : function(wrapper, map) {
  3077. var self = this;
  3078. if (self.commonNode(map)) {
  3079. self.remove(map);
  3080. } else {
  3081. self.wrap(wrapper);
  3082. }
  3083. return self.select();
  3084. },
  3085. bold : function() {
  3086. return this.toggle('<strong></strong>', {
  3087. span : '.font-weight=bold',
  3088. strong : '*',
  3089. b : '*'
  3090. });
  3091. },
  3092. italic : function() {
  3093. return this.toggle('<em></em>', {
  3094. span : '.font-style=italic',
  3095. em : '*',
  3096. i : '*'
  3097. });
  3098. },
  3099. underline : function() {
  3100. return this.toggle('<u></u>', {
  3101. span : '.text-decoration=underline',
  3102. u : '*'
  3103. });
  3104. },
  3105. strikethrough : function() {
  3106. return this.toggle('<s></s>', {
  3107. span : '.text-decoration=line-through',
  3108. s : '*'
  3109. });
  3110. },
  3111. forecolor : function(val) {
  3112. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3113. },
  3114. hilitecolor : function(val) {
  3115. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3116. },
  3117. fontsize : function(val) {
  3118. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3119. },
  3120. fontname : function(val) {
  3121. return this.fontfamily(val);
  3122. },
  3123. fontfamily : function(val) {
  3124. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3125. },
  3126. removeformat : function() {
  3127. var map = {
  3128. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3129. },
  3130. tags = _STYLE_TAG_MAP;
  3131. _each(tags, function(key, val) {
  3132. map[key] = '*';
  3133. });
  3134. this.remove(map);
  3135. return this.select();
  3136. },
  3137. inserthtml : function(val, quickMode) {
  3138. var self = this, range = self.range;
  3139. if (val === '') {
  3140. return self;
  3141. }
  3142. function pasteHtml(range, val) {
  3143. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3144. var rng = range.get();
  3145. if (rng.item) {
  3146. rng.item(0).outerHTML = val;
  3147. } else {
  3148. rng.pasteHTML(val);
  3149. }
  3150. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3151. temp.parentNode.removeChild(temp);
  3152. var newRange = _toRange(rng);
  3153. range.setEnd(newRange.endContainer, newRange.endOffset);
  3154. range.collapse(false);
  3155. self.select(false);
  3156. }
  3157. function insertHtml(range, val) {
  3158. var doc = range.doc,
  3159. frag = doc.createDocumentFragment();
  3160. K('@' + val, doc).each(function() {
  3161. frag.appendChild(this);
  3162. });
  3163. range.deleteContents();
  3164. range.insertNode(frag);
  3165. range.collapse(false);
  3166. self.select(false);
  3167. }
  3168. if (_IERANGE && quickMode) {
  3169. try {
  3170. pasteHtml(range, val);
  3171. } catch(e) {
  3172. insertHtml(range, val);
  3173. }
  3174. return self;
  3175. }
  3176. insertHtml(range, val);
  3177. return self;
  3178. },
  3179. hr : function() {
  3180. return this.inserthtml('<hr />');
  3181. },
  3182. print : function() {
  3183. this.win.print();
  3184. return this;
  3185. },
  3186. insertimage : function(url, title, width, height, border, align) {
  3187. title = _undef(title, '');
  3188. border = _undef(border, 0);
  3189. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3190. if (width) {
  3191. html += 'width="' + _escape(width) + '" ';
  3192. }
  3193. if (height) {
  3194. html += 'height="' + _escape(height) + '" ';
  3195. }
  3196. if (title) {
  3197. html += 'title="' + _escape(title) + '" ';
  3198. }
  3199. if (align) {
  3200. html += 'align="' + _escape(align) + '" ';
  3201. }
  3202. html += 'alt="' + _escape(title) + '" ';
  3203. html += '/>';
  3204. return this.inserthtml(html);
  3205. },
  3206. createlink : function(url, type) {
  3207. var self = this, doc = self.doc, range = self.range;
  3208. self.select();
  3209. var a = self.commonNode({ a : '*' });
  3210. if (a && !range.isControl()) {
  3211. range.selectNode(a.get());
  3212. self.select();
  3213. }
  3214. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3215. if (type) {
  3216. html += ' target="' + _escape(type) + '"';
  3217. }
  3218. if (range.collapsed) {
  3219. html += '>' + _escape(url) + '</a>';
  3220. return self.inserthtml(html);
  3221. }
  3222. if (range.isControl()) {
  3223. var node = K(range.startContainer.childNodes[range.startOffset]);
  3224. html += '></a>';
  3225. node.after(K(html, doc));
  3226. node.next().append(node);
  3227. range.selectNode(node[0]);
  3228. return self.select();
  3229. }
  3230. function setAttr(node, url, type) {
  3231. K(node).attr('href', url).attr('data-ke-src', url);
  3232. if (type) {
  3233. K(node).attr('target', type);
  3234. } else {
  3235. K(node).removeAttr('target');
  3236. }
  3237. }
  3238. var sc = range.startContainer, so = range.startOffset,
  3239. ec = range.endContainer, eo = range.endOffset;
  3240. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3241. var child = sc.childNodes[so];
  3242. if (child.nodeName.toLowerCase() == 'a') {
  3243. setAttr(child, url, type);
  3244. return self;
  3245. }
  3246. }
  3247. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3248. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3249. setAttr(this, url, type);
  3250. });
  3251. return self;
  3252. },
  3253. unlink : function() {
  3254. var self = this, doc = self.doc, range = self.range;
  3255. self.select();
  3256. if (range.collapsed) {
  3257. var a = self.commonNode({ a : '*' });
  3258. if (a) {
  3259. range.selectNode(a.get());
  3260. self.select();
  3261. }
  3262. _nativeCommand(doc, 'unlink', null);
  3263. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3264. var parent = K(range.startContainer).parent();
  3265. if (parent.name === 'a') {
  3266. parent.remove(true);
  3267. }
  3268. }
  3269. } else {
  3270. _nativeCommand(doc, 'unlink', null);
  3271. }
  3272. return self;
  3273. }
  3274. });
  3275. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3276. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3277. KCmd.prototype[name] = function(val) {
  3278. var self = this;
  3279. self.select();
  3280. _nativeCommand(self.doc, name, val);
  3281. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3282. self.selection();
  3283. }
  3284. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3285. self.selection();
  3286. }
  3287. return self;
  3288. };
  3289. });
  3290. _each('cut,copy,paste'.split(','), function(i, name) {
  3291. KCmd.prototype[name] = function() {
  3292. var self = this;
  3293. if (!self.doc.queryCommandSupported(name)) {
  3294. throw 'not supported';
  3295. }
  3296. self.select();
  3297. _nativeCommand(self.doc, name, null);
  3298. return self;
  3299. };
  3300. });
  3301. function _cmd(mixed) {
  3302. if (mixed.nodeName) {
  3303. var doc = _getDoc(mixed);
  3304. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3305. }
  3306. return new KCmd(mixed);
  3307. }
  3308. K.CmdClass = KCmd;
  3309. K.cmd = _cmd;
  3310. function _drag(options) {
  3311. var moveEl = options.moveEl,
  3312. moveFn = options.moveFn,
  3313. clickEl = options.clickEl || moveEl,
  3314. beforeDrag = options.beforeDrag,
  3315. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3316. var docs = [document];
  3317. if (iframeFix) {
  3318. K('iframe').each(function() {
  3319. var src = _formatUrl(this.src || '', 'absolute');
  3320. if (/^https?:\/\//.test(src)) {
  3321. return;
  3322. }
  3323. var doc;
  3324. try {
  3325. doc = _iframeDoc(this);
  3326. } catch(e) {}
  3327. if (doc) {
  3328. var pos = K(this).pos();
  3329. K(doc).data('pos-x', pos.x);
  3330. K(doc).data('pos-y', pos.y);
  3331. docs.push(doc);
  3332. }
  3333. });
  3334. }
  3335. clickEl.mousedown(function(e) {
  3336. if(e.button !== 0 && e.button !== 1) {
  3337. return;
  3338. }
  3339. e.stopPropagation();
  3340. var self = clickEl.get(),
  3341. x = _removeUnit(moveEl.css('left')),
  3342. y = _removeUnit(moveEl.css('top')),
  3343. width = moveEl.width(),
  3344. height = moveEl.height(),
  3345. pageX = e.pageX,
  3346. pageY = e.pageY;
  3347. if (beforeDrag) {
  3348. beforeDrag();
  3349. }
  3350. function moveListener(e) {
  3351. e.preventDefault();
  3352. var kdoc = K(_getDoc(e.target));
  3353. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3354. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3355. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3356. }
  3357. function selectListener(e) {
  3358. e.preventDefault();
  3359. }
  3360. function upListener(e) {
  3361. e.preventDefault();
  3362. K(docs).unbind('mousemove', moveListener)
  3363. .unbind('mouseup', upListener)
  3364. .unbind('selectstart', selectListener);
  3365. if (self.releaseCapture) {
  3366. self.releaseCapture();
  3367. }
  3368. }
  3369. K(docs).mousemove(moveListener)
  3370. .mouseup(upListener)
  3371. .bind('selectstart', selectListener);
  3372. if (self.setCapture) {
  3373. self.setCapture();
  3374. }
  3375. });
  3376. }
  3377. function KWidget(options) {
  3378. this.init(options);
  3379. }
  3380. _extend(KWidget, {
  3381. init : function(options) {
  3382. var self = this;
  3383. self.name = options.name || '';
  3384. self.doc = options.doc || document;
  3385. self.win = _getWin(self.doc);
  3386. self.x = _addUnit(options.x);
  3387. self.y = _addUnit(options.y);
  3388. self.z = options.z;
  3389. self.width = _addUnit(options.width);
  3390. self.height = _addUnit(options.height);
  3391. self.div = K('<div style="display:block;"></div>');
  3392. self.options = options;
  3393. self._alignEl = options.alignEl;
  3394. if (self.width) {
  3395. self.div.css('width', self.width);
  3396. }
  3397. if (self.height) {
  3398. self.div.css('height', self.height);
  3399. }
  3400. if (self.z) {
  3401. self.div.css({
  3402. position : 'absolute',
  3403. left : self.x,
  3404. top : self.y,
  3405. 'z-index' : self.z
  3406. });
  3407. }
  3408. if (self.z && (self.x === undefined || self.y === undefined)) {
  3409. self.autoPos(self.width, self.height);
  3410. }
  3411. if (options.cls) {
  3412. self.div.addClass(options.cls);
  3413. }
  3414. if (options.shadowMode) {
  3415. self.div.addClass('ke-shadow');
  3416. }
  3417. if (options.css) {
  3418. self.div.css(options.css);
  3419. }
  3420. if (options.src) {
  3421. K(options.src).replaceWith(self.div);
  3422. } else {
  3423. K(self.doc.body).append(self.div);
  3424. }
  3425. if (options.html) {
  3426. self.div.html(options.html);
  3427. }
  3428. if (options.autoScroll) {
  3429. if (_IE && _V < 7 || _QUIRKS) {
  3430. var scrollPos = _getScrollPos();
  3431. K(self.win).bind('scroll', function(e) {
  3432. var pos = _getScrollPos(),
  3433. diffX = pos.x - scrollPos.x,
  3434. diffY = pos.y - scrollPos.y;
  3435. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3436. });
  3437. } else {
  3438. self.div.css('position', 'fixed');
  3439. }
  3440. }
  3441. },
  3442. pos : function(x, y, updateProp) {
  3443. var self = this;
  3444. updateProp = _undef(updateProp, true);
  3445. if (x !== null) {
  3446. x = x < 0 ? 0 : _addUnit(x);
  3447. self.div.css('left', x);
  3448. if (updateProp) {
  3449. self.x = x;
  3450. }
  3451. }
  3452. if (y !== null) {
  3453. y = y < 0 ? 0 : _addUnit(y);
  3454. self.div.css('top', y);
  3455. if (updateProp) {
  3456. self.y = y;
  3457. }
  3458. }
  3459. return self;
  3460. },
  3461. autoPos : function(width, height) {
  3462. var self = this,
  3463. w = _removeUnit(width) || 0,
  3464. h = _removeUnit(height) || 0,
  3465. scrollPos = _getScrollPos();
  3466. if (self._alignEl) {
  3467. var knode = K(self._alignEl),
  3468. pos = knode.pos(),
  3469. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3470. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3471. x = diffX < 0 ? pos.x : pos.x + diffX;
  3472. y = diffY < 0 ? pos.y : pos.y + diffY;
  3473. } else {
  3474. var docEl = _docElement(self.doc);
  3475. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3476. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3477. }
  3478. if (!(_IE && _V < 7 || _QUIRKS)) {
  3479. x -= scrollPos.x;
  3480. y -= scrollPos.y;
  3481. }
  3482. return self.pos(x, y);
  3483. },
  3484. remove : function() {
  3485. var self = this;
  3486. if (_IE && _V < 7 || _QUIRKS) {
  3487. K(self.win).unbind('scroll');
  3488. }
  3489. self.div.remove();
  3490. _each(self, function(i) {
  3491. self[i] = null;
  3492. });
  3493. return this;
  3494. },
  3495. show : function() {
  3496. this.div.show();
  3497. return this;
  3498. },
  3499. hide : function() {
  3500. this.div.hide();
  3501. return this;
  3502. },
  3503. draggable : function(options) {
  3504. var self = this;
  3505. options = options || {};
  3506. options.moveEl = self.div;
  3507. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3508. if ((x = x + diffX) < 0) {
  3509. x = 0;
  3510. }
  3511. if ((y = y + diffY) < 0) {
  3512. y = 0;
  3513. }
  3514. self.pos(x, y);
  3515. };
  3516. _drag(options);
  3517. return self;
  3518. }
  3519. });
  3520. function _widget(options) {
  3521. return new KWidget(options);
  3522. }
  3523. K.WidgetClass = KWidget;
  3524. K.widget = _widget;
  3525. function _iframeDoc(iframe) {
  3526. iframe = _get(iframe);
  3527. return iframe.contentDocument || iframe.contentWindow.document;
  3528. }
  3529. var html, _direction = '';
  3530. if ((html = document.getElementsByTagName('html'))) {
  3531. _direction = html[0].dir;
  3532. }
  3533. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3534. var arr = [
  3535. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3536. '<head><meta charset="utf-8" /><title></title>',
  3537. '<style>',
  3538. 'html {margin:0;padding:0;}',
  3539. 'body {margin:0;padding:5px;}',
  3540. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3541. 'body, p, div {word-wrap: break-word;}',
  3542. 'p {margin:5px 0;}',
  3543. 'table {border-collapse:collapse;}',
  3544. 'img {border:0; max-width:500px}',
  3545. 'noscript {display:none;}',
  3546. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3547. 'img.ke-flash {',
  3548. ' border:1px solid #AAA;',
  3549. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3550. ' background-position:center center;',
  3551. ' background-repeat:no-repeat;',
  3552. ' width:100px;',
  3553. ' height:100px;',
  3554. '}',
  3555. 'img.ke-rm {',
  3556. ' border:1px solid #AAA;',
  3557. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3558. ' background-position:center center;',
  3559. ' background-repeat:no-repeat;',
  3560. ' width:100px;',
  3561. ' height:100px;',
  3562. '}',
  3563. 'img.ke-media {',
  3564. ' border:1px solid #AAA;',
  3565. ' background-image:url(' + themesPath + 'common/media.gif);',
  3566. ' background-position:center center;',
  3567. ' background-repeat:no-repeat;',
  3568. ' width:100px;',
  3569. ' height:100px;',
  3570. '}',
  3571. 'img.ke-anchor {',
  3572. ' border:1px dashed #666;',
  3573. ' width:16px;',
  3574. ' height:16px;',
  3575. '}',
  3576. '.ke-script, .ke-noscript, .ke-display-none {',
  3577. ' display:none;',
  3578. ' font-size:0;',
  3579. ' width:0;',
  3580. ' height:0;',
  3581. '}',
  3582. '.ke-pagebreak {',
  3583. ' border:1px dotted #AAA;',
  3584. ' font-size:0;',
  3585. ' height:2px;',
  3586. '}',
  3587. '</style>'
  3588. ];
  3589. if (!_isArray(cssPath)) {
  3590. cssPath = [cssPath];
  3591. }
  3592. _each(cssPath, function(i, path) {
  3593. if (path) {
  3594. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3595. }
  3596. });
  3597. if (cssData) {
  3598. arr.push('<style>' + cssData + '</style>');
  3599. }
  3600. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3601. return arr.join('\n');
  3602. }
  3603. function _elementVal(knode, val) {
  3604. if (knode.hasVal()) {
  3605. if (val === undefined) {
  3606. var html = knode.val();
  3607. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3608. return html;
  3609. }
  3610. return knode.val(val);
  3611. }
  3612. return knode.html(val);
  3613. }
  3614. function KEdit(options) {
  3615. this.init(options);
  3616. }
  3617. _extend(KEdit, KWidget, {
  3618. init : function(options) {
  3619. var self = this;
  3620. KEdit.parent.init.call(self, options);
  3621. self.srcElement = K(options.srcElement);
  3622. self.div.addClass('ke-edit');
  3623. self.designMode = _undef(options.designMode, true);
  3624. self.beforeGetHtml = options.beforeGetHtml;
  3625. self.beforeSetHtml = options.beforeSetHtml;
  3626. self.afterSetHtml = options.afterSetHtml;
  3627. var themesPath = _undef(options.themesPath, ''),
  3628. bodyClass = options.bodyClass,
  3629. cssPath = options.cssPath,
  3630. cssData = options.cssData,
  3631. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3632. srcScript = ('document.open();' +
  3633. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3634. 'document.close();'),
  3635. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3636. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3637. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3638. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3639. self.iframe.attr('tabindex', self.tabIndex);
  3640. self.textarea.attr('tabindex', self.tabIndex);
  3641. if (self.width) {
  3642. self.setWidth(self.width);
  3643. }
  3644. if (self.height) {
  3645. self.setHeight(self.height);
  3646. }
  3647. if (self.designMode) {
  3648. self.textarea.hide();
  3649. } else {
  3650. self.iframe.hide();
  3651. }
  3652. function ready() {
  3653. var doc = _iframeDoc(self.iframe);
  3654. doc.open();
  3655. if (isDocumentDomain) {
  3656. doc.domain = document.domain;
  3657. }
  3658. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3659. doc.close();
  3660. self.win = self.iframe[0].contentWindow;
  3661. self.doc = doc;
  3662. var cmd = _cmd(doc);
  3663. self.afterChange(function(e) {
  3664. cmd.selection();
  3665. });
  3666. if (_WEBKIT) {
  3667. K(doc).click(function(e) {
  3668. if (K(e.target).name === 'img') {
  3669. cmd.selection(true);
  3670. cmd.range.selectNode(e.target);
  3671. cmd.select();
  3672. }
  3673. });
  3674. }
  3675. if (_IE) {
  3676. self._mousedownHandler = function() {
  3677. var newRange = cmd.range.cloneRange();
  3678. newRange.shrink();
  3679. if (newRange.isControl()) {
  3680. self.blur();
  3681. }
  3682. };
  3683. K(document).mousedown(self._mousedownHandler);
  3684. K(doc).keydown(function(e) {
  3685. if (e.which == 8) {
  3686. cmd.selection();
  3687. var rng = cmd.range;
  3688. if (rng.isControl()) {
  3689. rng.collapse(true);
  3690. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3691. e.preventDefault();
  3692. }
  3693. }
  3694. });
  3695. }
  3696. self.cmd = cmd;
  3697. self.html(_elementVal(self.srcElement));
  3698. if (_IE) {
  3699. doc.body.disabled = true;
  3700. doc.body.contentEditable = true;
  3701. doc.body.removeAttribute('disabled');
  3702. } else {
  3703. doc.designMode = 'on';
  3704. }
  3705. if (options.afterCreate) {
  3706. options.afterCreate.call(self);
  3707. }
  3708. }
  3709. if (isDocumentDomain) {
  3710. self.iframe.bind('load', function(e) {
  3711. self.iframe.unbind('load');
  3712. if (_IE) {
  3713. ready();
  3714. } else {
  3715. setTimeout(ready, 0);
  3716. }
  3717. });
  3718. }
  3719. self.div.append(self.iframe);
  3720. self.div.append(self.textarea);
  3721. self.srcElement.hide();
  3722. !isDocumentDomain && ready();
  3723. },
  3724. setWidth : function(val) {
  3725. var self = this;
  3726. val = _addUnit(val);
  3727. self.width = val;
  3728. self.div.css('width', val);
  3729. return self;
  3730. },
  3731. setHeight : function(val) {
  3732. var self = this;
  3733. val = _addUnit(val);
  3734. self.height = val;
  3735. self.div.css('height', val);
  3736. self.iframe.css('height', val);
  3737. if ((_IE && _V < 8) || _QUIRKS) {
  3738. val = _addUnit(_removeUnit(val) - 2);
  3739. }
  3740. self.textarea.css('height', val);
  3741. return self;
  3742. },
  3743. remove : function() {
  3744. var self = this, doc = self.doc;
  3745. K(doc.body).unbind();
  3746. K(doc).unbind();
  3747. K(self.win).unbind();
  3748. if (self._mousedownHandler) {
  3749. K(document).unbind('mousedown', self._mousedownHandler);
  3750. }
  3751. _elementVal(self.srcElement, self.html());
  3752. self.srcElement.show();
  3753. self.iframe.unbind();
  3754. self.textarea.unbind();
  3755. KEdit.parent.remove.call(self);
  3756. },
  3757. html : function(val, isFull) {
  3758. var self = this, doc = self.doc;
  3759. if (self.designMode) {
  3760. var body = doc.body;
  3761. if (val === undefined) {
  3762. if (isFull) {
  3763. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3764. } else {
  3765. val = body.innerHTML;
  3766. }
  3767. if (self.beforeGetHtml) {
  3768. val = self.beforeGetHtml(val);
  3769. }
  3770. if (_GECKO && val == '<br />') {
  3771. val = '';
  3772. }
  3773. return val;
  3774. }
  3775. if (self.beforeSetHtml) {
  3776. val = self.beforeSetHtml(val);
  3777. }
  3778. if (_IE && _V >= 9) {
  3779. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3780. }
  3781. K(body).html(val);
  3782. if (self.afterSetHtml) {
  3783. self.afterSetHtml();
  3784. }
  3785. return self;
  3786. }
  3787. if (val === undefined) {
  3788. return self.textarea.val();
  3789. }
  3790. self.textarea.val(val);
  3791. return self;
  3792. },
  3793. design : function(bool) {
  3794. var self = this, val;
  3795. if (bool === undefined ? !self.designMode : bool) {
  3796. if (!self.designMode) {
  3797. val = self.html();
  3798. self.designMode = true;
  3799. self.textarea.hide();
  3800. self.html(val);
  3801. var iframe = self.iframe;
  3802. var height = _removeUnit(self.height);
  3803. iframe.height(height - 2);
  3804. iframe.show();
  3805. setTimeout(function() {
  3806. iframe.height(height);
  3807. }, 0);
  3808. }
  3809. } else {
  3810. if (self.designMode) {
  3811. val = self.html();
  3812. self.designMode = false;
  3813. self.html(val);
  3814. self.iframe.hide();
  3815. self.textarea.show();
  3816. }
  3817. }
  3818. return self.focus();
  3819. },
  3820. focus : function() {
  3821. var self = this;
  3822. self.designMode ? self.win.focus() : self.textarea[0].focus();
  3823. return self;
  3824. },
  3825. blur : function() {
  3826. var self = this;
  3827. if (_IE) {
  3828. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3829. self.div.append(input);
  3830. input[0].focus();
  3831. input.remove();
  3832. } else {
  3833. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3834. }
  3835. return self;
  3836. },
  3837. afterChange : function(fn) {
  3838. var self = this, doc = self.doc, body = doc.body;
  3839. K(doc).keyup(function(e) {
  3840. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3841. fn(e);
  3842. }
  3843. });
  3844. K(doc).mouseup(fn).contextmenu(fn);
  3845. K(self.win).blur(fn);
  3846. function timeoutHandler(e) {
  3847. setTimeout(function() {
  3848. fn(e);
  3849. }, 1);
  3850. }
  3851. K(body).bind('paste', timeoutHandler);
  3852. K(body).bind('cut', timeoutHandler);
  3853. return self;
  3854. }
  3855. });
  3856. function _edit(options) {
  3857. return new KEdit(options);
  3858. }
  3859. K.EditClass = KEdit;
  3860. K.edit = _edit;
  3861. K.iframeDoc = _iframeDoc;
  3862. function _selectToolbar(name, fn) {
  3863. var self = this,
  3864. knode = self.get(name);
  3865. if (knode) {
  3866. if (knode.hasClass('ke-disabled')) {
  3867. return;
  3868. }
  3869. fn(knode);
  3870. }
  3871. }
  3872. function KToolbar(options) {
  3873. this.init(options);
  3874. }
  3875. _extend(KToolbar, KWidget, {
  3876. init : function(options) {
  3877. var self = this;
  3878. KToolbar.parent.init.call(self, options);
  3879. self.disableMode = _undef(options.disableMode, false);
  3880. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3881. self._itemMap = {};
  3882. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3883. e.preventDefault();
  3884. }).attr('unselectable', 'on');
  3885. function find(target) {
  3886. var knode = K(target);
  3887. if (knode.hasClass('ke-outline')) {
  3888. return knode;
  3889. }
  3890. if (knode.hasClass('ke-toolbar-icon')) {
  3891. return knode.parent();
  3892. }
  3893. }
  3894. function hover(e, method) {
  3895. var knode = find(e.target);
  3896. if (knode) {
  3897. if (knode.hasClass('ke-disabled')) {
  3898. return;
  3899. }
  3900. if (knode.hasClass('ke-selected')) {
  3901. return;
  3902. }
  3903. knode[method]('ke-on');
  3904. }
  3905. }
  3906. self.div.mouseover(function(e) {
  3907. hover(e, 'addClass');
  3908. })
  3909. .mouseout(function(e) {
  3910. hover(e, 'removeClass');
  3911. })
  3912. .click(function(e) {
  3913. var knode = find(e.target);
  3914. if (knode) {
  3915. if (knode.hasClass('ke-disabled')) {
  3916. return;
  3917. }
  3918. self.options.click.call(this, e, knode.attr('data-name'));
  3919. }
  3920. });
  3921. },
  3922. get : function(name) {
  3923. if (this._itemMap[name]) {
  3924. return this._itemMap[name];
  3925. }
  3926. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3927. },
  3928. select : function(name) {
  3929. _selectToolbar.call(this, name, function(knode) {
  3930. knode.addClass('ke-selected');
  3931. });
  3932. return self;
  3933. },
  3934. unselect : function(name) {
  3935. _selectToolbar.call(this, name, function(knode) {
  3936. knode.removeClass('ke-selected').removeClass('ke-on');
  3937. });
  3938. return self;
  3939. },
  3940. enable : function(name) {
  3941. var self = this,
  3942. knode = name.get ? name : self.get(name);
  3943. if (knode) {
  3944. knode.removeClass('ke-disabled');
  3945. knode.opacity(1);
  3946. }
  3947. return self;
  3948. },
  3949. disable : function(name) {
  3950. var self = this,
  3951. knode = name.get ? name : self.get(name);
  3952. if (knode) {
  3953. knode.removeClass('ke-selected').addClass('ke-disabled');
  3954. knode.opacity(0.5);
  3955. }
  3956. return self;
  3957. },
  3958. disableAll : function(bool, noDisableItems) {
  3959. var self = this, map = self.noDisableItemMap, item;
  3960. if (noDisableItems) {
  3961. map = _toMap(noDisableItems);
  3962. }
  3963. if (bool === undefined ? !self.disableMode : bool) {
  3964. K('span.ke-outline', self.div).each(function() {
  3965. var knode = K(this),
  3966. name = knode[0].getAttribute('data-name', 2);
  3967. if (!map[name]) {
  3968. self.disable(knode);
  3969. }
  3970. });
  3971. self.disableMode = true;
  3972. } else {
  3973. K('span.ke-outline', self.div).each(function() {
  3974. var knode = K(this),
  3975. name = knode[0].getAttribute('data-name', 2);
  3976. if (!map[name]) {
  3977. self.enable(knode);
  3978. }
  3979. });
  3980. self.disableMode = false;
  3981. }
  3982. return self;
  3983. }
  3984. });
  3985. function _toolbar(options) {
  3986. return new KToolbar(options);
  3987. }
  3988. K.ToolbarClass = KToolbar;
  3989. K.toolbar = _toolbar;
  3990. function KMenu(options) {
  3991. this.init(options);
  3992. }
  3993. _extend(KMenu, KWidget, {
  3994. init : function(options) {
  3995. var self = this;
  3996. options.z = options.z || 811213;
  3997. KMenu.parent.init.call(self, options);
  3998. self.centerLineMode = _undef(options.centerLineMode, true);
  3999. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  4000. e.stopPropagation();
  4001. }).attr('unselectable', 'on');
  4002. },
  4003. addItem : function(item) {
  4004. var self = this;
  4005. if (item.title === '-') {
  4006. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4007. return;
  4008. }
  4009. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4010. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4011. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4012. height = _addUnit(item.height),
  4013. iconClass = _undef(item.iconClass, '');
  4014. self.div.append(itemDiv);
  4015. if (height) {
  4016. itemDiv.css('height', height);
  4017. rightDiv.css('line-height', height);
  4018. }
  4019. var centerDiv;
  4020. if (self.centerLineMode) {
  4021. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4022. if (height) {
  4023. centerDiv.css('height', height);
  4024. }
  4025. }
  4026. itemDiv.mouseover(function(e) {
  4027. K(this).addClass('ke-menu-item-on');
  4028. if (centerDiv) {
  4029. centerDiv.addClass('ke-menu-item-center-on');
  4030. }
  4031. })
  4032. .mouseout(function(e) {
  4033. K(this).removeClass('ke-menu-item-on');
  4034. if (centerDiv) {
  4035. centerDiv.removeClass('ke-menu-item-center-on');
  4036. }
  4037. })
  4038. .click(function(e) {
  4039. item.click.call(K(this));
  4040. e.stopPropagation();
  4041. })
  4042. .append(leftDiv);
  4043. if (centerDiv) {
  4044. itemDiv.append(centerDiv);
  4045. }
  4046. itemDiv.append(rightDiv);
  4047. if (item.checked) {
  4048. iconClass = 'ke-icon-checked';
  4049. }
  4050. if (iconClass !== '') {
  4051. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4052. }
  4053. rightDiv.html(item.title);
  4054. return self;
  4055. },
  4056. remove : function() {
  4057. var self = this;
  4058. if (self.options.beforeRemove) {
  4059. self.options.beforeRemove.call(self);
  4060. }
  4061. K('.ke-menu-item', self.div[0]).unbind();
  4062. KMenu.parent.remove.call(self);
  4063. return self;
  4064. }
  4065. });
  4066. function _menu(options) {
  4067. return new KMenu(options);
  4068. }
  4069. K.MenuClass = KMenu;
  4070. K.menu = _menu;
  4071. function KColorPicker(options) {
  4072. this.init(options);
  4073. }
  4074. _extend(KColorPicker, KWidget, {
  4075. init : function(options) {
  4076. var self = this;
  4077. options.z = options.z || 811213;
  4078. KColorPicker.parent.init.call(self, options);
  4079. var colors = options.colors || [
  4080. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4081. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4082. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4083. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4084. ];
  4085. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4086. self._cells = [];
  4087. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4088. e.stopPropagation();
  4089. }).attr('unselectable', 'on');
  4090. var table = self.doc.createElement('table');
  4091. self.div.append(table);
  4092. table.className = 'ke-colorpicker-table';
  4093. table.cellPadding = 0;
  4094. table.cellSpacing = 0;
  4095. table.border = 0;
  4096. var row = table.insertRow(0), cell = row.insertCell(0);
  4097. cell.colSpan = colors[0].length;
  4098. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4099. for (var i = 0; i < colors.length; i++) {
  4100. row = table.insertRow(i + 1);
  4101. for (var j = 0; j < colors[i].length; j++) {
  4102. cell = row.insertCell(j);
  4103. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4104. }
  4105. }
  4106. },
  4107. _addAttr : function(cell, color, cls) {
  4108. var self = this;
  4109. cell = K(cell).addClass(cls);
  4110. if (self.selectedColor === color.toLowerCase()) {
  4111. cell.addClass('ke-colorpicker-cell-selected');
  4112. }
  4113. cell.attr('title', color || self.options.noColor);
  4114. cell.mouseover(function(e) {
  4115. K(this).addClass('ke-colorpicker-cell-on');
  4116. });
  4117. cell.mouseout(function(e) {
  4118. K(this).removeClass('ke-colorpicker-cell-on');
  4119. });
  4120. cell.click(function(e) {
  4121. e.stop();
  4122. self.options.click.call(K(this), color);
  4123. });
  4124. if (color) {
  4125. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4126. } else {
  4127. cell.html(self.options.noColor);
  4128. }
  4129. K(cell).attr('unselectable', 'on');
  4130. self._cells.push(cell);
  4131. },
  4132. remove : function() {
  4133. var self = this;
  4134. _each(self._cells, function() {
  4135. this.unbind();
  4136. });
  4137. KColorPicker.parent.remove.call(self);
  4138. return self;
  4139. }
  4140. });
  4141. function _colorpicker(options) {
  4142. return new KColorPicker(options);
  4143. }
  4144. K.ColorPickerClass = KColorPicker;
  4145. K.colorpicker = _colorpicker;
  4146. function KUploadButton(options) {
  4147. this.init(options);
  4148. }
  4149. _extend(KUploadButton, {
  4150. init : function(options) {
  4151. var self = this,
  4152. button = K(options.button),
  4153. fieldName = options.fieldName || 'file',
  4154. url = options.url || '',
  4155. title = button.val(),
  4156. extraParams = options.extraParams || {},
  4157. cls = button[0].className || '',
  4158. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4159. options.afterError = options.afterError || function(str) {
  4160. alert(str);
  4161. };
  4162. var hiddenElements = [];
  4163. for(var k in extraParams){
  4164. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  4165. }
  4166. var html = [
  4167. '<div class="ke-inline-block ' + cls + '">',
  4168. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4169. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4170. '<span class="ke-button-common">',
  4171. hiddenElements.join(''),
  4172. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4173. '</span>',
  4174. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4175. (options.form ? '</div>' : '</form>'),
  4176. '</div>'].join('');
  4177. var div = K(html, button.doc);
  4178. button.hide();
  4179. button.before(div);
  4180. self.div = div;
  4181. self.button = button;
  4182. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4183. self.form = options.form ? K(options.form) : K('form', div);
  4184. self.fileBox = K('.ke-upload-file', div);
  4185. var width = options.width || K('.ke-button-common', div).width();
  4186. K('.ke-upload-area', div).width(width);
  4187. self.options = options;
  4188. },
  4189. submit : function() {
  4190. var self = this,
  4191. iframe = self.iframe;
  4192. iframe.bind('load', function() {
  4193. iframe.unbind();
  4194. var tempForm = document.createElement('form');
  4195. self.fileBox.before(tempForm);
  4196. K(tempForm).append(self.fileBox);
  4197. tempForm.reset();
  4198. K(tempForm).remove(true);
  4199. var doc = K.iframeDoc(iframe),
  4200. pre = doc.getElementsByTagName('pre')[0],
  4201. str = '', data;
  4202. if (pre) {
  4203. str = pre.innerHTML;
  4204. } else {
  4205. str = doc.body.innerHTML;
  4206. }
  4207. str = _unescape(str);
  4208. iframe[0].src = 'javascript:false';
  4209. try {
  4210. data = K.json(str);
  4211. } catch (e) {
  4212. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4213. }
  4214. if (data) {
  4215. self.options.afterUpload.call(self, data);
  4216. }
  4217. });
  4218. self.form[0].submit();
  4219. return self;
  4220. },
  4221. remove : function() {
  4222. var self = this;
  4223. if (self.fileBox) {
  4224. self.fileBox.unbind();
  4225. }
  4226. self.iframe.remove();
  4227. self.div.remove();
  4228. self.button.show();
  4229. return self;
  4230. }
  4231. });
  4232. function _uploadbutton(options) {
  4233. return new KUploadButton(options);
  4234. }
  4235. K.UploadButtonClass = KUploadButton;
  4236. K.uploadbutton = _uploadbutton;
  4237. function _createButton(arg) {
  4238. arg = arg || {};
  4239. var name = arg.name || '',
  4240. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4241. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4242. if (arg.click) {
  4243. btn.click(arg.click);
  4244. }
  4245. span.append(btn);
  4246. return span;
  4247. }
  4248. function KDialog(options) {
  4249. this.init(options);
  4250. }
  4251. _extend(KDialog, KWidget, {
  4252. init : function(options) {
  4253. var self = this;
  4254. var shadowMode = _undef(options.shadowMode, true);
  4255. options.z = options.z || 811213;
  4256. options.shadowMode = false;
  4257. options.autoScroll = _undef(options.autoScroll, true);
  4258. KDialog.parent.init.call(self, options);
  4259. var title = options.title,
  4260. body = K(options.body, self.doc),
  4261. previewBtn = options.previewBtn,
  4262. yesBtn = options.yesBtn,
  4263. noBtn = options.noBtn,
  4264. closeBtn = options.closeBtn,
  4265. showMask = _undef(options.showMask, true);
  4266. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4267. e.stopPropagation();
  4268. });
  4269. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4270. if (_IE && _V < 7) {
  4271. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4272. } else if (shadowMode) {
  4273. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4274. }
  4275. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4276. contentDiv.append(headerDiv);
  4277. headerDiv.html(title);
  4278. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4279. headerDiv.append(self.closeIcon);
  4280. self.draggable({
  4281. clickEl : headerDiv,
  4282. beforeDrag : options.beforeDrag
  4283. });
  4284. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4285. contentDiv.append(bodyDiv);
  4286. bodyDiv.append(body);
  4287. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4288. if (previewBtn || yesBtn || noBtn) {
  4289. contentDiv.append(footerDiv);
  4290. }
  4291. _each([
  4292. { btn : previewBtn, name : 'preview' },
  4293. { btn : yesBtn, name : 'yes' },
  4294. { btn : noBtn, name : 'no' }
  4295. ], function() {
  4296. if (this.btn) {
  4297. var button = _createButton(this.btn);
  4298. button.addClass('ke-dialog-' + this.name);
  4299. footerDiv.append(button);
  4300. }
  4301. });
  4302. if (self.height) {
  4303. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4304. }
  4305. self.div.width(self.div.width());
  4306. self.div.height(self.div.height());
  4307. self.mask = null;
  4308. if (showMask) {
  4309. var docEl = _docElement(self.doc),
  4310. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4311. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4312. self.mask = _widget({
  4313. x : 0,
  4314. y : 0,
  4315. z : self.z - 1,
  4316. cls : 'ke-dialog-mask',
  4317. width : docWidth,
  4318. height : docHeight
  4319. });
  4320. }
  4321. self.autoPos(self.div.width(), self.div.height());
  4322. self.footerDiv = footerDiv;
  4323. self.bodyDiv = bodyDiv;
  4324. self.headerDiv = headerDiv;
  4325. self.isLoading = false;
  4326. },
  4327. setMaskIndex : function(z) {
  4328. var self = this;
  4329. self.mask.div.css('z-index', z);
  4330. },
  4331. showLoading : function(msg) {
  4332. msg = _undef(msg, '');
  4333. var self = this, body = self.bodyDiv;
  4334. 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>')
  4335. .width(body.width()).height(body.height())
  4336. .css('top', self.headerDiv.height() + 'px');
  4337. body.css('visibility', 'hidden').after(self.loading);
  4338. self.isLoading = true;
  4339. return self;
  4340. },
  4341. hideLoading : function() {
  4342. this.loading && this.loading.remove();
  4343. this.bodyDiv.css('visibility', 'visible');
  4344. this.isLoading = false;
  4345. return this;
  4346. },
  4347. remove : function() {
  4348. var self = this;
  4349. if (self.options.beforeRemove) {
  4350. self.options.beforeRemove.call(self);
  4351. }
  4352. self.mask && self.mask.remove();
  4353. self.iframeMask && self.iframeMask.remove();
  4354. self.closeIcon.unbind();
  4355. K('input', self.div).unbind();
  4356. K('button', self.div).unbind();
  4357. self.footerDiv.unbind();
  4358. self.bodyDiv.unbind();
  4359. self.headerDiv.unbind();
  4360. K('iframe', self.div).each(function() {
  4361. K(this).remove();
  4362. });
  4363. KDialog.parent.remove.call(self);
  4364. return self;
  4365. }
  4366. });
  4367. function _dialog(options) {
  4368. return new KDialog(options);
  4369. }
  4370. K.DialogClass = KDialog;
  4371. K.dialog = _dialog;
  4372. function _tabs(options) {
  4373. var self = _widget(options),
  4374. remove = self.remove,
  4375. afterSelect = options.afterSelect,
  4376. div = self.div,
  4377. liList = [];
  4378. div.addClass('ke-tabs')
  4379. .bind('contextmenu,mousedown,mousemove', function(e) {
  4380. e.preventDefault();
  4381. });
  4382. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4383. div.append(ul);
  4384. self.add = function(tab) {
  4385. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4386. li.data('tab', tab);
  4387. liList.push(li);
  4388. ul.append(li);
  4389. };
  4390. self.selectedIndex = 0;
  4391. self.select = function(index) {
  4392. self.selectedIndex = index;
  4393. _each(liList, function(i, li) {
  4394. li.unbind();
  4395. if (i === index) {
  4396. li.addClass('ke-tabs-li-selected');
  4397. K(li.data('tab').panel).show('');
  4398. } else {
  4399. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4400. .mouseover(function() {
  4401. K(this).addClass('ke-tabs-li-on');
  4402. })
  4403. .mouseout(function() {
  4404. K(this).removeClass('ke-tabs-li-on');
  4405. })
  4406. .click(function() {
  4407. self.select(i);
  4408. });
  4409. K(li.data('tab').panel).hide();
  4410. }
  4411. });
  4412. if (afterSelect) {
  4413. afterSelect.call(self, index);
  4414. }
  4415. };
  4416. self.remove = function() {
  4417. _each(liList, function() {
  4418. this.remove();
  4419. });
  4420. ul.remove();
  4421. remove.call(self);
  4422. };
  4423. return self;
  4424. }
  4425. K.tabs = _tabs;
  4426. function _loadScript(url, fn) {
  4427. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4428. script = document.createElement('script');
  4429. head.appendChild(script);
  4430. script.src = url;
  4431. script.charset = 'utf-8';
  4432. script.onload = script.onreadystatechange = function() {
  4433. if (!this.readyState || this.readyState === 'loaded') {
  4434. if (fn) {
  4435. fn();
  4436. }
  4437. script.onload = script.onreadystatechange = null;
  4438. head.removeChild(script);
  4439. }
  4440. };
  4441. }
  4442. function _chopQuery(url) {
  4443. var index = url.indexOf('?');
  4444. return index > 0 ? url.substr(0, index) : url;
  4445. }
  4446. function _loadStyle(url) {
  4447. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4448. link = document.createElement('link'),
  4449. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4450. var links = K('link[rel="stylesheet"]', head);
  4451. for (var i = 0, len = links.length; i < len; i++) {
  4452. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4453. return;
  4454. }
  4455. }
  4456. head.appendChild(link);
  4457. link.href = url;
  4458. link.rel = 'stylesheet';
  4459. }
  4460. function _ajax(url, fn, method, param, dataType) {
  4461. method = method || 'GET';
  4462. dataType = dataType || 'json';
  4463. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4464. xhr.open(method, url, true);
  4465. xhr.onreadystatechange = function () {
  4466. if (xhr.readyState == 4 && xhr.status == 200) {
  4467. if (fn) {
  4468. var data = _trim(xhr.responseText);
  4469. if (dataType == 'json') {
  4470. data = _json(data);
  4471. }
  4472. fn(data);
  4473. }
  4474. }
  4475. };
  4476. if (method == 'POST') {
  4477. var params = [];
  4478. _each(param, function(key, val) {
  4479. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4480. });
  4481. try {
  4482. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4483. } catch (e) {}
  4484. xhr.send(params.join('&'));
  4485. } else {
  4486. xhr.send(null);
  4487. }
  4488. }
  4489. K.loadScript = _loadScript;
  4490. K.loadStyle = _loadStyle;
  4491. K.ajax = _ajax;
  4492. var _plugins = {};
  4493. function _plugin(name, fn) {
  4494. if (name === undefined) {
  4495. return _plugins;
  4496. }
  4497. if (!fn) {
  4498. return _plugins[name];
  4499. }
  4500. _plugins[name] = fn;
  4501. }
  4502. var _language = {};
  4503. function _parseLangKey(key) {
  4504. var match, ns = 'core';
  4505. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4506. ns = match[1];
  4507. key = match[2];
  4508. }
  4509. return { ns : ns, key : key };
  4510. }
  4511. function _lang(mixed, langType) {
  4512. langType = langType === undefined ? K.options.langType : langType;
  4513. if (typeof mixed === 'string') {
  4514. if (!_language[langType]) {
  4515. return 'no language';
  4516. }
  4517. var pos = mixed.length - 1;
  4518. if (mixed.substr(pos) === '.') {
  4519. return _language[langType][mixed.substr(0, pos)];
  4520. }
  4521. var obj = _parseLangKey(mixed);
  4522. return _language[langType][obj.ns][obj.key];
  4523. }
  4524. _each(mixed, function(key, val) {
  4525. var obj = _parseLangKey(key);
  4526. if (!_language[langType]) {
  4527. _language[langType] = {};
  4528. }
  4529. if (!_language[langType][obj.ns]) {
  4530. _language[langType][obj.ns] = {};
  4531. }
  4532. _language[langType][obj.ns][obj.key] = val;
  4533. });
  4534. }
  4535. function _getImageFromRange(range, fn) {
  4536. if (range.collapsed) {
  4537. return;
  4538. }
  4539. range = range.cloneRange().up();
  4540. var sc = range.startContainer, so = range.startOffset;
  4541. if (!_WEBKIT && !range.isControl()) {
  4542. return;
  4543. }
  4544. var img = K(sc.childNodes[so]);
  4545. if (!img || img.name != 'img') {
  4546. return;
  4547. }
  4548. if (fn(img)) {
  4549. return img;
  4550. }
  4551. }
  4552. function _bindContextmenuEvent() {
  4553. var self = this, doc = self.edit.doc;
  4554. K(doc).contextmenu(function(e) {
  4555. if (self.menu) {
  4556. self.hideMenu();
  4557. }
  4558. if (!self.useContextmenu) {
  4559. e.preventDefault();
  4560. return;
  4561. }
  4562. if (self._contextmenus.length === 0) {
  4563. return;
  4564. }
  4565. var maxWidth = 0, items = [];
  4566. _each(self._contextmenus, function() {
  4567. if (this.title == '-') {
  4568. items.push(this);
  4569. return;
  4570. }
  4571. if (this.cond && this.cond()) {
  4572. items.push(this);
  4573. if (this.width && this.width > maxWidth) {
  4574. maxWidth = this.width;
  4575. }
  4576. }
  4577. });
  4578. while (items.length > 0 && items[0].title == '-') {
  4579. items.shift();
  4580. }
  4581. while (items.length > 0 && items[items.length - 1].title == '-') {
  4582. items.pop();
  4583. }
  4584. var prevItem = null;
  4585. _each(items, function(i) {
  4586. if (this.title == '-' && prevItem.title == '-') {
  4587. delete items[i];
  4588. }
  4589. prevItem = this;
  4590. });
  4591. if (items.length > 0) {
  4592. e.preventDefault();
  4593. var pos = K(self.edit.iframe).pos(),
  4594. menu = _menu({
  4595. x : pos.x + e.clientX,
  4596. y : pos.y + e.clientY,
  4597. width : maxWidth,
  4598. css : { visibility: 'hidden' },
  4599. shadowMode : self.shadowMode
  4600. });
  4601. _each(items, function() {
  4602. if (this.title) {
  4603. menu.addItem(this);
  4604. }
  4605. });
  4606. var docEl = _docElement(menu.doc),
  4607. menuHeight = menu.div.height();
  4608. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4609. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4610. }
  4611. menu.div.css('visibility', 'visible');
  4612. self.menu = menu;
  4613. }
  4614. });
  4615. }
  4616. function _bindNewlineEvent() {
  4617. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4618. if (_IE && newlineTag !== 'br') {
  4619. return;
  4620. }
  4621. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4622. return;
  4623. }
  4624. if (_OPERA && _V < 9) {
  4625. return;
  4626. }
  4627. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4628. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4629. function getAncestorTagName(range) {
  4630. var ancestor = K(range.commonAncestor());
  4631. while (ancestor) {
  4632. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4633. break;
  4634. }
  4635. ancestor = ancestor.parent();
  4636. }
  4637. return ancestor.name;
  4638. }
  4639. K(doc).keydown(function(e) {
  4640. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4641. return;
  4642. }
  4643. self.cmd.selection();
  4644. var tagName = getAncestorTagName(self.cmd.range);
  4645. if (tagName == 'marquee' || tagName == 'select') {
  4646. return;
  4647. }
  4648. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4649. e.preventDefault();
  4650. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4651. return;
  4652. }
  4653. if (!pSkipTagMap[tagName]) {
  4654. _nativeCommand(doc, 'formatblock', '<p>');
  4655. }
  4656. });
  4657. K(doc).keyup(function(e) {
  4658. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4659. return;
  4660. }
  4661. if (newlineTag == 'br') {
  4662. return;
  4663. }
  4664. if (_GECKO) {
  4665. var root = self.cmd.commonAncestor('p');
  4666. var a = self.cmd.commonAncestor('a');
  4667. if (a && a.text() == '') {
  4668. a.remove(true);
  4669. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4670. self.cmd.select();
  4671. }
  4672. return;
  4673. }
  4674. self.cmd.selection();
  4675. var tagName = getAncestorTagName(self.cmd.range);
  4676. if (tagName == 'marquee' || tagName == 'select') {
  4677. return;
  4678. }
  4679. if (!pSkipTagMap[tagName]) {
  4680. _nativeCommand(doc, 'formatblock', '<p>');
  4681. }
  4682. var div = self.cmd.commonAncestor('div');
  4683. if (div) {
  4684. var p = K('<p></p>'),
  4685. child = div[0].firstChild;
  4686. while (child) {
  4687. var next = child.nextSibling;
  4688. p.append(child);
  4689. child = next;
  4690. }
  4691. div.before(p);
  4692. div.remove();
  4693. self.cmd.range.selectNodeContents(p[0]);
  4694. self.cmd.select();
  4695. }
  4696. });
  4697. }
  4698. function _bindTabEvent() {
  4699. var self = this, doc = self.edit.doc;
  4700. K(doc).keydown(function(e) {
  4701. if (e.which == 9) {
  4702. e.preventDefault();
  4703. if (self.afterTab) {
  4704. self.afterTab.call(self, e);
  4705. return;
  4706. }
  4707. var cmd = self.cmd, range = cmd.range;
  4708. range.shrink();
  4709. if (range.collapsed && range.startContainer.nodeType == 1) {
  4710. range.insertNode(K('@&nbsp;', doc)[0]);
  4711. cmd.select();
  4712. }
  4713. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4714. }
  4715. });
  4716. }
  4717. function _bindFocusEvent() {
  4718. var self = this;
  4719. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4720. if (self.afterFocus) {
  4721. self.afterFocus.call(self, e);
  4722. }
  4723. }).blur(function(e) {
  4724. if (self.afterBlur) {
  4725. self.afterBlur.call(self, e);
  4726. }
  4727. });
  4728. }
  4729. function _removeBookmarkTag(html) {
  4730. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4731. }
  4732. function _removeTempTag(html) {
  4733. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4734. }
  4735. function _addBookmarkToStack(stack, bookmark) {
  4736. if (stack.length === 0) {
  4737. stack.push(bookmark);
  4738. return;
  4739. }
  4740. var prev = stack[stack.length - 1];
  4741. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4742. stack.push(bookmark);
  4743. }
  4744. }
  4745. function _undoToRedo(fromStack, toStack) {
  4746. var self = this, edit = self.edit,
  4747. body = edit.doc.body,
  4748. range, bookmark;
  4749. if (fromStack.length === 0) {
  4750. return self;
  4751. }
  4752. if (edit.designMode) {
  4753. range = self.cmd.range;
  4754. bookmark = range.createBookmark(true);
  4755. bookmark.html = body.innerHTML;
  4756. } else {
  4757. bookmark = {
  4758. html : body.innerHTML
  4759. };
  4760. }
  4761. _addBookmarkToStack(toStack, bookmark);
  4762. var prev = fromStack.pop();
  4763. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4764. prev = fromStack.pop();
  4765. }
  4766. if (edit.designMode) {
  4767. edit.html(prev.html);
  4768. if (prev.start) {
  4769. range.moveToBookmark(prev);
  4770. self.select();
  4771. }
  4772. } else {
  4773. K(body).html(_removeBookmarkTag(prev.html));
  4774. }
  4775. return self;
  4776. }
  4777. function KEditor(options) {
  4778. var self = this;
  4779. self.options = {};
  4780. function setOption(key, val) {
  4781. if (KEditor.prototype[key] === undefined) {
  4782. self[key] = val;
  4783. }
  4784. self.options[key] = val;
  4785. }
  4786. _each(options, function(key, val) {
  4787. setOption(key, options[key]);
  4788. });
  4789. _each(K.options, function(key, val) {
  4790. if (self[key] === undefined) {
  4791. setOption(key, val);
  4792. }
  4793. });
  4794. var se = K(self.srcElement || '<textarea/>');
  4795. if (!self.width) {
  4796. self.width = se[0].style.width || se.width();
  4797. }
  4798. if (!self.height) {
  4799. self.height = se[0].style.height || se.height();
  4800. }
  4801. setOption('width', _undef(self.width, self.minWidth));
  4802. setOption('height', _undef(self.height, self.minHeight));
  4803. setOption('width', _addUnit(self.width));
  4804. setOption('height', _addUnit(self.height));
  4805. if (_MOBILE && (!_IOS || _V < 534)) {
  4806. self.designMode = false;
  4807. }
  4808. self.srcElement = se;
  4809. self.initContent = '';
  4810. self.plugin = {};
  4811. self.isCreated = false;
  4812. self._handlers = {};
  4813. self._contextmenus = [];
  4814. self._undoStack = [];
  4815. self._redoStack = [];
  4816. self._firstAddBookmark = true;
  4817. self.menu = self.contextmenu = null;
  4818. self.dialogs = [];
  4819. }
  4820. KEditor.prototype = {
  4821. lang : function(mixed) {
  4822. return _lang(mixed, this.langType);
  4823. },
  4824. loadPlugin : function(name, fn) {
  4825. var self = this;
  4826. var _pluginStatus = this._pluginStatus;
  4827. if (!_pluginStatus) {
  4828. _pluginStatus = this._pluginStatus = {};
  4829. }
  4830. if (_plugins[name]) {
  4831. if (!_isFunction(_plugins[name])) {
  4832. setTimeout(function() {
  4833. self.loadPlugin(name, fn);
  4834. }, 100);
  4835. return self;
  4836. }
  4837. if(!_pluginStatus[name]) {
  4838. _plugins[name].call(self, KindEditor);
  4839. _pluginStatus[name] = 'inited';
  4840. }
  4841. if (fn) {
  4842. fn.call(self);
  4843. }
  4844. return self;
  4845. }
  4846. _plugins[name] = 'loading';
  4847. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4848. setTimeout(function() {
  4849. if (_plugins[name]) {
  4850. self.loadPlugin(name, fn);
  4851. }
  4852. }, 0);
  4853. });
  4854. return self;
  4855. },
  4856. handler : function(key, fn) {
  4857. var self = this;
  4858. if (!self._handlers[key]) {
  4859. self._handlers[key] = [];
  4860. }
  4861. if (_isFunction(fn)) {
  4862. self._handlers[key].push(fn);
  4863. return self;
  4864. }
  4865. _each(self._handlers[key], function() {
  4866. fn = this.call(self, fn);
  4867. });
  4868. return fn;
  4869. },
  4870. clickToolbar : function(name, fn) {
  4871. var self = this, key = 'clickToolbar' + name;
  4872. if (fn === undefined) {
  4873. if (self._handlers[key]) {
  4874. return self.handler(key);
  4875. }
  4876. self.loadPlugin(name, function() {
  4877. self.handler(key);
  4878. });
  4879. return self;
  4880. }
  4881. return self.handler(key, fn);
  4882. },
  4883. updateState : function() {
  4884. var self = this;
  4885. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4886. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4887. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4888. });
  4889. return self;
  4890. },
  4891. addContextmenu : function(item) {
  4892. this._contextmenus.push(item);
  4893. return this;
  4894. },
  4895. afterCreate : function(fn) {
  4896. return this.handler('afterCreate', fn);
  4897. },
  4898. beforeRemove : function(fn) {
  4899. return this.handler('beforeRemove', fn);
  4900. },
  4901. beforeGetHtml : function(fn) {
  4902. return this.handler('beforeGetHtml', fn);
  4903. },
  4904. beforeSetHtml : function(fn) {
  4905. return this.handler('beforeSetHtml', fn);
  4906. },
  4907. afterSetHtml : function(fn) {
  4908. return this.handler('afterSetHtml', fn);
  4909. },
  4910. create : function() {
  4911. var self = this, fullscreenMode = self.fullscreenMode;
  4912. if (self.isCreated) {
  4913. return self;
  4914. }
  4915. if (self.srcElement.data('kindeditor')) {
  4916. return self;
  4917. }
  4918. self.srcElement.data('kindeditor', 'true');
  4919. if (fullscreenMode) {
  4920. _docElement().style.overflow = 'hidden';
  4921. } else {
  4922. _docElement().style.overflow = '';
  4923. }
  4924. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4925. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4926. if ((_IE && _V < 8) || _QUIRKS) {
  4927. height = _addUnit(_removeUnit(height) + 2);
  4928. }
  4929. var container = self.container = K(self.layout);
  4930. if (fullscreenMode) {
  4931. K(document.body).append(container);
  4932. } else {
  4933. self.srcElement.before(container);
  4934. }
  4935. var toolbarDiv = K('.toolbar', container),
  4936. editDiv = K('.edit', container),
  4937. statusbar = self.statusbar = K('.statusbar', container);
  4938. container.removeClass('container')
  4939. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4940. if (fullscreenMode) {
  4941. container.css({
  4942. position : 'absolute',
  4943. left : 0,
  4944. top : 0,
  4945. 'z-index' : 811211
  4946. });
  4947. if (!_GECKO) {
  4948. self._scrollPos = _getScrollPos();
  4949. }
  4950. window.scrollTo(0, 0);
  4951. K(document.body).css({
  4952. 'height' : '1px',
  4953. 'overflow' : 'hidden'
  4954. });
  4955. K(document.body.parentNode).css('overflow', 'hidden');
  4956. self._fullscreenExecuted = true;
  4957. } else {
  4958. if (self._fullscreenExecuted) {
  4959. K(document.body).css({
  4960. 'height' : '',
  4961. 'overflow' : ''
  4962. });
  4963. K(document.body.parentNode).css('overflow', '');
  4964. }
  4965. if (self._scrollPos) {
  4966. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  4967. }
  4968. }
  4969. var htmlList = [];
  4970. K.each(self.items, function(i, name) {
  4971. if (name == '|') {
  4972. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  4973. } else if (name == '/') {
  4974. htmlList.push('<div class="ke-hr"></div>');
  4975. } else {
  4976. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  4977. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  4978. }
  4979. });
  4980. var toolbar = self.toolbar = _toolbar({
  4981. src : toolbarDiv,
  4982. html : htmlList.join(''),
  4983. noDisableItems : self.noDisableItems,
  4984. click : function(e, name) {
  4985. e.stop();
  4986. if (self.menu) {
  4987. var menuName = self.menu.name;
  4988. self.hideMenu();
  4989. if (menuName === name) {
  4990. return;
  4991. }
  4992. }
  4993. self.clickToolbar(name);
  4994. }
  4995. });
  4996. var editHeight = _removeUnit(height) - toolbar.div.height();
  4997. var edit = self.edit = _edit({
  4998. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  4999. src : editDiv,
  5000. srcElement : self.srcElement,
  5001. designMode : self.designMode,
  5002. themesPath : self.themesPath,
  5003. bodyClass : self.bodyClass,
  5004. cssPath : self.cssPath,
  5005. cssData : self.cssData,
  5006. beforeGetHtml : function(html) {
  5007. html = self.beforeGetHtml(html);
  5008. html = _removeBookmarkTag(_removeTempTag(html));
  5009. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  5010. },
  5011. beforeSetHtml : function(html) {
  5012. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  5013. return self.beforeSetHtml(html);
  5014. },
  5015. afterSetHtml : function() {
  5016. self.edit = edit = this;
  5017. self.afterSetHtml();
  5018. },
  5019. afterCreate : function() {
  5020. self.edit = edit = this;
  5021. self.cmd = edit.cmd;
  5022. self._docMousedownFn = function(e) {
  5023. if (self.menu) {
  5024. self.hideMenu();
  5025. }
  5026. };
  5027. K(edit.doc, document).mousedown(self._docMousedownFn);
  5028. _bindContextmenuEvent.call(self);
  5029. _bindNewlineEvent.call(self);
  5030. _bindTabEvent.call(self);
  5031. _bindFocusEvent.call(self);
  5032. edit.afterChange(function(e) {
  5033. if (!edit.designMode) {
  5034. return;
  5035. }
  5036. self.updateState();
  5037. self.addBookmark();
  5038. if (self.options.afterChange) {
  5039. self.options.afterChange.call(self);
  5040. }
  5041. });
  5042. edit.textarea.keyup(function(e) {
  5043. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5044. if (self.options.afterChange) {
  5045. self.options.afterChange.call(self);
  5046. }
  5047. }
  5048. });
  5049. if (self.readonlyMode) {
  5050. self.readonly();
  5051. }
  5052. self.isCreated = true;
  5053. if (self.initContent === '') {
  5054. self.initContent = self.html();
  5055. }
  5056. if (self._undoStack.length > 0) {
  5057. var prev = self._undoStack.pop();
  5058. if (prev.start) {
  5059. self.html(prev.html);
  5060. edit.cmd.range.moveToBookmark(prev);
  5061. self.select();
  5062. }
  5063. }
  5064. self.afterCreate();
  5065. if (self.options.afterCreate) {
  5066. self.options.afterCreate.call(self);
  5067. }
  5068. }
  5069. });
  5070. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5071. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5072. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5073. if (self._fullscreenResizeHandler) {
  5074. K(window).unbind('resize', self._fullscreenResizeHandler);
  5075. self._fullscreenResizeHandler = null;
  5076. }
  5077. function initResize() {
  5078. if (statusbar.height() === 0) {
  5079. setTimeout(initResize, 100);
  5080. return;
  5081. }
  5082. self.resize(width, height, false);
  5083. }
  5084. initResize();
  5085. if (fullscreenMode) {
  5086. self._fullscreenResizeHandler = function(e) {
  5087. if (self.isCreated) {
  5088. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5089. }
  5090. };
  5091. K(window).bind('resize', self._fullscreenResizeHandler);
  5092. toolbar.select('fullscreen');
  5093. statusbar.first().css('visibility', 'hidden');
  5094. statusbar.last().css('visibility', 'hidden');
  5095. } else {
  5096. if (_GECKO) {
  5097. K(window).bind('scroll', function(e) {
  5098. self._scrollPos = _getScrollPos();
  5099. });
  5100. }
  5101. if (self.resizeType > 0) {
  5102. _drag({
  5103. moveEl : container,
  5104. clickEl : statusbar,
  5105. moveFn : function(x, y, width, height, diffX, diffY) {
  5106. height += diffY;
  5107. self.resize(null, height);
  5108. }
  5109. });
  5110. } else {
  5111. statusbar.first().css('visibility', 'hidden');
  5112. }
  5113. if (self.resizeType === 2) {
  5114. _drag({
  5115. moveEl : container,
  5116. clickEl : statusbar.last(),
  5117. moveFn : function(x, y, width, height, diffX, diffY) {
  5118. width += diffX;
  5119. height += diffY;
  5120. self.resize(width, height);
  5121. }
  5122. });
  5123. } else {
  5124. statusbar.last().css('visibility', 'hidden');
  5125. }
  5126. }
  5127. return self;
  5128. },
  5129. remove : function() {
  5130. var self = this;
  5131. if (!self.isCreated) {
  5132. return self;
  5133. }
  5134. self.beforeRemove();
  5135. self.srcElement.data('kindeditor', '');
  5136. if (self.menu) {
  5137. self.hideMenu();
  5138. }
  5139. _each(self.dialogs, function() {
  5140. self.hideDialog();
  5141. });
  5142. K(document).unbind('mousedown', self._docMousedownFn);
  5143. self.toolbar.remove();
  5144. self.edit.remove();
  5145. self.statusbar.last().unbind();
  5146. self.statusbar.unbind();
  5147. self.container.remove();
  5148. self.container = self.toolbar = self.edit = self.menu = null;
  5149. self.dialogs = [];
  5150. self.isCreated = false;
  5151. return self;
  5152. },
  5153. resize : function(width, height, updateProp) {
  5154. var self = this;
  5155. updateProp = _undef(updateProp, true);
  5156. if (width) {
  5157. if (!/%/.test(width)) {
  5158. width = _removeUnit(width);
  5159. width = width < self.minWidth ? self.minWidth : width;
  5160. }
  5161. self.container.css('width', _addUnit(width));
  5162. if (updateProp) {
  5163. self.width = _addUnit(width);
  5164. }
  5165. }
  5166. if (height) {
  5167. height = _removeUnit(height);
  5168. editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5169. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5170. self.edit.setHeight(editHeight);
  5171. if (updateProp) {
  5172. self.height = _addUnit(height);
  5173. }
  5174. }
  5175. return self;
  5176. },
  5177. select : function() {
  5178. this.isCreated && this.cmd.select();
  5179. return this;
  5180. },
  5181. html : function(val) {
  5182. var self = this;
  5183. if (val === undefined) {
  5184. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5185. }
  5186. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5187. if (self.isCreated) {
  5188. self.cmd.selection();
  5189. }
  5190. return self;
  5191. },
  5192. fullHtml : function() {
  5193. return this.isCreated ? this.edit.html(undefined, true) : '';
  5194. },
  5195. text : function(val) {
  5196. var self = this;
  5197. if (val === undefined) {
  5198. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5199. } else {
  5200. return self.html(_escape(val));
  5201. }
  5202. },
  5203. isEmpty : function() {
  5204. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5205. },
  5206. isDirty : function() {
  5207. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5208. },
  5209. selectedHtml : function() {
  5210. var val = this.isCreated ? this.cmd.range.html() : '';
  5211. val = _removeBookmarkTag(_removeTempTag(val));
  5212. return val;
  5213. },
  5214. count : function(mode) {
  5215. var self = this;
  5216. mode = (mode || 'html').toLowerCase();
  5217. if (mode === 'html') {
  5218. return self.html().length;
  5219. }
  5220. if (mode === 'text') {
  5221. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5222. }
  5223. return 0;
  5224. },
  5225. exec : function(key) {
  5226. key = key.toLowerCase();
  5227. var self = this, cmd = self.cmd,
  5228. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5229. if (changeFlag) {
  5230. self.addBookmark(false);
  5231. }
  5232. cmd[key].apply(cmd, _toArray(arguments, 1));
  5233. if (changeFlag) {
  5234. self.updateState();
  5235. self.addBookmark(false);
  5236. if (self.options.afterChange) {
  5237. self.options.afterChange.call(self);
  5238. }
  5239. }
  5240. return self;
  5241. },
  5242. insertHtml : function(val, quickMode) {
  5243. if (!this.isCreated) {
  5244. return this;
  5245. }
  5246. val = this.beforeSetHtml(val);
  5247. this.exec('inserthtml', val, quickMode);
  5248. return this;
  5249. },
  5250. appendHtml : function(val) {
  5251. this.html(this.html() + val);
  5252. if (this.isCreated) {
  5253. var cmd = this.cmd;
  5254. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5255. cmd.select();
  5256. }
  5257. return this;
  5258. },
  5259. sync : function() {
  5260. _elementVal(this.srcElement, this.html());
  5261. return this;
  5262. },
  5263. focus : function() {
  5264. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5265. return this;
  5266. },
  5267. blur : function() {
  5268. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5269. return this;
  5270. },
  5271. addBookmark : function(checkSize) {
  5272. checkSize = _undef(checkSize, true);
  5273. var self = this, edit = self.edit,
  5274. body = edit.doc.body,
  5275. html = _removeTempTag(body.innerHTML), bookmark;
  5276. if (checkSize && self._undoStack.length > 0) {
  5277. var prev = self._undoStack[self._undoStack.length - 1];
  5278. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5279. return self;
  5280. }
  5281. }
  5282. if (edit.designMode && !self._firstAddBookmark) {
  5283. var range = self.cmd.range;
  5284. bookmark = range.createBookmark(true);
  5285. bookmark.html = _removeTempTag(body.innerHTML);
  5286. range.moveToBookmark(bookmark);
  5287. } else {
  5288. bookmark = {
  5289. html : html
  5290. };
  5291. }
  5292. self._firstAddBookmark = false;
  5293. _addBookmarkToStack(self._undoStack, bookmark);
  5294. return self;
  5295. },
  5296. undo : function() {
  5297. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5298. },
  5299. redo : function() {
  5300. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5301. },
  5302. fullscreen : function(bool) {
  5303. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5304. this.addBookmark(false);
  5305. return this.remove().create();
  5306. },
  5307. readonly : function(isReadonly) {
  5308. isReadonly = _undef(isReadonly, true);
  5309. var self = this, edit = self.edit, doc = edit.doc;
  5310. if (self.designMode) {
  5311. self.toolbar.disableAll(isReadonly, []);
  5312. } else {
  5313. _each(self.noDisableItems, function() {
  5314. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5315. });
  5316. }
  5317. if (_IE) {
  5318. doc.body.contentEditable = !isReadonly;
  5319. } else {
  5320. doc.designMode = isReadonly ? 'off' : 'on';
  5321. }
  5322. edit.textarea[0].disabled = isReadonly;
  5323. },
  5324. createMenu : function(options) {
  5325. var self = this,
  5326. name = options.name,
  5327. knode = self.toolbar.get(name),
  5328. pos = knode.pos();
  5329. options.x = pos.x;
  5330. options.y = pos.y + knode.height();
  5331. options.z = self.options.zIndex;
  5332. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5333. if (options.selectedColor !== undefined) {
  5334. options.cls = 'ke-colorpicker-' + self.themeType;
  5335. options.noColor = self.lang('noColor');
  5336. self.menu = _colorpicker(options);
  5337. } else {
  5338. options.cls = 'ke-menu-' + self.themeType;
  5339. options.centerLineMode = false;
  5340. self.menu = _menu(options);
  5341. }
  5342. return self.menu;
  5343. },
  5344. hideMenu : function() {
  5345. this.menu.remove();
  5346. this.menu = null;
  5347. return this;
  5348. },
  5349. hideContextmenu : function() {
  5350. this.contextmenu.remove();
  5351. this.contextmenu = null;
  5352. return this;
  5353. },
  5354. createDialog : function(options) {
  5355. var self = this, name = options.name;
  5356. options.z = self.options.zIndex;
  5357. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5358. options.closeBtn = _undef(options.closeBtn, {
  5359. name : self.lang('close'),
  5360. click : function(e) {
  5361. self.hideDialog();
  5362. if (_IE && self.cmd) {
  5363. self.cmd.select();
  5364. }
  5365. }
  5366. });
  5367. options.noBtn = _undef(options.noBtn, {
  5368. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5369. click : function(e) {
  5370. self.hideDialog();
  5371. if (_IE && self.cmd) {
  5372. self.cmd.select();
  5373. }
  5374. }
  5375. });
  5376. if (self.dialogAlignType != 'page') {
  5377. options.alignEl = self.container;
  5378. }
  5379. options.cls = 'ke-dialog-' + self.themeType;
  5380. if (self.dialogs.length > 0) {
  5381. var firstDialog = self.dialogs[0],
  5382. parentDialog = self.dialogs[self.dialogs.length - 1];
  5383. firstDialog.setMaskIndex(parentDialog.z + 2);
  5384. options.z = parentDialog.z + 3;
  5385. options.showMask = false;
  5386. }
  5387. var dialog = _dialog(options);
  5388. self.dialogs.push(dialog);
  5389. return dialog;
  5390. },
  5391. hideDialog : function() {
  5392. var self = this;
  5393. if (self.dialogs.length > 0) {
  5394. self.dialogs.pop().remove();
  5395. }
  5396. if (self.dialogs.length > 0) {
  5397. var firstDialog = self.dialogs[0],
  5398. parentDialog = self.dialogs[self.dialogs.length - 1];
  5399. firstDialog.setMaskIndex(parentDialog.z - 1);
  5400. }
  5401. return self;
  5402. },
  5403. errorDialog : function(html) {
  5404. var self = this;
  5405. var dialog = self.createDialog({
  5406. width : 750,
  5407. title : self.lang('uploadError'),
  5408. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5409. });
  5410. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5411. doc.open();
  5412. doc.write(html);
  5413. doc.close();
  5414. K(doc.body).css('background-color', '#FFF');
  5415. iframe[0].contentWindow.focus();
  5416. return self;
  5417. }
  5418. };
  5419. function _editor(options) {
  5420. return new KEditor(options);
  5421. }
  5422. _instances = [];
  5423. function _create(expr, options) {
  5424. options = options || {};
  5425. options.basePath = _undef(options.basePath, K.basePath);
  5426. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5427. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5428. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5429. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5430. var themeType = _undef(options.themeType, K.options.themeType);
  5431. _loadStyle(options.themesPath + 'default/default.css');
  5432. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5433. }
  5434. function create(editor) {
  5435. _each(_plugins, function(name, fn) {
  5436. if (_isFunction(fn)) {
  5437. fn.call(editor, KindEditor);
  5438. if (!editor._pluginStatus) {
  5439. editor._pluginStatus = {};
  5440. }
  5441. editor._pluginStatus[name] = 'inited';
  5442. }
  5443. });
  5444. return editor.create();
  5445. }
  5446. var knode = K(expr);
  5447. if (!knode || knode.length === 0) {
  5448. return;
  5449. }
  5450. if (knode.length > 1) {
  5451. knode.each(function() {
  5452. _create(this, options);
  5453. });
  5454. return _instances[0];
  5455. }
  5456. options.srcElement = knode[0];
  5457. var editor = new KEditor(options);
  5458. _instances.push(editor);
  5459. if (_language[editor.langType]) {
  5460. return create(editor);
  5461. }
  5462. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5463. create(editor);
  5464. });
  5465. return editor;
  5466. }
  5467. function _eachEditor(expr, fn) {
  5468. K(expr).each(function(i, el) {
  5469. K.each(_instances, function(j, editor) {
  5470. if (editor && editor.srcElement[0] == el) {
  5471. fn.call(editor, j);
  5472. return false;
  5473. }
  5474. });
  5475. });
  5476. }
  5477. K.remove = function(expr) {
  5478. _eachEditor(expr, function(i) {
  5479. this.remove();
  5480. _instances.splice(i, 1);
  5481. });
  5482. };
  5483. K.sync = function(expr) {
  5484. _eachEditor(expr, function() {
  5485. this.sync();
  5486. });
  5487. };
  5488. K.html = function(expr, val) {
  5489. _eachEditor(expr, function() {
  5490. this.html(val);
  5491. });
  5492. };
  5493. K.insertHtml = function(expr, val) {
  5494. _eachEditor(expr, function() {
  5495. this.insertHtml(val);
  5496. });
  5497. };
  5498. K.appendHtml = function(expr, val) {
  5499. _eachEditor(expr, function() {
  5500. this.appendHtml(val);
  5501. });
  5502. };
  5503. if (_IE && _V < 7) {
  5504. _nativeCommand(document, 'BackgroundImageCache', true);
  5505. }
  5506. K.EditorClass = KEditor;
  5507. K.editor = _editor;
  5508. K.create = _create;
  5509. K.instances = _instances;
  5510. K.plugin = _plugin;
  5511. K.lang = _lang;
  5512. _plugin('core', function(K) {
  5513. var self = this,
  5514. shortcutKeys = {
  5515. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5516. };
  5517. self.afterSetHtml(function() {
  5518. if (self.options.afterChange) {
  5519. self.options.afterChange.call(self);
  5520. }
  5521. });
  5522. self.afterCreate(function() {
  5523. if (self.syncType != 'form') {
  5524. return;
  5525. }
  5526. var el = K(self.srcElement), hasForm = false;
  5527. while ((el = el.parent())) {
  5528. if (el.name == 'form') {
  5529. hasForm = true;
  5530. break;
  5531. }
  5532. }
  5533. if (hasForm) {
  5534. el.bind('submit', function(e) {
  5535. self.sync();
  5536. K(window).bind('unload', function() {
  5537. self.edit.textarea.remove();
  5538. });
  5539. });
  5540. var resetBtn = K('[type="reset"]', el);
  5541. resetBtn.click(function() {
  5542. self.html(self.initContent);
  5543. self.cmd.selection();
  5544. });
  5545. self.beforeRemove(function() {
  5546. el.unbind();
  5547. resetBtn.unbind();
  5548. });
  5549. }
  5550. });
  5551. self.clickToolbar('source', function() {
  5552. if (self.edit.designMode) {
  5553. self.toolbar.disableAll(true);
  5554. self.edit.design(false);
  5555. self.toolbar.select('source');
  5556. } else {
  5557. self.toolbar.disableAll(false);
  5558. self.edit.design(true);
  5559. self.toolbar.unselect('source');
  5560. if (_GECKO) {
  5561. setTimeout(function() {
  5562. self.cmd.selection();
  5563. }, 0);
  5564. } else {
  5565. self.cmd.selection();
  5566. }
  5567. }
  5568. self.designMode = self.edit.designMode;
  5569. });
  5570. self.afterCreate(function() {
  5571. if (!self.designMode) {
  5572. self.toolbar.disableAll(true).select('source');
  5573. }
  5574. });
  5575. self.clickToolbar('fullscreen', function() {
  5576. self.fullscreen();
  5577. });
  5578. if (self.fullscreenShortcut) {
  5579. var loaded = false;
  5580. self.afterCreate(function() {
  5581. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5582. if (e.which == 27) {
  5583. setTimeout(function() {
  5584. self.fullscreen();
  5585. }, 0);
  5586. }
  5587. });
  5588. if (loaded) {
  5589. if (_IE && !self.designMode) {
  5590. return;
  5591. }
  5592. self.focus();
  5593. }
  5594. if (!loaded) {
  5595. loaded = true;
  5596. }
  5597. });
  5598. }
  5599. _each('undo,redo'.split(','), function(i, name) {
  5600. if (shortcutKeys[name]) {
  5601. self.afterCreate(function() {
  5602. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5603. self.clickToolbar(name);
  5604. });
  5605. });
  5606. }
  5607. self.clickToolbar(name, function() {
  5608. self[name]();
  5609. });
  5610. });
  5611. self.clickToolbar('formatblock', function() {
  5612. var blocks = self.lang('formatblock.formatBlock'),
  5613. heights = {
  5614. h1 : 28,
  5615. h2 : 24,
  5616. h3 : 18,
  5617. H4 : 14,
  5618. p : 12
  5619. },
  5620. curVal = self.cmd.val('formatblock'),
  5621. menu = self.createMenu({
  5622. name : 'formatblock',
  5623. width : self.langType == 'en' ? 200 : 150
  5624. });
  5625. _each(blocks, function(key, val) {
  5626. var style = 'font-size:' + heights[key] + 'px;';
  5627. if (key.charAt(0) === 'h') {
  5628. style += 'font-weight:bold;';
  5629. }
  5630. menu.addItem({
  5631. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5632. height : heights[key] + 12,
  5633. checked : (curVal === key || curVal === val),
  5634. click : function() {
  5635. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5636. }
  5637. });
  5638. });
  5639. });
  5640. self.clickToolbar('fontname', function() {
  5641. var curVal = self.cmd.val('fontname'),
  5642. menu = self.createMenu({
  5643. name : 'fontname',
  5644. width : 150
  5645. });
  5646. _each(self.lang('fontname.fontName'), function(key, val) {
  5647. menu.addItem({
  5648. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5649. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5650. click : function() {
  5651. self.exec('fontname', key).hideMenu();
  5652. }
  5653. });
  5654. });
  5655. });
  5656. self.clickToolbar('fontsize', function() {
  5657. var curVal = self.cmd.val('fontsize'),
  5658. menu = self.createMenu({
  5659. name : 'fontsize',
  5660. width : 150
  5661. });
  5662. _each(self.fontSizeTable, function(i, val) {
  5663. menu.addItem({
  5664. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5665. height : _removeUnit(val) + 12,
  5666. checked : curVal === val,
  5667. click : function() {
  5668. self.exec('fontsize', val).hideMenu();
  5669. }
  5670. });
  5671. });
  5672. });
  5673. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5674. self.clickToolbar(name, function() {
  5675. self.createMenu({
  5676. name : name,
  5677. selectedColor : self.cmd.val(name) || 'default',
  5678. colors : self.colorTable,
  5679. click : function(color) {
  5680. self.exec(name, color).hideMenu();
  5681. }
  5682. });
  5683. });
  5684. });
  5685. _each(('cut,copy,paste').split(','), function(i, name) {
  5686. self.clickToolbar(name, function() {
  5687. self.focus();
  5688. try {
  5689. self.exec(name, null);
  5690. } catch(e) {
  5691. alert(self.lang(name + 'Error'));
  5692. }
  5693. });
  5694. });
  5695. self.clickToolbar('about', function() {
  5696. var html = '<div style="margin:20px;">' +
  5697. '<div>KindEditor ' + _VERSION + '</div>' +
  5698. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5699. '</div>';
  5700. self.createDialog({
  5701. name : 'about',
  5702. width : 350,
  5703. title : self.lang('about'),
  5704. body : html
  5705. });
  5706. });
  5707. self.plugin.getSelectedLink = function() {
  5708. return self.cmd.commonAncestor('a');
  5709. };
  5710. self.plugin.getSelectedImage = function() {
  5711. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5712. return !/^ke-\w+$/i.test(img[0].className);
  5713. });
  5714. };
  5715. self.plugin.getSelectedFlash = function() {
  5716. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5717. return img[0].className == 'ke-flash';
  5718. });
  5719. };
  5720. self.plugin.getSelectedMedia = function() {
  5721. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5722. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5723. });
  5724. };
  5725. self.plugin.getSelectedAnchor = function() {
  5726. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5727. return img[0].className == 'ke-anchor';
  5728. });
  5729. };
  5730. _each('link,image,flash,media,anchor'.split(','), function(i, name) {
  5731. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5732. _each('edit,delete'.split(','), function(j, val) {
  5733. self.addContextmenu({
  5734. title : self.lang(val + uName),
  5735. click : function() {
  5736. self.loadPlugin(name, function() {
  5737. self.plugin[name][val]();
  5738. self.hideMenu();
  5739. });
  5740. },
  5741. cond : self.plugin['getSelected' + uName],
  5742. width : 150,
  5743. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5744. });
  5745. });
  5746. self.addContextmenu({ title : '-' });
  5747. });
  5748. self.plugin.getSelectedTable = function() {
  5749. return self.cmd.commonAncestor('table');
  5750. };
  5751. self.plugin.getSelectedRow = function() {
  5752. return self.cmd.commonAncestor('tr');
  5753. };
  5754. self.plugin.getSelectedCell = function() {
  5755. return self.cmd.commonAncestor('td');
  5756. };
  5757. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5758. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5759. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5760. self.addContextmenu({
  5761. title : self.lang('table' + val),
  5762. click : function() {
  5763. self.loadPlugin('table', function() {
  5764. self.plugin.table[val]();
  5765. self.hideMenu();
  5766. });
  5767. },
  5768. cond : cond,
  5769. width : 170,
  5770. iconClass : 'ke-icon-table' + val
  5771. });
  5772. });
  5773. self.addContextmenu({ title : '-' });
  5774. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5775. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5776. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5777. if (shortcutKeys[name]) {
  5778. self.afterCreate(function() {
  5779. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5780. self.cmd.selection();
  5781. self.clickToolbar(name);
  5782. });
  5783. });
  5784. }
  5785. self.clickToolbar(name, function() {
  5786. self.focus().exec(name, null);
  5787. });
  5788. });
  5789. self.afterCreate(function() {
  5790. var doc = self.edit.doc, cmd, bookmark, div,
  5791. cls = '__kindeditor_paste__', pasting = false;
  5792. function movePastedData() {
  5793. cmd.range.moveToBookmark(bookmark);
  5794. cmd.select();
  5795. if (_WEBKIT) {
  5796. K('div.' + cls, div).each(function() {
  5797. K(this).after('<br />').remove(true);
  5798. });
  5799. K('span.Apple-style-span', div).remove(true);
  5800. K('span.Apple-tab-span', div).remove(true);
  5801. K('span[style]', div).each(function() {
  5802. if (K(this).css('white-space') == 'nowrap') {
  5803. K(this).remove(true);
  5804. }
  5805. });
  5806. K('meta', div).remove();
  5807. }
  5808. var html = div[0].innerHTML;
  5809. div.remove();
  5810. if (html === '') {
  5811. return;
  5812. }
  5813. if (_WEBKIT) {
  5814. html = html.replace(/(<br>)\1/ig, '$1');
  5815. }
  5816. if (self.pasteType === 2) {
  5817. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5818. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5819. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5820. } else {
  5821. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5822. html = self.beforeSetHtml(html);
  5823. }
  5824. }
  5825. if (self.pasteType === 1) {
  5826. html = html.replace(/&nbsp;/ig, ' ');
  5827. html = html.replace(/\n\s*\n/g, '\n');
  5828. html = html.replace(/<br[^>]*>/ig, '\n');
  5829. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5830. html = html.replace(/<[^>]+>/g, '');
  5831. html = html.replace(/ {2}/g, ' &nbsp;');
  5832. if (self.newlineTag == 'p') {
  5833. if (/\n/.test(html)) {
  5834. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5835. }
  5836. } else {
  5837. html = html.replace(/\n/g, '<br />$&');
  5838. }
  5839. }
  5840. self.insertHtml(html, true);
  5841. }
  5842. K(doc.body).bind('paste', function(e){
  5843. if (self.pasteType === 0) {
  5844. e.stop();
  5845. return;
  5846. }
  5847. if (pasting) {
  5848. return;
  5849. }
  5850. pasting = true;
  5851. K('div.' + cls, doc).remove();
  5852. cmd = self.cmd.selection();
  5853. bookmark = cmd.range.createBookmark();
  5854. div = K('<div class="' + cls + '"></div>', doc).css({
  5855. position : 'absolute',
  5856. width : '1px',
  5857. height : '1px',
  5858. overflow : 'hidden',
  5859. left : '-1981px',
  5860. top : K(bookmark.start).pos().y + 'px',
  5861. 'white-space' : 'nowrap'
  5862. });
  5863. K(doc.body).append(div);
  5864. if (_IE) {
  5865. var rng = cmd.range.get(true);
  5866. rng.moveToElementText(div[0]);
  5867. rng.select();
  5868. rng.execCommand('paste');
  5869. e.preventDefault();
  5870. } else {
  5871. cmd.range.selectNodeContents(div[0]);
  5872. cmd.select();
  5873. div[0].tabIndex = -1;
  5874. div[0].focus();
  5875. }
  5876. setTimeout(function() {
  5877. movePastedData();
  5878. pasting = false;
  5879. }, 0);
  5880. });
  5881. });
  5882. self.beforeGetHtml(function(html) {
  5883. if (_IE && _V <= 8) {
  5884. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  5885. return unescape(tag);
  5886. });
  5887. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  5888. if (!/\s+type="[^"]+"/i.test($0)) {
  5889. return $1 + ' type="text"' + $2;
  5890. }
  5891. return $0;
  5892. });
  5893. }
  5894. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  5895. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  5896. })
  5897. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  5898. var imgAttrs = _getAttrList(full);
  5899. var styles = _getCssList(imgAttrs.style || '');
  5900. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  5901. var width = _undef(styles.width, '');
  5902. var height = _undef(styles.height, '');
  5903. if (/px/i.test(width)) {
  5904. width = _removeUnit(width);
  5905. }
  5906. if (/px/i.test(height)) {
  5907. height = _removeUnit(height);
  5908. }
  5909. attrs.width = _undef(imgAttrs.width, width);
  5910. attrs.height = _undef(imgAttrs.height, height);
  5911. return _mediaEmbed(attrs);
  5912. })
  5913. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  5914. var imgAttrs = _getAttrList(full);
  5915. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  5916. })
  5917. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  5918. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  5919. })
  5920. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  5921. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  5922. })
  5923. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  5924. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  5925. return $1 + _unescape(src) + $2;
  5926. });
  5927. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  5928. return full;
  5929. })
  5930. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  5931. return start + end;
  5932. });
  5933. });
  5934. self.beforeSetHtml(function(html) {
  5935. if (_IE && _V <= 8) {
  5936. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  5937. var attrs = _getAttrList(full);
  5938. var styles = _getCssList(attrs.style || '');
  5939. if (styles.display == 'none') {
  5940. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  5941. }
  5942. return full;
  5943. });
  5944. }
  5945. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  5946. var attrs = _getAttrList(full);
  5947. attrs.src = _undef(attrs.src, '');
  5948. attrs.width = _undef(attrs.width, 0);
  5949. attrs.height = _undef(attrs.height, 0);
  5950. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  5951. })
  5952. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  5953. var attrs = _getAttrList(full);
  5954. if (attrs.href !== undefined) {
  5955. return full;
  5956. }
  5957. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  5958. })
  5959. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  5960. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5961. })
  5962. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  5963. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  5964. })
  5965. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  5966. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  5967. return full;
  5968. }
  5969. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  5970. return full;
  5971. })
  5972. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  5973. return start + 'data-ke-' + end;
  5974. })
  5975. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  5976. if (full.indexOf('ke-zeroborder') >= 0) {
  5977. return full;
  5978. }
  5979. return _addClassToTag(full, 'ke-zeroborder');
  5980. });
  5981. });
  5982. });
  5983. })(window);
  5984. /*******************************************************************************
  5985. * KindEditor - WYSIWYG HTML Editor for Internet
  5986. * Copyright (C) 2006-2011 kindsoft.net
  5987. *
  5988. * @author Roddy <luolonghao@gmail.com>
  5989. * @site http://www.kindsoft.net/
  5990. * @licence http://www.kindsoft.net/license.php
  5991. *******************************************************************************/
  5992. KindEditor.lang({
  5993. source : 'HTML代码',
  5994. preview : '预览',
  5995. undo : '后退(Ctrl+Z)',
  5996. redo : '前进(Ctrl+Y)',
  5997. cut : '剪切(Ctrl+X)',
  5998. copy : '复制(Ctrl+C)',
  5999. paste : '粘贴(Ctrl+V)',
  6000. plainpaste : '粘贴为无格式文本',
  6001. wordpaste : '从Word粘贴',
  6002. selectall : '全选(Ctrl+A)',
  6003. justifyleft : '左对齐',
  6004. justifycenter : '居中',
  6005. justifyright : '右对齐',
  6006. justifyfull : '两端对齐',
  6007. insertorderedlist : '编号',
  6008. insertunorderedlist : '项目符号',
  6009. indent : '增加缩进',
  6010. outdent : '减少缩进',
  6011. subscript : '下标',
  6012. superscript : '上标',
  6013. formatblock : '段落',
  6014. fontname : '字体',
  6015. fontsize : '文字大小',
  6016. forecolor : '文字颜色',
  6017. hilitecolor : '文字背景',
  6018. bold : '粗体(Ctrl+B)',
  6019. italic : '斜体(Ctrl+I)',
  6020. underline : '下划线(Ctrl+U)',
  6021. strikethrough : '删除线',
  6022. removeformat : '删除格式',
  6023. image : '图片',
  6024. multiimage : '批量图片上传',
  6025. flash : 'Flash',
  6026. media : '视音频',
  6027. table : '表格',
  6028. tablecell : '单元格',
  6029. hr : '插入横线',
  6030. emoticons : '插入表情',
  6031. link : '超级链接',
  6032. unlink : '取消超级链接',
  6033. fullscreen : '全屏显示',
  6034. about : '关于',
  6035. print : '打印(Ctrl+P)',
  6036. filemanager : '文件空间',
  6037. code : '插入程序代码',
  6038. map : 'Google地图',
  6039. baidumap : '百度地图',
  6040. lineheight : '行距',
  6041. clearhtml : '清理HTML代码',
  6042. pagebreak : '插入分页符',
  6043. quickformat : '一键排版',
  6044. insertfile : '插入文件',
  6045. template : '插入模板',
  6046. anchor : '锚点',
  6047. yes : '确定',
  6048. no : '取消',
  6049. close : '关闭',
  6050. editImage : '图片属性',
  6051. deleteImage : '删除图片',
  6052. editFlash : 'Flash属性',
  6053. deleteFlash : '删除Flash',
  6054. editMedia : '视音频属性',
  6055. deleteMedia : '删除视音频',
  6056. editLink : '超级链接属性',
  6057. deleteLink : '取消超级链接',
  6058. editAnchor : '锚点属性',
  6059. deleteAnchor : '删除锚点',
  6060. tableprop : '表格属性',
  6061. tablecellprop : '单元格属性',
  6062. tableinsert : '插入表格',
  6063. tabledelete : '删除表格',
  6064. tablecolinsertleft : '左侧插入列',
  6065. tablecolinsertright : '右侧插入列',
  6066. tablerowinsertabove : '上方插入行',
  6067. tablerowinsertbelow : '下方插入行',
  6068. tablerowmerge : '向下合并单元格',
  6069. tablecolmerge : '向右合并单元格',
  6070. tablerowsplit : '拆分行',
  6071. tablecolsplit : '拆分列',
  6072. tablecoldelete : '删除列',
  6073. tablerowdelete : '删除行',
  6074. noColor : '无颜色',
  6075. pleaseSelectFile : '请选择文件。',
  6076. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6077. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6078. invalidWidth : "宽度必须为数字。",
  6079. invalidHeight : "高度必须为数字。",
  6080. invalidBorder : "边框必须为数字。",
  6081. invalidUrl : "请输入有效的URL地址。",
  6082. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6083. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6084. invalidPadding : '边距必须为数字。',
  6085. invalidSpacing : '间距必须为数字。',
  6086. invalidJson : '服务器发生故障。',
  6087. uploadSuccess : '上传成功。',
  6088. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6089. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6090. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6091. ajaxLoading : '加载中,请稍候 ...',
  6092. uploadLoading : '上传中,请稍候 ...',
  6093. uploadError : '上传错误',
  6094. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6095. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6096. 'code.pleaseInput' : '请输入程序代码。',
  6097. 'link.url' : 'URL',
  6098. 'link.linkType' : '打开类型',
  6099. 'link.newWindow' : '新窗口',
  6100. 'link.selfWindow' : '当前窗口',
  6101. 'flash.url' : 'URL',
  6102. 'flash.width' : '宽度',
  6103. 'flash.height' : '高度',
  6104. 'flash.upload' : '上传',
  6105. 'flash.viewServer' : '文件空间',
  6106. 'media.url' : 'URL',
  6107. 'media.width' : '宽度',
  6108. 'media.height' : '高度',
  6109. 'media.autostart' : '自动播放',
  6110. 'media.upload' : '上传',
  6111. 'media.viewServer' : '文件空间',
  6112. 'image.remoteImage' : '图片属性',
  6113. 'image.localImage' : '本地上传',
  6114. 'image.remoteUrl' : '图片地址',
  6115. 'image.localUrl' : '上传文件',
  6116. 'image.size' : '图片大小',
  6117. 'image.width' : '宽',
  6118. 'image.height' : '高',
  6119. 'image.resetSize' : '重置大小',
  6120. 'image.align' : '对齐方式',
  6121. 'image.defaultAlign' : '默认方式',
  6122. 'image.leftAlign' : '左对齐',
  6123. 'image.rightAlign' : '右对齐',
  6124. 'image.imgTitle' : '图片说明',
  6125. 'image.upload' : '浏览...',
  6126. 'image.viewServer' : '图片空间',
  6127. 'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6128. 'multiimage.startUpload' : '开始上传',
  6129. 'multiimage.clearAll' : '全部清空',
  6130. 'multiimage.insertAll' : '全部插入',
  6131. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6132. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6133. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6134. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6135. 'multiimage.unknownError' : '发生异常,无法上传。',
  6136. 'multiimage.pending' : '等待上传',
  6137. 'multiimage.uploadError' : '上传失败',
  6138. 'filemanager.emptyFolder' : '空文件夹',
  6139. 'filemanager.moveup' : '移到上一级文件夹',
  6140. 'filemanager.viewType' : '显示方式:',
  6141. 'filemanager.viewImage' : '缩略图',
  6142. 'filemanager.listImage' : '详细信息',
  6143. 'filemanager.orderType' : '排序方式:',
  6144. 'filemanager.fileName' : '名称',
  6145. 'filemanager.fileSize' : '大小',
  6146. 'filemanager.fileType' : '类型',
  6147. 'insertfile.url' : 'URL',
  6148. 'insertfile.title' : '文件说明',
  6149. 'insertfile.upload' : '上传',
  6150. 'insertfile.viewServer' : '文件空间',
  6151. 'table.cells' : '单元格数',
  6152. 'table.rows' : '行数',
  6153. 'table.cols' : '列数',
  6154. 'table.size' : '大小',
  6155. 'table.width' : '宽度',
  6156. 'table.height' : '高度',
  6157. 'table.percent' : '%',
  6158. 'table.px' : 'px',
  6159. 'table.space' : '边距间距',
  6160. 'table.padding' : '边距',
  6161. 'table.spacing' : '间距',
  6162. 'table.align' : '对齐方式',
  6163. 'table.textAlign' : '水平对齐',
  6164. 'table.verticalAlign' : '垂直对齐',
  6165. 'table.alignDefault' : '默认',
  6166. 'table.alignLeft' : '左对齐',
  6167. 'table.alignCenter' : '居中',
  6168. 'table.alignRight' : '右对齐',
  6169. 'table.alignTop' : '顶部',
  6170. 'table.alignMiddle' : '中部',
  6171. 'table.alignBottom' : '底部',
  6172. 'table.alignBaseline' : '基线',
  6173. 'table.border' : '边框',
  6174. 'table.borderWidth' : '边框',
  6175. 'table.borderColor' : '颜色',
  6176. 'table.backgroundColor' : '背景颜色',
  6177. 'map.address' : '地址: ',
  6178. 'map.search' : '搜索',
  6179. 'baidumap.address' : '地址: ',
  6180. 'baidumap.search' : '搜索',
  6181. 'baidumap.insertDynamicMap' : '插入动态地图',
  6182. 'anchor.name' : '锚点名称',
  6183. 'formatblock.formatBlock' : {
  6184. h1 : '标题 1',
  6185. h2 : '标题 2',
  6186. h3 : '标题 3',
  6187. h4 : '标题 4',
  6188. p : '正 文'
  6189. },
  6190. 'fontname.fontName' : {
  6191. 'SimSun' : '宋体',
  6192. 'NSimSun' : '新宋体',
  6193. 'FangSong_GB2312' : '仿宋_GB2312',
  6194. 'KaiTi_GB2312' : '楷体_GB2312',
  6195. 'SimHei' : '黑体',
  6196. 'Microsoft YaHei' : '微软雅黑',
  6197. 'Arial' : 'Arial',
  6198. 'Arial Black' : 'Arial Black',
  6199. 'Times New Roman' : 'Times New Roman',
  6200. 'Courier New' : 'Courier New',
  6201. 'Tahoma' : 'Tahoma',
  6202. 'Verdana' : 'Verdana'
  6203. },
  6204. 'lineheight.lineHeight' : [
  6205. {'1' : '单倍行距'},
  6206. {'1.5' : '1.5倍行距'},
  6207. {'2' : '2倍行距'},
  6208. {'2.5' : '2.5倍行距'},
  6209. {'3' : '3倍行距'}
  6210. ],
  6211. 'template.selectTemplate' : '可选模板',
  6212. 'template.replaceContent' : '替换当前内容',
  6213. 'template.fileList' : {
  6214. '1.html' : '图片和文字',
  6215. '2.html' : '表格',
  6216. '3.html' : '项目编号'
  6217. }
  6218. }, 'zh-CN');
  6219. KindEditor.options.langType = 'zh-CN';
  6220. /*******************************************************************************
  6221. * KindEditor - WYSIWYG HTML Editor for Internet
  6222. * Copyright (C) 2006-2011 kindsoft.net
  6223. *
  6224. * @author Roddy <luolonghao@gmail.com>
  6225. * @site http://www.kindsoft.net/
  6226. * @licence http://www.kindsoft.net/license.php
  6227. *******************************************************************************/
  6228. KindEditor.plugin('anchor', function(K) {
  6229. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6230. self.plugin.anchor = {
  6231. edit : function() {
  6232. var html = ['<div style="padding:20px;">',
  6233. '<div class="ke-dialog-row">',
  6234. '<label for="keName">' + lang.name + '</label>',
  6235. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6236. '</div>',
  6237. '</div>'].join('');
  6238. var dialog = self.createDialog({
  6239. name : name,
  6240. width : 300,
  6241. title : self.lang(name),
  6242. body : html,
  6243. yesBtn : {
  6244. name : self.lang('yes'),
  6245. click : function(e) {
  6246. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6247. }
  6248. }
  6249. });
  6250. var div = dialog.div,
  6251. nameBox = K('input[name="name"]', div);
  6252. var img = self.plugin.getSelectedAnchor();
  6253. if (img) {
  6254. nameBox.val(unescape(img.attr('data-ke-name')));
  6255. }
  6256. nameBox[0].focus();
  6257. nameBox[0].select();
  6258. },
  6259. 'delete' : function() {
  6260. self.plugin.getSelectedAnchor().remove();
  6261. }
  6262. };
  6263. self.clickToolbar(name, self.plugin.anchor.edit);
  6264. });
  6265. /*******************************************************************************
  6266. * KindEditor - WYSIWYG HTML Editor for Internet
  6267. * Copyright (C) 2006-2011 kindsoft.net
  6268. *
  6269. * @author Roddy <luolonghao@gmail.com>
  6270. * @site http://www.kindsoft.net/
  6271. * @licence http://www.kindsoft.net/license.php
  6272. *******************************************************************************/
  6273. KindEditor.plugin('autoheight', function(K) {
  6274. var self = this;
  6275. if (!self.autoHeightMode) {
  6276. return;
  6277. }
  6278. var minHeight;
  6279. function hideScroll() {
  6280. var edit = self.edit;
  6281. var body = edit.doc.body;
  6282. edit.iframe[0].scroll = 'no';
  6283. body.style.overflowY = 'hidden';
  6284. }
  6285. function resetHeight() {
  6286. var edit = self.edit;
  6287. var body = edit.doc.body;
  6288. edit.iframe.height(minHeight);
  6289. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6290. }
  6291. function init() {
  6292. minHeight = K.removeUnit(self.height);
  6293. self.edit.afterChange(resetHeight);
  6294. hideScroll();
  6295. resetHeight();
  6296. }
  6297. if (self.isCreated) {
  6298. init();
  6299. } else {
  6300. self.afterCreate(init);
  6301. }
  6302. });
  6303. /*
  6304. * 如何实现真正的自动高度?
  6305. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6306. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6307. * 由此就实现了真正的自动高度
  6308. * 测试:chrome、firefox、IE9、IE8
  6309. * */
  6310. /*******************************************************************************
  6311. * KindEditor - WYSIWYG HTML Editor for Internet
  6312. * Copyright (C) 2006-2011 kindsoft.net
  6313. *
  6314. * @author Roddy <luolonghao@gmail.com>
  6315. * @site http://www.kindsoft.net/
  6316. * @licence http://www.kindsoft.net/license.php
  6317. *******************************************************************************/
  6318. KindEditor.plugin('baidumap', function(K) {
  6319. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6320. var mapWidth = K.undef(self.mapWidth, 558);
  6321. var mapHeight = K.undef(self.mapHeight, 360);
  6322. self.clickToolbar(name, function() {
  6323. var html = ['<div style="padding:10px 20px;">',
  6324. '<div class="ke-header">',
  6325. '<div class="ke-left">',
  6326. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6327. '<span class="ke-button-common ke-button-outer">',
  6328. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6329. '</span>',
  6330. '</div>',
  6331. '<div class="ke-right">',
  6332. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6333. '</div>',
  6334. '<div class="ke-clearfix"></div>',
  6335. '</div>',
  6336. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6337. '</div>'].join('');
  6338. var dialog = self.createDialog({
  6339. name : name,
  6340. width : mapWidth + 42,
  6341. title : self.lang(name),
  6342. body : html,
  6343. yesBtn : {
  6344. name : self.lang('yes'),
  6345. click : function(e) {
  6346. var map = win.map;
  6347. var centerObj = map.getCenter();
  6348. var center = centerObj.lng + ',' + centerObj.lat;
  6349. var zoom = map.getZoom();
  6350. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6351. '?center=' + encodeURIComponent(center),
  6352. '&zoom=' + encodeURIComponent(zoom),
  6353. '&width=' + mapWidth,
  6354. '&height=' + mapHeight,
  6355. '&markers=' + encodeURIComponent(center),
  6356. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6357. if (checkbox[0].checked) {
  6358. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6359. } else {
  6360. self.exec('insertimage', url);
  6361. }
  6362. self.hideDialog().focus();
  6363. }
  6364. },
  6365. beforeRemove : function() {
  6366. searchBtn.remove();
  6367. if (doc) {
  6368. doc.write('');
  6369. }
  6370. iframe.remove();
  6371. }
  6372. });
  6373. var div = dialog.div,
  6374. addressBox = K('[name="address"]', div),
  6375. searchBtn = K('[name="searchBtn"]', div),
  6376. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6377. win, doc;
  6378. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6379. function ready() {
  6380. win = iframe[0].contentWindow;
  6381. doc = K.iframeDoc(iframe);
  6382. }
  6383. iframe.bind('load', function() {
  6384. iframe.unbind('load');
  6385. if (K.IE) {
  6386. ready();
  6387. } else {
  6388. setTimeout(ready, 0);
  6389. }
  6390. });
  6391. K('.ke-map', div).replaceWith(iframe);
  6392. searchBtn.click(function() {
  6393. win.search(addressBox.val());
  6394. });
  6395. });
  6396. });
  6397. /*******************************************************************************
  6398. * KindEditor - WYSIWYG HTML Editor for Internet
  6399. * Copyright (C) 2006-2011 kindsoft.net
  6400. *
  6401. * @author Roddy <luolonghao@gmail.com>
  6402. * @site http://www.kindsoft.net/
  6403. * @licence http://www.kindsoft.net/license.php
  6404. *******************************************************************************/
  6405. KindEditor.plugin('map', function(K) {
  6406. var self = this, name = 'map', lang = self.lang(name + '.');
  6407. self.clickToolbar(name, function() {
  6408. var html = ['<div style="padding:10px 20px;">',
  6409. '<div class="ke-dialog-row">',
  6410. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6411. '<span class="ke-button-common ke-button-outer">',
  6412. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6413. '</span>',
  6414. '</div>',
  6415. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  6416. '</div>'].join('');
  6417. var dialog = self.createDialog({
  6418. name : name,
  6419. width : 600,
  6420. title : self.lang(name),
  6421. body : html,
  6422. yesBtn : {
  6423. name : self.lang('yes'),
  6424. click : function(e) {
  6425. var geocoder = win.geocoder,
  6426. map = win.map,
  6427. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  6428. zoom = map.getZoom(),
  6429. maptype = map.getMapTypeId(),
  6430. url = 'http://maps.googleapis.com/maps/api/staticmap';
  6431. url += '?center=' + encodeURIComponent(center);
  6432. url += '&zoom=' + encodeURIComponent(zoom);
  6433. url += '&size=558x360';
  6434. url += '&maptype=' + encodeURIComponent(maptype);
  6435. url += '&markers=' + encodeURIComponent(center);
  6436. url += '&language=' + self.langType;
  6437. url += '&sensor=false';
  6438. self.exec('insertimage', url).hideDialog().focus();
  6439. }
  6440. },
  6441. beforeRemove : function() {
  6442. searchBtn.remove();
  6443. if (doc) {
  6444. doc.write('');
  6445. }
  6446. iframe.remove();
  6447. }
  6448. });
  6449. var div = dialog.div,
  6450. addressBox = K('[name="address"]', div),
  6451. searchBtn = K('[name="searchBtn"]', div),
  6452. win, doc;
  6453. var iframeHtml = ['<!doctype html><html><head>',
  6454. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  6455. '<style>',
  6456. ' html { height: 100% }',
  6457. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  6458. ' #map_canvas { height: 100% }',
  6459. '</style>',
  6460. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  6461. '<script>',
  6462. 'var map, geocoder;',
  6463. 'function initialize() {',
  6464. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  6465. ' var options = {',
  6466. ' zoom: 11,',
  6467. ' center: latlng,',
  6468. ' disableDefaultUI: true,',
  6469. ' panControl: true,',
  6470. ' zoomControl: true,',
  6471. ' mapTypeControl: true,',
  6472. ' scaleControl: true,',
  6473. ' streetViewControl: false,',
  6474. ' overviewMapControl: true,',
  6475. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  6476. ' };',
  6477. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  6478. ' geocoder = new google.maps.Geocoder();',
  6479. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  6480. ' if (status == google.maps.GeocoderStatus.OK) {',
  6481. ' if (results[3]) {',
  6482. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  6483. ' }',
  6484. ' }',
  6485. ' });',
  6486. '}',
  6487. 'function search(address) {',
  6488. ' if (!map) return;',
  6489. ' geocoder.geocode({address : address}, function(results, status) {',
  6490. ' if (status == google.maps.GeocoderStatus.OK) {',
  6491. ' map.setZoom(11);',
  6492. ' map.setCenter(results[0].geometry.location);',
  6493. ' var marker = new google.maps.Marker({',
  6494. ' map: map,',
  6495. ' position: results[0].geometry.location',
  6496. ' });',
  6497. ' } else {',
  6498. ' alert("Invalid address: " + address);',
  6499. ' }',
  6500. ' });',
  6501. '}',
  6502. '</script>',
  6503. '</head>',
  6504. '<body onload="initialize();">',
  6505. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  6506. '</body></html>'].join('\n');
  6507. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  6508. function ready() {
  6509. win = iframe[0].contentWindow;
  6510. doc = K.iframeDoc(iframe);
  6511. }
  6512. iframe.bind('load', function() {
  6513. iframe.unbind('load');
  6514. if (K.IE) {
  6515. ready();
  6516. } else {
  6517. setTimeout(ready, 0);
  6518. }
  6519. });
  6520. K('.ke-map', div).replaceWith(iframe);
  6521. searchBtn.click(function() {
  6522. win.search(addressBox.val());
  6523. });
  6524. });
  6525. });
  6526. /*******************************************************************************
  6527. * KindEditor - WYSIWYG HTML Editor for Internet
  6528. * Copyright (C) 2006-2011 kindsoft.net
  6529. *
  6530. * @author Roddy <luolonghao@gmail.com>
  6531. * @site http://www.kindsoft.net/
  6532. * @licence http://www.kindsoft.net/license.php
  6533. *******************************************************************************/
  6534. KindEditor.plugin('clearhtml', function(K) {
  6535. var self = this, name = 'clearhtml';
  6536. self.clickToolbar(name, function() {
  6537. self.focus();
  6538. var html = self.html();
  6539. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6540. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6541. html = K.formatHtml(html, {
  6542. a : ['href', 'target'],
  6543. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6544. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6545. table : ['border'],
  6546. 'td,th' : ['rowspan', 'colspan'],
  6547. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6548. });
  6549. self.html(html);
  6550. self.cmd.selection(true);
  6551. self.addBookmark();
  6552. });
  6553. });
  6554. /*******************************************************************************
  6555. * KindEditor - WYSIWYG HTML Editor for Internet
  6556. * Copyright (C) 2006-2011 kindsoft.net
  6557. *
  6558. * @author Roddy <luolonghao@gmail.com>
  6559. * @site http://www.kindsoft.net/
  6560. * @licence http://www.kindsoft.net/license.php
  6561. *******************************************************************************/
  6562. KindEditor.plugin('code', function(K) {
  6563. var self = this, name = 'code';
  6564. self.clickToolbar(name, function() {
  6565. var lang = self.lang(name + '.'),
  6566. html = ['<div style="padding:10px 20px;">',
  6567. '<div class="ke-dialog-row">',
  6568. '<select class="ke-code-type">',
  6569. '<option value="js">JavaScript</option>',
  6570. '<option value="html">HTML</option>',
  6571. '<option value="css">CSS</option>',
  6572. '<option value="php">PHP</option>',
  6573. '<option value="pl">Perl</option>',
  6574. '<option value="py">Python</option>',
  6575. '<option value="rb">Ruby</option>',
  6576. '<option value="java">Java</option>',
  6577. '<option value="vb">ASP/VB</option>',
  6578. '<option value="cpp">C/C++</option>',
  6579. '<option value="cs">C#</option>',
  6580. '<option value="xml">XML</option>',
  6581. '<option value="bsh">Shell</option>',
  6582. '<option value="">Other</option>',
  6583. '</select>',
  6584. '</div>',
  6585. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6586. '</div>'].join(''),
  6587. dialog = self.createDialog({
  6588. name : name,
  6589. width : 450,
  6590. title : self.lang(name),
  6591. body : html,
  6592. yesBtn : {
  6593. name : self.lang('yes'),
  6594. click : function(e) {
  6595. var type = K('.ke-code-type', dialog.div).val(),
  6596. code = textarea.val(),
  6597. cls = type === '' ? '' : ' lang-' + type,
  6598. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6599. if (K.trim(code) === '') {
  6600. alert(lang.pleaseInput);
  6601. textarea[0].focus();
  6602. return;
  6603. }
  6604. self.insertHtml(html).hideDialog().focus();
  6605. }
  6606. }
  6607. }),
  6608. textarea = K('textarea', dialog.div);
  6609. textarea[0].focus();
  6610. });
  6611. });
  6612. /*******************************************************************************
  6613. * KindEditor - WYSIWYG HTML Editor for Internet
  6614. * Copyright (C) 2006-2011 kindsoft.net
  6615. *
  6616. * @author Roddy <luolonghao@gmail.com>
  6617. * @site http://www.kindsoft.net/
  6618. * @licence http://www.kindsoft.net/license.php
  6619. *******************************************************************************/
  6620. KindEditor.plugin('emoticons', function(K) {
  6621. var self = this, name = 'emoticons',
  6622. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6623. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6624. currentPageNum = 1;
  6625. self.clickToolbar(name, function() {
  6626. var rows = 5, cols = 9, total = 135, startNum = 0,
  6627. cells = rows * cols, pages = Math.ceil(total / cells),
  6628. colsHalf = Math.floor(cols / 2),
  6629. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6630. elements = [],
  6631. menu = self.createMenu({
  6632. name : name,
  6633. beforeRemove : function() {
  6634. removeEvent();
  6635. }
  6636. });
  6637. menu.div.append(wrapperDiv);
  6638. var previewDiv, previewImg;
  6639. if (allowPreview) {
  6640. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6641. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6642. wrapperDiv.append(previewDiv);
  6643. previewDiv.append(previewImg);
  6644. }
  6645. function bindCellEvent(cell, j, num) {
  6646. if (previewDiv) {
  6647. cell.mouseover(function() {
  6648. if (j > colsHalf) {
  6649. previewDiv.css('left', 0);
  6650. previewDiv.css('right', '');
  6651. } else {
  6652. previewDiv.css('left', '');
  6653. previewDiv.css('right', 0);
  6654. }
  6655. previewImg.attr('src', path + num + '.gif');
  6656. K(this).addClass('ke-on');
  6657. });
  6658. } else {
  6659. cell.mouseover(function() {
  6660. K(this).addClass('ke-on');
  6661. });
  6662. }
  6663. cell.mouseout(function() {
  6664. K(this).removeClass('ke-on');
  6665. });
  6666. cell.click(function(e) {
  6667. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6668. e.stop();
  6669. });
  6670. }
  6671. function createEmoticonsTable(pageNum, parentDiv) {
  6672. var table = document.createElement('table');
  6673. parentDiv.append(table);
  6674. if (previewDiv) {
  6675. K(table).mouseover(function() {
  6676. previewDiv.show('block');
  6677. });
  6678. K(table).mouseout(function() {
  6679. previewDiv.hide();
  6680. });
  6681. elements.push(K(table));
  6682. }
  6683. table.className = 'ke-table';
  6684. table.cellPadding = 0;
  6685. table.cellSpacing = 0;
  6686. table.border = 0;
  6687. var num = (pageNum - 1) * cells + startNum;
  6688. for (var i = 0; i < rows; i++) {
  6689. var row = table.insertRow(i);
  6690. for (var j = 0; j < cols; j++) {
  6691. var cell = K(row.insertCell(j));
  6692. cell.addClass('ke-cell');
  6693. bindCellEvent(cell, j, num);
  6694. var span = K('<span class="ke-img"></span>')
  6695. .css('background-position', '-' + (24 * num) + 'px 0px')
  6696. .css('background-image', 'url(' + path + 'static.gif)');
  6697. cell.append(span);
  6698. elements.push(cell);
  6699. num++;
  6700. }
  6701. }
  6702. return table;
  6703. }
  6704. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6705. function removeEvent() {
  6706. K.each(elements, function() {
  6707. this.unbind();
  6708. });
  6709. }
  6710. var pageDiv;
  6711. function bindPageEvent(el, pageNum) {
  6712. el.click(function(e) {
  6713. removeEvent();
  6714. table.parentNode.removeChild(table);
  6715. pageDiv.remove();
  6716. table = createEmoticonsTable(pageNum, wrapperDiv);
  6717. createPageTable(pageNum);
  6718. currentPageNum = pageNum;
  6719. e.stop();
  6720. });
  6721. }
  6722. function createPageTable(currentPageNum) {
  6723. pageDiv = K('<div class="ke-page"></div>');
  6724. wrapperDiv.append(pageDiv);
  6725. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6726. if (currentPageNum !== pageNum) {
  6727. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6728. bindPageEvent(a, pageNum);
  6729. pageDiv.append(a);
  6730. elements.push(a);
  6731. } else {
  6732. pageDiv.append(K('@[' + pageNum + ']'));
  6733. }
  6734. pageDiv.append(K('@&nbsp;'));
  6735. }
  6736. }
  6737. createPageTable(currentPageNum);
  6738. });
  6739. });
  6740. /*******************************************************************************
  6741. * KindEditor - WYSIWYG HTML Editor for Internet
  6742. * Copyright (C) 2006-2011 kindsoft.net
  6743. *
  6744. * @author Roddy <luolonghao@gmail.com>
  6745. * @site http://www.kindsoft.net/
  6746. * @licence http://www.kindsoft.net/license.php
  6747. *******************************************************************************/
  6748. KindEditor.plugin('filemanager', function(K) {
  6749. var self = this, name = 'filemanager',
  6750. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6751. imgPath = self.pluginsPath + name + '/images/',
  6752. lang = self.lang(name + '.');
  6753. function makeFileTitle(filename, filesize, datetime) {
  6754. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6755. }
  6756. function bindTitle(el, data) {
  6757. if (data.is_dir) {
  6758. el.attr('title', data.filename);
  6759. } else {
  6760. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6761. }
  6762. }
  6763. self.plugin.filemanagerDialog = function(options) {
  6764. var width = K.undef(options.width, 650),
  6765. height = K.undef(options.height, 510),
  6766. dirName = K.undef(options.dirName, ''),
  6767. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(),
  6768. clickFn = options.clickFn;
  6769. var html = [
  6770. '<div style="padding:10px 20px;">',
  6771. '<div class="ke-plugin-filemanager-header">',
  6772. '<div class="ke-left">',
  6773. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6774. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6775. '</div>',
  6776. '<div class="ke-right">',
  6777. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6778. '<option value="VIEW">' + lang.viewImage + '</option>',
  6779. '<option value="LIST">' + lang.listImage + '</option>',
  6780. '</select> ',
  6781. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6782. '<option value="NAME">' + lang.fileName + '</option>',
  6783. '<option value="SIZE">' + lang.fileSize + '</option>',
  6784. '<option value="TYPE">' + lang.fileType + '</option>',
  6785. '</select>',
  6786. '</div>',
  6787. '<div class="ke-clearfix"></div>',
  6788. '</div>',
  6789. '<div class="ke-plugin-filemanager-body"></div>',
  6790. '</div>'
  6791. ].join('');
  6792. var dialog = self.createDialog({
  6793. name : name,
  6794. width : width,
  6795. height : height,
  6796. title : self.lang(name),
  6797. body : html
  6798. }),
  6799. div = dialog.div,
  6800. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6801. moveupImg = K('[name="moveupImg"]', div),
  6802. moveupLink = K('[name="moveupLink"]', div),
  6803. viewServerBtn = K('[name="viewServer"]', div),
  6804. viewTypeBox = K('[name="viewType"]', div),
  6805. orderTypeBox = K('[name="orderType"]', div);
  6806. function reloadPage(path, order, func) {
  6807. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName + '&datetime' + new Date().getTime().toString();
  6808. dialog.showLoading(self.lang('ajaxLoading'));
  6809. K.ajax(K.addParam(fileManagerJson, param), function(data) {
  6810. dialog.hideLoading();
  6811. func(data);
  6812. });
  6813. }
  6814. var elList = [];
  6815. function bindEvent(el, result, data, createFunc) {
  6816. var fileUrl = K.formatUrl(result.current_url + data.filename, 'absolute'),
  6817. dirPath = encodeURIComponent(result.current_dir_path + data.filename + '/');
  6818. if (data.is_dir) {
  6819. el.click(function(e) {
  6820. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6821. });
  6822. } else if (data.is_photo) {
  6823. el.click(function(e) {
  6824. clickFn.call(this, fileUrl, data.filename);
  6825. });
  6826. } else {
  6827. el.click(function(e) {
  6828. clickFn.call(this, fileUrl, data.filename);
  6829. });
  6830. }
  6831. elList.push(el);
  6832. }
  6833. function createCommon(result, createFunc) {
  6834. K.each(elList, function() {
  6835. this.unbind();
  6836. });
  6837. moveupLink.unbind();
  6838. viewTypeBox.unbind();
  6839. orderTypeBox.unbind();
  6840. if (result.current_dir_path) {
  6841. moveupLink.click(function(e) {
  6842. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  6843. });
  6844. }
  6845. function changeFunc() {
  6846. if (viewTypeBox.val() == 'VIEW') {
  6847. reloadPage(result.current_dir_path, orderTypeBox.val(), createView);
  6848. } else {
  6849. reloadPage(result.current_dir_path, orderTypeBox.val(), createList);
  6850. }
  6851. }
  6852. viewTypeBox.change(changeFunc);
  6853. orderTypeBox.change(changeFunc);
  6854. bodyDiv.html('');
  6855. }
  6856. function createList(result) {
  6857. createCommon(result, createList);
  6858. var table = document.createElement('table');
  6859. table.className = 'ke-table';
  6860. table.cellPadding = 0;
  6861. table.cellSpacing = 0;
  6862. table.border = 0;
  6863. bodyDiv.append(table);
  6864. var fileList = result.file_list;
  6865. for (var i = 0, len = fileList.length; i < len; i++) {
  6866. var data = fileList[i], row = K(table.insertRow(i));
  6867. row.mouseover(function(e) {
  6868. K(this).addClass('ke-on');
  6869. })
  6870. .mouseout(function(e) {
  6871. K(this).removeClass('ke-on');
  6872. });
  6873. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  6874. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  6875. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  6876. if (!data.is_dir || data.has_file) {
  6877. row.css('cursor', 'pointer');
  6878. cell0.attr('title', data.filename);
  6879. bindEvent(cell0, result, data, createList);
  6880. } else {
  6881. cell0.attr('title', lang.emptyFolder);
  6882. }
  6883. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  6884. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  6885. }
  6886. }
  6887. function createView(result) {
  6888. createCommon(result, createView);
  6889. var fileList = result.file_list;
  6890. for (var i = 0, len = fileList.length; i < len; i++) {
  6891. var data = fileList[i],
  6892. div = K('<div class="ke-inline-block ke-item"></div>');
  6893. bodyDiv.append(div);
  6894. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  6895. .mouseover(function(e) {
  6896. K(this).addClass('ke-on');
  6897. })
  6898. .mouseout(function(e) {
  6899. K(this).removeClass('ke-on');
  6900. });
  6901. div.append(photoDiv);
  6902. var fileUrl = result.current_url + data.filename,
  6903. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  6904. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  6905. if (!data.is_dir || data.has_file) {
  6906. photoDiv.css('cursor', 'pointer');
  6907. bindTitle(photoDiv, data);
  6908. bindEvent(photoDiv, result, data, createView);
  6909. } else {
  6910. photoDiv.attr('title', lang.emptyFolder);
  6911. }
  6912. photoDiv.append(img);
  6913. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  6914. }
  6915. }
  6916. viewTypeBox.val(viewType);
  6917. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  6918. return dialog;
  6919. }
  6920. });
  6921. /*******************************************************************************
  6922. * KindEditor - WYSIWYG HTML Editor for Internet
  6923. * Copyright (C) 2006-2011 kindsoft.net
  6924. *
  6925. * @author Roddy <luolonghao@gmail.com>
  6926. * @site http://www.kindsoft.net/
  6927. * @licence http://www.kindsoft.net/license.php
  6928. *******************************************************************************/
  6929. KindEditor.plugin('flash', function(K) {
  6930. var self = this, name = 'flash', lang = self.lang(name + '.'),
  6931. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  6932. allowFileManager = K.undef(self.allowFileManager, false),
  6933. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  6934. extraParams = K.undef(self.extraFileUploadParams, {}),
  6935. filePostName = K.undef(self.filePostName, 'imgFile'),
  6936. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  6937. self.plugin.flash = {
  6938. edit : function() {
  6939. var html = [
  6940. '<div style="padding:20px;">',
  6941. '<div class="ke-dialog-row">',
  6942. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  6943. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  6944. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  6945. '<span class="ke-button-common ke-button-outer">',
  6946. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  6947. '</span>',
  6948. '</div>',
  6949. '<div class="ke-dialog-row">',
  6950. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  6951. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  6952. '</div>',
  6953. '<div class="ke-dialog-row">',
  6954. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  6955. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  6956. '</div>',
  6957. '</div>'
  6958. ].join('');
  6959. var dialog = self.createDialog({
  6960. name : name,
  6961. width : 450,
  6962. title : self.lang(name),
  6963. body : html,
  6964. yesBtn : {
  6965. name : self.lang('yes'),
  6966. click : function(e) {
  6967. var url = K.trim(urlBox.val()),
  6968. width = widthBox.val(),
  6969. height = heightBox.val();
  6970. if (url == 'http://' || K.invalidUrl(url)) {
  6971. alert(self.lang('invalidUrl'));
  6972. urlBox[0].focus();
  6973. return;
  6974. }
  6975. if (!/^\d*$/.test(width)) {
  6976. alert(self.lang('invalidWidth'));
  6977. widthBox[0].focus();
  6978. return;
  6979. }
  6980. if (!/^\d*$/.test(height)) {
  6981. alert(self.lang('invalidHeight'));
  6982. heightBox[0].focus();
  6983. return;
  6984. }
  6985. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  6986. src : url,
  6987. type : K.mediaType('.swf'),
  6988. width : width,
  6989. height : height,
  6990. quality : 'high'
  6991. });
  6992. self.insertHtml(html).hideDialog().focus();
  6993. }
  6994. }
  6995. }),
  6996. div = dialog.div,
  6997. urlBox = K('[name="url"]', div),
  6998. viewServerBtn = K('[name="viewServer"]', div),
  6999. widthBox = K('[name="width"]', div),
  7000. heightBox = K('[name="height"]', div);
  7001. urlBox.val('http://');
  7002. if (allowFlashUpload) {
  7003. var uploadbutton = K.uploadbutton({
  7004. button : K('.ke-upload-button', div)[0],
  7005. fieldName : filePostName,
  7006. extraParams : extraParams,
  7007. url : K.addParam(uploadJson, 'dir=flash'),
  7008. afterUpload : function(data) {
  7009. dialog.hideLoading();
  7010. if (data.error === 0) {
  7011. var url = data.url;
  7012. if (formatUploadUrl) {
  7013. url = K.formatUrl(url, 'absolute');
  7014. }
  7015. urlBox.val(url);
  7016. if (self.afterUpload) {
  7017. self.afterUpload.call(self, url, data, name);
  7018. }
  7019. alert(self.lang('uploadSuccess'));
  7020. } else {
  7021. alert(data.message);
  7022. }
  7023. },
  7024. afterError : function(html) {
  7025. dialog.hideLoading();
  7026. self.errorDialog(html);
  7027. }
  7028. });
  7029. uploadbutton.fileBox.change(function(e) {
  7030. dialog.showLoading(self.lang('uploadLoading'));
  7031. uploadbutton.submit();
  7032. });
  7033. } else {
  7034. K('.ke-upload-button', div).hide();
  7035. }
  7036. if (allowFileManager) {
  7037. viewServerBtn.click(function(e) {
  7038. self.loadPlugin('filemanager', function() {
  7039. self.plugin.filemanagerDialog({
  7040. viewType : 'LIST',
  7041. dirName : 'flash',
  7042. clickFn : function(url, title) {
  7043. if (self.dialogs.length > 1) {
  7044. K('[name="url"]', div).val(url);
  7045. if (self.afterSelectFile) {
  7046. self.afterSelectFile.call(self, url);
  7047. }
  7048. self.hideDialog();
  7049. }
  7050. }
  7051. });
  7052. });
  7053. });
  7054. } else {
  7055. viewServerBtn.hide();
  7056. }
  7057. var img = self.plugin.getSelectedFlash();
  7058. if (img) {
  7059. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7060. urlBox.val(attrs.src);
  7061. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7062. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7063. }
  7064. urlBox[0].focus();
  7065. urlBox[0].select();
  7066. },
  7067. 'delete' : function() {
  7068. self.plugin.getSelectedFlash().remove();
  7069. self.addBookmark();
  7070. }
  7071. };
  7072. self.clickToolbar(name, self.plugin.flash.edit);
  7073. });
  7074. /*******************************************************************************
  7075. * KindEditor - WYSIWYG HTML Editor for Internet
  7076. * Copyright (C) 2006-2011 kindsoft.net
  7077. *
  7078. * @author Roddy <luolonghao@gmail.com>
  7079. * @site http://www.kindsoft.net/
  7080. * @licence http://www.kindsoft.net/license.php
  7081. *******************************************************************************/
  7082. KindEditor.plugin('image', function(K) {
  7083. var self = this, name = 'image',
  7084. allowImageUpload = K.undef(self.allowImageUpload, true),
  7085. allowImageRemote = K.undef(self.allowImageRemote, true),
  7086. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7087. allowFileManager = K.undef(self.allowFileManager, false),
  7088. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7089. imageTabIndex = K.undef(self.imageTabIndex, 0),
  7090. imgPath = self.pluginsPath + 'image/images/',
  7091. extraParams = K.undef(self.extraFileUploadParams, {}),
  7092. filePostName = K.undef(self.filePostName, 'imgFile'),
  7093. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  7094. lang = self.lang(name + '.');
  7095. self.plugin.imageDialog = function(options) {
  7096. var imageUrl = options.imageUrl,
  7097. imageWidth = K.undef(options.imageWidth, ''),
  7098. imageHeight = K.undef(options.imageHeight, ''),
  7099. imageTitle = K.undef(options.imageTitle, ''),
  7100. imageAlign = K.undef(options.imageAlign, ''),
  7101. showRemote = K.undef(options.showRemote, true),
  7102. showLocal = K.undef(options.showLocal, true),
  7103. tabIndex = K.undef(options.tabIndex, 0),
  7104. clickFn = options.clickFn;
  7105. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  7106. var hiddenElements = [];
  7107. for(var k in extraParams){
  7108. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  7109. }
  7110. var html = [
  7111. '<div style="padding:20px;">',
  7112. '<div class="tabs"></div>',
  7113. '<div class="tab1" style="display:none;">',
  7114. '<div class="ke-dialog-row">',
  7115. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  7116. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  7117. '<span class="ke-button-common ke-button-outer">',
  7118. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7119. '</span>',
  7120. '</div>',
  7121. '<div class="ke-dialog-row">',
  7122. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  7123. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  7124. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  7125. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  7126. '</div>',
  7127. '<div class="ke-dialog-row">',
  7128. '<label style="width:60px;">' + lang.align + '</label>',
  7129. '<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="" />',
  7130. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  7131. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7132. '</div>',
  7133. '<div class="ke-dialog-row">',
  7134. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7135. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7136. '</div>',
  7137. '</div>',
  7138. '<div class="tab2" style="display:none;">',
  7139. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7140. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7141. '<div class="ke-dialog-row">',
  7142. hiddenElements.join(''),
  7143. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7144. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7145. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7146. '</div>',
  7147. '</form>',
  7148. '</div>',
  7149. '</div>'
  7150. ].join('');
  7151. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7152. dialogHeight = showLocal && showRemote ? 300 : 250;
  7153. var dialog = self.createDialog({
  7154. name : name,
  7155. width : dialogWidth,
  7156. height : dialogHeight,
  7157. title : self.lang(name),
  7158. body : html,
  7159. yesBtn : {
  7160. name : self.lang('yes'),
  7161. click : function(e) {
  7162. if (dialog.isLoading) {
  7163. return;
  7164. }
  7165. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7166. if (uploadbutton.fileBox.val() == '') {
  7167. alert(self.lang('pleaseSelectFile'));
  7168. return;
  7169. }
  7170. dialog.showLoading(self.lang('uploadLoading'));
  7171. uploadbutton.submit();
  7172. localUrlBox.val('');
  7173. return;
  7174. }
  7175. var url = K.trim(urlBox.val()),
  7176. width = widthBox.val(),
  7177. height = heightBox.val(),
  7178. title = titleBox.val(),
  7179. align = '';
  7180. alignBox.each(function() {
  7181. if (this.checked) {
  7182. align = this.value;
  7183. return false;
  7184. }
  7185. });
  7186. if (url == 'http://' || K.invalidUrl(url)) {
  7187. alert(self.lang('invalidUrl'));
  7188. urlBox[0].focus();
  7189. return;
  7190. }
  7191. if (!/^\d*$/.test(width)) {
  7192. alert(self.lang('invalidWidth'));
  7193. widthBox[0].focus();
  7194. return;
  7195. }
  7196. if (!/^\d*$/.test(height)) {
  7197. alert(self.lang('invalidHeight'));
  7198. heightBox[0].focus();
  7199. return;
  7200. }
  7201. clickFn.call(self, url, title, width, height, 0, align);
  7202. }
  7203. },
  7204. beforeRemove : function() {
  7205. viewServerBtn.unbind();
  7206. widthBox.unbind();
  7207. heightBox.unbind();
  7208. refreshBtn.unbind();
  7209. }
  7210. }),
  7211. div = dialog.div;
  7212. var urlBox = K('[name="url"]', div),
  7213. localUrlBox = K('[name="localUrl"]', div),
  7214. viewServerBtn = K('[name="viewServer"]', div),
  7215. widthBox = K('.tab1 [name="width"]', div),
  7216. heightBox = K('.tab1 [name="height"]', div),
  7217. refreshBtn = K('.ke-refresh-btn', div),
  7218. titleBox = K('.tab1 [name="title"]', div),
  7219. alignBox = K('.tab1 [name="align"]', div);
  7220. var tabs;
  7221. if (showRemote && showLocal) {
  7222. tabs = K.tabs({
  7223. src : K('.tabs', div),
  7224. afterSelect : function(i) {}
  7225. });
  7226. tabs.add({
  7227. title : lang.remoteImage,
  7228. panel : K('.tab1', div)
  7229. });
  7230. tabs.add({
  7231. title : lang.localImage,
  7232. panel : K('.tab2', div)
  7233. });
  7234. tabs.select(tabIndex);
  7235. } else if (showRemote) {
  7236. K('.tab1', div).show();
  7237. } else if (showLocal) {
  7238. K('.tab2', div).show();
  7239. }
  7240. var uploadbutton = K.uploadbutton({
  7241. button : K('.ke-upload-button', div)[0],
  7242. fieldName : filePostName,
  7243. form : K('.ke-form', div),
  7244. target : target,
  7245. width: 60,
  7246. afterUpload : function(data) {
  7247. dialog.hideLoading();
  7248. if (data.error === 0) {
  7249. var url = data.url;
  7250. if (formatUploadUrl) {
  7251. url = K.formatUrl(url, 'absolute');
  7252. }
  7253. if (self.afterUpload) {
  7254. self.afterUpload.call(self, url, data, name);
  7255. }
  7256. if (!fillDescAfterUploadImage) {
  7257. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7258. } else {
  7259. K(".ke-dialog-row #remoteUrl", div).val(url);
  7260. K(".ke-tabs-li", div)[0].click();
  7261. K(".ke-refresh-btn", div).click();
  7262. }
  7263. } else {
  7264. alert(data.message);
  7265. }
  7266. },
  7267. afterError : function(html) {
  7268. dialog.hideLoading();
  7269. self.errorDialog(html);
  7270. }
  7271. });
  7272. uploadbutton.fileBox.change(function(e) {
  7273. localUrlBox.val(uploadbutton.fileBox.val());
  7274. });
  7275. if (allowFileManager) {
  7276. viewServerBtn.click(function(e) {
  7277. self.loadPlugin('filemanager', function() {
  7278. self.plugin.filemanagerDialog({
  7279. viewType : 'VIEW',
  7280. dirName : 'image',
  7281. clickFn : function(url, title) {
  7282. if (self.dialogs.length > 1) {
  7283. K('[name="url"]', div).val(url);
  7284. if (self.afterSelectFile) {
  7285. self.afterSelectFile.call(self, url);
  7286. }
  7287. self.hideDialog();
  7288. }
  7289. }
  7290. });
  7291. });
  7292. });
  7293. } else {
  7294. viewServerBtn.hide();
  7295. }
  7296. var originalWidth = 0, originalHeight = 0;
  7297. function setSize(width, height) {
  7298. widthBox.val(width);
  7299. heightBox.val(height);
  7300. originalWidth = width;
  7301. originalHeight = height;
  7302. }
  7303. refreshBtn.click(function(e) {
  7304. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7305. position : 'absolute',
  7306. visibility : 'hidden',
  7307. top : 0,
  7308. left : '-1000px'
  7309. });
  7310. tempImg.bind('load', function() {
  7311. setSize(tempImg.width(), tempImg.height());
  7312. tempImg.remove();
  7313. });
  7314. K(document.body).append(tempImg);
  7315. });
  7316. widthBox.change(function(e) {
  7317. if (originalWidth > 0) {
  7318. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7319. }
  7320. });
  7321. heightBox.change(function(e) {
  7322. if (originalHeight > 0) {
  7323. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7324. }
  7325. });
  7326. urlBox.val(options.imageUrl);
  7327. setSize(options.imageWidth, options.imageHeight);
  7328. titleBox.val(options.imageTitle);
  7329. alignBox.each(function() {
  7330. if (this.value === options.imageAlign) {
  7331. this.checked = true;
  7332. return false;
  7333. }
  7334. });
  7335. if (showRemote && tabIndex === 0) {
  7336. urlBox[0].focus();
  7337. urlBox[0].select();
  7338. }
  7339. return dialog;
  7340. };
  7341. self.plugin.image = {
  7342. edit : function() {
  7343. var img = self.plugin.getSelectedImage();
  7344. self.plugin.imageDialog({
  7345. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7346. imageWidth : img ? img.width() : '',
  7347. imageHeight : img ? img.height() : '',
  7348. imageTitle : img ? img.attr('title') : '',
  7349. imageAlign : img ? img.attr('align') : '',
  7350. showRemote : allowImageRemote,
  7351. showLocal : allowImageUpload,
  7352. tabIndex: img ? 0 : imageTabIndex,
  7353. clickFn : function(url, title, width, height, border, align) {
  7354. if (img) {
  7355. img.attr('src', url);
  7356. img.attr('data-ke-src', url);
  7357. img.attr('width', width);
  7358. img.attr('height', height);
  7359. img.attr('title', title);
  7360. img.attr('align', align);
  7361. img.attr('alt', title);
  7362. } else {
  7363. self.exec('insertimage', url, title, width, height, border, align);
  7364. }
  7365. setTimeout(function() {
  7366. self.hideDialog().focus();
  7367. }, 0);
  7368. }
  7369. });
  7370. },
  7371. 'delete' : function() {
  7372. var target = self.plugin.getSelectedImage();
  7373. if (target.parent().name == 'a') {
  7374. target = target.parent();
  7375. }
  7376. target.remove();
  7377. self.addBookmark();
  7378. }
  7379. };
  7380. self.clickToolbar(name, self.plugin.image.edit);
  7381. });
  7382. /*******************************************************************************
  7383. * KindEditor - WYSIWYG HTML Editor for Internet
  7384. * Copyright (C) 2006-2011 kindsoft.net
  7385. *
  7386. * @author Roddy <luolonghao@gmail.com>
  7387. * @site http://www.kindsoft.net/
  7388. * @licence http://www.kindsoft.net/license.php
  7389. *******************************************************************************/
  7390. KindEditor.plugin('insertfile', function(K) {
  7391. var self = this, name = 'insertfile',
  7392. allowFileUpload = K.undef(self.allowFileUpload, true),
  7393. allowFileManager = K.undef(self.allowFileManager, false),
  7394. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7395. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7396. extraParams = K.undef(self.extraFileUploadParams, {}),
  7397. filePostName = K.undef(self.filePostName, 'imgFile'),
  7398. lang = self.lang(name + '.');
  7399. self.plugin.fileDialog = function(options) {
  7400. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7401. fileTitle = K.undef(options.fileTitle, ''),
  7402. clickFn = options.clickFn;
  7403. var html = [
  7404. '<div style="padding:20px;">',
  7405. '<div class="ke-dialog-row">',
  7406. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7407. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7408. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7409. '<span class="ke-button-common ke-button-outer">',
  7410. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7411. '</span>',
  7412. '</div>',
  7413. '<div class="ke-dialog-row">',
  7414. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7415. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7416. '</div>',
  7417. '</form>',
  7418. '</div>'
  7419. ].join('');
  7420. var dialog = self.createDialog({
  7421. name : name,
  7422. width : 450,
  7423. title : self.lang(name),
  7424. body : html,
  7425. yesBtn : {
  7426. name : self.lang('yes'),
  7427. click : function(e) {
  7428. var url = K.trim(urlBox.val()),
  7429. title = titleBox.val();
  7430. if (url == 'http://' || K.invalidUrl(url)) {
  7431. alert(self.lang('invalidUrl'));
  7432. urlBox[0].focus();
  7433. return;
  7434. }
  7435. if (K.trim(title) === '') {
  7436. title = url;
  7437. }
  7438. clickFn.call(self, url, title);
  7439. }
  7440. }
  7441. }),
  7442. div = dialog.div;
  7443. var urlBox = K('[name="url"]', div),
  7444. viewServerBtn = K('[name="viewServer"]', div),
  7445. titleBox = K('[name="title"]', div);
  7446. if (allowFileUpload) {
  7447. var uploadbutton = K.uploadbutton({
  7448. button : K('.ke-upload-button', div)[0],
  7449. fieldName : filePostName,
  7450. url : K.addParam(uploadJson, 'dir=file'),
  7451. extraParams : extraParams,
  7452. afterUpload : function(data) {
  7453. dialog.hideLoading();
  7454. if (data.error === 0) {
  7455. var url = data.url;
  7456. var fileName = data.fileName;
  7457. if (formatUploadUrl) {
  7458. url = K.formatUrl(url, 'absolute');
  7459. }
  7460. urlBox.val(url);
  7461. titleBox.val(fileName);
  7462. if (self.afterUpload) {
  7463. self.afterUpload.call(self, url, data, name);
  7464. }
  7465. alert(self.lang('uploadSuccess'));
  7466. } else {
  7467. alert(data.message);
  7468. }
  7469. },
  7470. afterError : function(html) {
  7471. dialog.hideLoading();
  7472. self.errorDialog(html);
  7473. }
  7474. });
  7475. uploadbutton.fileBox.change(function(e) {
  7476. dialog.showLoading(self.lang('uploadLoading'));
  7477. uploadbutton.submit();
  7478. });
  7479. } else {
  7480. K('.ke-upload-button', div).hide();
  7481. }
  7482. if (allowFileManager) {
  7483. viewServerBtn.click(function(e) {
  7484. self.loadPlugin('filemanager', function() {
  7485. self.plugin.filemanagerDialog({
  7486. viewType : 'LIST',
  7487. dirName : 'file',
  7488. clickFn : function(url, title) {
  7489. if (self.dialogs.length > 1) {
  7490. K('[name="url"]', div).val(url);
  7491. if (self.afterSelectFile) {
  7492. self.afterSelectFile.call(self, url);
  7493. }
  7494. self.hideDialog();
  7495. }
  7496. }
  7497. });
  7498. });
  7499. });
  7500. } else {
  7501. viewServerBtn.hide();
  7502. }
  7503. urlBox.val(fileUrl);
  7504. titleBox.val(fileTitle);
  7505. urlBox[0].focus();
  7506. urlBox[0].select();
  7507. };
  7508. self.clickToolbar(name, function() {
  7509. self.plugin.fileDialog({
  7510. clickFn : function(url, title) {
  7511. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7512. self.insertHtml(html).hideDialog().focus();
  7513. }
  7514. });
  7515. });
  7516. });
  7517. /*******************************************************************************
  7518. * KindEditor - WYSIWYG HTML Editor for Internet
  7519. * Copyright (C) 2006-2011 kindsoft.net
  7520. *
  7521. * @author Roddy <luolonghao@gmail.com>
  7522. * @site http://www.kindsoft.net/
  7523. * @licence http://www.kindsoft.net/license.php
  7524. *******************************************************************************/
  7525. KindEditor.plugin('lineheight', function(K) {
  7526. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7527. self.clickToolbar(name, function() {
  7528. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7529. if (commonNode) {
  7530. curVal = commonNode.css('line-height');
  7531. }
  7532. var menu = self.createMenu({
  7533. name : name,
  7534. width : 150
  7535. });
  7536. K.each(lang.lineHeight, function(i, row) {
  7537. K.each(row, function(key, val) {
  7538. menu.addItem({
  7539. title : val,
  7540. checked : curVal === key,
  7541. click : function() {
  7542. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7543. span : '.line-height=' + key
  7544. });
  7545. self.updateState();
  7546. self.addBookmark();
  7547. self.hideMenu();
  7548. }
  7549. });
  7550. });
  7551. });
  7552. });
  7553. });
  7554. /*******************************************************************************
  7555. * KindEditor - WYSIWYG HTML Editor for Internet
  7556. * Copyright (C) 2006-2011 kindsoft.net
  7557. *
  7558. * @author Roddy <luolonghao@gmail.com>
  7559. * @site http://www.kindsoft.net/
  7560. * @licence http://www.kindsoft.net/license.php
  7561. *******************************************************************************/
  7562. KindEditor.plugin('link', function(K) {
  7563. var self = this, name = 'link';
  7564. self.plugin.link = {
  7565. edit : function() {
  7566. var lang = self.lang(name + '.'),
  7567. html = '<div style="padding:20px;">' +
  7568. '<div class="ke-dialog-row">' +
  7569. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7570. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7571. '<div class="ke-dialog-row"">' +
  7572. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7573. '<select id="keType" name="type"></select>' +
  7574. '</div>' +
  7575. '</div>',
  7576. dialog = self.createDialog({
  7577. name : name,
  7578. width : 450,
  7579. title : self.lang(name),
  7580. body : html,
  7581. yesBtn : {
  7582. name : self.lang('yes'),
  7583. click : function(e) {
  7584. var url = K.trim(urlBox.val());
  7585. if (url == 'http://' || K.invalidUrl(url)) {
  7586. alert(self.lang('invalidUrl'));
  7587. urlBox[0].focus();
  7588. return;
  7589. }
  7590. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7591. }
  7592. }
  7593. }),
  7594. div = dialog.div,
  7595. urlBox = K('input[name="url"]', div),
  7596. typeBox = K('select[name="type"]', div);
  7597. urlBox.val('http://');
  7598. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7599. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7600. self.cmd.selection();
  7601. var a = self.plugin.getSelectedLink();
  7602. if (a) {
  7603. self.cmd.range.selectNode(a[0]);
  7604. self.cmd.select();
  7605. urlBox.val(a.attr('data-ke-src'));
  7606. typeBox.val(a.attr('target'));
  7607. }
  7608. urlBox[0].focus();
  7609. urlBox[0].select();
  7610. },
  7611. 'delete' : function() {
  7612. self.exec('unlink', null);
  7613. }
  7614. };
  7615. self.clickToolbar(name, self.plugin.link.edit);
  7616. });
  7617. /*******************************************************************************
  7618. * KindEditor - WYSIWYG HTML Editor for Internet
  7619. * Copyright (C) 2006-2011 kindsoft.net
  7620. *
  7621. * @author Roddy <luolonghao@gmail.com>
  7622. * @site http://www.kindsoft.net/
  7623. * @licence http://www.kindsoft.net/license.php
  7624. *******************************************************************************/
  7625. KindEditor.plugin('media', function(K) {
  7626. var self = this, name = 'media', lang = self.lang(name + '.'),
  7627. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7628. allowFileManager = K.undef(self.allowFileManager, false),
  7629. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7630. extraParams = K.undef(self.extraFileUploadParams, {}),
  7631. filePostName = K.undef(self.filePostName, 'imgFile'),
  7632. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7633. self.plugin.media = {
  7634. edit : function() {
  7635. var html = [
  7636. '<div style="padding:20px;">',
  7637. '<div class="ke-dialog-row">',
  7638. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7639. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7640. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7641. '<span class="ke-button-common ke-button-outer">',
  7642. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7643. '</span>',
  7644. '</div>',
  7645. '<div class="ke-dialog-row">',
  7646. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7647. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" />',
  7648. '</div>',
  7649. '<div class="ke-dialog-row">',
  7650. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7651. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" />',
  7652. '</div>',
  7653. '<div class="ke-dialog-row">',
  7654. '<label for="keAutostart">' + lang.autostart + '</label>',
  7655. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7656. '</div>',
  7657. '</div>'
  7658. ].join('');
  7659. var dialog = self.createDialog({
  7660. name : name,
  7661. width : 450,
  7662. height : 230,
  7663. title : self.lang(name),
  7664. body : html,
  7665. yesBtn : {
  7666. name : self.lang('yes'),
  7667. click : function(e) {
  7668. var url = K.trim(urlBox.val()),
  7669. width = widthBox.val(),
  7670. height = heightBox.val();
  7671. if (url == 'http://' || K.invalidUrl(url)) {
  7672. alert(self.lang('invalidUrl'));
  7673. urlBox[0].focus();
  7674. return;
  7675. }
  7676. if (!/^\d*$/.test(width)) {
  7677. alert(self.lang('invalidWidth'));
  7678. widthBox[0].focus();
  7679. return;
  7680. }
  7681. if (!/^\d*$/.test(height)) {
  7682. alert(self.lang('invalidHeight'));
  7683. heightBox[0].focus();
  7684. return;
  7685. }
  7686. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7687. src : url,
  7688. type : K.mediaType(url),
  7689. width : width,
  7690. height : height,
  7691. autostart : autostartBox[0].checked ? 'true' : 'false',
  7692. loop : 'true'
  7693. });
  7694. self.insertHtml(html).hideDialog().focus();
  7695. }
  7696. }
  7697. }),
  7698. div = dialog.div,
  7699. urlBox = K('[name="url"]', div),
  7700. viewServerBtn = K('[name="viewServer"]', div),
  7701. widthBox = K('[name="width"]', div),
  7702. heightBox = K('[name="height"]', div),
  7703. autostartBox = K('[name="autostart"]', div);
  7704. urlBox.val('http://');
  7705. if (allowMediaUpload) {
  7706. var uploadbutton = K.uploadbutton({
  7707. button : K('.ke-upload-button', div)[0],
  7708. fieldName : filePostName,
  7709. extraParams : extraParams,
  7710. url : K.addParam(uploadJson, 'dir=media'),
  7711. afterUpload : function(data) {
  7712. dialog.hideLoading();
  7713. if (data.error === 0) {
  7714. var url = data.url;
  7715. if (formatUploadUrl) {
  7716. url = K.formatUrl(url, 'absolute');
  7717. }
  7718. urlBox.val(url);
  7719. if (self.afterUpload) {
  7720. self.afterUpload.call(self, url, data, name);
  7721. }
  7722. alert(self.lang('uploadSuccess'));
  7723. } else {
  7724. alert(data.message);
  7725. }
  7726. },
  7727. afterError : function(html) {
  7728. dialog.hideLoading();
  7729. self.errorDialog(html);
  7730. }
  7731. });
  7732. uploadbutton.fileBox.change(function(e) {
  7733. dialog.showLoading(self.lang('uploadLoading'));
  7734. uploadbutton.submit();
  7735. });
  7736. } else {
  7737. K('.ke-upload-button', div).hide();
  7738. }
  7739. if (allowFileManager) {
  7740. viewServerBtn.click(function(e) {
  7741. self.loadPlugin('filemanager', function() {
  7742. self.plugin.filemanagerDialog({
  7743. viewType : 'LIST',
  7744. dirName : 'media',
  7745. clickFn : function(url, title) {
  7746. if (self.dialogs.length > 1) {
  7747. K('[name="url"]', div).val(url);
  7748. if (self.afterSelectFile) {
  7749. self.afterSelectFile.call(self, url);
  7750. }
  7751. self.hideDialog();
  7752. }
  7753. }
  7754. });
  7755. });
  7756. });
  7757. } else {
  7758. viewServerBtn.hide();
  7759. }
  7760. var img = self.plugin.getSelectedMedia();
  7761. if (img) {
  7762. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7763. urlBox.val(attrs.src);
  7764. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7765. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7766. autostartBox[0].checked = (attrs.autostart === 'true');
  7767. }
  7768. urlBox[0].focus();
  7769. urlBox[0].select();
  7770. },
  7771. 'delete' : function() {
  7772. self.plugin.getSelectedMedia().remove();
  7773. self.addBookmark();
  7774. }
  7775. };
  7776. self.clickToolbar(name, self.plugin.media.edit);
  7777. });
  7778. /*******************************************************************************
  7779. * KindEditor - WYSIWYG HTML Editor for Internet
  7780. * Copyright (C) 2006-2011 kindsoft.net
  7781. *
  7782. * @author Roddy <luolonghao@gmail.com>
  7783. * @site http://www.kindsoft.net/
  7784. * @licence http://www.kindsoft.net/license.php
  7785. *******************************************************************************/
  7786. (function(K) {
  7787. function KSWFUpload(options) {
  7788. this.init(options);
  7789. }
  7790. K.extend(KSWFUpload, {
  7791. init : function(options) {
  7792. var self = this;
  7793. options.afterError = options.afterError || function(str) {
  7794. alert(str);
  7795. };
  7796. self.options = options;
  7797. self.progressbars = {};
  7798. self.div = K(options.container).html([
  7799. '<div class="ke-swfupload">',
  7800. '<div class="ke-swfupload-top">',
  7801. '<div class="ke-inline-block ke-swfupload-button">',
  7802. '<input type="button" value="Browse" />',
  7803. '</div>',
  7804. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  7805. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  7806. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  7807. '</span>',
  7808. '</div>',
  7809. '<div class="ke-swfupload-body"></div>',
  7810. '</div>'
  7811. ].join(''));
  7812. self.bodyDiv = K('.ke-swfupload-body', self.div);
  7813. function showError(itemDiv, msg) {
  7814. K('.ke-status > div', itemDiv).hide();
  7815. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  7816. }
  7817. var settings = {
  7818. debug : false,
  7819. upload_url : options.uploadUrl,
  7820. flash_url : options.flashUrl,
  7821. file_post_name : options.filePostName,
  7822. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  7823. button_image_url: options.buttonImageUrl,
  7824. button_width: options.buttonWidth,
  7825. button_height: options.buttonHeight,
  7826. button_cursor : SWFUpload.CURSOR.HAND,
  7827. file_types : options.fileTypes,
  7828. file_types_description : options.fileTypesDesc,
  7829. file_upload_limit : options.fileUploadLimit,
  7830. file_size_limit : options.fileSizeLimit,
  7831. post_params : options.postParams,
  7832. file_queued_handler : function(file) {
  7833. file.url = self.options.fileIconUrl;
  7834. self.appendFile(file);
  7835. },
  7836. file_queue_error_handler : function(file, errorCode, message) {
  7837. var errorName = '';
  7838. switch (errorCode) {
  7839. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  7840. errorName = options.queueLimitExceeded;
  7841. break;
  7842. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  7843. errorName = options.fileExceedsSizeLimit;
  7844. break;
  7845. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  7846. errorName = options.zeroByteFile;
  7847. break;
  7848. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  7849. errorName = options.invalidFiletype;
  7850. break;
  7851. default:
  7852. errorName = options.unknownError;
  7853. break;
  7854. }
  7855. K.DEBUG && alert(errorName);
  7856. },
  7857. upload_start_handler : function(file) {
  7858. var self = this;
  7859. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  7860. K('.ke-status > div', itemDiv).hide();
  7861. K('.ke-progressbar', itemDiv).show();
  7862. },
  7863. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  7864. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  7865. var progressbar = self.progressbars[file.id];
  7866. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  7867. progressbar.percent.html(percent + '%');
  7868. },
  7869. upload_error_handler : function(file, errorCode, message) {
  7870. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  7871. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7872. showError(itemDiv, self.options.errorMessage);
  7873. }
  7874. },
  7875. upload_success_handler : function(file, serverData) {
  7876. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  7877. var data = {};
  7878. try {
  7879. data = K.json(serverData);
  7880. } catch (e) {
  7881. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  7882. }
  7883. if (data.error !== 0) {
  7884. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  7885. return;
  7886. }
  7887. file.url = data.url;
  7888. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  7889. K('.ke-status > div', itemDiv).hide();
  7890. }
  7891. };
  7892. self.swfu = new SWFUpload(settings);
  7893. K('.ke-swfupload-startupload input', self.div).click(function() {
  7894. self.swfu.startUpload();
  7895. });
  7896. },
  7897. getUrlList : function() {
  7898. var list = [];
  7899. K('.ke-img', self.bodyDiv).each(function() {
  7900. var img = K(this);
  7901. var status = img.attr('data-status');
  7902. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  7903. list.push(img.data('data'));
  7904. }
  7905. });
  7906. return list;
  7907. },
  7908. removeFile : function(fileId) {
  7909. var self = this;
  7910. self.swfu.cancelUpload(fileId);
  7911. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  7912. K('.ke-photo', itemDiv).unbind();
  7913. K('.ke-delete', itemDiv).unbind();
  7914. itemDiv.remove();
  7915. },
  7916. removeFiles : function() {
  7917. var self = this;
  7918. K('.ke-item', self.bodyDiv).each(function() {
  7919. self.removeFile(K(this).attr('data-id'));
  7920. });
  7921. },
  7922. appendFile : function(file) {
  7923. var self = this;
  7924. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  7925. self.bodyDiv.append(itemDiv);
  7926. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7927. .mouseover(function(e) {
  7928. K(this).addClass('ke-on');
  7929. })
  7930. .mouseout(function(e) {
  7931. K(this).removeClass('ke-on');
  7932. });
  7933. itemDiv.append(photoDiv);
  7934. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  7935. photoDiv.append(img);
  7936. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  7937. self.removeFile(file.id);
  7938. });
  7939. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  7940. K(['<div class="ke-progressbar">',
  7941. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  7942. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  7943. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  7944. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  7945. self.progressbars[file.id] = {
  7946. bar : K('.ke-progressbar-bar-inner', photoDiv),
  7947. percent : K('.ke-progressbar-percent', photoDiv)
  7948. };
  7949. },
  7950. remove : function() {
  7951. this.removeFiles();
  7952. this.swfu.destroy();
  7953. this.div.html('');
  7954. }
  7955. });
  7956. K.swfupload = function(element, options) {
  7957. return new KSWFUpload(element, options);
  7958. };
  7959. })(KindEditor);
  7960. KindEditor.plugin('multiimage', function(K) {
  7961. var self = this, name = 'multiimage',
  7962. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7963. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7964. imgPath = self.pluginsPath + 'multiimage/images/',
  7965. imageSizeLimit = K.undef(self.imageSizeLimit, '2MB'),
  7966. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  7967. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  7968. filePostName = K.undef(self.filePostName, 'imgFile'),
  7969. lang = self.lang(name + '.');
  7970. self.plugin.multiImageDialog = function(options) {
  7971. var clickFn = options.clickFn,
  7972. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  7973. var html = [
  7974. '<div style="padding:20px;">',
  7975. '<div class="swfupload">',
  7976. '</div>',
  7977. '</div>'
  7978. ].join('');
  7979. var dialog = self.createDialog({
  7980. name : name,
  7981. width : 650,
  7982. height : 510,
  7983. title : self.lang(name),
  7984. body : html,
  7985. previewBtn : {
  7986. name : lang.insertAll,
  7987. click : function(e) {
  7988. clickFn.call(self, swfupload.getUrlList());
  7989. }
  7990. },
  7991. yesBtn : {
  7992. name : lang.clearAll,
  7993. click : function(e) {
  7994. swfupload.removeFiles();
  7995. }
  7996. },
  7997. beforeRemove : function() {
  7998. if (!K.IE || K.V <= 8) {
  7999. swfupload.remove();
  8000. }
  8001. }
  8002. }),
  8003. div = dialog.div;
  8004. var swfupload = K.swfupload({
  8005. container : K('.swfupload', div),
  8006. buttonImageUrl : imgPath + (self.langType == 'zh-CN' ? 'select-files-zh-CN.png' : 'select-files-en.png'),
  8007. buttonWidth : self.langType == 'zh-CN' ? 72 : 88,
  8008. buttonHeight : 23,
  8009. fileIconUrl : imgPath + 'image.png',
  8010. uploadDesc : uploadDesc,
  8011. startButtonValue : lang.startUpload,
  8012. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  8013. flashUrl : imgPath + 'swfupload.swf',
  8014. filePostName : filePostName,
  8015. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8016. fileTypesDesc : 'Image Files',
  8017. fileUploadLimit : imageUploadLimit,
  8018. fileSizeLimit : imageSizeLimit,
  8019. postParams : K.undef(self.extraFileUploadParams, {}),
  8020. queueLimitExceeded : lang.queueLimitExceeded,
  8021. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  8022. zeroByteFile : lang.zeroByteFile,
  8023. invalidFiletype : lang.invalidFiletype,
  8024. unknownError : lang.unknownError,
  8025. pendingMessage : lang.pending,
  8026. errorMessage : lang.uploadError,
  8027. afterError : function(html) {
  8028. self.errorDialog(html);
  8029. }
  8030. });
  8031. return dialog;
  8032. };
  8033. self.clickToolbar(name, function() {
  8034. self.plugin.multiImageDialog({
  8035. clickFn : function (urlList) {
  8036. if (urlList.length === 0) {
  8037. return;
  8038. }
  8039. K.each(urlList, function(i, data) {
  8040. if (self.afterUpload) {
  8041. self.afterUpload.call(self, data.url, data, 'multiimage');
  8042. }
  8043. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8044. });
  8045. setTimeout(function() {
  8046. self.hideDialog().focus();
  8047. }, 0);
  8048. }
  8049. });
  8050. });
  8051. });
  8052. /* ******************* */
  8053. /* Constructor & Init */
  8054. /* ******************* */
  8055. (function() {
  8056. window.SWFUpload = function (settings) {
  8057. this.initSWFUpload(settings);
  8058. };
  8059. SWFUpload.prototype.initSWFUpload = function (settings) {
  8060. try {
  8061. this.customSettings = {};
  8062. this.settings = settings;
  8063. this.eventQueue = [];
  8064. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8065. this.movieElement = null;
  8066. SWFUpload.instances[this.movieName] = this;
  8067. this.initSettings();
  8068. this.loadFlash();
  8069. this.displayDebugInfo();
  8070. } catch (ex) {
  8071. delete SWFUpload.instances[this.movieName];
  8072. throw ex;
  8073. }
  8074. };
  8075. /* *************** */
  8076. /* Static Members */
  8077. /* *************** */
  8078. SWFUpload.instances = {};
  8079. SWFUpload.movieCount = 0;
  8080. SWFUpload.version = "2.2.0 2009-03-25";
  8081. SWFUpload.QUEUE_ERROR = {
  8082. QUEUE_LIMIT_EXCEEDED : -100,
  8083. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8084. ZERO_BYTE_FILE : -120,
  8085. INVALID_FILETYPE : -130
  8086. };
  8087. SWFUpload.UPLOAD_ERROR = {
  8088. HTTP_ERROR : -200,
  8089. MISSING_UPLOAD_URL : -210,
  8090. IO_ERROR : -220,
  8091. SECURITY_ERROR : -230,
  8092. UPLOAD_LIMIT_EXCEEDED : -240,
  8093. UPLOAD_FAILED : -250,
  8094. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8095. FILE_VALIDATION_FAILED : -270,
  8096. FILE_CANCELLED : -280,
  8097. UPLOAD_STOPPED : -290
  8098. };
  8099. SWFUpload.FILE_STATUS = {
  8100. QUEUED : -1,
  8101. IN_PROGRESS : -2,
  8102. ERROR : -3,
  8103. COMPLETE : -4,
  8104. CANCELLED : -5
  8105. };
  8106. SWFUpload.BUTTON_ACTION = {
  8107. SELECT_FILE : -100,
  8108. SELECT_FILES : -110,
  8109. START_UPLOAD : -120
  8110. };
  8111. SWFUpload.CURSOR = {
  8112. ARROW : -1,
  8113. HAND : -2
  8114. };
  8115. SWFUpload.WINDOW_MODE = {
  8116. WINDOW : "window",
  8117. TRANSPARENT : "transparent",
  8118. OPAQUE : "opaque"
  8119. };
  8120. SWFUpload.completeURL = function(url) {
  8121. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8122. return url;
  8123. }
  8124. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8125. var indexSlash = window.location.pathname.lastIndexOf("/");
  8126. if (indexSlash <= 0) {
  8127. path = "/";
  8128. } else {
  8129. path = window.location.pathname.substr(0, indexSlash) + "/";
  8130. }
  8131. return /*currentURL +*/ path + url;
  8132. };
  8133. /* ******************** */
  8134. /* Instance Members */
  8135. /* ******************** */
  8136. SWFUpload.prototype.initSettings = function () {
  8137. this.ensureDefault = function (settingName, defaultValue) {
  8138. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8139. };
  8140. this.ensureDefault("upload_url", "");
  8141. this.ensureDefault("preserve_relative_urls", false);
  8142. this.ensureDefault("file_post_name", "Filedata");
  8143. this.ensureDefault("post_params", {});
  8144. this.ensureDefault("use_query_string", false);
  8145. this.ensureDefault("requeue_on_error", false);
  8146. this.ensureDefault("http_success", []);
  8147. this.ensureDefault("assume_success_timeout", 0);
  8148. this.ensureDefault("file_types", "*.*");
  8149. this.ensureDefault("file_types_description", "All Files");
  8150. this.ensureDefault("file_size_limit", 0);
  8151. this.ensureDefault("file_upload_limit", 0);
  8152. this.ensureDefault("file_queue_limit", 0);
  8153. this.ensureDefault("flash_url", "swfupload.swf");
  8154. this.ensureDefault("prevent_swf_caching", true);
  8155. this.ensureDefault("button_image_url", "");
  8156. this.ensureDefault("button_width", 1);
  8157. this.ensureDefault("button_height", 1);
  8158. this.ensureDefault("button_text", "");
  8159. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8160. this.ensureDefault("button_text_top_padding", 0);
  8161. this.ensureDefault("button_text_left_padding", 0);
  8162. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8163. this.ensureDefault("button_disabled", false);
  8164. this.ensureDefault("button_placeholder_id", "");
  8165. this.ensureDefault("button_placeholder", null);
  8166. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8167. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8168. this.ensureDefault("debug", false);
  8169. this.settings.debug_enabled = this.settings.debug;
  8170. this.settings.return_upload_start_handler = this.returnUploadStart;
  8171. this.ensureDefault("swfupload_loaded_handler", null);
  8172. this.ensureDefault("file_dialog_start_handler", null);
  8173. this.ensureDefault("file_queued_handler", null);
  8174. this.ensureDefault("file_queue_error_handler", null);
  8175. this.ensureDefault("file_dialog_complete_handler", null);
  8176. this.ensureDefault("upload_start_handler", null);
  8177. this.ensureDefault("upload_progress_handler", null);
  8178. this.ensureDefault("upload_error_handler", null);
  8179. this.ensureDefault("upload_success_handler", null);
  8180. this.ensureDefault("upload_complete_handler", null);
  8181. this.ensureDefault("debug_handler", this.debugMessage);
  8182. this.ensureDefault("custom_settings", {});
  8183. this.customSettings = this.settings.custom_settings;
  8184. if (!!this.settings.prevent_swf_caching) {
  8185. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8186. }
  8187. if (!this.settings.preserve_relative_urls) {
  8188. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8189. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8190. }
  8191. delete this.ensureDefault;
  8192. };
  8193. SWFUpload.prototype.loadFlash = function () {
  8194. var targetElement, tempParent;
  8195. if (document.getElementById(this.movieName) !== null) {
  8196. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8197. }
  8198. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8199. if (targetElement == undefined) {
  8200. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8201. }
  8202. tempParent = document.createElement("div");
  8203. tempParent.innerHTML = this.getFlashHTML();
  8204. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8205. if (window[this.movieName] == undefined) {
  8206. window[this.movieName] = this.getMovieElement();
  8207. }
  8208. };
  8209. SWFUpload.prototype.getFlashHTML = function () {
  8210. var classid = '';
  8211. if (KindEditor.IE && KindEditor.V > 8) {
  8212. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8213. }
  8214. 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">',
  8215. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8216. '<param name="movie" value="', this.settings.flash_url, '" />',
  8217. '<param name="quality" value="high" />',
  8218. '<param name="menu" value="false" />',
  8219. '<param name="allowScriptAccess" value="always" />',
  8220. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8221. '</object>'].join("");
  8222. };
  8223. SWFUpload.prototype.getFlashVars = function () {
  8224. var paramString = this.buildParamString();
  8225. var httpSuccessString = this.settings.http_success.join(",");
  8226. return ["movieName=", encodeURIComponent(this.movieName),
  8227. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8228. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8229. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8230. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8231. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8232. "&amp;params=", encodeURIComponent(paramString),
  8233. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8234. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8235. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8236. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8237. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8238. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8239. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8240. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8241. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8242. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8243. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8244. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8245. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8246. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8247. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8248. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8249. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8250. ].join("");
  8251. };
  8252. SWFUpload.prototype.getMovieElement = function () {
  8253. if (this.movieElement == undefined) {
  8254. this.movieElement = document.getElementById(this.movieName);
  8255. }
  8256. if (this.movieElement === null) {
  8257. throw "Could not find Flash element";
  8258. }
  8259. return this.movieElement;
  8260. };
  8261. SWFUpload.prototype.buildParamString = function () {
  8262. var postParams = this.settings.post_params;
  8263. var paramStringPairs = [];
  8264. if (typeof(postParams) === "object") {
  8265. for (var name in postParams) {
  8266. if (postParams.hasOwnProperty(name)) {
  8267. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8268. }
  8269. }
  8270. }
  8271. return paramStringPairs.join("&amp;");
  8272. };
  8273. SWFUpload.prototype.destroy = function () {
  8274. try {
  8275. this.cancelUpload(null, false);
  8276. var movieElement = null;
  8277. movieElement = this.getMovieElement();
  8278. if (movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8279. for (var i in movieElement) {
  8280. try {
  8281. if (typeof(movieElement[i]) === "function") {
  8282. movieElement[i] = null;
  8283. }
  8284. } catch (ex1) {}
  8285. }
  8286. try {
  8287. movieElement.parentNode.removeChild(movieElement);
  8288. } catch (ex) {}
  8289. }
  8290. window[this.movieName] = null;
  8291. SWFUpload.instances[this.movieName] = null;
  8292. delete SWFUpload.instances[this.movieName];
  8293. this.movieElement = null;
  8294. this.settings = null;
  8295. this.customSettings = null;
  8296. this.eventQueue = null;
  8297. this.movieName = null;
  8298. return true;
  8299. } catch (ex2) {
  8300. return false;
  8301. }
  8302. };
  8303. SWFUpload.prototype.displayDebugInfo = function () {
  8304. this.debug(
  8305. [
  8306. "---SWFUpload Instance Info---\n",
  8307. "Version: ", SWFUpload.version, "\n",
  8308. "Movie Name: ", this.movieName, "\n",
  8309. "Settings:\n",
  8310. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8311. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8312. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8313. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8314. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8315. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8316. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8317. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8318. "\t", "file_types: ", this.settings.file_types, "\n",
  8319. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8320. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8321. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8322. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8323. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8324. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8325. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8326. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8327. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8328. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8329. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8330. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8331. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8332. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8333. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8334. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8335. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8336. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8337. "Event Handlers:\n",
  8338. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8339. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8340. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8341. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8342. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8343. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8344. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8345. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8346. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8347. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8348. ].join("")
  8349. );
  8350. };
  8351. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8352. the maintain v2 API compatibility
  8353. */
  8354. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8355. if (value == undefined) {
  8356. return (this.settings[name] = default_value);
  8357. } else {
  8358. return (this.settings[name] = value);
  8359. }
  8360. };
  8361. SWFUpload.prototype.getSetting = function (name) {
  8362. if (this.settings[name] != undefined) {
  8363. return this.settings[name];
  8364. }
  8365. return "";
  8366. };
  8367. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8368. argumentArray = argumentArray || [];
  8369. var movieElement = this.getMovieElement();
  8370. var returnValue, returnString;
  8371. try {
  8372. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8373. returnValue = eval(returnString);
  8374. } catch (ex) {
  8375. throw "Call to " + functionName + " failed";
  8376. }
  8377. if (returnValue != undefined && typeof returnValue.post === "object") {
  8378. returnValue = this.unescapeFilePostParams(returnValue);
  8379. }
  8380. return returnValue;
  8381. };
  8382. /* *****************************
  8383. -- Flash control methods --
  8384. Your UI should use these
  8385. to operate SWFUpload
  8386. ***************************** */
  8387. SWFUpload.prototype.selectFile = function () {
  8388. this.callFlash("SelectFile");
  8389. };
  8390. SWFUpload.prototype.selectFiles = function () {
  8391. this.callFlash("SelectFiles");
  8392. };
  8393. SWFUpload.prototype.startUpload = function (fileID) {
  8394. this.callFlash("StartUpload", [fileID]);
  8395. };
  8396. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8397. if (triggerErrorEvent !== false) {
  8398. triggerErrorEvent = true;
  8399. }
  8400. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8401. };
  8402. SWFUpload.prototype.stopUpload = function () {
  8403. this.callFlash("StopUpload");
  8404. };
  8405. /* ************************
  8406. * Settings methods
  8407. * These methods change the SWFUpload settings.
  8408. * SWFUpload settings should not be changed directly on the settings object
  8409. * since many of the settings need to be passed to Flash in order to take
  8410. * effect.
  8411. * *********************** */
  8412. SWFUpload.prototype.getStats = function () {
  8413. return this.callFlash("GetStats");
  8414. };
  8415. SWFUpload.prototype.setStats = function (statsObject) {
  8416. this.callFlash("SetStats", [statsObject]);
  8417. };
  8418. SWFUpload.prototype.getFile = function (fileID) {
  8419. if (typeof(fileID) === "number") {
  8420. return this.callFlash("GetFileByIndex", [fileID]);
  8421. } else {
  8422. return this.callFlash("GetFile", [fileID]);
  8423. }
  8424. };
  8425. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8426. return this.callFlash("AddFileParam", [fileID, name, value]);
  8427. };
  8428. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8429. this.callFlash("RemoveFileParam", [fileID, name]);
  8430. };
  8431. SWFUpload.prototype.setUploadURL = function (url) {
  8432. this.settings.upload_url = url.toString();
  8433. this.callFlash("SetUploadURL", [url]);
  8434. };
  8435. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8436. this.settings.post_params = paramsObject;
  8437. this.callFlash("SetPostParams", [paramsObject]);
  8438. };
  8439. SWFUpload.prototype.addPostParam = function (name, value) {
  8440. this.settings.post_params[name] = value;
  8441. this.callFlash("SetPostParams", [this.settings.post_params]);
  8442. };
  8443. SWFUpload.prototype.removePostParam = function (name) {
  8444. delete this.settings.post_params[name];
  8445. this.callFlash("SetPostParams", [this.settings.post_params]);
  8446. };
  8447. SWFUpload.prototype.setFileTypes = function (types, description) {
  8448. this.settings.file_types = types;
  8449. this.settings.file_types_description = description;
  8450. this.callFlash("SetFileTypes", [types, description]);
  8451. };
  8452. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8453. this.settings.file_size_limit = fileSizeLimit;
  8454. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8455. };
  8456. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8457. this.settings.file_upload_limit = fileUploadLimit;
  8458. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8459. };
  8460. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8461. this.settings.file_queue_limit = fileQueueLimit;
  8462. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8463. };
  8464. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8465. this.settings.file_post_name = filePostName;
  8466. this.callFlash("SetFilePostName", [filePostName]);
  8467. };
  8468. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8469. this.settings.use_query_string = useQueryString;
  8470. this.callFlash("SetUseQueryString", [useQueryString]);
  8471. };
  8472. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8473. this.settings.requeue_on_error = requeueOnError;
  8474. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8475. };
  8476. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8477. if (typeof http_status_codes === "string") {
  8478. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8479. }
  8480. this.settings.http_success = http_status_codes;
  8481. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8482. };
  8483. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8484. this.settings.assume_success_timeout = timeout_seconds;
  8485. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8486. };
  8487. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8488. this.settings.debug_enabled = debugEnabled;
  8489. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8490. };
  8491. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8492. if (buttonImageURL == undefined) {
  8493. buttonImageURL = "";
  8494. }
  8495. this.settings.button_image_url = buttonImageURL;
  8496. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8497. };
  8498. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8499. this.settings.button_width = width;
  8500. this.settings.button_height = height;
  8501. var movie = this.getMovieElement();
  8502. if (movie != undefined) {
  8503. movie.style.width = width + "px";
  8504. movie.style.height = height + "px";
  8505. }
  8506. this.callFlash("SetButtonDimensions", [width, height]);
  8507. };
  8508. SWFUpload.prototype.setButtonText = function (html) {
  8509. this.settings.button_text = html;
  8510. this.callFlash("SetButtonText", [html]);
  8511. };
  8512. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8513. this.settings.button_text_top_padding = top;
  8514. this.settings.button_text_left_padding = left;
  8515. this.callFlash("SetButtonTextPadding", [left, top]);
  8516. };
  8517. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8518. this.settings.button_text_style = css;
  8519. this.callFlash("SetButtonTextStyle", [css]);
  8520. };
  8521. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8522. this.settings.button_disabled = isDisabled;
  8523. this.callFlash("SetButtonDisabled", [isDisabled]);
  8524. };
  8525. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8526. this.settings.button_action = buttonAction;
  8527. this.callFlash("SetButtonAction", [buttonAction]);
  8528. };
  8529. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8530. this.settings.button_cursor = cursor;
  8531. this.callFlash("SetButtonCursor", [cursor]);
  8532. };
  8533. /* *******************************
  8534. Flash Event Interfaces
  8535. These functions are used by Flash to trigger the various
  8536. events.
  8537. All these functions a Private.
  8538. Because the ExternalInterface library is buggy the event calls
  8539. are added to a queue and the queue then executed by a setTimeout.
  8540. This ensures that events are executed in a determinate order and that
  8541. the ExternalInterface bugs are avoided.
  8542. ******************************* */
  8543. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8544. if (argumentArray == undefined) {
  8545. argumentArray = [];
  8546. } else if (!(argumentArray instanceof Array)) {
  8547. argumentArray = [argumentArray];
  8548. }
  8549. var self = this;
  8550. if (typeof this.settings[handlerName] === "function") {
  8551. this.eventQueue.push(function () {
  8552. this.settings[handlerName].apply(this, argumentArray);
  8553. });
  8554. setTimeout(function () {
  8555. self.executeNextEvent();
  8556. }, 0);
  8557. } else if (this.settings[handlerName] !== null) {
  8558. throw "Event handler " + handlerName + " is unknown or is not a function";
  8559. }
  8560. };
  8561. SWFUpload.prototype.executeNextEvent = function () {
  8562. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8563. if (typeof(f) === "function") {
  8564. f.apply(this);
  8565. }
  8566. };
  8567. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8568. var reg = /[$]([0-9a-f]{4})/i;
  8569. var unescapedPost = {};
  8570. var uk;
  8571. if (file != undefined) {
  8572. for (var k in file.post) {
  8573. if (file.post.hasOwnProperty(k)) {
  8574. uk = k;
  8575. var match;
  8576. while ((match = reg.exec(uk)) !== null) {
  8577. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8578. }
  8579. unescapedPost[uk] = file.post[k];
  8580. }
  8581. }
  8582. file.post = unescapedPost;
  8583. }
  8584. return file;
  8585. };
  8586. SWFUpload.prototype.testExternalInterface = function () {
  8587. try {
  8588. return this.callFlash("TestExternalInterface");
  8589. } catch (ex) {
  8590. return false;
  8591. }
  8592. };
  8593. SWFUpload.prototype.flashReady = function () {
  8594. var movieElement = this.getMovieElement();
  8595. if (!movieElement) {
  8596. this.debug("Flash called back ready but the flash movie can't be found.");
  8597. return;
  8598. }
  8599. this.cleanUp(movieElement);
  8600. this.queueEvent("swfupload_loaded_handler");
  8601. };
  8602. SWFUpload.prototype.cleanUp = function (movieElement) {
  8603. try {
  8604. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8605. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8606. for (var key in movieElement) {
  8607. try {
  8608. if (typeof(movieElement[key]) === "function") {
  8609. movieElement[key] = null;
  8610. }
  8611. } catch (ex) {
  8612. }
  8613. }
  8614. }
  8615. } catch (ex1) {
  8616. }
  8617. window["__flash__removeCallback"] = function (instance, name) {
  8618. try {
  8619. if (instance) {
  8620. instance[name] = null;
  8621. }
  8622. } catch (flashEx) {
  8623. }
  8624. };
  8625. };
  8626. /* This is a chance to do something before the browse window opens */
  8627. SWFUpload.prototype.fileDialogStart = function () {
  8628. this.queueEvent("file_dialog_start_handler");
  8629. };
  8630. /* Called when a file is successfully added to the queue. */
  8631. SWFUpload.prototype.fileQueued = function (file) {
  8632. file = this.unescapeFilePostParams(file);
  8633. this.queueEvent("file_queued_handler", file);
  8634. };
  8635. /* Handle errors that occur when an attempt to queue a file fails. */
  8636. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  8637. file = this.unescapeFilePostParams(file);
  8638. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  8639. };
  8640. /* Called after the file dialog has closed and the selected files have been queued.
  8641. You could call startUpload here if you want the queued files to begin uploading immediately. */
  8642. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  8643. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  8644. };
  8645. SWFUpload.prototype.uploadStart = function (file) {
  8646. file = this.unescapeFilePostParams(file);
  8647. this.queueEvent("return_upload_start_handler", file);
  8648. };
  8649. SWFUpload.prototype.returnUploadStart = function (file) {
  8650. var returnValue;
  8651. if (typeof this.settings.upload_start_handler === "function") {
  8652. file = this.unescapeFilePostParams(file);
  8653. returnValue = this.settings.upload_start_handler.call(this, file);
  8654. } else if (this.settings.upload_start_handler != undefined) {
  8655. throw "upload_start_handler must be a function";
  8656. }
  8657. if (returnValue === undefined) {
  8658. returnValue = true;
  8659. }
  8660. returnValue = !!returnValue;
  8661. this.callFlash("ReturnUploadStart", [returnValue]);
  8662. };
  8663. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  8664. file = this.unescapeFilePostParams(file);
  8665. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  8666. };
  8667. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  8668. file = this.unescapeFilePostParams(file);
  8669. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  8670. };
  8671. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  8672. file = this.unescapeFilePostParams(file);
  8673. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  8674. };
  8675. SWFUpload.prototype.uploadComplete = function (file) {
  8676. file = this.unescapeFilePostParams(file);
  8677. this.queueEvent("upload_complete_handler", file);
  8678. };
  8679. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  8680. internal debug console. You can override this event and have messages written where you want. */
  8681. SWFUpload.prototype.debug = function (message) {
  8682. this.queueEvent("debug_handler", message);
  8683. };
  8684. /* **********************************
  8685. Debug Console
  8686. The debug console is a self contained, in page location
  8687. for debug message to be sent. The Debug Console adds
  8688. itself to the body if necessary.
  8689. The console is automatically scrolled as messages appear.
  8690. If you are using your own debug handler or when you deploy to production and
  8691. have debug disabled you can remove these functions to reduce the file size
  8692. and complexity.
  8693. ********************************** */
  8694. SWFUpload.prototype.debugMessage = function (message) {
  8695. if (this.settings.debug) {
  8696. var exceptionMessage, exceptionValues = [];
  8697. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  8698. for (var key in message) {
  8699. if (message.hasOwnProperty(key)) {
  8700. exceptionValues.push(key + ": " + message[key]);
  8701. }
  8702. }
  8703. exceptionMessage = exceptionValues.join("\n") || "";
  8704. exceptionValues = exceptionMessage.split("\n");
  8705. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  8706. SWFUpload.Console.writeLine(exceptionMessage);
  8707. } else {
  8708. SWFUpload.Console.writeLine(message);
  8709. }
  8710. }
  8711. };
  8712. SWFUpload.Console = {};
  8713. SWFUpload.Console.writeLine = function (message) {
  8714. var console, documentForm;
  8715. try {
  8716. console = document.getElementById("SWFUpload_Console");
  8717. if (!console) {
  8718. documentForm = document.createElement("form");
  8719. document.getElementsByTagName("body")[0].appendChild(documentForm);
  8720. console = document.createElement("textarea");
  8721. console.id = "SWFUpload_Console";
  8722. console.style.fontFamily = "monospace";
  8723. console.setAttribute("wrap", "off");
  8724. console.wrap = "off";
  8725. console.style.overflow = "auto";
  8726. console.style.width = "700px";
  8727. console.style.height = "350px";
  8728. console.style.margin = "5px";
  8729. documentForm.appendChild(console);
  8730. }
  8731. console.value += message + "\n";
  8732. console.scrollTop = console.scrollHeight - console.clientHeight;
  8733. } catch (ex) {
  8734. alert("Exception: " + ex.name + " Message: " + ex.message);
  8735. }
  8736. };
  8737. })();
  8738. (function() {
  8739. /*
  8740. Queue Plug-in
  8741. Features:
  8742. *Adds a cancelQueue() method for cancelling the entire queue.
  8743. *All queued files are uploaded when startUpload() is called.
  8744. *If false is returned from uploadComplete then the queue upload is stopped.
  8745. If false is not returned (strict comparison) then the queue upload is continued.
  8746. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  8747. Set the event handler with the queue_complete_handler setting.
  8748. */
  8749. if (typeof(SWFUpload) === "function") {
  8750. SWFUpload.queue = {};
  8751. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  8752. return function () {
  8753. if (typeof(oldInitSettings) === "function") {
  8754. oldInitSettings.call(this);
  8755. }
  8756. this.queueSettings = {};
  8757. this.queueSettings.queue_cancelled_flag = false;
  8758. this.queueSettings.queue_upload_count = 0;
  8759. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  8760. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  8761. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  8762. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  8763. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  8764. };
  8765. })(SWFUpload.prototype.initSettings);
  8766. SWFUpload.prototype.startUpload = function (fileID) {
  8767. this.queueSettings.queue_cancelled_flag = false;
  8768. this.callFlash("StartUpload", [fileID]);
  8769. };
  8770. SWFUpload.prototype.cancelQueue = function () {
  8771. this.queueSettings.queue_cancelled_flag = true;
  8772. this.stopUpload();
  8773. var stats = this.getStats();
  8774. while (stats.files_queued > 0) {
  8775. this.cancelUpload();
  8776. stats = this.getStats();
  8777. }
  8778. };
  8779. SWFUpload.queue.uploadStartHandler = function (file) {
  8780. var returnValue;
  8781. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  8782. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  8783. }
  8784. returnValue = (returnValue === false) ? false : true;
  8785. this.queueSettings.queue_cancelled_flag = !returnValue;
  8786. return returnValue;
  8787. };
  8788. SWFUpload.queue.uploadCompleteHandler = function (file) {
  8789. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  8790. var continueUpload;
  8791. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  8792. this.queueSettings.queue_upload_count++;
  8793. }
  8794. if (typeof(user_upload_complete_handler) === "function") {
  8795. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  8796. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  8797. continueUpload = false;
  8798. } else {
  8799. continueUpload = true;
  8800. }
  8801. if (continueUpload) {
  8802. var stats = this.getStats();
  8803. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  8804. this.startUpload();
  8805. } else if (this.queueSettings.queue_cancelled_flag === false) {
  8806. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  8807. this.queueSettings.queue_upload_count = 0;
  8808. } else {
  8809. this.queueSettings.queue_cancelled_flag = false;
  8810. this.queueSettings.queue_upload_count = 0;
  8811. }
  8812. }
  8813. };
  8814. }
  8815. })();
  8816. /*******************************************************************************
  8817. * KindEditor - WYSIWYG HTML Editor for Internet
  8818. * Copyright (C) 2006-2011 kindsoft.net
  8819. *
  8820. * @author Roddy <luolonghao@gmail.com>
  8821. * @site http://www.kindsoft.net/
  8822. * @licence http://www.kindsoft.net/license.php
  8823. *******************************************************************************/
  8824. KindEditor.plugin('pagebreak', function(K) {
  8825. var self = this;
  8826. var name = 'pagebreak';
  8827. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  8828. self.clickToolbar(name, function() {
  8829. var cmd = self.cmd, range = cmd.range;
  8830. self.focus();
  8831. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  8832. self.insertHtml(pagebreakHtml + tail);
  8833. if (tail !== '') {
  8834. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  8835. range.selectNodeContents(p[0]);
  8836. p.removeAttr('id');
  8837. cmd.select();
  8838. }
  8839. });
  8840. });
  8841. /*******************************************************************************
  8842. * KindEditor - WYSIWYG HTML Editor for Internet
  8843. * Copyright (C) 2006-2011 kindsoft.net
  8844. *
  8845. * @author Roddy <luolonghao@gmail.com>
  8846. * @site http://www.kindsoft.net/
  8847. * @licence http://www.kindsoft.net/license.php
  8848. *******************************************************************************/
  8849. KindEditor.plugin('plainpaste', function(K) {
  8850. var self = this, name = 'plainpaste';
  8851. self.clickToolbar(name, function() {
  8852. var lang = self.lang(name + '.'),
  8853. html = '<div style="padding:10px 20px;">' +
  8854. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  8855. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  8856. '</div>',
  8857. dialog = self.createDialog({
  8858. name : name,
  8859. width : 450,
  8860. title : self.lang(name),
  8861. body : html,
  8862. yesBtn : {
  8863. name : self.lang('yes'),
  8864. click : function(e) {
  8865. var html = textarea.val();
  8866. html = K.escape(html);
  8867. html = html.replace(/ {2}/g, ' &nbsp;');
  8868. if (self.newlineTag == 'p') {
  8869. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  8870. } else {
  8871. html = html.replace(/\n/g, '<br />$&');
  8872. }
  8873. self.insertHtml(html).hideDialog().focus();
  8874. }
  8875. }
  8876. }),
  8877. textarea = K('textarea', dialog.div);
  8878. textarea[0].focus();
  8879. });
  8880. });
  8881. /*******************************************************************************
  8882. * KindEditor - WYSIWYG HTML Editor for Internet
  8883. * Copyright (C) 2006-2011 kindsoft.net
  8884. *
  8885. * @author Roddy <luolonghao@gmail.com>
  8886. * @site http://www.kindsoft.net/
  8887. * @licence http://www.kindsoft.net/license.php
  8888. *******************************************************************************/
  8889. KindEditor.plugin('preview', function(K) {
  8890. var self = this, name = 'preview', undefined;
  8891. self.clickToolbar(name, function() {
  8892. var lang = self.lang(name + '.'),
  8893. html = '<div style="padding:10px 20px;">' +
  8894. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  8895. '</div>',
  8896. dialog = self.createDialog({
  8897. name : name,
  8898. width : 750,
  8899. title : self.lang(name),
  8900. body : html
  8901. }),
  8902. iframe = K('iframe', dialog.div),
  8903. doc = K.iframeDoc(iframe);
  8904. doc.open();
  8905. doc.write(self.fullHtml());
  8906. doc.close();
  8907. K(doc.body).css('background-color', '#FFF');
  8908. iframe[0].contentWindow.focus();
  8909. });
  8910. });
  8911. /*******************************************************************************
  8912. * KindEditor - WYSIWYG HTML Editor for Internet
  8913. * Copyright (C) 2006-2011 kindsoft.net
  8914. *
  8915. * @author Roddy <luolonghao@gmail.com>
  8916. * @site http://www.kindsoft.net/
  8917. * @licence http://www.kindsoft.net/license.php
  8918. *******************************************************************************/
  8919. KindEditor.plugin('quickformat', function(K) {
  8920. var self = this, name = 'quickformat',
  8921. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  8922. function getFirstChild(knode) {
  8923. var child = knode.first();
  8924. while (child && child.first()) {
  8925. child = child.first();
  8926. }
  8927. return child;
  8928. }
  8929. self.clickToolbar(name, function() {
  8930. self.focus();
  8931. var doc = self.edit.doc,
  8932. range = self.cmd.range,
  8933. child = K(doc.body).first(), next,
  8934. nodeList = [], subList = [],
  8935. bookmark = range.createBookmark(true);
  8936. while(child) {
  8937. next = child.next();
  8938. var firstChild = getFirstChild(child);
  8939. if (!firstChild || firstChild.name != 'img') {
  8940. if (blockMap[child.name]) {
  8941. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  8942. child.css('text-indent', '2em');
  8943. } else {
  8944. subList.push(child);
  8945. }
  8946. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  8947. if (subList.length > 0) {
  8948. nodeList.push(subList);
  8949. }
  8950. subList = [];
  8951. }
  8952. }
  8953. child = next;
  8954. }
  8955. K.each(nodeList, function(i, subList) {
  8956. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  8957. subList[0].before(wrapper);
  8958. K.each(subList, function(i, knode) {
  8959. wrapper.append(knode);
  8960. });
  8961. });
  8962. range.moveToBookmark(bookmark);
  8963. self.addBookmark();
  8964. });
  8965. });
  8966. /*******************************************************************************
  8967. * KindEditor - WYSIWYG HTML Editor for Internet
  8968. * Copyright (C) 2006-2011 kindsoft.net
  8969. *
  8970. * @author Roddy <luolonghao@gmail.com>
  8971. * @site http://www.kindsoft.net/
  8972. * @licence http://www.kindsoft.net/license.php
  8973. *******************************************************************************/
  8974. KindEditor.plugin('table', function(K) {
  8975. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  8976. function _setColor(box, color) {
  8977. color = color.toUpperCase();
  8978. box.css('background-color', color);
  8979. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  8980. box.html(color);
  8981. }
  8982. var pickerList = [];
  8983. function _initColorPicker(dialogDiv, colorBox) {
  8984. colorBox.bind('click,mousedown', function(e){
  8985. e.stopPropagation();
  8986. });
  8987. function removePicker() {
  8988. K.each(pickerList, function() {
  8989. this.remove();
  8990. });
  8991. pickerList = [];
  8992. K(document).unbind('click,mousedown', removePicker);
  8993. dialogDiv.unbind('click,mousedown', removePicker);
  8994. }
  8995. colorBox.click(function(e) {
  8996. removePicker();
  8997. var box = K(this),
  8998. pos = box.pos();
  8999. var picker = K.colorpicker({
  9000. x : pos.x,
  9001. y : pos.y + box.height(),
  9002. z : 811214,
  9003. selectedColor : K(this).html(),
  9004. colors : self.colorTable,
  9005. noColor : self.lang('noColor'),
  9006. shadowMode : self.shadowMode,
  9007. click : function(color) {
  9008. _setColor(box, color);
  9009. removePicker();
  9010. }
  9011. });
  9012. pickerList.push(picker);
  9013. K(document).bind('click,mousedown', removePicker);
  9014. dialogDiv.bind('click,mousedown', removePicker);
  9015. });
  9016. }
  9017. function _getCellIndex(table, row, cell) {
  9018. var rowSpanCount = 0;
  9019. for (var i = 0, len = row.cells.length; i < len; i++) {
  9020. if (row.cells[i] == cell) {
  9021. break;
  9022. }
  9023. rowSpanCount += row.cells[i].rowSpan - 1;
  9024. }
  9025. return cell.cellIndex - rowSpanCount;
  9026. }
  9027. self.plugin.table = {
  9028. prop : function(isInsert) {
  9029. var html = [
  9030. '<div style="padding:20px;">',
  9031. '<div class="ke-dialog-row">',
  9032. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9033. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9034. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9035. '</div>',
  9036. '<div class="ke-dialog-row">',
  9037. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9038. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9039. '<select name="widthType">',
  9040. '<option value="%">' + lang.percent + '</option>',
  9041. '<option value="px">' + lang.px + '</option>',
  9042. '</select> &nbsp; ',
  9043. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9044. '<select name="heightType">',
  9045. '<option value="%">' + lang.percent + '</option>',
  9046. '<option value="px">' + lang.px + '</option>',
  9047. '</select>',
  9048. '</div>',
  9049. '<div class="ke-dialog-row">',
  9050. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9051. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9052. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9053. '</div>',
  9054. '<div class="ke-dialog-row">',
  9055. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9056. '<select id="keAlign" name="align">',
  9057. '<option value="">' + lang.alignDefault + '</option>',
  9058. '<option value="left">' + lang.alignLeft + '</option>',
  9059. '<option value="center">' + lang.alignCenter + '</option>',
  9060. '<option value="right">' + lang.alignRight + '</option>',
  9061. '</select>',
  9062. '</div>',
  9063. '<div class="ke-dialog-row">',
  9064. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9065. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9066. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9067. '</div>',
  9068. '<div class="ke-dialog-row">',
  9069. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9070. '<span class="ke-inline-block ke-input-color"></span>',
  9071. '</div>',
  9072. '</div>'
  9073. ].join('');
  9074. var bookmark = self.cmd.range.createBookmark();
  9075. var dialog = self.createDialog({
  9076. name : name,
  9077. width : 500,
  9078. title : self.lang(name),
  9079. body : html,
  9080. beforeRemove : function() {
  9081. colorBox.unbind();
  9082. },
  9083. yesBtn : {
  9084. name : self.lang('yes'),
  9085. click : function(e) {
  9086. var rows = rowsBox.val(),
  9087. cols = colsBox.val(),
  9088. width = widthBox.val(),
  9089. height = heightBox.val(),
  9090. widthType = widthTypeBox.val(),
  9091. heightType = heightTypeBox.val(),
  9092. padding = paddingBox.val(),
  9093. spacing = spacingBox.val(),
  9094. align = alignBox.val(),
  9095. border = borderBox.val(),
  9096. borderColor = K(colorBox[0]).html() || '',
  9097. bgColor = K(colorBox[1]).html() || '';
  9098. if (rows == 0 || !/^\d+$/.test(rows)) {
  9099. alert(self.lang('invalidRows'));
  9100. rowsBox[0].focus();
  9101. return;
  9102. }
  9103. if (cols == 0 || !/^\d+$/.test(cols)) {
  9104. alert(self.lang('invalidRows'));
  9105. colsBox[0].focus();
  9106. return;
  9107. }
  9108. if (!/^\d*$/.test(width)) {
  9109. alert(self.lang('invalidWidth'));
  9110. widthBox[0].focus();
  9111. return;
  9112. }
  9113. if (!/^\d*$/.test(height)) {
  9114. alert(self.lang('invalidHeight'));
  9115. heightBox[0].focus();
  9116. return;
  9117. }
  9118. if (!/^\d*$/.test(padding)) {
  9119. alert(self.lang('invalidPadding'));
  9120. paddingBox[0].focus();
  9121. return;
  9122. }
  9123. if (!/^\d*$/.test(spacing)) {
  9124. alert(self.lang('invalidSpacing'));
  9125. spacingBox[0].focus();
  9126. return;
  9127. }
  9128. if (!/^\d*$/.test(border)) {
  9129. alert(self.lang('invalidBorder'));
  9130. borderBox[0].focus();
  9131. return;
  9132. }
  9133. if (table) {
  9134. if (width !== '') {
  9135. table.width(width + widthType);
  9136. } else {
  9137. table.css('width', '');
  9138. }
  9139. if (table[0].width !== undefined) {
  9140. table.removeAttr('width');
  9141. }
  9142. if (height !== '') {
  9143. table.height(height + heightType);
  9144. } else {
  9145. table.css('height', '');
  9146. }
  9147. if (table[0].height !== undefined) {
  9148. table.removeAttr('height');
  9149. }
  9150. table.css('background-color', bgColor);
  9151. if (table[0].bgColor !== undefined) {
  9152. table.removeAttr('bgColor');
  9153. }
  9154. if (padding !== '') {
  9155. table[0].cellPadding = padding;
  9156. } else {
  9157. table.removeAttr('cellPadding');
  9158. }
  9159. if (spacing !== '') {
  9160. table[0].cellSpacing = spacing;
  9161. } else {
  9162. table.removeAttr('cellSpacing');
  9163. }
  9164. if (align !== '') {
  9165. table[0].align = align;
  9166. } else {
  9167. table.removeAttr('align');
  9168. }
  9169. if (border !== '') {
  9170. table.attr('border', border);
  9171. } else {
  9172. table.removeAttr('border');
  9173. }
  9174. if (border === '' || border === '0') {
  9175. table.addClass(zeroborder);
  9176. } else {
  9177. table.removeClass(zeroborder);
  9178. }
  9179. if (borderColor !== '') {
  9180. table.attr('borderColor', borderColor);
  9181. } else {
  9182. table.removeAttr('borderColor');
  9183. }
  9184. self.hideDialog().focus();
  9185. self.cmd.range.moveToBookmark(bookmark);
  9186. self.cmd.select();
  9187. self.addBookmark();
  9188. return;
  9189. }
  9190. var style = '';
  9191. if (width !== '') {
  9192. style += 'width:' + width + widthType + ';';
  9193. }
  9194. if (height !== '') {
  9195. style += 'height:' + height + heightType + ';';
  9196. }
  9197. if (bgColor !== '') {
  9198. style += 'background-color:' + bgColor + ';';
  9199. }
  9200. var html = '<table';
  9201. if (style !== '') {
  9202. html += ' style="' + style + '"';
  9203. }
  9204. if (padding !== '') {
  9205. html += ' cellpadding="' + padding + '"';
  9206. }
  9207. if (spacing !== '') {
  9208. html += ' cellspacing="' + spacing + '"';
  9209. }
  9210. if (align !== '') {
  9211. html += ' align="' + align + '"';
  9212. }
  9213. if (border !== '') {
  9214. html += ' border="' + border + '"';
  9215. }
  9216. if (border === '' || border === '0') {
  9217. html += ' class="' + zeroborder + '"';
  9218. }
  9219. if (borderColor !== '') {
  9220. html += ' bordercolor="' + borderColor + '"';
  9221. }
  9222. html += '>';
  9223. for (var i = 0; i < rows; i++) {
  9224. html += '<tr>';
  9225. for (var j = 0; j < cols; j++) {
  9226. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9227. }
  9228. html += '</tr>';
  9229. }
  9230. html += '</table>';
  9231. if (!K.IE) {
  9232. html += '<br />';
  9233. }
  9234. self.insertHtml(html);
  9235. self.select().hideDialog().focus();
  9236. self.addBookmark();
  9237. }
  9238. }
  9239. }),
  9240. div = dialog.div,
  9241. rowsBox = K('[name="rows"]', div).val(3),
  9242. colsBox = K('[name="cols"]', div).val(2),
  9243. widthBox = K('[name="width"]', div).val(100),
  9244. heightBox = K('[name="height"]', div),
  9245. widthTypeBox = K('[name="widthType"]', div),
  9246. heightTypeBox = K('[name="heightType"]', div),
  9247. paddingBox = K('[name="padding"]', div).val(2),
  9248. spacingBox = K('[name="spacing"]', div).val(0),
  9249. alignBox = K('[name="align"]', div),
  9250. borderBox = K('[name="border"]', div).val(1),
  9251. colorBox = K('.ke-input-color', div);
  9252. _initColorPicker(div, colorBox.eq(0));
  9253. _initColorPicker(div, colorBox.eq(1));
  9254. _setColor(colorBox.eq(0), '#000000');
  9255. _setColor(colorBox.eq(1), '');
  9256. rowsBox[0].focus();
  9257. rowsBox[0].select();
  9258. var table;
  9259. if (isInsert) {
  9260. return;
  9261. }
  9262. table = self.plugin.getSelectedTable();
  9263. if (table) {
  9264. rowsBox.val(table[0].rows.length);
  9265. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9266. rowsBox.attr('disabled', true);
  9267. colsBox.attr('disabled', true);
  9268. var match,
  9269. tableWidth = table[0].style.width || table[0].width,
  9270. tableHeight = table[0].style.height || table[0].height;
  9271. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9272. widthBox.val(match[1]);
  9273. widthTypeBox.val(match[2]);
  9274. } else {
  9275. widthBox.val('');
  9276. }
  9277. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9278. heightBox.val(match[1]);
  9279. heightTypeBox.val(match[2]);
  9280. }
  9281. paddingBox.val(table[0].cellPadding || '');
  9282. spacingBox.val(table[0].cellSpacing || '');
  9283. alignBox.val(table[0].align || '');
  9284. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9285. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9286. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9287. widthBox[0].focus();
  9288. widthBox[0].select();
  9289. }
  9290. },
  9291. cellprop : function() {
  9292. var html = [
  9293. '<div style="padding:20px;">',
  9294. '<div class="ke-dialog-row">',
  9295. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9296. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9297. '<select name="widthType">',
  9298. '<option value="%">' + lang.percent + '</option>',
  9299. '<option value="px">' + lang.px + '</option>',
  9300. '</select> &nbsp; ',
  9301. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9302. '<select name="heightType">',
  9303. '<option value="%">' + lang.percent + '</option>',
  9304. '<option value="px">' + lang.px + '</option>',
  9305. '</select>',
  9306. '</div>',
  9307. '<div class="ke-dialog-row">',
  9308. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9309. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9310. '<option value="">' + lang.alignDefault + '</option>',
  9311. '<option value="left">' + lang.alignLeft + '</option>',
  9312. '<option value="center">' + lang.alignCenter + '</option>',
  9313. '<option value="right">' + lang.alignRight + '</option>',
  9314. '</select> ',
  9315. lang.verticalAlign + ' <select name="verticalAlign">',
  9316. '<option value="">' + lang.alignDefault + '</option>',
  9317. '<option value="top">' + lang.alignTop + '</option>',
  9318. '<option value="middle">' + lang.alignMiddle + '</option>',
  9319. '<option value="bottom">' + lang.alignBottom + '</option>',
  9320. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9321. '</select>',
  9322. '</div>',
  9323. '<div class="ke-dialog-row">',
  9324. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9325. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9326. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9327. '</div>',
  9328. '<div class="ke-dialog-row">',
  9329. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9330. '<span class="ke-inline-block ke-input-color"></span>',
  9331. '</div>',
  9332. '</div>'
  9333. ].join('');
  9334. var bookmark = self.cmd.range.createBookmark();
  9335. var dialog = self.createDialog({
  9336. name : name,
  9337. width : 500,
  9338. title : self.lang('tablecell'),
  9339. body : html,
  9340. beforeRemove : function() {
  9341. colorBox.unbind();
  9342. },
  9343. yesBtn : {
  9344. name : self.lang('yes'),
  9345. click : function(e) {
  9346. var width = widthBox.val(),
  9347. height = heightBox.val(),
  9348. widthType = widthTypeBox.val(),
  9349. heightType = heightTypeBox.val(),
  9350. padding = paddingBox.val(),
  9351. spacing = spacingBox.val(),
  9352. textAlign = textAlignBox.val(),
  9353. verticalAlign = verticalAlignBox.val(),
  9354. border = borderBox.val(),
  9355. borderColor = K(colorBox[0]).html() || '',
  9356. bgColor = K(colorBox[1]).html() || '';
  9357. if (!/^\d*$/.test(width)) {
  9358. alert(self.lang('invalidWidth'));
  9359. widthBox[0].focus();
  9360. return;
  9361. }
  9362. if (!/^\d*$/.test(height)) {
  9363. alert(self.lang('invalidHeight'));
  9364. heightBox[0].focus();
  9365. return;
  9366. }
  9367. if (!/^\d*$/.test(border)) {
  9368. alert(self.lang('invalidBorder'));
  9369. borderBox[0].focus();
  9370. return;
  9371. }
  9372. cell.css({
  9373. width : width !== '' ? (width + widthType) : '',
  9374. height : height !== '' ? (height + heightType) : '',
  9375. 'background-color' : bgColor,
  9376. 'text-align' : textAlign,
  9377. 'vertical-align' : verticalAlign,
  9378. 'border-width' : border,
  9379. 'border-style' : border !== '' ? 'solid' : '',
  9380. 'border-color' : borderColor
  9381. });
  9382. self.hideDialog().focus();
  9383. self.cmd.range.moveToBookmark(bookmark);
  9384. self.cmd.select();
  9385. self.addBookmark();
  9386. }
  9387. }
  9388. }),
  9389. div = dialog.div,
  9390. widthBox = K('[name="width"]', div).val(100),
  9391. heightBox = K('[name="height"]', div),
  9392. widthTypeBox = K('[name="widthType"]', div),
  9393. heightTypeBox = K('[name="heightType"]', div),
  9394. paddingBox = K('[name="padding"]', div).val(2),
  9395. spacingBox = K('[name="spacing"]', div).val(0),
  9396. textAlignBox = K('[name="textAlign"]', div),
  9397. verticalAlignBox = K('[name="verticalAlign"]', div),
  9398. borderBox = K('[name="border"]', div).val(1),
  9399. colorBox = K('.ke-input-color', div);
  9400. _initColorPicker(div, colorBox.eq(0));
  9401. _initColorPicker(div, colorBox.eq(1));
  9402. _setColor(colorBox.eq(0), '#000000');
  9403. _setColor(colorBox.eq(1), '');
  9404. widthBox[0].focus();
  9405. widthBox[0].select();
  9406. var cell = self.plugin.getSelectedCell();
  9407. var match,
  9408. cellWidth = cell[0].style.width || cell[0].width || '',
  9409. cellHeight = cell[0].style.height || cell[0].height || '';
  9410. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9411. widthBox.val(match[1]);
  9412. widthTypeBox.val(match[2]);
  9413. } else {
  9414. widthBox.val('');
  9415. }
  9416. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9417. heightBox.val(match[1]);
  9418. heightTypeBox.val(match[2]);
  9419. }
  9420. textAlignBox.val(cell[0].style.textAlign || '');
  9421. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9422. var border = cell[0].style.borderWidth || '';
  9423. if (border) {
  9424. border = parseInt(border);
  9425. }
  9426. borderBox.val(border);
  9427. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9428. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9429. widthBox[0].focus();
  9430. widthBox[0].select();
  9431. },
  9432. insert : function() {
  9433. this.prop(true);
  9434. },
  9435. 'delete' : function() {
  9436. var table = self.plugin.getSelectedTable();
  9437. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9438. self.cmd.select();
  9439. table.remove();
  9440. self.addBookmark();
  9441. },
  9442. colinsert : function(offset) {
  9443. var table = self.plugin.getSelectedTable()[0],
  9444. row = self.plugin.getSelectedRow()[0],
  9445. cell = self.plugin.getSelectedCell()[0],
  9446. index = cell.cellIndex + offset;
  9447. index += table.rows[0].cells.length - row.cells.length;
  9448. for (var i = 0, len = table.rows.length; i < len; i++) {
  9449. var newRow = table.rows[i],
  9450. newCell = newRow.insertCell(index);
  9451. newCell.innerHTML = K.IE ? '' : '<br />';
  9452. index = _getCellIndex(table, newRow, newCell);
  9453. }
  9454. self.cmd.range.selectNodeContents(cell).collapse(true);
  9455. self.cmd.select();
  9456. self.addBookmark();
  9457. },
  9458. colinsertleft : function() {
  9459. this.colinsert(0);
  9460. },
  9461. colinsertright : function() {
  9462. this.colinsert(1);
  9463. },
  9464. rowinsert : function(offset) {
  9465. var table = self.plugin.getSelectedTable()[0],
  9466. row = self.plugin.getSelectedRow()[0],
  9467. cell = self.plugin.getSelectedCell()[0];
  9468. var rowIndex = row.rowIndex;
  9469. if (offset === 1) {
  9470. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9471. }
  9472. var newRow = table.insertRow(rowIndex);
  9473. for (var i = 0, len = row.cells.length; i < len; i++) {
  9474. if (row.cells[i].rowSpan > 1) {
  9475. len -= row.cells[i].rowSpan - 1;
  9476. }
  9477. var newCell = newRow.insertCell(i);
  9478. if (offset === 1 && row.cells[i].colSpan > 1) {
  9479. newCell.colSpan = row.cells[i].colSpan;
  9480. }
  9481. newCell.innerHTML = K.IE ? '' : '<br />';
  9482. }
  9483. for (var j = rowIndex; j >= 0; j--) {
  9484. var cells = table.rows[j].cells;
  9485. if (cells.length > i) {
  9486. for (var k = cell.cellIndex; k >= 0; k--) {
  9487. if (cells[k].rowSpan > 1) {
  9488. cells[k].rowSpan += 1;
  9489. }
  9490. }
  9491. break;
  9492. }
  9493. }
  9494. self.cmd.range.selectNodeContents(cell).collapse(true);
  9495. self.cmd.select();
  9496. self.addBookmark();
  9497. },
  9498. rowinsertabove : function() {
  9499. this.rowinsert(0);
  9500. },
  9501. rowinsertbelow : function() {
  9502. this.rowinsert(1);
  9503. },
  9504. rowmerge : function() {
  9505. var table = self.plugin.getSelectedTable()[0],
  9506. row = self.plugin.getSelectedRow()[0],
  9507. cell = self.plugin.getSelectedCell()[0],
  9508. rowIndex = row.rowIndex,
  9509. nextRowIndex = rowIndex + cell.rowSpan,
  9510. nextRow = table.rows[nextRowIndex];
  9511. if (table.rows.length <= nextRowIndex) {
  9512. return;
  9513. }
  9514. var cellIndex = cell.cellIndex;
  9515. if (nextRow.cells.length <= cellIndex) {
  9516. return;
  9517. }
  9518. var nextCell = nextRow.cells[cellIndex];
  9519. if (cell.colSpan !== nextCell.colSpan) {
  9520. return;
  9521. }
  9522. cell.rowSpan += nextCell.rowSpan;
  9523. nextRow.deleteCell(cellIndex);
  9524. self.cmd.range.selectNodeContents(cell).collapse(true);
  9525. self.cmd.select();
  9526. self.addBookmark();
  9527. },
  9528. colmerge : function() {
  9529. var table = self.plugin.getSelectedTable()[0],
  9530. row = self.plugin.getSelectedRow()[0],
  9531. cell = self.plugin.getSelectedCell()[0],
  9532. rowIndex = row.rowIndex,
  9533. cellIndex = cell.cellIndex,
  9534. nextCellIndex = cellIndex + 1;
  9535. if (row.cells.length <= nextCellIndex) {
  9536. return;
  9537. }
  9538. var nextCell = row.cells[nextCellIndex];
  9539. if (cell.rowSpan !== nextCell.rowSpan) {
  9540. return;
  9541. }
  9542. cell.colSpan += nextCell.colSpan;
  9543. row.deleteCell(nextCellIndex);
  9544. self.cmd.range.selectNodeContents(cell).collapse(true);
  9545. self.cmd.select();
  9546. self.addBookmark();
  9547. },
  9548. rowsplit : function() {
  9549. var table = self.plugin.getSelectedTable()[0],
  9550. row = self.plugin.getSelectedRow()[0],
  9551. cell = self.plugin.getSelectedCell()[0],
  9552. rowIndex = row.rowIndex;
  9553. if (cell.rowSpan === 1) {
  9554. return;
  9555. }
  9556. var cellIndex = _getCellIndex(table, row, cell);
  9557. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9558. var newRow = table.rows[rowIndex + i],
  9559. newCell = newRow.insertCell(cellIndex);
  9560. if (cell.colSpan > 1) {
  9561. newCell.colSpan = cell.colSpan;
  9562. }
  9563. newCell.innerHTML = K.IE ? '' : '<br />';
  9564. cellIndex = _getCellIndex(table, newRow, newCell);
  9565. }
  9566. K(cell).removeAttr('rowSpan');
  9567. self.cmd.range.selectNodeContents(cell).collapse(true);
  9568. self.cmd.select();
  9569. self.addBookmark();
  9570. },
  9571. colsplit : function() {
  9572. var table = self.plugin.getSelectedTable()[0],
  9573. row = self.plugin.getSelectedRow()[0],
  9574. cell = self.plugin.getSelectedCell()[0],
  9575. cellIndex = cell.cellIndex;
  9576. if (cell.colSpan === 1) {
  9577. return;
  9578. }
  9579. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9580. var newCell = row.insertCell(cellIndex + i);
  9581. if (cell.rowSpan > 1) {
  9582. newCell.rowSpan = cell.rowSpan;
  9583. }
  9584. newCell.innerHTML = K.IE ? '' : '<br />';
  9585. }
  9586. K(cell).removeAttr('colSpan');
  9587. self.cmd.range.selectNodeContents(cell).collapse(true);
  9588. self.cmd.select();
  9589. self.addBookmark();
  9590. },
  9591. coldelete : function() {
  9592. var table = self.plugin.getSelectedTable()[0],
  9593. row = self.plugin.getSelectedRow()[0],
  9594. cell = self.plugin.getSelectedCell()[0],
  9595. index = cell.cellIndex;
  9596. for (var i = 0, len = table.rows.length; i < len; i++) {
  9597. var newRow = table.rows[i],
  9598. newCell = newRow.cells[index];
  9599. if (newCell.colSpan > 1) {
  9600. newCell.colSpan -= 1;
  9601. if (newCell.colSpan === 1) {
  9602. K(newCell).removeAttr('colSpan');
  9603. }
  9604. } else {
  9605. newRow.deleteCell(index);
  9606. }
  9607. if (newCell.rowSpan > 1) {
  9608. i += newCell.rowSpan - 1;
  9609. }
  9610. }
  9611. if (row.cells.length === 0) {
  9612. self.cmd.range.setStartBefore(table).collapse(true);
  9613. self.cmd.select();
  9614. K(table).remove();
  9615. } else {
  9616. self.cmd.selection(true);
  9617. }
  9618. self.addBookmark();
  9619. },
  9620. rowdelete : function() {
  9621. var table = self.plugin.getSelectedTable()[0],
  9622. row = self.plugin.getSelectedRow()[0],
  9623. cell = self.plugin.getSelectedCell()[0],
  9624. rowIndex = row.rowIndex;
  9625. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9626. table.deleteRow(rowIndex + i);
  9627. }
  9628. if (table.rows.length === 0) {
  9629. self.cmd.range.setStartBefore(table).collapse(true);
  9630. self.cmd.select();
  9631. K(table).remove();
  9632. } else {
  9633. self.cmd.selection(true);
  9634. }
  9635. self.addBookmark();
  9636. }
  9637. };
  9638. self.clickToolbar(name, self.plugin.table.prop);
  9639. });
  9640. /*******************************************************************************
  9641. * KindEditor - WYSIWYG HTML Editor for Internet
  9642. * Copyright (C) 2006-2011 kindsoft.net
  9643. *
  9644. * @author Roddy <luolonghao@gmail.com>
  9645. * @site http://www.kindsoft.net/
  9646. * @licence http://www.kindsoft.net/license.php
  9647. *******************************************************************************/
  9648. KindEditor.plugin('template', function(K) {
  9649. var self = this, name = 'template', lang = self.lang(name + '.'),
  9650. htmlPath = self.pluginsPath + name + '/html/';
  9651. function getFilePath(fileName) {
  9652. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9653. }
  9654. self.clickToolbar(name, function() {
  9655. var lang = self.lang(name + '.'),
  9656. arr = ['<div style="padding:10px 20px;">',
  9657. '<div class="ke-header">',
  9658. '<div class="ke-left">',
  9659. lang. selectTemplate + ' <select>'];
  9660. K.each(lang.fileList, function(key, val) {
  9661. arr.push('<option value="' + key + '">' + val + '</option>');
  9662. });
  9663. html = [arr.join(''),
  9664. '</select></div>',
  9665. '<div class="ke-right">',
  9666. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9667. '</div>',
  9668. '<div class="ke-clearfix"></div>',
  9669. '</div>',
  9670. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9671. '</div>'].join('');
  9672. var dialog = self.createDialog({
  9673. name : name,
  9674. width : 500,
  9675. title : self.lang(name),
  9676. body : html,
  9677. yesBtn : {
  9678. name : self.lang('yes'),
  9679. click : function(e) {
  9680. var doc = K.iframeDoc(iframe);
  9681. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9682. }
  9683. }
  9684. });
  9685. var selectBox = K('select', dialog.div),
  9686. checkbox = K('[name="replaceFlag"]', dialog.div),
  9687. iframe = K('iframe', dialog.div);
  9688. checkbox[0].checked = true;
  9689. iframe.attr('src', getFilePath(selectBox.val()));
  9690. selectBox.change(function() {
  9691. iframe.attr('src', getFilePath(this.value));
  9692. });
  9693. });
  9694. });
  9695. /*******************************************************************************
  9696. * KindEditor - WYSIWYG HTML Editor for Internet
  9697. * Copyright (C) 2006-2011 kindsoft.net
  9698. *
  9699. * @author Roddy <luolonghao@gmail.com>
  9700. * @site http://www.kindsoft.net/
  9701. * @licence http://www.kindsoft.net/license.php
  9702. *******************************************************************************/
  9703. KindEditor.plugin('wordpaste', function(K) {
  9704. var self = this, name = 'wordpaste';
  9705. self.clickToolbar(name, function() {
  9706. var lang = self.lang(name + '.'),
  9707. html = '<div style="padding:10px 20px;">' +
  9708. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9709. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  9710. '</div>',
  9711. dialog = self.createDialog({
  9712. name : name,
  9713. width : 450,
  9714. title : self.lang(name),
  9715. body : html,
  9716. yesBtn : {
  9717. name : self.lang('yes'),
  9718. click : function(e) {
  9719. var str = doc.body.innerHTML;
  9720. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  9721. self.insertHtml(str).hideDialog().focus();
  9722. }
  9723. }
  9724. }),
  9725. div = dialog.div,
  9726. iframe = K('iframe', div),
  9727. doc = K.iframeDoc(iframe);
  9728. if (!K.IE) {
  9729. doc.designMode = 'on';
  9730. }
  9731. doc.open();
  9732. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  9733. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  9734. if (!K.IE) {
  9735. doc.write('<br />');
  9736. }
  9737. doc.write('</body></html>');
  9738. doc.close();
  9739. if (K.IE) {
  9740. doc.body.contentEditable = 'true';
  9741. }
  9742. iframe[0].contentWindow.focus();
  9743. });
  9744. });
  9745. KindEditor.plugin('fixtoolbar', function (K) {
  9746. var self = this;
  9747. if (!self.fixToolBar) {
  9748. return;
  9749. }
  9750. function init() {
  9751. var toolbar = K('.ke-toolbar');
  9752. var originY = toolbar.pos().y;
  9753. K(window).bind('scroll', function () {
  9754. if (toolbar.css('position') == 'fixed') {
  9755. if(document.body.scrollTop - originY < 0){
  9756. toolbar.css('position', 'static');
  9757. toolbar.css('top', 'auto');
  9758. }
  9759. } else {
  9760. if (toolbar.pos().y - document.body.scrollTop < 0) {
  9761. toolbar.css('position', 'fixed');
  9762. toolbar.css('top', 0);
  9763. }
  9764. }
  9765. });
  9766. }
  9767. if (self.isCreated) {
  9768. init();
  9769. } else {
  9770. self.afterCreate(init);
  9771. }
  9772. });