kindeditor-all-min.js 305 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359
  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2017 kindsoft.net
  4. *
  5. * @author Roddy <luolonghao@gmail.com>
  6. * @website http://www.kindsoft.net/
  7. * @licence http://www.kindsoft.net/license.php
  8. * @version 4.1.12 (2017-04-12)
  9. *******************************************************************************/
  10. (function (window, undefined) {
  11. if (window.KindEditor) {
  12. return;
  13. }
  14. if (!window.console) {
  15. window.console = {};
  16. }
  17. if (!console.log) {
  18. console.log = function () {};
  19. }
  20. var _VERSION = '4.1.12 (2017-04-12)',
  21. _ua = navigator.userAgent.toLowerCase(),
  22. _IE = _ua.indexOf('msie') > -1 && _ua.indexOf('opera') == -1,
  23. _NEWIE = _ua.indexOf('msie') == -1 && _ua.indexOf('trident') > -1,
  24. _GECKO = _ua.indexOf('gecko') > -1 && _ua.indexOf('khtml') == -1,
  25. _WEBKIT = _ua.indexOf('applewebkit') > -1,
  26. _OPERA = _ua.indexOf('opera') > -1,
  27. _MOBILE = _ua.indexOf('mobile') > -1,
  28. _IOS = /ipad|iphone|ipod/.test(_ua),
  29. _QUIRKS = document.compatMode != 'CSS1Compat',
  30. _IERANGE = !window.getSelection,
  31. _matches = /(?:msie|firefox|webkit|opera)[\/:\s](\d+)/.exec(_ua),
  32. _V = _matches ? _matches[1] : '0',
  33. _TIME = new Date().getTime();
  34. function _isArray(val) {
  35. if (!val) {
  36. return false;
  37. }
  38. return Object.prototype.toString.call(val) === '[object Array]';
  39. }
  40. function _isFunction(val) {
  41. if (!val) {
  42. return false;
  43. }
  44. return Object.prototype.toString.call(val) === '[object Function]';
  45. }
  46. function _inArray(val, arr) {
  47. for (var i = 0, len = arr.length; i < len; i++) {
  48. if (val === arr[i]) {
  49. return i;
  50. }
  51. }
  52. return -1;
  53. }
  54. function _each(obj, fn) {
  55. if (_isArray(obj)) {
  56. for (var i = 0, len = obj.length; i < len; i++) {
  57. if (fn.call(obj[i], i, obj[i]) === false) {
  58. break;
  59. }
  60. }
  61. } else {
  62. for (var key in obj) {
  63. if (obj.hasOwnProperty(key)) {
  64. if (fn.call(obj[key], key, obj[key]) === false) {
  65. break;
  66. }
  67. }
  68. }
  69. }
  70. }
  71. function _trim(str) {
  72. return str.replace(/(?:^[ \t\n\r]+)|(?:[ \t\n\r]+$)/g, '');
  73. }
  74. function _inString(val, str, delimiter) {
  75. delimiter = delimiter === undefined ? ',' : delimiter;
  76. return (delimiter + str + delimiter).indexOf(delimiter + val + delimiter) >= 0;
  77. }
  78. function _addUnit(val, unit) {
  79. unit = unit || 'px';
  80. return val && /^-?\d+(?:\.\d+)?$/.test(val) ? val + unit : val;
  81. }
  82. function _removeUnit(val) {
  83. var match;
  84. return val && (match = /(\d+)/.exec(val)) ? parseInt(match[1], 10) : 0;
  85. }
  86. function _escape(val) {
  87. return val.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  88. }
  89. function _unescape(val) {
  90. return val.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&amp;/g, '&');
  91. }
  92. function _toCamel(str) {
  93. var arr = str.split('-');
  94. str = '';
  95. _each(arr, function(key, val) {
  96. str += (key > 0) ? val.charAt(0).toUpperCase() + val.substr(1) : val;
  97. });
  98. return str;
  99. }
  100. function _toHex(val) {
  101. function hex(d) {
  102. var s = parseInt(d, 10).toString(16).toUpperCase();
  103. return s.length > 1 ? s : '0' + s;
  104. }
  105. return val.replace(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/ig,
  106. function($0, $1, $2, $3) {
  107. return '#' + hex($1) + hex($2) + hex($3);
  108. }
  109. );
  110. }
  111. function _toMap(val, delimiter) {
  112. delimiter = delimiter === undefined ? ',' : delimiter;
  113. var map = {}, arr = _isArray(val) ? val : val.split(delimiter), match;
  114. _each(arr, function(key, val) {
  115. if ((match = /^(\d+)\.\.(\d+)$/.exec(val))) {
  116. for (var i = parseInt(match[1], 10); i <= parseInt(match[2], 10); i++) {
  117. map[i.toString()] = true;
  118. }
  119. } else {
  120. map[val] = true;
  121. }
  122. });
  123. return map;
  124. }
  125. function _toArray(obj, offset) {
  126. return Array.prototype.slice.call(obj, offset || 0);
  127. }
  128. function _undef(val, defaultVal) {
  129. return val === undefined ? defaultVal : val;
  130. }
  131. function _invalidUrl(url) {
  132. return !url || /[<>"]/.test(url);
  133. }
  134. function _addParam(url, param) {
  135. return url.indexOf('?') >= 0 ? url + '&' + param : url + '?' + param;
  136. }
  137. function _extend(child, parent, proto) {
  138. if (!proto) {
  139. proto = parent;
  140. parent = null;
  141. }
  142. var childProto;
  143. if (parent) {
  144. var fn = function () {};
  145. fn.prototype = parent.prototype;
  146. childProto = new fn();
  147. _each(proto, function(key, val) {
  148. childProto[key] = val;
  149. });
  150. } else {
  151. childProto = proto;
  152. }
  153. childProto.constructor = child;
  154. child.prototype = childProto;
  155. child.parent = parent ? parent.prototype : null;
  156. }
  157. function _json(text) {
  158. var match;
  159. if ((match = /\{[\s\S]*\}|\[[\s\S]*\]/.exec(text))) {
  160. text = match[0];
  161. }
  162. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  163. cx.lastIndex = 0;
  164. if (cx.test(text)) {
  165. text = text.replace(cx, function (a) {
  166. return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  167. });
  168. }
  169. if (/^[\],:{}\s]*$/.
  170. test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
  171. replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
  172. replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  173. return eval('(' + text + ')');
  174. }
  175. throw 'JSON parse error';
  176. }
  177. var _round = Math.round;
  178. var K = {
  179. DEBUG : false,
  180. VERSION : _VERSION,
  181. IE : _IE,
  182. GECKO : _GECKO,
  183. WEBKIT : _WEBKIT,
  184. OPERA : _OPERA,
  185. V : _V,
  186. TIME : _TIME,
  187. each : _each,
  188. isArray : _isArray,
  189. isFunction : _isFunction,
  190. inArray : _inArray,
  191. inString : _inString,
  192. trim : _trim,
  193. addUnit : _addUnit,
  194. removeUnit : _removeUnit,
  195. escape : _escape,
  196. unescape : _unescape,
  197. toCamel : _toCamel,
  198. toHex : _toHex,
  199. toMap : _toMap,
  200. toArray : _toArray,
  201. undef : _undef,
  202. invalidUrl : _invalidUrl,
  203. addParam : _addParam,
  204. extend : _extend,
  205. json : _json
  206. };
  207. var _INLINE_TAG_MAP = _toMap('a,abbr,acronym,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,img,input,ins,kbd,label,map,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'),
  208. _BLOCK_TAG_MAP = _toMap('address,applet,blockquote,body,center,dd,dir,div,dl,dt,fieldset,form,frameset,h1,h2,h3,h4,h5,h6,head,hr,html,iframe,ins,isindex,li,map,menu,meta,noframes,noscript,object,ol,p,pre,script,style,table,tbody,td,tfoot,th,thead,title,tr,ul'),
  209. _SINGLE_TAG_MAP = _toMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'),
  210. _STYLE_TAG_MAP = _toMap('b,basefont,big,del,em,font,i,s,small,span,strike,strong,sub,sup,u'),
  211. _CONTROL_TAG_MAP = _toMap('img,table,input,textarea,button'),
  212. _PRE_TAG_MAP = _toMap('pre,style,script'),
  213. _NOSPLIT_TAG_MAP = _toMap('html,head,body,td,tr,table,ol,ul,li'),
  214. _AUTOCLOSE_TAG_MAP = _toMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'),
  215. _FILL_ATTR_MAP = _toMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
  216. _VALUE_TAG_MAP = _toMap('input,button,textarea,select');
  217. function _getBasePath() {
  218. var els = document.getElementsByTagName('script'), src;
  219. for (var i = 0, len = els.length; i < len; i++) {
  220. src = els[i].src || '';
  221. if (/kindeditor[\w\-\.]*\.js/.test(src)) {
  222. return src.substring(0, src.lastIndexOf('/') + 1);
  223. }
  224. }
  225. return '';
  226. }
  227. K.basePath = _getBasePath();
  228. K.options = {
  229. index : 0,
  230. designMode : true,
  231. fullscreenMode : false,
  232. filterMode : true,
  233. wellFormatMode : true,
  234. shadowMode : true,
  235. loadStyleMode : true,
  236. basePath : K.basePath,
  237. themesPath : K.basePath + 'themes/',
  238. langPath : K.basePath + 'lang/',
  239. pluginsPath : K.basePath + 'plugins/',
  240. themeType : 'default',
  241. langType : 'zh-CN',
  242. urlType : '',
  243. newlineTag : 'p',
  244. resizeType : 2,
  245. syncType : 'form',
  246. pasteType : 2,
  247. dialogAlignType : 'page',
  248. useContextmenu : true,
  249. fullscreenShortcut : false,
  250. bodyClass : 'ke-content',
  251. indentChar : '\t',
  252. cssPath : '',
  253. cssData : '',
  254. minWidth : 650,
  255. minHeight : 100,
  256. minChangeSize : 50,
  257. zIndex : 19850426,
  258. items : [
  259. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  260. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  261. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  262. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  263. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  264. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  265. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  266. 'anchor', 'link', 'unlink', '|', 'about'
  267. ],
  268. noDisableItems : ['source', 'fullscreen'],
  269. colorTable : [
  270. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  271. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  272. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  273. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  274. ],
  275. fontSizeTable : ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
  276. fontHeightTable : ['0px', '0.25px', '0.5px', '1px', '1.5px', '2px', '2.5px', '3px', '4px', '5px'],
  277. htmlTags : {
  278. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  279. span : [
  280. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  281. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  282. ],
  283. div : [
  284. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  285. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  286. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  287. ],
  288. table: [
  289. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  290. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  291. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  292. '.width', '.height', '.border-collapse'
  293. ],
  294. 'td,th': [
  295. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  296. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  297. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  298. ],
  299. a : ['id', 'class', 'href', 'target', 'name'],
  300. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', 'wmode'],
  301. img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  302. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  303. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  304. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  305. ],
  306. pre : ['id', 'class'],
  307. hr : ['id', 'class', '.page-break-after'],
  308. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  309. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  310. },
  311. layout : '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  312. };
  313. var _useCapture = false;
  314. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  315. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  316. var _CHANGE_KEY_MAP = {};
  317. _each(_INPUT_KEY_MAP, function(key, val) {
  318. _CHANGE_KEY_MAP[key] = val;
  319. });
  320. _each(_CURSORMOVE_KEY_MAP, function(key, val) {
  321. _CHANGE_KEY_MAP[key] = val;
  322. });
  323. function _bindEvent(el, type, fn) {
  324. if (el.addEventListener){
  325. el.addEventListener(type, fn, _useCapture);
  326. } else if (el.attachEvent){
  327. el.attachEvent('on' + type, fn);
  328. }
  329. }
  330. function _unbindEvent(el, type, fn) {
  331. if (el.removeEventListener){
  332. el.removeEventListener(type, fn, _useCapture);
  333. } else if (el.detachEvent){
  334. el.detachEvent('on' + type, fn);
  335. }
  336. }
  337. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  338. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  339. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  340. function KEvent(el, event) {
  341. this.init(el, event);
  342. }
  343. _extend(KEvent, {
  344. init : function(el, event) {
  345. var self = this, doc = el.ownerDocument || el.document || el;
  346. self.event = event;
  347. _each(_EVENT_PROPS, function(key, val) {
  348. self[val] = event[val];
  349. });
  350. if (!self.target) {
  351. self.target = self.srcElement || doc;
  352. }
  353. if (self.target.nodeType === 3) {
  354. self.target = self.target.parentNode;
  355. }
  356. if (!self.relatedTarget && self.fromElement) {
  357. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  358. }
  359. if (self.pageX == null && self.clientX != null) {
  360. var d = doc.documentElement, body = doc.body;
  361. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  362. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  363. }
  364. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  365. self.which = self.charCode || self.keyCode;
  366. }
  367. if (!self.metaKey && self.ctrlKey) {
  368. self.metaKey = self.ctrlKey;
  369. }
  370. if (!self.which && self.button !== undefined) {
  371. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  372. }
  373. switch (self.which) {
  374. case 186 :
  375. self.which = 59;
  376. break;
  377. case 187 :
  378. case 107 :
  379. case 43 :
  380. self.which = 61;
  381. break;
  382. case 189 :
  383. case 45 :
  384. self.which = 109;
  385. break;
  386. case 42 :
  387. self.which = 106;
  388. break;
  389. case 47 :
  390. self.which = 111;
  391. break;
  392. case 78 :
  393. self.which = 110;
  394. break;
  395. }
  396. if (self.which >= 96 && self.which <= 105) {
  397. self.which -= 48;
  398. }
  399. },
  400. preventDefault : function() {
  401. var ev = this.event;
  402. if (ev.preventDefault) {
  403. ev.preventDefault();
  404. } else {
  405. ev.returnValue = false;
  406. }
  407. },
  408. stopPropagation : function() {
  409. var ev = this.event;
  410. if (ev.stopPropagation) {
  411. ev.stopPropagation();
  412. } else {
  413. ev.cancelBubble = true;
  414. }
  415. },
  416. stop : function() {
  417. this.preventDefault();
  418. this.stopPropagation();
  419. }
  420. });
  421. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  422. function _getId(el) {
  423. return el[_eventExpendo] || null;
  424. }
  425. function _setId(el) {
  426. el[_eventExpendo] = ++_eventId;
  427. return _eventId;
  428. }
  429. function _removeId(el) {
  430. try {
  431. delete el[_eventExpendo];
  432. } catch(e) {
  433. if (el.removeAttribute) {
  434. el.removeAttribute(_eventExpendo);
  435. }
  436. }
  437. }
  438. function _bind(el, type, fn) {
  439. if (type.indexOf(',') >= 0) {
  440. _each(type.split(','), function() {
  441. _bind(el, this, fn);
  442. });
  443. return;
  444. }
  445. var id = _getId(el);
  446. if (!id) {
  447. id = _setId(el);
  448. }
  449. if (_eventData[id] === undefined) {
  450. _eventData[id] = {};
  451. }
  452. var events = _eventData[id][type];
  453. if (events && events.length > 0) {
  454. _unbindEvent(el, type, events[0]);
  455. } else {
  456. _eventData[id][type] = [];
  457. _eventData[id].el = el;
  458. }
  459. events = _eventData[id][type];
  460. if (events.length === 0) {
  461. events[0] = function(e) {
  462. var kevent = e ? new KEvent(el, e) : undefined;
  463. _each(events, function(i, event) {
  464. if (i > 0 && event) {
  465. event.call(el, kevent);
  466. }
  467. });
  468. };
  469. }
  470. if (_inArray(fn, events) < 0) {
  471. events.push(fn);
  472. }
  473. _bindEvent(el, type, events[0]);
  474. }
  475. function _unbind(el, type, fn) {
  476. if (type && type.indexOf(',') >= 0) {
  477. _each(type.split(','), function() {
  478. _unbind(el, this, fn);
  479. });
  480. return;
  481. }
  482. var id = _getId(el);
  483. if (!id) {
  484. return;
  485. }
  486. if (type === undefined) {
  487. if (id in _eventData) {
  488. _each(_eventData[id], function(key, events) {
  489. if (key != 'el' && events.length > 0) {
  490. _unbindEvent(el, key, events[0]);
  491. }
  492. });
  493. delete _eventData[id];
  494. _removeId(el);
  495. }
  496. return;
  497. }
  498. if (!_eventData[id]) {
  499. return;
  500. }
  501. var events = _eventData[id][type];
  502. if (events && events.length > 0) {
  503. if (fn === undefined) {
  504. _unbindEvent(el, type, events[0]);
  505. delete _eventData[id][type];
  506. } else {
  507. _each(events, function(i, event) {
  508. if (i > 0 && event === fn) {
  509. events.splice(i, 1);
  510. }
  511. });
  512. if (events.length == 1) {
  513. _unbindEvent(el, type, events[0]);
  514. delete _eventData[id][type];
  515. }
  516. }
  517. var count = 0;
  518. _each(_eventData[id], function() {
  519. count++;
  520. });
  521. if (count < 2) {
  522. delete _eventData[id];
  523. _removeId(el);
  524. }
  525. }
  526. }
  527. function _fire(el, type) {
  528. if (type.indexOf(',') >= 0) {
  529. _each(type.split(','), function() {
  530. _fire(el, this);
  531. });
  532. return;
  533. }
  534. var id = _getId(el);
  535. if (!id) {
  536. return;
  537. }
  538. var events = _eventData[id][type];
  539. if (_eventData[id] && events && events.length > 0) {
  540. events[0]();
  541. }
  542. }
  543. function _ctrl(el, key, fn) {
  544. var self = this;
  545. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  546. _bind(el, 'keydown', function(e) {
  547. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  548. fn.call(el);
  549. e.stop();
  550. }
  551. });
  552. }
  553. var _readyFinished = false;
  554. function _ready(fn) {
  555. if (_readyFinished) {
  556. fn(KindEditor);
  557. return;
  558. }
  559. var loaded = false;
  560. function readyFunc() {
  561. if (!loaded) {
  562. loaded = true;
  563. fn(KindEditor);
  564. _readyFinished = true;
  565. }
  566. }
  567. function ieReadyFunc() {
  568. if (!loaded) {
  569. try {
  570. document.documentElement.doScroll('left');
  571. } catch(e) {
  572. setTimeout(ieReadyFunc, 100);
  573. return;
  574. }
  575. readyFunc();
  576. }
  577. }
  578. function ieReadyStateFunc() {
  579. if (document.readyState === 'complete') {
  580. readyFunc();
  581. }
  582. }
  583. if (document.addEventListener) {
  584. _bind(document, 'DOMContentLoaded', readyFunc);
  585. } else if (document.attachEvent) {
  586. _bind(document, 'readystatechange', ieReadyStateFunc);
  587. var toplevel = false;
  588. try {
  589. toplevel = window.frameElement == null;
  590. } catch(e) {}
  591. if (document.documentElement.doScroll && toplevel) {
  592. ieReadyFunc();
  593. }
  594. }
  595. _bind(window, 'load', readyFunc);
  596. }
  597. if (window.attachEvent) {
  598. window.attachEvent('onunload', function() {
  599. _each(_eventData, function(key, events) {
  600. if (events.el) {
  601. _unbind(events.el);
  602. }
  603. });
  604. });
  605. }
  606. K.ctrl = _ctrl;
  607. K.ready = _ready;
  608. function _getCssList(css) {
  609. css = css.replace(/&quot;/g, '"');
  610. var list = {},
  611. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  612. match;
  613. while ((match = reg.exec(css))) {
  614. var key = _trim(match[1].toLowerCase()),
  615. val = _trim(_toHex(match[2]));
  616. list[key] = val;
  617. }
  618. return list;
  619. }
  620. function _getAttrList(tag) {
  621. var list = {},
  622. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  623. match;
  624. while ((match = reg.exec(tag))) {
  625. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  626. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  627. list[key] = val;
  628. }
  629. return list;
  630. }
  631. function _addClassToTag(tag, className) {
  632. if (/\s+class\s*=/.test(tag)) {
  633. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  634. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  635. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  636. } else {
  637. return $0;
  638. }
  639. });
  640. } else {
  641. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  642. }
  643. return tag;
  644. }
  645. function _formatCss(css) {
  646. var str = '';
  647. _each(_getCssList(css), function(key, val) {
  648. str += key + ':' + val + ';';
  649. });
  650. return str;
  651. }
  652. function _formatUrl(url, mode, host, pathname) {
  653. return url;
  654. mode = _undef(mode, '').toLowerCase();
  655. if (url.substr(0, 5) != 'data:') {
  656. url = url.replace(/([^:])\/\//g, '$1/');
  657. }
  658. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  659. return url;
  660. }
  661. host = host || location.protocol + '//' + location.host;
  662. if (pathname === undefined) {
  663. var m = location.pathname.match(/^(\/.*)\//);
  664. pathname = m ? m[1] : '';
  665. }
  666. var match;
  667. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  668. if (match[1] !== host) {
  669. return url;
  670. }
  671. } else if (/^\w+:/.test(url)) {
  672. return url;
  673. }
  674. function getRealPath(path) {
  675. var parts = path.split('/'), paths = [];
  676. for (var i = 0, len = parts.length; i < len; i++) {
  677. var part = parts[i];
  678. if (part == '..') {
  679. if (paths.length > 0) {
  680. paths.pop();
  681. }
  682. } else if (part !== '' && part != '.') {
  683. paths.push(part);
  684. }
  685. }
  686. return '/' + paths.join('/');
  687. }
  688. if (/^\//.test(url)) {
  689. url = host + getRealPath(url.substr(1));
  690. } else if (!/^\w+:\/\//.test(url)) {
  691. url = host + getRealPath(pathname + '/' + url);
  692. }
  693. function getRelativePath(path, depth) {
  694. if (url.substr(0, path.length) === path) {
  695. var arr = [];
  696. for (var i = 0; i < depth; i++) {
  697. arr.push('..');
  698. }
  699. var prefix = '.';
  700. if (arr.length > 0) {
  701. prefix += '/' + arr.join('/');
  702. }
  703. if (pathname == '/') {
  704. prefix += '/';
  705. }
  706. return prefix + url.substr(path.length);
  707. } else {
  708. if ((match = /^(.*)\//.exec(path))) {
  709. return getRelativePath(match[1], ++depth);
  710. }
  711. }
  712. }
  713. if (mode === 'relative') {
  714. url = getRelativePath(host + pathname, 0).substr(2);
  715. } else if (mode === 'absolute') {
  716. if (url.substr(0, host.length) === host) {
  717. url = url.substr(host.length);
  718. }
  719. }
  720. return url;
  721. }
  722. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  723. if (html == null) {
  724. html = '';
  725. }
  726. urlType = urlType || '';
  727. wellFormatted = _undef(wellFormatted, false);
  728. indentChar = _undef(indentChar, '\t');
  729. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  730. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  731. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  732. });
  733. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  734. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  735. html = html.replace(/\u200B/g, '');
  736. html = html.replace(/\u00A9/g, '&copy;');
  737. html = html.replace(/\u00AE/g, '&reg;');
  738. html = html.replace(/\u2003/g, '&emsp;');
  739. html = html.replace(/\u3000/g, '&emsp;');
  740. html = html.replace(/&quot;/g, '');
  741. html = html.replace(/, " helvetica=""(.*?)"="/g, '');
  742. html = html.replace(/<[^>]+/g, function($0) {
  743. return $0.replace(/\s+/g, ' ');
  744. });
  745. var htmlTagMap = {};
  746. if (htmlTags) {
  747. _each(htmlTags, function(key, val) {
  748. var arr = key.split(',');
  749. for (var i = 0, len = arr.length; i < len; i++) {
  750. htmlTagMap[arr[i]] = _toMap(val);
  751. }
  752. });
  753. if (!htmlTagMap.script) {
  754. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  755. }
  756. if (!htmlTagMap.style) {
  757. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  758. }
  759. }
  760. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  761. var tagStack = [];
  762. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  763. var full = $0,
  764. startNewline = $1 || '',
  765. startSlash = $2 || '',
  766. tagName = $3.toLowerCase(),
  767. attr = $4 || '',
  768. endSlash = $5 ? ' ' + $5 : '',
  769. endNewline = $6 || '';
  770. if (htmlTags && !htmlTagMap[tagName]) {
  771. return '';
  772. }
  773. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  774. endSlash = ' /';
  775. }
  776. if (_INLINE_TAG_MAP[tagName]) {
  777. if (startNewline) {
  778. startNewline = ' ';
  779. }
  780. if (endNewline) {
  781. endNewline = ' ';
  782. }
  783. }
  784. if (_PRE_TAG_MAP[tagName]) {
  785. if (startSlash) {
  786. endNewline = '\n';
  787. } else {
  788. startNewline = '\n';
  789. }
  790. }
  791. if (wellFormatted && tagName == 'br') {
  792. endNewline = '\n';
  793. }
  794. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  795. if (wellFormatted) {
  796. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  797. tagStack.pop();
  798. } else {
  799. tagStack.push(tagName);
  800. }
  801. startNewline = '\n';
  802. endNewline = '\n';
  803. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  804. startNewline += indentChar;
  805. if (!startSlash) {
  806. endNewline += indentChar;
  807. }
  808. }
  809. if (endSlash) {
  810. tagStack.pop();
  811. } else if (!startSlash) {
  812. endNewline += indentChar;
  813. }
  814. } else {
  815. startNewline = endNewline = '';
  816. }
  817. }
  818. if (attr !== '') {
  819. var attrMap = _getAttrList(full);
  820. if (tagName === 'font') {
  821. var fontStyleMap = {}, fontStyle = '';
  822. _each(attrMap, function(key, val) {
  823. if (key === 'color') {
  824. fontStyleMap.color = val;
  825. delete attrMap[key];
  826. }
  827. if (key === 'size') {
  828. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  829. delete attrMap[key];
  830. }
  831. if (key === 'face') {
  832. fontStyleMap['font-family'] = val;
  833. delete attrMap[key];
  834. }
  835. if (key === 'style') {
  836. fontStyle = val;
  837. }
  838. });
  839. if (fontStyle && !/;$/.test(fontStyle)) {
  840. fontStyle += ';';
  841. }
  842. _each(fontStyleMap, function(key, val) {
  843. if (val === '') {
  844. return;
  845. }
  846. if (/\s/.test(val)) {
  847. val = "'" + val + "'";
  848. }
  849. fontStyle += key + ':' + val + ';';
  850. });
  851. attrMap.style = fontStyle;
  852. }
  853. _each(attrMap, function(key, val) {
  854. if (_FILL_ATTR_MAP[key]) {
  855. attrMap[key] = key;
  856. }
  857. if (_inArray(key, ['src', 'href']) >= 0) {
  858. attrMap[key] = _formatUrl(val, urlType);
  859. }
  860. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  861. tagName === 'body' && key === 'contenteditable' ||
  862. /^kindeditor_\d+$/.test(key)) {
  863. delete attrMap[key];
  864. }
  865. if (key === 'style' && val !== '') {
  866. var styleMap = _getCssList(val);
  867. _each(styleMap, function(k, v) {
  868. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  869. delete styleMap[k];
  870. }
  871. });
  872. var style = '';
  873. _each(styleMap, function(k, v) {
  874. style += k + ':' + v + ';';
  875. });
  876. attrMap.style = style;
  877. }
  878. });
  879. attr = '';
  880. _each(attrMap, function(key, val) {
  881. if (key === 'style' && val === '') {
  882. return;
  883. }
  884. val = val.replace(/"/g, '&quot;');
  885. attr += ' ' + key + '="' + val + '"';
  886. });
  887. }
  888. if (tagName === 'font') {
  889. tagName = 'span';
  890. }
  891. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  892. });
  893. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  894. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  895. });
  896. html = html.replace(/\n\s*\n/g, '\n');
  897. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  898. return _trim(html);
  899. }
  900. function _clearMsWord(html, htmlTags) {
  901. html = html.replace(/<meta[\s\S]*?>/ig, '')
  902. .replace(/<![\s\S]*?>/ig, '')
  903. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  904. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  905. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  906. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  907. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  908. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  909. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  910. });
  911. return _formatHtml(html, htmlTags);
  912. }
  913. function _mediaType(src) {
  914. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  915. return 'audio/x-pn-realaudio-plugin';
  916. }
  917. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  918. return 'application/x-shockwave-flash';
  919. }
  920. return 'video/x-ms-asf-plugin';
  921. }
  922. function _mediaClass(type) {
  923. if (/realaudio/i.test(type)) {
  924. return 'ke-rm';
  925. }
  926. if (/flash/i.test(type)) {
  927. return 'ke-flash';
  928. }
  929. return 'ke-media';
  930. }
  931. function _mediaAttrs(srcTag) {
  932. return _getAttrList(unescape(srcTag));
  933. }
  934. function _mediaEmbed(attrs) {
  935. var html = '<embed ';
  936. _each(attrs, function(key, val) {
  937. html += key + '="' + val + '" ';
  938. });
  939. html += '/>';
  940. return html;
  941. }
  942. function _mediaImg(blankPath, attrs) {
  943. var width = attrs.width,
  944. height = attrs.height,
  945. type = attrs.type || _mediaType(attrs.src),
  946. srcTag = _mediaEmbed(attrs),
  947. style = '';
  948. if (/\D/.test(width)) {
  949. style += 'width:' + width + ';';
  950. } else if (width > 0) {
  951. style += 'width:' + width + 'px;';
  952. }
  953. if (/\D/.test(height)) {
  954. style += 'height:' + height + ';';
  955. } else if (height > 0) {
  956. style += 'height:' + height + 'px;';
  957. }
  958. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  959. if (style !== '') {
  960. html += 'style="' + style + '" ';
  961. }
  962. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  963. return html;
  964. }
  965. function _tmpl(str, data) {
  966. var fn = new Function("obj",
  967. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  968. "with(obj){p.push('" +
  969. str.replace(/[\r\t\n]/g, " ")
  970. .split("<%").join("\t")
  971. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  972. .replace(/\t=(.*?)%>/g, "',$1,'")
  973. .split("\t").join("');")
  974. .split("%>").join("p.push('")
  975. .split("\r").join("\\'") + "');}return p.join('');");
  976. return data ? fn(data) : fn;
  977. }
  978. K.formatUrl = _formatUrl;
  979. K.formatHtml = _formatHtml;
  980. K.getCssList = _getCssList;
  981. K.getAttrList = _getAttrList;
  982. K.mediaType = _mediaType;
  983. K.mediaAttrs = _mediaAttrs;
  984. K.mediaEmbed = _mediaEmbed;
  985. K.mediaImg = _mediaImg;
  986. K.clearMsWord = _clearMsWord;
  987. K.tmpl = _tmpl;
  988. function _contains(nodeA, nodeB) {
  989. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  990. return true;
  991. }
  992. while ((nodeB = nodeB.parentNode)) {
  993. if (nodeB == nodeA) {
  994. return true;
  995. }
  996. }
  997. return false;
  998. }
  999. var _getSetAttrDiv = document.createElement('div');
  1000. _getSetAttrDiv.setAttribute('className', 't');
  1001. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  1002. function _getAttr(el, key) {
  1003. key = key.toLowerCase();
  1004. var val = null;
  1005. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  1006. var div = el.ownerDocument.createElement('div');
  1007. div.appendChild(el.cloneNode(false));
  1008. var list = _getAttrList(_unescape(div.innerHTML));
  1009. if (key in list) {
  1010. val = list[key];
  1011. }
  1012. } else {
  1013. try {
  1014. val = el.getAttribute(key, 2);
  1015. } catch(e) {
  1016. val = el.getAttribute(key, 1);
  1017. }
  1018. }
  1019. if (key === 'style' && val !== null) {
  1020. val = _formatCss(val);
  1021. }
  1022. return val;
  1023. }
  1024. function _queryAll(expr, root) {
  1025. var exprList = expr.split(',');
  1026. if (exprList.length > 1) {
  1027. var mergedResults = [];
  1028. _each(exprList, function() {
  1029. _each(_queryAll(this, root), function() {
  1030. if (_inArray(this, mergedResults) < 0) {
  1031. mergedResults.push(this);
  1032. }
  1033. });
  1034. });
  1035. return mergedResults;
  1036. }
  1037. root = root || document;
  1038. function escape(str) {
  1039. if (typeof str != 'string') {
  1040. return str;
  1041. }
  1042. return str.replace(/([^\w\-])/g, '\\$1');
  1043. }
  1044. function stripslashes(str) {
  1045. return str.replace(/\\/g, '');
  1046. }
  1047. function cmpTag(tagA, tagB) {
  1048. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1049. }
  1050. function byId(id, tag, root) {
  1051. var arr = [],
  1052. doc = root.ownerDocument || root,
  1053. el = doc.getElementById(stripslashes(id));
  1054. if (el) {
  1055. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1056. arr.push(el);
  1057. }
  1058. }
  1059. return arr;
  1060. }
  1061. function byClass(className, tag, root) {
  1062. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1063. if (root.getElementsByClassName) {
  1064. els = root.getElementsByClassName(stripslashes(className));
  1065. for (i = 0, len = els.length; i < len; i++) {
  1066. el = els[i];
  1067. if (cmpTag(tag, el.nodeName)) {
  1068. arr.push(el);
  1069. }
  1070. }
  1071. } else if (doc.querySelectorAll) {
  1072. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1073. for (i = 0, len = els.length; i < len; i++) {
  1074. el = els[i];
  1075. if (_contains(root, el)) {
  1076. arr.push(el);
  1077. }
  1078. }
  1079. } else {
  1080. els = root.getElementsByTagName(tag);
  1081. className = ' ' + className + ' ';
  1082. for (i = 0, len = els.length; i < len; i++) {
  1083. el = els[i];
  1084. if (el.nodeType == 1) {
  1085. var cls = el.className;
  1086. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1087. arr.push(el);
  1088. }
  1089. }
  1090. }
  1091. }
  1092. return arr;
  1093. }
  1094. function byName(name, tag, root) {
  1095. var arr = [], doc = root.ownerDocument || root,
  1096. els = doc.getElementsByName(stripslashes(name)), el;
  1097. for (var i = 0, len = els.length; i < len; i++) {
  1098. el = els[i];
  1099. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1100. if (el.getAttribute('name') !== null) {
  1101. arr.push(el);
  1102. }
  1103. }
  1104. }
  1105. return arr;
  1106. }
  1107. function byAttr(key, val, tag, root) {
  1108. var arr = [], els = root.getElementsByTagName(tag), el;
  1109. for (var i = 0, len = els.length; i < len; i++) {
  1110. el = els[i];
  1111. if (el.nodeType == 1) {
  1112. if (val === null) {
  1113. if (_getAttr(el, key) !== null) {
  1114. arr.push(el);
  1115. }
  1116. } else {
  1117. if (val === escape(_getAttr(el, key))) {
  1118. arr.push(el);
  1119. }
  1120. }
  1121. }
  1122. }
  1123. return arr;
  1124. }
  1125. function select(expr, root) {
  1126. var arr = [], matches;
  1127. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1128. var tag = matches ? matches[1] : '*';
  1129. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1130. arr = byId(matches[1], tag, root);
  1131. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1132. arr = byClass(matches[1], tag, root);
  1133. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1134. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1135. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1136. var key = matches[1].toLowerCase(), val = matches[2];
  1137. if (key === 'id') {
  1138. arr = byId(val, tag, root);
  1139. } else if (key === 'class') {
  1140. arr = byClass(val, tag, root);
  1141. } else if (key === 'name') {
  1142. arr = byName(val, tag, root);
  1143. } else {
  1144. arr = byAttr(key, val, tag, root);
  1145. }
  1146. } else {
  1147. var els = root.getElementsByTagName(tag), el;
  1148. for (var i = 0, len = els.length; i < len; i++) {
  1149. el = els[i];
  1150. if (el.nodeType == 1) {
  1151. arr.push(el);
  1152. }
  1153. }
  1154. }
  1155. return arr;
  1156. }
  1157. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1158. while ((arr = re.exec(expr))) {
  1159. if (arr[1] !== ' ') {
  1160. parts.push(arr[1]);
  1161. }
  1162. }
  1163. var results = [];
  1164. if (parts.length == 1) {
  1165. return select(parts[0], root);
  1166. }
  1167. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1168. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1169. part = parts[i];
  1170. if (part === '>') {
  1171. isChild = true;
  1172. continue;
  1173. }
  1174. if (i > 0) {
  1175. els = [];
  1176. for (j = 0, len = results.length; j < len; j++) {
  1177. val = results[j];
  1178. subResults = select(part, val);
  1179. for (k = 0, l = subResults.length; k < l; k++) {
  1180. v = subResults[k];
  1181. if (isChild) {
  1182. if (val === v.parentNode) {
  1183. els.push(v);
  1184. }
  1185. } else {
  1186. els.push(v);
  1187. }
  1188. }
  1189. }
  1190. results = els;
  1191. } else {
  1192. results = select(part, root);
  1193. }
  1194. if (results.length === 0) {
  1195. return [];
  1196. }
  1197. }
  1198. return results;
  1199. }
  1200. function _query(expr, root) {
  1201. var arr = _queryAll(expr, root);
  1202. return arr.length > 0 ? arr[0] : null;
  1203. }
  1204. K.query = _query;
  1205. K.queryAll = _queryAll;
  1206. function _get(val) {
  1207. return K(val)[0];
  1208. }
  1209. function _getDoc(node) {
  1210. if (!node) {
  1211. return document;
  1212. }
  1213. return node.ownerDocument || node.document || node;
  1214. }
  1215. function _getWin(node) {
  1216. if (!node) {
  1217. return window;
  1218. }
  1219. var doc = _getDoc(node);
  1220. return doc.parentWindow || doc.defaultView;
  1221. }
  1222. function _setHtml(el, html) {
  1223. if (el.nodeType != 1) {
  1224. return;
  1225. }
  1226. var doc = _getDoc(el);
  1227. try {
  1228. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1229. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1230. temp.parentNode.removeChild(temp);
  1231. } catch(e) {
  1232. K(el).empty();
  1233. K('@' + html, doc).each(function() {
  1234. el.appendChild(this);
  1235. });
  1236. }
  1237. }
  1238. function _hasClass(el, cls) {
  1239. return _inString(cls, el.className, ' ');
  1240. }
  1241. function _setAttr(el, key, val) {
  1242. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1243. key = 'className';
  1244. }
  1245. el.setAttribute(key, '' + val);
  1246. }
  1247. function _removeAttr(el, key) {
  1248. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1249. key = 'className';
  1250. }
  1251. _setAttr(el, key, '');
  1252. el.removeAttribute(key);
  1253. }
  1254. function _getNodeName(node) {
  1255. if (!node || !node.nodeName) {
  1256. return '';
  1257. }
  1258. return node.nodeName.toLowerCase();
  1259. }
  1260. function _computedCss(el, key) {
  1261. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1262. if (win.getComputedStyle) {
  1263. var style = win.getComputedStyle(el, null);
  1264. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1265. } else if (el.currentStyle) {
  1266. val = el.currentStyle[camelKey] || el.style[camelKey];
  1267. }
  1268. return val;
  1269. }
  1270. function _hasVal(node) {
  1271. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1272. }
  1273. function _docElement(doc) {
  1274. doc = doc || document;
  1275. return _QUIRKS ? doc.body : doc.documentElement;
  1276. }
  1277. function _docHeight(doc) {
  1278. var el = _docElement(doc);
  1279. return Math.max(el.scrollHeight, el.clientHeight);
  1280. }
  1281. function _docWidth(doc) {
  1282. var el = _docElement(doc);
  1283. return Math.max(el.scrollWidth, el.clientWidth);
  1284. }
  1285. function _getScrollPos(doc) {
  1286. doc = doc || document;
  1287. var x, y;
  1288. if (_IE || _NEWIE || _OPERA) {
  1289. x = _docElement(doc).scrollLeft;
  1290. y = _docElement(doc).scrollTop;
  1291. } else {
  1292. x = _getWin(doc).scrollX;
  1293. y = _getWin(doc).scrollY;
  1294. }
  1295. return {x : x, y : y};
  1296. }
  1297. function KNode(node) {
  1298. this.init(node);
  1299. }
  1300. _extend(KNode, {
  1301. init : function(node) {
  1302. var self = this;
  1303. node = _isArray(node) ? node : [node];
  1304. var length = 0;
  1305. for (var i = 0, len = node.length; i < len; i++) {
  1306. if (node[i]) {
  1307. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1308. length++;
  1309. }
  1310. }
  1311. self.length = length;
  1312. self.doc = _getDoc(self[0]);
  1313. self.name = _getNodeName(self[0]);
  1314. self.type = self.length > 0 ? self[0].nodeType : null;
  1315. self.win = _getWin(self[0]);
  1316. },
  1317. each : function(fn) {
  1318. var self = this;
  1319. for (var i = 0; i < self.length; i++) {
  1320. if (fn.call(self[i], i, self[i]) === false) {
  1321. return self;
  1322. }
  1323. }
  1324. return self;
  1325. },
  1326. bind : function(type, fn) {
  1327. this.each(function() {
  1328. _bind(this, type, fn);
  1329. });
  1330. return this;
  1331. },
  1332. unbind : function(type, fn) {
  1333. this.each(function() {
  1334. _unbind(this, type, fn);
  1335. });
  1336. return this;
  1337. },
  1338. fire : function(type) {
  1339. if (this.length < 1) {
  1340. return this;
  1341. }
  1342. _fire(this[0], type);
  1343. return this;
  1344. },
  1345. hasAttr : function(key) {
  1346. if (this.length < 1) {
  1347. return false;
  1348. }
  1349. return !!_getAttr(this[0], key);
  1350. },
  1351. attr : function(key, val) {
  1352. var self = this;
  1353. if (key === undefined) {
  1354. return _getAttrList(self.outer());
  1355. }
  1356. if (typeof key === 'object') {
  1357. _each(key, function(k, v) {
  1358. self.attr(k, v);
  1359. });
  1360. return self;
  1361. }
  1362. if (val === undefined) {
  1363. val = self.length < 1 ? null : _getAttr(self[0], key);
  1364. return val === null ? '' : val;
  1365. }
  1366. self.each(function() {
  1367. _setAttr(this, key, val);
  1368. });
  1369. return self;
  1370. },
  1371. removeAttr : function(key) {
  1372. this.each(function() {
  1373. _removeAttr(this, key);
  1374. });
  1375. return this;
  1376. },
  1377. get : function(i) {
  1378. if (this.length < 1) {
  1379. return null;
  1380. }
  1381. return this[i || 0];
  1382. },
  1383. eq : function(i) {
  1384. if (this.length < 1) {
  1385. return null;
  1386. }
  1387. return this[i] ? new KNode(this[i]) : null;
  1388. },
  1389. hasClass : function(cls) {
  1390. if (this.length < 1) {
  1391. return false;
  1392. }
  1393. return _hasClass(this[0], cls);
  1394. },
  1395. addClass : function(cls) {
  1396. this.each(function() {
  1397. if (!_hasClass(this, cls)) {
  1398. this.className = _trim(this.className + ' ' + cls);
  1399. }
  1400. });
  1401. return this;
  1402. },
  1403. removeClass : function(cls) {
  1404. this.each(function() {
  1405. if (_hasClass(this, cls)) {
  1406. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1407. }
  1408. });
  1409. return this;
  1410. },
  1411. html : function(val) {
  1412. var self = this;
  1413. if (val === undefined) {
  1414. if (self.length < 1 || self.type != 1) {
  1415. return '';
  1416. }
  1417. return _formatHtml(self[0].innerHTML);
  1418. }
  1419. self.each(function() {
  1420. _setHtml(this, val);
  1421. });
  1422. return self;
  1423. },
  1424. text : function() {
  1425. var self = this;
  1426. if (self.length < 1) {
  1427. return '';
  1428. }
  1429. return _IE ? self[0].innerText : self[0].textContent;
  1430. },
  1431. hasVal : function() {
  1432. if (this.length < 1) {
  1433. return false;
  1434. }
  1435. return _hasVal(this[0]);
  1436. },
  1437. val : function(val) {
  1438. var self = this;
  1439. if (val === undefined) {
  1440. if (self.length < 1) {
  1441. return '';
  1442. }
  1443. return self.hasVal() ? self[0].value : self.attr('value');
  1444. } else {
  1445. self.each(function() {
  1446. if (_hasVal(this)) {
  1447. this.value = val;
  1448. } else {
  1449. _setAttr(this, 'value' , val);
  1450. }
  1451. });
  1452. return self;
  1453. }
  1454. },
  1455. css : function(key, val) {
  1456. var self = this;
  1457. if (key === undefined) {
  1458. return _getCssList(self.attr('style'));
  1459. }
  1460. if (typeof key === 'object') {
  1461. _each(key, function(k, v) {
  1462. self.css(k, v);
  1463. });
  1464. return self;
  1465. }
  1466. if (val === undefined) {
  1467. if (self.length < 1) {
  1468. return '';
  1469. }
  1470. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1471. }
  1472. self.each(function() {
  1473. this.style[_toCamel(key)] = val;
  1474. });
  1475. return self;
  1476. },
  1477. width : function(val) {
  1478. var self = this;
  1479. if (val === undefined) {
  1480. if (self.length < 1) {
  1481. return 0;
  1482. }
  1483. return self[0].offsetWidth;
  1484. }
  1485. return self.css('width', _addUnit(val));
  1486. },
  1487. height : function(val) {
  1488. var self = this;
  1489. if (val === undefined) {
  1490. if (self.length < 1) {
  1491. return 0;
  1492. }
  1493. return self[0].offsetHeight;
  1494. }
  1495. return self.css('height', _addUnit(val));
  1496. },
  1497. opacity : function(val) {
  1498. this.each(function() {
  1499. if (this.style.opacity === undefined) {
  1500. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1501. } else {
  1502. this.style.opacity = val == 1 ? '' : val;
  1503. }
  1504. });
  1505. return this;
  1506. },
  1507. data : function(key, val) {
  1508. var self = this;
  1509. key = 'kindeditor_data_' + key;
  1510. if (val === undefined) {
  1511. if (self.length < 1) {
  1512. return null;
  1513. }
  1514. return self[0][key];
  1515. }
  1516. this.each(function() {
  1517. this[key] = val;
  1518. });
  1519. return self;
  1520. },
  1521. pos : function() {
  1522. var self = this, node = self[0], x = 0, y = 0;
  1523. if (node) {
  1524. if (node.getBoundingClientRect) {
  1525. var box = node.getBoundingClientRect(),
  1526. pos = _getScrollPos(self.doc);
  1527. x = box.left + pos.x;
  1528. y = box.top + pos.y;
  1529. } else {
  1530. while (node) {
  1531. x += node.offsetLeft;
  1532. y += node.offsetTop;
  1533. node = node.offsetParent;
  1534. }
  1535. }
  1536. }
  1537. return {x : _round(x), y : _round(y)};
  1538. },
  1539. clone : function(bool) {
  1540. if (this.length < 1) {
  1541. return new KNode([]);
  1542. }
  1543. return new KNode(this[0].cloneNode(bool));
  1544. },
  1545. append : function(expr) {
  1546. this.each(function() {
  1547. if (this.appendChild) {
  1548. this.appendChild(_get(expr));
  1549. }
  1550. });
  1551. return this;
  1552. },
  1553. appendTo : function(expr) {
  1554. this.each(function() {
  1555. _get(expr).appendChild(this);
  1556. });
  1557. return this;
  1558. },
  1559. before : function(expr) {
  1560. this.each(function() {
  1561. this.parentNode.insertBefore(_get(expr), this);
  1562. });
  1563. return this;
  1564. },
  1565. after : function(expr) {
  1566. this.each(function() {
  1567. if (this.nextSibling) {
  1568. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1569. } else {
  1570. this.parentNode.appendChild(_get(expr));
  1571. }
  1572. });
  1573. return this;
  1574. },
  1575. replaceWith : function(expr) {
  1576. var nodes = [];
  1577. this.each(function(i, node) {
  1578. _unbind(node);
  1579. var newNode = _get(expr);
  1580. node.parentNode.replaceChild(newNode, node);
  1581. nodes.push(newNode);
  1582. });
  1583. return K(nodes);
  1584. },
  1585. empty : function() {
  1586. var self = this;
  1587. self.each(function(i, node) {
  1588. var child = node.firstChild;
  1589. while (child) {
  1590. if (!node.parentNode) {
  1591. return;
  1592. }
  1593. var next = child.nextSibling;
  1594. child.parentNode.removeChild(child);
  1595. child = next;
  1596. }
  1597. });
  1598. return self;
  1599. },
  1600. remove : function(keepChilds) {
  1601. var self = this;
  1602. self.each(function(i, node) {
  1603. if (!node.parentNode) {
  1604. return;
  1605. }
  1606. _unbind(node);
  1607. if (keepChilds) {
  1608. var child = node.firstChild;
  1609. while (child) {
  1610. var next = child.nextSibling;
  1611. node.parentNode.insertBefore(child, node);
  1612. child = next;
  1613. }
  1614. }
  1615. node.parentNode.removeChild(node);
  1616. delete self[i];
  1617. });
  1618. self.length = 0;
  1619. return self;
  1620. },
  1621. show : function(val) {
  1622. var self = this;
  1623. if (val === undefined) {
  1624. val = self._originDisplay || '';
  1625. }
  1626. if (self.css('display') != 'none') {
  1627. return self;
  1628. }
  1629. return self.css('display', val);
  1630. },
  1631. hide : function() {
  1632. var self = this;
  1633. if (self.length < 1) {
  1634. return self;
  1635. }
  1636. self._originDisplay = self[0].style.display;
  1637. return self.css('display', 'none');
  1638. },
  1639. outer : function() {
  1640. var self = this;
  1641. if (self.length < 1) {
  1642. return '';
  1643. }
  1644. var div = self.doc.createElement('div'), html;
  1645. div.appendChild(self[0].cloneNode(true));
  1646. html = _formatHtml(div.innerHTML);
  1647. div = null;
  1648. return html;
  1649. },
  1650. isSingle : function() {
  1651. return !!_SINGLE_TAG_MAP[this.name];
  1652. },
  1653. isInline : function() {
  1654. return !!_INLINE_TAG_MAP[this.name];
  1655. },
  1656. isBlock : function() {
  1657. return !!_BLOCK_TAG_MAP[this.name];
  1658. },
  1659. isStyle : function() {
  1660. return !!_STYLE_TAG_MAP[this.name];
  1661. },
  1662. isControl : function() {
  1663. return !!_CONTROL_TAG_MAP[this.name];
  1664. },
  1665. contains : function(otherNode) {
  1666. if (this.length < 1) {
  1667. return false;
  1668. }
  1669. return _contains(this[0], _get(otherNode));
  1670. },
  1671. parent : function() {
  1672. if (this.length < 1) {
  1673. return null;
  1674. }
  1675. var node = this[0].parentNode;
  1676. return node ? new KNode(node) : null;
  1677. },
  1678. children : function() {
  1679. if (this.length < 1) {
  1680. return new KNode([]);
  1681. }
  1682. var list = [], child = this[0].firstChild;
  1683. while (child) {
  1684. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1685. list.push(child);
  1686. }
  1687. child = child.nextSibling;
  1688. }
  1689. return new KNode(list);
  1690. },
  1691. first : function() {
  1692. var list = this.children();
  1693. return list.length > 0 ? list.eq(0) : null;
  1694. },
  1695. last : function() {
  1696. var list = this.children();
  1697. return list.length > 0 ? list.eq(list.length - 1) : null;
  1698. },
  1699. index : function() {
  1700. if (this.length < 1) {
  1701. return -1;
  1702. }
  1703. var i = -1, sibling = this[0];
  1704. while (sibling) {
  1705. i++;
  1706. sibling = sibling.previousSibling;
  1707. }
  1708. return i;
  1709. },
  1710. prev : function() {
  1711. if (this.length < 1) {
  1712. return null;
  1713. }
  1714. var node = this[0].previousSibling;
  1715. return node ? new KNode(node) : null;
  1716. },
  1717. next : function() {
  1718. if (this.length < 1) {
  1719. return null;
  1720. }
  1721. var node = this[0].nextSibling;
  1722. return node ? new KNode(node) : null;
  1723. },
  1724. scan : function(fn, order) {
  1725. if (this.length < 1) {
  1726. return;
  1727. }
  1728. order = (order === undefined) ? true : order;
  1729. function walk(node) {
  1730. var n = order ? node.firstChild : node.lastChild;
  1731. while (n) {
  1732. var next = order ? n.nextSibling : n.previousSibling;
  1733. if (fn(n) === false) {
  1734. return false;
  1735. }
  1736. if (walk(n) === false) {
  1737. return false;
  1738. }
  1739. n = next;
  1740. }
  1741. }
  1742. walk(this[0]);
  1743. return this;
  1744. }
  1745. });
  1746. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1747. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1748. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1749. KNode.prototype[type] = function(fn) {
  1750. return fn ? this.bind(type, fn) : this.fire(type);
  1751. };
  1752. });
  1753. var _K = K;
  1754. K = function(expr, root) {
  1755. if (expr === undefined || expr === null) {
  1756. return;
  1757. }
  1758. function newNode(node) {
  1759. if (!node[0]) {
  1760. node = [];
  1761. }
  1762. return new KNode(node);
  1763. }
  1764. if (typeof expr === 'string') {
  1765. if (root) {
  1766. root = _get(root);
  1767. }
  1768. var length = expr.length;
  1769. if (expr.charAt(0) === '@') {
  1770. expr = expr.substr(1);
  1771. }
  1772. if (expr.length !== length || /<.+>/.test(expr)) {
  1773. var doc = root ? root.ownerDocument || root : document,
  1774. div = doc.createElement('div'), list = [];
  1775. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1776. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1777. var child = div.childNodes[i];
  1778. if (child.id == '__kindeditor_temp_tag__') {
  1779. continue;
  1780. }
  1781. list.push(child);
  1782. }
  1783. return newNode(list);
  1784. }
  1785. return newNode(_queryAll(expr, root));
  1786. }
  1787. if (expr && expr.constructor === KNode) {
  1788. return expr;
  1789. }
  1790. if (expr.toArray) {
  1791. expr = expr.toArray();
  1792. }
  1793. if (_isArray(expr)) {
  1794. return newNode(expr);
  1795. }
  1796. return newNode(_toArray(arguments));
  1797. };
  1798. _each(_K, function(key, val) {
  1799. K[key] = val;
  1800. });
  1801. K.NodeClass = KNode;
  1802. window.KindEditor = K;
  1803. var _START_TO_START = 0,
  1804. _START_TO_END = 1,
  1805. _END_TO_END = 2,
  1806. _END_TO_START = 3,
  1807. _BOOKMARK_ID = 0;
  1808. function _updateCollapsed(range) {
  1809. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1810. return range;
  1811. }
  1812. function _copyAndDelete(range, isCopy, isDelete) {
  1813. var doc = range.doc, nodeList = [];
  1814. function splitTextNode(node, startOffset, endOffset) {
  1815. var length = node.nodeValue.length, centerNode;
  1816. if (isCopy) {
  1817. var cloneNode = node.cloneNode(true);
  1818. if (startOffset > 0) {
  1819. centerNode = cloneNode.splitText(startOffset);
  1820. } else {
  1821. centerNode = cloneNode;
  1822. }
  1823. if (endOffset < length) {
  1824. centerNode.splitText(endOffset - startOffset);
  1825. }
  1826. }
  1827. if (isDelete) {
  1828. var center = node;
  1829. if (startOffset > 0) {
  1830. center = node.splitText(startOffset);
  1831. range.setStart(node, startOffset);
  1832. }
  1833. if (endOffset < length) {
  1834. var right = center.splitText(endOffset - startOffset);
  1835. range.setEnd(right, 0);
  1836. }
  1837. nodeList.push(center);
  1838. }
  1839. return centerNode;
  1840. }
  1841. function removeNodes() {
  1842. if (isDelete) {
  1843. range.up().collapse(true);
  1844. }
  1845. for (var i = 0, len = nodeList.length; i < len; i++) {
  1846. var node = nodeList[i];
  1847. if (node.parentNode) {
  1848. node.parentNode.removeChild(node);
  1849. }
  1850. }
  1851. }
  1852. var copyRange = range.cloneRange().down();
  1853. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1854. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1855. if (ancestor.nodeType == 3) {
  1856. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1857. if (isCopy) {
  1858. frag.appendChild(textNode);
  1859. }
  1860. removeNodes();
  1861. return isCopy ? frag : range;
  1862. }
  1863. function extractNodes(parent, frag) {
  1864. var node = parent.firstChild, nextNode;
  1865. while (node) {
  1866. var testRange = new KRange(doc).selectNode(node);
  1867. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1868. if (start >= 0 && incStart <= 0) {
  1869. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1870. }
  1871. if (incStart >= 0 && incEnd <= 0) {
  1872. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1873. }
  1874. if (incEnd >= 0 && end <= 0) {
  1875. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1876. }
  1877. if (end >= 0) {
  1878. return false;
  1879. }
  1880. nextNode = node.nextSibling;
  1881. if (start > 0) {
  1882. if (node.nodeType == 1) {
  1883. if (incStart >= 0 && incEnd <= 0) {
  1884. if (isCopy) {
  1885. frag.appendChild(node.cloneNode(true));
  1886. }
  1887. if (isDelete) {
  1888. nodeList.push(node);
  1889. }
  1890. } else {
  1891. var childFlag;
  1892. if (isCopy) {
  1893. childFlag = node.cloneNode(false);
  1894. frag.appendChild(childFlag);
  1895. }
  1896. if (extractNodes(node, childFlag) === false) {
  1897. return false;
  1898. }
  1899. }
  1900. } else if (node.nodeType == 3) {
  1901. var textNode;
  1902. if (node == copyRange.startContainer) {
  1903. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1904. } else if (node == copyRange.endContainer) {
  1905. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1906. } else {
  1907. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1908. }
  1909. if (isCopy) {
  1910. try {
  1911. frag.appendChild(textNode);
  1912. } catch(e) {}
  1913. }
  1914. }
  1915. }
  1916. node = nextNode;
  1917. }
  1918. }
  1919. extractNodes(ancestor, frag);
  1920. if (isDelete) {
  1921. range.up().collapse(true);
  1922. }
  1923. for (var i = 0, len = nodeList.length; i < len; i++) {
  1924. var node = nodeList[i];
  1925. if (node.parentNode) {
  1926. node.parentNode.removeChild(node);
  1927. }
  1928. }
  1929. return isCopy ? frag : range;
  1930. }
  1931. function _moveToElementText(range, el) {
  1932. var node = el;
  1933. while (node) {
  1934. var knode = K(node);
  1935. if (knode.name == 'marquee' || knode.name == 'select') {
  1936. return;
  1937. }
  1938. node = node.parentNode;
  1939. }
  1940. try {
  1941. range.moveToElementText(el);
  1942. } catch(e) {}
  1943. }
  1944. function _getStartEnd(rng, isStart) {
  1945. var doc = rng.parentElement().ownerDocument,
  1946. pointRange = rng.duplicate();
  1947. pointRange.collapse(isStart);
  1948. var parent = pointRange.parentElement(),
  1949. nodes = parent.childNodes;
  1950. if (nodes.length === 0) {
  1951. return {node: parent.parentNode, offset: K(parent).index()};
  1952. }
  1953. var startNode = doc, startPos = 0, cmp = -1;
  1954. var testRange = rng.duplicate();
  1955. _moveToElementText(testRange, parent);
  1956. for (var i = 0, len = nodes.length; i < len; i++) {
  1957. var node = nodes[i];
  1958. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1959. if (cmp === 0) {
  1960. return {node: node.parentNode, offset: i};
  1961. }
  1962. if (node.nodeType == 1) {
  1963. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1964. if (knode.isControl()) {
  1965. dummy = doc.createElement('span');
  1966. knode.after(dummy);
  1967. newNode = dummy;
  1968. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1969. }
  1970. _moveToElementText(nodeRange, newNode);
  1971. testRange.setEndPoint('StartToEnd', nodeRange);
  1972. if (cmp > 0) {
  1973. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1974. } else {
  1975. startPos = 0;
  1976. }
  1977. if (dummy) {
  1978. K(dummy).remove();
  1979. }
  1980. } else if (node.nodeType == 3) {
  1981. testRange.moveStart('character', node.nodeValue.length);
  1982. startPos += node.nodeValue.length;
  1983. }
  1984. if (cmp < 0) {
  1985. startNode = node;
  1986. }
  1987. }
  1988. if (cmp < 0 && startNode.nodeType == 1) {
  1989. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1990. }
  1991. if (cmp > 0) {
  1992. while (startNode.nextSibling && startNode.nodeType == 1) {
  1993. startNode = startNode.nextSibling;
  1994. }
  1995. }
  1996. testRange = rng.duplicate();
  1997. _moveToElementText(testRange, parent);
  1998. testRange.setEndPoint('StartToEnd', pointRange);
  1999. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  2000. if (cmp > 0 && startNode.nodeType == 3) {
  2001. var prevNode = startNode.previousSibling;
  2002. while (prevNode && prevNode.nodeType == 3) {
  2003. startPos -= prevNode.nodeValue.length;
  2004. prevNode = prevNode.previousSibling;
  2005. }
  2006. }
  2007. return {node: startNode, offset: startPos};
  2008. }
  2009. function _getEndRange(node, offset) {
  2010. var doc = node.ownerDocument || node,
  2011. range = doc.body.createTextRange();
  2012. if (doc == node) {
  2013. range.collapse(true);
  2014. return range;
  2015. }
  2016. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2017. var children = node.childNodes, isStart, child;
  2018. if (offset === 0) {
  2019. child = children[0];
  2020. isStart = true;
  2021. } else {
  2022. child = children[offset - 1];
  2023. isStart = false;
  2024. }
  2025. if (!child) {
  2026. return range;
  2027. }
  2028. if (K(child).name === 'head') {
  2029. if (offset === 1) {
  2030. isStart = true;
  2031. }
  2032. if (offset === 2) {
  2033. isStart = false;
  2034. }
  2035. range.collapse(isStart);
  2036. return range;
  2037. }
  2038. if (child.nodeType == 1) {
  2039. var kchild = K(child), span;
  2040. if (kchild.isControl()) {
  2041. span = doc.createElement('span');
  2042. if (isStart) {
  2043. kchild.before(span);
  2044. } else {
  2045. kchild.after(span);
  2046. }
  2047. child = span;
  2048. }
  2049. _moveToElementText(range, child);
  2050. range.collapse(isStart);
  2051. if (span) {
  2052. K(span).remove();
  2053. }
  2054. return range;
  2055. }
  2056. node = child;
  2057. offset = isStart ? 0 : child.nodeValue.length;
  2058. }
  2059. var dummy = doc.createElement('span');
  2060. K(node).before(dummy);
  2061. _moveToElementText(range, dummy);
  2062. range.moveStart('character', offset);
  2063. K(dummy).remove();
  2064. return range;
  2065. }
  2066. function _toRange(rng) {
  2067. var doc, range;
  2068. function tr2td(start) {
  2069. if (K(start.node).name == 'tr') {
  2070. start.node = start.node.cells[start.offset];
  2071. start.offset = 0;
  2072. }
  2073. }
  2074. if (_IERANGE) {
  2075. if (rng.item) {
  2076. doc = _getDoc(rng.item(0));
  2077. range = new KRange(doc);
  2078. range.selectNode(rng.item(0));
  2079. return range;
  2080. }
  2081. doc = rng.parentElement().ownerDocument;
  2082. var start = _getStartEnd(rng, true),
  2083. end = _getStartEnd(rng, false);
  2084. tr2td(start);
  2085. tr2td(end);
  2086. range = new KRange(doc);
  2087. range.setStart(start.node, start.offset);
  2088. range.setEnd(end.node, end.offset);
  2089. return range;
  2090. }
  2091. var startContainer = rng.startContainer;
  2092. doc = startContainer.ownerDocument || startContainer;
  2093. range = new KRange(doc);
  2094. range.setStart(startContainer, rng.startOffset);
  2095. range.setEnd(rng.endContainer, rng.endOffset);
  2096. return range;
  2097. }
  2098. function KRange(doc) {
  2099. this.init(doc);
  2100. }
  2101. _extend(KRange, {
  2102. init : function(doc) {
  2103. var self = this;
  2104. self.startContainer = doc;
  2105. self.startOffset = 0;
  2106. self.endContainer = doc;
  2107. self.endOffset = 0;
  2108. self.collapsed = true;
  2109. self.doc = doc;
  2110. },
  2111. commonAncestor : function() {
  2112. function getParents(node) {
  2113. var parents = [];
  2114. while (node) {
  2115. parents.push(node);
  2116. node = node.parentNode;
  2117. }
  2118. return parents;
  2119. }
  2120. var parentsA = getParents(this.startContainer),
  2121. parentsB = getParents(this.endContainer),
  2122. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2123. while (++i) {
  2124. parentA = parentsA[lenA - i];
  2125. parentB = parentsB[lenB - i];
  2126. if (!parentA || !parentB || parentA !== parentB) {
  2127. break;
  2128. }
  2129. }
  2130. return parentsA[lenA - i + 1];
  2131. },
  2132. setStart : function(node, offset) {
  2133. var self = this, doc = self.doc;
  2134. self.startContainer = node;
  2135. self.startOffset = offset;
  2136. if (self.endContainer === doc) {
  2137. self.endContainer = node;
  2138. self.endOffset = offset;
  2139. }
  2140. return _updateCollapsed(this);
  2141. },
  2142. setEnd : function(node, offset) {
  2143. var self = this, doc = self.doc;
  2144. self.endContainer = node;
  2145. self.endOffset = offset;
  2146. if (self.startContainer === doc) {
  2147. self.startContainer = node;
  2148. self.startOffset = offset;
  2149. }
  2150. return _updateCollapsed(this);
  2151. },
  2152. setStartBefore : function(node) {
  2153. return this.setStart(node.parentNode || this.doc, K(node).index());
  2154. },
  2155. setStartAfter : function(node) {
  2156. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2157. },
  2158. setEndBefore : function(node) {
  2159. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2160. },
  2161. setEndAfter : function(node) {
  2162. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2163. },
  2164. selectNode : function(node) {
  2165. return this.setStartBefore(node).setEndAfter(node);
  2166. },
  2167. selectNodeContents : function(node) {
  2168. var knode = K(node);
  2169. if (knode.type == 3 || knode.isSingle()) {
  2170. return this.selectNode(node);
  2171. }
  2172. var children = knode.children();
  2173. if (children.length > 0) {
  2174. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2175. }
  2176. return this.setStart(node, 0).setEnd(node, 0);
  2177. },
  2178. collapse : function(toStart) {
  2179. if (toStart) {
  2180. return this.setEnd(this.startContainer, this.startOffset);
  2181. }
  2182. return this.setStart(this.endContainer, this.endOffset);
  2183. },
  2184. compareBoundaryPoints : function(how, range) {
  2185. var rangeA = this.get(), rangeB = range.get();
  2186. if (_IERANGE) {
  2187. var arr = {};
  2188. arr[_START_TO_START] = 'StartToStart';
  2189. arr[_START_TO_END] = 'EndToStart';
  2190. arr[_END_TO_END] = 'EndToEnd';
  2191. arr[_END_TO_START] = 'StartToEnd';
  2192. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2193. if (cmp !== 0) {
  2194. return cmp;
  2195. }
  2196. var nodeA, nodeB, nodeC, posA, posB;
  2197. if (how === _START_TO_START || how === _END_TO_START) {
  2198. nodeA = this.startContainer;
  2199. posA = this.startOffset;
  2200. }
  2201. if (how === _START_TO_END || how === _END_TO_END) {
  2202. nodeA = this.endContainer;
  2203. posA = this.endOffset;
  2204. }
  2205. if (how === _START_TO_START || how === _START_TO_END) {
  2206. nodeB = range.startContainer;
  2207. posB = range.startOffset;
  2208. }
  2209. if (how === _END_TO_END || how === _END_TO_START) {
  2210. nodeB = range.endContainer;
  2211. posB = range.endOffset;
  2212. }
  2213. if (nodeA === nodeB) {
  2214. var diff = posA - posB;
  2215. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2216. }
  2217. nodeC = nodeB;
  2218. while (nodeC && nodeC.parentNode !== nodeA) {
  2219. nodeC = nodeC.parentNode;
  2220. }
  2221. if (nodeC) {
  2222. return K(nodeC).index() >= posA ? -1 : 1;
  2223. }
  2224. nodeC = nodeA;
  2225. while (nodeC && nodeC.parentNode !== nodeB) {
  2226. nodeC = nodeC.parentNode;
  2227. }
  2228. if (nodeC) {
  2229. return K(nodeC).index() >= posB ? 1 : -1;
  2230. }
  2231. nodeC = K(nodeB).next();
  2232. if (nodeC && nodeC.contains(nodeA)) {
  2233. return 1;
  2234. }
  2235. nodeC = K(nodeA).next();
  2236. if (nodeC && nodeC.contains(nodeB)) {
  2237. return -1;
  2238. }
  2239. } else {
  2240. return rangeA.compareBoundaryPoints(how, rangeB);
  2241. }
  2242. },
  2243. cloneRange : function() {
  2244. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2245. },
  2246. toString : function() {
  2247. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2248. return str.replace(/\r\n|\n|\r/g, '');
  2249. },
  2250. cloneContents : function() {
  2251. return _copyAndDelete(this, true, false);
  2252. },
  2253. deleteContents : function() {
  2254. return _copyAndDelete(this, false, true);
  2255. },
  2256. extractContents : function() {
  2257. return _copyAndDelete(this, true, true);
  2258. },
  2259. insertNode : function(node) {
  2260. var self = this,
  2261. sc = self.startContainer, so = self.startOffset,
  2262. ec = self.endContainer, eo = self.endOffset,
  2263. firstChild, lastChild, c, nodeCount = 1;
  2264. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2265. firstChild = node.firstChild;
  2266. lastChild = node.lastChild;
  2267. nodeCount = node.childNodes.length;
  2268. }
  2269. if (sc.nodeType == 1) {
  2270. c = sc.childNodes[so];
  2271. if (c) {
  2272. sc.insertBefore(node, c);
  2273. if (sc === ec) {
  2274. eo += nodeCount;
  2275. }
  2276. } else {
  2277. sc.appendChild(node);
  2278. }
  2279. } else if (sc.nodeType == 3) {
  2280. if (so === 0) {
  2281. sc.parentNode.insertBefore(node, sc);
  2282. if (sc.parentNode === ec) {
  2283. eo += nodeCount;
  2284. }
  2285. } else if (so >= sc.nodeValue.length) {
  2286. if (sc.nextSibling) {
  2287. sc.parentNode.insertBefore(node, sc.nextSibling);
  2288. } else {
  2289. sc.parentNode.appendChild(node);
  2290. }
  2291. } else {
  2292. if (so > 0) {
  2293. c = sc.splitText(so);
  2294. } else {
  2295. c = sc;
  2296. }
  2297. sc.parentNode.insertBefore(node, c);
  2298. if (sc === ec) {
  2299. ec = c;
  2300. eo -= so;
  2301. }
  2302. }
  2303. }
  2304. if (firstChild) {
  2305. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2306. } else {
  2307. self.selectNode(node);
  2308. }
  2309. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2310. return self;
  2311. }
  2312. return self.setEnd(ec, eo);
  2313. },
  2314. surroundContents : function(node) {
  2315. node.appendChild(this.extractContents());
  2316. return this.insertNode(node).selectNode(node);
  2317. },
  2318. isControl : function() {
  2319. var self = this,
  2320. sc = self.startContainer, so = self.startOffset,
  2321. ec = self.endContainer, eo = self.endOffset, rng;
  2322. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2323. },
  2324. get : function(hasControlRange) {
  2325. var self = this, doc = self.doc, node, rng;
  2326. if (!_IERANGE) {
  2327. rng = doc.createRange();
  2328. try {
  2329. rng.setStart(self.startContainer, self.startOffset);
  2330. rng.setEnd(self.endContainer, self.endOffset);
  2331. } catch (e) {}
  2332. return rng;
  2333. }
  2334. if (hasControlRange && self.isControl()) {
  2335. rng = doc.body.createControlRange();
  2336. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2337. return rng;
  2338. }
  2339. var range = self.cloneRange().down();
  2340. rng = doc.body.createTextRange();
  2341. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2342. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2343. return rng;
  2344. },
  2345. html : function() {
  2346. return K(this.cloneContents()).outer();
  2347. },
  2348. down : function() {
  2349. var self = this;
  2350. function downPos(node, pos, isStart) {
  2351. if (node.nodeType != 1) {
  2352. return;
  2353. }
  2354. var children = K(node).children();
  2355. if (children.length === 0) {
  2356. return;
  2357. }
  2358. var left, right, child, offset;
  2359. if (pos > 0) {
  2360. left = children.eq(pos - 1);
  2361. }
  2362. if (pos < children.length) {
  2363. right = children.eq(pos);
  2364. }
  2365. if (left && left.type == 3) {
  2366. child = left[0];
  2367. offset = child.nodeValue.length;
  2368. }
  2369. if (right && right.type == 3) {
  2370. child = right[0];
  2371. offset = 0;
  2372. }
  2373. if (!child) {
  2374. return;
  2375. }
  2376. if (isStart) {
  2377. self.setStart(child, offset);
  2378. } else {
  2379. self.setEnd(child, offset);
  2380. }
  2381. }
  2382. downPos(self.startContainer, self.startOffset, true);
  2383. downPos(self.endContainer, self.endOffset, false);
  2384. return self;
  2385. },
  2386. up : function() {
  2387. var self = this;
  2388. function upPos(node, pos, isStart) {
  2389. if (node.nodeType != 3) {
  2390. return;
  2391. }
  2392. if (pos === 0) {
  2393. if (isStart) {
  2394. self.setStartBefore(node);
  2395. } else {
  2396. self.setEndBefore(node);
  2397. }
  2398. } else if (pos == node.nodeValue.length) {
  2399. if (isStart) {
  2400. self.setStartAfter(node);
  2401. } else {
  2402. self.setEndAfter(node);
  2403. }
  2404. }
  2405. }
  2406. upPos(self.startContainer, self.startOffset, true);
  2407. upPos(self.endContainer, self.endOffset, false);
  2408. return self;
  2409. },
  2410. enlarge : function(toBlock) {
  2411. var self = this;
  2412. self.up();
  2413. function enlargePos(node, pos, isStart) {
  2414. var knode = K(node), parent;
  2415. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2416. return;
  2417. }
  2418. if (pos === 0) {
  2419. while (!knode.prev()) {
  2420. parent = knode.parent();
  2421. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2422. break;
  2423. }
  2424. knode = parent;
  2425. }
  2426. if (isStart) {
  2427. self.setStartBefore(knode[0]);
  2428. } else {
  2429. self.setEndBefore(knode[0]);
  2430. }
  2431. } else if (pos == knode.children().length) {
  2432. while (!knode.next()) {
  2433. parent = knode.parent();
  2434. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2435. break;
  2436. }
  2437. knode = parent;
  2438. }
  2439. if (isStart) {
  2440. self.setStartAfter(knode[0]);
  2441. } else {
  2442. self.setEndAfter(knode[0]);
  2443. }
  2444. }
  2445. }
  2446. enlargePos(self.startContainer, self.startOffset, true);
  2447. enlargePos(self.endContainer, self.endOffset, false);
  2448. return self;
  2449. },
  2450. shrink : function() {
  2451. var self = this, child, collapsed = self.collapsed;
  2452. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2453. self.setStart(child, 0);
  2454. }
  2455. if (collapsed) {
  2456. return self.collapse(collapsed);
  2457. }
  2458. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2459. self.setEnd(child, child.childNodes.length);
  2460. }
  2461. return self;
  2462. },
  2463. createBookmark : function(serialize) {
  2464. var self = this, doc = self.doc, endNode,
  2465. startNode = K('<span style="display:none;"></span>', doc)[0];
  2466. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2467. if (!self.collapsed) {
  2468. endNode = startNode.cloneNode(true);
  2469. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2470. }
  2471. if (endNode) {
  2472. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2473. }
  2474. self.insertNode(startNode).setStartAfter(startNode);
  2475. return {
  2476. start : serialize ? '#' + startNode.id : startNode,
  2477. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2478. };
  2479. },
  2480. moveToBookmark : function(bookmark) {
  2481. var self = this, doc = self.doc,
  2482. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2483. if (!start || start.length < 1) {
  2484. return self;
  2485. }
  2486. self.setStartBefore(start[0]);
  2487. start.remove();
  2488. if (end && end.length > 0) {
  2489. self.setEndBefore(end[0]);
  2490. end.remove();
  2491. } else {
  2492. self.collapse(true);
  2493. }
  2494. return self;
  2495. },
  2496. dump : function() {
  2497. console.log('--------------------');
  2498. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2499. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2500. }
  2501. });
  2502. function _range(mixed) {
  2503. if (!mixed.nodeName) {
  2504. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2505. }
  2506. return new KRange(mixed);
  2507. }
  2508. K.RangeClass = KRange;
  2509. K.range = _range;
  2510. K.START_TO_START = _START_TO_START;
  2511. K.START_TO_END = _START_TO_END;
  2512. K.END_TO_END = _END_TO_END;
  2513. K.END_TO_START = _END_TO_START;
  2514. function _nativeCommand(doc, key, val) {
  2515. try {
  2516. doc.execCommand(key, false, val);
  2517. } catch(e) {}
  2518. }
  2519. function _nativeCommandValue(doc, key) {
  2520. var val = '';
  2521. try {
  2522. val = doc.queryCommandValue(key);
  2523. } catch (e) {}
  2524. if (typeof val !== 'string') {
  2525. val = '';
  2526. }
  2527. return val;
  2528. }
  2529. function _getSel(doc) {
  2530. var win = _getWin(doc);
  2531. return _IERANGE ? doc.selection : win.getSelection();
  2532. }
  2533. function _getRng(doc) {
  2534. var sel = _getSel(doc), rng;
  2535. try {
  2536. if (sel.rangeCount > 0) {
  2537. rng = sel.getRangeAt(0);
  2538. } else {
  2539. rng = sel.createRange();
  2540. }
  2541. } catch(e) {}
  2542. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2543. return null;
  2544. }
  2545. return rng;
  2546. }
  2547. function _singleKeyMap(map) {
  2548. var newMap = {}, arr, v;
  2549. _each(map, function(key, val) {
  2550. arr = key.split(',');
  2551. for (var i = 0, len = arr.length; i < len; i++) {
  2552. v = arr[i];
  2553. newMap[v] = val;
  2554. }
  2555. });
  2556. return newMap;
  2557. }
  2558. function _hasAttrOrCss(knode, map) {
  2559. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2560. }
  2561. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2562. mapKey = mapKey || knode.name;
  2563. if (knode.type !== 1) {
  2564. return false;
  2565. }
  2566. var newMap = _singleKeyMap(map);
  2567. if (!newMap[mapKey]) {
  2568. return false;
  2569. }
  2570. var arr = newMap[mapKey].split(',');
  2571. for (var i = 0, len = arr.length; i < len; i++) {
  2572. var key = arr[i];
  2573. if (key === '*') {
  2574. return true;
  2575. }
  2576. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2577. var method = match[1] ? 'css' : 'attr';
  2578. key = match[2];
  2579. var val = match[3] || '';
  2580. if (val === '' && knode[method](key) !== '') {
  2581. return true;
  2582. }
  2583. if (val !== '' && knode[method](key) === val) {
  2584. return true;
  2585. }
  2586. }
  2587. return false;
  2588. }
  2589. function _removeAttrOrCss(knode, map) {
  2590. if (knode.type != 1) {
  2591. return;
  2592. }
  2593. _removeAttrOrCssByKey(knode, map, '*');
  2594. _removeAttrOrCssByKey(knode, map);
  2595. }
  2596. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2597. mapKey = mapKey || knode.name;
  2598. if (knode.type !== 1) {
  2599. return;
  2600. }
  2601. var newMap = _singleKeyMap(map);
  2602. if (!newMap[mapKey]) {
  2603. return;
  2604. }
  2605. var arr = newMap[mapKey].split(','), allFlag = false;
  2606. for (var i = 0, len = arr.length; i < len; i++) {
  2607. var key = arr[i];
  2608. if (key === '*') {
  2609. allFlag = true;
  2610. break;
  2611. }
  2612. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2613. key = match[2];
  2614. if (match[1]) {
  2615. key = _toCamel(key);
  2616. if (knode[0].style[key]) {
  2617. knode[0].style[key] = '';
  2618. }
  2619. } else {
  2620. knode.removeAttr(key);
  2621. }
  2622. }
  2623. if (allFlag) {
  2624. knode.remove(true);
  2625. }
  2626. }
  2627. function _getInnerNode(knode) {
  2628. var inner = knode;
  2629. while (inner.first()) {
  2630. inner = inner.first();
  2631. }
  2632. return inner;
  2633. }
  2634. function _isEmptyNode(knode) {
  2635. if (knode.type != 1 || knode.isSingle()) {
  2636. return false;
  2637. }
  2638. return knode.html().replace(/<[^>]+>/g, '') === '';
  2639. }
  2640. function _mergeWrapper(a, b) {
  2641. a = a.clone(true);
  2642. var lastA = _getInnerNode(a), childA = a, merged = false;
  2643. while (b) {
  2644. while (childA) {
  2645. if (childA.name === b.name) {
  2646. _mergeAttrs(childA, b.attr(), b.css());
  2647. merged = true;
  2648. }
  2649. childA = childA.first();
  2650. }
  2651. if (!merged) {
  2652. lastA.append(b.clone(false));
  2653. }
  2654. merged = false;
  2655. b = b.first();
  2656. }
  2657. return a;
  2658. }
  2659. function _wrapNode(knode, wrapper) {
  2660. wrapper = wrapper.clone(true);
  2661. if (knode.type == 3) {
  2662. _getInnerNode(wrapper).append(knode.clone(false));
  2663. knode.replaceWith(wrapper);
  2664. return wrapper;
  2665. }
  2666. var nodeWrapper = knode, child;
  2667. while ((child = knode.first()) && child.children().length == 1) {
  2668. knode = child;
  2669. }
  2670. child = knode.first();
  2671. var frag = knode.doc.createDocumentFragment();
  2672. while (child) {
  2673. frag.appendChild(child[0]);
  2674. child = child.next();
  2675. }
  2676. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2677. if (frag.firstChild) {
  2678. _getInnerNode(wrapper).append(frag);
  2679. }
  2680. nodeWrapper.replaceWith(wrapper);
  2681. return wrapper;
  2682. }
  2683. function _mergeAttrs(knode, attrs, styles) {
  2684. _each(attrs, function(key, val) {
  2685. if (key !== 'style') {
  2686. knode.attr(key, val);
  2687. }
  2688. });
  2689. _each(styles, function(key, val) {
  2690. knode.css(key, val);
  2691. });
  2692. }
  2693. function _inPreElement(knode) {
  2694. while (knode && knode.name != 'body') {
  2695. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2696. return true;
  2697. }
  2698. knode = knode.parent();
  2699. }
  2700. return false;
  2701. }
  2702. function KCmd(range) {
  2703. this.init(range);
  2704. }
  2705. _extend(KCmd, {
  2706. init : function(range) {
  2707. var self = this, doc = range.doc;
  2708. self.doc = doc;
  2709. self.win = _getWin(doc);
  2710. self.sel = _getSel(doc);
  2711. self.range = range;
  2712. },
  2713. selection : function(forceReset) {
  2714. var self = this, doc = self.doc, rng = _getRng(doc);
  2715. self.sel = _getSel(doc);
  2716. if (rng) {
  2717. self.range = _range(rng);
  2718. if (K(self.range.startContainer).name == 'html') {
  2719. self.range.selectNodeContents(doc.body).collapse(false);
  2720. }
  2721. return self;
  2722. }
  2723. if (forceReset) {
  2724. self.range.selectNodeContents(doc.body).collapse(false);
  2725. }
  2726. return self;
  2727. },
  2728. select : function(hasDummy) {
  2729. hasDummy = _undef(hasDummy, true);
  2730. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2731. sc = range.startContainer, so = range.startOffset,
  2732. ec = range.endContainer, eo = range.endOffset,
  2733. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2734. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2735. if (_IERANGE) {
  2736. var dummy = K('<span>&nbsp;</span>', doc);
  2737. range.insertNode(dummy[0]);
  2738. rng = doc.body.createTextRange();
  2739. try {
  2740. rng.moveToElementText(dummy[0]);
  2741. } catch(ex) {}
  2742. rng.collapse(false);
  2743. rng.select();
  2744. dummy.remove();
  2745. win.focus();
  2746. return self;
  2747. }
  2748. if (_WEBKIT) {
  2749. var children = sc.childNodes;
  2750. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2751. range.insertNode(doc.createTextNode('\u200B'));
  2752. hasU200b = true;
  2753. }
  2754. }
  2755. }
  2756. if (_IERANGE) {
  2757. try {
  2758. rng = range.get(true);
  2759. rng.select();
  2760. } catch(e) {}
  2761. } else {
  2762. if (hasU200b) {
  2763. range.collapse(false);
  2764. }
  2765. rng = range.get(true);
  2766. sel.removeAllRanges();
  2767. sel.addRange(rng);
  2768. if (doc !== document) {
  2769. var pos = K(rng.endContainer).pos();
  2770. //win.scrollTo(pos.x, pos.y);
  2771. }
  2772. }
  2773. win.focus();
  2774. return self;
  2775. },
  2776. wrap : function(val) {
  2777. var self = this, doc = self.doc, range = self.range, wrapper;
  2778. wrapper = K(val, doc);
  2779. if (range.collapsed) {
  2780. range.shrink();
  2781. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2782. return self;
  2783. }
  2784. if (wrapper.isBlock()) {
  2785. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2786. while (child.first()) {
  2787. child = child.first();
  2788. }
  2789. child.append(range.extractContents());
  2790. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2791. return self;
  2792. }
  2793. range.enlarge();
  2794. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2795. K(ancestor).scan(function(node) {
  2796. if (!isStart && node == bookmark.start) {
  2797. isStart = true;
  2798. return;
  2799. }
  2800. if (isStart) {
  2801. if (node == bookmark.end) {
  2802. return false;
  2803. }
  2804. var knode = K(node);
  2805. if (_inPreElement(knode)) {
  2806. return;
  2807. }
  2808. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2809. var parent;
  2810. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2811. knode = parent;
  2812. }
  2813. _wrapNode(knode, wrapper);
  2814. }
  2815. }
  2816. });
  2817. range.moveToBookmark(bookmark);
  2818. return self;
  2819. },
  2820. split : function(isStart, map) {
  2821. var range = this.range, doc = range.doc;
  2822. var tempRange = range.cloneRange().collapse(isStart);
  2823. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2824. parent = node.nodeType == 3 ? node.parentNode : node,
  2825. needSplit = false, knode;
  2826. while (parent && parent.parentNode) {
  2827. knode = K(parent);
  2828. if (map) {
  2829. if (!knode.isStyle()) {
  2830. break;
  2831. }
  2832. if (!_hasAttrOrCss(knode, map)) {
  2833. break;
  2834. }
  2835. } else {
  2836. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2837. break;
  2838. }
  2839. }
  2840. needSplit = true;
  2841. parent = parent.parentNode;
  2842. }
  2843. if (needSplit) {
  2844. var dummy = doc.createElement('span');
  2845. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2846. if (isStart) {
  2847. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2848. } else {
  2849. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2850. }
  2851. var frag = tempRange.extractContents(),
  2852. first = frag.firstChild, last = frag.lastChild;
  2853. if (isStart) {
  2854. tempRange.insertNode(frag);
  2855. range.setStartAfter(last).setEndBefore(dummy);
  2856. } else {
  2857. parent.appendChild(frag);
  2858. range.setStartBefore(dummy).setEndBefore(first);
  2859. }
  2860. var dummyParent = dummy.parentNode;
  2861. if (dummyParent == range.endContainer) {
  2862. var prev = K(dummy).prev(), next = K(dummy).next();
  2863. if (prev && next && prev.type == 3 && next.type == 3) {
  2864. range.setEnd(prev[0], prev[0].nodeValue.length);
  2865. } else if (!isStart) {
  2866. range.setEnd(range.endContainer, range.endOffset - 1);
  2867. }
  2868. }
  2869. dummyParent.removeChild(dummy);
  2870. }
  2871. return this;
  2872. },
  2873. remove : function(map) {
  2874. var self = this, doc = self.doc, range = self.range;
  2875. range.enlarge();
  2876. if (range.startOffset === 0) {
  2877. var ksc = K(range.startContainer), parent;
  2878. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2879. ksc = parent;
  2880. }
  2881. range.setStart(ksc[0], 0);
  2882. ksc = K(range.startContainer);
  2883. if (ksc.isBlock()) {
  2884. _removeAttrOrCss(ksc, map);
  2885. }
  2886. var kscp = ksc.parent();
  2887. if (kscp && kscp.isBlock()) {
  2888. _removeAttrOrCss(kscp, map);
  2889. }
  2890. }
  2891. var sc, so;
  2892. if (range.collapsed) {
  2893. self.split(true, map);
  2894. sc = range.startContainer;
  2895. so = range.startOffset;
  2896. if (so > 0) {
  2897. var sb = K(sc.childNodes[so - 1]);
  2898. if (sb && _isEmptyNode(sb)) {
  2899. sb.remove();
  2900. range.setStart(sc, so - 1);
  2901. }
  2902. }
  2903. var sa = K(sc.childNodes[so]);
  2904. if (sa && _isEmptyNode(sa)) {
  2905. sa.remove();
  2906. }
  2907. if (_isEmptyNode(sc)) {
  2908. range.startBefore(sc);
  2909. sc.remove();
  2910. }
  2911. range.collapse(true);
  2912. return self;
  2913. }
  2914. self.split(true, map);
  2915. self.split(false, map);
  2916. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2917. range.cloneRange().collapse(false).insertNode(endDummy);
  2918. range.cloneRange().collapse(true).insertNode(startDummy);
  2919. var nodeList = [], cmpStart = false;
  2920. K(range.commonAncestor()).scan(function(node) {
  2921. if (!cmpStart && node == startDummy) {
  2922. cmpStart = true;
  2923. return;
  2924. }
  2925. if (node == endDummy) {
  2926. return false;
  2927. }
  2928. if (cmpStart) {
  2929. nodeList.push(node);
  2930. }
  2931. });
  2932. K(startDummy).remove();
  2933. K(endDummy).remove();
  2934. sc = range.startContainer;
  2935. so = range.startOffset;
  2936. var ec = range.endContainer, eo = range.endOffset;
  2937. if (so > 0) {
  2938. var startBefore = K(sc.childNodes[so - 1]);
  2939. if (startBefore && _isEmptyNode(startBefore)) {
  2940. startBefore.remove();
  2941. range.setStart(sc, so - 1);
  2942. if (sc == ec) {
  2943. range.setEnd(ec, eo - 1);
  2944. }
  2945. }
  2946. var startAfter = K(sc.childNodes[so]);
  2947. if (startAfter && _isEmptyNode(startAfter)) {
  2948. startAfter.remove();
  2949. if (sc == ec) {
  2950. range.setEnd(ec, eo - 1);
  2951. }
  2952. }
  2953. }
  2954. var endAfter = K(ec.childNodes[range.endOffset]);
  2955. if (endAfter && _isEmptyNode(endAfter)) {
  2956. endAfter.remove();
  2957. }
  2958. var bookmark = range.createBookmark(true);
  2959. _each(nodeList, function(i, node) {
  2960. _removeAttrOrCss(K(node), map);
  2961. });
  2962. range.moveToBookmark(bookmark);
  2963. return self;
  2964. },
  2965. commonNode : function(map) {
  2966. var range = this.range;
  2967. var ec = range.endContainer, eo = range.endOffset,
  2968. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2969. function find(node) {
  2970. var child = node, parent = node;
  2971. while (parent) {
  2972. if (_hasAttrOrCss(K(parent), map)) {
  2973. return K(parent);
  2974. }
  2975. parent = parent.parentNode;
  2976. }
  2977. while (child && (child = child.lastChild)) {
  2978. if (_hasAttrOrCss(K(child), map)) {
  2979. return K(child);
  2980. }
  2981. }
  2982. return null;
  2983. }
  2984. var cNode = find(node);
  2985. if (cNode) {
  2986. return cNode;
  2987. }
  2988. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2989. var prev = K(node).prev();
  2990. if (prev) {
  2991. return find(prev);
  2992. }
  2993. }
  2994. return null;
  2995. },
  2996. commonAncestor : function(tagName) {
  2997. var range = this.range,
  2998. sc = range.startContainer, so = range.startOffset,
  2999. ec = range.endContainer, eo = range.endOffset,
  3000. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  3001. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  3002. function find(node) {
  3003. while (node) {
  3004. if (node.nodeType == 1) {
  3005. if (node.tagName.toLowerCase() === tagName) {
  3006. return node;
  3007. }
  3008. }
  3009. node = node.parentNode;
  3010. }
  3011. return null;
  3012. }
  3013. var start = find(startNode), end = find(endNode);
  3014. if (start && end && start === end) {
  3015. return K(start);
  3016. }
  3017. return null;
  3018. },
  3019. state : function(key) {
  3020. var self = this, doc = self.doc, bool = false;
  3021. try {
  3022. bool = doc.queryCommandState(key);
  3023. } catch (e) {}
  3024. return bool;
  3025. },
  3026. val : function(key) {
  3027. var self = this, doc = self.doc, range = self.range;
  3028. function lc(val) {
  3029. return val.toLowerCase();
  3030. }
  3031. key = lc(key);
  3032. var val = '', knode;
  3033. if (key === 'fontfamily' || key === 'fontname') {
  3034. val = _nativeCommandValue(doc, 'fontname');
  3035. val = val.replace(/['"]/g, '');
  3036. return lc(val);
  3037. }
  3038. if (key === 'formatblock') {
  3039. val = _nativeCommandValue(doc, key);
  3040. if (val === '') {
  3041. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3042. if (knode) {
  3043. val = knode.name;
  3044. }
  3045. }
  3046. if (val === 'Normal') {
  3047. val = 'p';
  3048. }
  3049. return lc(val);
  3050. }
  3051. if (key === 'fontsize') {
  3052. knode = self.commonNode({'*' : '.font-size'});
  3053. if (knode) {
  3054. val = knode.css('font-size');
  3055. }
  3056. return lc(val);
  3057. }
  3058. if (key === 'fontheight') {
  3059. knode = self.commonNode({'*' : '.letter-spacing'});
  3060. if (knode) {
  3061. val = knode.css('letter-spacing');
  3062. }
  3063. return lc(val);
  3064. }
  3065. if (key === 'forecolor') {
  3066. knode = self.commonNode({'*' : '.color'});
  3067. if (knode) {
  3068. val = knode.css('color');
  3069. }
  3070. val = _toHex(val);
  3071. if (val === '') {
  3072. val = 'default';
  3073. }
  3074. return lc(val);
  3075. }
  3076. if (key === 'hilitecolor') {
  3077. knode = self.commonNode({'*' : '.background-color'});
  3078. if (knode) {
  3079. val = knode.css('background-color');
  3080. }
  3081. val = _toHex(val);
  3082. if (val === '') {
  3083. val = 'default';
  3084. }
  3085. return lc(val);
  3086. }
  3087. return val;
  3088. },
  3089. toggle : function(wrapper, map) {
  3090. var self = this;
  3091. if (self.commonNode(map)) {
  3092. self.remove(map);
  3093. } else {
  3094. self.wrap(wrapper);
  3095. }
  3096. return self.select();
  3097. },
  3098. bold : function() {
  3099. return this.toggle('<strong></strong>', {
  3100. span : '.font-weight=bold',
  3101. strong : '*',
  3102. b : '*'
  3103. });
  3104. },
  3105. italic : function() {
  3106. return this.toggle('<em></em>', {
  3107. span : '.font-style=italic',
  3108. em : '*',
  3109. i : '*'
  3110. });
  3111. },
  3112. underline : function() {
  3113. return this.toggle('<u></u>', {
  3114. span : '.text-decoration=underline',
  3115. u : '*'
  3116. });
  3117. },
  3118. strikethrough : function() {
  3119. return this.toggle('<s></s>', {
  3120. span : '.text-decoration=line-through',
  3121. s : '*'
  3122. });
  3123. },
  3124. forecolor : function(val) {
  3125. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3126. },
  3127. hilitecolor : function(val) {
  3128. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3129. },
  3130. fontsize : function(val) {
  3131. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3132. },
  3133. fontheight : function(val) {
  3134. return this.wrap('<span style="letter-spacing:' + val + ';"></span>').select();
  3135. },
  3136. fontname : function(val) {
  3137. return this.fontfamily(val);
  3138. },
  3139. fontfamily : function(val) {
  3140. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3141. },
  3142. removeformat : function() {
  3143. var map = {
  3144. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3145. },
  3146. tags = _STYLE_TAG_MAP;
  3147. _each(tags, function(key, val) {
  3148. map[key] = '*';
  3149. });
  3150. this.remove(map);
  3151. return this.select();
  3152. },
  3153. inserthtml : function(val, quickMode) {
  3154. var self = this, range = self.range;
  3155. if (val === '') {
  3156. return self;
  3157. }
  3158. function pasteHtml(range, val) {
  3159. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3160. var rng = range.get();
  3161. if (rng.item) {
  3162. rng.item(0).outerHTML = val;
  3163. } else {
  3164. rng.pasteHTML(val);
  3165. }
  3166. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3167. temp.parentNode.removeChild(temp);
  3168. var newRange = _toRange(rng);
  3169. range.setEnd(newRange.endContainer, newRange.endOffset);
  3170. range.collapse(false);
  3171. self.select(false);
  3172. }
  3173. function insertHtml(range, val) {
  3174. var doc = range.doc,
  3175. frag = doc.createDocumentFragment();
  3176. K('@' + val, doc).each(function() {
  3177. frag.appendChild(this);
  3178. });
  3179. range.deleteContents();
  3180. range.insertNode(frag);
  3181. range.collapse(false);
  3182. self.select(false);
  3183. }
  3184. if (_IERANGE && quickMode) {
  3185. try {
  3186. pasteHtml(range, val);
  3187. } catch(e) {
  3188. insertHtml(range, val);
  3189. }
  3190. return self;
  3191. }
  3192. insertHtml(range, val);
  3193. return self;
  3194. },
  3195. hr : function() {
  3196. return this.inserthtml('<hr />');
  3197. },
  3198. print : function() {
  3199. this.win.print();
  3200. return this;
  3201. },
  3202. insertimage : function(url, title, width, height, border, align) {
  3203. title = _undef(title, '');
  3204. border = _undef(border, 0);
  3205. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3206. if (width) {
  3207. html += 'width="' + _escape(width) + '" ';
  3208. }
  3209. if (height) {
  3210. html += 'height="' + _escape(height) + '" ';
  3211. }
  3212. if (title) {
  3213. html += 'title="' + _escape(title) + '" ';
  3214. }
  3215. if (align) {
  3216. html += 'align="' + _escape(align) + '" ';
  3217. }
  3218. html += 'alt="' + _escape(title) + '" ';
  3219. html += '/>';
  3220. return this.inserthtml(html);
  3221. },
  3222. createlink : function(url, type) {
  3223. var self = this, doc = self.doc, range = self.range;
  3224. self.select();
  3225. var a = self.commonNode({ a : '*' });
  3226. if (a && !range.isControl()) {
  3227. range.selectNode(a.get());
  3228. self.select();
  3229. }
  3230. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3231. if (type) {
  3232. html += ' target="' + _escape(type) + '"';
  3233. }
  3234. if (range.collapsed) {
  3235. html += '>' + _escape(url) + '</a>';
  3236. return self.inserthtml(html);
  3237. }
  3238. if (range.isControl()) {
  3239. var node = K(range.startContainer.childNodes[range.startOffset]);
  3240. html += '></a>';
  3241. node.after(K(html, doc));
  3242. node.next().append(node);
  3243. range.selectNode(node[0]);
  3244. return self.select();
  3245. }
  3246. function setAttr(node, url, type) {
  3247. K(node).attr('href', url).attr('data-ke-src', url);
  3248. if (type) {
  3249. K(node).attr('target', type);
  3250. } else {
  3251. K(node).removeAttr('target');
  3252. }
  3253. }
  3254. var sc = range.startContainer, so = range.startOffset,
  3255. ec = range.endContainer, eo = range.endOffset;
  3256. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3257. var child = sc.childNodes[so];
  3258. if (child.nodeName.toLowerCase() == 'a') {
  3259. setAttr(child, url, type);
  3260. return self;
  3261. }
  3262. }
  3263. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3264. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3265. setAttr(this, url, type);
  3266. });
  3267. return self;
  3268. },
  3269. unlink : function() {
  3270. var self = this, doc = self.doc, range = self.range;
  3271. self.select();
  3272. if (range.collapsed) {
  3273. var a = self.commonNode({ a : '*' });
  3274. if (a) {
  3275. range.selectNode(a.get());
  3276. self.select();
  3277. }
  3278. _nativeCommand(doc, 'unlink', null);
  3279. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3280. var parent = K(range.startContainer).parent();
  3281. if (parent.name === 'a') {
  3282. parent.remove(true);
  3283. }
  3284. }
  3285. } else {
  3286. _nativeCommand(doc, 'unlink', null);
  3287. }
  3288. return self;
  3289. }
  3290. });
  3291. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3292. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3293. KCmd.prototype[name] = function(val) {
  3294. var self = this;
  3295. self.select();
  3296. _nativeCommand(self.doc, name, val);
  3297. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3298. self.selection();
  3299. }
  3300. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3301. self.selection();
  3302. }
  3303. return self;
  3304. };
  3305. });
  3306. _each('cut,copy,paste'.split(','), function(i, name) {
  3307. KCmd.prototype[name] = function() {
  3308. var self = this;
  3309. if (!self.doc.queryCommandSupported(name)) {
  3310. throw 'not supported';
  3311. }
  3312. self.select();
  3313. _nativeCommand(self.doc, name, null);
  3314. return self;
  3315. };
  3316. });
  3317. function _cmd(mixed) {
  3318. if (mixed.nodeName) {
  3319. var doc = _getDoc(mixed);
  3320. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3321. }
  3322. return new KCmd(mixed);
  3323. }
  3324. K.CmdClass = KCmd;
  3325. K.cmd = _cmd;
  3326. function _drag(options) {
  3327. var moveEl = options.moveEl,
  3328. moveFn = options.moveFn,
  3329. clickEl = options.clickEl || moveEl,
  3330. beforeDrag = options.beforeDrag,
  3331. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3332. var docs = [document];
  3333. if (iframeFix) {
  3334. K('iframe').each(function() {
  3335. var src = _formatUrl(this.src || '', 'absolute');
  3336. if (/^https?:\/\//.test(src)) {
  3337. return;
  3338. }
  3339. var doc;
  3340. try {
  3341. doc = _iframeDoc(this);
  3342. } catch(e) {}
  3343. if (doc) {
  3344. var pos = K(this).pos();
  3345. K(doc).data('pos-x', pos.x);
  3346. K(doc).data('pos-y', pos.y);
  3347. docs.push(doc);
  3348. }
  3349. });
  3350. }
  3351. clickEl.mousedown(function(e) {
  3352. if(e.button !== 0 && e.button !== 1) {
  3353. return;
  3354. }
  3355. e.stopPropagation();
  3356. var self = clickEl.get(),
  3357. x = _removeUnit(moveEl.css('left')),
  3358. y = _removeUnit(moveEl.css('top')),
  3359. width = moveEl.width(),
  3360. height = moveEl.height(),
  3361. pageX = e.pageX,
  3362. pageY = e.pageY;
  3363. if (beforeDrag) {
  3364. beforeDrag();
  3365. }
  3366. function moveListener(e) {
  3367. e.preventDefault();
  3368. var kdoc = K(_getDoc(e.target));
  3369. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3370. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3371. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3372. }
  3373. function selectListener(e) {
  3374. e.preventDefault();
  3375. }
  3376. function upListener(e) {
  3377. e.preventDefault();
  3378. K(docs).unbind('mousemove', moveListener)
  3379. .unbind('mouseup', upListener)
  3380. .unbind('selectstart', selectListener);
  3381. if (self.releaseCapture) {
  3382. self.releaseCapture();
  3383. }
  3384. }
  3385. K(docs).mousemove(moveListener)
  3386. .mouseup(upListener)
  3387. .bind('selectstart', selectListener);
  3388. if (self.setCapture) {
  3389. self.setCapture();
  3390. }
  3391. });
  3392. }
  3393. function KWidget(options) {
  3394. this.init(options);
  3395. }
  3396. _extend(KWidget, {
  3397. init : function(options) {
  3398. var self = this;
  3399. self.name = options.name || '';
  3400. self.doc = options.doc || document;
  3401. self.win = _getWin(self.doc);
  3402. self.x = _addUnit(options.x);
  3403. self.y = _addUnit(options.y);
  3404. self.z = options.z;
  3405. self.width = _addUnit(options.width);
  3406. self.height = _addUnit(options.height);
  3407. self.index = _addUnit(options.index);
  3408. self.div = K('<div style="display:block;"></div>');
  3409. self.options = options;
  3410. self._alignEl = options.alignEl;
  3411. if (self.width) {
  3412. self.div.css('width', self.width);
  3413. }
  3414. if (self.height) {
  3415. self.div.css('height', self.height);
  3416. }
  3417. if (self.z) {
  3418. self.div.css({
  3419. position : 'absolute',
  3420. left : self.x,
  3421. top : self.y,
  3422. 'z-index' : self.z
  3423. });
  3424. }
  3425. if (self.z && (self.x === undefined || self.y === undefined)) {
  3426. self.autoPos(self.width, self.height);
  3427. }
  3428. if (options.cls) {
  3429. self.div.addClass(options.cls);
  3430. }
  3431. if (options.shadowMode) {
  3432. self.div.addClass('ke-shadow');
  3433. }
  3434. if (options.css) {
  3435. self.div.css(options.css);
  3436. }
  3437. if (options.src) {
  3438. K(options.src).replaceWith(self.div);
  3439. } else {
  3440. K(self.doc.body).append(self.div);
  3441. }
  3442. if (options.html) {
  3443. self.div.html(options.html);
  3444. }
  3445. if (options.autoScroll) {
  3446. if (_IE && _V < 7 || _QUIRKS) {
  3447. var scrollPos = _getScrollPos();
  3448. K(self.win).bind('scroll', function(e) {
  3449. var pos = _getScrollPos(),
  3450. diffX = pos.x - scrollPos.x,
  3451. diffY = pos.y - scrollPos.y;
  3452. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3453. });
  3454. } else {
  3455. self.div.css('position', 'fixed');
  3456. }
  3457. }
  3458. },
  3459. pos : function(x, y, updateProp) {
  3460. var self = this;
  3461. updateProp = _undef(updateProp, true);
  3462. if (x !== null) {
  3463. x = x < 0 ? 0 : _addUnit(x);
  3464. self.div.css('left', x);
  3465. if (updateProp) {
  3466. self.x = x;
  3467. }
  3468. }
  3469. if (y !== null) {
  3470. y = y < 0 ? 0 : _addUnit(y);
  3471. self.div.css('top', y);
  3472. if (updateProp) {
  3473. self.y = y;
  3474. }
  3475. }
  3476. return self;
  3477. },
  3478. autoPos : function(width, height) {
  3479. var x, y, self = this,
  3480. w = _removeUnit(width) || 0,
  3481. h = _removeUnit(height) || 0,
  3482. scrollPos = _getScrollPos();
  3483. if (self._alignEl) {
  3484. var knode = K(self._alignEl),
  3485. pos = knode.pos(),
  3486. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3487. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3488. x = diffX < 0 ? pos.x : pos.x + diffX;
  3489. y = diffY < 0 ? pos.y : pos.y + diffY;
  3490. } else {
  3491. var docEl = _docElement(self.doc);
  3492. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3493. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3494. }
  3495. if (!(_IE && _V < 7 || _QUIRKS)) {
  3496. x -= scrollPos.x;
  3497. y -= scrollPos.y;
  3498. }
  3499. return self.pos(x, y);
  3500. },
  3501. remove : function() {
  3502. var self = this;
  3503. if (_IE && _V < 7 || _QUIRKS) {
  3504. K(self.win).unbind('scroll');
  3505. }
  3506. self.div.remove();
  3507. _each(self, function(i) {
  3508. self[i] = null;
  3509. });
  3510. return this;
  3511. },
  3512. show : function() {
  3513. this.div.show();
  3514. return this;
  3515. },
  3516. hide : function() {
  3517. this.div.hide();
  3518. return this;
  3519. },
  3520. draggable : function(options) {
  3521. var self = this;
  3522. options = options || {};
  3523. options.moveEl = self.div;
  3524. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3525. if ((x = x + diffX) < 0) {
  3526. x = 0;
  3527. }
  3528. if ((y = y + diffY) < 0) {
  3529. y = 0;
  3530. }
  3531. self.pos(x, y);
  3532. };
  3533. _drag(options);
  3534. return self;
  3535. }
  3536. });
  3537. function _widget(options) {
  3538. return new KWidget(options);
  3539. }
  3540. K.WidgetClass = KWidget;
  3541. K.widget = _widget;
  3542. function _iframeDoc(iframe) {
  3543. iframe = _get(iframe);
  3544. return iframe.contentDocument || iframe.contentWindow.document;
  3545. }
  3546. var html, _direction = '';
  3547. if ((html = document.getElementsByTagName('html'))) {
  3548. _direction = html[0].dir;
  3549. }
  3550. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3551. var arr = [
  3552. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3553. '<head><meta charset="utf-8" /><title></title>',
  3554. '<style>',
  3555. 'html {margin:0;padding:0;}',
  3556. 'body {margin:0;padding:5px;}',
  3557. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3558. 'body, p, div {word-wrap: break-word;}',
  3559. 'p {margin:5px 0;}',
  3560. 'table {border-collapse:collapse;}',
  3561. 'img {border:0;}',
  3562. 'noscript {display:none;}',
  3563. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3564. 'img.ke-flash {',
  3565. ' border:1px solid #AAA;',
  3566. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3567. ' background-position:center center;',
  3568. ' background-repeat:no-repeat;',
  3569. ' width:100px;',
  3570. ' height:100px;',
  3571. '}',
  3572. 'img.ke-rm {',
  3573. ' border:1px solid #AAA;',
  3574. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3575. ' background-position:center center;',
  3576. ' background-repeat:no-repeat;',
  3577. ' width:100px;',
  3578. ' height:100px;',
  3579. '}',
  3580. 'img.ke-media {',
  3581. ' border:1px solid #AAA;',
  3582. ' background-image:url(' + themesPath + 'common/media.gif);',
  3583. ' background-position:center center;',
  3584. ' background-repeat:no-repeat;',
  3585. ' width:100px;',
  3586. ' height:100px;',
  3587. '}',
  3588. 'img.ke-anchor {',
  3589. ' border:1px dashed #666;',
  3590. ' width:16px;',
  3591. ' height:16px;',
  3592. '}',
  3593. '.ke-script, .ke-noscript, .ke-display-none {',
  3594. ' display:none;',
  3595. ' font-size:0;',
  3596. ' width:0;',
  3597. ' height:0;',
  3598. '}',
  3599. '.ke-pagebreak {',
  3600. ' border:1px dotted #AAA;',
  3601. ' font-size:0;',
  3602. ' height:2px;',
  3603. '}',
  3604. '</style>'
  3605. ];
  3606. if (!_isArray(cssPath)) {
  3607. cssPath = [cssPath];
  3608. }
  3609. _each(cssPath, function(i, path) {
  3610. if (path) {
  3611. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3612. }
  3613. });
  3614. if (cssData) {
  3615. arr.push('<style>' + cssData + '</style>');
  3616. }
  3617. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3618. return arr.join('\n');
  3619. }
  3620. function _elementVal(knode, val) {
  3621. if (knode.hasVal()) {
  3622. if (val === undefined) {
  3623. var html = knode.val();
  3624. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3625. return html;
  3626. }
  3627. return knode.val(val);
  3628. }
  3629. return knode.html(val);
  3630. }
  3631. function KEdit(options) {
  3632. this.init(options);
  3633. }
  3634. _extend(KEdit, KWidget, {
  3635. init : function(options) {
  3636. var self = this;
  3637. KEdit.parent.init.call(self, options);
  3638. self.srcElement = K(options.srcElement);
  3639. self.div.addClass('ke-edit');
  3640. self.designMode = _undef(options.designMode, true);
  3641. self.beforeGetHtml = options.beforeGetHtml;
  3642. self.beforeSetHtml = options.beforeSetHtml;
  3643. self.afterSetHtml = options.afterSetHtml;
  3644. var themesPath = _undef(options.themesPath, ''),
  3645. bodyClass = options.bodyClass,
  3646. cssPath = options.cssPath,
  3647. cssData = options.cssData,
  3648. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3649. srcScript = ('document.open();' +
  3650. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3651. 'document.close();'),
  3652. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3653. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3654. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3655. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3656. self.iframe.attr('tabindex', self.tabIndex);
  3657. self.textarea.attr('tabindex', self.tabIndex);
  3658. if (self.width) {
  3659. self.setWidth(self.width);
  3660. }
  3661. if (self.height) {
  3662. self.setHeight(self.height);
  3663. }
  3664. if (self.designMode) {
  3665. self.textarea.hide();
  3666. } else {
  3667. self.iframe.hide();
  3668. }
  3669. function ready() {
  3670. var doc = _iframeDoc(self.iframe);
  3671. doc.open();
  3672. if (isDocumentDomain) {
  3673. doc.domain = document.domain;
  3674. }
  3675. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3676. doc.close();
  3677. self.win = self.iframe[0].contentWindow;
  3678. self.doc = doc;
  3679. var cmd = _cmd(doc);
  3680. self.afterChange(function(e) {
  3681. cmd.selection();
  3682. });
  3683. if (_WEBKIT) {
  3684. K(doc).click(function(e) {
  3685. if (K(e.target).name === 'img') {
  3686. cmd.selection(true);
  3687. cmd.range.selectNode(e.target);
  3688. cmd.select();
  3689. }
  3690. });
  3691. }
  3692. if (_IE) {
  3693. self._mousedownHandler = function() {
  3694. var newRange = cmd.range.cloneRange();
  3695. newRange.shrink();
  3696. if (newRange.isControl()) {
  3697. self.blur();
  3698. }
  3699. };
  3700. K(document).mousedown(self._mousedownHandler);
  3701. K(doc).keydown(function(e) {
  3702. if (e.which == 8) {
  3703. cmd.selection();
  3704. var rng = cmd.range;
  3705. if (rng.isControl()) {
  3706. rng.collapse(true);
  3707. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3708. e.preventDefault();
  3709. }
  3710. }
  3711. });
  3712. }
  3713. self.cmd = cmd;
  3714. self.html(_elementVal(self.srcElement));
  3715. if (_IE) {
  3716. doc.body.disabled = true;
  3717. doc.body.contentEditable = true;
  3718. doc.body.removeAttribute('disabled');
  3719. } else {
  3720. doc.designMode = 'on';
  3721. }
  3722. if (options.afterCreate) {
  3723. options.afterCreate.call(self);
  3724. }
  3725. }
  3726. if (isDocumentDomain) {
  3727. self.iframe.bind('load', function(e) {
  3728. self.iframe.unbind('load');
  3729. if (_IE) {
  3730. ready();
  3731. } else {
  3732. setTimeout(ready, 0);
  3733. }
  3734. });
  3735. }
  3736. self.div.append(self.iframe);
  3737. self.div.append(self.textarea);
  3738. self.srcElement.hide();
  3739. !isDocumentDomain && ready();
  3740. },
  3741. setWidth : function(val) {
  3742. var self = this;
  3743. val = _addUnit(val);
  3744. self.width = val;
  3745. self.div.css('width', val);
  3746. return self;
  3747. },
  3748. setHeight : function(val) {
  3749. var self = this;
  3750. val = _addUnit(val);
  3751. self.height = val;
  3752. self.div.css('height', val);
  3753. self.iframe.css('height', val);
  3754. if ((_IE && _V < 8) || _QUIRKS) {
  3755. val = _addUnit(_removeUnit(val) - 2);
  3756. }
  3757. self.textarea.css('height', val);
  3758. return self;
  3759. },
  3760. remove : function() {
  3761. var self = this, doc = self.doc;
  3762. K(doc.body).unbind();
  3763. K(doc).unbind();
  3764. K(self.win).unbind();
  3765. if (self._mousedownHandler) {
  3766. K(document).unbind('mousedown', self._mousedownHandler);
  3767. }
  3768. _elementVal(self.srcElement, self.html());
  3769. self.srcElement.show();
  3770. self.iframe.unbind();
  3771. self.textarea.unbind();
  3772. KEdit.parent.remove.call(self);
  3773. },
  3774. html : function(val, isFull) {
  3775. var self = this, doc = self.doc;
  3776. if (self.designMode) {
  3777. var body = doc.body;
  3778. if (val === undefined) {
  3779. if (isFull) {
  3780. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3781. } else {
  3782. val = body.innerHTML;
  3783. }
  3784. if (self.beforeGetHtml) {
  3785. val = self.beforeGetHtml(val);
  3786. }
  3787. if (_GECKO && val == '<br />') {
  3788. val = '';
  3789. }
  3790. return val;
  3791. }
  3792. if (self.beforeSetHtml) {
  3793. val = self.beforeSetHtml(val);
  3794. }
  3795. if (_IE && _V >= 9) {
  3796. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3797. }
  3798. K(body).html(val);
  3799. if (self.afterSetHtml) {
  3800. self.afterSetHtml();
  3801. }
  3802. return self;
  3803. }
  3804. if (val === undefined) {
  3805. return self.textarea.val();
  3806. }
  3807. self.textarea.val(val);
  3808. return self;
  3809. },
  3810. design : function(bool) {
  3811. var self = this, val;
  3812. if (bool === undefined ? !self.designMode : bool) {
  3813. if (!self.designMode) {
  3814. val = self.html();
  3815. self.designMode = true;
  3816. self.textarea.hide();
  3817. self.html(val);
  3818. var iframe = self.iframe;
  3819. var height = _removeUnit(self.height);
  3820. iframe.height(height - 2);
  3821. iframe.show();
  3822. setTimeout(function() {
  3823. iframe.height(height);
  3824. }, 0);
  3825. }
  3826. } else {
  3827. if (self.designMode) {
  3828. val = self.html();
  3829. self.designMode = false;
  3830. self.html(val);
  3831. self.iframe.hide();
  3832. self.textarea.show();
  3833. }
  3834. }
  3835. return self.focus();
  3836. },
  3837. focus : function() {
  3838. var self = this;
  3839. //self.designMode ? self.win.focus() : self.textarea[0].focus();
  3840. return self;
  3841. },
  3842. blur : function() {
  3843. var self = this;
  3844. if (_IE) {
  3845. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3846. self.div.append(input);
  3847. input[0].focus();
  3848. input.remove();
  3849. } else {
  3850. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3851. }
  3852. return self;
  3853. },
  3854. afterChange : function(fn) {
  3855. var self = this, doc = self.doc, body = doc.body;
  3856. K(doc).keyup(function(e) {
  3857. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3858. fn(e);
  3859. }
  3860. });
  3861. K(doc).mouseup(fn).contextmenu(fn);
  3862. K(self.win).blur(fn);
  3863. function timeoutHandler(e) {
  3864. setTimeout(function() {
  3865. fn(e);
  3866. }, 1);
  3867. }
  3868. K(body).bind('paste', timeoutHandler);
  3869. K(body).bind('cut', timeoutHandler);
  3870. return self;
  3871. }
  3872. });
  3873. function _edit(options) {
  3874. return new KEdit(options);
  3875. }
  3876. K.EditClass = KEdit;
  3877. K.edit = _edit;
  3878. K.iframeDoc = _iframeDoc;
  3879. function _selectToolbar(name, fn) {
  3880. var self = this,
  3881. knode = self.get(name);
  3882. if (knode) {
  3883. if (knode.hasClass('ke-disabled')) {
  3884. return;
  3885. }
  3886. fn(knode);
  3887. }
  3888. }
  3889. function KToolbar(options) {
  3890. this.init(options);
  3891. }
  3892. _extend(KToolbar, KWidget, {
  3893. init : function(options) {
  3894. var self = this;
  3895. KToolbar.parent.init.call(self, options);
  3896. self.disableMode = _undef(options.disableMode, false);
  3897. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3898. self._itemMap = {};
  3899. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3900. e.preventDefault();
  3901. }).attr('unselectable', 'on');
  3902. function find(target) {
  3903. var knode = K(target);
  3904. if (knode.hasClass('ke-outline')) {
  3905. return knode;
  3906. }
  3907. if (knode.hasClass('ke-toolbar-icon')) {
  3908. return knode.parent();
  3909. }
  3910. }
  3911. function hover(e, method) {
  3912. var knode = find(e.target);
  3913. if (knode) {
  3914. if (knode.hasClass('ke-disabled')) {
  3915. return;
  3916. }
  3917. if (knode.hasClass('ke-selected')) {
  3918. return;
  3919. }
  3920. knode[method]('ke-on');
  3921. }
  3922. }
  3923. self.div.mouseover(function(e) {
  3924. hover(e, 'addClass');
  3925. })
  3926. .mouseout(function(e) {
  3927. hover(e, 'removeClass');
  3928. })
  3929. .click(function(e) {
  3930. var knode = find(e.target);
  3931. if (knode) {
  3932. if (knode.hasClass('ke-disabled')) {
  3933. return;
  3934. }
  3935. self.options.click.call(this, e, knode.attr('data-name'));
  3936. }
  3937. });
  3938. },
  3939. get : function(name) {
  3940. if (this._itemMap[name]) {
  3941. return this._itemMap[name];
  3942. }
  3943. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3944. },
  3945. select : function(name) {
  3946. _selectToolbar.call(this, name, function(knode) {
  3947. knode.addClass('ke-selected');
  3948. });
  3949. return self;
  3950. },
  3951. unselect : function(name) {
  3952. _selectToolbar.call(this, name, function(knode) {
  3953. knode.removeClass('ke-selected').removeClass('ke-on');
  3954. });
  3955. return self;
  3956. },
  3957. enable : function(name) {
  3958. var self = this,
  3959. knode = name.get ? name : self.get(name);
  3960. if (knode) {
  3961. knode.removeClass('ke-disabled');
  3962. knode.opacity(1);
  3963. }
  3964. return self;
  3965. },
  3966. disable : function(name) {
  3967. var self = this,
  3968. knode = name.get ? name : self.get(name);
  3969. if (knode) {
  3970. knode.removeClass('ke-selected').addClass('ke-disabled');
  3971. knode.opacity(0.5);
  3972. }
  3973. return self;
  3974. },
  3975. disableAll : function(bool, noDisableItems) {
  3976. var self = this, map = self.noDisableItemMap, item;
  3977. if (noDisableItems) {
  3978. map = _toMap(noDisableItems);
  3979. }
  3980. if (bool === undefined ? !self.disableMode : bool) {
  3981. K('span.ke-outline', self.div).each(function() {
  3982. var knode = K(this),
  3983. name = knode[0].getAttribute('data-name', 2);
  3984. if (!map[name]) {
  3985. self.disable(knode);
  3986. }
  3987. });
  3988. self.disableMode = true;
  3989. } else {
  3990. K('span.ke-outline', self.div).each(function() {
  3991. var knode = K(this),
  3992. name = knode[0].getAttribute('data-name', 2);
  3993. if (!map[name]) {
  3994. self.enable(knode);
  3995. }
  3996. });
  3997. self.disableMode = false;
  3998. }
  3999. return self;
  4000. }
  4001. });
  4002. function _toolbar(options) {
  4003. return new KToolbar(options);
  4004. }
  4005. K.ToolbarClass = KToolbar;
  4006. K.toolbar = _toolbar;
  4007. function KMenu(options) {
  4008. this.init(options);
  4009. }
  4010. _extend(KMenu, KWidget, {
  4011. init : function(options) {
  4012. var self = this;
  4013. options.z = options.z || 811213;
  4014. KMenu.parent.init.call(self, options);
  4015. self.centerLineMode = _undef(options.centerLineMode, true);
  4016. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  4017. e.stopPropagation();
  4018. }).attr('unselectable', 'on');
  4019. },
  4020. addItem : function(item) {
  4021. var self = this;
  4022. if (item.title === '-') {
  4023. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4024. return;
  4025. }
  4026. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4027. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4028. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4029. height = _addUnit(item.height),
  4030. iconClass = _undef(item.iconClass, '');
  4031. self.div.append(itemDiv);
  4032. if (height) {
  4033. itemDiv.css('height', height);
  4034. rightDiv.css('line-height', height);
  4035. }
  4036. var centerDiv;
  4037. if (self.centerLineMode) {
  4038. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4039. if (height) {
  4040. centerDiv.css('height', height);
  4041. }
  4042. }
  4043. itemDiv.mouseover(function(e) {
  4044. K(this).addClass('ke-menu-item-on');
  4045. if (centerDiv) {
  4046. centerDiv.addClass('ke-menu-item-center-on');
  4047. }
  4048. })
  4049. .mouseout(function(e) {
  4050. K(this).removeClass('ke-menu-item-on');
  4051. if (centerDiv) {
  4052. centerDiv.removeClass('ke-menu-item-center-on');
  4053. }
  4054. })
  4055. .click(function(e) {
  4056. item.click.call(K(this));
  4057. e.stopPropagation();
  4058. })
  4059. .append(leftDiv);
  4060. if (centerDiv) {
  4061. itemDiv.append(centerDiv);
  4062. }
  4063. itemDiv.append(rightDiv);
  4064. if (item.checked) {
  4065. iconClass = 'ke-icon-checked';
  4066. }
  4067. if (iconClass !== '') {
  4068. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4069. }
  4070. rightDiv.html(item.title);
  4071. return self;
  4072. },
  4073. remove : function() {
  4074. var self = this;
  4075. if (self.options.beforeRemove) {
  4076. self.options.beforeRemove.call(self);
  4077. }
  4078. K('.ke-menu-item', self.div[0]).unbind();
  4079. KMenu.parent.remove.call(self);
  4080. return self;
  4081. }
  4082. });
  4083. function _menu(options) {
  4084. return new KMenu(options);
  4085. }
  4086. K.MenuClass = KMenu;
  4087. K.menu = _menu;
  4088. function KColorPicker(options) {
  4089. this.init(options);
  4090. }
  4091. _extend(KColorPicker, KWidget, {
  4092. init : function(options) {
  4093. var self = this;
  4094. options.z = options.z || 811213;
  4095. KColorPicker.parent.init.call(self, options);
  4096. var colors = options.colors || [
  4097. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4098. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4099. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4100. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4101. ];
  4102. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4103. self._cells = [];
  4104. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4105. e.stopPropagation();
  4106. }).attr('unselectable', 'on');
  4107. var table = self.doc.createElement('table');
  4108. self.div.append(table);
  4109. table.className = 'ke-colorpicker-table';
  4110. table.cellPadding = 0;
  4111. table.cellSpacing = 0;
  4112. table.border = 0;
  4113. var row = table.insertRow(0), cell = row.insertCell(0);
  4114. cell.colSpan = colors[0].length;
  4115. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4116. for (var i = 0; i < colors.length; i++) {
  4117. row = table.insertRow(i + 1);
  4118. for (var j = 0; j < colors[i].length; j++) {
  4119. cell = row.insertCell(j);
  4120. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4121. }
  4122. }
  4123. },
  4124. _addAttr : function(cell, color, cls) {
  4125. var self = this;
  4126. cell = K(cell).addClass(cls);
  4127. if (self.selectedColor === color.toLowerCase()) {
  4128. cell.addClass('ke-colorpicker-cell-selected');
  4129. }
  4130. cell.attr('title', color || self.options.noColor);
  4131. cell.mouseover(function(e) {
  4132. K(this).addClass('ke-colorpicker-cell-on');
  4133. });
  4134. cell.mouseout(function(e) {
  4135. K(this).removeClass('ke-colorpicker-cell-on');
  4136. });
  4137. cell.click(function(e) {
  4138. e.stop();
  4139. self.options.click.call(K(this), color);
  4140. });
  4141. if (color) {
  4142. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4143. } else {
  4144. cell.html(self.options.noColor);
  4145. }
  4146. K(cell).attr('unselectable', 'on');
  4147. self._cells.push(cell);
  4148. },
  4149. remove : function() {
  4150. var self = this;
  4151. _each(self._cells, function() {
  4152. this.unbind();
  4153. });
  4154. KColorPicker.parent.remove.call(self);
  4155. return self;
  4156. }
  4157. });
  4158. function _colorpicker(options) {
  4159. return new KColorPicker(options);
  4160. }
  4161. K.ColorPickerClass = KColorPicker;
  4162. K.colorpicker = _colorpicker;
  4163. function KUploadButton(options) {
  4164. this.init(options);
  4165. }
  4166. _extend(KUploadButton, {
  4167. init : function(options) {
  4168. var self = this,
  4169. button = K(options.button),
  4170. fieldName = options.fieldName || 'file',
  4171. url = options.url || '',
  4172. title = button.val(),
  4173. extraParams = options.extraParams || {},
  4174. cls = button[0].className || '',
  4175. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4176. options.afterError = options.afterError || function(str) {
  4177. alert(str);
  4178. };
  4179. var hiddenElements = [];
  4180. for(var k in extraParams){
  4181. hiddenElements.push('<input type="hidden" class="ke-upload-file-'+k+'" name="' + k + '" value="' + extraParams[k] + '" />');
  4182. }
  4183. var html = [
  4184. '<div class="ke-inline-block ' + cls + '">',
  4185. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4186. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4187. '<span class="ke-button-common">',
  4188. hiddenElements.join(''),
  4189. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4190. '</span>',
  4191. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4192. (options.form ? '</div>' : '</form>'),
  4193. '</div>'].join('');
  4194. var div = K(html, button.doc);
  4195. button.hide();
  4196. button.before(div);
  4197. self.div = div;
  4198. self.button = button;
  4199. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4200. self.form = options.form ? K(options.form) : K('form', div);
  4201. self.fileBox = K('.ke-upload-file', div);
  4202. var width = options.width || K('.ke-button-common', div).width();
  4203. K('.ke-upload-area', div).width(width);
  4204. self.options = options;
  4205. },
  4206. submit : function(e) {
  4207. var self = this,
  4208. iframe = self.iframe;
  4209. e = false;
  4210. if (e) {
  4211. var file = e.files[0];
  4212. var filename = file.name;
  4213. var temp = filename.split('.');
  4214. //putExtra.params["x:name"] = temp[0];
  4215. var filename = hex_md5(file.name) + '.' + temp[temp.length-1];
  4216. var path = $('.' + 'ke-upload-file-key').val();
  4217. $('.' + 'ke-upload-file-key').val(path + filename);
  4218. //这里要修改 以后再改
  4219. } else {
  4220. iframe.bind('load', function() {
  4221. iframe.unbind();
  4222. var tempForm = document.createElement('form');
  4223. self.fileBox.before(tempForm);
  4224. K(tempForm).append(self.fileBox);
  4225. tempForm.reset();
  4226. K(tempForm).remove(true);
  4227. var doc = K.iframeDoc(iframe),
  4228. pre = doc.getElementsByTagName('pre')[0],
  4229. str = '', data;
  4230. if (pre) {
  4231. str = pre.innerHTML;
  4232. } else {
  4233. str = doc.body.innerHTML;
  4234. }
  4235. str = _unescape(str);
  4236. iframe[0].src = 'javascript:false';
  4237. try {
  4238. data = K.json(str);
  4239. } catch (e) {
  4240. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4241. }
  4242. if (data) {
  4243. self.options.afterUpload.call(self, data);
  4244. }
  4245. });
  4246. self.form[0].submit();
  4247. }
  4248. self.form[0].submit();
  4249. return self;
  4250. },
  4251. remove : function() {
  4252. var self = this;
  4253. if (self.fileBox) {
  4254. self.fileBox.unbind();
  4255. }
  4256. self.iframe.remove();
  4257. self.div.remove();
  4258. self.button.show();
  4259. return self;
  4260. }
  4261. });
  4262. function _uploadbutton(options) {
  4263. return new KUploadButton(options);
  4264. }
  4265. K.UploadButtonClass = KUploadButton;
  4266. K.uploadbutton = _uploadbutton;
  4267. function _createButton(arg) {
  4268. arg = arg || {};
  4269. var name = arg.name || '',
  4270. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4271. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4272. if (arg.click) {
  4273. btn.click(arg.click);
  4274. }
  4275. span.append(btn);
  4276. return span;
  4277. }
  4278. function KDialog(options) {
  4279. this.init(options);
  4280. }
  4281. _extend(KDialog, KWidget, {
  4282. init : function(options) {
  4283. var self = this;
  4284. var shadowMode = _undef(options.shadowMode, true);
  4285. options.z = options.z || 811213;
  4286. options.shadowMode = false;
  4287. options.autoScroll = _undef(options.autoScroll, true);
  4288. KDialog.parent.init.call(self, options);
  4289. var title = options.title,
  4290. body = K(options.body, self.doc),
  4291. previewBtn = options.previewBtn,
  4292. yesBtn = options.yesBtn,
  4293. noBtn = options.noBtn,
  4294. closeBtn = options.closeBtn,
  4295. showMask = _undef(options.showMask, true);
  4296. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4297. e.stopPropagation();
  4298. });
  4299. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4300. if (_IE && _V < 7) {
  4301. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4302. } else if (shadowMode) {
  4303. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4304. }
  4305. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4306. contentDiv.append(headerDiv);
  4307. headerDiv.html(title);
  4308. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4309. headerDiv.append(self.closeIcon);
  4310. self.draggable({
  4311. clickEl : headerDiv,
  4312. beforeDrag : options.beforeDrag
  4313. });
  4314. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4315. contentDiv.append(bodyDiv);
  4316. bodyDiv.append(body);
  4317. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4318. if (previewBtn || yesBtn || noBtn) {
  4319. contentDiv.append(footerDiv);
  4320. }
  4321. _each([
  4322. { btn : previewBtn, name : 'preview' },
  4323. { btn : yesBtn, name : 'yes' },
  4324. { btn : noBtn, name : 'no' }
  4325. ], function() {
  4326. if (this.btn) {
  4327. var button = _createButton(this.btn);
  4328. button.addClass('ke-dialog-' + this.name);
  4329. footerDiv.append(button);
  4330. }
  4331. });
  4332. if (self.height) {
  4333. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4334. }
  4335. self.div.width(self.div.width());
  4336. self.div.height(self.div.height());
  4337. self.mask = null;
  4338. if (showMask) {
  4339. var docEl = _docElement(self.doc),
  4340. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4341. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4342. self.mask = _widget({
  4343. x : 0,
  4344. y : 0,
  4345. z : self.z - 1,
  4346. cls : 'ke-dialog-mask',
  4347. width : docWidth,
  4348. height : docHeight
  4349. });
  4350. }
  4351. self.autoPos(self.div.width(), self.div.height());
  4352. self.footerDiv = footerDiv;
  4353. self.bodyDiv = bodyDiv;
  4354. self.headerDiv = headerDiv;
  4355. self.isLoading = false;
  4356. },
  4357. setMaskIndex : function(z) {
  4358. var self = this;
  4359. self.mask.div.css('z-index', z);
  4360. },
  4361. showLoading : function(msg) {
  4362. msg = _undef(msg, '');
  4363. var self = this, body = self.bodyDiv;
  4364. 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>')
  4365. .width(body.width()).height(body.height())
  4366. .css('top', self.headerDiv.height() + 'px');
  4367. body.css('visibility', 'hidden').after(self.loading);
  4368. self.isLoading = true;
  4369. return self;
  4370. },
  4371. hideLoading : function() {
  4372. this.loading && this.loading.remove();
  4373. this.bodyDiv.css('visibility', 'visible');
  4374. this.isLoading = false;
  4375. return this;
  4376. },
  4377. remove : function() {
  4378. var self = this;
  4379. if (self.options.beforeRemove) {
  4380. self.options.beforeRemove.call(self);
  4381. }
  4382. self.mask && self.mask.remove();
  4383. self.iframeMask && self.iframeMask.remove();
  4384. self.closeIcon.unbind();
  4385. K('input', self.div).unbind();
  4386. K('button', self.div).unbind();
  4387. self.footerDiv.unbind();
  4388. self.bodyDiv.unbind();
  4389. self.headerDiv.unbind();
  4390. K('iframe', self.div).each(function() {
  4391. K(this).remove();
  4392. });
  4393. KDialog.parent.remove.call(self);
  4394. return self;
  4395. }
  4396. });
  4397. function _dialog(options) {
  4398. return new KDialog(options);
  4399. }
  4400. K.DialogClass = KDialog;
  4401. K.dialog = _dialog;
  4402. function _tabs(options) {
  4403. var self = _widget(options),
  4404. remove = self.remove,
  4405. afterSelect = options.afterSelect,
  4406. div = self.div,
  4407. liList = [];
  4408. div.addClass('ke-tabs')
  4409. .bind('contextmenu,mousedown,mousemove', function(e) {
  4410. e.preventDefault();
  4411. });
  4412. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4413. div.append(ul);
  4414. self.add = function(tab) {
  4415. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4416. li.data('tab', tab);
  4417. liList.push(li);
  4418. ul.append(li);
  4419. };
  4420. self.selectedIndex = 0;
  4421. self.select = function(index) {
  4422. self.selectedIndex = index;
  4423. _each(liList, function(i, li) {
  4424. li.unbind();
  4425. if (i === index) {
  4426. li.addClass('ke-tabs-li-selected');
  4427. K(li.data('tab').panel).show('');
  4428. } else {
  4429. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4430. .mouseover(function() {
  4431. K(this).addClass('ke-tabs-li-on');
  4432. })
  4433. .mouseout(function() {
  4434. K(this).removeClass('ke-tabs-li-on');
  4435. })
  4436. .click(function() {
  4437. self.select(i);
  4438. });
  4439. K(li.data('tab').panel).hide();
  4440. }
  4441. });
  4442. if (afterSelect) {
  4443. afterSelect.call(self, index);
  4444. }
  4445. };
  4446. self.remove = function() {
  4447. _each(liList, function() {
  4448. this.remove();
  4449. });
  4450. ul.remove();
  4451. remove.call(self);
  4452. };
  4453. return self;
  4454. }
  4455. K.tabs = _tabs;
  4456. function _loadScript(url, fn) {
  4457. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4458. script = document.createElement('script');
  4459. head.appendChild(script);
  4460. script.src = url;
  4461. script.charset = 'utf-8';
  4462. script.onload = script.onreadystatechange = function() {
  4463. if (!this.readyState || this.readyState === 'loaded') {
  4464. if (fn) {
  4465. fn();
  4466. }
  4467. script.onload = script.onreadystatechange = null;
  4468. head.removeChild(script);
  4469. }
  4470. };
  4471. }
  4472. function _chopQuery(url) {
  4473. var index = url.indexOf('?');
  4474. return index > 0 ? url.substr(0, index) : url;
  4475. }
  4476. function _loadStyle(url) {
  4477. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4478. link = document.createElement('link'),
  4479. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4480. var links = K('link[rel="stylesheet"]', head);
  4481. for (var i = 0, len = links.length; i < len; i++) {
  4482. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4483. return;
  4484. }
  4485. }
  4486. head.appendChild(link);
  4487. link.href = url;
  4488. link.rel = 'stylesheet';
  4489. }
  4490. function _ajax(url, fn, method, param, dataType) {
  4491. method = method || 'GET';
  4492. dataType = dataType || 'json';
  4493. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4494. xhr.open(method, url, true);
  4495. xhr.onreadystatechange = function () {
  4496. if (xhr.readyState == 4 && xhr.status == 200) {
  4497. if (fn) {
  4498. var data = _trim(xhr.responseText);
  4499. if (dataType == 'json') {
  4500. data = _json(data);
  4501. }
  4502. fn(data);
  4503. }
  4504. }
  4505. };
  4506. if (method == 'POST') {
  4507. var params = [];
  4508. _each(param, function(key, val) {
  4509. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4510. });
  4511. try {
  4512. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4513. } catch (e) {}
  4514. xhr.send(params.join('&'));
  4515. } else {
  4516. xhr.send(null);
  4517. }
  4518. }
  4519. K.loadScript = _loadScript;
  4520. K.loadStyle = _loadStyle;
  4521. K.ajax = _ajax;
  4522. var _plugins = {};
  4523. function _plugin(name, fn) {
  4524. if (name === undefined) {
  4525. return _plugins;
  4526. }
  4527. if (!fn) {
  4528. return _plugins[name];
  4529. }
  4530. _plugins[name] = fn;
  4531. }
  4532. var _language = {};
  4533. function _parseLangKey(key) {
  4534. var match, ns = 'core';
  4535. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4536. ns = match[1];
  4537. key = match[2];
  4538. }
  4539. return { ns : ns, key : key };
  4540. }
  4541. function _lang(mixed, langType) {
  4542. langType = langType === undefined ? K.options.langType : langType;
  4543. if (typeof mixed === 'string') {
  4544. if (!_language[langType]) {
  4545. return 'no language';
  4546. }
  4547. var pos = mixed.length - 1;
  4548. if (mixed.substr(pos) === '.') {
  4549. return _language[langType][mixed.substr(0, pos)];
  4550. }
  4551. var obj = _parseLangKey(mixed);
  4552. return _language[langType][obj.ns][obj.key];
  4553. }
  4554. _each(mixed, function(key, val) {
  4555. var obj = _parseLangKey(key);
  4556. if (!_language[langType]) {
  4557. _language[langType] = {};
  4558. }
  4559. if (!_language[langType][obj.ns]) {
  4560. _language[langType][obj.ns] = {};
  4561. }
  4562. _language[langType][obj.ns][obj.key] = val;
  4563. });
  4564. }
  4565. function _getImageFromRange(range, fn) {
  4566. if (range.collapsed) {
  4567. return;
  4568. }
  4569. range = range.cloneRange().up();
  4570. var sc = range.startContainer, so = range.startOffset;
  4571. if (!_WEBKIT && !range.isControl()) {
  4572. return;
  4573. }
  4574. var img = K(sc.childNodes[so]);
  4575. if (!img || img.name != 'img') {
  4576. return;
  4577. }
  4578. if (fn(img)) {
  4579. return img;
  4580. }
  4581. }
  4582. function _bindContextmenuEvent() {
  4583. var self = this, doc = self.edit.doc;
  4584. K(doc).contextmenu(function(e) {
  4585. if (self.menu) {
  4586. self.hideMenu();
  4587. }
  4588. if (!self.useContextmenu) {
  4589. e.preventDefault();
  4590. return;
  4591. }
  4592. if (self._contextmenus.length === 0) {
  4593. return;
  4594. }
  4595. var maxWidth = 0, items = [];
  4596. _each(self._contextmenus, function() {
  4597. if (this.title == '-') {
  4598. items.push(this);
  4599. return;
  4600. }
  4601. if (this.cond && this.cond()) {
  4602. items.push(this);
  4603. if (this.width && this.width > maxWidth) {
  4604. maxWidth = this.width;
  4605. }
  4606. }
  4607. });
  4608. while (items.length > 0 && items[0].title == '-') {
  4609. items.shift();
  4610. }
  4611. while (items.length > 0 && items[items.length - 1].title == '-') {
  4612. items.pop();
  4613. }
  4614. var prevItem = null;
  4615. _each(items, function(i) {
  4616. if (this.title == '-' && prevItem.title == '-') {
  4617. delete items[i];
  4618. }
  4619. prevItem = this;
  4620. });
  4621. if (items.length > 0) {
  4622. e.preventDefault();
  4623. var pos = K(self.edit.iframe).pos(),
  4624. menu = _menu({
  4625. x : pos.x + e.clientX,
  4626. y : pos.y + e.clientY,
  4627. width : maxWidth,
  4628. css : { visibility: 'hidden' },
  4629. shadowMode : self.shadowMode
  4630. });
  4631. _each(items, function() {
  4632. if (this.title) {
  4633. menu.addItem(this);
  4634. }
  4635. });
  4636. var docEl = _docElement(menu.doc),
  4637. menuHeight = menu.div.height();
  4638. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4639. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4640. }
  4641. menu.div.css('visibility', 'visible');
  4642. self.menu = menu;
  4643. }
  4644. });
  4645. }
  4646. function _bindNewlineEvent() {
  4647. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4648. if (_IE && newlineTag !== 'br') {
  4649. return;
  4650. }
  4651. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4652. return;
  4653. }
  4654. if (_OPERA && _V < 9) {
  4655. return;
  4656. }
  4657. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4658. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4659. function getAncestorTagName(range) {
  4660. var ancestor = K(range.commonAncestor());
  4661. while (ancestor) {
  4662. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4663. break;
  4664. }
  4665. ancestor = ancestor.parent();
  4666. }
  4667. return ancestor.name;
  4668. }
  4669. K(doc).keydown(function(e) {
  4670. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4671. autoImg(self);
  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 (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4680. e.preventDefault();
  4681. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4682. return;
  4683. }
  4684. if (!pSkipTagMap[tagName]) {
  4685. _nativeCommand(doc, 'formatblock', '<p>');
  4686. }
  4687. });
  4688. K(doc).keyup(function(e) {
  4689. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4690. return;
  4691. }
  4692. if (newlineTag == 'br') {
  4693. return;
  4694. }
  4695. if (_GECKO) {
  4696. var root = self.cmd.commonAncestor('p');
  4697. var a = self.cmd.commonAncestor('a');
  4698. if (a && a.text() == '') {
  4699. a.remove(true);
  4700. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4701. self.cmd.select();
  4702. }
  4703. return;
  4704. }
  4705. self.cmd.selection();
  4706. var tagName = getAncestorTagName(self.cmd.range);
  4707. if (tagName == 'marquee' || tagName == 'select') {
  4708. return;
  4709. }
  4710. if (!pSkipTagMap[tagName]) {
  4711. _nativeCommand(doc, 'formatblock', '<p>');
  4712. }
  4713. var div = self.cmd.commonAncestor('div');
  4714. if (div) {
  4715. var p = K('<p></p>'),
  4716. child = div[0].firstChild;
  4717. while (child) {
  4718. var next = child.nextSibling;
  4719. p.append(child);
  4720. child = next;
  4721. }
  4722. div.before(p);
  4723. div.remove();
  4724. self.cmd.range.selectNodeContents(p[0]);
  4725. self.cmd.select();
  4726. }
  4727. });
  4728. }
  4729. function _bindTabEvent() {
  4730. var self = this, doc = self.edit.doc;
  4731. K(doc).keydown(function(e) {
  4732. if (e.which == 9) {
  4733. e.preventDefault();
  4734. if (self.afterTab) {
  4735. self.afterTab.call(self, e);
  4736. return;
  4737. }
  4738. var cmd = self.cmd, range = cmd.range;
  4739. range.shrink();
  4740. if (range.collapsed && range.startContainer.nodeType == 1) {
  4741. range.insertNode(K('@&nbsp;', doc)[0]);
  4742. cmd.select();
  4743. }
  4744. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4745. }
  4746. });
  4747. }
  4748. function _bindFocusEvent() {
  4749. var self = this;
  4750. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4751. if (self.afterFocus) {
  4752. self.afterFocus.call(self, e);
  4753. }
  4754. }).blur(function(e) {
  4755. if (self.afterBlur) {
  4756. self.afterBlur.call(self, e);
  4757. }
  4758. });
  4759. }
  4760. function _removeBookmarkTag(html) {
  4761. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4762. }
  4763. function _removeTempTag(html) {
  4764. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4765. }
  4766. function _addBookmarkToStack(stack, bookmark) {
  4767. if (stack.length === 0) {
  4768. stack.push(bookmark);
  4769. return;
  4770. }
  4771. var prev = stack[stack.length - 1];
  4772. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4773. stack.push(bookmark);
  4774. }
  4775. }
  4776. function _undoToRedo(fromStack, toStack) {
  4777. var self = this, edit = self.edit,
  4778. body = edit.doc.body,
  4779. range, bookmark;
  4780. if (fromStack.length === 0) {
  4781. return self;
  4782. }
  4783. if (edit.designMode) {
  4784. range = self.cmd.range;
  4785. bookmark = range.createBookmark(true);
  4786. bookmark.html = body.innerHTML;
  4787. } else {
  4788. bookmark = {
  4789. html : body.innerHTML
  4790. };
  4791. }
  4792. _addBookmarkToStack(toStack, bookmark);
  4793. var prev = fromStack.pop();
  4794. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4795. prev = fromStack.pop();
  4796. }
  4797. if (edit.designMode) {
  4798. edit.html(prev.html);
  4799. if (prev.start) {
  4800. range.moveToBookmark(prev);
  4801. self.select();
  4802. }
  4803. } else {
  4804. K(body).html(_removeBookmarkTag(prev.html));
  4805. }
  4806. return self;
  4807. }
  4808. function KEditor(options) {
  4809. var self = this;
  4810. self.options = {};
  4811. function setOption(key, val) {
  4812. if (KEditor.prototype[key] === undefined) {
  4813. self[key] = val;
  4814. }
  4815. self.options[key] = val;
  4816. }
  4817. _each(options, function(key, val) {
  4818. setOption(key, options[key]);
  4819. });
  4820. _each(K.options, function(key, val) {
  4821. if (self[key] === undefined) {
  4822. setOption(key, val);
  4823. }
  4824. });
  4825. var se = K(self.srcElement || '<textarea/>');
  4826. if (!self.width) {
  4827. self.width = se[0].style.width || se.width();
  4828. if (!self.width) {
  4829. self.width = '700';
  4830. }
  4831. }
  4832. if (!self.height) {
  4833. self.height = se[0].style.height || se.height();
  4834. }
  4835. setOption('width', _undef(self.width, self.minWidth));
  4836. setOption('height', _undef(self.height, self.minHeight));
  4837. setOption('width', _addUnit(self.width));
  4838. setOption('height', _addUnit(self.height));
  4839. if (_MOBILE && (!_IOS || _V < 534)) {
  4840. //self.designMode = false;
  4841. }
  4842. self.srcElement = se;
  4843. self.initContent = '';
  4844. self.plugin = {};
  4845. self.isCreated = false;
  4846. self._handlers = {};
  4847. self._contextmenus = [];
  4848. self._undoStack = [];
  4849. self._redoStack = [];
  4850. self._firstAddBookmark = true;
  4851. self.menu = self.contextmenu = null;
  4852. self.dialogs = [];
  4853. }
  4854. KEditor.prototype = {
  4855. lang : function(mixed) {
  4856. return _lang(mixed, this.langType);
  4857. },
  4858. loadPlugin : function(name, fn) {
  4859. var self = this;
  4860. var _pluginStatus = this._pluginStatus;
  4861. if (!_pluginStatus) {
  4862. _pluginStatus = this._pluginStatus = {};
  4863. }
  4864. if (_plugins[name]) {
  4865. if (!_isFunction(_plugins[name])) {
  4866. setTimeout(function() {
  4867. self.loadPlugin(name, fn);
  4868. }, 100);
  4869. return self;
  4870. }
  4871. if(!_pluginStatus[name]) {
  4872. _plugins[name].call(self, KindEditor);
  4873. _pluginStatus[name] = 'inited';
  4874. }
  4875. if (fn) {
  4876. fn.call(self);
  4877. }
  4878. return self;
  4879. }
  4880. _plugins[name] = 'loading';
  4881. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4882. setTimeout(function() {
  4883. if (_plugins[name]) {
  4884. self.loadPlugin(name, fn);
  4885. }
  4886. }, 0);
  4887. });
  4888. return self;
  4889. },
  4890. handler : function(key, fn) {
  4891. var self = this;
  4892. if (!self._handlers[key]) {
  4893. self._handlers[key] = [];
  4894. }
  4895. if (_isFunction(fn)) {
  4896. self._handlers[key].push(fn);
  4897. return self;
  4898. }
  4899. _each(self._handlers[key], function() {
  4900. fn = this.call(self, fn);
  4901. });
  4902. return fn;
  4903. },
  4904. clickToolbar : function(name, fn) {
  4905. var self = this, key = 'clickToolbar' + name;
  4906. if (fn === undefined) {
  4907. if (self._handlers[key]) {
  4908. return self.handler(key);
  4909. }
  4910. self.loadPlugin(name, function() {
  4911. self.handler(key);
  4912. });
  4913. return self;
  4914. }
  4915. return self.handler(key, fn);
  4916. },
  4917. updateState : function() {
  4918. var self = this;
  4919. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4920. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4921. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4922. });
  4923. return self;
  4924. },
  4925. addContextmenu : function(item) {
  4926. this._contextmenus.push(item);
  4927. return this;
  4928. },
  4929. afterCreate : function(fn) {
  4930. return this.handler('afterCreate', fn);
  4931. },
  4932. beforeRemove : function(fn) {
  4933. return this.handler('beforeRemove', fn);
  4934. },
  4935. beforeGetHtml : function(fn) {
  4936. return this.handler('beforeGetHtml', fn);
  4937. },
  4938. beforeSetHtml : function(fn) {
  4939. return this.handler('beforeSetHtml', fn);
  4940. },
  4941. afterSetHtml : function(fn) {
  4942. return this.handler('afterSetHtml', fn);
  4943. },
  4944. create : function() {
  4945. var self = this, fullscreenMode = self.fullscreenMode;
  4946. if (self.isCreated) {
  4947. return self;
  4948. }
  4949. if (self.srcElement.data('kindeditor')) {
  4950. return self;
  4951. }
  4952. self.srcElement.data('kindeditor', 'true');
  4953. if (fullscreenMode) {
  4954. _docElement().style.overflow = 'hidden';
  4955. } else {
  4956. _docElement().style.overflow = '';
  4957. }
  4958. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4959. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4960. if ((_IE && _V < 8) || _QUIRKS) {
  4961. height = _addUnit(_removeUnit(height) + 2);
  4962. }
  4963. var container = self.container = K(self.layout);
  4964. if (fullscreenMode) {
  4965. K(document.body).append(container);
  4966. } else {
  4967. self.srcElement.before(container);
  4968. }
  4969. var toolbarDiv = K('.toolbar', container),
  4970. editDiv = K('.edit', container),
  4971. statusbar = self.statusbar = K('.statusbar', container);
  4972. container.removeClass('container')
  4973. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4974. if (fullscreenMode) {
  4975. container.css({
  4976. position : 'absolute',
  4977. left : 0,
  4978. top : 0,
  4979. 'z-index' : 811211
  4980. });
  4981. if (!_GECKO) {
  4982. self._scrollPos = _getScrollPos();
  4983. }
  4984. window.scrollTo(0, 0);
  4985. K(document.body).css({
  4986. 'height' : '1px',
  4987. 'overflow' : 'hidden'
  4988. });
  4989. K(document.body.parentNode).css('overflow', 'hidden');
  4990. self._fullscreenExecuted = true;
  4991. } else {
  4992. if (self._fullscreenExecuted) {
  4993. K(document.body).css({
  4994. 'height' : '',
  4995. 'overflow' : ''
  4996. });
  4997. K(document.body.parentNode).css('overflow', '');
  4998. }
  4999. if (self._scrollPos) {
  5000. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  5001. }
  5002. }
  5003. var htmlList = [];
  5004. K.each(self.items, function(i, name) {
  5005. if (name == '|') {
  5006. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  5007. } else if (name == '/') {
  5008. htmlList.push('<div class="ke-hr"></div>');
  5009. } else {
  5010. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  5011. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  5012. }
  5013. });
  5014. var toolbar = self.toolbar = _toolbar({
  5015. src : toolbarDiv,
  5016. html : htmlList.join(''),
  5017. noDisableItems : self.noDisableItems,
  5018. click : function(e, name) {
  5019. e.stop();
  5020. if (self.menu) {
  5021. var menuName = self.menu.name;
  5022. self.hideMenu();
  5023. if (menuName === name) {
  5024. return;
  5025. }
  5026. }
  5027. self.clickToolbar(name);
  5028. }
  5029. });
  5030. var editHeight = _removeUnit(height) - toolbar.div.height();
  5031. var edit = self.edit = _edit({
  5032. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  5033. src : editDiv,
  5034. srcElement : self.srcElement,
  5035. designMode : self.designMode,
  5036. themesPath : self.themesPath,
  5037. bodyClass : self.bodyClass,
  5038. cssPath : self.cssPath,
  5039. cssData : self.cssData,
  5040. beforeGetHtml : function(html) {
  5041. html = self.beforeGetHtml(html);
  5042. html = _removeBookmarkTag(_removeTempTag(html));
  5043. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  5044. },
  5045. beforeSetHtml : function(html) {
  5046. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  5047. return self.beforeSetHtml(html);
  5048. },
  5049. afterSetHtml : function() {
  5050. self.edit = edit = this;
  5051. self.afterSetHtml();
  5052. },
  5053. afterCreate : function() {
  5054. self.edit = edit = this;
  5055. self.cmd = edit.cmd;
  5056. self._docMousedownFn = function(e) {
  5057. if (self.menu) {
  5058. self.hideMenu();
  5059. }
  5060. };
  5061. K(edit.doc, document).mousedown(self._docMousedownFn);
  5062. _bindContextmenuEvent.call(self);
  5063. _bindNewlineEvent.call(self);
  5064. _bindTabEvent.call(self);
  5065. _bindFocusEvent.call(self);
  5066. edit.afterChange(function(e) {
  5067. if (!edit.designMode) {
  5068. return;
  5069. }
  5070. self.updateState();
  5071. self.addBookmark();
  5072. if (self.options.afterChange) {
  5073. self.options.afterChange.call(self);
  5074. }
  5075. });
  5076. edit.textarea.keyup(function(e) {
  5077. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5078. if (self.options.afterChange) {
  5079. self.options.afterChange.call(self);
  5080. }
  5081. }
  5082. });
  5083. if (self.readonlyMode) {
  5084. self.readonly();
  5085. }
  5086. self.isCreated = true;
  5087. if (self.initContent === '') {
  5088. self.initContent = self.html();
  5089. }
  5090. if (self._undoStack.length > 0) {
  5091. var prev = self._undoStack.pop();
  5092. if (prev.start) {
  5093. self.html(prev.html);
  5094. edit.cmd.range.moveToBookmark(prev);
  5095. self.select();
  5096. }
  5097. }
  5098. self.afterCreate();
  5099. if (self.options.afterCreate) {
  5100. self.options.afterCreate.call(self);
  5101. }
  5102. }
  5103. });
  5104. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5105. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5106. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5107. if (self._fullscreenResizeHandler) {
  5108. K(window).unbind('resize', self._fullscreenResizeHandler);
  5109. self._fullscreenResizeHandler = null;
  5110. }
  5111. function initResize() {
  5112. if (statusbar.height() === 0) {
  5113. setTimeout(initResize, 100);
  5114. return;
  5115. }
  5116. self.resize(width, height, false);
  5117. }
  5118. initResize();
  5119. if (fullscreenMode) {
  5120. self._fullscreenResizeHandler = function(e) {
  5121. if (self.isCreated) {
  5122. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5123. }
  5124. };
  5125. K(window).bind('resize', self._fullscreenResizeHandler);
  5126. toolbar.select('fullscreen');
  5127. statusbar.first().css('visibility', 'hidden');
  5128. statusbar.last().css('visibility', 'hidden');
  5129. } else {
  5130. if (_GECKO) {
  5131. K(window).bind('scroll', function(e) {
  5132. self._scrollPos = _getScrollPos();
  5133. });
  5134. }
  5135. if (self.resizeType > 0) {
  5136. _drag({
  5137. moveEl : container,
  5138. clickEl : statusbar,
  5139. moveFn : function(x, y, width, height, diffX, diffY) {
  5140. height += diffY;
  5141. self.resize(null, height);
  5142. }
  5143. });
  5144. } else {
  5145. statusbar.first().css('visibility', 'hidden');
  5146. }
  5147. if (self.resizeType === 2) {
  5148. _drag({
  5149. moveEl : container,
  5150. clickEl : statusbar.last(),
  5151. moveFn : function(x, y, width, height, diffX, diffY) {
  5152. width += diffX;
  5153. height += diffY;
  5154. self.resize(width, height);
  5155. }
  5156. });
  5157. } else {
  5158. statusbar.last().css('visibility', 'hidden');
  5159. }
  5160. }
  5161. return self;
  5162. },
  5163. remove : function() {
  5164. var self = this;
  5165. if (!self.isCreated) {
  5166. return self;
  5167. }
  5168. self.beforeRemove();
  5169. self.srcElement.data('kindeditor', '');
  5170. if (self.menu) {
  5171. self.hideMenu();
  5172. }
  5173. _each(self.dialogs, function() {
  5174. self.hideDialog();
  5175. });
  5176. K(document).unbind('mousedown', self._docMousedownFn);
  5177. self.toolbar.remove();
  5178. self.edit.remove();
  5179. self.statusbar.last().unbind();
  5180. self.statusbar.unbind();
  5181. self.container.remove();
  5182. self.container = self.toolbar = self.edit = self.menu = null;
  5183. self.dialogs = [];
  5184. self.isCreated = false;
  5185. return self;
  5186. },
  5187. resize : function(width, height, updateProp) {
  5188. var self = this;
  5189. updateProp = _undef(updateProp, true);
  5190. if (width) {
  5191. if (!/%/.test(width)) {
  5192. width = _removeUnit(width);
  5193. width = width < self.minWidth ? self.minWidth : width;
  5194. }
  5195. self.container.css('width', _addUnit(width));
  5196. if (updateProp) {
  5197. self.width = _addUnit(width);
  5198. }
  5199. }
  5200. if (height) {
  5201. height = _removeUnit(height);
  5202. var editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5203. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5204. self.edit.setHeight(editHeight);
  5205. if (updateProp) {
  5206. self.height = _addUnit(height);
  5207. }
  5208. }
  5209. return self;
  5210. },
  5211. select : function() {
  5212. this.isCreated && this.cmd.select();
  5213. return this;
  5214. },
  5215. html : function(val) {
  5216. var self = this;
  5217. if (val === undefined) {
  5218. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5219. }
  5220. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5221. if (self.isCreated) {
  5222. self.cmd.selection();
  5223. }
  5224. return self;
  5225. },
  5226. fullHtml : function() {
  5227. return this.isCreated ? this.edit.html(undefined, true) : '';
  5228. },
  5229. text : function(val) {
  5230. var self = this;
  5231. if (val === undefined) {
  5232. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5233. } else {
  5234. return self.html(_escape(val));
  5235. }
  5236. },
  5237. isEmpty : function() {
  5238. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5239. },
  5240. isDirty : function() {
  5241. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5242. },
  5243. selectedHtml : function() {
  5244. var val = this.isCreated ? this.cmd.range.html() : '';
  5245. val = _removeBookmarkTag(_removeTempTag(val));
  5246. return val;
  5247. },
  5248. count : function(mode) {
  5249. var self = this;
  5250. mode = (mode || 'html').toLowerCase();
  5251. if (mode === 'html') {
  5252. return self.html().length;
  5253. }
  5254. if (mode === 'text') {
  5255. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5256. }
  5257. return 0;
  5258. },
  5259. exec : function(key) {
  5260. key = key.toLowerCase();
  5261. var self = this, cmd = self.cmd,
  5262. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5263. if (changeFlag) {
  5264. self.addBookmark(false);
  5265. }
  5266. cmd[key].apply(cmd, _toArray(arguments, 1));
  5267. if (changeFlag) {
  5268. self.updateState();
  5269. self.addBookmark(false);
  5270. if (self.options.afterChange) {
  5271. self.options.afterChange.call(self);
  5272. }
  5273. }
  5274. return self;
  5275. },
  5276. insertHtml : function(val, quickMode) {
  5277. if (!this.isCreated) {
  5278. return this;
  5279. }
  5280. val = this.beforeSetHtml(val);
  5281. this.exec('inserthtml', val, quickMode);
  5282. return this;
  5283. },
  5284. appendHtml : function(val) {
  5285. this.html(this.html() + val);
  5286. if (this.isCreated) {
  5287. var cmd = this.cmd;
  5288. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5289. cmd.select();
  5290. }
  5291. return this;
  5292. },
  5293. sync : function() {
  5294. _elementVal(this.srcElement, this.html());
  5295. return this;
  5296. },
  5297. focus : function() {
  5298. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5299. return this;
  5300. },
  5301. blur : function() {
  5302. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5303. return this;
  5304. },
  5305. addBookmark : function(checkSize) {
  5306. checkSize = _undef(checkSize, true);
  5307. var self = this, edit = self.edit,
  5308. body = edit.doc.body,
  5309. html = _removeTempTag(body.innerHTML), bookmark;
  5310. if (checkSize && self._undoStack.length > 0) {
  5311. var prev = self._undoStack[self._undoStack.length - 1];
  5312. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5313. return self;
  5314. }
  5315. }
  5316. if (edit.designMode && !self._firstAddBookmark) {
  5317. var range = self.cmd.range;
  5318. bookmark = range.createBookmark(true);
  5319. bookmark.html = _removeTempTag(body.innerHTML);
  5320. range.moveToBookmark(bookmark);
  5321. } else {
  5322. bookmark = {
  5323. html : html
  5324. };
  5325. }
  5326. self._firstAddBookmark = false;
  5327. _addBookmarkToStack(self._undoStack, bookmark);
  5328. return self;
  5329. },
  5330. undo : function() {
  5331. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5332. },
  5333. redo : function() {
  5334. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5335. },
  5336. fullscreen : function(bool) {
  5337. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5338. this.addBookmark(false);
  5339. return this.remove().create();
  5340. },
  5341. readonly : function(isReadonly) {
  5342. isReadonly = _undef(isReadonly, true);
  5343. var self = this, edit = self.edit, doc = edit.doc;
  5344. if (self.designMode) {
  5345. self.toolbar.disableAll(isReadonly, []);
  5346. } else {
  5347. _each(self.noDisableItems, function() {
  5348. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5349. });
  5350. }
  5351. if (_IE) {
  5352. doc.body.contentEditable = !isReadonly;
  5353. } else {
  5354. doc.designMode = isReadonly ? 'off' : 'on';
  5355. }
  5356. edit.textarea[0].disabled = isReadonly;
  5357. },
  5358. createMenu : function(options) {
  5359. var self = this,
  5360. name = options.name,
  5361. knode = self.toolbar.get(name),
  5362. pos = knode.pos();
  5363. options.x = pos.x;
  5364. options.y = pos.y + knode.height();
  5365. options.z = self.options.zIndex;
  5366. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5367. if (options.selectedColor !== undefined) {
  5368. options.cls = 'ke-colorpicker-' + self.themeType;
  5369. options.noColor = self.lang('noColor');
  5370. self.menu = _colorpicker(options);
  5371. } else {
  5372. options.cls = 'ke-menu-' + self.themeType;
  5373. options.centerLineMode = false;
  5374. self.menu = _menu(options);
  5375. }
  5376. return self.menu;
  5377. },
  5378. hideMenu : function() {
  5379. this.menu.remove();
  5380. this.menu = null;
  5381. return this;
  5382. },
  5383. hideContextmenu : function() {
  5384. this.contextmenu.remove();
  5385. this.contextmenu = null;
  5386. return this;
  5387. },
  5388. createDialog : function(options) {
  5389. var self = this, name = options.name;
  5390. options.z = self.options.zIndex;
  5391. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5392. options.closeBtn = _undef(options.closeBtn, {
  5393. name : self.lang('close'),
  5394. click : function(e) {
  5395. self.hideDialog();
  5396. if (_IE && self.cmd) {
  5397. self.cmd.select();
  5398. }
  5399. }
  5400. });
  5401. options.noBtn = _undef(options.noBtn, {
  5402. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5403. click : function(e) {
  5404. self.hideDialog();
  5405. if (_IE && self.cmd) {
  5406. self.cmd.select();
  5407. }
  5408. }
  5409. });
  5410. if (self.dialogAlignType != 'page') {
  5411. options.alignEl = self.container;
  5412. }
  5413. options.cls = 'ke-dialog-' + self.themeType;
  5414. if (self.dialogs.length > 0) {
  5415. var firstDialog = self.dialogs[0],
  5416. parentDialog = self.dialogs[self.dialogs.length - 1];
  5417. firstDialog.setMaskIndex(parentDialog.z + 2);
  5418. options.z = parentDialog.z + 3;
  5419. options.showMask = false;
  5420. }
  5421. var dialog = _dialog(options);
  5422. self.dialogs.push(dialog);
  5423. return dialog;
  5424. },
  5425. hideDialog : function() {
  5426. var self = this;
  5427. if (self.dialogs.length > 0) {
  5428. self.dialogs.pop().remove();
  5429. }
  5430. if (self.dialogs.length > 0) {
  5431. var firstDialog = self.dialogs[0],
  5432. parentDialog = self.dialogs[self.dialogs.length - 1];
  5433. firstDialog.setMaskIndex(parentDialog.z - 1);
  5434. }
  5435. return self;
  5436. },
  5437. errorDialog : function(html) {
  5438. var self = this;
  5439. var dialog = self.createDialog({
  5440. width : 750,
  5441. title : self.lang('uploadError'),
  5442. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5443. });
  5444. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5445. doc.open();
  5446. doc.write(html);
  5447. doc.close();
  5448. K(doc.body).css('background-color', '#FFF');
  5449. iframe[0].contentWindow.focus();
  5450. return self;
  5451. }
  5452. };
  5453. function _editor(options) {
  5454. return new KEditor(options);
  5455. }
  5456. var _instances = [];
  5457. function _create(expr, options) {
  5458. options = options || {};
  5459. options.basePath = _undef(options.basePath, K.basePath);
  5460. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5461. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5462. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5463. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5464. var themeType = _undef(options.themeType, K.options.themeType);
  5465. _loadStyle(options.themesPath + 'default/default.css');
  5466. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5467. }
  5468. function create(editor) {
  5469. _each(_plugins, function(name, fn) {
  5470. if (_isFunction(fn)) {
  5471. fn.call(editor, KindEditor);
  5472. if (!editor._pluginStatus) {
  5473. editor._pluginStatus = {};
  5474. }
  5475. editor._pluginStatus[name] = 'inited';
  5476. }
  5477. });
  5478. return editor.create();
  5479. }
  5480. var knode = K(expr);
  5481. if (!knode || knode.length === 0) {
  5482. return;
  5483. }
  5484. if (knode.length > 1) {
  5485. knode.each(function() {
  5486. _create(this, options);
  5487. });
  5488. return _instances[0];
  5489. }
  5490. options.srcElement = knode[0];
  5491. var editor = new KEditor(options);
  5492. _instances.push(editor);
  5493. if (_language[editor.langType]) {
  5494. return create(editor);
  5495. }
  5496. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5497. create(editor);
  5498. });
  5499. return editor;
  5500. }
  5501. function _eachEditor(expr, fn) {
  5502. K(expr).each(function(i, el) {
  5503. K.each(_instances, function(j, editor) {
  5504. if (editor && editor.srcElement[0] == el) {
  5505. fn.call(editor, j);
  5506. return false;
  5507. }
  5508. });
  5509. });
  5510. }
  5511. K.remove = function(expr) {
  5512. _eachEditor(expr, function(i) {
  5513. this.remove();
  5514. _instances.splice(i, 1);
  5515. });
  5516. };
  5517. K.sync = function(expr) {
  5518. _eachEditor(expr, function() {
  5519. this.sync();
  5520. });
  5521. };
  5522. K.html = function(expr, val) {
  5523. _eachEditor(expr, function() {
  5524. this.html(val);
  5525. });
  5526. };
  5527. K.insertHtml = function(expr, val) {
  5528. _eachEditor(expr, function() {
  5529. this.insertHtml(val);
  5530. });
  5531. };
  5532. K.appendHtml = function(expr, val) {
  5533. _eachEditor(expr, function() {
  5534. this.appendHtml(val);
  5535. });
  5536. };
  5537. if (_IE && _V < 7) {
  5538. _nativeCommand(document, 'BackgroundImageCache', true);
  5539. }
  5540. K.EditorClass = KEditor;
  5541. K.editor = _editor;
  5542. K.create = _create;
  5543. K.instances = _instances;
  5544. K.plugin = _plugin;
  5545. K.lang = _lang;
  5546. _plugin('core', function(K) {
  5547. var self = this,
  5548. shortcutKeys = {
  5549. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5550. };
  5551. self.afterSetHtml(function() {
  5552. if (self.options.afterChange) {
  5553. self.options.afterChange.call(self);
  5554. }
  5555. });
  5556. self.afterCreate(function() {
  5557. if (self.syncType != 'form') {
  5558. return;
  5559. }
  5560. var el = K(self.srcElement), hasForm = false;
  5561. while ((el = el.parent())) {
  5562. if (el.name == 'form') {
  5563. hasForm = true;
  5564. break;
  5565. }
  5566. }
  5567. if (hasForm) {
  5568. el.bind('submit', function(e) {
  5569. self.sync();
  5570. K(window).bind('unload', function() {
  5571. self.edit.textarea.remove();
  5572. });
  5573. });
  5574. var resetBtn = K('[type="reset"]', el);
  5575. resetBtn.click(function() {
  5576. self.html(self.initContent);
  5577. self.cmd.selection();
  5578. });
  5579. self.beforeRemove(function() {
  5580. el.unbind();
  5581. resetBtn.unbind();
  5582. });
  5583. }
  5584. });
  5585. self.clickToolbar('source', function() {
  5586. if (self.edit.designMode) {
  5587. self.toolbar.disableAll(true);
  5588. self.edit.design(false);
  5589. self.toolbar.select('source');
  5590. } else {
  5591. self.toolbar.disableAll(false);
  5592. self.edit.design(true);
  5593. self.toolbar.unselect('source');
  5594. if (_GECKO) {
  5595. setTimeout(function() {
  5596. self.cmd.selection();
  5597. }, 0);
  5598. } else {
  5599. self.cmd.selection();
  5600. }
  5601. }
  5602. self.designMode = self.edit.designMode;
  5603. });
  5604. self.afterCreate(function() {
  5605. if (!self.designMode) {
  5606. self.toolbar.disableAll(true).select('source');
  5607. }
  5608. });
  5609. self.clickToolbar('fullscreen', function() {
  5610. self.fullscreen();
  5611. });
  5612. if (self.fullscreenShortcut) {
  5613. var loaded = false;
  5614. self.afterCreate(function() {
  5615. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5616. if (e.which == 27) {
  5617. setTimeout(function() {
  5618. self.fullscreen();
  5619. }, 0);
  5620. }
  5621. });
  5622. if (loaded) {
  5623. if (_IE && !self.designMode) {
  5624. return;
  5625. }
  5626. self.focus();
  5627. }
  5628. if (!loaded) {
  5629. loaded = true;
  5630. }
  5631. });
  5632. }
  5633. _each('undo,redo'.split(','), function(i, name) {
  5634. if (shortcutKeys[name]) {
  5635. self.afterCreate(function() {
  5636. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5637. self.clickToolbar(name);
  5638. });
  5639. });
  5640. }
  5641. self.clickToolbar(name, function() {
  5642. self[name]();
  5643. });
  5644. });
  5645. self.clickToolbar('formatblock', function() {
  5646. var blocks = self.lang('formatblock.formatBlock'),
  5647. heights = {
  5648. h1 : 28,
  5649. h2 : 24,
  5650. h3 : 18,
  5651. H4 : 14,
  5652. p : 12
  5653. },
  5654. curVal = self.cmd.val('formatblock'),
  5655. menu = self.createMenu({
  5656. name : 'formatblock',
  5657. width : self.langType == 'en' ? 200 : 150
  5658. });
  5659. _each(blocks, function(key, val) {
  5660. var style = 'font-size:' + heights[key] + 'px;';
  5661. if (key.charAt(0) === 'h') {
  5662. style += 'font-weight:bold;';
  5663. }
  5664. menu.addItem({
  5665. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5666. height : heights[key] + 12,
  5667. checked : (curVal === key || curVal === val),
  5668. click : function() {
  5669. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5670. }
  5671. });
  5672. });
  5673. });
  5674. self.clickToolbar('fontname', function() {
  5675. var curVal = self.cmd.val('fontname'),
  5676. menu = self.createMenu({
  5677. name : 'fontname',
  5678. width : 150
  5679. });
  5680. _each(self.lang('fontname.fontName'), function(key, val) {
  5681. menu.addItem({
  5682. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5683. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5684. click : function() {
  5685. self.exec('fontname', key).hideMenu();
  5686. }
  5687. });
  5688. });
  5689. });
  5690. self.clickToolbar('fontsize', function() {
  5691. var curVal = self.cmd.val('fontsize'),
  5692. menu = self.createMenu({
  5693. name : 'fontsize',
  5694. width : 150
  5695. });
  5696. _each(self.fontSizeTable, function(i, val) {
  5697. menu.addItem({
  5698. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5699. height : _removeUnit(val) + 12,
  5700. checked : curVal === val,
  5701. click : function() {
  5702. self.exec('fontsize', val).hideMenu();
  5703. }
  5704. });
  5705. });
  5706. });
  5707. self.clickToolbar('fontheight', function() {
  5708. var curVal = self.cmd.val('fontheight'),
  5709. menu = self.createMenu({
  5710. name : 'fontsize',
  5711. width : 150
  5712. });
  5713. _each(self.fontHeightTable, function(i, val) {
  5714. menu.addItem({
  5715. title : '<span unselectable="on">' + val + '</span>',
  5716. height : 20,
  5717. checked : curVal === val,
  5718. click : function() {
  5719. self.exec('fontheight', val).hideMenu();
  5720. }
  5721. });
  5722. });
  5723. });
  5724. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5725. self.clickToolbar(name, function() {
  5726. self.createMenu({
  5727. name : name,
  5728. selectedColor : self.cmd.val(name) || 'default',
  5729. colors : self.colorTable,
  5730. click : function(color) {
  5731. self.exec(name, color).hideMenu();
  5732. }
  5733. });
  5734. });
  5735. });
  5736. _each(('cut,copy,paste').split(','), function(i, name) {
  5737. self.clickToolbar(name, function() {
  5738. self.focus();
  5739. try {
  5740. self.exec(name, null);
  5741. } catch(e) {
  5742. alert(self.lang(name + 'Error'));
  5743. }
  5744. });
  5745. });
  5746. self.clickToolbar('about', function() {
  5747. var html = '<div style="margin:20px;">' +
  5748. '<div>KindEditor ' + _VERSION + '</div>' +
  5749. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5750. '</div>';
  5751. self.createDialog({
  5752. name : 'about',
  5753. width : 350,
  5754. title : self.lang('about'),
  5755. body : html
  5756. });
  5757. });
  5758. self.plugin.getSelectedLink = function() {
  5759. return self.cmd.commonAncestor('a');
  5760. };
  5761. self.plugin.getSelectedImage = function() {
  5762. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5763. return !/^ke-\w+$/i.test(img[0].className);
  5764. });
  5765. };
  5766. self.plugin.getSelectedFlash = function() {
  5767. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5768. return img[0].className == 'ke-flash';
  5769. });
  5770. };
  5771. self.plugin.getSelectedMedia = function() {
  5772. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5773. return img[0].className == 'ke-media' || img[0].className == 'ke-rm';
  5774. });
  5775. };
  5776. self.plugin.getSelectedAnchor = function() {
  5777. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5778. return img[0].className == 'ke-anchor';
  5779. });
  5780. };
  5781. _each('link,image,flash,media,anchor'.split(','), function(i, name) {
  5782. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5783. _each('edit,delete'.split(','), function(j, val) {
  5784. self.addContextmenu({
  5785. title : self.lang(val + uName),
  5786. click : function() {
  5787. self.loadPlugin(name, function() {
  5788. self.plugin[name][val]();
  5789. self.hideMenu();
  5790. });
  5791. },
  5792. cond : self.plugin['getSelected' + uName],
  5793. width : 150,
  5794. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5795. });
  5796. });
  5797. self.addContextmenu({ title : '-' });
  5798. });
  5799. self.plugin.getSelectedTable = function() {
  5800. return self.cmd.commonAncestor('table');
  5801. };
  5802. self.plugin.getSelectedRow = function() {
  5803. return self.cmd.commonAncestor('tr');
  5804. };
  5805. self.plugin.getSelectedCell = function() {
  5806. return self.cmd.commonAncestor('td');
  5807. };
  5808. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5809. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5810. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5811. self.addContextmenu({
  5812. title : self.lang('table' + val),
  5813. click : function() {
  5814. self.loadPlugin('table', function() {
  5815. self.plugin.table[val]();
  5816. self.hideMenu();
  5817. });
  5818. },
  5819. cond : cond,
  5820. width : 170,
  5821. iconClass : 'ke-icon-table' + val
  5822. });
  5823. });
  5824. self.addContextmenu({ title : '-' });
  5825. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5826. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5827. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5828. if (shortcutKeys[name]) {
  5829. self.afterCreate(function() {
  5830. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5831. self.cmd.selection();
  5832. self.clickToolbar(name);
  5833. });
  5834. });
  5835. }
  5836. self.clickToolbar(name, function() {
  5837. self.focus().exec(name, null);
  5838. });
  5839. });
  5840. self.afterCreate(function() {
  5841. var doc = self.edit.doc, cmd, bookmark, div,
  5842. cls = '__kindeditor_paste__', pasting = false;
  5843. function movePastedData() {
  5844. cmd.range.moveToBookmark(bookmark);
  5845. cmd.select();
  5846. if (_WEBKIT) {
  5847. K('div.' + cls, div).each(function() {
  5848. K(this).after('<br />').remove(true);
  5849. });
  5850. K('span.Apple-style-span', div).remove(true);
  5851. K('span.Apple-tab-span', div).remove(true);
  5852. K('span[style]', div).each(function() {
  5853. if (K(this).css('white-space') == 'nowrap') {
  5854. K(this).remove(true);
  5855. }
  5856. });
  5857. K('meta', div).remove();
  5858. }
  5859. var html = div[0].innerHTML;
  5860. div.remove();
  5861. if (html === '') {
  5862. return;
  5863. }
  5864. if (_WEBKIT) {
  5865. html = html.replace(/(<br>)\1/ig, '$1');
  5866. }
  5867. if (self.pasteType === 2) {
  5868. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5869. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5870. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5871. } else {
  5872. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5873. html = self.beforeSetHtml(html);
  5874. }
  5875. }
  5876. if (self.pasteType === 1) {
  5877. html = html.replace(/&nbsp;/ig, ' ');
  5878. html = html.replace(/\n\s*\n/g, '\n');
  5879. html = html.replace(/<br[^>]*>/ig, '\n');
  5880. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5881. html = html.replace(/<[^>]+>/g, '');
  5882. html = html.replace(/ {2}/g, ' &nbsp;');
  5883. if (self.newlineTag == 'p') {
  5884. if (/\n/.test(html)) {
  5885. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5886. }
  5887. } else {
  5888. html = html.replace(/\n/g, '<br />$&');
  5889. }
  5890. }
  5891. self.insertHtml(html, true);
  5892. autoImg(self);
  5893. }
  5894. K(doc.body).bind('paste', function(e){
  5895. //处理IE11,Chrome粘贴图片上传
  5896. function dopasteImg() {
  5897. //debugger;
  5898. var file = null;
  5899. if (window.clipboardData) {//ie
  5900. if (clipboardData.files && clipboardData.files.length)//IE11
  5901. file = clipboardData.files[0];
  5902. else if (!clipboardData.getData("text") && !clipboardData.getData("url")) {
  5903. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5904. return true;
  5905. }
  5906. } else {
  5907. if (e.event.clipboardData.items)//chrome
  5908. for (var i = 0; i < e.event.clipboardData.items.length; i++) {
  5909. if (e.event.clipboardData.items[i].kind === "file") {
  5910. file = e.event.clipboardData.items[i];
  5911. break;
  5912. }
  5913. }
  5914. if (file == null) {
  5915. if (!e.event.clipboardData.getData("url") && !e.event.clipboardData.getData("text")) {
  5916. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5917. return true;
  5918. }
  5919. }
  5920. }
  5921. if (file) {
  5922. if (!K.undef(self.allowImageUpload, true)) {
  5923. alert("编辑器禁止上传图片,请与有关人员联系!");
  5924. return true;
  5925. }
  5926. //获取File Blob
  5927. //debugger;
  5928. var blb;
  5929. if (file.getAsFile) {//Chrome
  5930. blb = file.getAsFile();
  5931. if (blb.size === 0) {
  5932. alert("不能获取剪切板中的" + (file.type.indexOf("image/") === 0 ? "图像" : "文件")
  5933. +"\n如果是从OutLook中复制的,请换其他程序,如Word");
  5934. return true;
  5935. }
  5936. sendfile(blb, file.type);
  5937. } else {
  5938. var fr = new FileReader();
  5939. if (fr.readAsArrayBuffer) {//ie
  5940. fr.onloadend = function (evt) {
  5941. blb = evt.target.result;
  5942. sendfile(blb, file.type);
  5943. }
  5944. fr.readAsArrayBuffer(file);
  5945. }
  5946. }
  5947. function sendfile(b, t) {
  5948. var xhr = new XMLHttpRequest();
  5949. var formData = new FormData();
  5950. var isImg = t.indexOf("image/") === 0;
  5951. //formData.append('imgFile', file,"untitled." + t.split('/')[1]);
  5952. //formData.append('imgFile', b);
  5953. var myBlob = new Blob([b], { "type": t });
  5954. formData.append(self.filePostName, myBlob, "untitled." + t.split('/')[1]);
  5955. //formData.append('imgFile', b);
  5956. formData.append('dir', isImg ? 'image' : 'file');
  5957. if (self.uploadYunJson && self.uploadYunJson.domain) {
  5958. formData.append('token', self.uploadYunJson.token);
  5959. xhr.open('POST', self.uploadYunJson.domain);
  5960. } else {
  5961. xhr.open('POST', self.uploadJson);
  5962. }
  5963. xhr.onreadystatechange = function () {
  5964. if (xhr.readyState == 4&&xhr.status == 200) {
  5965. // if (fn) {
  5966. var data = _trim(xhr.responseText);
  5967. //if (dataType == 'json') {
  5968. data = _json(data);
  5969. if (data.error) {
  5970. if (typeof ($) !== "undefined" && $.messager && $.messager.alert) {
  5971. $.messager.alert('Error', data.message, 'warning');
  5972. } else {
  5973. alert(data.message);
  5974. }
  5975. } else {
  5976. //self.exec('insertimage', url, title, width, height, border, align);
  5977. if(K.undef(self.formatUploadUrl, true))
  5978. data.url =K.formatUrl(data.url, 'absolute');
  5979. self.exec('insertimage', data.url, "from clipboard", undefined, undefined, undefined, undefined);
  5980. }
  5981. //}
  5982. // fn(data);
  5983. // }
  5984. }
  5985. }
  5986. xhr.send(formData);
  5987. }
  5988. return true;
  5989. }
  5990. }
  5991. //debugger;
  5992. if (dopasteImg())
  5993. e.stop();
  5994. //处理粘贴结束5825
  5995. if (self.pasteType === 0) {
  5996. e.stop();
  5997. return;
  5998. }
  5999. if (pasting) {
  6000. return;
  6001. }
  6002. pasting = true;
  6003. K('div.' + cls, doc).remove();
  6004. cmd = self.cmd.selection();
  6005. bookmark = cmd.range.createBookmark();
  6006. div = K('<div class="' + cls + '"></div>', doc).css({
  6007. position : 'absolute',
  6008. width : '1px',
  6009. height : '1px',
  6010. overflow : 'hidden',
  6011. left : '-1981px',
  6012. top : K(bookmark.start).pos().y + 'px',
  6013. 'white-space' : 'nowrap'
  6014. });
  6015. K(doc.body).append(div);
  6016. if (_IE) {
  6017. var rng = cmd.range.get(true);
  6018. rng.moveToElementText(div[0]);
  6019. rng.select();
  6020. rng.execCommand('paste');
  6021. e.preventDefault();
  6022. } else {
  6023. cmd.range.selectNodeContents(div[0]);
  6024. cmd.select();
  6025. div[0].tabIndex = -1;
  6026. div[0].focus();
  6027. }
  6028. setTimeout(function() {
  6029. movePastedData();
  6030. pasting = false;
  6031. }, 0);
  6032. });
  6033. });
  6034. self.beforeGetHtml(function(html) {
  6035. if (_IE && _V <= 8) {
  6036. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  6037. return unescape(tag);
  6038. });
  6039. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  6040. if (!/\s+type="[^"]+"/i.test($0)) {
  6041. return $1 + ' type="text"' + $2;
  6042. }
  6043. return $0;
  6044. });
  6045. }
  6046. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  6047. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  6048. })
  6049. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  6050. var imgAttrs = _getAttrList(full);
  6051. var styles = _getCssList(imgAttrs.style || '');
  6052. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  6053. var width = _undef(styles.width, '');
  6054. var height = _undef(styles.height, '');
  6055. if (/px/i.test(width)) {
  6056. width = _removeUnit(width);
  6057. }
  6058. if (/px/i.test(height)) {
  6059. height = _removeUnit(height);
  6060. }
  6061. attrs.width = _undef(imgAttrs.width, width);
  6062. attrs.height = _undef(imgAttrs.height, height);
  6063. return _mediaEmbed(attrs);
  6064. })
  6065. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  6066. var imgAttrs = _getAttrList(full);
  6067. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  6068. })
  6069. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6070. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  6071. })
  6072. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6073. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  6074. })
  6075. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  6076. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  6077. return $1 + _unescape(src) + $2;
  6078. });
  6079. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  6080. return full;
  6081. })
  6082. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6083. return start + end;
  6084. });
  6085. });
  6086. self.beforeSetHtml(function(html) {
  6087. if (_IE && _V <= 8) {
  6088. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  6089. var attrs = _getAttrList(full);
  6090. var styles = _getCssList(attrs.style || '');
  6091. if (styles.display == 'none') {
  6092. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  6093. }
  6094. return full;
  6095. });
  6096. }
  6097. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  6098. var attrs = _getAttrList(full);
  6099. attrs.src = _undef(attrs.src, '');
  6100. attrs.width = _undef(attrs.width, 0);
  6101. attrs.height = _undef(attrs.height, 0);
  6102. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  6103. })
  6104. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  6105. var attrs = _getAttrList(full);
  6106. if (attrs.href !== undefined) {
  6107. return full;
  6108. }
  6109. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  6110. })
  6111. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  6112. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6113. })
  6114. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  6115. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6116. })
  6117. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  6118. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  6119. return full;
  6120. }
  6121. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  6122. return full;
  6123. })
  6124. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6125. return start + 'data-ke-' + end;
  6126. })
  6127. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  6128. if (full.indexOf('ke-zeroborder') >= 0) {
  6129. return full;
  6130. }
  6131. return _addClassToTag(full, 'ke-zeroborder');
  6132. });
  6133. });
  6134. });
  6135. })(window);
  6136. /*******************************************************************************
  6137. * KindEditor - WYSIWYG HTML Editor for Internet
  6138. * Copyright (C) 2006-2011 kindsoft.net
  6139. *
  6140. * @author Roddy <luolonghao@gmail.com>
  6141. * @site http://www.kindsoft.net/
  6142. * @licence http://www.kindsoft.net/license.php
  6143. *******************************************************************************/
  6144. KindEditor.lang({
  6145. source : 'HTML代码',
  6146. preview : '预览',
  6147. undo : '后退(Ctrl+Z)',
  6148. redo : '前进(Ctrl+Y)',
  6149. cut : '剪切(Ctrl+X)',
  6150. copy : '复制(Ctrl+C)',
  6151. paste : '粘贴(Ctrl+V)',
  6152. plainpaste : '粘贴为无格式文本',
  6153. wordpaste : '从Word粘贴',
  6154. selectall : '全选(Ctrl+A)',
  6155. justifyleft : '左对齐',
  6156. justifycenter : '居中',
  6157. justifyright : '右对齐',
  6158. justifyfull : '两端对齐',
  6159. insertorderedlist : '编号',
  6160. insertunorderedlist : '项目符号',
  6161. indent : '增加缩进',
  6162. outdent : '减少缩进',
  6163. subscript : '下标',
  6164. superscript : '上标',
  6165. formatblock : '段落',
  6166. fontname : '字体',
  6167. fontsize : '文字大小',
  6168. fontheight : '文字间距',
  6169. forecolor : '文字颜色',
  6170. hilitecolor : '文字背景',
  6171. bold : '粗体(Ctrl+B)',
  6172. italic : '斜体(Ctrl+I)',
  6173. underline : '下划线(Ctrl+U)',
  6174. strikethrough : '删除线',
  6175. removeformat : '删除格式',
  6176. image : '图片',
  6177. multiimage : '批量图片上传',
  6178. flash : 'Flash',
  6179. media : '音频',
  6180. table : '表格',
  6181. tablecell : '单元格',
  6182. hr : '插入横线',
  6183. emoticons : '插入表情',
  6184. link : '超级链接',
  6185. unlink : '取消超级链接',
  6186. fullscreen : '全屏显示',
  6187. about : '关于',
  6188. print : '打印(Ctrl+P)',
  6189. filemanager : '文件库',
  6190. code : '插入程序代码',
  6191. map : 'Google地图',
  6192. baidumap : '百度地图',
  6193. lineheight : '行距',
  6194. clearhtml : '清理HTML代码',
  6195. pagebreak : '插入分页符',
  6196. quickformat : '一键排版',
  6197. insertfile : '插入文件',
  6198. template : '插入模板',
  6199. anchor : '锚点',
  6200. yes : '确定',
  6201. no : '取消',
  6202. close : '关闭',
  6203. editImage : '图片属性',
  6204. deleteImage : '删除图片',
  6205. editFlash : 'Flash属性',
  6206. deleteFlash : '删除Flash',
  6207. editMedia : '音频属性',
  6208. deleteMedia : '删除音频',
  6209. editLink : '超级链接属性',
  6210. deleteLink : '取消超级链接',
  6211. editAnchor : '锚点属性',
  6212. deleteAnchor : '删除锚点',
  6213. tableprop : '表格属性',
  6214. tablecellprop : '单元格属性',
  6215. tableinsert : '插入表格',
  6216. tabledelete : '删除表格',
  6217. tablecolinsertleft : '左侧插入列',
  6218. tablecolinsertright : '右侧插入列',
  6219. tablerowinsertabove : '上方插入行',
  6220. tablerowinsertbelow : '下方插入行',
  6221. tablerowmerge : '向下合并单元格',
  6222. tablecolmerge : '向右合并单元格',
  6223. tablerowsplit : '拆分行',
  6224. tablecolsplit : '拆分列',
  6225. tablecoldelete : '删除列',
  6226. tablerowdelete : '删除行',
  6227. noColor : '无颜色',
  6228. pleaseSelectFile : '请选择文件。',
  6229. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6230. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6231. invalidWidth : "宽度必须为数字。",
  6232. invalidHeight : "高度必须为数字。",
  6233. invalidBorder : "边框必须为数字。",
  6234. invalidUrl : "请输入有效的URL地址。",
  6235. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6236. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6237. invalidPadding : '边距必须为数字。',
  6238. invalidSpacing : '间距必须为数字。',
  6239. invalidJson : '服务器发生故障。',
  6240. uploadSuccess : '上传成功。',
  6241. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6242. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6243. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6244. ajaxLoading : '加载中,请稍候 ...',
  6245. uploadLoading : '上传中,请稍候 ...',
  6246. uploadError : '上传错误',
  6247. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6248. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6249. 'code.pleaseInput' : '请输入程序代码。',
  6250. 'link.url' : 'URL',
  6251. 'link.linkType' : '打开类型',
  6252. 'link.newWindow' : '新窗口',
  6253. 'link.selfWindow' : '当前窗口',
  6254. 'flash.url' : 'URL',
  6255. 'flash.width' : '宽度',
  6256. 'flash.height' : '高度',
  6257. 'flash.upload' : '上传',
  6258. 'flash.viewServer' : '文件空间',
  6259. 'media.url' : 'URL',
  6260. 'media.width' : '宽度',
  6261. 'media.height' : '高度',
  6262. 'media.autostart' : '自动播放',
  6263. 'media.upload' : '上传',
  6264. 'media.viewServer' : '文件空间',
  6265. 'image.remoteImage' : '网络图片',
  6266. 'image.localImage' : '本地上传',
  6267. 'image.remoteUrl' : '图片地址',
  6268. 'image.localUrl' : '上传文件',
  6269. 'image.size' : '图片大小',
  6270. 'image.width' : '宽',
  6271. 'image.height' : '高',
  6272. 'image.resetSize' : '重置大小',
  6273. 'image.align' : '对齐方式',
  6274. 'image.defaultAlign' : '默认方式',
  6275. 'image.leftAlign' : '左对齐',
  6276. 'image.rightAlign' : '右对齐',
  6277. 'image.imgTitle' : '图片说明',
  6278. 'image.upload' : '浏览...',
  6279. 'image.viewServer' : '图片空间',
  6280. //'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6281. 'multiimage.uploadDesc' : '',
  6282. 'multiimage.startUpload' : '开始上传',
  6283. 'multiimage.clearAll' : '全部清空',
  6284. 'multiimage.insertAll' : '全部插入',
  6285. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6286. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6287. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6288. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6289. 'multiimage.unknownError' : '发生异常,无法上传。',
  6290. 'multiimage.pending' : '等待上传',
  6291. 'multiimage.uploadError' : '上传失败',
  6292. 'filemanager.emptyFolder' : '空文件夹',
  6293. 'filemanager.moveup' : '移到上一级文件夹',
  6294. 'filemanager.viewType' : '显示方式:',
  6295. 'filemanager.viewImage' : '缩略图',
  6296. 'filemanager.listImage' : '详细信息',
  6297. 'filemanager.orderType' : '排序方式:',
  6298. 'filemanager.fileName' : '名称',
  6299. 'filemanager.fileSize' : '大小',
  6300. 'filemanager.fileType' : '类型',
  6301. 'insertfile.url' : 'URL',
  6302. 'insertfile.title' : '文件说明',
  6303. 'insertfile.upload' : '上传',
  6304. 'insertfile.viewServer' : '文件空间',
  6305. 'table.cells' : '单元格数',
  6306. 'table.rows' : '行数',
  6307. 'table.cols' : '列数',
  6308. 'table.size' : '大小',
  6309. 'table.width' : '宽度',
  6310. 'table.height' : '高度',
  6311. 'table.percent' : '%',
  6312. 'table.px' : 'px',
  6313. 'table.space' : '边距间距',
  6314. 'table.padding' : '边距',
  6315. 'table.spacing' : '间距',
  6316. 'table.align' : '对齐方式',
  6317. 'table.textAlign' : '水平对齐',
  6318. 'table.verticalAlign' : '垂直对齐',
  6319. 'table.alignDefault' : '默认',
  6320. 'table.alignLeft' : '左对齐',
  6321. 'table.alignCenter' : '居中',
  6322. 'table.alignRight' : '右对齐',
  6323. 'table.alignTop' : '顶部',
  6324. 'table.alignMiddle' : '中部',
  6325. 'table.alignBottom' : '底部',
  6326. 'table.alignBaseline' : '基线',
  6327. 'table.border' : '边框',
  6328. 'table.borderWidth' : '边框',
  6329. 'table.borderColor' : '颜色',
  6330. 'table.backgroundColor' : '背景颜色',
  6331. 'map.address' : '地址: ',
  6332. 'map.search' : '搜索',
  6333. 'baidumap.address' : '地址: ',
  6334. 'baidumap.search' : '搜索',
  6335. 'baidumap.insertDynamicMap' : '插入动态地图',
  6336. 'anchor.name' : '锚点名称',
  6337. 'formatblock.formatBlock' : {
  6338. h1 : '标题 1',
  6339. h2 : '标题 2',
  6340. h3 : '标题 3',
  6341. h4 : '标题 4',
  6342. p : '正 文'
  6343. },
  6344. 'fontname.fontName' : {
  6345. 'SimSun' : '宋体',
  6346. 'NSimSun' : '新宋体',
  6347. 'FangSong_GB2312' : '仿宋_GB2312',
  6348. 'KaiTi_GB2312' : '楷体_GB2312',
  6349. 'SimHei' : '黑体',
  6350. 'Microsoft YaHei' : '微软雅黑',
  6351. 'Arial' : 'Arial',
  6352. 'Arial Black' : 'Arial Black',
  6353. 'Times New Roman' : 'Times New Roman',
  6354. 'Courier New' : 'Courier New',
  6355. 'Tahoma' : 'Tahoma',
  6356. 'Verdana' : 'Verdana'
  6357. },
  6358. 'lineheight.lineHeight' : [
  6359. {'1' : '单倍行距'},
  6360. {'1.5' : '1.5倍行距'},
  6361. {'1.75' : '1.75倍行距'},
  6362. {'2' : '2倍行距'},
  6363. {'2.5' : '2.5倍行距'},
  6364. {'3' : '3倍行距'}
  6365. ],
  6366. 'template.selectTemplate' : '可选模板',
  6367. 'template.replaceContent' : '替换当前内容',
  6368. 'template.fileList' : {
  6369. '1.html' : '图片和文字',
  6370. '2.html' : '表格',
  6371. '3.html' : '项目编号'
  6372. }
  6373. }, 'zh-CN');
  6374. KindEditor.options.langType = 'zh-CN';
  6375. /*******************************************************************************
  6376. * KindEditor - WYSIWYG HTML Editor for Internet
  6377. * Copyright (C) 2006-2011 kindsoft.net
  6378. *
  6379. * @author Roddy <luolonghao@gmail.com>
  6380. * @site http://www.kindsoft.net/
  6381. * @licence http://www.kindsoft.net/license.php
  6382. *******************************************************************************/
  6383. KindEditor.plugin('anchor', function(K) {
  6384. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6385. self.plugin.anchor = {
  6386. edit : function() {
  6387. var html = ['<div style="padding:20px;">',
  6388. '<div class="ke-dialog-row">',
  6389. '<label for="keName">' + lang.name + '</label>',
  6390. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6391. '</div>',
  6392. '</div>'].join('');
  6393. var dialog = self.createDialog({
  6394. name : name,
  6395. width : 300,
  6396. title : self.lang(name),
  6397. body : html,
  6398. yesBtn : {
  6399. name : self.lang('yes'),
  6400. click : function(e) {
  6401. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6402. }
  6403. }
  6404. });
  6405. var div = dialog.div,
  6406. nameBox = K('input[name="name"]', div);
  6407. var img = self.plugin.getSelectedAnchor();
  6408. if (img) {
  6409. nameBox.val(unescape(img.attr('data-ke-name')));
  6410. }
  6411. nameBox[0].focus();
  6412. nameBox[0].select();
  6413. },
  6414. 'delete' : function() {
  6415. self.plugin.getSelectedAnchor().remove();
  6416. }
  6417. };
  6418. self.clickToolbar(name, self.plugin.anchor.edit);
  6419. });
  6420. /*******************************************************************************
  6421. * KindEditor - WYSIWYG HTML Editor for Internet
  6422. * Copyright (C) 2006-2011 kindsoft.net
  6423. *
  6424. * @author Roddy <luolonghao@gmail.com>
  6425. * @site http://www.kindsoft.net/
  6426. * @licence http://www.kindsoft.net/license.php
  6427. *******************************************************************************/
  6428. KindEditor.plugin('autoheight', function(K) {
  6429. var self = this;
  6430. if (!self.autoHeightMode) {
  6431. return;
  6432. }
  6433. var minHeight;
  6434. function hideScroll() {
  6435. var edit = self.edit;
  6436. var body = edit.doc.body;
  6437. edit.iframe[0].scroll = 'no';
  6438. body.style.overflowY = 'hidden';
  6439. }
  6440. function resetHeight() {
  6441. if(self.fullscreenMode){
  6442. return;
  6443. }
  6444. var edit = self.edit;
  6445. var body = edit.doc.body;
  6446. edit.iframe.height(minHeight);
  6447. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6448. }
  6449. function init() {
  6450. minHeight = K.removeUnit(self.height);
  6451. self.edit.afterChange(resetHeight);
  6452. if(!self.fullscreenMode){
  6453. hideScroll();
  6454. }
  6455. resetHeight();
  6456. }
  6457. if (self.isCreated) {
  6458. init();
  6459. } else {
  6460. self.afterCreate(init);
  6461. }
  6462. });
  6463. /*
  6464. * 如何实现真正的自动高度?
  6465. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6466. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6467. * 由此就实现了真正的自动高度
  6468. * 测试:chrome、firefox、IE9、IE8
  6469. * */
  6470. /*******************************************************************************
  6471. * KindEditor - WYSIWYG HTML Editor for Internet
  6472. * Copyright (C) 2006-2011 kindsoft.net
  6473. *
  6474. * @author Roddy <luolonghao@gmail.com>
  6475. * @site http://www.kindsoft.net/
  6476. * @licence http://www.kindsoft.net/license.php
  6477. *******************************************************************************/
  6478. KindEditor.plugin('baidumap', function(K) {
  6479. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6480. var mapWidth = K.undef(self.mapWidth, 558);
  6481. var mapHeight = K.undef(self.mapHeight, 360);
  6482. self.clickToolbar(name, function() {
  6483. var html = ['<div style="padding:10px 20px;">',
  6484. '<div class="ke-header">',
  6485. '<div class="ke-left">',
  6486. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6487. '<span class="ke-button-common ke-button-outer">',
  6488. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6489. '</span>',
  6490. '</div>',
  6491. '<div class="ke-right">',
  6492. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6493. '</div>',
  6494. '<div class="ke-clearfix"></div>',
  6495. '</div>',
  6496. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6497. '</div>'].join('');
  6498. var dialog = self.createDialog({
  6499. name : name,
  6500. width : mapWidth + 42,
  6501. title : self.lang(name),
  6502. body : html,
  6503. yesBtn : {
  6504. name : self.lang('yes'),
  6505. click : function(e) {
  6506. var map = win.map;
  6507. var centerObj = map.getCenter();
  6508. var center = centerObj.lng + ',' + centerObj.lat;
  6509. var zoom = map.getZoom();
  6510. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6511. '?center=' + encodeURIComponent(center),
  6512. '&zoom=' + encodeURIComponent(zoom),
  6513. '&width=' + mapWidth,
  6514. '&height=' + mapHeight,
  6515. '&markers=' + encodeURIComponent(center),
  6516. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6517. if (checkbox[0].checked) {
  6518. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6519. } else {
  6520. self.exec('insertimage', url);
  6521. }
  6522. self.hideDialog().focus();
  6523. }
  6524. },
  6525. beforeRemove : function() {
  6526. searchBtn.remove();
  6527. if (doc) {
  6528. doc.write('');
  6529. }
  6530. iframe.remove();
  6531. }
  6532. });
  6533. var div = dialog.div,
  6534. addressBox = K('[name="address"]', div),
  6535. searchBtn = K('[name="searchBtn"]', div),
  6536. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6537. win, doc;
  6538. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6539. function ready() {
  6540. win = iframe[0].contentWindow;
  6541. doc = K.iframeDoc(iframe);
  6542. }
  6543. iframe.bind('load', function() {
  6544. iframe.unbind('load');
  6545. if (K.IE) {
  6546. ready();
  6547. } else {
  6548. setTimeout(ready, 0);
  6549. }
  6550. });
  6551. K('.ke-map', div).replaceWith(iframe);
  6552. searchBtn.click(function() {
  6553. win.search(addressBox.val());
  6554. });
  6555. });
  6556. });
  6557. /*******************************************************************************
  6558. * KindEditor - WYSIWYG HTML Editor for Internet
  6559. * Copyright (C) 2006-2011 kindsoft.net
  6560. *
  6561. * @author Roddy <luolonghao@gmail.com>
  6562. * @site http://www.kindsoft.net/
  6563. * @licence http://www.kindsoft.net/license.php
  6564. *******************************************************************************/
  6565. KindEditor.plugin('map', function(K) {
  6566. var self = this, name = 'map', lang = self.lang(name + '.');
  6567. self.clickToolbar(name, function() {
  6568. var html = ['<div style="padding:10px 20px;">',
  6569. '<div class="ke-dialog-row">',
  6570. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6571. '<span class="ke-button-common ke-button-outer">',
  6572. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6573. '</span>',
  6574. '</div>',
  6575. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  6576. '</div>'].join('');
  6577. var dialog = self.createDialog({
  6578. name : name,
  6579. width : 600,
  6580. title : self.lang(name),
  6581. body : html,
  6582. yesBtn : {
  6583. name : self.lang('yes'),
  6584. click : function(e) {
  6585. var geocoder = win.geocoder,
  6586. map = win.map,
  6587. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  6588. zoom = map.getZoom(),
  6589. maptype = map.getMapTypeId(),
  6590. url = 'http://maps.googleapis.com/maps/api/staticmap';
  6591. url += '?center=' + encodeURIComponent(center);
  6592. url += '&zoom=' + encodeURIComponent(zoom);
  6593. url += '&size=558x360';
  6594. url += '&maptype=' + encodeURIComponent(maptype);
  6595. url += '&markers=' + encodeURIComponent(center);
  6596. url += '&language=' + self.langType;
  6597. url += '&sensor=false';
  6598. self.exec('insertimage', url).hideDialog().focus();
  6599. }
  6600. },
  6601. beforeRemove : function() {
  6602. searchBtn.remove();
  6603. if (doc) {
  6604. doc.write('');
  6605. }
  6606. iframe.remove();
  6607. }
  6608. });
  6609. var div = dialog.div,
  6610. addressBox = K('[name="address"]', div),
  6611. searchBtn = K('[name="searchBtn"]', div),
  6612. win, doc;
  6613. var iframeHtml = ['<!doctype html><html><head>',
  6614. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  6615. '<style>',
  6616. ' html { height: 100% }',
  6617. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  6618. ' #map_canvas { height: 100% }',
  6619. '</style>',
  6620. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  6621. '<script>',
  6622. 'var map, geocoder;',
  6623. 'function initialize() {',
  6624. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  6625. ' var options = {',
  6626. ' zoom: 11,',
  6627. ' center: latlng,',
  6628. ' disableDefaultUI: true,',
  6629. ' panControl: true,',
  6630. ' zoomControl: true,',
  6631. ' mapTypeControl: true,',
  6632. ' scaleControl: true,',
  6633. ' streetViewControl: false,',
  6634. ' overviewMapControl: true,',
  6635. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  6636. ' };',
  6637. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  6638. ' geocoder = new google.maps.Geocoder();',
  6639. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  6640. ' if (status == google.maps.GeocoderStatus.OK) {',
  6641. ' if (results[3]) {',
  6642. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  6643. ' }',
  6644. ' }',
  6645. ' });',
  6646. '}',
  6647. 'function search(address) {',
  6648. ' if (!map) return;',
  6649. ' geocoder.geocode({address : address}, function(results, status) {',
  6650. ' if (status == google.maps.GeocoderStatus.OK) {',
  6651. ' map.setZoom(11);',
  6652. ' map.setCenter(results[0].geometry.location);',
  6653. ' var marker = new google.maps.Marker({',
  6654. ' map: map,',
  6655. ' position: results[0].geometry.location',
  6656. ' });',
  6657. ' } else {',
  6658. ' alert("Invalid address: " + address);',
  6659. ' }',
  6660. ' });',
  6661. '}',
  6662. '</script>',
  6663. '</head>',
  6664. '<body onload="initialize();">',
  6665. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  6666. '</body></html>'].join('\n');
  6667. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  6668. function ready() {
  6669. win = iframe[0].contentWindow;
  6670. doc = K.iframeDoc(iframe);
  6671. }
  6672. iframe.bind('load', function() {
  6673. iframe.unbind('load');
  6674. if (K.IE) {
  6675. ready();
  6676. } else {
  6677. setTimeout(ready, 0);
  6678. }
  6679. });
  6680. K('.ke-map', div).replaceWith(iframe);
  6681. searchBtn.click(function() {
  6682. win.search(addressBox.val());
  6683. });
  6684. });
  6685. });
  6686. /*******************************************************************************
  6687. * KindEditor - WYSIWYG HTML Editor for Internet
  6688. * Copyright (C) 2006-2011 kindsoft.net
  6689. *
  6690. * @author Roddy <luolonghao@gmail.com>
  6691. * @site http://www.kindsoft.net/
  6692. * @licence http://www.kindsoft.net/license.php
  6693. *******************************************************************************/
  6694. KindEditor.plugin('clearhtml', function(K) {
  6695. var self = this, name = 'clearhtml';
  6696. self.clickToolbar(name, function() {
  6697. self.focus();
  6698. var html = self.html();
  6699. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6700. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6701. html = K.formatHtml(html, {
  6702. a : ['href', 'target'],
  6703. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6704. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6705. table : ['border'],
  6706. 'td,th' : ['rowspan', 'colspan'],
  6707. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6708. });
  6709. self.html(html);
  6710. self.cmd.selection(true);
  6711. self.addBookmark();
  6712. });
  6713. });
  6714. /*******************************************************************************
  6715. * KindEditor - WYSIWYG HTML Editor for Internet
  6716. * Copyright (C) 2006-2011 kindsoft.net
  6717. *
  6718. * @author Roddy <luolonghao@gmail.com>
  6719. * @site http://www.kindsoft.net/
  6720. * @licence http://www.kindsoft.net/license.php
  6721. *******************************************************************************/
  6722. KindEditor.plugin('code', function(K) {
  6723. var self = this, name = 'code';
  6724. self.clickToolbar(name, function() {
  6725. var lang = self.lang(name + '.'),
  6726. html = ['<div style="padding:10px 20px;">',
  6727. '<div class="ke-dialog-row">',
  6728. '<select class="ke-code-type">',
  6729. '<option value="js">JavaScript</option>',
  6730. '<option value="html">HTML</option>',
  6731. '<option value="css">CSS</option>',
  6732. '<option value="php">PHP</option>',
  6733. '<option value="pl">Perl</option>',
  6734. '<option value="py">Python</option>',
  6735. '<option value="rb">Ruby</option>',
  6736. '<option value="java">Java</option>',
  6737. '<option value="vb">ASP/VB</option>',
  6738. '<option value="cpp">C/C++</option>',
  6739. '<option value="cs">C#</option>',
  6740. '<option value="xml">XML</option>',
  6741. '<option value="bsh">Shell</option>',
  6742. '<option value="">Other</option>',
  6743. '</select>',
  6744. '</div>',
  6745. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6746. '</div>'].join(''),
  6747. dialog = self.createDialog({
  6748. name : name,
  6749. width : 450,
  6750. title : self.lang(name),
  6751. body : html,
  6752. yesBtn : {
  6753. name : self.lang('yes'),
  6754. click : function(e) {
  6755. var type = K('.ke-code-type', dialog.div).val(),
  6756. code = textarea.val(),
  6757. cls = type === '' ? '' : ' lang-' + type,
  6758. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6759. if (K.trim(code) === '') {
  6760. alert(lang.pleaseInput);
  6761. textarea[0].focus();
  6762. return;
  6763. }
  6764. self.insertHtml(html).hideDialog().focus();
  6765. }
  6766. }
  6767. }),
  6768. textarea = K('textarea', dialog.div);
  6769. textarea[0].focus();
  6770. });
  6771. });
  6772. /*******************************************************************************
  6773. * KindEditor - WYSIWYG HTML Editor for Internet
  6774. * Copyright (C) 2006-2011 kindsoft.net
  6775. *
  6776. * @author Roddy <luolonghao@gmail.com>
  6777. * @site http://www.kindsoft.net/
  6778. * @licence http://www.kindsoft.net/license.php
  6779. *******************************************************************************/
  6780. KindEditor.plugin('emoticons', function(K) {
  6781. var self = this, name = 'emoticons',
  6782. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6783. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6784. currentPageNum = 1;
  6785. self.clickToolbar(name, function() {
  6786. var rows = 5, cols = 9, total = 135, startNum = 0,
  6787. cells = rows * cols, pages = Math.ceil(total / cells),
  6788. colsHalf = Math.floor(cols / 2),
  6789. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6790. elements = [],
  6791. menu = self.createMenu({
  6792. name : name,
  6793. beforeRemove : function() {
  6794. removeEvent();
  6795. }
  6796. });
  6797. menu.div.append(wrapperDiv);
  6798. var previewDiv, previewImg;
  6799. if (allowPreview) {
  6800. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6801. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6802. wrapperDiv.append(previewDiv);
  6803. previewDiv.append(previewImg);
  6804. }
  6805. function bindCellEvent(cell, j, num) {
  6806. if (previewDiv) {
  6807. cell.mouseover(function() {
  6808. if (j > colsHalf) {
  6809. previewDiv.css('left', 0);
  6810. previewDiv.css('right', '');
  6811. } else {
  6812. previewDiv.css('left', '');
  6813. previewDiv.css('right', 0);
  6814. }
  6815. previewImg.attr('src', path + num + '.gif');
  6816. K(this).addClass('ke-on');
  6817. });
  6818. } else {
  6819. cell.mouseover(function() {
  6820. K(this).addClass('ke-on');
  6821. });
  6822. }
  6823. cell.mouseout(function() {
  6824. K(this).removeClass('ke-on');
  6825. });
  6826. cell.click(function(e) {
  6827. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6828. e.stop();
  6829. });
  6830. }
  6831. function createEmoticonsTable(pageNum, parentDiv) {
  6832. var table = document.createElement('table');
  6833. parentDiv.append(table);
  6834. if (previewDiv) {
  6835. K(table).mouseover(function() {
  6836. previewDiv.show('block');
  6837. });
  6838. K(table).mouseout(function() {
  6839. previewDiv.hide();
  6840. });
  6841. elements.push(K(table));
  6842. }
  6843. table.className = 'ke-table';
  6844. table.cellPadding = 0;
  6845. table.cellSpacing = 0;
  6846. table.border = 0;
  6847. var num = (pageNum - 1) * cells + startNum;
  6848. for (var i = 0; i < rows; i++) {
  6849. var row = table.insertRow(i);
  6850. for (var j = 0; j < cols; j++) {
  6851. var cell = K(row.insertCell(j));
  6852. cell.addClass('ke-cell');
  6853. bindCellEvent(cell, j, num);
  6854. var span = K('<span class="ke-img"></span>')
  6855. .css('background-position', '-' + (24 * num) + 'px 0px')
  6856. .css('background-image', 'url(' + path + 'static.gif)');
  6857. cell.append(span);
  6858. elements.push(cell);
  6859. num++;
  6860. }
  6861. }
  6862. return table;
  6863. }
  6864. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6865. function removeEvent() {
  6866. K.each(elements, function() {
  6867. this.unbind();
  6868. });
  6869. }
  6870. var pageDiv;
  6871. function bindPageEvent(el, pageNum) {
  6872. el.click(function(e) {
  6873. removeEvent();
  6874. table.parentNode.removeChild(table);
  6875. pageDiv.remove();
  6876. table = createEmoticonsTable(pageNum, wrapperDiv);
  6877. createPageTable(pageNum);
  6878. currentPageNum = pageNum;
  6879. e.stop();
  6880. });
  6881. }
  6882. function createPageTable(currentPageNum) {
  6883. pageDiv = K('<div class="ke-page"></div>');
  6884. wrapperDiv.append(pageDiv);
  6885. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6886. if (currentPageNum !== pageNum) {
  6887. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6888. bindPageEvent(a, pageNum);
  6889. pageDiv.append(a);
  6890. elements.push(a);
  6891. } else {
  6892. pageDiv.append(K('@[' + pageNum + ']'));
  6893. }
  6894. pageDiv.append(K('@&nbsp;'));
  6895. }
  6896. }
  6897. createPageTable(currentPageNum);
  6898. });
  6899. });
  6900. /*******************************************************************************
  6901. * KindEditor - WYSIWYG HTML Editor for Internet
  6902. * Copyright (C) 2006-2011 kindsoft.net
  6903. *
  6904. * @author Roddy <luolonghao@gmail.com>
  6905. * @site http://www.kindsoft.net/
  6906. * @licence http://www.kindsoft.net/license.php
  6907. *******************************************************************************/
  6908. KindEditor.plugin('filemanager', function(K) {
  6909. var self = this, name = 'filemanager',
  6910. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6911. imgPath = self.pluginsPath + name + '/images/',
  6912. lang = self.lang(name + '.');
  6913. function makeFileTitle(filename, filesize, datetime) {
  6914. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6915. }
  6916. function bindTitle(el, data) {
  6917. if (data.is_dir) {
  6918. el.attr('title', data.filename);
  6919. } else {
  6920. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6921. }
  6922. }
  6923. self.plugin.filemanagerDialog = function(options) {
  6924. var width = K.undef(options.width, 650),
  6925. height = K.undef(options.height, 510),
  6926. dirName = K.undef(options.dirName, ''),
  6927. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(),
  6928. clickFn = options.clickFn;
  6929. var html = [
  6930. '<div style="padding:10px 20px;">',
  6931. '<div class="ke-plugin-filemanager-header">',
  6932. '<div class="ke-left">',
  6933. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6934. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6935. '</div>',
  6936. '<div class="ke-right">',
  6937. '标签 <input type="text" style="width:100px;" value="" name="viewTag">',
  6938. '分类 <select class="ke-inline-block" name="viewCate">',
  6939. '',
  6940. '</select> ',
  6941. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6942. '<option value="VIEW">' + lang.viewImage + '</option>',
  6943. '<option value="LIST">' + lang.listImage + '</option>',
  6944. '</select> ',
  6945. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6946. '<option value="NAME">' + lang.fileName + '</option>',
  6947. '<option value="SIZE">' + lang.fileSize + '</option>',
  6948. '<option value="TYPE">' + lang.fileType + '</option>',
  6949. '</select>',
  6950. '</div>',
  6951. '<div class="ke-clearfix"></div>',
  6952. '</div>',
  6953. '<div class="ke-plugin-filemanager-body"></div>',
  6954. '</div>'
  6955. ].join('');
  6956. var dialog = self.createDialog({
  6957. name : name,
  6958. width : width,
  6959. height : height,
  6960. title : self.lang(name),
  6961. body : html
  6962. }),
  6963. div = dialog.div,
  6964. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6965. moveupImg = K('[name="moveupImg"]', div),
  6966. moveupLink = K('[name="moveupLink"]', div),
  6967. viewServerBtn = K('[name="viewServer"]', div),
  6968. viewCateBox = K('[name="viewCate"]', div),
  6969. viewTagBox = K('[name="viewTag"]', div),
  6970. viewTypeBox = K('[name="viewType"]', div),
  6971. orderTypeBox = K('[name="orderType"]', div);
  6972. function reloadPage(path, order, func, cate, tag) {
  6973. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6974. if (cate) {
  6975. param += '&cate=' + cate;
  6976. }
  6977. if (tag) {
  6978. param += '&tag=' + tag;
  6979. }
  6980. dialog.showLoading(self.lang('ajaxLoading'));
  6981. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6982. dialog.hideLoading();
  6983. func(data);
  6984. });
  6985. }
  6986. var elList = [];
  6987. function bindEvent(el, result, data, createFunc) {
  6988. var fileUrl = K.formatUrl(result.current_url + data.file, 'absolute'),
  6989. dirPath = encodeURIComponent(result.current_dir_path + data.path + '/');
  6990. if (data.is_dir) {
  6991. el.click(function(e) {
  6992. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  6993. });
  6994. } else if (data.is_photo) {
  6995. el.click(function(e) {
  6996. clickFn.call(this, fileUrl, data.file);
  6997. });
  6998. } else {
  6999. el.click(function(e) {
  7000. clickFn.call(this, fileUrl, data.file);
  7001. });
  7002. }
  7003. elList.push(el);
  7004. }
  7005. function createCommon(result, createFunc) {
  7006. K.each(elList, function() {
  7007. this.unbind();
  7008. });
  7009. moveupLink.unbind();
  7010. viewTypeBox.unbind();
  7011. orderTypeBox.unbind();
  7012. if (result.current_dir_path) {
  7013. moveupLink.click(function(e) {
  7014. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  7015. });
  7016. }
  7017. function changeFunc() {
  7018. if (viewTypeBox.val() == 'VIEW') {
  7019. reloadPage(result.current_dir_path, orderTypeBox.val(), createView, viewCateBox.val(), viewTagBox.val());
  7020. } else {
  7021. reloadPage(result.current_dir_path, orderTypeBox.val(), createList, viewCateBox.val(), viewTagBox.val());
  7022. }
  7023. }
  7024. viewTypeBox.change(changeFunc);
  7025. orderTypeBox.change(changeFunc);
  7026. viewCateBox.change(changeFunc);
  7027. bodyDiv.html('');
  7028. }
  7029. function createList(result) {
  7030. createCommon(result, createList);
  7031. var table = document.createElement('table');
  7032. table.className = 'ke-table';
  7033. table.cellPadding = 0;
  7034. table.cellSpacing = 0;
  7035. table.border = 0;
  7036. bodyDiv.append(table);
  7037. var fileList = result.file_list;
  7038. for (var i = 0, len = fileList.length; i < len; i++) {
  7039. var data = fileList[i], row = K(table.insertRow(i));
  7040. row.mouseover(function(e) {
  7041. K(this).addClass('ke-on');
  7042. })
  7043. .mouseout(function(e) {
  7044. K(this).removeClass('ke-on');
  7045. });
  7046. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  7047. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  7048. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  7049. if (!data.is_dir || data.has_file) {
  7050. row.css('cursor', 'pointer');
  7051. cell0.attr('title', data.filename);
  7052. bindEvent(cell0, result, data, createList);
  7053. } else {
  7054. cell0.attr('title', lang.emptyFolder);
  7055. }
  7056. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  7057. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  7058. }
  7059. }
  7060. function createView(result) {
  7061. createCommon(result, createView);
  7062. var fileList = result.file_list;
  7063. for (var i = 0, len = fileList.length; i < len; i++) {
  7064. var data = fileList[i],
  7065. div = K('<div class="ke-inline-block ke-item"></div>');
  7066. bodyDiv.append(div);
  7067. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7068. .mouseover(function(e) {
  7069. K(this).addClass('ke-on');
  7070. })
  7071. .mouseout(function(e) {
  7072. K(this).removeClass('ke-on');
  7073. });
  7074. div.append(photoDiv);
  7075. var fileUrl = result.current_url + data.file,
  7076. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  7077. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  7078. if (!data.is_dir || data.has_file) {
  7079. photoDiv.css('cursor', 'pointer');
  7080. bindTitle(photoDiv, data);
  7081. bindEvent(photoDiv, result, data, createView);
  7082. } else {
  7083. photoDiv.attr('title', lang.emptyFolder);
  7084. }
  7085. photoDiv.append(img);
  7086. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  7087. }
  7088. }
  7089. viewTypeBox.val(viewType);
  7090. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  7091. return dialog;
  7092. }
  7093. });
  7094. /*******************************************************************************
  7095. * KindEditor - WYSIWYG HTML Editor for Internet
  7096. * Copyright (C) 2006-2011 kindsoft.net
  7097. *
  7098. * @author Roddy <luolonghao@gmail.com>
  7099. * @site http://www.kindsoft.net/
  7100. * @licence http://www.kindsoft.net/license.php
  7101. *******************************************************************************/
  7102. KindEditor.plugin('flash', function(K) {
  7103. var self = this, name = 'flash', lang = self.lang(name + '.'),
  7104. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  7105. allowFileManager = K.undef(self.allowFileManager, false),
  7106. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7107. extraParams = K.undef(self.extraFileUploadParams, {}),
  7108. filePostName = K.undef(self.filePostName, 'imgFile'),
  7109. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7110. self.plugin.flash = {
  7111. edit : function() {
  7112. var html = [
  7113. '<div style="padding:20px;">',
  7114. '<div class="ke-dialog-row">',
  7115. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7116. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7117. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7118. '<span class="ke-button-common ke-button-outer">',
  7119. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7120. '</span>',
  7121. '</div>',
  7122. '<div class="ke-dialog-row">',
  7123. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7124. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  7125. '</div>',
  7126. '<div class="ke-dialog-row">',
  7127. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7128. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  7129. '</div>',
  7130. '</div>'
  7131. ].join('');
  7132. var dialog = self.createDialog({
  7133. name : name,
  7134. width : 450,
  7135. title : self.lang(name),
  7136. body : html,
  7137. yesBtn : {
  7138. name : self.lang('yes'),
  7139. click : function(e) {
  7140. var url = K.trim(urlBox.val()),
  7141. width = widthBox.val(),
  7142. height = heightBox.val();
  7143. if (url == 'http://' || K.invalidUrl(url)) {
  7144. alert(self.lang('invalidUrl'));
  7145. urlBox[0].focus();
  7146. return;
  7147. }
  7148. if (!/^\d*$/.test(width)) {
  7149. alert(self.lang('invalidWidth'));
  7150. widthBox[0].focus();
  7151. return;
  7152. }
  7153. if (!/^\d*$/.test(height)) {
  7154. alert(self.lang('invalidHeight'));
  7155. heightBox[0].focus();
  7156. return;
  7157. }
  7158. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7159. src : url,
  7160. type : K.mediaType('.swf'),
  7161. width : width,
  7162. height : height,
  7163. quality : 'high'
  7164. });
  7165. self.insertHtml(html).hideDialog().focus();
  7166. }
  7167. }
  7168. }),
  7169. div = dialog.div,
  7170. urlBox = K('[name="url"]', div),
  7171. viewServerBtn = K('[name="viewServer"]', div),
  7172. widthBox = K('[name="width"]', div),
  7173. heightBox = K('[name="height"]', div);
  7174. urlBox.val('http://');
  7175. if (allowFlashUpload) {
  7176. var uploadbutton = K.uploadbutton({
  7177. button : K('.ke-upload-button', div)[0],
  7178. fieldName : filePostName,
  7179. extraParams : extraParams,
  7180. url : K.addParam(uploadJson, 'dir=flash'),
  7181. afterUpload : function(data) {
  7182. dialog.hideLoading();
  7183. if (data.error === 0) {
  7184. var url = data.url;
  7185. if (formatUploadUrl) {
  7186. url = K.formatUrl(url, 'absolute');
  7187. }
  7188. urlBox.val(url);
  7189. if (self.afterUpload) {
  7190. self.afterUpload.call(self, url, data, name);
  7191. }
  7192. alert(self.lang('uploadSuccess'));
  7193. } else {
  7194. alert(data.message);
  7195. }
  7196. },
  7197. afterError : function(html) {
  7198. dialog.hideLoading();
  7199. self.errorDialog(html);
  7200. }
  7201. });
  7202. uploadbutton.fileBox.change(function(e) {
  7203. dialog.showLoading(self.lang('uploadLoading'));
  7204. uploadbutton.submit();
  7205. });
  7206. } else {
  7207. K('.ke-upload-button', div).hide();
  7208. }
  7209. if (allowFileManager) {
  7210. viewServerBtn.click(function(e) {
  7211. var clickFn = function(url, title, id) {
  7212. K('[name="url"]', div).val(url);
  7213. if (self.afterSelectFile) {
  7214. self.afterSelectFile.call(self, url);
  7215. }
  7216. };
  7217. var cur = K('[name="url"]', div).val();
  7218. editorShowUpload(cur, self.fileManagerJson, 'flash库', clickFn, this);
  7219. /*
  7220. self.loadPlugin('filemanager', function() {
  7221. self.plugin.filemanagerDialog({
  7222. viewType : 'LIST',
  7223. dirName : 'flash',
  7224. clickFn : function(url, title) {
  7225. if (self.dialogs.length > 1) {
  7226. K('[name="url"]', div).val(url);
  7227. if (self.afterSelectFile) {
  7228. self.afterSelectFile.call(self, url);
  7229. }
  7230. self.hideDialog();
  7231. }
  7232. }
  7233. });
  7234. });
  7235. */
  7236. });
  7237. } else {
  7238. viewServerBtn.hide();
  7239. }
  7240. var img = self.plugin.getSelectedFlash();
  7241. if (img) {
  7242. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7243. urlBox.val(attrs.src);
  7244. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7245. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7246. }
  7247. urlBox[0].focus();
  7248. urlBox[0].select();
  7249. },
  7250. 'delete' : function() {
  7251. self.plugin.getSelectedFlash().remove();
  7252. self.addBookmark();
  7253. }
  7254. };
  7255. self.clickToolbar(name, self.plugin.flash.edit);
  7256. });
  7257. /*******************************************************************************
  7258. * KindEditor - WYSIWYG HTML Editor for Internet
  7259. * Copyright (C) 2006-2011 kindsoft.net
  7260. *
  7261. * @author Roddy <luolonghao@gmail.com>
  7262. * @site http://www.kindsoft.net/
  7263. * @licence http://www.kindsoft.net/license.php
  7264. *******************************************************************************/
  7265. KindEditor.plugin('image', function(K) {
  7266. var self = this, name = 'image',
  7267. allowImageUpload = K.undef(self.allowImageUpload, true),
  7268. allowImageRemote = K.undef(self.allowImageRemote, true),
  7269. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7270. allowFileManager = K.undef(self.allowFileManager, false),
  7271. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7272. imageTabIndex = K.undef(self.imageTabIndex, 0),
  7273. imgPath = self.pluginsPath + 'image/images/',
  7274. extraParams = K.undef(self.extraFileUploadParams, {}),
  7275. filePostName = K.undef(self.filePostName, 'imgFile'),
  7276. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  7277. lang = self.lang(name + '.');
  7278. self.plugin.imageDialog = function(options) {
  7279. var imageUrl = options.imageUrl,
  7280. imageWidth = K.undef(options.imageWidth, ''),
  7281. imageHeight = K.undef(options.imageHeight, ''),
  7282. imageTitle = K.undef(options.imageTitle, ''),
  7283. imageAlign = K.undef(options.imageAlign, ''),
  7284. showRemote = K.undef(options.showRemote, true),
  7285. showLocal = K.undef(options.showLocal, true),
  7286. tabIndex = K.undef(options.tabIndex, 0),
  7287. clickFn = options.clickFn;
  7288. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  7289. var hiddenElements = [];
  7290. for(var k in extraParams){
  7291. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  7292. }
  7293. var html = [
  7294. '<div style="padding:20px;">',
  7295. '<div class="tabs"></div>',
  7296. '<div class="tab1" style="display:none;">',
  7297. '<div class="ke-dialog-row">',
  7298. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  7299. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  7300. '<span class="ke-button-common ke-button-outer">',
  7301. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7302. '</span>',
  7303. '</div>',
  7304. '<div class="ke-dialog-row">',
  7305. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  7306. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  7307. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  7308. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  7309. '</div>',
  7310. '<div class="ke-dialog-row">',
  7311. '<label style="width:60px;">' + lang.align + '</label>',
  7312. '<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="" />',
  7313. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  7314. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7315. '</div>',
  7316. '<div class="ke-dialog-row">',
  7317. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7318. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7319. '</div>',
  7320. '</div>',
  7321. '<div class="tab2" style="display:none;">',
  7322. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7323. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7324. '<div class="ke-dialog-row">',
  7325. hiddenElements.join(''),
  7326. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7327. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7328. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7329. '</div>',
  7330. '</form>',
  7331. '</div>',
  7332. '</div>'
  7333. ].join('');
  7334. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7335. dialogHeight = showLocal && showRemote ? 300 : 250;
  7336. var dialog = self.createDialog({
  7337. name : name,
  7338. width : dialogWidth,
  7339. height : dialogHeight,
  7340. title : self.lang(name),
  7341. body : html,
  7342. yesBtn : {
  7343. name : self.lang('yes'),
  7344. click : function(e) {
  7345. if (dialog.isLoading) {
  7346. return;
  7347. }
  7348. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7349. if (uploadbutton.fileBox.val() == '') {
  7350. alert(self.lang('pleaseSelectFile'));
  7351. return;
  7352. }
  7353. dialog.showLoading(self.lang('uploadLoading'));
  7354. uploadbutton.submit();
  7355. localUrlBox.val('');
  7356. return;
  7357. }
  7358. var url = K.trim(urlBox.val()),
  7359. width = widthBox.val(),
  7360. height = heightBox.val(),
  7361. title = titleBox.val(),
  7362. align = '';
  7363. alignBox.each(function() {
  7364. if (this.checked) {
  7365. align = this.value;
  7366. return false;
  7367. }
  7368. });
  7369. if (url == 'http://' || K.invalidUrl(url)) {
  7370. alert(self.lang('invalidUrl'));
  7371. urlBox[0].focus();
  7372. return;
  7373. }
  7374. if (!/^\d*$/.test(width)) {
  7375. alert(self.lang('invalidWidth'));
  7376. widthBox[0].focus();
  7377. return;
  7378. }
  7379. if (!/^\d*$/.test(height)) {
  7380. alert(self.lang('invalidHeight'));
  7381. heightBox[0].focus();
  7382. return;
  7383. }
  7384. clickFn.call(self, url, title, width, height, 0, align);
  7385. }
  7386. },
  7387. beforeRemove : function() {
  7388. viewServerBtn.unbind();
  7389. widthBox.unbind();
  7390. heightBox.unbind();
  7391. refreshBtn.unbind();
  7392. }
  7393. }),
  7394. div = dialog.div;
  7395. var urlBox = K('[name="url"]', div),
  7396. localUrlBox = K('[name="localUrl"]', div),
  7397. viewServerBtn = K('[name="viewServer"]', div),
  7398. widthBox = K('.tab1 [name="width"]', div),
  7399. heightBox = K('.tab1 [name="height"]', div),
  7400. refreshBtn = K('.ke-refresh-btn', div),
  7401. titleBox = K('.tab1 [name="title"]', div),
  7402. alignBox = K('.tab1 [name="align"]', div);
  7403. var tabs;
  7404. if (showRemote && showLocal) {
  7405. tabs = K.tabs({
  7406. src : K('.tabs', div),
  7407. afterSelect : function(i) {}
  7408. });
  7409. tabs.add({
  7410. title : lang.remoteImage,
  7411. panel : K('.tab1', div)
  7412. });
  7413. tabs.add({
  7414. title : lang.localImage,
  7415. panel : K('.tab2', div)
  7416. });
  7417. tabs.select(1);
  7418. } else if (showRemote) {
  7419. K('.tab1', div).show();
  7420. } else if (showLocal) {
  7421. K('.tab2', div).show();
  7422. }
  7423. var uploadbutton = K.uploadbutton({
  7424. button : K('.ke-upload-button', div)[0],
  7425. fieldName : filePostName,
  7426. form : K('.ke-form', div),
  7427. target : target,
  7428. width: 60,
  7429. afterUpload : function(data) {
  7430. dialog.hideLoading();
  7431. if (data.error === 0) {
  7432. var url = data.url;
  7433. if (formatUploadUrl) {
  7434. url = K.formatUrl(url, 'absolute');
  7435. }
  7436. if (self.afterUpload) {
  7437. self.afterUpload.call(self, url, data, name);
  7438. }
  7439. if (!fillDescAfterUploadImage) {
  7440. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7441. } else {
  7442. K(".ke-dialog-row #remoteUrl", div).val(url);
  7443. K(".ke-tabs-li", div)[0].click();
  7444. K(".ke-refresh-btn", div).click();
  7445. }
  7446. } else {
  7447. alert(data.message);
  7448. }
  7449. },
  7450. afterError : function(html) {
  7451. dialog.hideLoading();
  7452. self.errorDialog(html);
  7453. }
  7454. });
  7455. uploadbutton.fileBox.change(function(e) {
  7456. localUrlBox.val(uploadbutton.fileBox.val());
  7457. });
  7458. if (allowFileManager) {
  7459. viewServerBtn.click(function(e) {
  7460. //clickFn.call(this, fileUrl, data.file);
  7461. var clickFn = function(url, title, id) {
  7462. K('[name="url"]', div).val(url);
  7463. if (self.afterSelectFile) {
  7464. self.afterSelectFile.call(self, url);
  7465. }
  7466. };
  7467. var cur = K('[name="url"]', div).val();
  7468. editorShowUpload(cur, self.uploadJson.replace('save.kindeditor', 'view.files'), '图库', clickFn, this);
  7469. /*
  7470. self.loadPlugin('filemanager', function() {
  7471. self.plugin.filemanagerDialog({
  7472. viewType : 'VIEW',
  7473. dirName : 'image',
  7474. clickFn : function(url, title) {
  7475. if (self.dialogs.length > 1) {
  7476. K('[name="url"]', div).val(url);
  7477. if (self.afterSelectFile) {
  7478. self.afterSelectFile.call(self, url);
  7479. }
  7480. self.hideDialog();
  7481. }
  7482. }
  7483. });
  7484. });
  7485. */
  7486. });
  7487. } else {
  7488. viewServerBtn.hide();
  7489. }
  7490. var originalWidth = 0, originalHeight = 0;
  7491. function setSize(width, height) {
  7492. widthBox.val(width);
  7493. heightBox.val(height);
  7494. originalWidth = width;
  7495. originalHeight = height;
  7496. }
  7497. refreshBtn.click(function(e) {
  7498. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7499. position : 'absolute',
  7500. visibility : 'hidden',
  7501. top : 0,
  7502. left : '-1000px'
  7503. });
  7504. tempImg.bind('load', function() {
  7505. setSize(tempImg.width(), tempImg.height());
  7506. tempImg.remove();
  7507. });
  7508. K(document.body).append(tempImg);
  7509. });
  7510. widthBox.change(function(e) {
  7511. if (originalWidth > 0) {
  7512. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7513. }
  7514. });
  7515. heightBox.change(function(e) {
  7516. if (originalHeight > 0) {
  7517. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7518. }
  7519. });
  7520. urlBox.val(options.imageUrl);
  7521. setSize(options.imageWidth, options.imageHeight);
  7522. titleBox.val(options.imageTitle);
  7523. alignBox.each(function() {
  7524. if (this.value === options.imageAlign) {
  7525. this.checked = true;
  7526. return false;
  7527. }
  7528. });
  7529. if (showRemote && tabIndex === 0) {
  7530. urlBox[0].focus();
  7531. urlBox[0].select();
  7532. }
  7533. return dialog;
  7534. };
  7535. self.plugin.image = {
  7536. edit : function() {
  7537. var img = self.plugin.getSelectedImage();
  7538. self.plugin.imageDialog({
  7539. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7540. imageWidth : img ? img.width() : '',
  7541. imageHeight : img ? img.height() : '',
  7542. imageTitle : img ? img.attr('title') : '',
  7543. imageAlign : img ? img.attr('align') : '',
  7544. showRemote : allowImageRemote,
  7545. showLocal : allowImageUpload,
  7546. tabIndex: img ? 0 : imageTabIndex,
  7547. clickFn : function(url, title, width, height, border, align) {
  7548. if (img) {
  7549. img.attr('src', url);
  7550. img.attr('data-ke-src', url);
  7551. img.attr('width', width);
  7552. img.attr('height', height);
  7553. img.attr('title', title);
  7554. img.attr('align', align);
  7555. img.attr('alt', title);
  7556. } else {
  7557. self.exec('insertimage', url, title, width, height, border, align);
  7558. }
  7559. setTimeout(function() {
  7560. self.hideDialog().focus();
  7561. }, 0);
  7562. }
  7563. });
  7564. },
  7565. 'delete' : function() {
  7566. var target = self.plugin.getSelectedImage();
  7567. if (target.parent().name == 'a') {
  7568. target = target.parent();
  7569. }
  7570. target.remove();
  7571. self.addBookmark();
  7572. }
  7573. };
  7574. self.clickToolbar(name, self.plugin.image.edit);
  7575. });
  7576. /*******************************************************************************
  7577. * KindEditor - WYSIWYG HTML Editor for Internet
  7578. * Copyright (C) 2006-2011 kindsoft.net
  7579. *
  7580. * @author Roddy <luolonghao@gmail.com>
  7581. * @site http://www.kindsoft.net/
  7582. * @licence http://www.kindsoft.net/license.php
  7583. *******************************************************************************/
  7584. KindEditor.plugin('insertfile', function(K) {
  7585. var self = this, name = 'insertfile',
  7586. allowFileUpload = K.undef(self.allowFileUpload, true),
  7587. allowFileManager = K.undef(self.allowFileManager, false),
  7588. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7589. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7590. extraParams = K.undef(self.extraFileUploadParams, {}),
  7591. filePostName = K.undef(self.filePostName, 'imgFile'),
  7592. lang = self.lang(name + '.');
  7593. self.plugin.fileDialog = function(options) {
  7594. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7595. fileTitle = K.undef(options.fileTitle, ''),
  7596. clickFn = options.clickFn;
  7597. var html = [
  7598. '<div style="padding:20px;">',
  7599. '<div class="ke-dialog-row">',
  7600. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7601. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7602. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7603. '<span class="ke-button-common ke-button-outer">',
  7604. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7605. '</span>',
  7606. '</div>',
  7607. '<div class="ke-dialog-row">',
  7608. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7609. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7610. '</div>',
  7611. '</form>',
  7612. '</div>'
  7613. ].join('');
  7614. var dialog = self.createDialog({
  7615. name : name,
  7616. width : 450,
  7617. title : self.lang(name),
  7618. body : html,
  7619. yesBtn : {
  7620. name : self.lang('yes'),
  7621. click : function(e) {
  7622. var url = K.trim(urlBox.val()),
  7623. title = titleBox.val();
  7624. if (url == 'http://' || K.invalidUrl(url)) {
  7625. alert(self.lang('invalidUrl'));
  7626. urlBox[0].focus();
  7627. return;
  7628. }
  7629. if (K.trim(title) === '') {
  7630. title = url;
  7631. }
  7632. clickFn.call(self, url, title);
  7633. }
  7634. }
  7635. }),
  7636. div = dialog.div;
  7637. var urlBox = K('[name="url"]', div),
  7638. viewServerBtn = K('[name="viewServer"]', div),
  7639. titleBox = K('[name="title"]', div);
  7640. if (allowFileUpload) {
  7641. var uploadbutton = K.uploadbutton({
  7642. button : K('.ke-upload-button', div)[0],
  7643. fieldName : filePostName,
  7644. url : K.addParam(uploadJson, 'dir=file'),
  7645. extraParams : extraParams,
  7646. afterUpload : function(data) {
  7647. dialog.hideLoading();
  7648. if (data.error === 0) {
  7649. var url = data.url;
  7650. if (formatUploadUrl) {
  7651. url = K.formatUrl(url, 'absolute');
  7652. }
  7653. urlBox.val(url);
  7654. if (self.afterUpload) {
  7655. self.afterUpload.call(self, url, data, name);
  7656. }
  7657. alert(self.lang('uploadSuccess'));
  7658. } else {
  7659. alert(data.message);
  7660. }
  7661. },
  7662. afterError : function(html) {
  7663. dialog.hideLoading();
  7664. self.errorDialog(html);
  7665. }
  7666. });
  7667. uploadbutton.fileBox.change(function(e) {
  7668. dialog.showLoading(self.lang('uploadLoading'));
  7669. uploadbutton.submit();
  7670. });
  7671. } else {
  7672. K('.ke-upload-button', div).hide();
  7673. }
  7674. if (allowFileManager) {
  7675. viewServerBtn.click(function(e) {
  7676. var clickFn = function(url, title, id) {
  7677. K('[name="url"]', div).val(url);
  7678. if (self.afterSelectFile) {
  7679. self.afterSelectFile.call(self, url);
  7680. }
  7681. };
  7682. var cur = K('[name="url"]', div).val();
  7683. editorShowUpload(cur, self.uploadJson.replace('save.kindeditor', 'view.files'), '文件库', clickFn, this);
  7684. /*
  7685. self.loadPlugin('filemanager', function() {
  7686. self.plugin.filemanagerDialog({
  7687. viewType : 'LIST',
  7688. dirName : 'file',
  7689. clickFn : function(url, title) {
  7690. if (self.dialogs.length > 1) {
  7691. self.hideDialog();
  7692. }
  7693. }
  7694. });
  7695. });
  7696. */
  7697. });
  7698. } else {
  7699. viewServerBtn.hide();
  7700. }
  7701. urlBox.val(fileUrl);
  7702. titleBox.val(fileTitle);
  7703. urlBox[0].focus();
  7704. urlBox[0].select();
  7705. };
  7706. self.clickToolbar(name, function() {
  7707. self.plugin.fileDialog({
  7708. clickFn : function(url, title) {
  7709. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7710. self.insertHtml(html).hideDialog().focus();
  7711. }
  7712. });
  7713. });
  7714. });
  7715. /*******************************************************************************
  7716. * KindEditor - WYSIWYG HTML Editor for Internet
  7717. * Copyright (C) 2006-2011 kindsoft.net
  7718. *
  7719. * @author Roddy <luolonghao@gmail.com>
  7720. * @site http://www.kindsoft.net/
  7721. * @licence http://www.kindsoft.net/license.php
  7722. *******************************************************************************/
  7723. KindEditor.plugin('lineheight', function(K) {
  7724. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7725. self.clickToolbar(name, function() {
  7726. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7727. if (commonNode) {
  7728. curVal = commonNode.css('line-height');
  7729. }
  7730. var menu = self.createMenu({
  7731. name : name,
  7732. width : 150
  7733. });
  7734. K.each(lang.lineHeight, function(i, row) {
  7735. K.each(row, function(key, val) {
  7736. menu.addItem({
  7737. title : val,
  7738. checked : curVal === key,
  7739. click : function() {
  7740. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7741. span : '.line-height=' + key
  7742. });
  7743. self.updateState();
  7744. self.addBookmark();
  7745. self.hideMenu();
  7746. }
  7747. });
  7748. });
  7749. });
  7750. });
  7751. });
  7752. /*******************************************************************************
  7753. * KindEditor - WYSIWYG HTML Editor for Internet
  7754. * Copyright (C) 2006-2011 kindsoft.net
  7755. *
  7756. * @author Roddy <luolonghao@gmail.com>
  7757. * @site http://www.kindsoft.net/
  7758. * @licence http://www.kindsoft.net/license.php
  7759. *******************************************************************************/
  7760. KindEditor.plugin('link', function(K) {
  7761. var self = this, name = 'link';
  7762. self.plugin.link = {
  7763. edit : function() {
  7764. var lang = self.lang(name + '.'),
  7765. html = '<div style="padding:20px;">' +
  7766. '<div class="ke-dialog-row">' +
  7767. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7768. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7769. '<div class="ke-dialog-row"">' +
  7770. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7771. '<select id="keType" name="type"></select>' +
  7772. '</div>' +
  7773. '</div>',
  7774. dialog = self.createDialog({
  7775. name : name,
  7776. width : 450,
  7777. title : self.lang(name),
  7778. body : html,
  7779. yesBtn : {
  7780. name : self.lang('yes'),
  7781. click : function(e) {
  7782. var url = K.trim(urlBox.val());
  7783. if (url == 'http://' || K.invalidUrl(url)) {
  7784. alert(self.lang('invalidUrl'));
  7785. urlBox[0].focus();
  7786. return;
  7787. }
  7788. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7789. }
  7790. }
  7791. }),
  7792. div = dialog.div,
  7793. urlBox = K('input[name="url"]', div),
  7794. typeBox = K('select[name="type"]', div);
  7795. urlBox.val('http://');
  7796. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7797. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7798. self.cmd.selection();
  7799. var a = self.plugin.getSelectedLink();
  7800. if (a) {
  7801. self.cmd.range.selectNode(a[0]);
  7802. //self.cmd.select();
  7803. urlBox.val(a.attr('data-ke-src'));
  7804. typeBox.val(a.attr('target'));
  7805. }
  7806. urlBox[0].focus();
  7807. urlBox[0].select();
  7808. },
  7809. 'delete' : function() {
  7810. self.exec('unlink', null);
  7811. }
  7812. };
  7813. self.clickToolbar(name, self.plugin.link.edit);
  7814. });
  7815. /*******************************************************************************
  7816. * KindEditor - WYSIWYG HTML Editor for Internet
  7817. * Copyright (C) 2006-2011 kindsoft.net
  7818. *
  7819. * @author Roddy <luolonghao@gmail.com>
  7820. * @site http://www.kindsoft.net/
  7821. * @licence http://www.kindsoft.net/license.php
  7822. *******************************************************************************/
  7823. KindEditor.plugin('media', function(K) {
  7824. var self = this, name = 'media', lang = self.lang(name + '.'),
  7825. allowFileUpload = K.undef(self.allowFileUpload, true),
  7826. allowFileManager = K.undef(self.allowFileManager, false),
  7827. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7828. allowFileManager = K.undef(self.allowFileManager, false),
  7829. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7830. extraParams = K.undef(self.extraFileUploadParams, {}),
  7831. uploadCoverJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7832. filePostName = K.undef(self.filePostName, 'imgFile'),
  7833. uploadJson = K.undef(self.uploadMediaJson, self.basePath + 'php/upload_json.php');
  7834. if (self.uploadYunJson && self.uploadYunJson.domain) {
  7835. uploadJson = self.uploadYunJson.domain;
  7836. extraParams.token = self.uploadYunJson.token;
  7837. extraParams.key = self.uploadYunJson.path;
  7838. }
  7839. self.plugin.media = {
  7840. edit : function() {
  7841. var html = [
  7842. '<div style="padding:20px;">',
  7843. '<div class="ke-dialog-row">',
  7844. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7845. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7846. '<input type="button" class="ke-upload-button ke-upload-button-media" value="' + lang.upload + '" /> &nbsp;',
  7847. '<span class="ke-button-common ke-button-outer">',
  7848. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7849. '</span>',
  7850. '</div>',
  7851. '<div class="ke-dialog-row">',
  7852. '<label for="keWidth" style="width:60px;">标题</label>',
  7853. '<input type="text" id="keName" class="ke-input-text" style="width:160px;" name="name" value="" maxlength="4" />',
  7854. '</div>',
  7855. '<div class="ke-dialog-row">',
  7856. '<label for="keUrl" style="width:60px;">封面</label>',
  7857. '<input class="ke-input-text" type="text" id="keUrlCover" name="cover_url" value="" style="width:160px;" /> &nbsp;',
  7858. '<input type="button" class="ke-upload-button ke-upload-button-cover" value="' + lang.upload + '" /> &nbsp;',
  7859. '<span class="ke-button-common ke-button-outer">',
  7860. '<input type="button" class="ke-button-common ke-button" name="viewCoverServer" value="' + lang.viewServer + '" />',
  7861. '</span>',
  7862. '<br /><br />(封面要求:图片尺寸80*80px或等比尺寸,上传大小不能超过2M,支持JPG、PNG、GIF格式,建议上传JPG格式)',
  7863. '</div>',
  7864. '<div class="ke-dialog-row" style="display:none;">',
  7865. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7866. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="80" maxlength="4" />',
  7867. '<div style="display: inline;margin-left: 20px;">',
  7868. '<label for="keHeight" >' + lang.height + '</label>',
  7869. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="80" maxlength="4" />',
  7870. '</div>',
  7871. '</div>',
  7872. '<div class="ke-dialog-row" style="display:none;">',
  7873. '<label for="keAutostart">' + lang.autostart + '</label>',
  7874. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7875. '</div>',
  7876. '</div>'
  7877. ].join('');
  7878. var dialog = self.createDialog({
  7879. name : name,
  7880. width : 450,
  7881. height : 230,
  7882. title : self.lang(name),
  7883. body : html,
  7884. yesBtn : {
  7885. name : self.lang('yes'),
  7886. click : function(e) {
  7887. var url = K.trim(urlBox.val()),
  7888. coverUrl = K.trim(coverUrlBox.val()),
  7889. name = nameBox.val(),
  7890. width = widthBox.val(),
  7891. height = heightBox.val();
  7892. if (url == 'http://' || K.invalidUrl(url)) {
  7893. alert(self.lang('invalidUrl'));
  7894. urlBox[0].focus();
  7895. return;
  7896. }
  7897. if (!name) {
  7898. alert('请填写标题');
  7899. urlBox[0].focus();
  7900. return;
  7901. }
  7902. if (coverUrl == 'http://' || K.invalidUrl(coverUrl)) {
  7903. alert('请上传封面');
  7904. urlBox[0].focus();
  7905. return;
  7906. }
  7907. if (!/^\d*$/.test(width)) {
  7908. alert(self.lang('invalidWidth'));
  7909. widthBox[0].focus();
  7910. return;
  7911. }
  7912. if (!/^\d*$/.test(height)) {
  7913. alert(self.lang('invalidHeight'));
  7914. heightBox[0].focus();
  7915. return;
  7916. }
  7917. if (!coverUrl) {
  7918. var cover = self.themesPath + 'common/blank.gif';
  7919. } else {
  7920. var cover = coverUrl;
  7921. }
  7922. /*
  7923. var html = K.mediaImg(cover, {
  7924. src : url,
  7925. type : K.mediaType(url),
  7926. width : width,
  7927. height : height,
  7928. autostart : autostartBox[0].checked ? 'true' : 'false',
  7929. loop : 'true'
  7930. });
  7931. */
  7932. var html = '<img src="'+cover+'" style="width:'+width+'px;height:'+height+'px;" data-file="'+url+'||'+name+'"/>';
  7933. self.insertHtml(html).hideDialog().focus();
  7934. }
  7935. }
  7936. }),
  7937. div = dialog.div,
  7938. nameBox = K('[name="name"]', div),
  7939. coverUrlBox = K('[name="cover_url"]', div),
  7940. viewCoverServerBtn = K('[name="viewCoverServer"]', div),
  7941. urlBox = K('[name="url"]', div),
  7942. viewServerBtn = K('[name="viewServer"]', div),
  7943. widthBox = K('[name="width"]', div),
  7944. heightBox = K('[name="height"]', div),
  7945. autostartBox = K('[name="autostart"]', div);
  7946. urlBox.val('http://');
  7947. coverUrlBox.val('http://');
  7948. if (allowMediaUpload) {
  7949. var uploadbutton = K.uploadbutton({
  7950. button : K('.ke-upload-button-media', div)[0],
  7951. fieldName : filePostName,
  7952. extraParams : extraParams,
  7953. url : K.addParam(uploadJson, 'dir=media'),
  7954. afterUpload : function(data) {
  7955. console.info(data);
  7956. dialog.hideLoading();
  7957. if (data.error === 0) {
  7958. var url = data.url;
  7959. if (formatUploadUrl) {
  7960. url = K.formatUrl(url, 'absolute');
  7961. }
  7962. urlBox.val(url);
  7963. if (self.afterUpload) {
  7964. self.afterUpload.call(self, url, data, name);
  7965. }
  7966. alert(self.lang('uploadSuccess'));
  7967. } else {
  7968. alert(data.message);
  7969. }
  7970. },
  7971. afterError : function(html) {
  7972. dialog.hideLoading();
  7973. self.errorDialog(html);
  7974. }
  7975. });
  7976. uploadbutton.fileBox.change(function(e) {
  7977. dialog.showLoading(self.lang('uploadLoading'));
  7978. uploadbutton.submit(this);
  7979. });
  7980. } else {
  7981. K('.ke-upload-button-media', div).hide();
  7982. }
  7983. if (allowFileUpload) {
  7984. var uploadbuttonCover = K.uploadbutton({
  7985. button : K('.ke-upload-button-cover', div)[0],
  7986. fieldName : filePostName,
  7987. url : K.addParam(uploadCoverJson, 'dir=file'),
  7988. extraParams : extraParams,
  7989. afterUpload : function(data) {
  7990. dialog.hideLoading();
  7991. if (data.error === 0) {
  7992. var url = data.url;
  7993. if (formatUploadUrl) {
  7994. url = K.formatUrl(url, 'absolute');
  7995. }
  7996. coverUrlBox.val(url);
  7997. if (self.afterUpload) {
  7998. self.afterUpload.call(self, url, data, name);
  7999. }
  8000. alert(self.lang('uploadSuccess'));
  8001. } else {
  8002. alert(data.message);
  8003. }
  8004. },
  8005. afterError : function(html) {
  8006. dialog.hideLoading();
  8007. self.errorDialog(html);
  8008. }
  8009. });
  8010. uploadbuttonCover.fileBox.change(function(e) {
  8011. dialog.showLoading(self.lang('uploadLoading'));
  8012. uploadbuttonCover.submit();
  8013. });
  8014. } else {
  8015. K('.ke-upload-button-cover', div).hide();
  8016. }
  8017. if (allowFileManager) {
  8018. viewServerBtn.click(function(e) {
  8019. var clickFn = function(url, title, id) {
  8020. K('[name="url"]', div).val(url);
  8021. if (self.afterSelectFile) {
  8022. self.afterSelectFile.call(self, url);
  8023. }
  8024. };
  8025. var cur = K('[name="url"]', div).val();
  8026. editorShowUpload(cur, self.fileManagerJson, '音频库', clickFn, this);
  8027. /*
  8028. self.loadPlugin('filemanager', function() {
  8029. self.plugin.filemanagerDialog({
  8030. viewType : 'LIST',
  8031. dirName : 'media',
  8032. clickFn : function(url, title) {
  8033. if (self.dialogs.length > 1) {
  8034. K('[name="url"]', div).val(url);
  8035. if (self.afterSelectFile) {
  8036. self.afterSelectFile.call(self, url);
  8037. }
  8038. self.hideDialog();
  8039. }
  8040. }
  8041. });
  8042. });
  8043. */
  8044. });
  8045. viewCoverServerBtn.click(function(e) {
  8046. var clickFn = function(url, title, id) {
  8047. K('[name="cover_url"]', div).val(url);
  8048. if (self.afterSelectFile) {
  8049. self.afterSelectFile.call(self, url);
  8050. }
  8051. };
  8052. var cur = K('[name="cover_url"]', div).val();
  8053. editorShowUpload(cur, self.uploadJson.replace('save.kindeditor', 'view.files'), '图库', clickFn, this);
  8054. /*
  8055. self.loadPlugin('filemanager', function() {
  8056. self.plugin.filemanagerDialog({
  8057. viewType : 'LIST',
  8058. dirName : 'file',
  8059. clickFn : function(url, title) {
  8060. if (self.dialogs.length > 1) {
  8061. self.hideDialog();
  8062. }
  8063. }
  8064. });
  8065. });
  8066. */
  8067. });
  8068. } else {
  8069. viewServerBtn.hide();
  8070. viewCoverServerBtn.hide();
  8071. }
  8072. var img = self.plugin.getSelectedMedia();
  8073. if (img) {
  8074. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  8075. urlBox.val(attrs.src);
  8076. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  8077. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  8078. autostartBox[0].checked = (attrs.autostart === 'true');
  8079. }
  8080. urlBox[0].focus();
  8081. urlBox[0].select();
  8082. },
  8083. 'delete' : function() {
  8084. self.plugin.getSelectedMedia().remove();
  8085. self.addBookmark();
  8086. }
  8087. };
  8088. self.clickToolbar(name, self.plugin.media.edit);
  8089. });
  8090. /*******************************************************************************
  8091. * KindEditor - WYSIWYG HTML Editor for Internet
  8092. * Copyright (C) 2006-2011 kindsoft.net
  8093. *
  8094. * @author Roddy <luolonghao@gmail.com>
  8095. * @site http://www.kindsoft.net/
  8096. * @licence http://www.kindsoft.net/license.php
  8097. *******************************************************************************/
  8098. (function(K) {
  8099. function KSWFUpload(options) {
  8100. this.init(options);
  8101. }
  8102. K.extend(KSWFUpload, {
  8103. init : function(options) {
  8104. var self = this;
  8105. options.afterError = options.afterError || function(str) {
  8106. alert(str);
  8107. };
  8108. self.options = options;
  8109. self.progressbars = {};
  8110. self.div = K(options.container).html([
  8111. '<div class="ke-swfupload">',
  8112. '<div class="ke-swfupload-top">',
  8113. '<div class="ke-inline-block ke-swfupload-button">',
  8114. '<input type="button" value="Browse" />',
  8115. '</div>',
  8116. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  8117. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  8118. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  8119. '</span>',
  8120. '</div>',
  8121. '<div class="ke-swfupload-body"></div>',
  8122. '</div>'
  8123. ].join(''));
  8124. self.bodyDiv = K('.ke-swfupload-body', self.div);
  8125. function showError(itemDiv, msg) {
  8126. K('.ke-status > div', itemDiv).hide();
  8127. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  8128. }
  8129. var settings = {
  8130. debug : false,
  8131. upload_url : options.uploadUrl,
  8132. flash_url : options.flashUrl,
  8133. file_post_name : options.filePostName,
  8134. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  8135. button_image_url: options.buttonImageUrl,
  8136. button_width: options.buttonWidth,
  8137. button_height: options.buttonHeight,
  8138. button_cursor : SWFUpload.CURSOR.HAND,
  8139. file_types : options.fileTypes,
  8140. file_types_description : options.fileTypesDesc,
  8141. file_upload_limit : options.fileUploadLimit,
  8142. file_size_limit : options.fileSizeLimit,
  8143. post_params : options.postParams,
  8144. file_queued_handler : function(file) {
  8145. file.url = self.options.fileIconUrl;
  8146. self.appendFile(file);
  8147. },
  8148. file_queue_error_handler : function(file, errorCode, message) {
  8149. var errorName = '';
  8150. switch (errorCode) {
  8151. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  8152. errorName = options.queueLimitExceeded;
  8153. break;
  8154. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  8155. errorName = options.fileExceedsSizeLimit;
  8156. break;
  8157. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  8158. errorName = options.zeroByteFile;
  8159. break;
  8160. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  8161. errorName = options.invalidFiletype;
  8162. break;
  8163. default:
  8164. errorName = options.unknownError;
  8165. break;
  8166. }
  8167. K.DEBUG && alert(errorName);
  8168. },
  8169. upload_start_handler : function(file) {
  8170. var self = this;
  8171. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  8172. K('.ke-status > div', itemDiv).hide();
  8173. K('.ke-progressbar', itemDiv).show();
  8174. },
  8175. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  8176. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  8177. var progressbar = self.progressbars[file.id];
  8178. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  8179. progressbar.percent.html(percent + '%');
  8180. },
  8181. upload_error_handler : function(file, errorCode, message) {
  8182. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  8183. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  8184. showError(itemDiv, self.options.errorMessage);
  8185. }
  8186. },
  8187. upload_success_handler : function(file, serverData) {
  8188. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  8189. var data = {};
  8190. try {
  8191. data = K.json(serverData);
  8192. } catch (e) {
  8193. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  8194. }
  8195. if (data.error !== 0) {
  8196. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  8197. return;
  8198. }
  8199. file.url = data.url;
  8200. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  8201. K('.ke-status > div', itemDiv).hide();
  8202. }
  8203. };
  8204. self.swfu = new SWFUpload(settings);
  8205. K('.ke-swfupload-startupload input', self.div).click(function() {
  8206. self.swfu.startUpload();
  8207. });
  8208. },
  8209. getUrlList : function() {
  8210. var list = [];
  8211. K('.ke-img', self.bodyDiv).each(function() {
  8212. var img = K(this);
  8213. var status = img.attr('data-status');
  8214. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  8215. list.push(img.data('data'));
  8216. }
  8217. });
  8218. return list;
  8219. },
  8220. removeFile : function(fileId) {
  8221. var self = this;
  8222. self.swfu.cancelUpload(fileId);
  8223. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  8224. K('.ke-photo', itemDiv).unbind();
  8225. K('.ke-delete', itemDiv).unbind();
  8226. itemDiv.remove();
  8227. },
  8228. removeFiles : function() {
  8229. var self = this;
  8230. K('.ke-item', self.bodyDiv).each(function() {
  8231. self.removeFile(K(this).attr('data-id'));
  8232. });
  8233. },
  8234. appendFile : function(file) {
  8235. var self = this;
  8236. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  8237. self.bodyDiv.append(itemDiv);
  8238. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  8239. .mouseover(function(e) {
  8240. K(this).addClass('ke-on');
  8241. })
  8242. .mouseout(function(e) {
  8243. K(this).removeClass('ke-on');
  8244. });
  8245. itemDiv.append(photoDiv);
  8246. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  8247. photoDiv.append(img);
  8248. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  8249. self.removeFile(file.id);
  8250. });
  8251. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  8252. K(['<div class="ke-progressbar">',
  8253. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  8254. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  8255. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  8256. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  8257. self.progressbars[file.id] = {
  8258. bar : K('.ke-progressbar-bar-inner', photoDiv),
  8259. percent : K('.ke-progressbar-percent', photoDiv)
  8260. };
  8261. },
  8262. remove : function() {
  8263. this.removeFiles();
  8264. this.swfu.destroy();
  8265. this.div.html('');
  8266. }
  8267. });
  8268. K.swfupload = function(element, options) {
  8269. return new KSWFUpload(element, options);
  8270. };
  8271. })(KindEditor);
  8272. KindEditor.plugin('multiimage', function(K) {
  8273. var self = this, name = 'multiimage',
  8274. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  8275. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  8276. imgPath = self.pluginsPath + 'multiimage/images/',
  8277. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  8278. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  8279. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  8280. filePostName = K.undef(self.filePostName, 'imgFile'),
  8281. lang = self.lang(name + '.');
  8282. self.plugin.multiImageDialog = function(options) {
  8283. var clickFn = options.clickFn,
  8284. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  8285. uploadDesc = '';
  8286. var html = [
  8287. '<div style="padding:20px;">',
  8288. '<div class="swfupload">',
  8289. '</div>',
  8290. '</div>'
  8291. ].join('');
  8292. var dialog = self.createDialog({
  8293. name : name,
  8294. width : 650,
  8295. height : 510,
  8296. title : self.lang(name),
  8297. body : html,
  8298. previewBtn : {
  8299. name : lang.insertAll,
  8300. click : function(e) {
  8301. clickFn.call(self, swfupload.getUrlList());
  8302. }
  8303. },
  8304. yesBtn : {
  8305. name : lang.clearAll,
  8306. click : function(e) {
  8307. swfupload.removeFiles();
  8308. }
  8309. },
  8310. beforeRemove : function() {
  8311. if (!K.IE || K.V <= 8) {
  8312. swfupload.remove();
  8313. }
  8314. }
  8315. }),
  8316. div = dialog.div;
  8317. var swfupload = K.swfupload({
  8318. container : K('.swfupload', div),
  8319. buttonImageUrl : imgPath + (self.langType == 'zh-CN' ? 'select-files-zh-CN.png' : 'select-files-en.png'),
  8320. buttonWidth : self.langType == 'zh-CN' ? 72 : 88,
  8321. buttonHeight : 23,
  8322. fileIconUrl : imgPath + 'image.png',
  8323. uploadDesc : uploadDesc,
  8324. startButtonValue : lang.startUpload,
  8325. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  8326. //uploadMediaUrl : K.addParam(uploadMediaUrl, 'dir=media'),
  8327. flashUrl : imgPath + 'swfupload.swf',
  8328. filePostName : filePostName,
  8329. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8330. fileTypesDesc : 'Image Files',
  8331. fileUploadLimit : imageUploadLimit,
  8332. fileSizeLimit : imageSizeLimit,
  8333. postParams : K.undef(self.extraFileUploadParams, {}),
  8334. queueLimitExceeded : lang.queueLimitExceeded,
  8335. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  8336. zeroByteFile : lang.zeroByteFile,
  8337. invalidFiletype : lang.invalidFiletype,
  8338. unknownError : lang.unknownError,
  8339. pendingMessage : lang.pending,
  8340. errorMessage : lang.uploadError,
  8341. afterError : function(html) {
  8342. self.errorDialog(html);
  8343. }
  8344. });
  8345. return dialog;
  8346. };
  8347. self.clickToolbar(name, function() {
  8348. self.plugin.multiImageDialog({
  8349. clickFn : function (urlList) {
  8350. if (urlList.length === 0) {
  8351. return;
  8352. }
  8353. K.each(urlList, function(i, data) {
  8354. if (self.afterUpload) {
  8355. self.afterUpload.call(self, data.url, data, 'multiimage');
  8356. }
  8357. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8358. });
  8359. setTimeout(function() {
  8360. self.hideDialog().focus();
  8361. }, 0);
  8362. }
  8363. });
  8364. });
  8365. });
  8366. /* ******************* */
  8367. /* Constructor & Init */
  8368. /* ******************* */
  8369. (function() {
  8370. window.SWFUpload = function (settings) {
  8371. this.initSWFUpload(settings);
  8372. };
  8373. SWFUpload.prototype.initSWFUpload = function (settings) {
  8374. try {
  8375. this.customSettings = {};
  8376. this.settings = settings;
  8377. this.eventQueue = [];
  8378. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8379. this.movieElement = null;
  8380. SWFUpload.instances[this.movieName] = this;
  8381. this.initSettings();
  8382. this.loadFlash();
  8383. this.displayDebugInfo();
  8384. } catch (ex) {
  8385. delete SWFUpload.instances[this.movieName];
  8386. throw ex;
  8387. }
  8388. };
  8389. /* *************** */
  8390. /* Static Members */
  8391. /* *************** */
  8392. SWFUpload.instances = {};
  8393. SWFUpload.movieCount = 0;
  8394. SWFUpload.version = "2.2.0 2009-03-25";
  8395. SWFUpload.QUEUE_ERROR = {
  8396. QUEUE_LIMIT_EXCEEDED : -100,
  8397. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8398. ZERO_BYTE_FILE : -120,
  8399. INVALID_FILETYPE : -130
  8400. };
  8401. SWFUpload.UPLOAD_ERROR = {
  8402. HTTP_ERROR : -200,
  8403. MISSING_UPLOAD_URL : -210,
  8404. IO_ERROR : -220,
  8405. SECURITY_ERROR : -230,
  8406. UPLOAD_LIMIT_EXCEEDED : -240,
  8407. UPLOAD_FAILED : -250,
  8408. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8409. FILE_VALIDATION_FAILED : -270,
  8410. FILE_CANCELLED : -280,
  8411. UPLOAD_STOPPED : -290
  8412. };
  8413. SWFUpload.FILE_STATUS = {
  8414. QUEUED : -1,
  8415. IN_PROGRESS : -2,
  8416. ERROR : -3,
  8417. COMPLETE : -4,
  8418. CANCELLED : -5
  8419. };
  8420. SWFUpload.BUTTON_ACTION = {
  8421. SELECT_FILE : -100,
  8422. SELECT_FILES : -110,
  8423. START_UPLOAD : -120
  8424. };
  8425. SWFUpload.CURSOR = {
  8426. ARROW : -1,
  8427. HAND : -2
  8428. };
  8429. SWFUpload.WINDOW_MODE = {
  8430. WINDOW : "window",
  8431. TRANSPARENT : "transparent",
  8432. OPAQUE : "opaque"
  8433. };
  8434. SWFUpload.completeURL = function(url) {
  8435. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8436. return url;
  8437. }
  8438. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8439. var indexSlash = window.location.pathname.lastIndexOf("/");
  8440. var path;
  8441. if (indexSlash <= 0) {
  8442. path = "/";
  8443. } else {
  8444. path = window.location.pathname.substr(0, indexSlash) + "/";
  8445. }
  8446. return /*currentURL +*/ path + url;
  8447. };
  8448. /* ******************** */
  8449. /* Instance Members */
  8450. /* ******************** */
  8451. SWFUpload.prototype.initSettings = function () {
  8452. this.ensureDefault = function (settingName, defaultValue) {
  8453. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8454. };
  8455. this.ensureDefault("upload_url", "");
  8456. this.ensureDefault("preserve_relative_urls", false);
  8457. this.ensureDefault("file_post_name", "Filedata");
  8458. this.ensureDefault("post_params", {});
  8459. this.ensureDefault("use_query_string", false);
  8460. this.ensureDefault("requeue_on_error", false);
  8461. this.ensureDefault("http_success", []);
  8462. this.ensureDefault("assume_success_timeout", 0);
  8463. this.ensureDefault("file_types", "*.*");
  8464. this.ensureDefault("file_types_description", "All Files");
  8465. this.ensureDefault("file_size_limit", 0);
  8466. this.ensureDefault("file_upload_limit", 0);
  8467. this.ensureDefault("file_queue_limit", 0);
  8468. this.ensureDefault("flash_url", "swfupload.swf");
  8469. this.ensureDefault("prevent_swf_caching", true);
  8470. this.ensureDefault("button_image_url", "");
  8471. this.ensureDefault("button_width", 1);
  8472. this.ensureDefault("button_height", 1);
  8473. this.ensureDefault("button_text", "");
  8474. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8475. this.ensureDefault("button_text_top_padding", 0);
  8476. this.ensureDefault("button_text_left_padding", 0);
  8477. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8478. this.ensureDefault("button_disabled", false);
  8479. this.ensureDefault("button_placeholder_id", "");
  8480. this.ensureDefault("button_placeholder", null);
  8481. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8482. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8483. this.ensureDefault("debug", false);
  8484. this.settings.debug_enabled = this.settings.debug;
  8485. this.settings.return_upload_start_handler = this.returnUploadStart;
  8486. this.ensureDefault("swfupload_loaded_handler", null);
  8487. this.ensureDefault("file_dialog_start_handler", null);
  8488. this.ensureDefault("file_queued_handler", null);
  8489. this.ensureDefault("file_queue_error_handler", null);
  8490. this.ensureDefault("file_dialog_complete_handler", null);
  8491. this.ensureDefault("upload_start_handler", null);
  8492. this.ensureDefault("upload_progress_handler", null);
  8493. this.ensureDefault("upload_error_handler", null);
  8494. this.ensureDefault("upload_success_handler", null);
  8495. this.ensureDefault("upload_complete_handler", null);
  8496. this.ensureDefault("debug_handler", this.debugMessage);
  8497. this.ensureDefault("custom_settings", {});
  8498. this.customSettings = this.settings.custom_settings;
  8499. if (!!this.settings.prevent_swf_caching) {
  8500. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8501. }
  8502. if (!this.settings.preserve_relative_urls) {
  8503. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8504. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8505. }
  8506. delete this.ensureDefault;
  8507. };
  8508. SWFUpload.prototype.loadFlash = function () {
  8509. var targetElement, tempParent;
  8510. if (document.getElementById(this.movieName) !== null) {
  8511. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8512. }
  8513. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8514. if (targetElement == undefined) {
  8515. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8516. }
  8517. tempParent = document.createElement("div");
  8518. tempParent.innerHTML = this.getFlashHTML();
  8519. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8520. if (window[this.movieName] == undefined) {
  8521. window[this.movieName] = this.getMovieElement();
  8522. }
  8523. };
  8524. SWFUpload.prototype.getFlashHTML = function () {
  8525. var classid = '';
  8526. if (KindEditor.IE && KindEditor.V > 8) {
  8527. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8528. }
  8529. 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">',
  8530. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8531. '<param name="movie" value="', this.settings.flash_url, '" />',
  8532. '<param name="quality" value="high" />',
  8533. '<param name="menu" value="false" />',
  8534. '<param name="allowScriptAccess" value="always" />',
  8535. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8536. '</object>'].join("");
  8537. };
  8538. SWFUpload.prototype.getFlashVars = function () {
  8539. var paramString = this.buildParamString();
  8540. var httpSuccessString = this.settings.http_success.join(",");
  8541. return ["movieName=", encodeURIComponent(this.movieName),
  8542. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8543. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8544. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8545. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8546. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8547. "&amp;params=", encodeURIComponent(paramString),
  8548. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8549. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8550. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8551. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8552. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8553. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8554. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8555. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8556. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8557. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8558. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8559. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8560. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8561. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8562. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8563. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8564. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8565. ].join("");
  8566. };
  8567. SWFUpload.prototype.getMovieElement = function () {
  8568. if (this.movieElement == undefined) {
  8569. this.movieElement = document.getElementById(this.movieName);
  8570. }
  8571. if (this.movieElement === null) {
  8572. throw "Could not find Flash element";
  8573. }
  8574. return this.movieElement;
  8575. };
  8576. SWFUpload.prototype.buildParamString = function () {
  8577. var postParams = this.settings.post_params;
  8578. var paramStringPairs = [];
  8579. if (typeof(postParams) === "object") {
  8580. for (var name in postParams) {
  8581. if (postParams.hasOwnProperty(name)) {
  8582. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8583. }
  8584. }
  8585. }
  8586. return paramStringPairs.join("&amp;");
  8587. };
  8588. SWFUpload.prototype.destroy = function () {
  8589. try {
  8590. this.cancelUpload(null, false);
  8591. var movieElement = null;
  8592. movieElement = this.getMovieElement();
  8593. if (movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8594. for (var i in movieElement) {
  8595. try {
  8596. if (typeof(movieElement[i]) === "function") {
  8597. movieElement[i] = null;
  8598. }
  8599. } catch (ex1) {}
  8600. }
  8601. try {
  8602. movieElement.parentNode.removeChild(movieElement);
  8603. } catch (ex) {}
  8604. }
  8605. window[this.movieName] = null;
  8606. SWFUpload.instances[this.movieName] = null;
  8607. delete SWFUpload.instances[this.movieName];
  8608. this.movieElement = null;
  8609. this.settings = null;
  8610. this.customSettings = null;
  8611. this.eventQueue = null;
  8612. this.movieName = null;
  8613. return true;
  8614. } catch (ex2) {
  8615. return false;
  8616. }
  8617. };
  8618. SWFUpload.prototype.displayDebugInfo = function () {
  8619. this.debug(
  8620. [
  8621. "---SWFUpload Instance Info---\n",
  8622. "Version: ", SWFUpload.version, "\n",
  8623. "Movie Name: ", this.movieName, "\n",
  8624. "Settings:\n",
  8625. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8626. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8627. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8628. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8629. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8630. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8631. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8632. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8633. "\t", "file_types: ", this.settings.file_types, "\n",
  8634. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8635. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8636. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8637. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8638. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8639. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8640. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8641. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8642. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8643. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8644. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8645. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8646. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8647. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8648. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8649. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8650. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8651. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8652. "Event Handlers:\n",
  8653. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8654. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8655. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8656. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8657. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8658. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8659. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8660. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8661. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8662. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8663. ].join("")
  8664. );
  8665. };
  8666. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8667. the maintain v2 API compatibility
  8668. */
  8669. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8670. if (value == undefined) {
  8671. return (this.settings[name] = default_value);
  8672. } else {
  8673. return (this.settings[name] = value);
  8674. }
  8675. };
  8676. SWFUpload.prototype.getSetting = function (name) {
  8677. if (this.settings[name] != undefined) {
  8678. return this.settings[name];
  8679. }
  8680. return "";
  8681. };
  8682. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8683. argumentArray = argumentArray || [];
  8684. var movieElement = this.getMovieElement();
  8685. var returnValue, returnString;
  8686. try {
  8687. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8688. returnValue = eval(returnString);
  8689. } catch (ex) {
  8690. throw "Call to " + functionName + " failed";
  8691. }
  8692. if (returnValue != undefined && typeof returnValue.post === "object") {
  8693. returnValue = this.unescapeFilePostParams(returnValue);
  8694. }
  8695. return returnValue;
  8696. };
  8697. /* *****************************
  8698. -- Flash control methods --
  8699. Your UI should use these
  8700. to operate SWFUpload
  8701. ***************************** */
  8702. SWFUpload.prototype.selectFile = function () {
  8703. this.callFlash("SelectFile");
  8704. };
  8705. SWFUpload.prototype.selectFiles = function () {
  8706. this.callFlash("SelectFiles");
  8707. };
  8708. SWFUpload.prototype.startUpload = function (fileID) {
  8709. this.callFlash("StartUpload", [fileID]);
  8710. };
  8711. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8712. if (triggerErrorEvent !== false) {
  8713. triggerErrorEvent = true;
  8714. }
  8715. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8716. };
  8717. SWFUpload.prototype.stopUpload = function () {
  8718. this.callFlash("StopUpload");
  8719. };
  8720. /* ************************
  8721. * Settings methods
  8722. * These methods change the SWFUpload settings.
  8723. * SWFUpload settings should not be changed directly on the settings object
  8724. * since many of the settings need to be passed to Flash in order to take
  8725. * effect.
  8726. * *********************** */
  8727. SWFUpload.prototype.getStats = function () {
  8728. return this.callFlash("GetStats");
  8729. };
  8730. SWFUpload.prototype.setStats = function (statsObject) {
  8731. this.callFlash("SetStats", [statsObject]);
  8732. };
  8733. SWFUpload.prototype.getFile = function (fileID) {
  8734. if (typeof(fileID) === "number") {
  8735. return this.callFlash("GetFileByIndex", [fileID]);
  8736. } else {
  8737. return this.callFlash("GetFile", [fileID]);
  8738. }
  8739. };
  8740. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8741. return this.callFlash("AddFileParam", [fileID, name, value]);
  8742. };
  8743. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8744. this.callFlash("RemoveFileParam", [fileID, name]);
  8745. };
  8746. SWFUpload.prototype.setUploadURL = function (url) {
  8747. this.settings.upload_url = url.toString();
  8748. this.callFlash("SetUploadURL", [url]);
  8749. };
  8750. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8751. this.settings.post_params = paramsObject;
  8752. this.callFlash("SetPostParams", [paramsObject]);
  8753. };
  8754. SWFUpload.prototype.addPostParam = function (name, value) {
  8755. this.settings.post_params[name] = value;
  8756. this.callFlash("SetPostParams", [this.settings.post_params]);
  8757. };
  8758. SWFUpload.prototype.removePostParam = function (name) {
  8759. delete this.settings.post_params[name];
  8760. this.callFlash("SetPostParams", [this.settings.post_params]);
  8761. };
  8762. SWFUpload.prototype.setFileTypes = function (types, description) {
  8763. this.settings.file_types = types;
  8764. this.settings.file_types_description = description;
  8765. this.callFlash("SetFileTypes", [types, description]);
  8766. };
  8767. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8768. this.settings.file_size_limit = fileSizeLimit;
  8769. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8770. };
  8771. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8772. this.settings.file_upload_limit = fileUploadLimit;
  8773. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8774. };
  8775. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8776. this.settings.file_queue_limit = fileQueueLimit;
  8777. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8778. };
  8779. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8780. this.settings.file_post_name = filePostName;
  8781. this.callFlash("SetFilePostName", [filePostName]);
  8782. };
  8783. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8784. this.settings.use_query_string = useQueryString;
  8785. this.callFlash("SetUseQueryString", [useQueryString]);
  8786. };
  8787. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8788. this.settings.requeue_on_error = requeueOnError;
  8789. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8790. };
  8791. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8792. if (typeof http_status_codes === "string") {
  8793. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8794. }
  8795. this.settings.http_success = http_status_codes;
  8796. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8797. };
  8798. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8799. this.settings.assume_success_timeout = timeout_seconds;
  8800. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8801. };
  8802. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8803. this.settings.debug_enabled = debugEnabled;
  8804. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8805. };
  8806. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8807. if (buttonImageURL == undefined) {
  8808. buttonImageURL = "";
  8809. }
  8810. this.settings.button_image_url = buttonImageURL;
  8811. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8812. };
  8813. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8814. this.settings.button_width = width;
  8815. this.settings.button_height = height;
  8816. var movie = this.getMovieElement();
  8817. if (movie != undefined) {
  8818. movie.style.width = width + "px";
  8819. movie.style.height = height + "px";
  8820. }
  8821. this.callFlash("SetButtonDimensions", [width, height]);
  8822. };
  8823. SWFUpload.prototype.setButtonText = function (html) {
  8824. this.settings.button_text = html;
  8825. this.callFlash("SetButtonText", [html]);
  8826. };
  8827. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8828. this.settings.button_text_top_padding = top;
  8829. this.settings.button_text_left_padding = left;
  8830. this.callFlash("SetButtonTextPadding", [left, top]);
  8831. };
  8832. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8833. this.settings.button_text_style = css;
  8834. this.callFlash("SetButtonTextStyle", [css]);
  8835. };
  8836. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8837. this.settings.button_disabled = isDisabled;
  8838. this.callFlash("SetButtonDisabled", [isDisabled]);
  8839. };
  8840. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8841. this.settings.button_action = buttonAction;
  8842. this.callFlash("SetButtonAction", [buttonAction]);
  8843. };
  8844. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8845. this.settings.button_cursor = cursor;
  8846. this.callFlash("SetButtonCursor", [cursor]);
  8847. };
  8848. /* *******************************
  8849. Flash Event Interfaces
  8850. These functions are used by Flash to trigger the various
  8851. events.
  8852. All these functions a Private.
  8853. Because the ExternalInterface library is buggy the event calls
  8854. are added to a queue and the queue then executed by a setTimeout.
  8855. This ensures that events are executed in a determinate order and that
  8856. the ExternalInterface bugs are avoided.
  8857. ******************************* */
  8858. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8859. if (argumentArray == undefined) {
  8860. argumentArray = [];
  8861. } else if (!(argumentArray instanceof Array)) {
  8862. argumentArray = [argumentArray];
  8863. }
  8864. var self = this;
  8865. if (typeof this.settings[handlerName] === "function") {
  8866. this.eventQueue.push(function () {
  8867. this.settings[handlerName].apply(this, argumentArray);
  8868. });
  8869. setTimeout(function () {
  8870. self.executeNextEvent();
  8871. }, 0);
  8872. } else if (this.settings[handlerName] !== null) {
  8873. throw "Event handler " + handlerName + " is unknown or is not a function";
  8874. }
  8875. };
  8876. SWFUpload.prototype.executeNextEvent = function () {
  8877. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8878. if (typeof(f) === "function") {
  8879. f.apply(this);
  8880. }
  8881. };
  8882. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8883. var reg = /[$]([0-9a-f]{4})/i;
  8884. var unescapedPost = {};
  8885. var uk;
  8886. if (file != undefined) {
  8887. for (var k in file.post) {
  8888. if (file.post.hasOwnProperty(k)) {
  8889. uk = k;
  8890. var match;
  8891. while ((match = reg.exec(uk)) !== null) {
  8892. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8893. }
  8894. unescapedPost[uk] = file.post[k];
  8895. }
  8896. }
  8897. file.post = unescapedPost;
  8898. }
  8899. return file;
  8900. };
  8901. SWFUpload.prototype.testExternalInterface = function () {
  8902. try {
  8903. return this.callFlash("TestExternalInterface");
  8904. } catch (ex) {
  8905. return false;
  8906. }
  8907. };
  8908. SWFUpload.prototype.flashReady = function () {
  8909. var movieElement = this.getMovieElement();
  8910. if (!movieElement) {
  8911. this.debug("Flash called back ready but the flash movie can't be found.");
  8912. return;
  8913. }
  8914. this.cleanUp(movieElement);
  8915. this.queueEvent("swfupload_loaded_handler");
  8916. };
  8917. SWFUpload.prototype.cleanUp = function (movieElement) {
  8918. try {
  8919. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8920. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8921. for (var key in movieElement) {
  8922. try {
  8923. if (typeof(movieElement[key]) === "function") {
  8924. movieElement[key] = null;
  8925. }
  8926. } catch (ex) {
  8927. }
  8928. }
  8929. }
  8930. } catch (ex1) {
  8931. }
  8932. window["__flash__removeCallback"] = function (instance, name) {
  8933. try {
  8934. if (instance) {
  8935. instance[name] = null;
  8936. }
  8937. } catch (flashEx) {
  8938. }
  8939. };
  8940. };
  8941. /* This is a chance to do something before the browse window opens */
  8942. SWFUpload.prototype.fileDialogStart = function () {
  8943. this.queueEvent("file_dialog_start_handler");
  8944. };
  8945. /* Called when a file is successfully added to the queue. */
  8946. SWFUpload.prototype.fileQueued = function (file) {
  8947. file = this.unescapeFilePostParams(file);
  8948. this.queueEvent("file_queued_handler", file);
  8949. };
  8950. /* Handle errors that occur when an attempt to queue a file fails. */
  8951. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  8952. file = this.unescapeFilePostParams(file);
  8953. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  8954. };
  8955. /* Called after the file dialog has closed and the selected files have been queued.
  8956. You could call startUpload here if you want the queued files to begin uploading immediately. */
  8957. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  8958. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  8959. };
  8960. SWFUpload.prototype.uploadStart = function (file) {
  8961. file = this.unescapeFilePostParams(file);
  8962. this.queueEvent("return_upload_start_handler", file);
  8963. };
  8964. SWFUpload.prototype.returnUploadStart = function (file) {
  8965. var returnValue;
  8966. if (typeof this.settings.upload_start_handler === "function") {
  8967. file = this.unescapeFilePostParams(file);
  8968. returnValue = this.settings.upload_start_handler.call(this, file);
  8969. } else if (this.settings.upload_start_handler != undefined) {
  8970. throw "upload_start_handler must be a function";
  8971. }
  8972. if (returnValue === undefined) {
  8973. returnValue = true;
  8974. }
  8975. returnValue = !!returnValue;
  8976. this.callFlash("ReturnUploadStart", [returnValue]);
  8977. };
  8978. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  8979. file = this.unescapeFilePostParams(file);
  8980. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  8981. };
  8982. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  8983. file = this.unescapeFilePostParams(file);
  8984. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  8985. };
  8986. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  8987. file = this.unescapeFilePostParams(file);
  8988. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  8989. };
  8990. SWFUpload.prototype.uploadComplete = function (file) {
  8991. file = this.unescapeFilePostParams(file);
  8992. this.queueEvent("upload_complete_handler", file);
  8993. };
  8994. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  8995. internal debug console. You can override this event and have messages written where you want. */
  8996. SWFUpload.prototype.debug = function (message) {
  8997. this.queueEvent("debug_handler", message);
  8998. };
  8999. /* **********************************
  9000. Debug Console
  9001. The debug console is a self contained, in page location
  9002. for debug message to be sent. The Debug Console adds
  9003. itself to the body if necessary.
  9004. The console is automatically scrolled as messages appear.
  9005. If you are using your own debug handler or when you deploy to production and
  9006. have debug disabled you can remove these functions to reduce the file size
  9007. and complexity.
  9008. ********************************** */
  9009. SWFUpload.prototype.debugMessage = function (message) {
  9010. if (this.settings.debug) {
  9011. var exceptionMessage, exceptionValues = [];
  9012. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  9013. for (var key in message) {
  9014. if (message.hasOwnProperty(key)) {
  9015. exceptionValues.push(key + ": " + message[key]);
  9016. }
  9017. }
  9018. exceptionMessage = exceptionValues.join("\n") || "";
  9019. exceptionValues = exceptionMessage.split("\n");
  9020. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  9021. SWFUpload.Console.writeLine(exceptionMessage);
  9022. } else {
  9023. SWFUpload.Console.writeLine(message);
  9024. }
  9025. }
  9026. };
  9027. SWFUpload.Console = {};
  9028. SWFUpload.Console.writeLine = function (message) {
  9029. var console, documentForm;
  9030. try {
  9031. console = document.getElementById("SWFUpload_Console");
  9032. if (!console) {
  9033. documentForm = document.createElement("form");
  9034. document.getElementsByTagName("body")[0].appendChild(documentForm);
  9035. console = document.createElement("textarea");
  9036. console.id = "SWFUpload_Console";
  9037. console.style.fontFamily = "monospace";
  9038. console.setAttribute("wrap", "off");
  9039. console.wrap = "off";
  9040. console.style.overflow = "auto";
  9041. console.style.width = "700px";
  9042. console.style.height = "350px";
  9043. console.style.margin = "5px";
  9044. documentForm.appendChild(console);
  9045. }
  9046. console.value += message + "\n";
  9047. console.scrollTop = console.scrollHeight - console.clientHeight;
  9048. } catch (ex) {
  9049. alert("Exception: " + ex.name + " Message: " + ex.message);
  9050. }
  9051. };
  9052. })();
  9053. (function() {
  9054. /*
  9055. Queue Plug-in
  9056. Features:
  9057. *Adds a cancelQueue() method for cancelling the entire queue.
  9058. *All queued files are uploaded when startUpload() is called.
  9059. *If false is returned from uploadComplete then the queue upload is stopped.
  9060. If false is not returned (strict comparison) then the queue upload is continued.
  9061. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  9062. Set the event handler with the queue_complete_handler setting.
  9063. */
  9064. if (typeof(SWFUpload) === "function") {
  9065. SWFUpload.queue = {};
  9066. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  9067. return function () {
  9068. if (typeof(oldInitSettings) === "function") {
  9069. oldInitSettings.call(this);
  9070. }
  9071. this.queueSettings = {};
  9072. this.queueSettings.queue_cancelled_flag = false;
  9073. this.queueSettings.queue_upload_count = 0;
  9074. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  9075. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  9076. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  9077. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  9078. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  9079. };
  9080. })(SWFUpload.prototype.initSettings);
  9081. SWFUpload.prototype.startUpload = function (fileID) {
  9082. this.queueSettings.queue_cancelled_flag = false;
  9083. this.callFlash("StartUpload", [fileID]);
  9084. };
  9085. SWFUpload.prototype.cancelQueue = function () {
  9086. this.queueSettings.queue_cancelled_flag = true;
  9087. this.stopUpload();
  9088. var stats = this.getStats();
  9089. while (stats.files_queued > 0) {
  9090. this.cancelUpload();
  9091. stats = this.getStats();
  9092. }
  9093. };
  9094. SWFUpload.queue.uploadStartHandler = function (file) {
  9095. var returnValue;
  9096. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  9097. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  9098. }
  9099. returnValue = (returnValue === false) ? false : true;
  9100. this.queueSettings.queue_cancelled_flag = !returnValue;
  9101. return returnValue;
  9102. };
  9103. SWFUpload.queue.uploadCompleteHandler = function (file) {
  9104. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  9105. var continueUpload;
  9106. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  9107. this.queueSettings.queue_upload_count++;
  9108. }
  9109. if (typeof(user_upload_complete_handler) === "function") {
  9110. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  9111. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  9112. continueUpload = false;
  9113. } else {
  9114. continueUpload = true;
  9115. }
  9116. if (continueUpload) {
  9117. var stats = this.getStats();
  9118. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  9119. this.startUpload();
  9120. } else if (this.queueSettings.queue_cancelled_flag === false) {
  9121. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  9122. this.queueSettings.queue_upload_count = 0;
  9123. } else {
  9124. this.queueSettings.queue_cancelled_flag = false;
  9125. this.queueSettings.queue_upload_count = 0;
  9126. }
  9127. }
  9128. };
  9129. }
  9130. })();
  9131. /*******************************************************************************
  9132. * KindEditor - WYSIWYG HTML Editor for Internet
  9133. * Copyright (C) 2006-2011 kindsoft.net
  9134. *
  9135. * @author Roddy <luolonghao@gmail.com>
  9136. * @site http://www.kindsoft.net/
  9137. * @licence http://www.kindsoft.net/license.php
  9138. *******************************************************************************/
  9139. KindEditor.plugin('pagebreak', function(K) {
  9140. var self = this;
  9141. var name = 'pagebreak';
  9142. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  9143. self.clickToolbar(name, function() {
  9144. var cmd = self.cmd, range = cmd.range;
  9145. self.focus();
  9146. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  9147. self.insertHtml(pagebreakHtml + tail);
  9148. if (tail !== '') {
  9149. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  9150. range.selectNodeContents(p[0]);
  9151. p.removeAttr('id');
  9152. cmd.select();
  9153. }
  9154. });
  9155. });
  9156. /*******************************************************************************
  9157. * KindEditor - WYSIWYG HTML Editor for Internet
  9158. * Copyright (C) 2006-2011 kindsoft.net
  9159. *
  9160. * @author Roddy <luolonghao@gmail.com>
  9161. * @site http://www.kindsoft.net/
  9162. * @licence http://www.kindsoft.net/license.php
  9163. *******************************************************************************/
  9164. KindEditor.plugin('plainpaste', function(K) {
  9165. var self = this, name = 'plainpaste';
  9166. self.clickToolbar(name, function() {
  9167. var lang = self.lang(name + '.'),
  9168. html = '<div style="padding:10px 20px;">' +
  9169. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9170. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  9171. '</div>',
  9172. dialog = self.createDialog({
  9173. name : name,
  9174. width : 450,
  9175. title : self.lang(name),
  9176. body : html,
  9177. yesBtn : {
  9178. name : self.lang('yes'),
  9179. click : function(e) {
  9180. var html = textarea.val();
  9181. html = K.escape(html);
  9182. html = html.replace(/ {2}/g, ' &nbsp;');
  9183. if (self.newlineTag == 'p') {
  9184. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  9185. } else {
  9186. html = html.replace(/\n/g, '<br />$&');
  9187. }
  9188. self.insertHtml(html).hideDialog().focus();
  9189. }
  9190. }
  9191. }),
  9192. textarea = K('textarea', dialog.div);
  9193. textarea[0].focus();
  9194. });
  9195. });
  9196. /*******************************************************************************
  9197. * KindEditor - WYSIWYG HTML Editor for Internet
  9198. * Copyright (C) 2006-2011 kindsoft.net
  9199. *
  9200. * @author Roddy <luolonghao@gmail.com>
  9201. * @site http://www.kindsoft.net/
  9202. * @licence http://www.kindsoft.net/license.php
  9203. *******************************************************************************/
  9204. KindEditor.plugin('preview', function(K) {
  9205. var self = this, name = 'preview', undefined;
  9206. self.clickToolbar(name, function() {
  9207. var lang = self.lang(name + '.'),
  9208. html = '<div style="padding:10px 20px;">' +
  9209. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  9210. '</div>',
  9211. dialog = self.createDialog({
  9212. name : name,
  9213. width : 750,
  9214. title : self.lang(name),
  9215. body : html
  9216. }),
  9217. iframe = K('iframe', dialog.div),
  9218. doc = K.iframeDoc(iframe);
  9219. doc.open();
  9220. doc.write(self.fullHtml());
  9221. doc.close();
  9222. K(doc.body).css('background-color', '#FFF');
  9223. iframe[0].contentWindow.focus();
  9224. });
  9225. });
  9226. /*******************************************************************************
  9227. * KindEditor - WYSIWYG HTML Editor for Internet
  9228. * Copyright (C) 2006-2011 kindsoft.net
  9229. *
  9230. * @author Roddy <luolonghao@gmail.com>
  9231. * @site http://www.kindsoft.net/
  9232. * @licence http://www.kindsoft.net/license.php
  9233. *******************************************************************************/
  9234. KindEditor.plugin('quickformat', function(K) {
  9235. var self = this, name = 'quickformat',
  9236. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  9237. function getFirstChild(knode) {
  9238. var child = knode.first();
  9239. while (child && child.first()) {
  9240. child = child.first();
  9241. }
  9242. return child;
  9243. }
  9244. self.clickToolbar(name, function() {
  9245. self.focus();
  9246. var doc = self.edit.doc,
  9247. range = self.cmd.range,
  9248. child = K(doc.body).first(), next,
  9249. nodeList = [], subList = [],
  9250. bookmark = range.createBookmark(true);
  9251. while(child) {
  9252. next = child.next();
  9253. var firstChild = getFirstChild(child);
  9254. if (!firstChild || firstChild.name != 'img') {
  9255. if (blockMap[child.name]) {
  9256. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  9257. child.css('text-indent', '2em');
  9258. } else {
  9259. subList.push(child);
  9260. }
  9261. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  9262. if (subList.length > 0) {
  9263. nodeList.push(subList);
  9264. }
  9265. subList = [];
  9266. }
  9267. }
  9268. child = next;
  9269. }
  9270. K.each(nodeList, function(i, subList) {
  9271. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  9272. subList[0].before(wrapper);
  9273. K.each(subList, function(i, knode) {
  9274. wrapper.append(knode);
  9275. });
  9276. });
  9277. range.moveToBookmark(bookmark);
  9278. self.addBookmark();
  9279. });
  9280. });
  9281. /*******************************************************************************
  9282. * KindEditor - WYSIWYG HTML Editor for Internet
  9283. * Copyright (C) 2006-2011 kindsoft.net
  9284. *
  9285. * @author Roddy <luolonghao@gmail.com>
  9286. * @site http://www.kindsoft.net/
  9287. * @licence http://www.kindsoft.net/license.php
  9288. *******************************************************************************/
  9289. KindEditor.plugin('table', function(K) {
  9290. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  9291. function _setColor(box, color) {
  9292. color = color.toUpperCase();
  9293. box.css('background-color', color);
  9294. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  9295. box.html(color);
  9296. }
  9297. var pickerList = [];
  9298. function _initColorPicker(dialogDiv, colorBox) {
  9299. colorBox.bind('click,mousedown', function(e){
  9300. e.stopPropagation();
  9301. });
  9302. function removePicker() {
  9303. K.each(pickerList, function() {
  9304. this.remove();
  9305. });
  9306. pickerList = [];
  9307. K(document).unbind('click,mousedown', removePicker);
  9308. dialogDiv.unbind('click,mousedown', removePicker);
  9309. }
  9310. colorBox.click(function(e) {
  9311. removePicker();
  9312. var box = K(this),
  9313. pos = box.pos();
  9314. var picker = K.colorpicker({
  9315. x : pos.x,
  9316. y : pos.y + box.height(),
  9317. z : 811214,
  9318. selectedColor : K(this).html(),
  9319. colors : self.colorTable,
  9320. noColor : self.lang('noColor'),
  9321. shadowMode : self.shadowMode,
  9322. click : function(color) {
  9323. _setColor(box, color);
  9324. removePicker();
  9325. }
  9326. });
  9327. pickerList.push(picker);
  9328. K(document).bind('click,mousedown', removePicker);
  9329. dialogDiv.bind('click,mousedown', removePicker);
  9330. });
  9331. }
  9332. function _getCellIndex(table, row, cell) {
  9333. var rowSpanCount = 0;
  9334. for (var i = 0, len = row.cells.length; i < len; i++) {
  9335. if (row.cells[i] == cell) {
  9336. break;
  9337. }
  9338. rowSpanCount += row.cells[i].rowSpan - 1;
  9339. }
  9340. return cell.cellIndex - rowSpanCount;
  9341. }
  9342. self.plugin.table = {
  9343. prop : function(isInsert) {
  9344. var html = [
  9345. '<div style="padding:20px;">',
  9346. '<div class="ke-dialog-row">',
  9347. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9348. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9349. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9350. '</div>',
  9351. '<div class="ke-dialog-row">',
  9352. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9353. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9354. '<select name="widthType">',
  9355. '<option value="%">' + lang.percent + '</option>',
  9356. '<option value="px">' + lang.px + '</option>',
  9357. '</select> &nbsp; ',
  9358. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9359. '<select name="heightType">',
  9360. '<option value="%">' + lang.percent + '</option>',
  9361. '<option value="px">' + lang.px + '</option>',
  9362. '</select>',
  9363. '</div>',
  9364. '<div class="ke-dialog-row">',
  9365. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9366. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9367. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9368. '</div>',
  9369. '<div class="ke-dialog-row">',
  9370. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9371. '<select id="keAlign" name="align">',
  9372. '<option value="">' + lang.alignDefault + '</option>',
  9373. '<option value="left">' + lang.alignLeft + '</option>',
  9374. '<option value="center">' + lang.alignCenter + '</option>',
  9375. '<option value="right">' + lang.alignRight + '</option>',
  9376. '</select>',
  9377. '</div>',
  9378. '<div class="ke-dialog-row">',
  9379. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9380. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9381. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9382. '</div>',
  9383. '<div class="ke-dialog-row">',
  9384. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9385. '<span class="ke-inline-block ke-input-color"></span>',
  9386. '</div>',
  9387. '</div>'
  9388. ].join('');
  9389. var bookmark = self.cmd.range.createBookmark();
  9390. var dialog = self.createDialog({
  9391. name : name,
  9392. width : 500,
  9393. title : self.lang(name),
  9394. body : html,
  9395. beforeRemove : function() {
  9396. colorBox.unbind();
  9397. },
  9398. yesBtn : {
  9399. name : self.lang('yes'),
  9400. click : function(e) {
  9401. var rows = rowsBox.val(),
  9402. cols = colsBox.val(),
  9403. width = widthBox.val(),
  9404. height = heightBox.val(),
  9405. widthType = widthTypeBox.val(),
  9406. heightType = heightTypeBox.val(),
  9407. padding = paddingBox.val(),
  9408. spacing = spacingBox.val(),
  9409. align = alignBox.val(),
  9410. border = borderBox.val(),
  9411. borderColor = K(colorBox[0]).html() || '',
  9412. bgColor = K(colorBox[1]).html() || '';
  9413. if (rows == 0 || !/^\d+$/.test(rows)) {
  9414. alert(self.lang('invalidRows'));
  9415. rowsBox[0].focus();
  9416. return;
  9417. }
  9418. if (cols == 0 || !/^\d+$/.test(cols)) {
  9419. alert(self.lang('invalidRows'));
  9420. colsBox[0].focus();
  9421. return;
  9422. }
  9423. if (!/^\d*$/.test(width)) {
  9424. alert(self.lang('invalidWidth'));
  9425. widthBox[0].focus();
  9426. return;
  9427. }
  9428. if (!/^\d*$/.test(height)) {
  9429. alert(self.lang('invalidHeight'));
  9430. heightBox[0].focus();
  9431. return;
  9432. }
  9433. if (!/^\d*$/.test(padding)) {
  9434. alert(self.lang('invalidPadding'));
  9435. paddingBox[0].focus();
  9436. return;
  9437. }
  9438. if (!/^\d*$/.test(spacing)) {
  9439. alert(self.lang('invalidSpacing'));
  9440. spacingBox[0].focus();
  9441. return;
  9442. }
  9443. if (!/^\d*$/.test(border)) {
  9444. alert(self.lang('invalidBorder'));
  9445. borderBox[0].focus();
  9446. return;
  9447. }
  9448. if (table) {
  9449. if (width !== '') {
  9450. table.width(width + widthType);
  9451. } else {
  9452. table.css('width', '');
  9453. }
  9454. if (table[0].width !== undefined) {
  9455. table.removeAttr('width');
  9456. }
  9457. if (height !== '') {
  9458. table.height(height + heightType);
  9459. } else {
  9460. table.css('height', '');
  9461. }
  9462. if (table[0].height !== undefined) {
  9463. table.removeAttr('height');
  9464. }
  9465. table.css('background-color', bgColor);
  9466. if (table[0].bgColor !== undefined) {
  9467. table.removeAttr('bgColor');
  9468. }
  9469. if (padding !== '') {
  9470. table[0].cellPadding = padding;
  9471. } else {
  9472. table.removeAttr('cellPadding');
  9473. }
  9474. if (spacing !== '') {
  9475. table[0].cellSpacing = spacing;
  9476. } else {
  9477. table.removeAttr('cellSpacing');
  9478. }
  9479. if (align !== '') {
  9480. table[0].align = align;
  9481. } else {
  9482. table.removeAttr('align');
  9483. }
  9484. if (border !== '') {
  9485. table.attr('border', border);
  9486. } else {
  9487. table.removeAttr('border');
  9488. }
  9489. if (border === '' || border === '0') {
  9490. table.addClass(zeroborder);
  9491. } else {
  9492. table.removeClass(zeroborder);
  9493. }
  9494. if (borderColor !== '') {
  9495. table.attr('borderColor', borderColor);
  9496. } else {
  9497. table.removeAttr('borderColor');
  9498. }
  9499. self.hideDialog().focus();
  9500. self.cmd.range.moveToBookmark(bookmark);
  9501. self.cmd.select();
  9502. self.addBookmark();
  9503. return;
  9504. }
  9505. var style = '';
  9506. if (width !== '') {
  9507. style += 'width:' + width + widthType + ';';
  9508. }
  9509. if (height !== '') {
  9510. style += 'height:' + height + heightType + ';';
  9511. }
  9512. if (bgColor !== '') {
  9513. style += 'background-color:' + bgColor + ';';
  9514. }
  9515. var html = '<table';
  9516. if (style !== '') {
  9517. html += ' style="' + style + '"';
  9518. }
  9519. if (padding !== '') {
  9520. html += ' cellpadding="' + padding + '"';
  9521. }
  9522. if (spacing !== '') {
  9523. html += ' cellspacing="' + spacing + '"';
  9524. }
  9525. if (align !== '') {
  9526. html += ' align="' + align + '"';
  9527. }
  9528. if (border !== '') {
  9529. html += ' border="' + border + '"';
  9530. }
  9531. if (border === '' || border === '0') {
  9532. html += ' class="' + zeroborder + '"';
  9533. }
  9534. if (borderColor !== '') {
  9535. html += ' bordercolor="' + borderColor + '"';
  9536. }
  9537. html += '>';
  9538. for (var i = 0; i < rows; i++) {
  9539. html += '<tr>';
  9540. for (var j = 0; j < cols; j++) {
  9541. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9542. }
  9543. html += '</tr>';
  9544. }
  9545. html += '</table>';
  9546. if (!K.IE) {
  9547. html += '<br />';
  9548. }
  9549. self.insertHtml(html);
  9550. self.select().hideDialog().focus();
  9551. self.addBookmark();
  9552. }
  9553. }
  9554. }),
  9555. div = dialog.div,
  9556. rowsBox = K('[name="rows"]', div).val(3),
  9557. colsBox = K('[name="cols"]', div).val(2),
  9558. widthBox = K('[name="width"]', div).val(100),
  9559. heightBox = K('[name="height"]', div),
  9560. widthTypeBox = K('[name="widthType"]', div),
  9561. heightTypeBox = K('[name="heightType"]', div),
  9562. paddingBox = K('[name="padding"]', div).val(2),
  9563. spacingBox = K('[name="spacing"]', div).val(0),
  9564. alignBox = K('[name="align"]', div),
  9565. borderBox = K('[name="border"]', div).val(1),
  9566. colorBox = K('.ke-input-color', div);
  9567. _initColorPicker(div, colorBox.eq(0));
  9568. _initColorPicker(div, colorBox.eq(1));
  9569. _setColor(colorBox.eq(0), '#000000');
  9570. _setColor(colorBox.eq(1), '');
  9571. rowsBox[0].focus();
  9572. rowsBox[0].select();
  9573. var table;
  9574. if (isInsert) {
  9575. return;
  9576. }
  9577. table = self.plugin.getSelectedTable();
  9578. if (table) {
  9579. rowsBox.val(table[0].rows.length);
  9580. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9581. rowsBox.attr('disabled', true);
  9582. colsBox.attr('disabled', true);
  9583. var match,
  9584. tableWidth = table[0].style.width || table[0].width,
  9585. tableHeight = table[0].style.height || table[0].height;
  9586. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9587. widthBox.val(match[1]);
  9588. widthTypeBox.val(match[2]);
  9589. } else {
  9590. widthBox.val('');
  9591. }
  9592. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9593. heightBox.val(match[1]);
  9594. heightTypeBox.val(match[2]);
  9595. }
  9596. paddingBox.val(table[0].cellPadding || '');
  9597. spacingBox.val(table[0].cellSpacing || '');
  9598. alignBox.val(table[0].align || '');
  9599. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9600. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9601. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9602. widthBox[0].focus();
  9603. widthBox[0].select();
  9604. }
  9605. },
  9606. cellprop : function() {
  9607. var html = [
  9608. '<div style="padding:20px;">',
  9609. '<div class="ke-dialog-row">',
  9610. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9611. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9612. '<select name="widthType">',
  9613. '<option value="%">' + lang.percent + '</option>',
  9614. '<option value="px">' + lang.px + '</option>',
  9615. '</select> &nbsp; ',
  9616. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9617. '<select name="heightType">',
  9618. '<option value="%">' + lang.percent + '</option>',
  9619. '<option value="px">' + lang.px + '</option>',
  9620. '</select>',
  9621. '</div>',
  9622. '<div class="ke-dialog-row">',
  9623. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9624. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9625. '<option value="">' + lang.alignDefault + '</option>',
  9626. '<option value="left">' + lang.alignLeft + '</option>',
  9627. '<option value="center">' + lang.alignCenter + '</option>',
  9628. '<option value="right">' + lang.alignRight + '</option>',
  9629. '</select> ',
  9630. lang.verticalAlign + ' <select name="verticalAlign">',
  9631. '<option value="">' + lang.alignDefault + '</option>',
  9632. '<option value="top">' + lang.alignTop + '</option>',
  9633. '<option value="middle">' + lang.alignMiddle + '</option>',
  9634. '<option value="bottom">' + lang.alignBottom + '</option>',
  9635. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9636. '</select>',
  9637. '</div>',
  9638. '<div class="ke-dialog-row">',
  9639. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9640. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9641. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9642. '</div>',
  9643. '<div class="ke-dialog-row">',
  9644. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9645. '<span class="ke-inline-block ke-input-color"></span>',
  9646. '</div>',
  9647. '</div>'
  9648. ].join('');
  9649. var bookmark = self.cmd.range.createBookmark();
  9650. var dialog = self.createDialog({
  9651. name : name,
  9652. width : 500,
  9653. title : self.lang('tablecell'),
  9654. body : html,
  9655. beforeRemove : function() {
  9656. colorBox.unbind();
  9657. },
  9658. yesBtn : {
  9659. name : self.lang('yes'),
  9660. click : function(e) {
  9661. var width = widthBox.val(),
  9662. height = heightBox.val(),
  9663. widthType = widthTypeBox.val(),
  9664. heightType = heightTypeBox.val(),
  9665. padding = paddingBox.val(),
  9666. spacing = spacingBox.val(),
  9667. textAlign = textAlignBox.val(),
  9668. verticalAlign = verticalAlignBox.val(),
  9669. border = borderBox.val(),
  9670. borderColor = K(colorBox[0]).html() || '',
  9671. bgColor = K(colorBox[1]).html() || '';
  9672. if (!/^\d*$/.test(width)) {
  9673. alert(self.lang('invalidWidth'));
  9674. widthBox[0].focus();
  9675. return;
  9676. }
  9677. if (!/^\d*$/.test(height)) {
  9678. alert(self.lang('invalidHeight'));
  9679. heightBox[0].focus();
  9680. return;
  9681. }
  9682. if (!/^\d*$/.test(border)) {
  9683. alert(self.lang('invalidBorder'));
  9684. borderBox[0].focus();
  9685. return;
  9686. }
  9687. cell.css({
  9688. width : width !== '' ? (width + widthType) : '',
  9689. height : height !== '' ? (height + heightType) : '',
  9690. 'background-color' : bgColor,
  9691. 'text-align' : textAlign,
  9692. 'vertical-align' : verticalAlign,
  9693. 'border-width' : border,
  9694. 'border-style' : border !== '' ? 'solid' : '',
  9695. 'border-color' : borderColor
  9696. });
  9697. self.hideDialog().focus();
  9698. self.cmd.range.moveToBookmark(bookmark);
  9699. self.cmd.select();
  9700. self.addBookmark();
  9701. }
  9702. }
  9703. }),
  9704. div = dialog.div,
  9705. widthBox = K('[name="width"]', div).val(100),
  9706. heightBox = K('[name="height"]', div),
  9707. widthTypeBox = K('[name="widthType"]', div),
  9708. heightTypeBox = K('[name="heightType"]', div),
  9709. paddingBox = K('[name="padding"]', div).val(2),
  9710. spacingBox = K('[name="spacing"]', div).val(0),
  9711. textAlignBox = K('[name="textAlign"]', div),
  9712. verticalAlignBox = K('[name="verticalAlign"]', div),
  9713. borderBox = K('[name="border"]', div).val(1),
  9714. colorBox = K('.ke-input-color', div);
  9715. _initColorPicker(div, colorBox.eq(0));
  9716. _initColorPicker(div, colorBox.eq(1));
  9717. _setColor(colorBox.eq(0), '#000000');
  9718. _setColor(colorBox.eq(1), '');
  9719. widthBox[0].focus();
  9720. widthBox[0].select();
  9721. var cell = self.plugin.getSelectedCell();
  9722. var match,
  9723. cellWidth = cell[0].style.width || cell[0].width || '',
  9724. cellHeight = cell[0].style.height || cell[0].height || '';
  9725. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9726. widthBox.val(match[1]);
  9727. widthTypeBox.val(match[2]);
  9728. } else {
  9729. widthBox.val('');
  9730. }
  9731. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9732. heightBox.val(match[1]);
  9733. heightTypeBox.val(match[2]);
  9734. }
  9735. textAlignBox.val(cell[0].style.textAlign || '');
  9736. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9737. var border = cell[0].style.borderWidth || '';
  9738. if (border) {
  9739. border = parseInt(border);
  9740. }
  9741. borderBox.val(border);
  9742. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9743. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9744. widthBox[0].focus();
  9745. widthBox[0].select();
  9746. },
  9747. insert : function() {
  9748. this.prop(true);
  9749. },
  9750. 'delete' : function() {
  9751. var table = self.plugin.getSelectedTable();
  9752. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9753. self.cmd.select();
  9754. table.remove();
  9755. self.addBookmark();
  9756. },
  9757. colinsert : function(offset) {
  9758. var table = self.plugin.getSelectedTable()[0],
  9759. row = self.plugin.getSelectedRow()[0],
  9760. cell = self.plugin.getSelectedCell()[0],
  9761. index = cell.cellIndex + offset;
  9762. index += table.rows[0].cells.length - row.cells.length;
  9763. for (var i = 0, len = table.rows.length; i < len; i++) {
  9764. var newRow = table.rows[i],
  9765. newCell = newRow.insertCell(index);
  9766. newCell.innerHTML = K.IE ? '' : '<br />';
  9767. index = _getCellIndex(table, newRow, newCell);
  9768. }
  9769. self.cmd.range.selectNodeContents(cell).collapse(true);
  9770. self.cmd.select();
  9771. self.addBookmark();
  9772. },
  9773. colinsertleft : function() {
  9774. this.colinsert(0);
  9775. },
  9776. colinsertright : function() {
  9777. this.colinsert(1);
  9778. },
  9779. rowinsert : function(offset) {
  9780. var table = self.plugin.getSelectedTable()[0],
  9781. row = self.plugin.getSelectedRow()[0],
  9782. cell = self.plugin.getSelectedCell()[0];
  9783. var rowIndex = row.rowIndex;
  9784. if (offset === 1) {
  9785. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9786. }
  9787. var newRow = table.insertRow(rowIndex);
  9788. for (var i = 0, len = row.cells.length; i < len; i++) {
  9789. if (row.cells[i].rowSpan > 1) {
  9790. len -= row.cells[i].rowSpan - 1;
  9791. }
  9792. var newCell = newRow.insertCell(i);
  9793. if (offset === 1 && row.cells[i].colSpan > 1) {
  9794. newCell.colSpan = row.cells[i].colSpan;
  9795. }
  9796. newCell.innerHTML = K.IE ? '' : '<br />';
  9797. }
  9798. for (var j = rowIndex; j >= 0; j--) {
  9799. var cells = table.rows[j].cells;
  9800. if (cells.length > i) {
  9801. for (var k = cell.cellIndex; k >= 0; k--) {
  9802. if (cells[k].rowSpan > 1) {
  9803. cells[k].rowSpan += 1;
  9804. }
  9805. }
  9806. break;
  9807. }
  9808. }
  9809. self.cmd.range.selectNodeContents(cell).collapse(true);
  9810. self.cmd.select();
  9811. self.addBookmark();
  9812. },
  9813. rowinsertabove : function() {
  9814. this.rowinsert(0);
  9815. },
  9816. rowinsertbelow : function() {
  9817. this.rowinsert(1);
  9818. },
  9819. rowmerge : function() {
  9820. var table = self.plugin.getSelectedTable()[0],
  9821. row = self.plugin.getSelectedRow()[0],
  9822. cell = self.plugin.getSelectedCell()[0],
  9823. rowIndex = row.rowIndex,
  9824. nextRowIndex = rowIndex + cell.rowSpan,
  9825. nextRow = table.rows[nextRowIndex];
  9826. if (table.rows.length <= nextRowIndex) {
  9827. return;
  9828. }
  9829. var cellIndex = cell.cellIndex;
  9830. if (nextRow.cells.length <= cellIndex) {
  9831. return;
  9832. }
  9833. var nextCell = nextRow.cells[cellIndex];
  9834. if (cell.colSpan !== nextCell.colSpan) {
  9835. return;
  9836. }
  9837. cell.rowSpan += nextCell.rowSpan;
  9838. nextRow.deleteCell(cellIndex);
  9839. self.cmd.range.selectNodeContents(cell).collapse(true);
  9840. self.cmd.select();
  9841. self.addBookmark();
  9842. },
  9843. colmerge : function() {
  9844. var table = self.plugin.getSelectedTable()[0],
  9845. row = self.plugin.getSelectedRow()[0],
  9846. cell = self.plugin.getSelectedCell()[0],
  9847. rowIndex = row.rowIndex,
  9848. cellIndex = cell.cellIndex,
  9849. nextCellIndex = cellIndex + 1;
  9850. if (row.cells.length <= nextCellIndex) {
  9851. return;
  9852. }
  9853. var nextCell = row.cells[nextCellIndex];
  9854. if (cell.rowSpan !== nextCell.rowSpan) {
  9855. return;
  9856. }
  9857. cell.colSpan += nextCell.colSpan;
  9858. row.deleteCell(nextCellIndex);
  9859. self.cmd.range.selectNodeContents(cell).collapse(true);
  9860. self.cmd.select();
  9861. self.addBookmark();
  9862. },
  9863. rowsplit : function() {
  9864. var table = self.plugin.getSelectedTable()[0],
  9865. row = self.plugin.getSelectedRow()[0],
  9866. cell = self.plugin.getSelectedCell()[0],
  9867. rowIndex = row.rowIndex;
  9868. if (cell.rowSpan === 1) {
  9869. return;
  9870. }
  9871. var cellIndex = _getCellIndex(table, row, cell);
  9872. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9873. var newRow = table.rows[rowIndex + i],
  9874. newCell = newRow.insertCell(cellIndex);
  9875. if (cell.colSpan > 1) {
  9876. newCell.colSpan = cell.colSpan;
  9877. }
  9878. newCell.innerHTML = K.IE ? '' : '<br />';
  9879. cellIndex = _getCellIndex(table, newRow, newCell);
  9880. }
  9881. K(cell).removeAttr('rowSpan');
  9882. self.cmd.range.selectNodeContents(cell).collapse(true);
  9883. self.cmd.select();
  9884. self.addBookmark();
  9885. },
  9886. colsplit : function() {
  9887. var table = self.plugin.getSelectedTable()[0],
  9888. row = self.plugin.getSelectedRow()[0],
  9889. cell = self.plugin.getSelectedCell()[0],
  9890. cellIndex = cell.cellIndex;
  9891. if (cell.colSpan === 1) {
  9892. return;
  9893. }
  9894. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9895. var newCell = row.insertCell(cellIndex + i);
  9896. if (cell.rowSpan > 1) {
  9897. newCell.rowSpan = cell.rowSpan;
  9898. }
  9899. newCell.innerHTML = K.IE ? '' : '<br />';
  9900. }
  9901. K(cell).removeAttr('colSpan');
  9902. self.cmd.range.selectNodeContents(cell).collapse(true);
  9903. self.cmd.select();
  9904. self.addBookmark();
  9905. },
  9906. coldelete : function() {
  9907. var table = self.plugin.getSelectedTable()[0],
  9908. row = self.plugin.getSelectedRow()[0],
  9909. cell = self.plugin.getSelectedCell()[0],
  9910. index = cell.cellIndex;
  9911. for (var i = 0, len = table.rows.length; i < len; i++) {
  9912. var newRow = table.rows[i],
  9913. newCell = newRow.cells[index];
  9914. if (newCell.colSpan > 1) {
  9915. newCell.colSpan -= 1;
  9916. if (newCell.colSpan === 1) {
  9917. K(newCell).removeAttr('colSpan');
  9918. }
  9919. } else {
  9920. newRow.deleteCell(index);
  9921. }
  9922. if (newCell.rowSpan > 1) {
  9923. i += newCell.rowSpan - 1;
  9924. }
  9925. }
  9926. if (row.cells.length === 0) {
  9927. self.cmd.range.setStartBefore(table).collapse(true);
  9928. self.cmd.select();
  9929. K(table).remove();
  9930. } else {
  9931. self.cmd.selection(true);
  9932. }
  9933. self.addBookmark();
  9934. },
  9935. rowdelete : function() {
  9936. var table = self.plugin.getSelectedTable()[0],
  9937. row = self.plugin.getSelectedRow()[0],
  9938. cell = self.plugin.getSelectedCell()[0],
  9939. rowIndex = row.rowIndex;
  9940. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  9941. table.deleteRow(rowIndex + i);
  9942. }
  9943. if (table.rows.length === 0) {
  9944. self.cmd.range.setStartBefore(table).collapse(true);
  9945. self.cmd.select();
  9946. K(table).remove();
  9947. } else {
  9948. self.cmd.selection(true);
  9949. }
  9950. self.addBookmark();
  9951. }
  9952. };
  9953. self.clickToolbar(name, self.plugin.table.prop);
  9954. });
  9955. /*******************************************************************************
  9956. * KindEditor - WYSIWYG HTML Editor for Internet
  9957. * Copyright (C) 2006-2011 kindsoft.net
  9958. *
  9959. * @author Roddy <luolonghao@gmail.com>
  9960. * @site http://www.kindsoft.net/
  9961. * @licence http://www.kindsoft.net/license.php
  9962. *******************************************************************************/
  9963. KindEditor.plugin('template', function(K) {
  9964. var self = this, name = 'template', lang = self.lang(name + '.'),
  9965. htmlPath = self.pluginsPath + name + '/html/';
  9966. function getFilePath(fileName) {
  9967. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  9968. }
  9969. self.clickToolbar(name, function() {
  9970. var lang = self.lang(name + '.'),
  9971. arr = ['<div style="padding:10px 20px;">',
  9972. '<div class="ke-header">',
  9973. '<div class="ke-left">',
  9974. lang. selectTemplate + ' <select>'];
  9975. K.each(lang.fileList, function(key, val) {
  9976. arr.push('<option value="' + key + '">' + val + '</option>');
  9977. });
  9978. html = [arr.join(''),
  9979. '</select></div>',
  9980. '<div class="ke-right">',
  9981. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  9982. '</div>',
  9983. '<div class="ke-clearfix"></div>',
  9984. '</div>',
  9985. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  9986. '</div>'].join('');
  9987. var dialog = self.createDialog({
  9988. name : name,
  9989. width : 500,
  9990. title : self.lang(name),
  9991. body : html,
  9992. yesBtn : {
  9993. name : self.lang('yes'),
  9994. click : function(e) {
  9995. var doc = K.iframeDoc(iframe);
  9996. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  9997. }
  9998. }
  9999. });
  10000. var selectBox = K('select', dialog.div),
  10001. checkbox = K('[name="replaceFlag"]', dialog.div),
  10002. iframe = K('iframe', dialog.div);
  10003. checkbox[0].checked = true;
  10004. iframe.attr('src', getFilePath(selectBox.val()));
  10005. selectBox.change(function() {
  10006. iframe.attr('src', getFilePath(this.value));
  10007. });
  10008. });
  10009. });
  10010. /*******************************************************************************
  10011. * KindEditor - WYSIWYG HTML Editor for Internet
  10012. * Copyright (C) 2006-2011 kindsoft.net
  10013. *
  10014. * @author Roddy <luolonghao@gmail.com>
  10015. * @site http://www.kindsoft.net/
  10016. * @licence http://www.kindsoft.net/license.php
  10017. *******************************************************************************/
  10018. KindEditor.plugin('wordpaste', function(K) {
  10019. var self = this, name = 'wordpaste';
  10020. self.clickToolbar(name, function() {
  10021. var lang = self.lang(name + '.'),
  10022. html = '<div style="padding:10px 20px;">' +
  10023. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  10024. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  10025. '</div>',
  10026. dialog = self.createDialog({
  10027. name : name,
  10028. width : 450,
  10029. title : self.lang(name),
  10030. body : html,
  10031. yesBtn : {
  10032. name : self.lang('yes'),
  10033. click : function(e) {
  10034. var str = doc.body.innerHTML;
  10035. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  10036. self.insertHtml(str).hideDialog().focus();
  10037. }
  10038. }
  10039. }),
  10040. div = dialog.div,
  10041. iframe = K('iframe', div),
  10042. doc = K.iframeDoc(iframe);
  10043. if (!K.IE) {
  10044. doc.designMode = 'on';
  10045. }
  10046. doc.open();
  10047. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  10048. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  10049. if (!K.IE) {
  10050. doc.write('<br />');
  10051. }
  10052. doc.write('</body></html>');
  10053. doc.close();
  10054. if (K.IE) {
  10055. doc.body.contentEditable = 'true';
  10056. }
  10057. iframe[0].contentWindow.focus();
  10058. });
  10059. });
  10060. KindEditor.plugin('fixtoolbar', function (K) {
  10061. var self = this;
  10062. if (!self.fixToolBar) {
  10063. return;
  10064. }
  10065. function init() {
  10066. var toolbar = K('.ke-toolbar');
  10067. var originY = toolbar.pos().y;
  10068. K(window).bind('scroll', function () {
  10069. if (toolbar.css('position') == 'fixed') {
  10070. if(document.body.scrollTop - originY < 0){
  10071. toolbar.css('position', 'static');
  10072. toolbar.css('top', 'auto');
  10073. }
  10074. } else {
  10075. if (toolbar.pos().y - document.body.scrollTop < 0) {
  10076. toolbar.css('position', 'fixed');
  10077. toolbar.css('top', 0);
  10078. }
  10079. }
  10080. });
  10081. }
  10082. if (self.isCreated) {
  10083. init();
  10084. } else {
  10085. self.afterCreate(init);
  10086. }
  10087. });
  10088. //自定义资源库
  10089. KindEditor.plugin('res', function(K) {
  10090. var self = this;
  10091. // 点击图标时执行
  10092. self.clickToolbar('res', function() {
  10093. var clickFn = function(url, title, id) {
  10094. var html = '<embed src="{url}" type="video/x-ms-asf-plugin" width="550" height="400" autostart="false" loop="true" id="{id}"/>';
  10095. html = html.replace('{url}', url);
  10096. html = html.replace('{id}', id);
  10097. self.insertHtml(html);
  10098. };
  10099. editorShowUpload('', self.fileManagerJson, '视频库', clickFn, this);
  10100. });
  10101. });
  10102. function autoImg(self) {
  10103. var index = self.index;
  10104. var haspicContainer = document.getElementById("has_pic_" + index);
  10105. if (haspicContainer == null) {
  10106. haspicContainer = document.createElement("div");
  10107. haspicContainer.id = "has_pic_" + index;
  10108. haspicContainer.innerHTML = "<input type='text' id='piclist_"+index+"' value='' style='display:none;'/><div id='upload_"+index+"' style='color:red'><b>您有图片需要上传到服务器</b>&nbsp;&nbsp;<a href='javascript:uploadpic(\""+self.uploadJson+"\", \""+self.filePostName+"\", \""+index+"\");' style='color:red'>[上传]</a></div><div id='confirm_"+index+"'></div>";
  10109. $(".ke-toolbar").eq(index).after(haspicContainer);
  10110. }
  10111. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  10112. var piccount = 0;
  10113. var sstr = '';
  10114. $(img).each(function (i) {
  10115. var that = $(this);
  10116. var host = gethost(self.uploadJson);
  10117. var yhost = '';
  10118. if (self.uploadYunJson && self.uploadYunJson.host) {
  10119. yhost = gethost(self.uploadYunJson.host);
  10120. }
  10121. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  10122. var n = gethost(that.attr("src"));
  10123. if (yhost) {
  10124. if (host != n && yhost != n) {
  10125. piccount++;
  10126. if (i == $(img).length - 1)
  10127. sstr += that.attr("src");
  10128. else
  10129. sstr += that.attr("src") + ",";
  10130. }
  10131. } else {
  10132. if (host != n) {
  10133. piccount++;
  10134. if (i == $(img).length - 1)
  10135. sstr += that.attr("src");
  10136. else
  10137. sstr += that.attr("src") + ",";
  10138. }
  10139. }
  10140. }
  10141. });
  10142. $("#piclist_" + index).val(encodeURIComponent(sstr));
  10143. document.getElementById("has_pic_" + index).style.display = (piccount > 0) ? "block" : "none";
  10144. }
  10145. function closeupload(index) {
  10146. $("#has_pic_" + index).hide();
  10147. $("#upload_" + index).show();
  10148. }
  10149. function uploadpic(url, name, index) {
  10150. var piclist = encodeURI($("#piclist_" + index).val());
  10151. if (piclist.length == 0) return false;
  10152. $.ajax({
  10153. url: url.replace('kindeditor', 'copys') + '&json=1',
  10154. data: name + "=" + piclist,
  10155. type: "POST",
  10156. dataType: "json",
  10157. beforeSend: function () {
  10158. $("#upload_" + index).hide();
  10159. $("#confirm_" + index).text("正在上传中...");
  10160. },
  10161. success: function (msg) {
  10162. var url = msg.data;
  10163. if (url !== "") {
  10164. var str = new Array();
  10165. str = url.split(',');
  10166. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  10167. $(img).each(function (i) {
  10168. var that = $(this);
  10169. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  10170. that.attr("src", str[i]);
  10171. that.attr("data-ke-src", str[i]);
  10172. }
  10173. });
  10174. $("#confirm_" + index).html(img.length + "张图片已经上传成功!&nbsp;&nbsp;<a href='javascript:closeupload("+index+");'>关闭</a>");
  10175. }
  10176. else $("#confirm_" + index).text("上传失败!");
  10177. }
  10178. });
  10179. }
  10180. function gethost(url){
  10181. var reg = /^http(s)?:\/\/(.*?)\//;
  10182. return reg.exec(url)[2];
  10183. }