kindeditor-all-min.js 307 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428
  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. if (typeof(val) == 'string') {
  88. return val.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  89. } else {
  90. return val;
  91. }
  92. }
  93. function _unescape(val) {
  94. return val.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&amp;/g, '&');
  95. }
  96. function _toCamel(str) {
  97. var arr = str.split('-');
  98. str = '';
  99. _each(arr, function(key, val) {
  100. str += (key > 0) ? val.charAt(0).toUpperCase() + val.substr(1) : val;
  101. });
  102. return str;
  103. }
  104. function _toHex(val) {
  105. function hex(d) {
  106. var s = parseInt(d, 10).toString(16).toUpperCase();
  107. return s.length > 1 ? s : '0' + s;
  108. }
  109. return val.replace(/rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/ig,
  110. function($0, $1, $2, $3) {
  111. return '#' + hex($1) + hex($2) + hex($3);
  112. }
  113. );
  114. }
  115. function _toMap(val, delimiter) {
  116. delimiter = delimiter === undefined ? ',' : delimiter;
  117. var map = {}, arr = _isArray(val) ? val : val.split(delimiter), match;
  118. _each(arr, function(key, val) {
  119. if ((match = /^(\d+)\.\.(\d+)$/.exec(val))) {
  120. for (var i = parseInt(match[1], 10); i <= parseInt(match[2], 10); i++) {
  121. map[i.toString()] = true;
  122. }
  123. } else {
  124. map[val] = true;
  125. }
  126. });
  127. return map;
  128. }
  129. function _toArray(obj, offset) {
  130. return Array.prototype.slice.call(obj, offset || 0);
  131. }
  132. function _undef(val, defaultVal) {
  133. return val === undefined ? defaultVal : val;
  134. }
  135. function _invalidUrl(url) {
  136. return !url || /[<>"]/.test(url);
  137. }
  138. function _addParam(url, param) {
  139. return url.indexOf('?') >= 0 ? url + '&' + param : url + '?' + param;
  140. }
  141. function _extend(child, parent, proto) {
  142. if (!proto) {
  143. proto = parent;
  144. parent = null;
  145. }
  146. var childProto;
  147. if (parent) {
  148. var fn = function () {};
  149. fn.prototype = parent.prototype;
  150. childProto = new fn();
  151. _each(proto, function(key, val) {
  152. childProto[key] = val;
  153. });
  154. } else {
  155. childProto = proto;
  156. }
  157. childProto.constructor = child;
  158. child.prototype = childProto;
  159. child.parent = parent ? parent.prototype : null;
  160. }
  161. function _json(text) {
  162. var match;
  163. if ((match = /\{[\s\S]*\}|\[[\s\S]*\]/.exec(text))) {
  164. text = match[0];
  165. }
  166. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
  167. cx.lastIndex = 0;
  168. if (cx.test(text)) {
  169. text = text.replace(cx, function (a) {
  170. return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  171. });
  172. }
  173. if (/^[\],:{}\s]*$/.
  174. test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
  175. replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
  176. replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
  177. return eval('(' + text + ')');
  178. }
  179. throw 'JSON parse error';
  180. }
  181. var _round = Math.round;
  182. var K = {
  183. DEBUG : false,
  184. VERSION : _VERSION,
  185. IE : _IE,
  186. GECKO : _GECKO,
  187. WEBKIT : _WEBKIT,
  188. OPERA : _OPERA,
  189. V : _V,
  190. TIME : _TIME,
  191. each : _each,
  192. isArray : _isArray,
  193. isFunction : _isFunction,
  194. inArray : _inArray,
  195. inString : _inString,
  196. trim : _trim,
  197. addUnit : _addUnit,
  198. removeUnit : _removeUnit,
  199. escape : _escape,
  200. unescape : _unescape,
  201. toCamel : _toCamel,
  202. toHex : _toHex,
  203. toMap : _toMap,
  204. toArray : _toArray,
  205. undef : _undef,
  206. invalidUrl : _invalidUrl,
  207. addParam : _addParam,
  208. extend : _extend,
  209. json : _json
  210. };
  211. 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'),
  212. _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'),
  213. _SINGLE_TAG_MAP = _toMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed'),
  214. _STYLE_TAG_MAP = _toMap('b,basefont,big,del,em,font,i,s,small,span,strike,strong,sub,sup,u'),
  215. _CONTROL_TAG_MAP = _toMap('img,table,input,textarea,button'),
  216. _PRE_TAG_MAP = _toMap('pre,style,script'),
  217. _NOSPLIT_TAG_MAP = _toMap('html,head,body,td,tr,table,ol,ul,li'),
  218. _AUTOCLOSE_TAG_MAP = _toMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'),
  219. _FILL_ATTR_MAP = _toMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
  220. _VALUE_TAG_MAP = _toMap('input,button,textarea,select');
  221. function _getBasePath() {
  222. var els = document.getElementsByTagName('script'), src;
  223. for (var i = 0, len = els.length; i < len; i++) {
  224. src = els[i].src || '';
  225. if (/kindeditor[\w\-\.]*\.js/.test(src)) {
  226. return src.substring(0, src.lastIndexOf('/') + 1);
  227. }
  228. }
  229. return '';
  230. }
  231. K.basePath = _getBasePath();
  232. K.options = {
  233. index : 0,
  234. designMode : true,
  235. fullscreenMode : false,
  236. filterMode : true,
  237. wellFormatMode : true,
  238. shadowMode : true,
  239. loadStyleMode : true,
  240. basePath : K.basePath,
  241. themesPath : K.basePath + 'themes/',
  242. langPath : K.basePath + 'lang/',
  243. pluginsPath : K.basePath + 'plugins/',
  244. themeType : 'default',
  245. langType : 'zh-CN',
  246. urlType : '',
  247. newlineTag : 'p',
  248. resizeType : 2,
  249. syncType : 'form',
  250. pasteType : 2,
  251. dialogAlignType : 'page',
  252. useContextmenu : true,
  253. fullscreenShortcut : false,
  254. bodyClass : 'ke-content',
  255. indentChar : '\t',
  256. cssPath : '',
  257. cssData : '',
  258. minWidth : 650,
  259. minHeight : 100,
  260. minChangeSize : 50,
  261. zIndex : 19850426,
  262. items : [
  263. 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
  264. 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
  265. 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
  266. 'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
  267. 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
  268. 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
  269. 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
  270. 'anchor', 'link', 'unlink', '|', 'about'
  271. ],
  272. noDisableItems : ['source', 'fullscreen'],
  273. colorTable : [
  274. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  275. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  276. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  277. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  278. ],
  279. fontSizeTable : ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px'],
  280. fontHeightTable : ['0px', '0.25px', '0.5px', '1px', '1.5px', '2px', '2.5px', '3px', '4px', '5px'],
  281. htmlTags : {
  282. font : ['id', 'class', 'color', 'size', 'face', '.background-color'],
  283. span : [
  284. 'id', 'class', '.color', '.background-color', '.font-size', '.font-family', '.background',
  285. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height'
  286. ],
  287. div : [
  288. 'id', 'class', 'align', '.border', '.margin', '.padding', '.text-align', '.color',
  289. '.background-color', '.font-size', '.font-family', '.font-weight', '.background',
  290. '.font-style', '.text-decoration', '.vertical-align', '.margin-left'
  291. ],
  292. table: [
  293. 'id', 'class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'bordercolor',
  294. '.padding', '.margin', '.border', 'bgcolor', '.text-align', '.color', '.background-color',
  295. '.font-size', '.font-family', '.font-weight', '.font-style', '.text-decoration', '.background',
  296. '.width', '.height', '.border-collapse'
  297. ],
  298. 'td,th': [
  299. 'id', 'class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor',
  300. '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.font-weight',
  301. '.font-style', '.text-decoration', '.vertical-align', '.background', '.border'
  302. ],
  303. a : ['id', 'class', 'href', 'target', 'name'],
  304. embed : ['id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess', 'wmode'],
  305. img : ['id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border'],
  306. 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [
  307. 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background',
  308. '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left'
  309. ],
  310. pre : ['id', 'class'],
  311. hr : ['id', 'class', '.page-break-after'],
  312. 'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : ['id', 'class'],
  313. iframe : ['id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height']
  314. },
  315. layout : '<div class="container"><div class="toolbar"></div><div class="edit"></div><div class="statusbar"></div></div>'
  316. };
  317. var _useCapture = false;
  318. var _INPUT_KEY_MAP = _toMap('8,9,13,32,46,48..57,59,61,65..90,106,109..111,188,190..192,219..222');
  319. var _CURSORMOVE_KEY_MAP = _toMap('33..40');
  320. var _CHANGE_KEY_MAP = {};
  321. _each(_INPUT_KEY_MAP, function(key, val) {
  322. _CHANGE_KEY_MAP[key] = val;
  323. });
  324. _each(_CURSORMOVE_KEY_MAP, function(key, val) {
  325. _CHANGE_KEY_MAP[key] = val;
  326. });
  327. function _bindEvent(el, type, fn) {
  328. if (el.addEventListener){
  329. el.addEventListener(type, fn, _useCapture);
  330. } else if (el.attachEvent){
  331. el.attachEvent('on' + type, fn);
  332. }
  333. }
  334. function _unbindEvent(el, type, fn) {
  335. if (el.removeEventListener){
  336. el.removeEventListener(type, fn, _useCapture);
  337. } else if (el.detachEvent){
  338. el.detachEvent('on' + type, fn);
  339. }
  340. }
  341. var _EVENT_PROPS = ('altKey,attrChange,attrName,bubbles,button,cancelable,charCode,clientX,clientY,ctrlKey,currentTarget,' +
  342. 'data,detail,eventPhase,fromElement,handler,keyCode,metaKey,newValue,offsetX,offsetY,originalTarget,pageX,' +
  343. 'pageY,prevValue,relatedNode,relatedTarget,screenX,screenY,shiftKey,srcElement,target,toElement,view,wheelDelta,which').split(',');
  344. function KEvent(el, event) {
  345. this.init(el, event);
  346. }
  347. _extend(KEvent, {
  348. init : function(el, event) {
  349. var self = this, doc = el.ownerDocument || el.document || el;
  350. self.event = event;
  351. _each(_EVENT_PROPS, function(key, val) {
  352. self[val] = event[val];
  353. });
  354. if (!self.target) {
  355. self.target = self.srcElement || doc;
  356. }
  357. if (self.target.nodeType === 3) {
  358. self.target = self.target.parentNode;
  359. }
  360. if (!self.relatedTarget && self.fromElement) {
  361. self.relatedTarget = self.fromElement === self.target ? self.toElement : self.fromElement;
  362. }
  363. if (self.pageX == null && self.clientX != null) {
  364. var d = doc.documentElement, body = doc.body;
  365. self.pageX = self.clientX + (d && d.scrollLeft || body && body.scrollLeft || 0) - (d && d.clientLeft || body && body.clientLeft || 0);
  366. self.pageY = self.clientY + (d && d.scrollTop || body && body.scrollTop || 0) - (d && d.clientTop || body && body.clientTop || 0);
  367. }
  368. if (!self.which && ((self.charCode || self.charCode === 0) ? self.charCode : self.keyCode)) {
  369. self.which = self.charCode || self.keyCode;
  370. }
  371. if (!self.metaKey && self.ctrlKey) {
  372. self.metaKey = self.ctrlKey;
  373. }
  374. if (!self.which && self.button !== undefined) {
  375. self.which = (self.button & 1 ? 1 : (self.button & 2 ? 3 : (self.button & 4 ? 2 : 0)));
  376. }
  377. switch (self.which) {
  378. case 186 :
  379. self.which = 59;
  380. break;
  381. case 187 :
  382. case 107 :
  383. case 43 :
  384. self.which = 61;
  385. break;
  386. case 189 :
  387. case 45 :
  388. self.which = 109;
  389. break;
  390. case 42 :
  391. self.which = 106;
  392. break;
  393. case 47 :
  394. self.which = 111;
  395. break;
  396. case 78 :
  397. self.which = 110;
  398. break;
  399. }
  400. if (self.which >= 96 && self.which <= 105) {
  401. self.which -= 48;
  402. }
  403. },
  404. preventDefault : function() {
  405. var ev = this.event;
  406. if (ev.preventDefault) {
  407. ev.preventDefault();
  408. } else {
  409. ev.returnValue = false;
  410. }
  411. },
  412. stopPropagation : function() {
  413. var ev = this.event;
  414. if (ev.stopPropagation) {
  415. ev.stopPropagation();
  416. } else {
  417. ev.cancelBubble = true;
  418. }
  419. },
  420. stop : function() {
  421. this.preventDefault();
  422. this.stopPropagation();
  423. }
  424. });
  425. var _eventExpendo = 'kindeditor_' + _TIME, _eventId = 0, _eventData = {};
  426. function _getId(el) {
  427. return el[_eventExpendo] || null;
  428. }
  429. function _setId(el) {
  430. el[_eventExpendo] = ++_eventId;
  431. return _eventId;
  432. }
  433. function _removeId(el) {
  434. try {
  435. delete el[_eventExpendo];
  436. } catch(e) {
  437. if (el.removeAttribute) {
  438. el.removeAttribute(_eventExpendo);
  439. }
  440. }
  441. }
  442. function _bind(el, type, fn) {
  443. if (type.indexOf(',') >= 0) {
  444. _each(type.split(','), function() {
  445. _bind(el, this, fn);
  446. });
  447. return;
  448. }
  449. var id = _getId(el);
  450. if (!id) {
  451. id = _setId(el);
  452. }
  453. if (_eventData[id] === undefined) {
  454. _eventData[id] = {};
  455. }
  456. var events = _eventData[id][type];
  457. if (events && events.length > 0) {
  458. _unbindEvent(el, type, events[0]);
  459. } else {
  460. _eventData[id][type] = [];
  461. _eventData[id].el = el;
  462. }
  463. events = _eventData[id][type];
  464. if (events.length === 0) {
  465. events[0] = function(e) {
  466. var kevent = e ? new KEvent(el, e) : undefined;
  467. _each(events, function(i, event) {
  468. if (i > 0 && event) {
  469. event.call(el, kevent);
  470. }
  471. });
  472. };
  473. }
  474. if (_inArray(fn, events) < 0) {
  475. events.push(fn);
  476. }
  477. _bindEvent(el, type, events[0]);
  478. }
  479. function _unbind(el, type, fn) {
  480. if (type && type.indexOf(',') >= 0) {
  481. _each(type.split(','), function() {
  482. _unbind(el, this, fn);
  483. });
  484. return;
  485. }
  486. var id = _getId(el);
  487. if (!id) {
  488. return;
  489. }
  490. if (type === undefined) {
  491. if (id in _eventData) {
  492. _each(_eventData[id], function(key, events) {
  493. if (key != 'el' && events.length > 0) {
  494. _unbindEvent(el, key, events[0]);
  495. }
  496. });
  497. delete _eventData[id];
  498. _removeId(el);
  499. }
  500. return;
  501. }
  502. if (!_eventData[id]) {
  503. return;
  504. }
  505. var events = _eventData[id][type];
  506. if (events && events.length > 0) {
  507. if (fn === undefined) {
  508. _unbindEvent(el, type, events[0]);
  509. delete _eventData[id][type];
  510. } else {
  511. _each(events, function(i, event) {
  512. if (i > 0 && event === fn) {
  513. events.splice(i, 1);
  514. }
  515. });
  516. if (events.length == 1) {
  517. _unbindEvent(el, type, events[0]);
  518. delete _eventData[id][type];
  519. }
  520. }
  521. var count = 0;
  522. _each(_eventData[id], function() {
  523. count++;
  524. });
  525. if (count < 2) {
  526. delete _eventData[id];
  527. _removeId(el);
  528. }
  529. }
  530. }
  531. function _fire(el, type) {
  532. if (type.indexOf(',') >= 0) {
  533. _each(type.split(','), function() {
  534. _fire(el, this);
  535. });
  536. return;
  537. }
  538. var id = _getId(el);
  539. if (!id) {
  540. return;
  541. }
  542. var events = _eventData[id][type];
  543. if (_eventData[id] && events && events.length > 0) {
  544. events[0]();
  545. }
  546. }
  547. function _ctrl(el, key, fn) {
  548. var self = this;
  549. key = /^\d{2,}$/.test(key) ? key : key.toUpperCase().charCodeAt(0);
  550. _bind(el, 'keydown', function(e) {
  551. if (e.ctrlKey && e.which == key && !e.shiftKey && !e.altKey) {
  552. fn.call(el);
  553. e.stop();
  554. }
  555. });
  556. }
  557. var _readyFinished = false;
  558. function _ready(fn) {
  559. if (_readyFinished) {
  560. fn(KindEditor);
  561. return;
  562. }
  563. var loaded = false;
  564. function readyFunc() {
  565. if (!loaded) {
  566. loaded = true;
  567. fn(KindEditor);
  568. _readyFinished = true;
  569. }
  570. }
  571. function ieReadyFunc() {
  572. if (!loaded) {
  573. try {
  574. document.documentElement.doScroll('left');
  575. } catch(e) {
  576. setTimeout(ieReadyFunc, 100);
  577. return;
  578. }
  579. readyFunc();
  580. }
  581. }
  582. function ieReadyStateFunc() {
  583. if (document.readyState === 'complete') {
  584. readyFunc();
  585. }
  586. }
  587. if (document.addEventListener) {
  588. _bind(document, 'DOMContentLoaded', readyFunc);
  589. } else if (document.attachEvent) {
  590. _bind(document, 'readystatechange', ieReadyStateFunc);
  591. var toplevel = false;
  592. try {
  593. toplevel = window.frameElement == null;
  594. } catch(e) {}
  595. if (document.documentElement.doScroll && toplevel) {
  596. ieReadyFunc();
  597. }
  598. }
  599. _bind(window, 'load', readyFunc);
  600. }
  601. if (window.attachEvent) {
  602. window.attachEvent('onunload', function() {
  603. _each(_eventData, function(key, events) {
  604. if (events.el) {
  605. _unbind(events.el);
  606. }
  607. });
  608. });
  609. }
  610. K.ctrl = _ctrl;
  611. K.ready = _ready;
  612. function _getCssList(css) {
  613. css = css.replace(/&quot;/g, '"');
  614. var list = {},
  615. reg = /\s*([\w\-]+)\s*:([^;]*)(;|$)/g,
  616. match;
  617. while ((match = reg.exec(css))) {
  618. var key = _trim(match[1].toLowerCase()),
  619. val = _trim(_toHex(match[2]));
  620. list[key] = val;
  621. }
  622. return list;
  623. }
  624. function _getAttrList(tag) {
  625. var list = {},
  626. reg = /\s+(?:([\w\-:]+)|(?:([\w\-:]+)=([^\s"'<>]+))|(?:([\w\-:"]+)="([^"]*)")|(?:([\w\-:"]+)='([^']*)'))(?=(?:\s|\/|>)+)/g,
  627. match;
  628. while ((match = reg.exec(tag))) {
  629. var key = (match[1] || match[2] || match[4] || match[6]).toLowerCase(),
  630. val = (match[2] ? match[3] : (match[4] ? match[5] : match[7])) || '';
  631. list[key] = val;
  632. }
  633. return list;
  634. }
  635. function _addClassToTag(tag, className) {
  636. if (/\s+class\s*=/.test(tag)) {
  637. tag = tag.replace(/(\s+class=["']?)([^"']*)(["']?[\s>])/, function($0, $1, $2, $3) {
  638. if ((' ' + $2 + ' ').indexOf(' ' + className + ' ') < 0) {
  639. return $2 === '' ? $1 + className + $3 : $1 + $2 + ' ' + className + $3;
  640. } else {
  641. return $0;
  642. }
  643. });
  644. } else {
  645. tag = tag.substr(0, tag.length - 1) + ' class="' + className + '">';
  646. }
  647. return tag;
  648. }
  649. function _formatCss(css) {
  650. var str = '';
  651. _each(_getCssList(css), function(key, val) {
  652. str += key + ':' + val + ';';
  653. });
  654. return str;
  655. }
  656. function _formatUrl(url, mode, host, pathname) {
  657. return url;
  658. mode = _undef(mode, '').toLowerCase();
  659. if (url.substr(0, 5) != 'data:') {
  660. url = url.replace(/([^:])\/\//g, '$1/');
  661. }
  662. if (_inArray(mode, ['absolute', 'relative', 'domain']) < 0) {
  663. return url;
  664. }
  665. host = host || location.protocol + '//' + location.host;
  666. if (pathname === undefined) {
  667. var m = location.pathname.match(/^(\/.*)\//);
  668. pathname = m ? m[1] : '';
  669. }
  670. var match;
  671. if ((match = /^(\w+:\/\/[^\/]*)/.exec(url))) {
  672. if (match[1] !== host) {
  673. return url;
  674. }
  675. } else if (/^\w+:/.test(url)) {
  676. return url;
  677. }
  678. function getRealPath(path) {
  679. var parts = path.split('/'), paths = [];
  680. for (var i = 0, len = parts.length; i < len; i++) {
  681. var part = parts[i];
  682. if (part == '..') {
  683. if (paths.length > 0) {
  684. paths.pop();
  685. }
  686. } else if (part !== '' && part != '.') {
  687. paths.push(part);
  688. }
  689. }
  690. return '/' + paths.join('/');
  691. }
  692. if (/^\//.test(url)) {
  693. url = host + getRealPath(url.substr(1));
  694. } else if (!/^\w+:\/\//.test(url)) {
  695. url = host + getRealPath(pathname + '/' + url);
  696. }
  697. function getRelativePath(path, depth) {
  698. if (url.substr(0, path.length) === path) {
  699. var arr = [];
  700. for (var i = 0; i < depth; i++) {
  701. arr.push('..');
  702. }
  703. var prefix = '.';
  704. if (arr.length > 0) {
  705. prefix += '/' + arr.join('/');
  706. }
  707. if (pathname == '/') {
  708. prefix += '/';
  709. }
  710. return prefix + url.substr(path.length);
  711. } else {
  712. if ((match = /^(.*)\//.exec(path))) {
  713. return getRelativePath(match[1], ++depth);
  714. }
  715. }
  716. }
  717. if (mode === 'relative') {
  718. url = getRelativePath(host + pathname, 0).substr(2);
  719. } else if (mode === 'absolute') {
  720. if (url.substr(0, host.length) === host) {
  721. url = url.substr(host.length);
  722. }
  723. }
  724. return url;
  725. }
  726. function _formatHtml(html, htmlTags, urlType, wellFormatted, indentChar) {
  727. if (html == null) {
  728. html = '';
  729. }
  730. urlType = urlType || '';
  731. wellFormatted = _undef(wellFormatted, false);
  732. indentChar = _undef(indentChar, '\t');
  733. var fontSizeList = 'xx-small,x-small,small,medium,large,x-large,xx-large'.split(',');
  734. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  735. return $1 + $2.replace(/<(?:br|br\s[^>]*)>/ig, '\n') + $3;
  736. });
  737. html = html.replace(/<(?:br|br\s[^>]*)\s*\/?>\s*<\/p>/ig, '</p>');
  738. html = html.replace(/(<(?:p|p\s[^>]*)>)\s*(<\/p>)/ig, '$1<br />$2');
  739. html = html.replace(/\u200B/g, '');
  740. html = html.replace(/\u00A9/g, '&copy;');
  741. html = html.replace(/\u00AE/g, '&reg;');
  742. html = html.replace(/\u2003/g, '&emsp;');
  743. html = html.replace(/\u3000/g, '&emsp;');
  744. html = html.replace(/&quot;/g, '');
  745. html = html.replace(/, " helvetica=""(.*?)"="/g, '');
  746. html = html.replace(/<[^>]+/g, function($0) {
  747. return $0.replace(/\s+/g, ' ');
  748. });
  749. var htmlTagMap = {};
  750. if (htmlTags) {
  751. _each(htmlTags, function(key, val) {
  752. var arr = key.split(',');
  753. for (var i = 0, len = arr.length; i < len; i++) {
  754. htmlTagMap[arr[i]] = _toMap(val);
  755. }
  756. });
  757. if (!htmlTagMap.script) {
  758. html = html.replace(/(<(?:script|script\s[^>]*)>)([\s\S]*?)(<\/script>)/ig, '');
  759. }
  760. if (!htmlTagMap.style) {
  761. html = html.replace(/(<(?:style|style\s[^>]*)>)([\s\S]*?)(<\/style>)/ig, '');
  762. }
  763. }
  764. var re = /(\s*)<(\/)?([\w\-:]+)((?:\s+|(?:\s+[\w\-:]+)|(?:\s+[\w\-:]+=[^\s"'<>]+)|(?:\s+[\w\-:"]+="[^"]*")|(?:\s+[\w\-:"]+='[^']*'))*)(\/)?>(\s*)/g;
  765. var tagStack = [];
  766. html = html.replace(re, function($0, $1, $2, $3, $4, $5, $6) {
  767. var full = $0,
  768. startNewline = $1 || '',
  769. startSlash = $2 || '',
  770. tagName = $3.toLowerCase(),
  771. attr = $4 || '',
  772. endSlash = $5 ? ' ' + $5 : '',
  773. endNewline = $6 || '';
  774. if (htmlTags && !htmlTagMap[tagName]) {
  775. return '';
  776. }
  777. if (endSlash === '' && _SINGLE_TAG_MAP[tagName]) {
  778. endSlash = ' /';
  779. }
  780. if (_INLINE_TAG_MAP[tagName]) {
  781. if (startNewline) {
  782. startNewline = ' ';
  783. }
  784. if (endNewline) {
  785. endNewline = ' ';
  786. }
  787. }
  788. if (_PRE_TAG_MAP[tagName]) {
  789. if (startSlash) {
  790. endNewline = '\n';
  791. } else {
  792. startNewline = '\n';
  793. }
  794. }
  795. if (wellFormatted && tagName == 'br') {
  796. endNewline = '\n';
  797. }
  798. if (_BLOCK_TAG_MAP[tagName] && !_PRE_TAG_MAP[tagName]) {
  799. if (wellFormatted) {
  800. if (startSlash && tagStack.length > 0 && tagStack[tagStack.length - 1] === tagName) {
  801. tagStack.pop();
  802. } else {
  803. tagStack.push(tagName);
  804. }
  805. startNewline = '\n';
  806. endNewline = '\n';
  807. for (var i = 0, len = startSlash ? tagStack.length : tagStack.length - 1; i < len; i++) {
  808. startNewline += indentChar;
  809. if (!startSlash) {
  810. endNewline += indentChar;
  811. }
  812. }
  813. if (endSlash) {
  814. tagStack.pop();
  815. } else if (!startSlash) {
  816. endNewline += indentChar;
  817. }
  818. } else {
  819. startNewline = endNewline = '';
  820. }
  821. }
  822. if (attr !== '') {
  823. var attrMap = _getAttrList(full);
  824. if (tagName === 'font') {
  825. var fontStyleMap = {}, fontStyle = '';
  826. _each(attrMap, function(key, val) {
  827. if (key === 'color') {
  828. fontStyleMap.color = val;
  829. delete attrMap[key];
  830. }
  831. if (key === 'size') {
  832. fontStyleMap['font-size'] = fontSizeList[parseInt(val, 10) - 1] || '';
  833. delete attrMap[key];
  834. }
  835. if (key === 'face') {
  836. fontStyleMap['font-family'] = val;
  837. delete attrMap[key];
  838. }
  839. if (key === 'style') {
  840. fontStyle = val;
  841. }
  842. });
  843. if (fontStyle && !/;$/.test(fontStyle)) {
  844. fontStyle += ';';
  845. }
  846. _each(fontStyleMap, function(key, val) {
  847. if (val === '') {
  848. return;
  849. }
  850. if (/\s/.test(val)) {
  851. val = "'" + val + "'";
  852. }
  853. fontStyle += key + ':' + val + ';';
  854. });
  855. attrMap.style = fontStyle;
  856. }
  857. _each(attrMap, function(key, val) {
  858. if (_FILL_ATTR_MAP[key]) {
  859. attrMap[key] = key;
  860. }
  861. if (_inArray(key, ['src', 'href']) >= 0) {
  862. attrMap[key] = _formatUrl(val, urlType);
  863. }
  864. if (htmlTags && key !== 'style' && !htmlTagMap[tagName]['*'] && !htmlTagMap[tagName][key] ||
  865. tagName === 'body' && key === 'contenteditable' ||
  866. /^kindeditor_\d+$/.test(key)) {
  867. delete attrMap[key];
  868. }
  869. if (key === 'style' && val !== '') {
  870. var styleMap = _getCssList(val);
  871. _each(styleMap, function(k, v) {
  872. if (htmlTags && !htmlTagMap[tagName].style && !htmlTagMap[tagName]['.' + k]) {
  873. delete styleMap[k];
  874. }
  875. });
  876. var style = '';
  877. _each(styleMap, function(k, v) {
  878. style += k + ':' + v + ';';
  879. });
  880. attrMap.style = style;
  881. }
  882. });
  883. attr = '';
  884. _each(attrMap, function(key, val) {
  885. if (key === 'style' && val === '') {
  886. return;
  887. }
  888. val = val.replace(/"/g, '&quot;');
  889. attr += ' ' + key + '="' + val + '"';
  890. });
  891. }
  892. if (tagName === 'font') {
  893. tagName = 'span';
  894. }
  895. return startNewline + '<' + startSlash + tagName + attr + endSlash + '>' + endNewline;
  896. });
  897. html = html.replace(/(<(?:pre|pre\s[^>]*)>)([\s\S]*?)(<\/pre>)/ig, function($0, $1, $2, $3) {
  898. return $1 + $2.replace(/\n/g, '<span id="__kindeditor_pre_newline__">\n') + $3;
  899. });
  900. html = html.replace(/\n\s*\n/g, '\n');
  901. html = html.replace(/<span id="__kindeditor_pre_newline__">\n/g, '\n');
  902. return _trim(html);
  903. }
  904. function _clearMsWord(html, htmlTags) {
  905. html = html.replace(/<meta[\s\S]*?>/ig, '')
  906. .replace(/<![\s\S]*?>/ig, '')
  907. .replace(/<style[^>]*>[\s\S]*?<\/style>/ig, '')
  908. .replace(/<script[^>]*>[\s\S]*?<\/script>/ig, '')
  909. .replace(/<w:[^>]+>[\s\S]*?<\/w:[^>]+>/ig, '')
  910. .replace(/<o:[^>]+>[\s\S]*?<\/o:[^>]+>/ig, '')
  911. .replace(/<xml>[\s\S]*?<\/xml>/ig, '')
  912. .replace(/<(?:table|td)[^>]*>/ig, function(full) {
  913. return full.replace(/border-bottom:([#\w\s]+)/ig, 'border:$1');
  914. });
  915. return _formatHtml(html, htmlTags);
  916. }
  917. function _mediaType(src) {
  918. if (/\.(rm|rmvb)(\?|$)/i.test(src)) {
  919. return 'audio/x-pn-realaudio-plugin';
  920. }
  921. if (/\.(swf|flv)(\?|$)/i.test(src)) {
  922. return 'application/x-shockwave-flash';
  923. }
  924. return 'video/x-ms-asf-plugin';
  925. }
  926. function _mediaClass(type) {
  927. if (/realaudio/i.test(type)) {
  928. return 'ke-rm';
  929. }
  930. if (/flash/i.test(type)) {
  931. return 'ke-flash';
  932. }
  933. return 'ke-media';
  934. }
  935. function _mediaAttrs(srcTag) {
  936. return _getAttrList(unescape(srcTag));
  937. }
  938. function _mediaEmbed(attrs) {
  939. var html = '<embed ';
  940. _each(attrs, function(key, val) {
  941. html += key + '="' + val + '" ';
  942. });
  943. html += '/>';
  944. return html;
  945. }
  946. function _mediaImg(blankPath, attrs) {
  947. var width = attrs.width,
  948. height = attrs.height,
  949. type = attrs.type || _mediaType(attrs.src),
  950. srcTag = _mediaEmbed(attrs),
  951. style = '';
  952. if (/\D/.test(width)) {
  953. style += 'width:' + width + ';';
  954. } else if (width > 0) {
  955. style += 'width:' + width + 'px;';
  956. }
  957. if (/\D/.test(height)) {
  958. style += 'height:' + height + ';';
  959. } else if (height > 0) {
  960. style += 'height:' + height + 'px;';
  961. }
  962. var html = '<img class="' + _mediaClass(type) + '" src="' + blankPath + '" ';
  963. if (style !== '') {
  964. html += 'style="' + style + '" ';
  965. }
  966. html += 'data-ke-tag="' + escape(srcTag) + '" alt="" />';
  967. return html;
  968. }
  969. function _tmpl(str, data) {
  970. var fn = new Function("obj",
  971. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  972. "with(obj){p.push('" +
  973. str.replace(/[\r\t\n]/g, " ")
  974. .split("<%").join("\t")
  975. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  976. .replace(/\t=(.*?)%>/g, "',$1,'")
  977. .split("\t").join("');")
  978. .split("%>").join("p.push('")
  979. .split("\r").join("\\'") + "');}return p.join('');");
  980. return data ? fn(data) : fn;
  981. }
  982. K.formatUrl = _formatUrl;
  983. K.formatHtml = _formatHtml;
  984. K.getCssList = _getCssList;
  985. K.getAttrList = _getAttrList;
  986. K.mediaType = _mediaType;
  987. K.mediaAttrs = _mediaAttrs;
  988. K.mediaEmbed = _mediaEmbed;
  989. K.mediaImg = _mediaImg;
  990. K.clearMsWord = _clearMsWord;
  991. K.tmpl = _tmpl;
  992. function _contains(nodeA, nodeB) {
  993. if (nodeA.nodeType == 9 && nodeB.nodeType != 9) {
  994. return true;
  995. }
  996. while ((nodeB = nodeB.parentNode)) {
  997. if (nodeB == nodeA) {
  998. return true;
  999. }
  1000. }
  1001. return false;
  1002. }
  1003. var _getSetAttrDiv = document.createElement('div');
  1004. _getSetAttrDiv.setAttribute('className', 't');
  1005. var _GET_SET_ATTRIBUTE = _getSetAttrDiv.className !== 't';
  1006. function _getAttr(el, key) {
  1007. key = key.toLowerCase();
  1008. var val = null;
  1009. if (!_GET_SET_ATTRIBUTE && el.nodeName.toLowerCase() != 'script') {
  1010. var div = el.ownerDocument.createElement('div');
  1011. div.appendChild(el.cloneNode(false));
  1012. var list = _getAttrList(_unescape(div.innerHTML));
  1013. if (key in list) {
  1014. val = list[key];
  1015. }
  1016. } else {
  1017. try {
  1018. val = el.getAttribute(key, 2);
  1019. } catch(e) {
  1020. val = el.getAttribute(key, 1);
  1021. }
  1022. }
  1023. if (key === 'style' && val !== null) {
  1024. val = _formatCss(val);
  1025. }
  1026. return val;
  1027. }
  1028. function _queryAll(expr, root) {
  1029. var exprList = expr.split(',');
  1030. if (exprList.length > 1) {
  1031. var mergedResults = [];
  1032. _each(exprList, function() {
  1033. _each(_queryAll(this, root), function() {
  1034. if (_inArray(this, mergedResults) < 0) {
  1035. mergedResults.push(this);
  1036. }
  1037. });
  1038. });
  1039. return mergedResults;
  1040. }
  1041. root = root || document;
  1042. function escape(str) {
  1043. if (typeof str != 'string') {
  1044. return str;
  1045. }
  1046. return str.replace(/([^\w\-])/g, '\\$1');
  1047. }
  1048. function stripslashes(str) {
  1049. return str.replace(/\\/g, '');
  1050. }
  1051. function cmpTag(tagA, tagB) {
  1052. return tagA === '*' || tagA.toLowerCase() === escape(tagB.toLowerCase());
  1053. }
  1054. function byId(id, tag, root) {
  1055. var arr = [],
  1056. doc = root.ownerDocument || root,
  1057. el = doc.getElementById(stripslashes(id));
  1058. if (el) {
  1059. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1060. arr.push(el);
  1061. }
  1062. }
  1063. return arr;
  1064. }
  1065. function byClass(className, tag, root) {
  1066. var doc = root.ownerDocument || root, arr = [], els, i, len, el;
  1067. if (root.getElementsByClassName) {
  1068. els = root.getElementsByClassName(stripslashes(className));
  1069. for (i = 0, len = els.length; i < len; i++) {
  1070. el = els[i];
  1071. if (cmpTag(tag, el.nodeName)) {
  1072. arr.push(el);
  1073. }
  1074. }
  1075. } else if (doc.querySelectorAll) {
  1076. els = doc.querySelectorAll((root.nodeName !== '#document' ? root.nodeName + ' ' : '') + tag + '.' + className);
  1077. for (i = 0, len = els.length; i < len; i++) {
  1078. el = els[i];
  1079. if (_contains(root, el)) {
  1080. arr.push(el);
  1081. }
  1082. }
  1083. } else {
  1084. els = root.getElementsByTagName(tag);
  1085. className = ' ' + className + ' ';
  1086. for (i = 0, len = els.length; i < len; i++) {
  1087. el = els[i];
  1088. if (el.nodeType == 1) {
  1089. var cls = el.className;
  1090. if (cls && (' ' + cls + ' ').indexOf(className) > -1) {
  1091. arr.push(el);
  1092. }
  1093. }
  1094. }
  1095. }
  1096. return arr;
  1097. }
  1098. function byName(name, tag, root) {
  1099. var arr = [], doc = root.ownerDocument || root,
  1100. els = doc.getElementsByName(stripslashes(name)), el;
  1101. for (var i = 0, len = els.length; i < len; i++) {
  1102. el = els[i];
  1103. if (cmpTag(tag, el.nodeName) && _contains(root, el)) {
  1104. if (el.getAttribute('name') !== null) {
  1105. arr.push(el);
  1106. }
  1107. }
  1108. }
  1109. return arr;
  1110. }
  1111. function byAttr(key, val, tag, root) {
  1112. var arr = [], els = root.getElementsByTagName(tag), el;
  1113. for (var i = 0, len = els.length; i < len; i++) {
  1114. el = els[i];
  1115. if (el.nodeType == 1) {
  1116. if (val === null) {
  1117. if (_getAttr(el, key) !== null) {
  1118. arr.push(el);
  1119. }
  1120. } else {
  1121. if (val === escape(_getAttr(el, key))) {
  1122. arr.push(el);
  1123. }
  1124. }
  1125. }
  1126. }
  1127. return arr;
  1128. }
  1129. function select(expr, root) {
  1130. var arr = [], matches;
  1131. matches = /^((?:\\.|[^.#\s\[<>])+)/.exec(expr);
  1132. var tag = matches ? matches[1] : '*';
  1133. if ((matches = /#((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1134. arr = byId(matches[1], tag, root);
  1135. } else if ((matches = /\.((?:[\w\-]|\\.)+)$/.exec(expr))) {
  1136. arr = byClass(matches[1], tag, root);
  1137. } else if ((matches = /\[((?:[\w\-]|\\.)+)\]/.exec(expr))) {
  1138. arr = byAttr(matches[1].toLowerCase(), null, tag, root);
  1139. } else if ((matches = /\[((?:[\w\-]|\\.)+)\s*=\s*['"]?((?:\\.|[^'"]+)+)['"]?\]/.exec(expr))) {
  1140. var key = matches[1].toLowerCase(), val = matches[2];
  1141. if (key === 'id') {
  1142. arr = byId(val, tag, root);
  1143. } else if (key === 'class') {
  1144. arr = byClass(val, tag, root);
  1145. } else if (key === 'name') {
  1146. arr = byName(val, tag, root);
  1147. } else {
  1148. arr = byAttr(key, val, tag, root);
  1149. }
  1150. } else {
  1151. var els = root.getElementsByTagName(tag), el;
  1152. for (var i = 0, len = els.length; i < len; i++) {
  1153. el = els[i];
  1154. if (el.nodeType == 1) {
  1155. arr.push(el);
  1156. }
  1157. }
  1158. }
  1159. return arr;
  1160. }
  1161. var parts = [], arr, re = /((?:\\.|[^\s>])+|[\s>])/g;
  1162. while ((arr = re.exec(expr))) {
  1163. if (arr[1] !== ' ') {
  1164. parts.push(arr[1]);
  1165. }
  1166. }
  1167. var results = [];
  1168. if (parts.length == 1) {
  1169. return select(parts[0], root);
  1170. }
  1171. var isChild = false, part, els, subResults, val, v, i, j, k, length, len, l;
  1172. for (i = 0, lenth = parts.length; i < lenth; i++) {
  1173. part = parts[i];
  1174. if (part === '>') {
  1175. isChild = true;
  1176. continue;
  1177. }
  1178. if (i > 0) {
  1179. els = [];
  1180. for (j = 0, len = results.length; j < len; j++) {
  1181. val = results[j];
  1182. subResults = select(part, val);
  1183. for (k = 0, l = subResults.length; k < l; k++) {
  1184. v = subResults[k];
  1185. if (isChild) {
  1186. if (val === v.parentNode) {
  1187. els.push(v);
  1188. }
  1189. } else {
  1190. els.push(v);
  1191. }
  1192. }
  1193. }
  1194. results = els;
  1195. } else {
  1196. results = select(part, root);
  1197. }
  1198. if (results.length === 0) {
  1199. return [];
  1200. }
  1201. }
  1202. return results;
  1203. }
  1204. function _query(expr, root) {
  1205. var arr = _queryAll(expr, root);
  1206. return arr.length > 0 ? arr[0] : null;
  1207. }
  1208. K.query = _query;
  1209. K.queryAll = _queryAll;
  1210. function _get(val) {
  1211. return K(val)[0];
  1212. }
  1213. function _getDoc(node) {
  1214. if (!node) {
  1215. return document;
  1216. }
  1217. return node.ownerDocument || node.document || node;
  1218. }
  1219. function _getWin(node) {
  1220. if (!node) {
  1221. return window;
  1222. }
  1223. var doc = _getDoc(node);
  1224. return doc.parentWindow || doc.defaultView;
  1225. }
  1226. function _setHtml(el, html) {
  1227. if (el.nodeType != 1) {
  1228. return;
  1229. }
  1230. var doc = _getDoc(el);
  1231. try {
  1232. el.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + html;
  1233. var temp = doc.getElementById('__kindeditor_temp_tag__');
  1234. temp.parentNode.removeChild(temp);
  1235. } catch(e) {
  1236. K(el).empty();
  1237. K('@' + html, doc).each(function() {
  1238. el.appendChild(this);
  1239. });
  1240. }
  1241. }
  1242. function _hasClass(el, cls) {
  1243. return _inString(cls, el.className, ' ');
  1244. }
  1245. function _setAttr(el, key, val) {
  1246. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1247. key = 'className';
  1248. }
  1249. el.setAttribute(key, '' + val);
  1250. }
  1251. function _removeAttr(el, key) {
  1252. if (_IE && _V < 8 && key.toLowerCase() == 'class') {
  1253. key = 'className';
  1254. }
  1255. _setAttr(el, key, '');
  1256. el.removeAttribute(key);
  1257. }
  1258. function _getNodeName(node) {
  1259. if (!node || !node.nodeName) {
  1260. return '';
  1261. }
  1262. return node.nodeName.toLowerCase();
  1263. }
  1264. function _computedCss(el, key) {
  1265. var self = this, win = _getWin(el), camelKey = _toCamel(key), val = '';
  1266. if (win.getComputedStyle) {
  1267. var style = win.getComputedStyle(el, null);
  1268. val = style[camelKey] || style.getPropertyValue(key) || el.style[camelKey];
  1269. } else if (el.currentStyle) {
  1270. val = el.currentStyle[camelKey] || el.style[camelKey];
  1271. }
  1272. return val;
  1273. }
  1274. function _hasVal(node) {
  1275. return !!_VALUE_TAG_MAP[_getNodeName(node)];
  1276. }
  1277. function _docElement(doc) {
  1278. doc = doc || document;
  1279. return _QUIRKS ? doc.body : doc.documentElement;
  1280. }
  1281. function _docHeight(doc) {
  1282. var el = _docElement(doc);
  1283. return Math.max(el.scrollHeight, el.clientHeight);
  1284. }
  1285. function _docWidth(doc) {
  1286. var el = _docElement(doc);
  1287. return Math.max(el.scrollWidth, el.clientWidth);
  1288. }
  1289. function _getScrollPos(doc) {
  1290. doc = doc || document;
  1291. var x, y;
  1292. if (_IE || _NEWIE || _OPERA) {
  1293. x = _docElement(doc).scrollLeft;
  1294. y = _docElement(doc).scrollTop;
  1295. } else {
  1296. x = _getWin(doc).scrollX;
  1297. y = _getWin(doc).scrollY;
  1298. }
  1299. return {x : x, y : y};
  1300. }
  1301. function KNode(node) {
  1302. this.init(node);
  1303. }
  1304. _extend(KNode, {
  1305. init : function(node) {
  1306. var self = this;
  1307. node = _isArray(node) ? node : [node];
  1308. var length = 0;
  1309. for (var i = 0, len = node.length; i < len; i++) {
  1310. if (node[i]) {
  1311. self[i] = node[i].constructor === KNode ? node[i][0] : node[i];
  1312. length++;
  1313. }
  1314. }
  1315. self.length = length;
  1316. self.doc = _getDoc(self[0]);
  1317. self.name = _getNodeName(self[0]);
  1318. self.type = self.length > 0 ? self[0].nodeType : null;
  1319. self.win = _getWin(self[0]);
  1320. },
  1321. each : function(fn) {
  1322. var self = this;
  1323. for (var i = 0; i < self.length; i++) {
  1324. if (fn.call(self[i], i, self[i]) === false) {
  1325. return self;
  1326. }
  1327. }
  1328. return self;
  1329. },
  1330. bind : function(type, fn) {
  1331. this.each(function() {
  1332. _bind(this, type, fn);
  1333. });
  1334. return this;
  1335. },
  1336. unbind : function(type, fn) {
  1337. this.each(function() {
  1338. _unbind(this, type, fn);
  1339. });
  1340. return this;
  1341. },
  1342. fire : function(type) {
  1343. if (this.length < 1) {
  1344. return this;
  1345. }
  1346. _fire(this[0], type);
  1347. return this;
  1348. },
  1349. hasAttr : function(key) {
  1350. if (this.length < 1) {
  1351. return false;
  1352. }
  1353. return !!_getAttr(this[0], key);
  1354. },
  1355. attr : function(key, val) {
  1356. var self = this;
  1357. if (key === undefined) {
  1358. return _getAttrList(self.outer());
  1359. }
  1360. if (typeof key === 'object') {
  1361. _each(key, function(k, v) {
  1362. self.attr(k, v);
  1363. });
  1364. return self;
  1365. }
  1366. if (val === undefined) {
  1367. val = self.length < 1 ? null : _getAttr(self[0], key);
  1368. return val === null ? '' : val;
  1369. }
  1370. self.each(function() {
  1371. _setAttr(this, key, val);
  1372. });
  1373. return self;
  1374. },
  1375. removeAttr : function(key) {
  1376. this.each(function() {
  1377. _removeAttr(this, key);
  1378. });
  1379. return this;
  1380. },
  1381. get : function(i) {
  1382. if (this.length < 1) {
  1383. return null;
  1384. }
  1385. return this[i || 0];
  1386. },
  1387. eq : function(i) {
  1388. if (this.length < 1) {
  1389. return null;
  1390. }
  1391. return this[i] ? new KNode(this[i]) : null;
  1392. },
  1393. hasClass : function(cls) {
  1394. if (this.length < 1) {
  1395. return false;
  1396. }
  1397. return _hasClass(this[0], cls);
  1398. },
  1399. addClass : function(cls) {
  1400. this.each(function() {
  1401. if (!_hasClass(this, cls)) {
  1402. this.className = _trim(this.className + ' ' + cls);
  1403. }
  1404. });
  1405. return this;
  1406. },
  1407. removeClass : function(cls) {
  1408. this.each(function() {
  1409. if (_hasClass(this, cls)) {
  1410. this.className = _trim(this.className.replace(new RegExp('(^|\\s)' + cls + '(\\s|$)'), ' '));
  1411. }
  1412. });
  1413. return this;
  1414. },
  1415. html : function(val) {
  1416. var self = this;
  1417. if (val === undefined) {
  1418. if (self.length < 1 || self.type != 1) {
  1419. return '';
  1420. }
  1421. return _formatHtml(self[0].innerHTML);
  1422. }
  1423. self.each(function() {
  1424. _setHtml(this, val);
  1425. });
  1426. return self;
  1427. },
  1428. text : function() {
  1429. var self = this;
  1430. if (self.length < 1) {
  1431. return '';
  1432. }
  1433. return _IE ? self[0].innerText : self[0].textContent;
  1434. },
  1435. hasVal : function() {
  1436. if (this.length < 1) {
  1437. return false;
  1438. }
  1439. return _hasVal(this[0]);
  1440. },
  1441. val : function(val) {
  1442. var self = this;
  1443. if (val === undefined) {
  1444. if (self.length < 1) {
  1445. return '';
  1446. }
  1447. return self.hasVal() ? self[0].value : self.attr('value');
  1448. } else {
  1449. self.each(function() {
  1450. if (_hasVal(this)) {
  1451. this.value = val;
  1452. } else {
  1453. _setAttr(this, 'value' , val);
  1454. }
  1455. });
  1456. return self;
  1457. }
  1458. },
  1459. css : function(key, val) {
  1460. var self = this;
  1461. if (key === undefined) {
  1462. return _getCssList(self.attr('style'));
  1463. }
  1464. if (typeof key === 'object') {
  1465. _each(key, function(k, v) {
  1466. self.css(k, v);
  1467. });
  1468. return self;
  1469. }
  1470. if (val === undefined) {
  1471. if (self.length < 1) {
  1472. return '';
  1473. }
  1474. return self[0].style[_toCamel(key)] || _computedCss(self[0], key) || '';
  1475. }
  1476. self.each(function() {
  1477. this.style[_toCamel(key)] = val;
  1478. });
  1479. return self;
  1480. },
  1481. width : function(val) {
  1482. var self = this;
  1483. if (val === undefined) {
  1484. if (self.length < 1) {
  1485. return 0;
  1486. }
  1487. return self[0].offsetWidth;
  1488. }
  1489. return self.css('width', _addUnit(val));
  1490. },
  1491. height : function(val) {
  1492. var self = this;
  1493. if (val === undefined) {
  1494. if (self.length < 1) {
  1495. return 0;
  1496. }
  1497. return self[0].offsetHeight;
  1498. }
  1499. return self.css('height', _addUnit(val));
  1500. },
  1501. opacity : function(val) {
  1502. this.each(function() {
  1503. if (this.style.opacity === undefined) {
  1504. this.style.filter = val == 1 ? '' : 'alpha(opacity=' + (val * 100) + ')';
  1505. } else {
  1506. this.style.opacity = val == 1 ? '' : val;
  1507. }
  1508. });
  1509. return this;
  1510. },
  1511. data : function(key, val) {
  1512. var self = this;
  1513. key = 'kindeditor_data_' + key;
  1514. if (val === undefined) {
  1515. if (self.length < 1) {
  1516. return null;
  1517. }
  1518. return self[0][key];
  1519. }
  1520. this.each(function() {
  1521. this[key] = val;
  1522. });
  1523. return self;
  1524. },
  1525. pos : function() {
  1526. var self = this, node = self[0], x = 0, y = 0;
  1527. if (node) {
  1528. if (node.getBoundingClientRect) {
  1529. var box = node.getBoundingClientRect(),
  1530. pos = _getScrollPos(self.doc);
  1531. x = box.left + pos.x;
  1532. y = box.top + pos.y;
  1533. } else {
  1534. while (node) {
  1535. x += node.offsetLeft;
  1536. y += node.offsetTop;
  1537. node = node.offsetParent;
  1538. }
  1539. }
  1540. }
  1541. return {x : _round(x), y : _round(y)};
  1542. },
  1543. clone : function(bool) {
  1544. if (this.length < 1) {
  1545. return new KNode([]);
  1546. }
  1547. return new KNode(this[0].cloneNode(bool));
  1548. },
  1549. append : function(expr) {
  1550. this.each(function() {
  1551. if (this.appendChild) {
  1552. this.appendChild(_get(expr));
  1553. }
  1554. });
  1555. return this;
  1556. },
  1557. appendTo : function(expr) {
  1558. this.each(function() {
  1559. _get(expr).appendChild(this);
  1560. });
  1561. return this;
  1562. },
  1563. before : function(expr) {
  1564. this.each(function() {
  1565. this.parentNode.insertBefore(_get(expr), this);
  1566. });
  1567. return this;
  1568. },
  1569. after : function(expr) {
  1570. this.each(function() {
  1571. if (this.nextSibling) {
  1572. this.parentNode.insertBefore(_get(expr), this.nextSibling);
  1573. } else {
  1574. this.parentNode.appendChild(_get(expr));
  1575. }
  1576. });
  1577. return this;
  1578. },
  1579. replaceWith : function(expr) {
  1580. var nodes = [];
  1581. this.each(function(i, node) {
  1582. _unbind(node);
  1583. var newNode = _get(expr);
  1584. node.parentNode.replaceChild(newNode, node);
  1585. nodes.push(newNode);
  1586. });
  1587. return K(nodes);
  1588. },
  1589. empty : function() {
  1590. var self = this;
  1591. self.each(function(i, node) {
  1592. var child = node.firstChild;
  1593. while (child) {
  1594. if (!node.parentNode) {
  1595. return;
  1596. }
  1597. var next = child.nextSibling;
  1598. child.parentNode.removeChild(child);
  1599. child = next;
  1600. }
  1601. });
  1602. return self;
  1603. },
  1604. remove : function(keepChilds) {
  1605. var self = this;
  1606. self.each(function(i, node) {
  1607. if (!node.parentNode) {
  1608. return;
  1609. }
  1610. _unbind(node);
  1611. if (keepChilds) {
  1612. var child = node.firstChild;
  1613. while (child) {
  1614. var next = child.nextSibling;
  1615. node.parentNode.insertBefore(child, node);
  1616. child = next;
  1617. }
  1618. }
  1619. node.parentNode.removeChild(node);
  1620. delete self[i];
  1621. });
  1622. self.length = 0;
  1623. return self;
  1624. },
  1625. show : function(val) {
  1626. var self = this;
  1627. if (val === undefined) {
  1628. val = self._originDisplay || '';
  1629. }
  1630. if (self.css('display') != 'none') {
  1631. return self;
  1632. }
  1633. return self.css('display', val);
  1634. },
  1635. hide : function() {
  1636. var self = this;
  1637. if (self.length < 1) {
  1638. return self;
  1639. }
  1640. self._originDisplay = self[0].style.display;
  1641. return self.css('display', 'none');
  1642. },
  1643. outer : function() {
  1644. var self = this;
  1645. if (self.length < 1) {
  1646. return '';
  1647. }
  1648. var div = self.doc.createElement('div'), html;
  1649. div.appendChild(self[0].cloneNode(true));
  1650. html = _formatHtml(div.innerHTML);
  1651. div = null;
  1652. return html;
  1653. },
  1654. isSingle : function() {
  1655. return !!_SINGLE_TAG_MAP[this.name];
  1656. },
  1657. isInline : function() {
  1658. return !!_INLINE_TAG_MAP[this.name];
  1659. },
  1660. isBlock : function() {
  1661. return !!_BLOCK_TAG_MAP[this.name];
  1662. },
  1663. isStyle : function() {
  1664. return !!_STYLE_TAG_MAP[this.name];
  1665. },
  1666. isControl : function() {
  1667. return !!_CONTROL_TAG_MAP[this.name];
  1668. },
  1669. contains : function(otherNode) {
  1670. if (this.length < 1) {
  1671. return false;
  1672. }
  1673. return _contains(this[0], _get(otherNode));
  1674. },
  1675. parent : function() {
  1676. if (this.length < 1) {
  1677. return null;
  1678. }
  1679. var node = this[0].parentNode;
  1680. return node ? new KNode(node) : null;
  1681. },
  1682. children : function() {
  1683. if (this.length < 1) {
  1684. return new KNode([]);
  1685. }
  1686. var list = [], child = this[0].firstChild;
  1687. while (child) {
  1688. if (child.nodeType != 3 || _trim(child.nodeValue) !== '') {
  1689. list.push(child);
  1690. }
  1691. child = child.nextSibling;
  1692. }
  1693. return new KNode(list);
  1694. },
  1695. first : function() {
  1696. var list = this.children();
  1697. return list.length > 0 ? list.eq(0) : null;
  1698. },
  1699. last : function() {
  1700. var list = this.children();
  1701. return list.length > 0 ? list.eq(list.length - 1) : null;
  1702. },
  1703. index : function() {
  1704. if (this.length < 1) {
  1705. return -1;
  1706. }
  1707. var i = -1, sibling = this[0];
  1708. while (sibling) {
  1709. i++;
  1710. sibling = sibling.previousSibling;
  1711. }
  1712. return i;
  1713. },
  1714. prev : function() {
  1715. if (this.length < 1) {
  1716. return null;
  1717. }
  1718. var node = this[0].previousSibling;
  1719. return node ? new KNode(node) : null;
  1720. },
  1721. next : function() {
  1722. if (this.length < 1) {
  1723. return null;
  1724. }
  1725. var node = this[0].nextSibling;
  1726. return node ? new KNode(node) : null;
  1727. },
  1728. scan : function(fn, order) {
  1729. if (this.length < 1) {
  1730. return;
  1731. }
  1732. order = (order === undefined) ? true : order;
  1733. function walk(node) {
  1734. var n = order ? node.firstChild : node.lastChild;
  1735. while (n) {
  1736. var next = order ? n.nextSibling : n.previousSibling;
  1737. if (fn(n) === false) {
  1738. return false;
  1739. }
  1740. if (walk(n) === false) {
  1741. return false;
  1742. }
  1743. n = next;
  1744. }
  1745. }
  1746. walk(this[0]);
  1747. return this;
  1748. }
  1749. });
  1750. _each(('blur,focus,focusin,focusout,load,resize,scroll,unload,click,dblclick,' +
  1751. 'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,' +
  1752. 'change,select,submit,keydown,keypress,keyup,error,contextmenu').split(','), function(i, type) {
  1753. KNode.prototype[type] = function(fn) {
  1754. return fn ? this.bind(type, fn) : this.fire(type);
  1755. };
  1756. });
  1757. var _K = K;
  1758. K = function(expr, root) {
  1759. if (expr === undefined || expr === null) {
  1760. return;
  1761. }
  1762. function newNode(node) {
  1763. if (!node[0]) {
  1764. node = [];
  1765. }
  1766. return new KNode(node);
  1767. }
  1768. if (typeof expr === 'string') {
  1769. if (root) {
  1770. root = _get(root);
  1771. }
  1772. var length = expr.length;
  1773. if (expr.charAt(0) === '@') {
  1774. expr = expr.substr(1);
  1775. }
  1776. if (expr.length !== length || /<.+>/.test(expr)) {
  1777. var doc = root ? root.ownerDocument || root : document,
  1778. div = doc.createElement('div'), list = [];
  1779. div.innerHTML = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + expr;
  1780. for (var i = 0, len = div.childNodes.length; i < len; i++) {
  1781. var child = div.childNodes[i];
  1782. if (child.id == '__kindeditor_temp_tag__') {
  1783. continue;
  1784. }
  1785. list.push(child);
  1786. }
  1787. return newNode(list);
  1788. }
  1789. return newNode(_queryAll(expr, root));
  1790. }
  1791. if (expr && expr.constructor === KNode) {
  1792. return expr;
  1793. }
  1794. if (expr.toArray) {
  1795. expr = expr.toArray();
  1796. }
  1797. if (_isArray(expr)) {
  1798. return newNode(expr);
  1799. }
  1800. return newNode(_toArray(arguments));
  1801. };
  1802. _each(_K, function(key, val) {
  1803. K[key] = val;
  1804. });
  1805. K.NodeClass = KNode;
  1806. window.KindEditor = K;
  1807. var _START_TO_START = 0,
  1808. _START_TO_END = 1,
  1809. _END_TO_END = 2,
  1810. _END_TO_START = 3,
  1811. _BOOKMARK_ID = 0;
  1812. function _updateCollapsed(range) {
  1813. range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
  1814. return range;
  1815. }
  1816. function _copyAndDelete(range, isCopy, isDelete) {
  1817. var doc = range.doc, nodeList = [];
  1818. function splitTextNode(node, startOffset, endOffset) {
  1819. var length = node.nodeValue.length, centerNode;
  1820. if (isCopy) {
  1821. var cloneNode = node.cloneNode(true);
  1822. if (startOffset > 0) {
  1823. centerNode = cloneNode.splitText(startOffset);
  1824. } else {
  1825. centerNode = cloneNode;
  1826. }
  1827. if (endOffset < length) {
  1828. centerNode.splitText(endOffset - startOffset);
  1829. }
  1830. }
  1831. if (isDelete) {
  1832. var center = node;
  1833. if (startOffset > 0) {
  1834. center = node.splitText(startOffset);
  1835. range.setStart(node, startOffset);
  1836. }
  1837. if (endOffset < length) {
  1838. var right = center.splitText(endOffset - startOffset);
  1839. range.setEnd(right, 0);
  1840. }
  1841. nodeList.push(center);
  1842. }
  1843. return centerNode;
  1844. }
  1845. function removeNodes() {
  1846. if (isDelete) {
  1847. range.up().collapse(true);
  1848. }
  1849. for (var i = 0, len = nodeList.length; i < len; i++) {
  1850. var node = nodeList[i];
  1851. if (node.parentNode) {
  1852. node.parentNode.removeChild(node);
  1853. }
  1854. }
  1855. }
  1856. var copyRange = range.cloneRange().down();
  1857. var start = -1, incStart = -1, incEnd = -1, end = -1,
  1858. ancestor = range.commonAncestor(), frag = doc.createDocumentFragment();
  1859. if (ancestor.nodeType == 3) {
  1860. var textNode = splitTextNode(ancestor, range.startOffset, range.endOffset);
  1861. if (isCopy) {
  1862. frag.appendChild(textNode);
  1863. }
  1864. removeNodes();
  1865. return isCopy ? frag : range;
  1866. }
  1867. function extractNodes(parent, frag) {
  1868. var node = parent.firstChild, nextNode;
  1869. while (node) {
  1870. var testRange = new KRange(doc).selectNode(node);
  1871. start = testRange.compareBoundaryPoints(_START_TO_END, range);
  1872. if (start >= 0 && incStart <= 0) {
  1873. incStart = testRange.compareBoundaryPoints(_START_TO_START, range);
  1874. }
  1875. if (incStart >= 0 && incEnd <= 0) {
  1876. incEnd = testRange.compareBoundaryPoints(_END_TO_END, range);
  1877. }
  1878. if (incEnd >= 0 && end <= 0) {
  1879. end = testRange.compareBoundaryPoints(_END_TO_START, range);
  1880. }
  1881. if (end >= 0) {
  1882. return false;
  1883. }
  1884. nextNode = node.nextSibling;
  1885. if (start > 0) {
  1886. if (node.nodeType == 1) {
  1887. if (incStart >= 0 && incEnd <= 0) {
  1888. if (isCopy) {
  1889. frag.appendChild(node.cloneNode(true));
  1890. }
  1891. if (isDelete) {
  1892. nodeList.push(node);
  1893. }
  1894. } else {
  1895. var childFlag;
  1896. if (isCopy) {
  1897. childFlag = node.cloneNode(false);
  1898. frag.appendChild(childFlag);
  1899. }
  1900. if (extractNodes(node, childFlag) === false) {
  1901. return false;
  1902. }
  1903. }
  1904. } else if (node.nodeType == 3) {
  1905. var textNode;
  1906. if (node == copyRange.startContainer) {
  1907. textNode = splitTextNode(node, copyRange.startOffset, node.nodeValue.length);
  1908. } else if (node == copyRange.endContainer) {
  1909. textNode = splitTextNode(node, 0, copyRange.endOffset);
  1910. } else {
  1911. textNode = splitTextNode(node, 0, node.nodeValue.length);
  1912. }
  1913. if (isCopy) {
  1914. try {
  1915. frag.appendChild(textNode);
  1916. } catch(e) {}
  1917. }
  1918. }
  1919. }
  1920. node = nextNode;
  1921. }
  1922. }
  1923. extractNodes(ancestor, frag);
  1924. if (isDelete) {
  1925. range.up().collapse(true);
  1926. }
  1927. for (var i = 0, len = nodeList.length; i < len; i++) {
  1928. var node = nodeList[i];
  1929. if (node.parentNode) {
  1930. node.parentNode.removeChild(node);
  1931. }
  1932. }
  1933. return isCopy ? frag : range;
  1934. }
  1935. function _moveToElementText(range, el) {
  1936. var node = el;
  1937. while (node) {
  1938. var knode = K(node);
  1939. if (knode.name == 'marquee' || knode.name == 'select') {
  1940. return;
  1941. }
  1942. node = node.parentNode;
  1943. }
  1944. try {
  1945. range.moveToElementText(el);
  1946. } catch(e) {}
  1947. }
  1948. function _getStartEnd(rng, isStart) {
  1949. var doc = rng.parentElement().ownerDocument,
  1950. pointRange = rng.duplicate();
  1951. pointRange.collapse(isStart);
  1952. var parent = pointRange.parentElement(),
  1953. nodes = parent.childNodes;
  1954. if (nodes.length === 0) {
  1955. return {node: parent.parentNode, offset: K(parent).index()};
  1956. }
  1957. var startNode = doc, startPos = 0, cmp = -1;
  1958. var testRange = rng.duplicate();
  1959. _moveToElementText(testRange, parent);
  1960. for (var i = 0, len = nodes.length; i < len; i++) {
  1961. var node = nodes[i];
  1962. cmp = testRange.compareEndPoints('StartToStart', pointRange);
  1963. if (cmp === 0) {
  1964. return {node: node.parentNode, offset: i};
  1965. }
  1966. if (node.nodeType == 1) {
  1967. var nodeRange = rng.duplicate(), dummy, knode = K(node), newNode = node;
  1968. if (knode.isControl()) {
  1969. dummy = doc.createElement('span');
  1970. knode.after(dummy);
  1971. newNode = dummy;
  1972. startPos += knode.text().replace(/\r\n|\n|\r/g, '').length;
  1973. }
  1974. _moveToElementText(nodeRange, newNode);
  1975. testRange.setEndPoint('StartToEnd', nodeRange);
  1976. if (cmp > 0) {
  1977. startPos += nodeRange.text.replace(/\r\n|\n|\r/g, '').length;
  1978. } else {
  1979. startPos = 0;
  1980. }
  1981. if (dummy) {
  1982. K(dummy).remove();
  1983. }
  1984. } else if (node.nodeType == 3) {
  1985. testRange.moveStart('character', node.nodeValue.length);
  1986. startPos += node.nodeValue.length;
  1987. }
  1988. if (cmp < 0) {
  1989. startNode = node;
  1990. }
  1991. }
  1992. if (cmp < 0 && startNode.nodeType == 1) {
  1993. return {node: parent, offset: K(parent.lastChild).index() + 1};
  1994. }
  1995. if (cmp > 0) {
  1996. while (startNode.nextSibling && startNode.nodeType == 1) {
  1997. startNode = startNode.nextSibling;
  1998. }
  1999. }
  2000. testRange = rng.duplicate();
  2001. _moveToElementText(testRange, parent);
  2002. testRange.setEndPoint('StartToEnd', pointRange);
  2003. startPos -= testRange.text.replace(/\r\n|\n|\r/g, '').length;
  2004. if (cmp > 0 && startNode.nodeType == 3) {
  2005. var prevNode = startNode.previousSibling;
  2006. while (prevNode && prevNode.nodeType == 3) {
  2007. startPos -= prevNode.nodeValue.length;
  2008. prevNode = prevNode.previousSibling;
  2009. }
  2010. }
  2011. return {node: startNode, offset: startPos};
  2012. }
  2013. function _getEndRange(node, offset) {
  2014. var doc = node.ownerDocument || node,
  2015. range = doc.body.createTextRange();
  2016. if (doc == node) {
  2017. range.collapse(true);
  2018. return range;
  2019. }
  2020. if (node.nodeType == 1 && node.childNodes.length > 0) {
  2021. var children = node.childNodes, isStart, child;
  2022. if (offset === 0) {
  2023. child = children[0];
  2024. isStart = true;
  2025. } else {
  2026. child = children[offset - 1];
  2027. isStart = false;
  2028. }
  2029. if (!child) {
  2030. return range;
  2031. }
  2032. if (K(child).name === 'head') {
  2033. if (offset === 1) {
  2034. isStart = true;
  2035. }
  2036. if (offset === 2) {
  2037. isStart = false;
  2038. }
  2039. range.collapse(isStart);
  2040. return range;
  2041. }
  2042. if (child.nodeType == 1) {
  2043. var kchild = K(child), span;
  2044. if (kchild.isControl()) {
  2045. span = doc.createElement('span');
  2046. if (isStart) {
  2047. kchild.before(span);
  2048. } else {
  2049. kchild.after(span);
  2050. }
  2051. child = span;
  2052. }
  2053. _moveToElementText(range, child);
  2054. range.collapse(isStart);
  2055. if (span) {
  2056. K(span).remove();
  2057. }
  2058. return range;
  2059. }
  2060. node = child;
  2061. offset = isStart ? 0 : child.nodeValue.length;
  2062. }
  2063. var dummy = doc.createElement('span');
  2064. K(node).before(dummy);
  2065. _moveToElementText(range, dummy);
  2066. range.moveStart('character', offset);
  2067. K(dummy).remove();
  2068. return range;
  2069. }
  2070. function _toRange(rng) {
  2071. var doc, range;
  2072. function tr2td(start) {
  2073. if (K(start.node).name == 'tr') {
  2074. start.node = start.node.cells[start.offset];
  2075. start.offset = 0;
  2076. }
  2077. }
  2078. if (_IERANGE) {
  2079. if (rng.item) {
  2080. doc = _getDoc(rng.item(0));
  2081. range = new KRange(doc);
  2082. range.selectNode(rng.item(0));
  2083. return range;
  2084. }
  2085. doc = rng.parentElement().ownerDocument;
  2086. var start = _getStartEnd(rng, true),
  2087. end = _getStartEnd(rng, false);
  2088. tr2td(start);
  2089. tr2td(end);
  2090. range = new KRange(doc);
  2091. range.setStart(start.node, start.offset);
  2092. range.setEnd(end.node, end.offset);
  2093. return range;
  2094. }
  2095. var startContainer = rng.startContainer;
  2096. doc = startContainer.ownerDocument || startContainer;
  2097. range = new KRange(doc);
  2098. range.setStart(startContainer, rng.startOffset);
  2099. range.setEnd(rng.endContainer, rng.endOffset);
  2100. return range;
  2101. }
  2102. function KRange(doc) {
  2103. this.init(doc);
  2104. }
  2105. _extend(KRange, {
  2106. init : function(doc) {
  2107. var self = this;
  2108. self.startContainer = doc;
  2109. self.startOffset = 0;
  2110. self.endContainer = doc;
  2111. self.endOffset = 0;
  2112. self.collapsed = true;
  2113. self.doc = doc;
  2114. },
  2115. commonAncestor : function() {
  2116. function getParents(node) {
  2117. var parents = [];
  2118. while (node) {
  2119. parents.push(node);
  2120. node = node.parentNode;
  2121. }
  2122. return parents;
  2123. }
  2124. var parentsA = getParents(this.startContainer),
  2125. parentsB = getParents(this.endContainer),
  2126. i = 0, lenA = parentsA.length, lenB = parentsB.length, parentA, parentB;
  2127. while (++i) {
  2128. parentA = parentsA[lenA - i];
  2129. parentB = parentsB[lenB - i];
  2130. if (!parentA || !parentB || parentA !== parentB) {
  2131. break;
  2132. }
  2133. }
  2134. return parentsA[lenA - i + 1];
  2135. },
  2136. setStart : function(node, offset) {
  2137. var self = this, doc = self.doc;
  2138. self.startContainer = node;
  2139. self.startOffset = offset;
  2140. if (self.endContainer === doc) {
  2141. self.endContainer = node;
  2142. self.endOffset = offset;
  2143. }
  2144. return _updateCollapsed(this);
  2145. },
  2146. setEnd : function(node, offset) {
  2147. var self = this, doc = self.doc;
  2148. self.endContainer = node;
  2149. self.endOffset = offset;
  2150. if (self.startContainer === doc) {
  2151. self.startContainer = node;
  2152. self.startOffset = offset;
  2153. }
  2154. return _updateCollapsed(this);
  2155. },
  2156. setStartBefore : function(node) {
  2157. return this.setStart(node.parentNode || this.doc, K(node).index());
  2158. },
  2159. setStartAfter : function(node) {
  2160. return this.setStart(node.parentNode || this.doc, K(node).index() + 1);
  2161. },
  2162. setEndBefore : function(node) {
  2163. return this.setEnd(node.parentNode || this.doc, K(node).index());
  2164. },
  2165. setEndAfter : function(node) {
  2166. return this.setEnd(node.parentNode || this.doc, K(node).index() + 1);
  2167. },
  2168. selectNode : function(node) {
  2169. return this.setStartBefore(node).setEndAfter(node);
  2170. },
  2171. selectNodeContents : function(node) {
  2172. var knode = K(node);
  2173. if (knode.type == 3 || knode.isSingle()) {
  2174. return this.selectNode(node);
  2175. }
  2176. var children = knode.children();
  2177. if (children.length > 0) {
  2178. return this.setStartBefore(children[0]).setEndAfter(children[children.length - 1]);
  2179. }
  2180. return this.setStart(node, 0).setEnd(node, 0);
  2181. },
  2182. collapse : function(toStart) {
  2183. if (toStart) {
  2184. return this.setEnd(this.startContainer, this.startOffset);
  2185. }
  2186. return this.setStart(this.endContainer, this.endOffset);
  2187. },
  2188. compareBoundaryPoints : function(how, range) {
  2189. var rangeA = this.get(), rangeB = range.get();
  2190. if (_IERANGE) {
  2191. var arr = {};
  2192. arr[_START_TO_START] = 'StartToStart';
  2193. arr[_START_TO_END] = 'EndToStart';
  2194. arr[_END_TO_END] = 'EndToEnd';
  2195. arr[_END_TO_START] = 'StartToEnd';
  2196. var cmp = rangeA.compareEndPoints(arr[how], rangeB);
  2197. if (cmp !== 0) {
  2198. return cmp;
  2199. }
  2200. var nodeA, nodeB, nodeC, posA, posB;
  2201. if (how === _START_TO_START || how === _END_TO_START) {
  2202. nodeA = this.startContainer;
  2203. posA = this.startOffset;
  2204. }
  2205. if (how === _START_TO_END || how === _END_TO_END) {
  2206. nodeA = this.endContainer;
  2207. posA = this.endOffset;
  2208. }
  2209. if (how === _START_TO_START || how === _START_TO_END) {
  2210. nodeB = range.startContainer;
  2211. posB = range.startOffset;
  2212. }
  2213. if (how === _END_TO_END || how === _END_TO_START) {
  2214. nodeB = range.endContainer;
  2215. posB = range.endOffset;
  2216. }
  2217. if (nodeA === nodeB) {
  2218. var diff = posA - posB;
  2219. return diff > 0 ? 1 : (diff < 0 ? -1 : 0);
  2220. }
  2221. nodeC = nodeB;
  2222. while (nodeC && nodeC.parentNode !== nodeA) {
  2223. nodeC = nodeC.parentNode;
  2224. }
  2225. if (nodeC) {
  2226. return K(nodeC).index() >= posA ? -1 : 1;
  2227. }
  2228. nodeC = nodeA;
  2229. while (nodeC && nodeC.parentNode !== nodeB) {
  2230. nodeC = nodeC.parentNode;
  2231. }
  2232. if (nodeC) {
  2233. return K(nodeC).index() >= posB ? 1 : -1;
  2234. }
  2235. nodeC = K(nodeB).next();
  2236. if (nodeC && nodeC.contains(nodeA)) {
  2237. return 1;
  2238. }
  2239. nodeC = K(nodeA).next();
  2240. if (nodeC && nodeC.contains(nodeB)) {
  2241. return -1;
  2242. }
  2243. } else {
  2244. return rangeA.compareBoundaryPoints(how, rangeB);
  2245. }
  2246. },
  2247. cloneRange : function() {
  2248. return new KRange(this.doc).setStart(this.startContainer, this.startOffset).setEnd(this.endContainer, this.endOffset);
  2249. },
  2250. toString : function() {
  2251. var rng = this.get(), str = _IERANGE ? rng.text : rng.toString();
  2252. return str.replace(/\r\n|\n|\r/g, '');
  2253. },
  2254. cloneContents : function() {
  2255. return _copyAndDelete(this, true, false);
  2256. },
  2257. deleteContents : function() {
  2258. return _copyAndDelete(this, false, true);
  2259. },
  2260. extractContents : function() {
  2261. return _copyAndDelete(this, true, true);
  2262. },
  2263. insertNode : function(node) {
  2264. var self = this,
  2265. sc = self.startContainer, so = self.startOffset,
  2266. ec = self.endContainer, eo = self.endOffset,
  2267. firstChild, lastChild, c, nodeCount = 1;
  2268. if (node.nodeName.toLowerCase() === '#document-fragment') {
  2269. firstChild = node.firstChild;
  2270. lastChild = node.lastChild;
  2271. nodeCount = node.childNodes.length;
  2272. }
  2273. if (sc.nodeType == 1) {
  2274. c = sc.childNodes[so];
  2275. if (c) {
  2276. sc.insertBefore(node, c);
  2277. if (sc === ec) {
  2278. eo += nodeCount;
  2279. }
  2280. } else {
  2281. sc.appendChild(node);
  2282. }
  2283. } else if (sc.nodeType == 3) {
  2284. if (so === 0) {
  2285. sc.parentNode.insertBefore(node, sc);
  2286. if (sc.parentNode === ec) {
  2287. eo += nodeCount;
  2288. }
  2289. } else if (so >= sc.nodeValue.length) {
  2290. if (sc.nextSibling) {
  2291. sc.parentNode.insertBefore(node, sc.nextSibling);
  2292. } else {
  2293. sc.parentNode.appendChild(node);
  2294. }
  2295. } else {
  2296. if (so > 0) {
  2297. c = sc.splitText(so);
  2298. } else {
  2299. c = sc;
  2300. }
  2301. sc.parentNode.insertBefore(node, c);
  2302. if (sc === ec) {
  2303. ec = c;
  2304. eo -= so;
  2305. }
  2306. }
  2307. }
  2308. if (firstChild) {
  2309. self.setStartBefore(firstChild).setEndAfter(lastChild);
  2310. } else {
  2311. self.selectNode(node);
  2312. }
  2313. if (self.compareBoundaryPoints(_END_TO_END, self.cloneRange().setEnd(ec, eo)) >= 1) {
  2314. return self;
  2315. }
  2316. return self.setEnd(ec, eo);
  2317. },
  2318. surroundContents : function(node) {
  2319. node.appendChild(this.extractContents());
  2320. return this.insertNode(node).selectNode(node);
  2321. },
  2322. isControl : function() {
  2323. var self = this,
  2324. sc = self.startContainer, so = self.startOffset,
  2325. ec = self.endContainer, eo = self.endOffset, rng;
  2326. return sc.nodeType == 1 && sc === ec && so + 1 === eo && K(sc.childNodes[so]).isControl();
  2327. },
  2328. get : function(hasControlRange) {
  2329. var self = this, doc = self.doc, node, rng;
  2330. if (!_IERANGE) {
  2331. rng = doc.createRange();
  2332. try {
  2333. rng.setStart(self.startContainer, self.startOffset);
  2334. rng.setEnd(self.endContainer, self.endOffset);
  2335. } catch (e) {}
  2336. return rng;
  2337. }
  2338. if (hasControlRange && self.isControl()) {
  2339. rng = doc.body.createControlRange();
  2340. rng.addElement(self.startContainer.childNodes[self.startOffset]);
  2341. return rng;
  2342. }
  2343. var range = self.cloneRange().down();
  2344. rng = doc.body.createTextRange();
  2345. rng.setEndPoint('StartToStart', _getEndRange(range.startContainer, range.startOffset));
  2346. rng.setEndPoint('EndToStart', _getEndRange(range.endContainer, range.endOffset));
  2347. return rng;
  2348. },
  2349. html : function() {
  2350. return K(this.cloneContents()).outer();
  2351. },
  2352. down : function() {
  2353. var self = this;
  2354. function downPos(node, pos, isStart) {
  2355. if (node.nodeType != 1) {
  2356. return;
  2357. }
  2358. var children = K(node).children();
  2359. if (children.length === 0) {
  2360. return;
  2361. }
  2362. var left, right, child, offset;
  2363. if (pos > 0) {
  2364. left = children.eq(pos - 1);
  2365. }
  2366. if (pos < children.length) {
  2367. right = children.eq(pos);
  2368. }
  2369. if (left && left.type == 3) {
  2370. child = left[0];
  2371. offset = child.nodeValue.length;
  2372. }
  2373. if (right && right.type == 3) {
  2374. child = right[0];
  2375. offset = 0;
  2376. }
  2377. if (!child) {
  2378. return;
  2379. }
  2380. if (isStart) {
  2381. self.setStart(child, offset);
  2382. } else {
  2383. self.setEnd(child, offset);
  2384. }
  2385. }
  2386. downPos(self.startContainer, self.startOffset, true);
  2387. downPos(self.endContainer, self.endOffset, false);
  2388. return self;
  2389. },
  2390. up : function() {
  2391. var self = this;
  2392. function upPos(node, pos, isStart) {
  2393. if (node.nodeType != 3) {
  2394. return;
  2395. }
  2396. if (pos === 0) {
  2397. if (isStart) {
  2398. self.setStartBefore(node);
  2399. } else {
  2400. self.setEndBefore(node);
  2401. }
  2402. } else if (pos == node.nodeValue.length) {
  2403. if (isStart) {
  2404. self.setStartAfter(node);
  2405. } else {
  2406. self.setEndAfter(node);
  2407. }
  2408. }
  2409. }
  2410. upPos(self.startContainer, self.startOffset, true);
  2411. upPos(self.endContainer, self.endOffset, false);
  2412. return self;
  2413. },
  2414. enlarge : function(toBlock) {
  2415. var self = this;
  2416. self.up();
  2417. function enlargePos(node, pos, isStart) {
  2418. var knode = K(node), parent;
  2419. if (knode.type == 3 || _NOSPLIT_TAG_MAP[knode.name] || !toBlock && knode.isBlock()) {
  2420. return;
  2421. }
  2422. if (pos === 0) {
  2423. while (!knode.prev()) {
  2424. parent = knode.parent();
  2425. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2426. break;
  2427. }
  2428. knode = parent;
  2429. }
  2430. if (isStart) {
  2431. self.setStartBefore(knode[0]);
  2432. } else {
  2433. self.setEndBefore(knode[0]);
  2434. }
  2435. } else if (pos == knode.children().length) {
  2436. while (!knode.next()) {
  2437. parent = knode.parent();
  2438. if (!parent || _NOSPLIT_TAG_MAP[parent.name] || !toBlock && parent.isBlock()) {
  2439. break;
  2440. }
  2441. knode = parent;
  2442. }
  2443. if (isStart) {
  2444. self.setStartAfter(knode[0]);
  2445. } else {
  2446. self.setEndAfter(knode[0]);
  2447. }
  2448. }
  2449. }
  2450. enlargePos(self.startContainer, self.startOffset, true);
  2451. enlargePos(self.endContainer, self.endOffset, false);
  2452. return self;
  2453. },
  2454. shrink : function() {
  2455. var self = this, child, collapsed = self.collapsed;
  2456. while (self.startContainer.nodeType == 1 && (child = self.startContainer.childNodes[self.startOffset]) && child.nodeType == 1 && !K(child).isSingle()) {
  2457. self.setStart(child, 0);
  2458. }
  2459. if (collapsed) {
  2460. return self.collapse(collapsed);
  2461. }
  2462. while (self.endContainer.nodeType == 1 && self.endOffset > 0 && (child = self.endContainer.childNodes[self.endOffset - 1]) && child.nodeType == 1 && !K(child).isSingle()) {
  2463. self.setEnd(child, child.childNodes.length);
  2464. }
  2465. return self;
  2466. },
  2467. createBookmark : function(serialize) {
  2468. var self = this, doc = self.doc, endNode,
  2469. startNode = K('<span style="display:none;"></span>', doc)[0];
  2470. startNode.id = '__kindeditor_bookmark_start_' + (_BOOKMARK_ID++) + '__';
  2471. if (!self.collapsed) {
  2472. endNode = startNode.cloneNode(true);
  2473. endNode.id = '__kindeditor_bookmark_end_' + (_BOOKMARK_ID++) + '__';
  2474. }
  2475. if (endNode) {
  2476. self.cloneRange().collapse(false).insertNode(endNode).setEndBefore(endNode);
  2477. }
  2478. self.insertNode(startNode).setStartAfter(startNode);
  2479. return {
  2480. start : serialize ? '#' + startNode.id : startNode,
  2481. end : endNode ? (serialize ? '#' + endNode.id : endNode) : null
  2482. };
  2483. },
  2484. moveToBookmark : function(bookmark) {
  2485. var self = this, doc = self.doc,
  2486. start = K(bookmark.start, doc), end = bookmark.end ? K(bookmark.end, doc) : null;
  2487. if (!start || start.length < 1) {
  2488. return self;
  2489. }
  2490. self.setStartBefore(start[0]);
  2491. start.remove();
  2492. if (end && end.length > 0) {
  2493. self.setEndBefore(end[0]);
  2494. end.remove();
  2495. } else {
  2496. self.collapse(true);
  2497. }
  2498. return self;
  2499. },
  2500. dump : function() {
  2501. console.log('--------------------');
  2502. console.log(this.startContainer.nodeType == 3 ? this.startContainer.nodeValue : this.startContainer, this.startOffset);
  2503. console.log(this.endContainer.nodeType == 3 ? this.endContainer.nodeValue : this.endContainer, this.endOffset);
  2504. }
  2505. });
  2506. function _range(mixed) {
  2507. if (!mixed.nodeName) {
  2508. return mixed.constructor === KRange ? mixed : _toRange(mixed);
  2509. }
  2510. return new KRange(mixed);
  2511. }
  2512. K.RangeClass = KRange;
  2513. K.range = _range;
  2514. K.START_TO_START = _START_TO_START;
  2515. K.START_TO_END = _START_TO_END;
  2516. K.END_TO_END = _END_TO_END;
  2517. K.END_TO_START = _END_TO_START;
  2518. function _nativeCommand(doc, key, val) {
  2519. try {
  2520. doc.execCommand(key, false, val);
  2521. } catch(e) {}
  2522. }
  2523. function _nativeCommandValue(doc, key) {
  2524. var val = '';
  2525. try {
  2526. val = doc.queryCommandValue(key);
  2527. } catch (e) {}
  2528. if (typeof val !== 'string') {
  2529. val = '';
  2530. }
  2531. return val;
  2532. }
  2533. function _getSel(doc) {
  2534. var win = _getWin(doc);
  2535. return _IERANGE ? doc.selection : win.getSelection();
  2536. }
  2537. function _getRng(doc) {
  2538. var sel = _getSel(doc), rng;
  2539. try {
  2540. if (sel.rangeCount > 0) {
  2541. rng = sel.getRangeAt(0);
  2542. } else {
  2543. rng = sel.createRange();
  2544. }
  2545. } catch(e) {}
  2546. if (_IERANGE && (!rng || (!rng.item && rng.parentElement().ownerDocument !== doc))) {
  2547. return null;
  2548. }
  2549. return rng;
  2550. }
  2551. function _singleKeyMap(map) {
  2552. var newMap = {}, arr, v;
  2553. _each(map, function(key, val) {
  2554. arr = key.split(',');
  2555. for (var i = 0, len = arr.length; i < len; i++) {
  2556. v = arr[i];
  2557. newMap[v] = val;
  2558. }
  2559. });
  2560. return newMap;
  2561. }
  2562. function _hasAttrOrCss(knode, map) {
  2563. return _hasAttrOrCssByKey(knode, map, '*') || _hasAttrOrCssByKey(knode, map);
  2564. }
  2565. function _hasAttrOrCssByKey(knode, map, mapKey) {
  2566. mapKey = mapKey || knode.name;
  2567. if (knode.type !== 1) {
  2568. return false;
  2569. }
  2570. var newMap = _singleKeyMap(map);
  2571. if (!newMap[mapKey]) {
  2572. return false;
  2573. }
  2574. var arr = newMap[mapKey].split(',');
  2575. for (var i = 0, len = arr.length; i < len; i++) {
  2576. var key = arr[i];
  2577. if (key === '*') {
  2578. return true;
  2579. }
  2580. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2581. var method = match[1] ? 'css' : 'attr';
  2582. key = match[2];
  2583. var val = match[3] || '';
  2584. if (val === '' && knode[method](key) !== '') {
  2585. return true;
  2586. }
  2587. if (val !== '' && knode[method](key) === val) {
  2588. return true;
  2589. }
  2590. }
  2591. return false;
  2592. }
  2593. function _removeAttrOrCss(knode, map) {
  2594. if (knode.type != 1) {
  2595. return;
  2596. }
  2597. _removeAttrOrCssByKey(knode, map, '*');
  2598. _removeAttrOrCssByKey(knode, map);
  2599. }
  2600. function _removeAttrOrCssByKey(knode, map, mapKey) {
  2601. mapKey = mapKey || knode.name;
  2602. if (knode.type !== 1) {
  2603. return;
  2604. }
  2605. var newMap = _singleKeyMap(map);
  2606. if (!newMap[mapKey]) {
  2607. return;
  2608. }
  2609. var arr = newMap[mapKey].split(','), allFlag = false;
  2610. for (var i = 0, len = arr.length; i < len; i++) {
  2611. var key = arr[i];
  2612. if (key === '*') {
  2613. allFlag = true;
  2614. break;
  2615. }
  2616. var match = /^(\.?)([^=]+)(?:=([^=]*))?$/.exec(key);
  2617. key = match[2];
  2618. if (match[1]) {
  2619. key = _toCamel(key);
  2620. if (knode[0].style[key]) {
  2621. knode[0].style[key] = '';
  2622. }
  2623. } else {
  2624. knode.removeAttr(key);
  2625. }
  2626. }
  2627. if (allFlag) {
  2628. knode.remove(true);
  2629. }
  2630. }
  2631. function _getInnerNode(knode) {
  2632. var inner = knode;
  2633. while (inner.first()) {
  2634. inner = inner.first();
  2635. }
  2636. return inner;
  2637. }
  2638. function _isEmptyNode(knode) {
  2639. if (knode.type != 1 || knode.isSingle()) {
  2640. return false;
  2641. }
  2642. return knode.html().replace(/<[^>]+>/g, '') === '';
  2643. }
  2644. function _mergeWrapper(a, b) {
  2645. a = a.clone(true);
  2646. var lastA = _getInnerNode(a), childA = a, merged = false;
  2647. while (b) {
  2648. while (childA) {
  2649. if (childA.name === b.name) {
  2650. _mergeAttrs(childA, b.attr(), b.css());
  2651. merged = true;
  2652. }
  2653. childA = childA.first();
  2654. }
  2655. if (!merged) {
  2656. lastA.append(b.clone(false));
  2657. }
  2658. merged = false;
  2659. b = b.first();
  2660. }
  2661. return a;
  2662. }
  2663. function _wrapNode(knode, wrapper) {
  2664. wrapper = wrapper.clone(true);
  2665. if (knode.type == 3) {
  2666. _getInnerNode(wrapper).append(knode.clone(false));
  2667. knode.replaceWith(wrapper);
  2668. return wrapper;
  2669. }
  2670. var nodeWrapper = knode, child;
  2671. while ((child = knode.first()) && child.children().length == 1) {
  2672. knode = child;
  2673. }
  2674. child = knode.first();
  2675. var frag = knode.doc.createDocumentFragment();
  2676. while (child) {
  2677. frag.appendChild(child[0]);
  2678. child = child.next();
  2679. }
  2680. wrapper = _mergeWrapper(nodeWrapper, wrapper);
  2681. if (frag.firstChild) {
  2682. _getInnerNode(wrapper).append(frag);
  2683. }
  2684. nodeWrapper.replaceWith(wrapper);
  2685. return wrapper;
  2686. }
  2687. function _mergeAttrs(knode, attrs, styles) {
  2688. _each(attrs, function(key, val) {
  2689. if (key !== 'style') {
  2690. knode.attr(key, val);
  2691. }
  2692. });
  2693. _each(styles, function(key, val) {
  2694. knode.css(key, val);
  2695. });
  2696. }
  2697. function _inPreElement(knode) {
  2698. while (knode && knode.name != 'body') {
  2699. if (_PRE_TAG_MAP[knode.name] || knode.name == 'div' && knode.hasClass('ke-script')) {
  2700. return true;
  2701. }
  2702. knode = knode.parent();
  2703. }
  2704. return false;
  2705. }
  2706. function KCmd(range) {
  2707. this.init(range);
  2708. }
  2709. _extend(KCmd, {
  2710. init : function(range) {
  2711. var self = this, doc = range.doc;
  2712. self.doc = doc;
  2713. self.win = _getWin(doc);
  2714. self.sel = _getSel(doc);
  2715. self.range = range;
  2716. },
  2717. selection : function(forceReset) {
  2718. var self = this, doc = self.doc, rng = _getRng(doc);
  2719. self.sel = _getSel(doc);
  2720. if (rng) {
  2721. self.range = _range(rng);
  2722. if (K(self.range.startContainer).name == 'html') {
  2723. self.range.selectNodeContents(doc.body).collapse(false);
  2724. }
  2725. return self;
  2726. }
  2727. if (forceReset) {
  2728. self.range.selectNodeContents(doc.body).collapse(false);
  2729. }
  2730. return self;
  2731. },
  2732. select : function(hasDummy) {
  2733. hasDummy = _undef(hasDummy, true);
  2734. var self = this, sel = self.sel, range = self.range.cloneRange().shrink(),
  2735. sc = range.startContainer, so = range.startOffset,
  2736. ec = range.endContainer, eo = range.endOffset,
  2737. doc = _getDoc(sc), win = self.win, rng, hasU200b = false;
  2738. if (hasDummy && sc.nodeType == 1 && range.collapsed) {
  2739. if (_IERANGE) {
  2740. var dummy = K('<span>&nbsp;</span>', doc);
  2741. range.insertNode(dummy[0]);
  2742. rng = doc.body.createTextRange();
  2743. try {
  2744. rng.moveToElementText(dummy[0]);
  2745. } catch(ex) {}
  2746. rng.collapse(false);
  2747. rng.select();
  2748. dummy.remove();
  2749. win.focus();
  2750. return self;
  2751. }
  2752. if (_WEBKIT) {
  2753. var children = sc.childNodes;
  2754. if (K(sc).isInline() || so > 0 && K(children[so - 1]).isInline() || children[so] && K(children[so]).isInline()) {
  2755. range.insertNode(doc.createTextNode('\u200B'));
  2756. hasU200b = true;
  2757. }
  2758. }
  2759. }
  2760. if (_IERANGE) {
  2761. try {
  2762. rng = range.get(true);
  2763. rng.select();
  2764. } catch(e) {}
  2765. } else {
  2766. if (hasU200b) {
  2767. range.collapse(false);
  2768. }
  2769. rng = range.get(true);
  2770. sel.removeAllRanges();
  2771. sel.addRange(rng);
  2772. if (doc !== document) {
  2773. var pos = K(rng.endContainer).pos();
  2774. //win.scrollTo(pos.x, pos.y);
  2775. }
  2776. }
  2777. win.focus();
  2778. return self;
  2779. },
  2780. wrap : function(val) {
  2781. var self = this, doc = self.doc, range = self.range, wrapper;
  2782. wrapper = K(val, doc);
  2783. if (range.collapsed) {
  2784. range.shrink();
  2785. range.insertNode(wrapper[0]).selectNodeContents(wrapper[0]);
  2786. return self;
  2787. }
  2788. if (wrapper.isBlock()) {
  2789. var copyWrapper = wrapper.clone(true), child = copyWrapper;
  2790. while (child.first()) {
  2791. child = child.first();
  2792. }
  2793. child.append(range.extractContents());
  2794. range.insertNode(copyWrapper[0]).selectNode(copyWrapper[0]);
  2795. return self;
  2796. }
  2797. range.enlarge();
  2798. var bookmark = range.createBookmark(), ancestor = range.commonAncestor(), isStart = false;
  2799. K(ancestor).scan(function(node) {
  2800. if (!isStart && node == bookmark.start) {
  2801. isStart = true;
  2802. return;
  2803. }
  2804. if (isStart) {
  2805. if (node == bookmark.end) {
  2806. return false;
  2807. }
  2808. var knode = K(node);
  2809. if (_inPreElement(knode)) {
  2810. return;
  2811. }
  2812. if (knode.type == 3 && _trim(node.nodeValue).length > 0) {
  2813. var parent;
  2814. while ((parent = knode.parent()) && parent.isStyle() && parent.children().length == 1) {
  2815. knode = parent;
  2816. }
  2817. _wrapNode(knode, wrapper);
  2818. }
  2819. }
  2820. });
  2821. range.moveToBookmark(bookmark);
  2822. return self;
  2823. },
  2824. split : function(isStart, map) {
  2825. var range = this.range, doc = range.doc;
  2826. var tempRange = range.cloneRange().collapse(isStart);
  2827. var node = tempRange.startContainer, pos = tempRange.startOffset,
  2828. parent = node.nodeType == 3 ? node.parentNode : node,
  2829. needSplit = false, knode;
  2830. while (parent && parent.parentNode) {
  2831. knode = K(parent);
  2832. if (map) {
  2833. if (!knode.isStyle()) {
  2834. break;
  2835. }
  2836. if (!_hasAttrOrCss(knode, map)) {
  2837. break;
  2838. }
  2839. } else {
  2840. if (_NOSPLIT_TAG_MAP[knode.name]) {
  2841. break;
  2842. }
  2843. }
  2844. needSplit = true;
  2845. parent = parent.parentNode;
  2846. }
  2847. if (needSplit) {
  2848. var dummy = doc.createElement('span');
  2849. range.cloneRange().collapse(!isStart).insertNode(dummy);
  2850. if (isStart) {
  2851. tempRange.setStartBefore(parent.firstChild).setEnd(node, pos);
  2852. } else {
  2853. tempRange.setStart(node, pos).setEndAfter(parent.lastChild);
  2854. }
  2855. var frag = tempRange.extractContents(),
  2856. first = frag.firstChild, last = frag.lastChild;
  2857. if (isStart) {
  2858. tempRange.insertNode(frag);
  2859. range.setStartAfter(last).setEndBefore(dummy);
  2860. } else {
  2861. parent.appendChild(frag);
  2862. range.setStartBefore(dummy).setEndBefore(first);
  2863. }
  2864. var dummyParent = dummy.parentNode;
  2865. if (dummyParent == range.endContainer) {
  2866. var prev = K(dummy).prev(), next = K(dummy).next();
  2867. if (prev && next && prev.type == 3 && next.type == 3) {
  2868. range.setEnd(prev[0], prev[0].nodeValue.length);
  2869. } else if (!isStart) {
  2870. range.setEnd(range.endContainer, range.endOffset - 1);
  2871. }
  2872. }
  2873. dummyParent.removeChild(dummy);
  2874. }
  2875. return this;
  2876. },
  2877. remove : function(map) {
  2878. var self = this, doc = self.doc, range = self.range;
  2879. range.enlarge();
  2880. if (range.startOffset === 0) {
  2881. var ksc = K(range.startContainer), parent;
  2882. while ((parent = ksc.parent()) && parent.isStyle() && parent.children().length == 1) {
  2883. ksc = parent;
  2884. }
  2885. range.setStart(ksc[0], 0);
  2886. ksc = K(range.startContainer);
  2887. if (ksc.isBlock()) {
  2888. _removeAttrOrCss(ksc, map);
  2889. }
  2890. var kscp = ksc.parent();
  2891. if (kscp && kscp.isBlock()) {
  2892. _removeAttrOrCss(kscp, map);
  2893. }
  2894. }
  2895. var sc, so;
  2896. if (range.collapsed) {
  2897. self.split(true, map);
  2898. sc = range.startContainer;
  2899. so = range.startOffset;
  2900. if (so > 0) {
  2901. var sb = K(sc.childNodes[so - 1]);
  2902. if (sb && _isEmptyNode(sb)) {
  2903. sb.remove();
  2904. range.setStart(sc, so - 1);
  2905. }
  2906. }
  2907. var sa = K(sc.childNodes[so]);
  2908. if (sa && _isEmptyNode(sa)) {
  2909. sa.remove();
  2910. }
  2911. if (_isEmptyNode(sc)) {
  2912. range.startBefore(sc);
  2913. sc.remove();
  2914. }
  2915. range.collapse(true);
  2916. return self;
  2917. }
  2918. self.split(true, map);
  2919. self.split(false, map);
  2920. var startDummy = doc.createElement('span'), endDummy = doc.createElement('span');
  2921. range.cloneRange().collapse(false).insertNode(endDummy);
  2922. range.cloneRange().collapse(true).insertNode(startDummy);
  2923. var nodeList = [], cmpStart = false;
  2924. K(range.commonAncestor()).scan(function(node) {
  2925. if (!cmpStart && node == startDummy) {
  2926. cmpStart = true;
  2927. return;
  2928. }
  2929. if (node == endDummy) {
  2930. return false;
  2931. }
  2932. if (cmpStart) {
  2933. nodeList.push(node);
  2934. }
  2935. });
  2936. K(startDummy).remove();
  2937. K(endDummy).remove();
  2938. sc = range.startContainer;
  2939. so = range.startOffset;
  2940. var ec = range.endContainer, eo = range.endOffset;
  2941. if (so > 0) {
  2942. var startBefore = K(sc.childNodes[so - 1]);
  2943. if (startBefore && _isEmptyNode(startBefore)) {
  2944. startBefore.remove();
  2945. range.setStart(sc, so - 1);
  2946. if (sc == ec) {
  2947. range.setEnd(ec, eo - 1);
  2948. }
  2949. }
  2950. var startAfter = K(sc.childNodes[so]);
  2951. if (startAfter && _isEmptyNode(startAfter)) {
  2952. startAfter.remove();
  2953. if (sc == ec) {
  2954. range.setEnd(ec, eo - 1);
  2955. }
  2956. }
  2957. }
  2958. var endAfter = K(ec.childNodes[range.endOffset]);
  2959. if (endAfter && _isEmptyNode(endAfter)) {
  2960. endAfter.remove();
  2961. }
  2962. var bookmark = range.createBookmark(true);
  2963. _each(nodeList, function(i, node) {
  2964. _removeAttrOrCss(K(node), map);
  2965. });
  2966. range.moveToBookmark(bookmark);
  2967. return self;
  2968. },
  2969. commonNode : function(map) {
  2970. var range = this.range;
  2971. var ec = range.endContainer, eo = range.endOffset,
  2972. node = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  2973. function find(node) {
  2974. var child = node, parent = node;
  2975. while (parent) {
  2976. if (_hasAttrOrCss(K(parent), map)) {
  2977. return K(parent);
  2978. }
  2979. parent = parent.parentNode;
  2980. }
  2981. while (child && (child = child.lastChild)) {
  2982. if (_hasAttrOrCss(K(child), map)) {
  2983. return K(child);
  2984. }
  2985. }
  2986. return null;
  2987. }
  2988. var cNode = find(node);
  2989. if (cNode) {
  2990. return cNode;
  2991. }
  2992. if (node.nodeType == 1 || (ec.nodeType == 3 && eo === 0)) {
  2993. var prev = K(node).prev();
  2994. if (prev) {
  2995. return find(prev);
  2996. }
  2997. }
  2998. return null;
  2999. },
  3000. commonAncestor : function(tagName) {
  3001. var range = this.range,
  3002. sc = range.startContainer, so = range.startOffset,
  3003. ec = range.endContainer, eo = range.endOffset,
  3004. startNode = (sc.nodeType == 3 || so === 0) ? sc : sc.childNodes[so - 1],
  3005. endNode = (ec.nodeType == 3 || eo === 0) ? ec : ec.childNodes[eo - 1];
  3006. function find(node) {
  3007. while (node) {
  3008. if (node.nodeType == 1) {
  3009. if (node.tagName.toLowerCase() === tagName) {
  3010. return node;
  3011. }
  3012. }
  3013. node = node.parentNode;
  3014. }
  3015. return null;
  3016. }
  3017. var start = find(startNode), end = find(endNode);
  3018. if (start && end && start === end) {
  3019. return K(start);
  3020. }
  3021. return null;
  3022. },
  3023. state : function(key) {
  3024. var self = this, doc = self.doc, bool = false;
  3025. try {
  3026. bool = doc.queryCommandState(key);
  3027. } catch (e) {}
  3028. return bool;
  3029. },
  3030. val : function(key) {
  3031. var self = this, doc = self.doc, range = self.range;
  3032. function lc(val) {
  3033. return val.toLowerCase();
  3034. }
  3035. key = lc(key);
  3036. var val = '', knode;
  3037. if (key === 'fontfamily' || key === 'fontname') {
  3038. val = _nativeCommandValue(doc, 'fontname');
  3039. val = val.replace(/['"]/g, '');
  3040. return lc(val);
  3041. }
  3042. if (key === 'formatblock') {
  3043. val = _nativeCommandValue(doc, key);
  3044. if (val === '') {
  3045. knode = self.commonNode({'h1,h2,h3,h4,h5,h6,p,div,pre,address' : '*'});
  3046. if (knode) {
  3047. val = knode.name;
  3048. }
  3049. }
  3050. if (val === 'Normal') {
  3051. val = 'p';
  3052. }
  3053. return lc(val);
  3054. }
  3055. if (key === 'fontsize') {
  3056. knode = self.commonNode({'*' : '.font-size'});
  3057. if (knode) {
  3058. val = knode.css('font-size');
  3059. }
  3060. return lc(val);
  3061. }
  3062. if (key === 'fontheight') {
  3063. knode = self.commonNode({'*' : '.letter-spacing'});
  3064. if (knode) {
  3065. val = knode.css('letter-spacing');
  3066. }
  3067. return lc(val);
  3068. }
  3069. if (key === 'forecolor') {
  3070. knode = self.commonNode({'*' : '.color'});
  3071. if (knode) {
  3072. val = knode.css('color');
  3073. }
  3074. val = _toHex(val);
  3075. if (val === '') {
  3076. val = 'default';
  3077. }
  3078. return lc(val);
  3079. }
  3080. if (key === 'hilitecolor') {
  3081. knode = self.commonNode({'*' : '.background-color'});
  3082. if (knode) {
  3083. val = knode.css('background-color');
  3084. }
  3085. val = _toHex(val);
  3086. if (val === '') {
  3087. val = 'default';
  3088. }
  3089. return lc(val);
  3090. }
  3091. return val;
  3092. },
  3093. toggle : function(wrapper, map) {
  3094. var self = this;
  3095. if (self.commonNode(map)) {
  3096. self.remove(map);
  3097. } else {
  3098. self.wrap(wrapper);
  3099. }
  3100. return self.select();
  3101. },
  3102. bold : function() {
  3103. return this.toggle('<strong></strong>', {
  3104. span : '.font-weight=bold',
  3105. strong : '*',
  3106. b : '*'
  3107. });
  3108. },
  3109. italic : function() {
  3110. return this.toggle('<em></em>', {
  3111. span : '.font-style=italic',
  3112. em : '*',
  3113. i : '*'
  3114. });
  3115. },
  3116. underline : function() {
  3117. return this.toggle('<u></u>', {
  3118. span : '.text-decoration=underline',
  3119. u : '*'
  3120. });
  3121. },
  3122. strikethrough : function() {
  3123. return this.toggle('<s></s>', {
  3124. span : '.text-decoration=line-through',
  3125. s : '*'
  3126. });
  3127. },
  3128. forecolor : function(val) {
  3129. return this.wrap('<span style="color:' + val + ';"></span>').select();
  3130. },
  3131. hilitecolor : function(val) {
  3132. return this.wrap('<span style="background-color:' + val + ';"></span>').select();
  3133. },
  3134. fontsize : function(val) {
  3135. return this.wrap('<span style="font-size:' + val + ';"></span>').select();
  3136. },
  3137. fontheight : function(val) {
  3138. return this.wrap('<span style="letter-spacing:' + val + ';"></span>').select();
  3139. },
  3140. fontname : function(val) {
  3141. return this.fontfamily(val);
  3142. },
  3143. fontfamily : function(val) {
  3144. return this.wrap('<span style="font-family:' + val + ';"></span>').select();
  3145. },
  3146. removeformat : function() {
  3147. var map = {
  3148. '*' : '.font-weight,.font-style,.text-decoration,.color,.background-color,.font-size,.font-family,.text-indent'
  3149. },
  3150. tags = _STYLE_TAG_MAP;
  3151. _each(tags, function(key, val) {
  3152. map[key] = '*';
  3153. });
  3154. this.remove(map);
  3155. return this.select();
  3156. },
  3157. inserthtml : function(val, quickMode) {
  3158. var self = this, range = self.range;
  3159. if (val === '') {
  3160. return self;
  3161. }
  3162. function pasteHtml(range, val) {
  3163. val = '<img id="__kindeditor_temp_tag__" width="0" height="0" style="display:none;" />' + val;
  3164. var rng = range.get();
  3165. if (rng.item) {
  3166. rng.item(0).outerHTML = val;
  3167. } else {
  3168. rng.pasteHTML(val);
  3169. }
  3170. var temp = range.doc.getElementById('__kindeditor_temp_tag__');
  3171. temp.parentNode.removeChild(temp);
  3172. var newRange = _toRange(rng);
  3173. range.setEnd(newRange.endContainer, newRange.endOffset);
  3174. range.collapse(false);
  3175. self.select(false);
  3176. }
  3177. function insertHtml(range, val) {
  3178. var doc = range.doc,
  3179. frag = doc.createDocumentFragment();
  3180. K('@' + val, doc).each(function() {
  3181. frag.appendChild(this);
  3182. });
  3183. range.deleteContents();
  3184. range.insertNode(frag);
  3185. range.collapse(false);
  3186. self.select(false);
  3187. }
  3188. if (_IERANGE && quickMode) {
  3189. try {
  3190. pasteHtml(range, val);
  3191. } catch(e) {
  3192. insertHtml(range, val);
  3193. }
  3194. return self;
  3195. }
  3196. insertHtml(range, val);
  3197. return self;
  3198. },
  3199. hr : function() {
  3200. return this.inserthtml('<hr />');
  3201. },
  3202. print : function() {
  3203. this.win.print();
  3204. return this;
  3205. },
  3206. insertimage : function(url, title, width, height, border, align) {
  3207. title = _undef(title, '');
  3208. border = _undef(border, 0);
  3209. var html = '<img src="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3210. if (width) {
  3211. html += 'width="' + _escape(width) + '" ';
  3212. }
  3213. if (height) {
  3214. html += 'height="' + _escape(height) + '" ';
  3215. }
  3216. if (title) {
  3217. html += 'title="' + _escape(title) + '" ';
  3218. }
  3219. if (align) {
  3220. html += 'align="' + _escape(align) + '" ';
  3221. }
  3222. html += 'alt="' + _escape(title) + '" ';
  3223. html += '/>';
  3224. return this.inserthtml(html);
  3225. },
  3226. createlink : function(url, type) {
  3227. var self = this, doc = self.doc, range = self.range;
  3228. self.select();
  3229. var a = self.commonNode({ a : '*' });
  3230. if (a && !range.isControl()) {
  3231. range.selectNode(a.get());
  3232. self.select();
  3233. }
  3234. var html = '<a href="' + _escape(url) + '" data-ke-src="' + _escape(url) + '" ';
  3235. if (type) {
  3236. html += ' target="' + _escape(type) + '"';
  3237. }
  3238. if (range.collapsed) {
  3239. html += '>' + _escape(url) + '</a>';
  3240. return self.inserthtml(html);
  3241. }
  3242. if (range.isControl()) {
  3243. var node = K(range.startContainer.childNodes[range.startOffset]);
  3244. html += '></a>';
  3245. node.after(K(html, doc));
  3246. node.next().append(node);
  3247. range.selectNode(node[0]);
  3248. return self.select();
  3249. }
  3250. function setAttr(node, url, type) {
  3251. K(node).attr('href', url).attr('data-ke-src', url);
  3252. if (type) {
  3253. K(node).attr('target', type);
  3254. } else {
  3255. K(node).removeAttr('target');
  3256. }
  3257. }
  3258. var sc = range.startContainer, so = range.startOffset,
  3259. ec = range.endContainer, eo = range.endOffset;
  3260. if (sc.nodeType == 1 && sc === ec && so + 1 === eo) {
  3261. var child = sc.childNodes[so];
  3262. if (child.nodeName.toLowerCase() == 'a') {
  3263. setAttr(child, url, type);
  3264. return self;
  3265. }
  3266. }
  3267. _nativeCommand(doc, 'createlink', '__kindeditor_temp_url__');
  3268. K('a[href="__kindeditor_temp_url__"]', doc).each(function() {
  3269. setAttr(this, url, type);
  3270. });
  3271. return self;
  3272. },
  3273. unlink : function() {
  3274. var self = this, doc = self.doc, range = self.range;
  3275. self.select();
  3276. if (range.collapsed) {
  3277. var a = self.commonNode({ a : '*' });
  3278. if (a) {
  3279. range.selectNode(a.get());
  3280. self.select();
  3281. }
  3282. _nativeCommand(doc, 'unlink', null);
  3283. if (_WEBKIT && K(range.startContainer).name === 'img') {
  3284. var parent = K(range.startContainer).parent();
  3285. if (parent.name === 'a') {
  3286. parent.remove(true);
  3287. }
  3288. }
  3289. } else {
  3290. _nativeCommand(doc, 'unlink', null);
  3291. }
  3292. return self;
  3293. }
  3294. });
  3295. _each(('formatblock,selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  3296. 'insertunorderedlist,indent,outdent,subscript,superscript').split(','), function(i, name) {
  3297. KCmd.prototype[name] = function(val) {
  3298. var self = this;
  3299. self.select();
  3300. _nativeCommand(self.doc, name, val);
  3301. if (_IERANGE && _inArray(name, 'justifyleft,justifycenter,justifyright,justifyfull'.split(',')) >= 0) {
  3302. self.selection();
  3303. }
  3304. if (!_IERANGE || _inArray(name, 'formatblock,selectall,insertorderedlist,insertunorderedlist'.split(',')) >= 0) {
  3305. self.selection();
  3306. }
  3307. return self;
  3308. };
  3309. });
  3310. _each('cut,copy,paste'.split(','), function(i, name) {
  3311. KCmd.prototype[name] = function() {
  3312. var self = this;
  3313. if (!self.doc.queryCommandSupported(name)) {
  3314. throw 'not supported';
  3315. }
  3316. self.select();
  3317. _nativeCommand(self.doc, name, null);
  3318. return self;
  3319. };
  3320. });
  3321. function _cmd(mixed) {
  3322. if (mixed.nodeName) {
  3323. var doc = _getDoc(mixed);
  3324. mixed = _range(doc).selectNodeContents(doc.body).collapse(false);
  3325. }
  3326. return new KCmd(mixed);
  3327. }
  3328. K.CmdClass = KCmd;
  3329. K.cmd = _cmd;
  3330. function _drag(options) {
  3331. var moveEl = options.moveEl,
  3332. moveFn = options.moveFn,
  3333. clickEl = options.clickEl || moveEl,
  3334. beforeDrag = options.beforeDrag,
  3335. iframeFix = options.iframeFix === undefined ? true : options.iframeFix;
  3336. var docs = [document];
  3337. if (iframeFix) {
  3338. K('iframe').each(function() {
  3339. var src = _formatUrl(this.src || '', 'absolute');
  3340. if (/^https?:\/\//.test(src)) {
  3341. return;
  3342. }
  3343. var doc;
  3344. try {
  3345. doc = _iframeDoc(this);
  3346. } catch(e) {}
  3347. if (doc) {
  3348. var pos = K(this).pos();
  3349. K(doc).data('pos-x', pos.x);
  3350. K(doc).data('pos-y', pos.y);
  3351. docs.push(doc);
  3352. }
  3353. });
  3354. }
  3355. clickEl.mousedown(function(e) {
  3356. if(e.button !== 0 && e.button !== 1) {
  3357. return;
  3358. }
  3359. e.stopPropagation();
  3360. var self = clickEl.get(),
  3361. x = _removeUnit(moveEl.css('left')),
  3362. y = _removeUnit(moveEl.css('top')),
  3363. width = moveEl.width(),
  3364. height = moveEl.height(),
  3365. pageX = e.pageX,
  3366. pageY = e.pageY;
  3367. if (beforeDrag) {
  3368. beforeDrag();
  3369. }
  3370. function moveListener(e) {
  3371. e.preventDefault();
  3372. var kdoc = K(_getDoc(e.target));
  3373. var diffX = _round((kdoc.data('pos-x') || 0) + e.pageX - pageX);
  3374. var diffY = _round((kdoc.data('pos-y') || 0) + e.pageY - pageY);
  3375. moveFn.call(clickEl, x, y, width, height, diffX, diffY);
  3376. }
  3377. function selectListener(e) {
  3378. e.preventDefault();
  3379. }
  3380. function upListener(e) {
  3381. e.preventDefault();
  3382. K(docs).unbind('mousemove', moveListener)
  3383. .unbind('mouseup', upListener)
  3384. .unbind('selectstart', selectListener);
  3385. if (self.releaseCapture) {
  3386. self.releaseCapture();
  3387. }
  3388. }
  3389. K(docs).mousemove(moveListener)
  3390. .mouseup(upListener)
  3391. .bind('selectstart', selectListener);
  3392. if (self.setCapture) {
  3393. self.setCapture();
  3394. }
  3395. });
  3396. }
  3397. function KWidget(options) {
  3398. this.init(options);
  3399. }
  3400. _extend(KWidget, {
  3401. init : function(options) {
  3402. var self = this;
  3403. self.name = options.name || '';
  3404. self.doc = options.doc || document;
  3405. self.win = _getWin(self.doc);
  3406. self.x = _addUnit(options.x);
  3407. self.y = _addUnit(options.y);
  3408. self.z = options.z;
  3409. self.width = _addUnit(options.width);
  3410. self.height = _addUnit(options.height);
  3411. self.index = _addUnit(options.index);
  3412. self.div = K('<div style="display:block;"></div>');
  3413. self.options = options;
  3414. self._alignEl = options.alignEl;
  3415. if (self.width) {
  3416. self.div.css('width', self.width);
  3417. }
  3418. if (self.height) {
  3419. self.div.css('height', self.height);
  3420. }
  3421. if (self.z) {
  3422. self.div.css({
  3423. position : 'absolute',
  3424. left : self.x,
  3425. top : self.y,
  3426. 'z-index' : self.z
  3427. });
  3428. }
  3429. if (self.z && (self.x === undefined || self.y === undefined)) {
  3430. self.autoPos(self.width, self.height);
  3431. }
  3432. if (options.cls) {
  3433. self.div.addClass(options.cls);
  3434. }
  3435. if (options.shadowMode) {
  3436. self.div.addClass('ke-shadow');
  3437. }
  3438. if (options.css) {
  3439. self.div.css(options.css);
  3440. }
  3441. if (options.src) {
  3442. K(options.src).replaceWith(self.div);
  3443. } else {
  3444. K(self.doc.body).append(self.div);
  3445. }
  3446. if (options.html) {
  3447. self.div.html(options.html);
  3448. }
  3449. if (options.autoScroll) {
  3450. if (_IE && _V < 7 || _QUIRKS) {
  3451. var scrollPos = _getScrollPos();
  3452. K(self.win).bind('scroll', function(e) {
  3453. var pos = _getScrollPos(),
  3454. diffX = pos.x - scrollPos.x,
  3455. diffY = pos.y - scrollPos.y;
  3456. self.pos(_removeUnit(self.x) + diffX, _removeUnit(self.y) + diffY, false);
  3457. });
  3458. } else {
  3459. self.div.css('position', 'fixed');
  3460. }
  3461. }
  3462. },
  3463. pos : function(x, y, updateProp) {
  3464. var self = this;
  3465. updateProp = _undef(updateProp, true);
  3466. if (x !== null) {
  3467. x = x < 0 ? 0 : _addUnit(x);
  3468. self.div.css('left', x);
  3469. if (updateProp) {
  3470. self.x = x;
  3471. }
  3472. }
  3473. if (y !== null) {
  3474. y = y < 0 ? 0 : _addUnit(y);
  3475. self.div.css('top', y);
  3476. if (updateProp) {
  3477. self.y = y;
  3478. }
  3479. }
  3480. return self;
  3481. },
  3482. autoPos : function(width, height) {
  3483. var x, y, self = this,
  3484. w = _removeUnit(width) || 0,
  3485. h = _removeUnit(height) || 0,
  3486. scrollPos = _getScrollPos();
  3487. if (self._alignEl) {
  3488. var knode = K(self._alignEl),
  3489. pos = knode.pos(),
  3490. diffX = _round(knode[0].clientWidth / 2 - w / 2),
  3491. diffY = _round(knode[0].clientHeight / 2 - h / 2);
  3492. x = diffX < 0 ? pos.x : pos.x + diffX;
  3493. y = diffY < 0 ? pos.y : pos.y + diffY;
  3494. } else {
  3495. var docEl = _docElement(self.doc);
  3496. x = _round(scrollPos.x + (docEl.clientWidth - w) / 2);
  3497. y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
  3498. }
  3499. if (!(_IE && _V < 7 || _QUIRKS)) {
  3500. x -= scrollPos.x;
  3501. y -= scrollPos.y;
  3502. }
  3503. return self.pos(x, y);
  3504. },
  3505. remove : function() {
  3506. var self = this;
  3507. if (_IE && _V < 7 || _QUIRKS) {
  3508. K(self.win).unbind('scroll');
  3509. }
  3510. self.div.remove();
  3511. _each(self, function(i) {
  3512. self[i] = null;
  3513. });
  3514. return this;
  3515. },
  3516. show : function() {
  3517. this.div.show();
  3518. return this;
  3519. },
  3520. hide : function() {
  3521. this.div.hide();
  3522. return this;
  3523. },
  3524. draggable : function(options) {
  3525. var self = this;
  3526. options = options || {};
  3527. options.moveEl = self.div;
  3528. options.moveFn = function(x, y, width, height, diffX, diffY) {
  3529. if ((x = x + diffX) < 0) {
  3530. x = 0;
  3531. }
  3532. if ((y = y + diffY) < 0) {
  3533. y = 0;
  3534. }
  3535. self.pos(x, y);
  3536. };
  3537. _drag(options);
  3538. return self;
  3539. }
  3540. });
  3541. function _widget(options) {
  3542. return new KWidget(options);
  3543. }
  3544. K.WidgetClass = KWidget;
  3545. K.widget = _widget;
  3546. function _iframeDoc(iframe) {
  3547. iframe = _get(iframe);
  3548. return iframe.contentDocument || iframe.contentWindow.document;
  3549. }
  3550. var html, _direction = '';
  3551. if ((html = document.getElementsByTagName('html'))) {
  3552. _direction = html[0].dir;
  3553. }
  3554. function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
  3555. var arr = [
  3556. (_direction === '' ? '<html>' : '<html dir="' + _direction + '">'),
  3557. '<head><meta charset="utf-8" /><title></title>',
  3558. '<style>',
  3559. 'html {margin:0;padding:0;}',
  3560. 'body {margin:0;padding:5px;}',
  3561. 'body, td {font:12px/1.5 "sans serif",tahoma,verdana,helvetica;}',
  3562. 'body, p, div {word-wrap: break-word;}',
  3563. 'p {margin:5px 0;}',
  3564. 'table {border-collapse:collapse;}',
  3565. 'img {border:0;}',
  3566. 'noscript {display:none;}',
  3567. 'table.ke-zeroborder td {border:1px dotted #AAA;}',
  3568. 'img.ke-flash {',
  3569. ' border:1px solid #AAA;',
  3570. ' background-image:url(' + themesPath + 'common/flash.gif);',
  3571. ' background-position:center center;',
  3572. ' background-repeat:no-repeat;',
  3573. ' width:100px;',
  3574. ' height:100px;',
  3575. '}',
  3576. 'img.ke-rm {',
  3577. ' border:1px solid #AAA;',
  3578. ' background-image:url(' + themesPath + 'common/rm.gif);',
  3579. ' background-position:center center;',
  3580. ' background-repeat:no-repeat;',
  3581. ' width:100px;',
  3582. ' height:100px;',
  3583. '}',
  3584. 'img.ke-media {',
  3585. ' border:1px solid #AAA;',
  3586. ' background-image:url(' + themesPath + 'common/media.gif);',
  3587. ' background-position:center center;',
  3588. ' background-repeat:no-repeat;',
  3589. ' width:100px;',
  3590. ' height:100px;',
  3591. '}',
  3592. 'img.ke-anchor {',
  3593. ' border:1px dashed #666;',
  3594. ' width:16px;',
  3595. ' height:16px;',
  3596. '}',
  3597. '.ke-script, .ke-noscript, .ke-display-none {',
  3598. ' display:none;',
  3599. ' font-size:0;',
  3600. ' width:0;',
  3601. ' height:0;',
  3602. '}',
  3603. '.ke-pagebreak {',
  3604. ' border:1px dotted #AAA;',
  3605. ' font-size:0;',
  3606. ' height:2px;',
  3607. '}',
  3608. '</style>'
  3609. ];
  3610. if (!_isArray(cssPath)) {
  3611. cssPath = [cssPath];
  3612. }
  3613. _each(cssPath, function(i, path) {
  3614. if (path) {
  3615. arr.push('<link href="' + path + '" rel="stylesheet" />');
  3616. }
  3617. });
  3618. if (cssData) {
  3619. arr.push('<style>' + cssData + '</style>');
  3620. }
  3621. arr.push('</head><body ' + (bodyClass ? 'class="' + bodyClass + '"' : '') + '></body></html>');
  3622. return arr.join('\n');
  3623. }
  3624. function _elementVal(knode, val) {
  3625. if (knode.hasVal()) {
  3626. if (val === undefined) {
  3627. var html = knode.val();
  3628. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  3629. return html;
  3630. }
  3631. return knode.val(val);
  3632. }
  3633. return knode.html(val);
  3634. }
  3635. function KEdit(options) {
  3636. this.init(options);
  3637. }
  3638. _extend(KEdit, KWidget, {
  3639. init : function(options) {
  3640. var self = this;
  3641. KEdit.parent.init.call(self, options);
  3642. self.srcElement = K(options.srcElement);
  3643. self.div.addClass('ke-edit');
  3644. self.designMode = _undef(options.designMode, true);
  3645. self.beforeGetHtml = options.beforeGetHtml;
  3646. self.beforeSetHtml = options.beforeSetHtml;
  3647. self.afterSetHtml = options.afterSetHtml;
  3648. var themesPath = _undef(options.themesPath, ''),
  3649. bodyClass = options.bodyClass,
  3650. cssPath = options.cssPath,
  3651. cssData = options.cssData,
  3652. isDocumentDomain = location.protocol != 'res:' && location.host.replace(/:\d+/, '') !== document.domain,
  3653. srcScript = ('document.open();' +
  3654. (isDocumentDomain ? 'document.domain="' + document.domain + '";' : '') +
  3655. 'document.close();'),
  3656. iframeSrc = _IE ? ' src="javascript:void(function(){' + encodeURIComponent(srcScript) + '}())"' : '';
  3657. self.iframe = K('<iframe class="ke-edit-iframe" hidefocus="true" frameborder="0"' + iframeSrc + '></iframe>').css('width', '100%');
  3658. self.textarea = K('<textarea class="ke-edit-textarea" hidefocus="true"></textarea>').css('width', '100%');
  3659. self.tabIndex = isNaN(parseInt(options.tabIndex, 10)) ? self.srcElement.attr('tabindex') : parseInt(options.tabIndex, 10);
  3660. self.iframe.attr('tabindex', self.tabIndex);
  3661. self.textarea.attr('tabindex', self.tabIndex);
  3662. if (self.width) {
  3663. self.setWidth(self.width);
  3664. }
  3665. if (self.height) {
  3666. self.setHeight(self.height);
  3667. }
  3668. if (self.designMode) {
  3669. self.textarea.hide();
  3670. } else {
  3671. self.iframe.hide();
  3672. }
  3673. function ready() {
  3674. var doc = _iframeDoc(self.iframe);
  3675. doc.open();
  3676. if (isDocumentDomain) {
  3677. doc.domain = document.domain;
  3678. }
  3679. doc.write(_getInitHtml(themesPath, bodyClass, cssPath, cssData));
  3680. doc.close();
  3681. self.win = self.iframe[0].contentWindow;
  3682. self.doc = doc;
  3683. var cmd = _cmd(doc);
  3684. self.afterChange(function(e) {
  3685. cmd.selection();
  3686. });
  3687. if (_WEBKIT) {
  3688. K(doc).click(function(e) {
  3689. if (K(e.target).name === 'img') {
  3690. cmd.selection(true);
  3691. cmd.range.selectNode(e.target);
  3692. cmd.select();
  3693. }
  3694. });
  3695. }
  3696. if (_IE) {
  3697. self._mousedownHandler = function() {
  3698. var newRange = cmd.range.cloneRange();
  3699. newRange.shrink();
  3700. if (newRange.isControl()) {
  3701. self.blur();
  3702. }
  3703. };
  3704. K(document).mousedown(self._mousedownHandler);
  3705. K(doc).keydown(function(e) {
  3706. if (e.which == 8) {
  3707. cmd.selection();
  3708. var rng = cmd.range;
  3709. if (rng.isControl()) {
  3710. rng.collapse(true);
  3711. K(rng.startContainer.childNodes[rng.startOffset]).remove();
  3712. e.preventDefault();
  3713. }
  3714. }
  3715. });
  3716. }
  3717. self.cmd = cmd;
  3718. self.html(_elementVal(self.srcElement));
  3719. if (_IE) {
  3720. doc.body.disabled = true;
  3721. doc.body.contentEditable = true;
  3722. doc.body.removeAttribute('disabled');
  3723. } else {
  3724. doc.designMode = 'on';
  3725. }
  3726. if (options.afterCreate) {
  3727. options.afterCreate.call(self);
  3728. }
  3729. }
  3730. if (isDocumentDomain) {
  3731. self.iframe.bind('load', function(e) {
  3732. self.iframe.unbind('load');
  3733. if (_IE) {
  3734. ready();
  3735. } else {
  3736. setTimeout(ready, 0);
  3737. }
  3738. });
  3739. }
  3740. self.div.append(self.iframe);
  3741. self.div.append(self.textarea);
  3742. self.srcElement.hide();
  3743. !isDocumentDomain && ready();
  3744. },
  3745. setWidth : function(val) {
  3746. var self = this;
  3747. val = _addUnit(val);
  3748. self.width = val;
  3749. self.div.css('width', val);
  3750. return self;
  3751. },
  3752. setHeight : function(val) {
  3753. var self = this;
  3754. val = _addUnit(val);
  3755. self.height = val;
  3756. self.div.css('height', val);
  3757. self.iframe.css('height', val);
  3758. if ((_IE && _V < 8) || _QUIRKS) {
  3759. val = _addUnit(_removeUnit(val) - 2);
  3760. }
  3761. self.textarea.css('height', val);
  3762. return self;
  3763. },
  3764. remove : function() {
  3765. var self = this, doc = self.doc;
  3766. K(doc.body).unbind();
  3767. K(doc).unbind();
  3768. K(self.win).unbind();
  3769. if (self._mousedownHandler) {
  3770. K(document).unbind('mousedown', self._mousedownHandler);
  3771. }
  3772. _elementVal(self.srcElement, self.html());
  3773. self.srcElement.show();
  3774. self.iframe.unbind();
  3775. self.textarea.unbind();
  3776. KEdit.parent.remove.call(self);
  3777. },
  3778. html : function(val, isFull) {
  3779. var self = this, doc = self.doc;
  3780. if (self.designMode) {
  3781. var body = doc.body;
  3782. if (val === undefined) {
  3783. if (isFull) {
  3784. val = '<!doctype html><html>' + body.parentNode.innerHTML + '</html>';
  3785. } else {
  3786. val = body.innerHTML;
  3787. }
  3788. if (self.beforeGetHtml) {
  3789. val = self.beforeGetHtml(val);
  3790. }
  3791. if (_GECKO && val == '<br />') {
  3792. val = '';
  3793. }
  3794. return val;
  3795. }
  3796. if (self.beforeSetHtml) {
  3797. val = self.beforeSetHtml(val);
  3798. }
  3799. if (_IE && _V >= 9) {
  3800. val = val.replace(/(<.*?checked=")checked(".*>)/ig, '$1$2');
  3801. }
  3802. K(body).html(val);
  3803. if (self.afterSetHtml) {
  3804. self.afterSetHtml();
  3805. }
  3806. return self;
  3807. }
  3808. if (val === undefined) {
  3809. return self.textarea.val();
  3810. }
  3811. self.textarea.val(val);
  3812. return self;
  3813. },
  3814. design : function(bool) {
  3815. var self = this, val;
  3816. if (bool === undefined ? !self.designMode : bool) {
  3817. if (!self.designMode) {
  3818. val = self.html();
  3819. self.designMode = true;
  3820. self.textarea.hide();
  3821. self.html(val);
  3822. var iframe = self.iframe;
  3823. var height = _removeUnit(self.height);
  3824. iframe.height(height - 2);
  3825. iframe.show();
  3826. setTimeout(function() {
  3827. iframe.height(height);
  3828. }, 0);
  3829. }
  3830. } else {
  3831. if (self.designMode) {
  3832. val = self.html();
  3833. self.designMode = false;
  3834. self.html(val);
  3835. self.iframe.hide();
  3836. self.textarea.show();
  3837. }
  3838. }
  3839. return self.focus();
  3840. },
  3841. focus : function() {
  3842. var self = this;
  3843. //self.designMode ? self.win.focus() : self.textarea[0].focus();
  3844. return self;
  3845. },
  3846. blur : function() {
  3847. var self = this;
  3848. if (_IE) {
  3849. var input = K('<input type="text" style="float:left;width:0;height:0;padding:0;margin:0;border:0;" value="" />', self.div);
  3850. self.div.append(input);
  3851. input[0].focus();
  3852. input.remove();
  3853. } else {
  3854. self.designMode ? self.win.blur() : self.textarea[0].blur();
  3855. }
  3856. return self;
  3857. },
  3858. afterChange : function(fn) {
  3859. var self = this, doc = self.doc, body = doc.body;
  3860. K(doc).keyup(function(e) {
  3861. if (!e.ctrlKey && !e.altKey && _CHANGE_KEY_MAP[e.which]) {
  3862. fn(e);
  3863. }
  3864. });
  3865. K(doc).mouseup(fn).contextmenu(fn);
  3866. K(self.win).blur(fn);
  3867. function timeoutHandler(e) {
  3868. setTimeout(function() {
  3869. fn(e);
  3870. }, 1);
  3871. }
  3872. K(body).bind('paste', timeoutHandler);
  3873. K(body).bind('cut', timeoutHandler);
  3874. return self;
  3875. }
  3876. });
  3877. function _edit(options) {
  3878. return new KEdit(options);
  3879. }
  3880. K.EditClass = KEdit;
  3881. K.edit = _edit;
  3882. K.iframeDoc = _iframeDoc;
  3883. function _selectToolbar(name, fn) {
  3884. var self = this,
  3885. knode = self.get(name);
  3886. if (knode) {
  3887. if (knode.hasClass('ke-disabled')) {
  3888. return;
  3889. }
  3890. fn(knode);
  3891. }
  3892. }
  3893. function KToolbar(options) {
  3894. this.init(options);
  3895. }
  3896. _extend(KToolbar, KWidget, {
  3897. init : function(options) {
  3898. var self = this;
  3899. KToolbar.parent.init.call(self, options);
  3900. self.disableMode = _undef(options.disableMode, false);
  3901. self.noDisableItemMap = _toMap(_undef(options.noDisableItems, []));
  3902. self._itemMap = {};
  3903. self.div.addClass('ke-toolbar').bind('contextmenu,mousedown,mousemove', function(e) {
  3904. e.preventDefault();
  3905. }).attr('unselectable', 'on');
  3906. function find(target) {
  3907. var knode = K(target);
  3908. if (knode.hasClass('ke-outline')) {
  3909. return knode;
  3910. }
  3911. if (knode.hasClass('ke-toolbar-icon')) {
  3912. return knode.parent();
  3913. }
  3914. }
  3915. function hover(e, method) {
  3916. var knode = find(e.target);
  3917. if (knode) {
  3918. if (knode.hasClass('ke-disabled')) {
  3919. return;
  3920. }
  3921. if (knode.hasClass('ke-selected')) {
  3922. return;
  3923. }
  3924. knode[method]('ke-on');
  3925. }
  3926. }
  3927. self.div.mouseover(function(e) {
  3928. hover(e, 'addClass');
  3929. })
  3930. .mouseout(function(e) {
  3931. hover(e, 'removeClass');
  3932. })
  3933. .click(function(e) {
  3934. var knode = find(e.target);
  3935. if (knode) {
  3936. if (knode.hasClass('ke-disabled')) {
  3937. return;
  3938. }
  3939. self.options.click.call(this, e, knode.attr('data-name'));
  3940. }
  3941. });
  3942. },
  3943. get : function(name) {
  3944. if (this._itemMap[name]) {
  3945. return this._itemMap[name];
  3946. }
  3947. return (this._itemMap[name] = K('span.ke-icon-' + name, this.div).parent());
  3948. },
  3949. select : function(name) {
  3950. _selectToolbar.call(this, name, function(knode) {
  3951. knode.addClass('ke-selected');
  3952. });
  3953. return self;
  3954. },
  3955. unselect : function(name) {
  3956. _selectToolbar.call(this, name, function(knode) {
  3957. knode.removeClass('ke-selected').removeClass('ke-on');
  3958. });
  3959. return self;
  3960. },
  3961. enable : function(name) {
  3962. var self = this,
  3963. knode = name.get ? name : self.get(name);
  3964. if (knode) {
  3965. knode.removeClass('ke-disabled');
  3966. knode.opacity(1);
  3967. }
  3968. return self;
  3969. },
  3970. disable : function(name) {
  3971. var self = this,
  3972. knode = name.get ? name : self.get(name);
  3973. if (knode) {
  3974. knode.removeClass('ke-selected').addClass('ke-disabled');
  3975. knode.opacity(0.5);
  3976. }
  3977. return self;
  3978. },
  3979. disableAll : function(bool, noDisableItems) {
  3980. var self = this, map = self.noDisableItemMap, item;
  3981. if (noDisableItems) {
  3982. map = _toMap(noDisableItems);
  3983. }
  3984. if (bool === undefined ? !self.disableMode : bool) {
  3985. K('span.ke-outline', self.div).each(function() {
  3986. var knode = K(this),
  3987. name = knode[0].getAttribute('data-name', 2);
  3988. if (!map[name]) {
  3989. self.disable(knode);
  3990. }
  3991. });
  3992. self.disableMode = true;
  3993. } else {
  3994. K('span.ke-outline', self.div).each(function() {
  3995. var knode = K(this),
  3996. name = knode[0].getAttribute('data-name', 2);
  3997. if (!map[name]) {
  3998. self.enable(knode);
  3999. }
  4000. });
  4001. self.disableMode = false;
  4002. }
  4003. return self;
  4004. }
  4005. });
  4006. function _toolbar(options) {
  4007. return new KToolbar(options);
  4008. }
  4009. K.ToolbarClass = KToolbar;
  4010. K.toolbar = _toolbar;
  4011. function KMenu(options) {
  4012. this.init(options);
  4013. }
  4014. _extend(KMenu, KWidget, {
  4015. init : function(options) {
  4016. var self = this;
  4017. options.z = options.z || 811213;
  4018. KMenu.parent.init.call(self, options);
  4019. self.centerLineMode = _undef(options.centerLineMode, true);
  4020. self.div.addClass('ke-menu').bind('click,mousedown', function(e){
  4021. e.stopPropagation();
  4022. }).attr('unselectable', 'on');
  4023. },
  4024. addItem : function(item) {
  4025. var self = this;
  4026. if (item.title === '-') {
  4027. self.div.append(K('<div class="ke-menu-separator"></div>'));
  4028. return;
  4029. }
  4030. var itemDiv = K('<div class="ke-menu-item" unselectable="on"></div>'),
  4031. leftDiv = K('<div class="ke-inline-block ke-menu-item-left"></div>'),
  4032. rightDiv = K('<div class="ke-inline-block ke-menu-item-right"></div>'),
  4033. height = _addUnit(item.height),
  4034. iconClass = _undef(item.iconClass, '');
  4035. self.div.append(itemDiv);
  4036. if (height) {
  4037. itemDiv.css('height', height);
  4038. rightDiv.css('line-height', height);
  4039. }
  4040. var centerDiv;
  4041. if (self.centerLineMode) {
  4042. centerDiv = K('<div class="ke-inline-block ke-menu-item-center"></div>');
  4043. if (height) {
  4044. centerDiv.css('height', height);
  4045. }
  4046. }
  4047. itemDiv.mouseover(function(e) {
  4048. K(this).addClass('ke-menu-item-on');
  4049. if (centerDiv) {
  4050. centerDiv.addClass('ke-menu-item-center-on');
  4051. }
  4052. })
  4053. .mouseout(function(e) {
  4054. K(this).removeClass('ke-menu-item-on');
  4055. if (centerDiv) {
  4056. centerDiv.removeClass('ke-menu-item-center-on');
  4057. }
  4058. })
  4059. .click(function(e) {
  4060. item.click.call(K(this));
  4061. e.stopPropagation();
  4062. })
  4063. .append(leftDiv);
  4064. if (centerDiv) {
  4065. itemDiv.append(centerDiv);
  4066. }
  4067. itemDiv.append(rightDiv);
  4068. if (item.checked) {
  4069. iconClass = 'ke-icon-checked';
  4070. }
  4071. if (iconClass !== '') {
  4072. leftDiv.html('<span class="ke-inline-block ke-toolbar-icon ke-toolbar-icon-url ' + iconClass + '"></span>');
  4073. }
  4074. rightDiv.html(item.title);
  4075. return self;
  4076. },
  4077. remove : function() {
  4078. var self = this;
  4079. if (self.options.beforeRemove) {
  4080. self.options.beforeRemove.call(self);
  4081. }
  4082. K('.ke-menu-item', self.div[0]).unbind();
  4083. KMenu.parent.remove.call(self);
  4084. return self;
  4085. }
  4086. });
  4087. function _menu(options) {
  4088. return new KMenu(options);
  4089. }
  4090. K.MenuClass = KMenu;
  4091. K.menu = _menu;
  4092. function KColorPicker(options) {
  4093. this.init(options);
  4094. }
  4095. _extend(KColorPicker, KWidget, {
  4096. init : function(options) {
  4097. var self = this;
  4098. options.z = options.z || 811213;
  4099. KColorPicker.parent.init.call(self, options);
  4100. var colors = options.colors || [
  4101. ['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500'],
  4102. ['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF'],
  4103. ['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE'],
  4104. ['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000']
  4105. ];
  4106. self.selectedColor = (options.selectedColor || '').toLowerCase();
  4107. self._cells = [];
  4108. self.div.addClass('ke-colorpicker').bind('click,mousedown', function(e){
  4109. e.stopPropagation();
  4110. }).attr('unselectable', 'on');
  4111. var table = self.doc.createElement('table');
  4112. self.div.append(table);
  4113. table.className = 'ke-colorpicker-table';
  4114. table.cellPadding = 0;
  4115. table.cellSpacing = 0;
  4116. table.border = 0;
  4117. var row = table.insertRow(0), cell = row.insertCell(0);
  4118. cell.colSpan = colors[0].length;
  4119. self._addAttr(cell, '', 'ke-colorpicker-cell-top');
  4120. for (var i = 0; i < colors.length; i++) {
  4121. row = table.insertRow(i + 1);
  4122. for (var j = 0; j < colors[i].length; j++) {
  4123. cell = row.insertCell(j);
  4124. self._addAttr(cell, colors[i][j], 'ke-colorpicker-cell');
  4125. }
  4126. }
  4127. },
  4128. _addAttr : function(cell, color, cls) {
  4129. var self = this;
  4130. cell = K(cell).addClass(cls);
  4131. if (self.selectedColor === color.toLowerCase()) {
  4132. cell.addClass('ke-colorpicker-cell-selected');
  4133. }
  4134. cell.attr('title', color || self.options.noColor);
  4135. cell.mouseover(function(e) {
  4136. K(this).addClass('ke-colorpicker-cell-on');
  4137. });
  4138. cell.mouseout(function(e) {
  4139. K(this).removeClass('ke-colorpicker-cell-on');
  4140. });
  4141. cell.click(function(e) {
  4142. e.stop();
  4143. self.options.click.call(K(this), color);
  4144. });
  4145. if (color) {
  4146. cell.append(K('<div class="ke-colorpicker-cell-color" unselectable="on"></div>').css('background-color', color));
  4147. } else {
  4148. cell.html(self.options.noColor);
  4149. }
  4150. K(cell).attr('unselectable', 'on');
  4151. self._cells.push(cell);
  4152. },
  4153. remove : function() {
  4154. var self = this;
  4155. _each(self._cells, function() {
  4156. this.unbind();
  4157. });
  4158. KColorPicker.parent.remove.call(self);
  4159. return self;
  4160. }
  4161. });
  4162. function _colorpicker(options) {
  4163. return new KColorPicker(options);
  4164. }
  4165. K.ColorPickerClass = KColorPicker;
  4166. K.colorpicker = _colorpicker;
  4167. function KUploadButton(options) {
  4168. this.init(options);
  4169. }
  4170. _extend(KUploadButton, {
  4171. init : function(options) {
  4172. var self = this,
  4173. button = K(options.button),
  4174. fieldName = options.fieldName || 'file',
  4175. url = options.url || '',
  4176. title = button.val(),
  4177. extraParams = options.extraParams || {},
  4178. cls = button[0].className || '',
  4179. target = options.target || 'kindeditor_upload_iframe_' + new Date().getTime();
  4180. options.afterError = options.afterError || function(str) {
  4181. alert(str);
  4182. };
  4183. var hiddenElements = [];
  4184. for(var k in extraParams){
  4185. hiddenElements.push('<input type="hidden" class="ke-upload-file-'+k+'" name="' + k + '" value="' + extraParams[k] + '" />');
  4186. }
  4187. var html = [
  4188. '<div class="ke-inline-block ' + cls + '">',
  4189. (options.target ? '' : '<iframe name="' + target + '" style="display:none;"></iframe>'),
  4190. (options.form ? '<div class="ke-upload-area">' : '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + url + '">'),
  4191. '<span class="ke-button-common">',
  4192. hiddenElements.join(''),
  4193. '<input type="button" class="ke-button-common ke-button" value="' + title + '" />',
  4194. '</span>',
  4195. '<input type="file" class="ke-upload-file" name="' + fieldName + '" tabindex="-1" />',
  4196. (options.form ? '</div>' : '</form>'),
  4197. '</div>'].join('');
  4198. var div = K(html, button.doc);
  4199. button.hide();
  4200. button.before(div);
  4201. self.div = div;
  4202. self.button = button;
  4203. self.iframe = options.target ? K('iframe[name="' + target + '"]') : K('iframe', div);
  4204. self.form = options.form ? K(options.form) : K('form', div);
  4205. self.fileBox = K('.ke-upload-file', div);
  4206. var width = options.width || K('.ke-button-common', div).width();
  4207. K('.ke-upload-area', div).width(width);
  4208. self.options = options;
  4209. },
  4210. submit : function(e) {
  4211. var self = this,
  4212. iframe = self.iframe;
  4213. e = false;
  4214. if (e) {
  4215. var file = e.files[0];
  4216. var filename = file.name;
  4217. var temp = filename.split('.');
  4218. //putExtra.params["x:name"] = temp[0];
  4219. var filename = hex_md5(file.name) + '.' + temp[temp.length-1];
  4220. var path = $('.' + 'ke-upload-file-key').val();
  4221. $('.' + 'ke-upload-file-key').val(path + filename);
  4222. //这里要修改 以后再改
  4223. } else {
  4224. iframe.bind('load', function() {
  4225. iframe.unbind();
  4226. var tempForm = document.createElement('form');
  4227. self.fileBox.before(tempForm);
  4228. K(tempForm).append(self.fileBox);
  4229. tempForm.reset();
  4230. K(tempForm).remove(true);
  4231. var doc = K.iframeDoc(iframe),
  4232. pre = doc.getElementsByTagName('pre')[0],
  4233. str = '', data;
  4234. if (pre) {
  4235. str = pre.innerHTML;
  4236. } else {
  4237. str = doc.body.innerHTML;
  4238. }
  4239. str = _unescape(str);
  4240. iframe[0].src = 'javascript:false';
  4241. try {
  4242. data = K.json(str);
  4243. } catch (e) {
  4244. self.options.afterError.call(self, '<!doctype html><html>' + doc.body.parentNode.innerHTML + '</html>');
  4245. }
  4246. if (data) {
  4247. self.options.afterUpload.call(self, data);
  4248. }
  4249. });
  4250. self.form[0].submit();
  4251. }
  4252. self.form[0].submit();
  4253. return self;
  4254. },
  4255. remove : function() {
  4256. var self = this;
  4257. if (self.fileBox) {
  4258. self.fileBox.unbind();
  4259. }
  4260. self.iframe.remove();
  4261. self.div.remove();
  4262. self.button.show();
  4263. return self;
  4264. }
  4265. });
  4266. function _uploadbutton(options) {
  4267. return new KUploadButton(options);
  4268. }
  4269. K.UploadButtonClass = KUploadButton;
  4270. K.uploadbutton = _uploadbutton;
  4271. function _createButton(arg) {
  4272. arg = arg || {};
  4273. var name = arg.name || '',
  4274. span = K('<span class="ke-button-common ke-button-outer" title="' + name + '"></span>'),
  4275. btn = K('<input class="ke-button-common ke-button" type="button" value="' + name + '" />');
  4276. if (arg.click) {
  4277. btn.click(arg.click);
  4278. }
  4279. span.append(btn);
  4280. return span;
  4281. }
  4282. function KDialog(options) {
  4283. this.init(options);
  4284. }
  4285. _extend(KDialog, KWidget, {
  4286. init : function(options) {
  4287. var self = this;
  4288. var shadowMode = _undef(options.shadowMode, true);
  4289. options.z = options.z || 811213;
  4290. options.shadowMode = false;
  4291. options.autoScroll = _undef(options.autoScroll, true);
  4292. KDialog.parent.init.call(self, options);
  4293. var title = options.title,
  4294. body = K(options.body, self.doc),
  4295. previewBtn = options.previewBtn,
  4296. yesBtn = options.yesBtn,
  4297. noBtn = options.noBtn,
  4298. closeBtn = options.closeBtn,
  4299. showMask = _undef(options.showMask, true);
  4300. self.div.addClass('ke-dialog').bind('click,mousedown', function(e){
  4301. e.stopPropagation();
  4302. });
  4303. var contentDiv = K('<div class="ke-dialog-content"></div>').appendTo(self.div);
  4304. if (_IE && _V < 7) {
  4305. self.iframeMask = K('<iframe src="about:blank" class="ke-dialog-shadow"></iframe>').appendTo(self.div);
  4306. } else if (shadowMode) {
  4307. K('<div class="ke-dialog-shadow"></div>').appendTo(self.div);
  4308. }
  4309. var headerDiv = K('<div class="ke-dialog-header"></div>');
  4310. contentDiv.append(headerDiv);
  4311. headerDiv.html(title);
  4312. self.closeIcon = K('<span class="ke-dialog-icon-close" title="' + closeBtn.name + '"></span>').click(closeBtn.click);
  4313. headerDiv.append(self.closeIcon);
  4314. self.draggable({
  4315. clickEl : headerDiv,
  4316. beforeDrag : options.beforeDrag
  4317. });
  4318. var bodyDiv = K('<div class="ke-dialog-body"></div>');
  4319. contentDiv.append(bodyDiv);
  4320. bodyDiv.append(body);
  4321. var footerDiv = K('<div class="ke-dialog-footer"></div>');
  4322. if (previewBtn || yesBtn || noBtn) {
  4323. contentDiv.append(footerDiv);
  4324. }
  4325. _each([
  4326. { btn : previewBtn, name : 'preview' },
  4327. { btn : yesBtn, name : 'yes' },
  4328. { btn : noBtn, name : 'no' }
  4329. ], function() {
  4330. if (this.btn) {
  4331. var button = _createButton(this.btn);
  4332. button.addClass('ke-dialog-' + this.name);
  4333. footerDiv.append(button);
  4334. }
  4335. });
  4336. if (self.height) {
  4337. bodyDiv.height(_removeUnit(self.height) - headerDiv.height() - footerDiv.height());
  4338. }
  4339. self.div.width(self.div.width());
  4340. self.div.height(self.div.height());
  4341. self.mask = null;
  4342. if (showMask) {
  4343. var docEl = _docElement(self.doc),
  4344. docWidth = Math.max(docEl.scrollWidth, docEl.clientWidth),
  4345. docHeight = Math.max(docEl.scrollHeight, docEl.clientHeight);
  4346. self.mask = _widget({
  4347. x : 0,
  4348. y : 0,
  4349. z : self.z - 1,
  4350. cls : 'ke-dialog-mask',
  4351. width : docWidth,
  4352. height : docHeight
  4353. });
  4354. }
  4355. self.autoPos(self.div.width(), self.div.height());
  4356. self.footerDiv = footerDiv;
  4357. self.bodyDiv = bodyDiv;
  4358. self.headerDiv = headerDiv;
  4359. self.isLoading = false;
  4360. },
  4361. setMaskIndex : function(z) {
  4362. var self = this;
  4363. self.mask.div.css('z-index', z);
  4364. },
  4365. showLoading : function(msg) {
  4366. msg = _undef(msg, '');
  4367. var self = this, body = self.bodyDiv;
  4368. 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>')
  4369. .width(body.width()).height(body.height())
  4370. .css('top', self.headerDiv.height() + 'px');
  4371. body.css('visibility', 'hidden').after(self.loading);
  4372. self.isLoading = true;
  4373. return self;
  4374. },
  4375. hideLoading : function() {
  4376. this.loading && this.loading.remove();
  4377. this.bodyDiv.css('visibility', 'visible');
  4378. this.isLoading = false;
  4379. return this;
  4380. },
  4381. remove : function() {
  4382. var self = this;
  4383. if (self.options.beforeRemove) {
  4384. self.options.beforeRemove.call(self);
  4385. }
  4386. self.mask && self.mask.remove();
  4387. self.iframeMask && self.iframeMask.remove();
  4388. self.closeIcon.unbind();
  4389. K('input', self.div).unbind();
  4390. K('button', self.div).unbind();
  4391. self.footerDiv.unbind();
  4392. self.bodyDiv.unbind();
  4393. self.headerDiv.unbind();
  4394. K('iframe', self.div).each(function() {
  4395. K(this).remove();
  4396. });
  4397. KDialog.parent.remove.call(self);
  4398. return self;
  4399. }
  4400. });
  4401. function _dialog(options) {
  4402. return new KDialog(options);
  4403. }
  4404. K.DialogClass = KDialog;
  4405. K.dialog = _dialog;
  4406. function _tabs(options) {
  4407. var self = _widget(options),
  4408. remove = self.remove,
  4409. afterSelect = options.afterSelect,
  4410. div = self.div,
  4411. liList = [];
  4412. div.addClass('ke-tabs')
  4413. .bind('contextmenu,mousedown,mousemove', function(e) {
  4414. e.preventDefault();
  4415. });
  4416. var ul = K('<ul class="ke-tabs-ul ke-clearfix"></ul>');
  4417. div.append(ul);
  4418. self.add = function(tab) {
  4419. var li = K('<li class="ke-tabs-li">' + tab.title + '</li>');
  4420. li.data('tab', tab);
  4421. liList.push(li);
  4422. ul.append(li);
  4423. };
  4424. self.selectedIndex = 0;
  4425. self.select = function(index) {
  4426. self.selectedIndex = index;
  4427. _each(liList, function(i, li) {
  4428. li.unbind();
  4429. if (i === index) {
  4430. li.addClass('ke-tabs-li-selected');
  4431. K(li.data('tab').panel).show('');
  4432. } else {
  4433. li.removeClass('ke-tabs-li-selected').removeClass('ke-tabs-li-on')
  4434. .mouseover(function() {
  4435. K(this).addClass('ke-tabs-li-on');
  4436. })
  4437. .mouseout(function() {
  4438. K(this).removeClass('ke-tabs-li-on');
  4439. })
  4440. .click(function() {
  4441. self.select(i);
  4442. });
  4443. K(li.data('tab').panel).hide();
  4444. }
  4445. });
  4446. if (afterSelect) {
  4447. afterSelect.call(self, index);
  4448. }
  4449. };
  4450. self.remove = function() {
  4451. _each(liList, function() {
  4452. this.remove();
  4453. });
  4454. ul.remove();
  4455. remove.call(self);
  4456. };
  4457. return self;
  4458. }
  4459. K.tabs = _tabs;
  4460. function _loadScript(url, fn) {
  4461. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4462. script = document.createElement('script');
  4463. head.appendChild(script);
  4464. script.src = url;
  4465. script.charset = 'utf-8';
  4466. script.onload = script.onreadystatechange = function() {
  4467. if (!this.readyState || this.readyState === 'loaded') {
  4468. if (fn) {
  4469. fn();
  4470. }
  4471. script.onload = script.onreadystatechange = null;
  4472. head.removeChild(script);
  4473. }
  4474. };
  4475. }
  4476. function _chopQuery(url) {
  4477. var index = url.indexOf('?');
  4478. return index > 0 ? url.substr(0, index) : url;
  4479. }
  4480. function _loadStyle(url) {
  4481. var head = document.getElementsByTagName('head')[0] || (_QUIRKS ? document.body : document.documentElement),
  4482. link = document.createElement('link'),
  4483. absoluteUrl = _chopQuery(_formatUrl(url, 'absolute'));
  4484. var links = K('link[rel="stylesheet"]', head);
  4485. for (var i = 0, len = links.length; i < len; i++) {
  4486. if (_chopQuery(_formatUrl(links[i].href, 'absolute')) === absoluteUrl) {
  4487. return;
  4488. }
  4489. }
  4490. head.appendChild(link);
  4491. link.href = url;
  4492. link.rel = 'stylesheet';
  4493. }
  4494. function _ajax(url, fn, method, param, dataType) {
  4495. method = method || 'GET';
  4496. dataType = dataType || 'json';
  4497. var xhr = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
  4498. xhr.open(method, url, true);
  4499. xhr.onreadystatechange = function () {
  4500. if (xhr.readyState == 4 && xhr.status == 200) {
  4501. if (fn) {
  4502. var data = _trim(xhr.responseText);
  4503. if (dataType == 'json') {
  4504. data = _json(data);
  4505. }
  4506. fn(data);
  4507. }
  4508. }
  4509. };
  4510. if (method == 'POST') {
  4511. var params = [];
  4512. _each(param, function(key, val) {
  4513. params.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
  4514. });
  4515. try {
  4516. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4517. } catch (e) {}
  4518. xhr.send(params.join('&'));
  4519. } else {
  4520. xhr.send(null);
  4521. }
  4522. }
  4523. K.loadScript = _loadScript;
  4524. K.loadStyle = _loadStyle;
  4525. K.ajax = _ajax;
  4526. var _plugins = {};
  4527. function _plugin(name, fn) {
  4528. if (name === undefined) {
  4529. return _plugins;
  4530. }
  4531. if (!fn) {
  4532. return _plugins[name];
  4533. }
  4534. _plugins[name] = fn;
  4535. }
  4536. var _language = {};
  4537. function _parseLangKey(key) {
  4538. var match, ns = 'core';
  4539. if ((match = /^(\w+)\.(\w+)$/.exec(key))) {
  4540. ns = match[1];
  4541. key = match[2];
  4542. }
  4543. return { ns : ns, key : key };
  4544. }
  4545. function _lang(mixed, langType) {
  4546. langType = langType === undefined ? K.options.langType : langType;
  4547. if (typeof mixed === 'string') {
  4548. if (!_language[langType]) {
  4549. return 'no language';
  4550. }
  4551. var pos = mixed.length - 1;
  4552. if (mixed.substr(pos) === '.') {
  4553. return _language[langType][mixed.substr(0, pos)];
  4554. }
  4555. var obj = _parseLangKey(mixed);
  4556. return _language[langType][obj.ns][obj.key];
  4557. }
  4558. _each(mixed, function(key, val) {
  4559. var obj = _parseLangKey(key);
  4560. if (!_language[langType]) {
  4561. _language[langType] = {};
  4562. }
  4563. if (!_language[langType][obj.ns]) {
  4564. _language[langType][obj.ns] = {};
  4565. }
  4566. _language[langType][obj.ns][obj.key] = val;
  4567. });
  4568. }
  4569. function _getImageFromRange(range, fn) {
  4570. if (range.collapsed) {
  4571. return;
  4572. }
  4573. range = range.cloneRange().up();
  4574. var sc = range.startContainer, so = range.startOffset;
  4575. if (!_WEBKIT && !range.isControl()) {
  4576. return;
  4577. }
  4578. var img = K(sc.childNodes[so]);
  4579. if (!img || img.name != 'img') {
  4580. return;
  4581. }
  4582. if (fn(img)) {
  4583. return img;
  4584. }
  4585. }
  4586. function _bindContextmenuEvent() {
  4587. var self = this, doc = self.edit.doc;
  4588. K(doc).contextmenu(function(e) {
  4589. if (self.menu) {
  4590. self.hideMenu();
  4591. }
  4592. if (!self.useContextmenu) {
  4593. e.preventDefault();
  4594. return;
  4595. }
  4596. if (self._contextmenus.length === 0) {
  4597. return;
  4598. }
  4599. var maxWidth = 0, items = [];
  4600. _each(self._contextmenus, function() {
  4601. if (this.title == '-') {
  4602. items.push(this);
  4603. return;
  4604. }
  4605. if (this.cond && this.cond()) {
  4606. items.push(this);
  4607. if (this.width && this.width > maxWidth) {
  4608. maxWidth = this.width;
  4609. }
  4610. }
  4611. });
  4612. while (items.length > 0 && items[0].title == '-') {
  4613. items.shift();
  4614. }
  4615. while (items.length > 0 && items[items.length - 1].title == '-') {
  4616. items.pop();
  4617. }
  4618. var prevItem = null;
  4619. _each(items, function(i) {
  4620. if (this.title == '-' && prevItem.title == '-') {
  4621. delete items[i];
  4622. }
  4623. prevItem = this;
  4624. });
  4625. if (items.length > 0) {
  4626. e.preventDefault();
  4627. var pos = K(self.edit.iframe).pos(),
  4628. menu = _menu({
  4629. x : pos.x + e.clientX,
  4630. y : pos.y + e.clientY,
  4631. width : maxWidth,
  4632. css : { visibility: 'hidden' },
  4633. shadowMode : self.shadowMode
  4634. });
  4635. _each(items, function() {
  4636. if (this.title) {
  4637. menu.addItem(this);
  4638. }
  4639. });
  4640. var docEl = _docElement(menu.doc),
  4641. menuHeight = menu.div.height();
  4642. if (e.clientY + menuHeight >= docEl.clientHeight - 100) {
  4643. menu.pos(menu.x, _removeUnit(menu.y) - menuHeight);
  4644. }
  4645. menu.div.css('visibility', 'visible');
  4646. self.menu = menu;
  4647. }
  4648. });
  4649. }
  4650. function _bindNewlineEvent() {
  4651. var self = this, doc = self.edit.doc, newlineTag = self.newlineTag;
  4652. if (_IE && newlineTag !== 'br') {
  4653. return;
  4654. }
  4655. if (_GECKO && _V < 3 && newlineTag !== 'p') {
  4656. return;
  4657. }
  4658. if (_OPERA && _V < 9) {
  4659. return;
  4660. }
  4661. var brSkipTagMap = _toMap('h1,h2,h3,h4,h5,h6,pre,li'),
  4662. pSkipTagMap = _toMap('p,h1,h2,h3,h4,h5,h6,pre,li,blockquote');
  4663. function getAncestorTagName(range) {
  4664. var ancestor = K(range.commonAncestor());
  4665. while (ancestor) {
  4666. if (ancestor.type == 1 && !ancestor.isStyle()) {
  4667. break;
  4668. }
  4669. ancestor = ancestor.parent();
  4670. }
  4671. return ancestor.name;
  4672. }
  4673. K(doc).keydown(function(e) {
  4674. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4675. autoImg(self);
  4676. return;
  4677. }
  4678. self.cmd.selection();
  4679. var tagName = getAncestorTagName(self.cmd.range);
  4680. if (tagName == 'marquee' || tagName == 'select') {
  4681. return;
  4682. }
  4683. if (newlineTag === 'br' && !brSkipTagMap[tagName]) {
  4684. e.preventDefault();
  4685. self.insertHtml('<br />' + (_IE && _V < 9 ? '' : '\u200B'));
  4686. return;
  4687. }
  4688. if (!pSkipTagMap[tagName]) {
  4689. _nativeCommand(doc, 'formatblock', '<p>');
  4690. }
  4691. });
  4692. K(doc).keyup(function(e) {
  4693. if (e.which != 13 || e.shiftKey || e.ctrlKey || e.altKey) {
  4694. return;
  4695. }
  4696. if (newlineTag == 'br') {
  4697. return;
  4698. }
  4699. if (_GECKO) {
  4700. var root = self.cmd.commonAncestor('p');
  4701. var a = self.cmd.commonAncestor('a');
  4702. if (a && a.text() == '') {
  4703. a.remove(true);
  4704. self.cmd.range.selectNodeContents(root[0]).collapse(true);
  4705. self.cmd.select();
  4706. }
  4707. return;
  4708. }
  4709. self.cmd.selection();
  4710. var tagName = getAncestorTagName(self.cmd.range);
  4711. if (tagName == 'marquee' || tagName == 'select') {
  4712. return;
  4713. }
  4714. if (!pSkipTagMap[tagName]) {
  4715. _nativeCommand(doc, 'formatblock', '<p>');
  4716. }
  4717. var div = self.cmd.commonAncestor('div');
  4718. if (div) {
  4719. var p = K('<p></p>'),
  4720. child = div[0].firstChild;
  4721. while (child) {
  4722. var next = child.nextSibling;
  4723. p.append(child);
  4724. child = next;
  4725. }
  4726. div.before(p);
  4727. div.remove();
  4728. self.cmd.range.selectNodeContents(p[0]);
  4729. self.cmd.select();
  4730. }
  4731. });
  4732. }
  4733. function _bindTabEvent() {
  4734. var self = this, doc = self.edit.doc;
  4735. K(doc).keydown(function(e) {
  4736. if (e.which == 9) {
  4737. e.preventDefault();
  4738. if (self.afterTab) {
  4739. self.afterTab.call(self, e);
  4740. return;
  4741. }
  4742. var cmd = self.cmd, range = cmd.range;
  4743. range.shrink();
  4744. if (range.collapsed && range.startContainer.nodeType == 1) {
  4745. range.insertNode(K('@&nbsp;', doc)[0]);
  4746. cmd.select();
  4747. }
  4748. self.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;');
  4749. }
  4750. });
  4751. }
  4752. function _bindFocusEvent() {
  4753. var self = this;
  4754. K(self.edit.textarea[0], self.edit.win).focus(function(e) {
  4755. if (self.afterFocus) {
  4756. self.afterFocus.call(self, e);
  4757. }
  4758. }).blur(function(e) {
  4759. if (self.afterBlur) {
  4760. self.afterBlur.call(self, e);
  4761. }
  4762. });
  4763. }
  4764. function _removeBookmarkTag(html) {
  4765. return _trim(html.replace(/<span [^>]*id="?__kindeditor_bookmark_\w+_\d+__"?[^>]*><\/span>/ig, ''));
  4766. }
  4767. function _removeTempTag(html) {
  4768. return html.replace(/<div[^>]+class="?__kindeditor_paste__"?[^>]*>[\s\S]*?<\/div>/ig, '');
  4769. }
  4770. function _addBookmarkToStack(stack, bookmark) {
  4771. if (stack.length === 0) {
  4772. stack.push(bookmark);
  4773. return;
  4774. }
  4775. var prev = stack[stack.length - 1];
  4776. if (_removeBookmarkTag(bookmark.html) !== _removeBookmarkTag(prev.html)) {
  4777. stack.push(bookmark);
  4778. }
  4779. }
  4780. function _undoToRedo(fromStack, toStack) {
  4781. var self = this, edit = self.edit,
  4782. body = edit.doc.body,
  4783. range, bookmark;
  4784. if (fromStack.length === 0) {
  4785. return self;
  4786. }
  4787. if (edit.designMode) {
  4788. range = self.cmd.range;
  4789. bookmark = range.createBookmark(true);
  4790. bookmark.html = body.innerHTML;
  4791. } else {
  4792. bookmark = {
  4793. html : body.innerHTML
  4794. };
  4795. }
  4796. _addBookmarkToStack(toStack, bookmark);
  4797. var prev = fromStack.pop();
  4798. if (_removeBookmarkTag(bookmark.html) === _removeBookmarkTag(prev.html) && fromStack.length > 0) {
  4799. prev = fromStack.pop();
  4800. }
  4801. if (edit.designMode) {
  4802. edit.html(prev.html);
  4803. if (prev.start) {
  4804. range.moveToBookmark(prev);
  4805. self.select();
  4806. }
  4807. } else {
  4808. K(body).html(_removeBookmarkTag(prev.html));
  4809. }
  4810. return self;
  4811. }
  4812. function KEditor(options) {
  4813. var self = this;
  4814. self.options = {};
  4815. function setOption(key, val) {
  4816. if (KEditor.prototype[key] === undefined) {
  4817. self[key] = val;
  4818. }
  4819. self.options[key] = val;
  4820. }
  4821. _each(options, function(key, val) {
  4822. setOption(key, options[key]);
  4823. });
  4824. _each(K.options, function(key, val) {
  4825. if (self[key] === undefined) {
  4826. setOption(key, val);
  4827. }
  4828. });
  4829. var se = K(self.srcElement || '<textarea/>');
  4830. if (!self.width) {
  4831. self.width = se[0].style.width || se.width();
  4832. if (!self.width) {
  4833. self.width = '700';
  4834. }
  4835. }
  4836. if (!self.height) {
  4837. self.height = se[0].style.height || se.height();
  4838. }
  4839. setOption('width', _undef(self.width, self.minWidth));
  4840. setOption('height', _undef(self.height, self.minHeight));
  4841. setOption('width', _addUnit(self.width));
  4842. setOption('height', _addUnit(self.height));
  4843. if (_MOBILE && (!_IOS || _V < 534)) {
  4844. //self.designMode = false;
  4845. }
  4846. self.srcElement = se;
  4847. self.initContent = '';
  4848. self.plugin = {};
  4849. self.isCreated = false;
  4850. self._handlers = {};
  4851. self._contextmenus = [];
  4852. self._undoStack = [];
  4853. self._redoStack = [];
  4854. self._firstAddBookmark = true;
  4855. self.menu = self.contextmenu = null;
  4856. self.dialogs = [];
  4857. }
  4858. KEditor.prototype = {
  4859. lang : function(mixed) {
  4860. return _lang(mixed, this.langType);
  4861. },
  4862. loadPlugin : function(name, fn) {
  4863. var self = this;
  4864. var _pluginStatus = this._pluginStatus;
  4865. if (!_pluginStatus) {
  4866. _pluginStatus = this._pluginStatus = {};
  4867. }
  4868. if (_plugins[name]) {
  4869. if (!_isFunction(_plugins[name])) {
  4870. setTimeout(function() {
  4871. self.loadPlugin(name, fn);
  4872. }, 100);
  4873. return self;
  4874. }
  4875. if(!_pluginStatus[name]) {
  4876. _plugins[name].call(self, KindEditor);
  4877. _pluginStatus[name] = 'inited';
  4878. }
  4879. if (fn) {
  4880. fn.call(self);
  4881. }
  4882. return self;
  4883. }
  4884. _plugins[name] = 'loading';
  4885. _loadScript(self.pluginsPath + name + '/' + name + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  4886. setTimeout(function() {
  4887. if (_plugins[name]) {
  4888. self.loadPlugin(name, fn);
  4889. }
  4890. }, 0);
  4891. });
  4892. return self;
  4893. },
  4894. handler : function(key, fn) {
  4895. var self = this;
  4896. if (!self._handlers[key]) {
  4897. self._handlers[key] = [];
  4898. }
  4899. if (_isFunction(fn)) {
  4900. self._handlers[key].push(fn);
  4901. return self;
  4902. }
  4903. _each(self._handlers[key], function() {
  4904. fn = this.call(self, fn);
  4905. });
  4906. return fn;
  4907. },
  4908. clickToolbar : function(name, fn) {
  4909. var self = this, key = 'clickToolbar' + name;
  4910. if (fn === undefined) {
  4911. if (self._handlers[key]) {
  4912. return self.handler(key);
  4913. }
  4914. self.loadPlugin(name, function() {
  4915. self.handler(key);
  4916. });
  4917. return self;
  4918. }
  4919. return self.handler(key, fn);
  4920. },
  4921. updateState : function() {
  4922. var self = this;
  4923. _each(('justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,insertunorderedlist,' +
  4924. 'subscript,superscript,bold,italic,underline,strikethrough').split(','), function(i, name) {
  4925. self.cmd.state(name) ? self.toolbar.select(name) : self.toolbar.unselect(name);
  4926. });
  4927. return self;
  4928. },
  4929. addContextmenu : function(item) {
  4930. this._contextmenus.push(item);
  4931. return this;
  4932. },
  4933. afterCreate : function(fn) {
  4934. return this.handler('afterCreate', fn);
  4935. },
  4936. beforeRemove : function(fn) {
  4937. return this.handler('beforeRemove', fn);
  4938. },
  4939. beforeGetHtml : function(fn) {
  4940. return this.handler('beforeGetHtml', fn);
  4941. },
  4942. beforeSetHtml : function(fn) {
  4943. return this.handler('beforeSetHtml', fn);
  4944. },
  4945. afterSetHtml : function(fn) {
  4946. return this.handler('afterSetHtml', fn);
  4947. },
  4948. create : function() {
  4949. var self = this, fullscreenMode = self.fullscreenMode;
  4950. if (self.isCreated) {
  4951. return self;
  4952. }
  4953. if (self.srcElement.data('kindeditor')) {
  4954. return self;
  4955. }
  4956. self.srcElement.data('kindeditor', 'true');
  4957. if (fullscreenMode) {
  4958. _docElement().style.overflow = 'hidden';
  4959. } else {
  4960. _docElement().style.overflow = '';
  4961. }
  4962. var width = fullscreenMode ? _docElement().clientWidth + 'px' : self.width,
  4963. height = fullscreenMode ? _docElement().clientHeight + 'px' : self.height;
  4964. if ((_IE && _V < 8) || _QUIRKS) {
  4965. height = _addUnit(_removeUnit(height) + 2);
  4966. }
  4967. var container = self.container = K(self.layout);
  4968. if (fullscreenMode) {
  4969. K(document.body).append(container);
  4970. } else {
  4971. self.srcElement.before(container);
  4972. }
  4973. var toolbarDiv = K('.toolbar', container),
  4974. editDiv = K('.edit', container),
  4975. statusbar = self.statusbar = K('.statusbar', container);
  4976. container.removeClass('container')
  4977. .addClass('ke-container ke-container-' + self.themeType).css('width', width);
  4978. if (fullscreenMode) {
  4979. container.css({
  4980. position : 'absolute',
  4981. left : 0,
  4982. top : 0,
  4983. 'z-index' : 811211
  4984. });
  4985. if (!_GECKO) {
  4986. self._scrollPos = _getScrollPos();
  4987. }
  4988. window.scrollTo(0, 0);
  4989. K(document.body).css({
  4990. 'height' : '1px',
  4991. 'overflow' : 'hidden'
  4992. });
  4993. K(document.body.parentNode).css('overflow', 'hidden');
  4994. self._fullscreenExecuted = true;
  4995. } else {
  4996. if (self._fullscreenExecuted) {
  4997. K(document.body).css({
  4998. 'height' : '',
  4999. 'overflow' : ''
  5000. });
  5001. K(document.body.parentNode).css('overflow', '');
  5002. }
  5003. if (self._scrollPos) {
  5004. window.scrollTo(self._scrollPos.x, self._scrollPos.y);
  5005. }
  5006. }
  5007. var htmlList = [];
  5008. K.each(self.items, function(i, name) {
  5009. if (name == '|') {
  5010. htmlList.push('<span class="ke-inline-block ke-separator"></span>');
  5011. } else if (name == '/') {
  5012. htmlList.push('<div class="ke-hr"></div>');
  5013. } else {
  5014. htmlList.push('<span class="ke-outline" data-name="' + name + '" title="' + self.lang(name) + '" unselectable="on">');
  5015. htmlList.push('<span class="ke-toolbar-icon ke-toolbar-icon-url ke-icon-' + name + '" unselectable="on"></span></span>');
  5016. }
  5017. });
  5018. var toolbar = self.toolbar = _toolbar({
  5019. src : toolbarDiv,
  5020. html : htmlList.join(''),
  5021. noDisableItems : self.noDisableItems,
  5022. click : function(e, name) {
  5023. e.stop();
  5024. if (self.menu) {
  5025. var menuName = self.menu.name;
  5026. self.hideMenu();
  5027. if (menuName === name) {
  5028. return;
  5029. }
  5030. }
  5031. self.clickToolbar(name);
  5032. }
  5033. });
  5034. var editHeight = _removeUnit(height) - toolbar.div.height();
  5035. var edit = self.edit = _edit({
  5036. height : editHeight > 0 && _removeUnit(height) > self.minHeight ? editHeight : self.minHeight,
  5037. src : editDiv,
  5038. srcElement : self.srcElement,
  5039. designMode : self.designMode,
  5040. themesPath : self.themesPath,
  5041. bodyClass : self.bodyClass,
  5042. cssPath : self.cssPath,
  5043. cssData : self.cssData,
  5044. beforeGetHtml : function(html) {
  5045. html = self.beforeGetHtml(html);
  5046. html = _removeBookmarkTag(_removeTempTag(html));
  5047. return _formatHtml(html, self.filterMode ? self.htmlTags : null, self.urlType, self.wellFormatMode, self.indentChar);
  5048. },
  5049. beforeSetHtml : function(html) {
  5050. html = _formatHtml(html, self.filterMode ? self.htmlTags : null, '', false);
  5051. return self.beforeSetHtml(html);
  5052. },
  5053. afterSetHtml : function() {
  5054. self.edit = edit = this;
  5055. self.afterSetHtml();
  5056. },
  5057. afterCreate : function() {
  5058. self.edit = edit = this;
  5059. self.cmd = edit.cmd;
  5060. self._docMousedownFn = function(e) {
  5061. if (self.menu) {
  5062. self.hideMenu();
  5063. }
  5064. };
  5065. K(edit.doc, document).mousedown(self._docMousedownFn);
  5066. _bindContextmenuEvent.call(self);
  5067. _bindNewlineEvent.call(self);
  5068. _bindTabEvent.call(self);
  5069. _bindFocusEvent.call(self);
  5070. edit.afterChange(function(e) {
  5071. if (!edit.designMode) {
  5072. return;
  5073. }
  5074. self.updateState();
  5075. self.addBookmark();
  5076. if (self.options.afterChange) {
  5077. self.options.afterChange.call(self);
  5078. }
  5079. });
  5080. edit.textarea.keyup(function(e) {
  5081. if (!e.ctrlKey && !e.altKey && _INPUT_KEY_MAP[e.which]) {
  5082. if (self.options.afterChange) {
  5083. self.options.afterChange.call(self);
  5084. }
  5085. }
  5086. });
  5087. if (self.readonlyMode) {
  5088. self.readonly();
  5089. }
  5090. self.isCreated = true;
  5091. if (self.initContent === '') {
  5092. self.initContent = self.html();
  5093. }
  5094. if (self._undoStack.length > 0) {
  5095. var prev = self._undoStack.pop();
  5096. if (prev.start) {
  5097. self.html(prev.html);
  5098. edit.cmd.range.moveToBookmark(prev);
  5099. self.select();
  5100. }
  5101. }
  5102. self.afterCreate();
  5103. if (self.options.afterCreate) {
  5104. self.options.afterCreate.call(self);
  5105. }
  5106. }
  5107. });
  5108. statusbar.removeClass('statusbar').addClass('ke-statusbar')
  5109. .append('<span class="ke-inline-block ke-statusbar-center-icon"></span>')
  5110. .append('<span class="ke-inline-block ke-statusbar-right-icon"></span>');
  5111. if (self._fullscreenResizeHandler) {
  5112. K(window).unbind('resize', self._fullscreenResizeHandler);
  5113. self._fullscreenResizeHandler = null;
  5114. }
  5115. function initResize() {
  5116. if (statusbar.height() === 0) {
  5117. setTimeout(initResize, 100);
  5118. return;
  5119. }
  5120. self.resize(width, height, false);
  5121. }
  5122. initResize();
  5123. if (fullscreenMode) {
  5124. self._fullscreenResizeHandler = function(e) {
  5125. if (self.isCreated) {
  5126. self.resize(_docElement().clientWidth, _docElement().clientHeight, false);
  5127. }
  5128. };
  5129. K(window).bind('resize', self._fullscreenResizeHandler);
  5130. toolbar.select('fullscreen');
  5131. statusbar.first().css('visibility', 'hidden');
  5132. statusbar.last().css('visibility', 'hidden');
  5133. } else {
  5134. if (_GECKO) {
  5135. K(window).bind('scroll', function(e) {
  5136. self._scrollPos = _getScrollPos();
  5137. });
  5138. }
  5139. if (self.resizeType > 0) {
  5140. _drag({
  5141. moveEl : container,
  5142. clickEl : statusbar,
  5143. moveFn : function(x, y, width, height, diffX, diffY) {
  5144. height += diffY;
  5145. self.resize(null, height);
  5146. }
  5147. });
  5148. } else {
  5149. statusbar.first().css('visibility', 'hidden');
  5150. }
  5151. if (self.resizeType === 2) {
  5152. _drag({
  5153. moveEl : container,
  5154. clickEl : statusbar.last(),
  5155. moveFn : function(x, y, width, height, diffX, diffY) {
  5156. width += diffX;
  5157. height += diffY;
  5158. self.resize(width, height);
  5159. }
  5160. });
  5161. } else {
  5162. statusbar.last().css('visibility', 'hidden');
  5163. }
  5164. }
  5165. return self;
  5166. },
  5167. remove : function() {
  5168. var self = this;
  5169. if (!self.isCreated) {
  5170. return self;
  5171. }
  5172. self.beforeRemove();
  5173. self.srcElement.data('kindeditor', '');
  5174. if (self.menu) {
  5175. self.hideMenu();
  5176. }
  5177. _each(self.dialogs, function() {
  5178. self.hideDialog();
  5179. });
  5180. K(document).unbind('mousedown', self._docMousedownFn);
  5181. self.toolbar.remove();
  5182. self.edit.remove();
  5183. self.statusbar.last().unbind();
  5184. self.statusbar.unbind();
  5185. self.container.remove();
  5186. self.container = self.toolbar = self.edit = self.menu = null;
  5187. self.dialogs = [];
  5188. self.isCreated = false;
  5189. return self;
  5190. },
  5191. resize : function(width, height, updateProp) {
  5192. var self = this;
  5193. updateProp = _undef(updateProp, true);
  5194. if (width) {
  5195. if (!/%/.test(width)) {
  5196. width = _removeUnit(width);
  5197. width = width < self.minWidth ? self.minWidth : width;
  5198. }
  5199. self.container.css('width', _addUnit(width));
  5200. if (updateProp) {
  5201. self.width = _addUnit(width);
  5202. }
  5203. }
  5204. if (height) {
  5205. height = _removeUnit(height);
  5206. var editHeight = _removeUnit(height) - self.toolbar.div.height() - self.statusbar.height();
  5207. editHeight = editHeight < self.minHeight ? self.minHeight : editHeight;
  5208. self.edit.setHeight(editHeight);
  5209. if (updateProp) {
  5210. self.height = _addUnit(height);
  5211. }
  5212. }
  5213. return self;
  5214. },
  5215. select : function() {
  5216. this.isCreated && this.cmd.select();
  5217. return this;
  5218. },
  5219. html : function(val) {
  5220. var self = this;
  5221. if (val === undefined) {
  5222. return self.isCreated ? self.edit.html() : _elementVal(self.srcElement);
  5223. }
  5224. self.isCreated ? self.edit.html(val) : _elementVal(self.srcElement, val);
  5225. if (self.isCreated) {
  5226. self.cmd.selection();
  5227. }
  5228. return self;
  5229. },
  5230. fullHtml : function() {
  5231. return this.isCreated ? this.edit.html(undefined, true) : '';
  5232. },
  5233. text : function(val) {
  5234. var self = this;
  5235. if (val === undefined) {
  5236. return _trim(self.html().replace(/<(?!img|embed).*?>/ig, '').replace(/&nbsp;/ig, ' '));
  5237. } else {
  5238. return self.html(_escape(val));
  5239. }
  5240. },
  5241. isEmpty : function() {
  5242. return _trim(this.text().replace(/\r\n|\n|\r/, '')) === '';
  5243. },
  5244. isDirty : function() {
  5245. return _trim(this.initContent.replace(/\r\n|\n|\r|t/g, '')) !== _trim(this.html().replace(/\r\n|\n|\r|t/g, ''));
  5246. },
  5247. selectedHtml : function() {
  5248. var val = this.isCreated ? this.cmd.range.html() : '';
  5249. val = _removeBookmarkTag(_removeTempTag(val));
  5250. return val;
  5251. },
  5252. count : function(mode) {
  5253. var self = this;
  5254. mode = (mode || 'html').toLowerCase();
  5255. if (mode === 'html') {
  5256. return self.html().length;
  5257. }
  5258. if (mode === 'text') {
  5259. return self.text().replace(/<(?:img|embed).*?>/ig, 'K').replace(/\r\n|\n|\r/g, '').length;
  5260. }
  5261. return 0;
  5262. },
  5263. exec : function(key) {
  5264. key = key.toLowerCase();
  5265. var self = this, cmd = self.cmd,
  5266. changeFlag = _inArray(key, 'selectall,copy,paste,print'.split(',')) < 0;
  5267. if (changeFlag) {
  5268. self.addBookmark(false);
  5269. }
  5270. cmd[key].apply(cmd, _toArray(arguments, 1));
  5271. if (changeFlag) {
  5272. self.updateState();
  5273. self.addBookmark(false);
  5274. if (self.options.afterChange) {
  5275. self.options.afterChange.call(self);
  5276. }
  5277. }
  5278. return self;
  5279. },
  5280. insertHtml : function(val, quickMode) {
  5281. if (!this.isCreated) {
  5282. return this;
  5283. }
  5284. val = this.beforeSetHtml(val);
  5285. this.exec('inserthtml', val, quickMode);
  5286. return this;
  5287. },
  5288. appendHtml : function(val) {
  5289. this.html(this.html() + val);
  5290. if (this.isCreated) {
  5291. var cmd = this.cmd;
  5292. cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
  5293. cmd.select();
  5294. }
  5295. return this;
  5296. },
  5297. sync : function() {
  5298. _elementVal(this.srcElement, this.html());
  5299. return this;
  5300. },
  5301. focus : function() {
  5302. this.isCreated ? this.edit.focus() : this.srcElement[0].focus();
  5303. return this;
  5304. },
  5305. blur : function() {
  5306. this.isCreated ? this.edit.blur() : this.srcElement[0].blur();
  5307. return this;
  5308. },
  5309. addBookmark : function(checkSize) {
  5310. checkSize = _undef(checkSize, true);
  5311. var self = this, edit = self.edit,
  5312. body = edit.doc.body,
  5313. html = _removeTempTag(body.innerHTML), bookmark;
  5314. if (checkSize && self._undoStack.length > 0) {
  5315. var prev = self._undoStack[self._undoStack.length - 1];
  5316. if (Math.abs(html.length - _removeBookmarkTag(prev.html).length) < self.minChangeSize) {
  5317. return self;
  5318. }
  5319. }
  5320. if (edit.designMode && !self._firstAddBookmark) {
  5321. var range = self.cmd.range;
  5322. bookmark = range.createBookmark(true);
  5323. bookmark.html = _removeTempTag(body.innerHTML);
  5324. range.moveToBookmark(bookmark);
  5325. } else {
  5326. bookmark = {
  5327. html : html
  5328. };
  5329. }
  5330. self._firstAddBookmark = false;
  5331. _addBookmarkToStack(self._undoStack, bookmark);
  5332. return self;
  5333. },
  5334. undo : function() {
  5335. return _undoToRedo.call(this, this._undoStack, this._redoStack);
  5336. },
  5337. redo : function() {
  5338. return _undoToRedo.call(this, this._redoStack, this._undoStack);
  5339. },
  5340. fullscreen : function(bool) {
  5341. this.fullscreenMode = (bool === undefined ? !this.fullscreenMode : bool);
  5342. this.addBookmark(false);
  5343. return this.remove().create();
  5344. },
  5345. readonly : function(isReadonly) {
  5346. isReadonly = _undef(isReadonly, true);
  5347. var self = this, edit = self.edit, doc = edit.doc;
  5348. if (self.designMode) {
  5349. self.toolbar.disableAll(isReadonly, []);
  5350. } else {
  5351. _each(self.noDisableItems, function() {
  5352. self.toolbar[isReadonly ? 'disable' : 'enable'](this);
  5353. });
  5354. }
  5355. if (_IE) {
  5356. doc.body.contentEditable = !isReadonly;
  5357. } else {
  5358. doc.designMode = isReadonly ? 'off' : 'on';
  5359. }
  5360. edit.textarea[0].disabled = isReadonly;
  5361. },
  5362. createMenu : function(options) {
  5363. var self = this,
  5364. name = options.name,
  5365. knode = self.toolbar.get(name),
  5366. pos = knode.pos();
  5367. options.x = pos.x;
  5368. options.y = pos.y + knode.height();
  5369. options.z = self.options.zIndex;
  5370. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5371. if (options.selectedColor !== undefined) {
  5372. options.cls = 'ke-colorpicker-' + self.themeType;
  5373. options.noColor = self.lang('noColor');
  5374. self.menu = _colorpicker(options);
  5375. } else {
  5376. options.cls = 'ke-menu-' + self.themeType;
  5377. options.centerLineMode = false;
  5378. self.menu = _menu(options);
  5379. }
  5380. return self.menu;
  5381. },
  5382. hideMenu : function() {
  5383. this.menu.remove();
  5384. this.menu = null;
  5385. return this;
  5386. },
  5387. hideContextmenu : function() {
  5388. this.contextmenu.remove();
  5389. this.contextmenu = null;
  5390. return this;
  5391. },
  5392. createDialog : function(options) {
  5393. var self = this, name = options.name;
  5394. options.z = self.options.zIndex;
  5395. options.shadowMode = _undef(options.shadowMode, self.shadowMode);
  5396. options.closeBtn = _undef(options.closeBtn, {
  5397. name : self.lang('close'),
  5398. click : function(e) {
  5399. self.hideDialog();
  5400. if (_IE && self.cmd) {
  5401. self.cmd.select();
  5402. }
  5403. }
  5404. });
  5405. options.noBtn = _undef(options.noBtn, {
  5406. name : self.lang(options.yesBtn ? 'no' : 'close'),
  5407. click : function(e) {
  5408. self.hideDialog();
  5409. if (_IE && self.cmd) {
  5410. self.cmd.select();
  5411. }
  5412. }
  5413. });
  5414. if (self.dialogAlignType != 'page') {
  5415. options.alignEl = self.container;
  5416. }
  5417. options.cls = 'ke-dialog-' + self.themeType;
  5418. if (self.dialogs.length > 0) {
  5419. var firstDialog = self.dialogs[0],
  5420. parentDialog = self.dialogs[self.dialogs.length - 1];
  5421. firstDialog.setMaskIndex(parentDialog.z + 2);
  5422. options.z = parentDialog.z + 3;
  5423. options.showMask = false;
  5424. }
  5425. var dialog = _dialog(options);
  5426. self.dialogs.push(dialog);
  5427. return dialog;
  5428. },
  5429. hideDialog : function() {
  5430. var self = this;
  5431. if (self.dialogs.length > 0) {
  5432. self.dialogs.pop().remove();
  5433. }
  5434. if (self.dialogs.length > 0) {
  5435. var firstDialog = self.dialogs[0],
  5436. parentDialog = self.dialogs[self.dialogs.length - 1];
  5437. firstDialog.setMaskIndex(parentDialog.z - 1);
  5438. }
  5439. return self;
  5440. },
  5441. errorDialog : function(html) {
  5442. var self = this;
  5443. var dialog = self.createDialog({
  5444. width : 750,
  5445. title : self.lang('uploadError'),
  5446. body : '<div style="padding:10px 20px;"><iframe frameborder="0" style="width:708px;height:400px;"></iframe></div>'
  5447. });
  5448. var iframe = K('iframe', dialog.div), doc = K.iframeDoc(iframe);
  5449. doc.open();
  5450. doc.write(html);
  5451. doc.close();
  5452. K(doc.body).css('background-color', '#FFF');
  5453. iframe[0].contentWindow.focus();
  5454. return self;
  5455. }
  5456. };
  5457. function _editor(options) {
  5458. return new KEditor(options);
  5459. }
  5460. var _instances = [];
  5461. function _create(expr, options) {
  5462. options = options || {};
  5463. options.basePath = _undef(options.basePath, K.basePath);
  5464. options.themesPath = _undef(options.themesPath, options.basePath + 'themes/');
  5465. options.langPath = _undef(options.langPath, options.basePath + 'lang/');
  5466. options.pluginsPath = _undef(options.pluginsPath, options.basePath + 'plugins/');
  5467. if (_undef(options.loadStyleMode, K.options.loadStyleMode)) {
  5468. var themeType = _undef(options.themeType, K.options.themeType);
  5469. _loadStyle(options.themesPath + 'default/default.css');
  5470. _loadStyle(options.themesPath + themeType + '/' + themeType + '.css');
  5471. }
  5472. function create(editor) {
  5473. _each(_plugins, function(name, fn) {
  5474. if (_isFunction(fn)) {
  5475. fn.call(editor, KindEditor);
  5476. if (!editor._pluginStatus) {
  5477. editor._pluginStatus = {};
  5478. }
  5479. editor._pluginStatus[name] = 'inited';
  5480. }
  5481. });
  5482. return editor.create();
  5483. }
  5484. var knode = K(expr);
  5485. if (!knode || knode.length === 0) {
  5486. return;
  5487. }
  5488. if (knode.length > 1) {
  5489. knode.each(function() {
  5490. _create(this, options);
  5491. });
  5492. return _instances[0];
  5493. }
  5494. options.srcElement = knode[0];
  5495. var editor = new KEditor(options);
  5496. _instances.push(editor);
  5497. if (_language[editor.langType]) {
  5498. return create(editor);
  5499. }
  5500. _loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(K.DEBUG ? _TIME : _VERSION), function() {
  5501. create(editor);
  5502. });
  5503. return editor;
  5504. }
  5505. function _eachEditor(expr, fn) {
  5506. K(expr).each(function(i, el) {
  5507. K.each(_instances, function(j, editor) {
  5508. if (editor && editor.srcElement[0] == el) {
  5509. fn.call(editor, j);
  5510. return false;
  5511. }
  5512. });
  5513. });
  5514. }
  5515. K.remove = function(expr) {
  5516. _eachEditor(expr, function(i) {
  5517. this.remove();
  5518. _instances.splice(i, 1);
  5519. });
  5520. };
  5521. K.sync = function(expr) {
  5522. _eachEditor(expr, function() {
  5523. this.sync();
  5524. });
  5525. };
  5526. K.html = function(expr, val) {
  5527. _eachEditor(expr, function() {
  5528. this.html(val);
  5529. });
  5530. };
  5531. K.insertHtml = function(expr, val) {
  5532. _eachEditor(expr, function() {
  5533. this.insertHtml(val);
  5534. });
  5535. };
  5536. K.appendHtml = function(expr, val) {
  5537. _eachEditor(expr, function() {
  5538. this.appendHtml(val);
  5539. });
  5540. };
  5541. if (_IE && _V < 7) {
  5542. _nativeCommand(document, 'BackgroundImageCache', true);
  5543. }
  5544. K.EditorClass = KEditor;
  5545. K.editor = _editor;
  5546. K.create = _create;
  5547. K.instances = _instances;
  5548. K.plugin = _plugin;
  5549. K.lang = _lang;
  5550. _plugin('core', function(K) {
  5551. var self = this,
  5552. shortcutKeys = {
  5553. undo : 'Z', redo : 'Y', bold : 'B', italic : 'I', underline : 'U', print : 'P', selectall : 'A'
  5554. };
  5555. self.afterSetHtml(function() {
  5556. if (self.options.afterChange) {
  5557. self.options.afterChange.call(self);
  5558. }
  5559. });
  5560. self.afterCreate(function() {
  5561. if (self.syncType != 'form') {
  5562. return;
  5563. }
  5564. var el = K(self.srcElement), hasForm = false;
  5565. while ((el = el.parent())) {
  5566. if (el.name == 'form') {
  5567. hasForm = true;
  5568. break;
  5569. }
  5570. }
  5571. if (hasForm) {
  5572. el.bind('submit', function(e) {
  5573. self.sync();
  5574. K(window).bind('unload', function() {
  5575. self.edit.textarea.remove();
  5576. });
  5577. });
  5578. var resetBtn = K('[type="reset"]', el);
  5579. resetBtn.click(function() {
  5580. self.html(self.initContent);
  5581. self.cmd.selection();
  5582. });
  5583. self.beforeRemove(function() {
  5584. el.unbind();
  5585. resetBtn.unbind();
  5586. });
  5587. }
  5588. });
  5589. self.clickToolbar('source', function() {
  5590. if (self.edit.designMode) {
  5591. self.toolbar.disableAll(true);
  5592. self.edit.design(false);
  5593. self.toolbar.select('source');
  5594. } else {
  5595. self.toolbar.disableAll(false);
  5596. self.edit.design(true);
  5597. self.toolbar.unselect('source');
  5598. if (_GECKO) {
  5599. setTimeout(function() {
  5600. self.cmd.selection();
  5601. }, 0);
  5602. } else {
  5603. self.cmd.selection();
  5604. }
  5605. }
  5606. self.designMode = self.edit.designMode;
  5607. });
  5608. self.afterCreate(function() {
  5609. if (!self.designMode) {
  5610. self.toolbar.disableAll(true).select('source');
  5611. }
  5612. });
  5613. self.clickToolbar('fullscreen', function() {
  5614. self.fullscreen();
  5615. });
  5616. if (self.fullscreenShortcut) {
  5617. var loaded = false;
  5618. self.afterCreate(function() {
  5619. K(self.edit.doc, self.edit.textarea).keyup(function(e) {
  5620. if (e.which == 27) {
  5621. setTimeout(function() {
  5622. self.fullscreen();
  5623. }, 0);
  5624. }
  5625. });
  5626. if (loaded) {
  5627. if (_IE && !self.designMode) {
  5628. return;
  5629. }
  5630. self.focus();
  5631. }
  5632. if (!loaded) {
  5633. loaded = true;
  5634. }
  5635. });
  5636. }
  5637. _each('undo,redo'.split(','), function(i, name) {
  5638. if (shortcutKeys[name]) {
  5639. self.afterCreate(function() {
  5640. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5641. self.clickToolbar(name);
  5642. });
  5643. });
  5644. }
  5645. self.clickToolbar(name, function() {
  5646. self[name]();
  5647. });
  5648. });
  5649. self.clickToolbar('formatblock', function() {
  5650. var blocks = self.lang('formatblock.formatBlock'),
  5651. heights = {
  5652. h1 : 28,
  5653. h2 : 24,
  5654. h3 : 18,
  5655. H4 : 14,
  5656. p : 12
  5657. },
  5658. curVal = self.cmd.val('formatblock'),
  5659. menu = self.createMenu({
  5660. name : 'formatblock',
  5661. width : self.langType == 'en' ? 200 : 150
  5662. });
  5663. _each(blocks, function(key, val) {
  5664. var style = 'font-size:' + heights[key] + 'px;';
  5665. if (key.charAt(0) === 'h') {
  5666. style += 'font-weight:bold;';
  5667. }
  5668. menu.addItem({
  5669. title : '<span style="' + style + '" unselectable="on">' + val + '</span>',
  5670. height : heights[key] + 12,
  5671. checked : (curVal === key || curVal === val),
  5672. click : function() {
  5673. self.select().exec('formatblock', '<' + key + '>').hideMenu();
  5674. }
  5675. });
  5676. });
  5677. });
  5678. self.clickToolbar('fontname', function() {
  5679. var curVal = self.cmd.val('fontname'),
  5680. menu = self.createMenu({
  5681. name : 'fontname',
  5682. width : 150
  5683. });
  5684. _each(self.lang('fontname.fontName'), function(key, val) {
  5685. menu.addItem({
  5686. title : '<span style="font-family: ' + key + ';" unselectable="on">' + val + '</span>',
  5687. checked : (curVal === key.toLowerCase() || curVal === val.toLowerCase()),
  5688. click : function() {
  5689. self.exec('fontname', key).hideMenu();
  5690. }
  5691. });
  5692. });
  5693. });
  5694. self.clickToolbar('fontsize', function() {
  5695. var curVal = self.cmd.val('fontsize'),
  5696. menu = self.createMenu({
  5697. name : 'fontsize',
  5698. width : 150
  5699. });
  5700. _each(self.fontSizeTable, function(i, val) {
  5701. menu.addItem({
  5702. title : '<span style="font-size:' + val + ';" unselectable="on">' + val + '</span>',
  5703. height : _removeUnit(val) + 12,
  5704. checked : curVal === val,
  5705. click : function() {
  5706. self.exec('fontsize', val).hideMenu();
  5707. }
  5708. });
  5709. });
  5710. });
  5711. self.clickToolbar('fontheight', function() {
  5712. var curVal = self.cmd.val('fontheight'),
  5713. menu = self.createMenu({
  5714. name : 'fontsize',
  5715. width : 150
  5716. });
  5717. _each(self.fontHeightTable, function(i, val) {
  5718. menu.addItem({
  5719. title : '<span unselectable="on">' + val + '</span>',
  5720. height : 20,
  5721. checked : curVal === val,
  5722. click : function() {
  5723. self.exec('fontheight', val).hideMenu();
  5724. }
  5725. });
  5726. });
  5727. });
  5728. _each('forecolor,hilitecolor'.split(','), function(i, name) {
  5729. self.clickToolbar(name, function() {
  5730. self.createMenu({
  5731. name : name,
  5732. selectedColor : self.cmd.val(name) || 'default',
  5733. colors : self.colorTable,
  5734. click : function(color) {
  5735. self.exec(name, color).hideMenu();
  5736. }
  5737. });
  5738. });
  5739. });
  5740. _each(('cut,copy,paste').split(','), function(i, name) {
  5741. self.clickToolbar(name, function() {
  5742. self.focus();
  5743. try {
  5744. self.exec(name, null);
  5745. } catch(e) {
  5746. alert(self.lang(name + 'Error'));
  5747. }
  5748. });
  5749. });
  5750. self.clickToolbar('about', function() {
  5751. var html = '<div style="margin:20px;">' +
  5752. '<div>KindEditor ' + _VERSION + '</div>' +
  5753. '<div>Copyright &copy; <a href="http://www.kindsoft.net/" target="_blank">kindsoft.net</a> All rights reserved.</div>' +
  5754. '</div>';
  5755. self.createDialog({
  5756. name : 'about',
  5757. width : 350,
  5758. title : self.lang('about'),
  5759. body : html
  5760. });
  5761. });
  5762. self.plugin.getSelectedLink = function() {
  5763. return self.cmd.commonAncestor('a');
  5764. };
  5765. self.plugin.getSelectedImage = function() {
  5766. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5767. return !/^ke-\w+$/i.test(img[0].className) && !img[0].getAttribute('data-key') && !img[0].getAttribute('data-applet') && !img[0].getAttribute('data-file');
  5768. });
  5769. };
  5770. self.plugin.getSelectedFlash = function() {
  5771. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5772. return img[0].className == 'ke-flash';
  5773. });
  5774. };
  5775. self.plugin.getSelectedMedia = function() {
  5776. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5777. return img[0].className == 'ke-media' || img[0].className == 'ke-rm' || img[0].getAttribute('data-file');
  5778. });
  5779. };
  5780. self.plugin.getSelectedDiy = function() {
  5781. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5782. return img[0].getAttribute('data-applet') || img[0].getAttribute('data-key');
  5783. });
  5784. };
  5785. self.plugin.getSelectedAnchor = function() {
  5786. return _getImageFromRange(self.edit.cmd.range, function(img) {
  5787. return img[0].className == 'ke-anchor';
  5788. });
  5789. };
  5790. _each('diy,link,image,flash,media,anchor'.split(','), function(i, name) {
  5791. var uName = name.charAt(0).toUpperCase() + name.substr(1);
  5792. _each('edit,delete'.split(','), function(j, val) {
  5793. self.addContextmenu({
  5794. title : self.lang(val + uName),
  5795. click : function() {
  5796. self.loadPlugin(name, function() {
  5797. self.plugin[name][val]();
  5798. self.hideMenu();
  5799. });
  5800. },
  5801. cond : self.plugin['getSelected' + uName],
  5802. width : 150,
  5803. iconClass : val == 'edit' ? 'ke-icon-' + name : undefined
  5804. });
  5805. });
  5806. self.addContextmenu({ title : '-' });
  5807. });
  5808. self.plugin.getSelectedTable = function() {
  5809. return self.cmd.commonAncestor('table');
  5810. };
  5811. self.plugin.getSelectedRow = function() {
  5812. return self.cmd.commonAncestor('tr');
  5813. };
  5814. self.plugin.getSelectedCell = function() {
  5815. return self.cmd.commonAncestor('td');
  5816. };
  5817. _each(('prop,cellprop,colinsertleft,colinsertright,rowinsertabove,rowinsertbelow,rowmerge,colmerge,' +
  5818. 'rowsplit,colsplit,coldelete,rowdelete,insert,delete').split(','), function(i, val) {
  5819. var cond = _inArray(val, ['prop', 'delete']) < 0 ? self.plugin.getSelectedCell : self.plugin.getSelectedTable;
  5820. self.addContextmenu({
  5821. title : self.lang('table' + val),
  5822. click : function() {
  5823. self.loadPlugin('table', function() {
  5824. self.plugin.table[val]();
  5825. self.hideMenu();
  5826. });
  5827. },
  5828. cond : cond,
  5829. width : 170,
  5830. iconClass : 'ke-icon-table' + val
  5831. });
  5832. });
  5833. self.addContextmenu({ title : '-' });
  5834. _each(('selectall,justifyleft,justifycenter,justifyright,justifyfull,insertorderedlist,' +
  5835. 'insertunorderedlist,indent,outdent,subscript,superscript,hr,print,' +
  5836. 'bold,italic,underline,strikethrough,removeformat,unlink').split(','), function(i, name) {
  5837. if (shortcutKeys[name]) {
  5838. self.afterCreate(function() {
  5839. _ctrl(this.edit.doc, shortcutKeys[name], function() {
  5840. self.cmd.selection();
  5841. self.clickToolbar(name);
  5842. });
  5843. });
  5844. }
  5845. self.clickToolbar(name, function() {
  5846. self.focus().exec(name, null);
  5847. });
  5848. });
  5849. self.afterCreate(function() {
  5850. var doc = self.edit.doc, cmd, bookmark, div,
  5851. cls = '__kindeditor_paste__', pasting = false;
  5852. function movePastedData() {
  5853. cmd.range.moveToBookmark(bookmark);
  5854. cmd.select();
  5855. if (_WEBKIT) {
  5856. K('div.' + cls, div).each(function() {
  5857. K(this).after('<br />').remove(true);
  5858. });
  5859. K('span.Apple-style-span', div).remove(true);
  5860. K('span.Apple-tab-span', div).remove(true);
  5861. K('span[style]', div).each(function() {
  5862. if (K(this).css('white-space') == 'nowrap') {
  5863. K(this).remove(true);
  5864. }
  5865. });
  5866. K('meta', div).remove();
  5867. }
  5868. var html = div[0].innerHTML;
  5869. div.remove();
  5870. if (html === '') {
  5871. return;
  5872. }
  5873. if (_WEBKIT) {
  5874. html = html.replace(/(<br>)\1/ig, '$1');
  5875. }
  5876. if (self.pasteType === 2) {
  5877. html = html.replace(/(<(?:p|p\s[^>]*)>) *(<\/p>)/ig, '');
  5878. if (/schemas-microsoft-com|worddocument|mso-\w+/i.test(html)) {
  5879. html = _clearMsWord(html, self.filterMode ? self.htmlTags : K.options.htmlTags);
  5880. } else {
  5881. html = _formatHtml(html, self.filterMode ? self.htmlTags : null);
  5882. html = self.beforeSetHtml(html);
  5883. }
  5884. }
  5885. if (self.pasteType === 1) {
  5886. html = html.replace(/&nbsp;/ig, ' ');
  5887. html = html.replace(/\n\s*\n/g, '\n');
  5888. html = html.replace(/<br[^>]*>/ig, '\n');
  5889. html = html.replace(/<\/p><p[^>]*>/ig, '\n');
  5890. html = html.replace(/<[^>]+>/g, '');
  5891. html = html.replace(/ {2}/g, ' &nbsp;');
  5892. if (self.newlineTag == 'p') {
  5893. if (/\n/.test(html)) {
  5894. html = html.replace(/^/, '<p>').replace(/$/, '<br /></p>').replace(/\n/g, '<br /></p><p>');
  5895. }
  5896. } else {
  5897. html = html.replace(/\n/g, '<br />$&');
  5898. }
  5899. }
  5900. self.insertHtml(html, true);
  5901. autoImg(self);
  5902. }
  5903. K(doc.body).bind('paste', function(e){
  5904. //处理IE11,Chrome粘贴图片上传
  5905. function dopasteImg() {
  5906. //debugger;
  5907. var file = null;
  5908. if (window.clipboardData) {//ie
  5909. if (clipboardData.files && clipboardData.files.length)//IE11
  5910. file = clipboardData.files[0];
  5911. else if (!clipboardData.getData("text") && !clipboardData.getData("url")) {
  5912. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5913. return true;
  5914. }
  5915. } else {
  5916. if (e.event.clipboardData.items)//chrome
  5917. for (var i = 0; i < e.event.clipboardData.items.length; i++) {
  5918. if (e.event.clipboardData.items[i].kind === "file") {
  5919. file = e.event.clipboardData.items[i];
  5920. break;
  5921. }
  5922. }
  5923. if (file == null) {
  5924. if (!e.event.clipboardData.getData("url") && !e.event.clipboardData.getData("text")) {
  5925. alert("不能粘贴文件或图片,请使用IE11或者Chrome浏览器,或使用上传功能");
  5926. return true;
  5927. }
  5928. }
  5929. }
  5930. if (file) {
  5931. if (!K.undef(self.allowImageUpload, true)) {
  5932. alert("编辑器禁止上传图片,请与有关人员联系!");
  5933. return true;
  5934. }
  5935. //获取File Blob
  5936. //debugger;
  5937. var blb;
  5938. if (file.getAsFile) {//Chrome
  5939. blb = file.getAsFile();
  5940. if (blb.size === 0) {
  5941. alert("不能获取剪切板中的" + (file.type.indexOf("image/") === 0 ? "图像" : "文件")
  5942. +"\n如果是从OutLook中复制的,请换其他程序,如Word");
  5943. return true;
  5944. }
  5945. sendfile(blb, file.type);
  5946. } else {
  5947. var fr = new FileReader();
  5948. if (fr.readAsArrayBuffer) {//ie
  5949. fr.onloadend = function (evt) {
  5950. blb = evt.target.result;
  5951. sendfile(blb, file.type);
  5952. }
  5953. fr.readAsArrayBuffer(file);
  5954. }
  5955. }
  5956. function sendfile(b, t) {
  5957. var xhr = new XMLHttpRequest();
  5958. var formData = new FormData();
  5959. var isImg = t.indexOf("image/") === 0;
  5960. //formData.append('imgFile', file,"untitled." + t.split('/')[1]);
  5961. //formData.append('imgFile', b);
  5962. var myBlob = new Blob([b], { "type": t });
  5963. formData.append(self.filePostName, myBlob, "untitled." + t.split('/')[1]);
  5964. //formData.append('imgFile', b);
  5965. formData.append('dir', isImg ? 'image' : 'file');
  5966. if (self.uploadYunJson && self.uploadYunJson.domain) {
  5967. formData.append('token', self.uploadYunJson.token);
  5968. xhr.open('POST', self.uploadYunJson.domain);
  5969. } else {
  5970. xhr.open('POST', self.uploadJson);
  5971. }
  5972. xhr.onreadystatechange = function () {
  5973. if (xhr.readyState == 4&&xhr.status == 200) {
  5974. // if (fn) {
  5975. var data = _trim(xhr.responseText);
  5976. //if (dataType == 'json') {
  5977. data = _json(data);
  5978. if (data.error) {
  5979. if (typeof ($) !== "undefined" && $.messager && $.messager.alert) {
  5980. $.messager.alert('Error', data.message, 'warning');
  5981. } else {
  5982. alert(data.message);
  5983. }
  5984. } else {
  5985. //self.exec('insertimage', url, title, width, height, border, align);
  5986. if(K.undef(self.formatUploadUrl, true))
  5987. data.url =K.formatUrl(data.url, 'absolute');
  5988. self.exec('insertimage', data.url, "from clipboard", undefined, undefined, undefined, undefined);
  5989. }
  5990. //}
  5991. // fn(data);
  5992. // }
  5993. }
  5994. }
  5995. xhr.send(formData);
  5996. }
  5997. return true;
  5998. }
  5999. }
  6000. //debugger;
  6001. if (dopasteImg())
  6002. e.stop();
  6003. //处理粘贴结束5825
  6004. if (self.pasteType === 0) {
  6005. e.stop();
  6006. return;
  6007. }
  6008. if (pasting) {
  6009. return;
  6010. }
  6011. pasting = true;
  6012. K('div.' + cls, doc).remove();
  6013. cmd = self.cmd.selection();
  6014. bookmark = cmd.range.createBookmark();
  6015. div = K('<div class="' + cls + '"></div>', doc).css({
  6016. position : 'absolute',
  6017. width : '1px',
  6018. height : '1px',
  6019. overflow : 'hidden',
  6020. left : '-1981px',
  6021. top : K(bookmark.start).pos().y + 'px',
  6022. 'white-space' : 'nowrap'
  6023. });
  6024. K(doc.body).append(div);
  6025. if (_IE) {
  6026. var rng = cmd.range.get(true);
  6027. rng.moveToElementText(div[0]);
  6028. rng.select();
  6029. rng.execCommand('paste');
  6030. e.preventDefault();
  6031. } else {
  6032. cmd.range.selectNodeContents(div[0]);
  6033. cmd.select();
  6034. div[0].tabIndex = -1;
  6035. div[0].focus();
  6036. }
  6037. setTimeout(function() {
  6038. movePastedData();
  6039. pasting = false;
  6040. }, 0);
  6041. });
  6042. });
  6043. self.beforeGetHtml(function(html) {
  6044. if (_IE && _V <= 8) {
  6045. html = html.replace(/<div\s+[^>]*data-ke-input-tag="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, tag) {
  6046. return unescape(tag);
  6047. });
  6048. html = html.replace(/(<input)((?:\s+[^>]*)?>)/ig, function($0, $1, $2) {
  6049. if (!/\s+type="[^"]+"/i.test($0)) {
  6050. return $1 + ' type="text"' + $2;
  6051. }
  6052. return $0;
  6053. });
  6054. }
  6055. return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
  6056. return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
  6057. })
  6058. .replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
  6059. var imgAttrs = _getAttrList(full);
  6060. var styles = _getCssList(imgAttrs.style || '');
  6061. var attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
  6062. var width = _undef(styles.width, '');
  6063. var height = _undef(styles.height, '');
  6064. if (/px/i.test(width)) {
  6065. width = _removeUnit(width);
  6066. }
  6067. if (/px/i.test(height)) {
  6068. height = _removeUnit(height);
  6069. }
  6070. attrs.width = _undef(imgAttrs.width, width);
  6071. attrs.height = _undef(imgAttrs.height, height);
  6072. return _mediaEmbed(attrs);
  6073. })
  6074. .replace(/<img[^>]*class="?ke-anchor"?[^>]*>/ig, function(full) {
  6075. var imgAttrs = _getAttrList(full);
  6076. return '<a name="' + unescape(imgAttrs['data-ke-name']) + '"></a>';
  6077. })
  6078. .replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6079. return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
  6080. })
  6081. .replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
  6082. return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
  6083. })
  6084. .replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
  6085. full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, function($0, $1, $2) {
  6086. return $1 + _unescape(src) + $2;
  6087. });
  6088. full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
  6089. return full;
  6090. })
  6091. .replace(/(<[^>]+\s)data-ke-(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6092. return start + end;
  6093. });
  6094. });
  6095. self.beforeSetHtml(function(html) {
  6096. if (_IE && _V <= 8) {
  6097. html = html.replace(/<input[^>]*>|<(select|button)[^>]*>[\s\S]*?<\/\1>/ig, function(full) {
  6098. var attrs = _getAttrList(full);
  6099. var styles = _getCssList(attrs.style || '');
  6100. if (styles.display == 'none') {
  6101. return '<div class="ke-display-none" data-ke-input-tag="' + escape(full) + '"></div>';
  6102. }
  6103. return full;
  6104. });
  6105. }
  6106. return html.replace(/<embed[^>]*type="([^"]+)"[^>]*>(?:<\/embed>)?/ig, function(full) {
  6107. var attrs = _getAttrList(full);
  6108. attrs.src = _undef(attrs.src, '');
  6109. attrs.width = _undef(attrs.width, 0);
  6110. attrs.height = _undef(attrs.height, 0);
  6111. return _mediaImg(self.themesPath + 'common/blank.gif', attrs);
  6112. })
  6113. .replace(/<a[^>]*name="([^"]+)"[^>]*>(?:<\/a>)?/ig, function(full) {
  6114. var attrs = _getAttrList(full);
  6115. if (attrs.href !== undefined) {
  6116. return full;
  6117. }
  6118. return '<img class="ke-anchor" src="' + self.themesPath + 'common/anchor.gif" data-ke-name="' + escape(attrs.name) + '" />';
  6119. })
  6120. .replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
  6121. return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6122. })
  6123. .replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
  6124. return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
  6125. })
  6126. .replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
  6127. if (full.match(/\sdata-ke-src="[^"]*"/i)) {
  6128. return full;
  6129. }
  6130. full = start + key + '="' + src + '"' + ' data-ke-src="' + _escape(src) + '"' + end;
  6131. return full;
  6132. })
  6133. .replace(/(<[^>]+\s)(on\w+="[^"]*"[^>]*>)/ig, function(full, start, end) {
  6134. return start + 'data-ke-' + end;
  6135. })
  6136. .replace(/<table[^>]*\s+border="0"[^>]*>/ig, function(full) {
  6137. if (full.indexOf('ke-zeroborder') >= 0) {
  6138. return full;
  6139. }
  6140. return _addClassToTag(full, 'ke-zeroborder');
  6141. });
  6142. });
  6143. });
  6144. })(window);
  6145. /*******************************************************************************
  6146. * KindEditor - WYSIWYG HTML Editor for Internet
  6147. * Copyright (C) 2006-2011 kindsoft.net
  6148. *
  6149. * @author Roddy <luolonghao@gmail.com>
  6150. * @site http://www.kindsoft.net/
  6151. * @licence http://www.kindsoft.net/license.php
  6152. *******************************************************************************/
  6153. KindEditor.lang({
  6154. source : 'HTML代码',
  6155. preview : '预览',
  6156. undo : '后退(Ctrl+Z)',
  6157. redo : '前进(Ctrl+Y)',
  6158. cut : '剪切(Ctrl+X)',
  6159. copy : '复制(Ctrl+C)',
  6160. paste : '粘贴(Ctrl+V)',
  6161. plainpaste : '粘贴为无格式文本',
  6162. wordpaste : '从Word粘贴',
  6163. selectall : '全选(Ctrl+A)',
  6164. justifyleft : '左对齐',
  6165. justifycenter : '居中',
  6166. justifyright : '右对齐',
  6167. justifyfull : '两端对齐',
  6168. insertorderedlist : '编号',
  6169. insertunorderedlist : '项目符号',
  6170. indent : '增加缩进',
  6171. outdent : '减少缩进',
  6172. subscript : '下标',
  6173. superscript : '上标',
  6174. formatblock : '段落',
  6175. fontname : '字体',
  6176. fontsize : '文字大小',
  6177. fontheight : '文字间距',
  6178. forecolor : '文字颜色',
  6179. hilitecolor : '文字背景',
  6180. bold : '粗体(Ctrl+B)',
  6181. italic : '斜体(Ctrl+I)',
  6182. underline : '下划线(Ctrl+U)',
  6183. strikethrough : '删除线',
  6184. removeformat : '删除格式',
  6185. image : '图片',
  6186. multiimage : '批量图片上传',
  6187. flash : 'Flash',
  6188. media : '音频',
  6189. table : '表格',
  6190. tablecell : '单元格',
  6191. hr : '插入横线',
  6192. emoticons : '插入表情',
  6193. link : '超级链接',
  6194. unlink : '取消超级链接',
  6195. fullscreen : '全屏显示',
  6196. about : '关于',
  6197. print : '打印(Ctrl+P)',
  6198. filemanager : '文件库',
  6199. code : '插入程序代码',
  6200. map : 'Google地图',
  6201. baidumap : '百度地图',
  6202. lineheight : '行距',
  6203. clearhtml : '清理HTML代码',
  6204. pagebreak : '插入分页符',
  6205. quickformat : '一键排版',
  6206. insertfile : '插入文件',
  6207. template : '插入模板',
  6208. anchor : '锚点',
  6209. yes : '确定',
  6210. no : '取消',
  6211. close : '关闭',
  6212. editImage : '图片属性',
  6213. deleteImage : '删除图片',
  6214. editFlash : 'Flash属性',
  6215. deleteFlash : '删除Flash',
  6216. editMedia : '音频属性',
  6217. deleteMedia : '删除音频',
  6218. editLink : '超级链接属性',
  6219. deleteLink : '取消超级链接',
  6220. editAnchor : '锚点属性',
  6221. deleteAnchor : '删除锚点',
  6222. tableprop : '表格属性',
  6223. tablecellprop : '单元格属性',
  6224. tableinsert : '插入表格',
  6225. tabledelete : '删除表格',
  6226. tablecolinsertleft : '左侧插入列',
  6227. tablecolinsertright : '右侧插入列',
  6228. tablerowinsertabove : '上方插入行',
  6229. tablerowinsertbelow : '下方插入行',
  6230. tablerowmerge : '向下合并单元格',
  6231. tablecolmerge : '向右合并单元格',
  6232. tablerowsplit : '拆分行',
  6233. tablecolsplit : '拆分列',
  6234. tablecoldelete : '删除列',
  6235. tablerowdelete : '删除行',
  6236. noColor : '无颜色',
  6237. pleaseSelectFile : '请选择文件。',
  6238. invalidImg : "请输入有效的URL地址。\n只允许jpg,gif,bmp,png格式。",
  6239. invalidMedia : "请输入有效的URL地址。\n只允许swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb格式。",
  6240. invalidWidth : "宽度必须为数字。",
  6241. invalidHeight : "高度必须为数字。",
  6242. invalidBorder : "边框必须为数字。",
  6243. invalidUrl : "请输入有效的URL地址。",
  6244. invalidRows : '行数为必选项,只允许输入大于0的数字。',
  6245. invalidCols : '列数为必选项,只允许输入大于0的数字。',
  6246. invalidPadding : '边距必须为数字。',
  6247. invalidSpacing : '间距必须为数字。',
  6248. invalidJson : '服务器发生故障。',
  6249. uploadSuccess : '上传成功。',
  6250. cutError : '您的浏览器安全设置不允许使用剪切操作,请使用快捷键(Ctrl+X)来完成。',
  6251. copyError : '您的浏览器安全设置不允许使用复制操作,请使用快捷键(Ctrl+C)来完成。',
  6252. pasteError : '您的浏览器安全设置不允许使用粘贴操作,请使用快捷键(Ctrl+V)来完成。',
  6253. ajaxLoading : '加载中,请稍候 ...',
  6254. uploadLoading : '上传中,请稍候 ...',
  6255. uploadError : '上传错误',
  6256. 'plainpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6257. 'wordpaste.comment' : '请使用快捷键(Ctrl+V)把内容粘贴到下面的方框里。',
  6258. 'code.pleaseInput' : '请输入程序代码。',
  6259. 'link.url' : 'URL',
  6260. 'link.linkType' : '打开类型',
  6261. 'link.newWindow' : '新窗口',
  6262. 'link.selfWindow' : '当前窗口',
  6263. 'flash.url' : 'URL',
  6264. 'flash.width' : '宽度',
  6265. 'flash.height' : '高度',
  6266. 'flash.upload' : '上传',
  6267. 'flash.viewServer' : '文件空间',
  6268. 'media.url' : 'URL',
  6269. 'media.width' : '宽度',
  6270. 'media.height' : '高度',
  6271. 'media.autostart' : '自动播放',
  6272. 'media.upload' : '上传',
  6273. 'media.viewServer' : '文件空间',
  6274. 'image.remoteImage' : '网络图片',
  6275. 'image.localImage' : '本地上传',
  6276. 'image.remoteUrl' : '图片地址',
  6277. 'image.localUrl' : '上传文件',
  6278. 'image.size' : '图片大小',
  6279. 'image.width' : '宽',
  6280. 'image.height' : '高',
  6281. 'image.resetSize' : '重置大小',
  6282. 'image.align' : '对齐方式',
  6283. 'image.defaultAlign' : '默认方式',
  6284. 'image.leftAlign' : '左对齐',
  6285. 'image.rightAlign' : '右对齐',
  6286. 'image.imgTitle' : '图片说明',
  6287. 'image.upload' : '浏览...',
  6288. 'image.viewServer' : '图片空间',
  6289. //'multiimage.uploadDesc' : '允许用户同时上传<%=uploadLimit%>张图片,单张图片容量不超过<%=sizeLimit%>',
  6290. 'multiimage.uploadDesc' : '',
  6291. 'multiimage.startUpload' : '开始上传',
  6292. 'multiimage.clearAll' : '全部清空',
  6293. 'multiimage.insertAll' : '全部插入',
  6294. 'multiimage.queueLimitExceeded' : '文件数量超过限制。',
  6295. 'multiimage.fileExceedsSizeLimit' : '文件大小超过限制。',
  6296. 'multiimage.zeroByteFile' : '无法上传空文件。',
  6297. 'multiimage.invalidFiletype' : '文件类型不正确。',
  6298. 'multiimage.unknownError' : '发生异常,无法上传。',
  6299. 'multiimage.pending' : '等待上传',
  6300. 'multiimage.uploadError' : '上传失败',
  6301. 'filemanager.emptyFolder' : '空文件夹',
  6302. 'filemanager.moveup' : '移到上一级文件夹',
  6303. 'filemanager.viewType' : '显示方式:',
  6304. 'filemanager.viewImage' : '缩略图',
  6305. 'filemanager.listImage' : '详细信息',
  6306. 'filemanager.orderType' : '排序方式:',
  6307. 'filemanager.fileName' : '名称',
  6308. 'filemanager.fileSize' : '大小',
  6309. 'filemanager.fileType' : '类型',
  6310. 'insertfile.url' : 'URL',
  6311. 'insertfile.title' : '文件说明',
  6312. 'insertfile.upload' : '上传',
  6313. 'insertfile.viewServer' : '文件空间',
  6314. 'table.cells' : '单元格数',
  6315. 'table.rows' : '行数',
  6316. 'table.cols' : '列数',
  6317. 'table.size' : '大小',
  6318. 'table.width' : '宽度',
  6319. 'table.height' : '高度',
  6320. 'table.percent' : '%',
  6321. 'table.px' : 'px',
  6322. 'table.space' : '边距间距',
  6323. 'table.padding' : '边距',
  6324. 'table.spacing' : '间距',
  6325. 'table.align' : '对齐方式',
  6326. 'table.textAlign' : '水平对齐',
  6327. 'table.verticalAlign' : '垂直对齐',
  6328. 'table.alignDefault' : '默认',
  6329. 'table.alignLeft' : '左对齐',
  6330. 'table.alignCenter' : '居中',
  6331. 'table.alignRight' : '右对齐',
  6332. 'table.alignTop' : '顶部',
  6333. 'table.alignMiddle' : '中部',
  6334. 'table.alignBottom' : '底部',
  6335. 'table.alignBaseline' : '基线',
  6336. 'table.border' : '边框',
  6337. 'table.borderWidth' : '边框',
  6338. 'table.borderColor' : '颜色',
  6339. 'table.backgroundColor' : '背景颜色',
  6340. 'map.address' : '地址: ',
  6341. 'map.search' : '搜索',
  6342. 'baidumap.address' : '地址: ',
  6343. 'baidumap.search' : '搜索',
  6344. 'baidumap.insertDynamicMap' : '插入动态地图',
  6345. 'anchor.name' : '锚点名称',
  6346. 'formatblock.formatBlock' : {
  6347. h1 : '标题 1',
  6348. h2 : '标题 2',
  6349. h3 : '标题 3',
  6350. h4 : '标题 4',
  6351. p : '正 文'
  6352. },
  6353. 'fontname.fontName' : {
  6354. 'SimSun' : '宋体',
  6355. 'NSimSun' : '新宋体',
  6356. 'FangSong_GB2312' : '仿宋_GB2312',
  6357. 'KaiTi_GB2312' : '楷体_GB2312',
  6358. 'SimHei' : '黑体',
  6359. 'Microsoft YaHei' : '微软雅黑',
  6360. 'Arial' : 'Arial',
  6361. 'Arial Black' : 'Arial Black',
  6362. 'Times New Roman' : 'Times New Roman',
  6363. 'Courier New' : 'Courier New',
  6364. 'Tahoma' : 'Tahoma',
  6365. 'Verdana' : 'Verdana'
  6366. },
  6367. 'lineheight.lineHeight' : [
  6368. {'1' : '单倍行距'},
  6369. {'1.5' : '1.5倍行距'},
  6370. {'1.75' : '1.75倍行距'},
  6371. {'2' : '2倍行距'},
  6372. {'2.5' : '2.5倍行距'},
  6373. {'3' : '3倍行距'}
  6374. ],
  6375. 'template.selectTemplate' : '可选模板',
  6376. 'template.replaceContent' : '替换当前内容',
  6377. 'template.fileList' : {
  6378. '1.html' : '图片和文字',
  6379. '2.html' : '表格',
  6380. '3.html' : '项目编号'
  6381. }
  6382. }, 'zh-CN');
  6383. KindEditor.options.langType = 'zh-CN';
  6384. /*******************************************************************************
  6385. * KindEditor - WYSIWYG HTML Editor for Internet
  6386. * Copyright (C) 2006-2011 kindsoft.net
  6387. *
  6388. * @author Roddy <luolonghao@gmail.com>
  6389. * @site http://www.kindsoft.net/
  6390. * @licence http://www.kindsoft.net/license.php
  6391. *******************************************************************************/
  6392. KindEditor.plugin('anchor', function(K) {
  6393. var self = this, name = 'anchor', lang = self.lang(name + '.');
  6394. self.plugin.anchor = {
  6395. edit : function() {
  6396. var html = ['<div style="padding:20px;">',
  6397. '<div class="ke-dialog-row">',
  6398. '<label for="keName">' + lang.name + '</label>',
  6399. '<input class="ke-input-text" type="text" id="keName" name="name" value="" style="width:100px;" />',
  6400. '</div>',
  6401. '</div>'].join('');
  6402. var dialog = self.createDialog({
  6403. name : name,
  6404. width : 300,
  6405. title : self.lang(name),
  6406. body : html,
  6407. yesBtn : {
  6408. name : self.lang('yes'),
  6409. click : function(e) {
  6410. self.insertHtml('<a name="' + nameBox.val() + '">').hideDialog().focus();
  6411. }
  6412. }
  6413. });
  6414. var div = dialog.div,
  6415. nameBox = K('input[name="name"]', div);
  6416. var img = self.plugin.getSelectedAnchor();
  6417. if (img) {
  6418. nameBox.val(unescape(img.attr('data-ke-name')));
  6419. }
  6420. nameBox[0].focus();
  6421. nameBox[0].select();
  6422. },
  6423. 'delete' : function() {
  6424. self.plugin.getSelectedAnchor().remove();
  6425. }
  6426. };
  6427. self.clickToolbar(name, self.plugin.anchor.edit);
  6428. });
  6429. /*******************************************************************************
  6430. * KindEditor - WYSIWYG HTML Editor for Internet
  6431. * Copyright (C) 2006-2011 kindsoft.net
  6432. *
  6433. * @author Roddy <luolonghao@gmail.com>
  6434. * @site http://www.kindsoft.net/
  6435. * @licence http://www.kindsoft.net/license.php
  6436. *******************************************************************************/
  6437. KindEditor.plugin('autoheight', function(K) {
  6438. var self = this;
  6439. if (!self.autoHeightMode) {
  6440. return;
  6441. }
  6442. var minHeight;
  6443. function hideScroll() {
  6444. var edit = self.edit;
  6445. var body = edit.doc.body;
  6446. edit.iframe[0].scroll = 'no';
  6447. body.style.overflowY = 'hidden';
  6448. }
  6449. function resetHeight() {
  6450. if(self.fullscreenMode){
  6451. return;
  6452. }
  6453. var edit = self.edit;
  6454. var body = edit.doc.body;
  6455. edit.iframe.height(minHeight);
  6456. self.resize(null, Math.max((K.IE ? body.scrollHeight : body.offsetHeight) + 76, minHeight));
  6457. }
  6458. function init() {
  6459. minHeight = K.removeUnit(self.height);
  6460. self.edit.afterChange(resetHeight);
  6461. if(!self.fullscreenMode){
  6462. hideScroll();
  6463. }
  6464. resetHeight();
  6465. }
  6466. if (self.isCreated) {
  6467. init();
  6468. } else {
  6469. self.afterCreate(init);
  6470. }
  6471. });
  6472. /*
  6473. * 如何实现真正的自动高度?
  6474. * 修改编辑器高度之后,再次获取body内容高度时,最小值只会是当前iframe的设置高度,这样就导致高度只增不减。
  6475. * 所以每次获取body内容高度之前,先将iframe的高度重置为最小高度,这样就能获取body的实际高度。
  6476. * 由此就实现了真正的自动高度
  6477. * 测试:chrome、firefox、IE9、IE8
  6478. * */
  6479. /*******************************************************************************
  6480. * KindEditor - WYSIWYG HTML Editor for Internet
  6481. * Copyright (C) 2006-2011 kindsoft.net
  6482. *
  6483. * @author Roddy <luolonghao@gmail.com>
  6484. * @site http://www.kindsoft.net/
  6485. * @licence http://www.kindsoft.net/license.php
  6486. *******************************************************************************/
  6487. KindEditor.plugin('baidumap', function(K) {
  6488. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  6489. var mapWidth = K.undef(self.mapWidth, 558);
  6490. var mapHeight = K.undef(self.mapHeight, 360);
  6491. self.clickToolbar(name, function() {
  6492. var html = ['<div style="padding:10px 20px;">',
  6493. '<div class="ke-header">',
  6494. '<div class="ke-left">',
  6495. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6496. '<span class="ke-button-common ke-button-outer">',
  6497. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6498. '</span>',
  6499. '</div>',
  6500. '<div class="ke-right">',
  6501. '<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
  6502. '</div>',
  6503. '<div class="ke-clearfix"></div>',
  6504. '</div>',
  6505. '<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
  6506. '</div>'].join('');
  6507. var dialog = self.createDialog({
  6508. name : name,
  6509. width : mapWidth + 42,
  6510. title : self.lang(name),
  6511. body : html,
  6512. yesBtn : {
  6513. name : self.lang('yes'),
  6514. click : function(e) {
  6515. var map = win.map;
  6516. var centerObj = map.getCenter();
  6517. var center = centerObj.lng + ',' + centerObj.lat;
  6518. var zoom = map.getZoom();
  6519. var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
  6520. '?center=' + encodeURIComponent(center),
  6521. '&zoom=' + encodeURIComponent(zoom),
  6522. '&width=' + mapWidth,
  6523. '&height=' + mapHeight,
  6524. '&markers=' + encodeURIComponent(center),
  6525. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  6526. if (checkbox[0].checked) {
  6527. self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
  6528. } else {
  6529. self.exec('insertimage', url);
  6530. }
  6531. self.hideDialog().focus();
  6532. }
  6533. },
  6534. beforeRemove : function() {
  6535. searchBtn.remove();
  6536. if (doc) {
  6537. doc.write('');
  6538. }
  6539. iframe.remove();
  6540. }
  6541. });
  6542. var div = dialog.div,
  6543. addressBox = K('[name="address"]', div),
  6544. searchBtn = K('[name="searchBtn"]', div),
  6545. checkbox = K('[name="insertDynamicMap"]', dialog.div),
  6546. win, doc;
  6547. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
  6548. function ready() {
  6549. win = iframe[0].contentWindow;
  6550. doc = K.iframeDoc(iframe);
  6551. }
  6552. iframe.bind('load', function() {
  6553. iframe.unbind('load');
  6554. if (K.IE) {
  6555. ready();
  6556. } else {
  6557. setTimeout(ready, 0);
  6558. }
  6559. });
  6560. K('.ke-map', div).replaceWith(iframe);
  6561. searchBtn.click(function() {
  6562. win.search(addressBox.val());
  6563. });
  6564. });
  6565. });
  6566. /*******************************************************************************
  6567. * KindEditor - WYSIWYG HTML Editor for Internet
  6568. * Copyright (C) 2006-2011 kindsoft.net
  6569. *
  6570. * @author Roddy <luolonghao@gmail.com>
  6571. * @site http://www.kindsoft.net/
  6572. * @licence http://www.kindsoft.net/license.php
  6573. *******************************************************************************/
  6574. KindEditor.plugin('map', function(K) {
  6575. var self = this, name = 'map', lang = self.lang(name + '.');
  6576. self.clickToolbar(name, function() {
  6577. var html = ['<div style="padding:10px 20px;">',
  6578. '<div class="ke-dialog-row">',
  6579. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  6580. '<span class="ke-button-common ke-button-outer">',
  6581. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  6582. '</span>',
  6583. '</div>',
  6584. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  6585. '</div>'].join('');
  6586. var dialog = self.createDialog({
  6587. name : name,
  6588. width : 600,
  6589. title : self.lang(name),
  6590. body : html,
  6591. yesBtn : {
  6592. name : self.lang('yes'),
  6593. click : function(e) {
  6594. var geocoder = win.geocoder,
  6595. map = win.map,
  6596. center = map.getCenter().lat() + ',' + map.getCenter().lng(),
  6597. zoom = map.getZoom(),
  6598. maptype = map.getMapTypeId(),
  6599. url = 'http://maps.googleapis.com/maps/api/staticmap';
  6600. url += '?center=' + encodeURIComponent(center);
  6601. url += '&zoom=' + encodeURIComponent(zoom);
  6602. url += '&size=558x360';
  6603. url += '&maptype=' + encodeURIComponent(maptype);
  6604. url += '&markers=' + encodeURIComponent(center);
  6605. url += '&language=' + self.langType;
  6606. url += '&sensor=false';
  6607. self.exec('insertimage', url).hideDialog().focus();
  6608. }
  6609. },
  6610. beforeRemove : function() {
  6611. searchBtn.remove();
  6612. if (doc) {
  6613. doc.write('');
  6614. }
  6615. iframe.remove();
  6616. }
  6617. });
  6618. var div = dialog.div,
  6619. addressBox = K('[name="address"]', div),
  6620. searchBtn = K('[name="searchBtn"]', div),
  6621. win, doc;
  6622. var iframeHtml = ['<!doctype html><html><head>',
  6623. '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />',
  6624. '<style>',
  6625. ' html { height: 100% }',
  6626. ' body { height: 100%; margin: 0; padding: 0; background-color: #FFF }',
  6627. ' #map_canvas { height: 100% }',
  6628. '</style>',
  6629. '<script src="http://maps.googleapis.com/maps/api/js?sensor=false&language=' + self.langType + '"></script>',
  6630. '<script>',
  6631. 'var map, geocoder;',
  6632. 'function initialize() {',
  6633. ' var latlng = new google.maps.LatLng(31.230393, 121.473704);',
  6634. ' var options = {',
  6635. ' zoom: 11,',
  6636. ' center: latlng,',
  6637. ' disableDefaultUI: true,',
  6638. ' panControl: true,',
  6639. ' zoomControl: true,',
  6640. ' mapTypeControl: true,',
  6641. ' scaleControl: true,',
  6642. ' streetViewControl: false,',
  6643. ' overviewMapControl: true,',
  6644. ' mapTypeId: google.maps.MapTypeId.ROADMAP',
  6645. ' };',
  6646. ' map = new google.maps.Map(document.getElementById("map_canvas"), options);',
  6647. ' geocoder = new google.maps.Geocoder();',
  6648. ' geocoder.geocode({latLng: latlng}, function(results, status) {',
  6649. ' if (status == google.maps.GeocoderStatus.OK) {',
  6650. ' if (results[3]) {',
  6651. ' parent.document.getElementById("kindeditor_plugin_map_address").value = results[3].formatted_address;',
  6652. ' }',
  6653. ' }',
  6654. ' });',
  6655. '}',
  6656. 'function search(address) {',
  6657. ' if (!map) return;',
  6658. ' geocoder.geocode({address : address}, function(results, status) {',
  6659. ' if (status == google.maps.GeocoderStatus.OK) {',
  6660. ' map.setZoom(11);',
  6661. ' map.setCenter(results[0].geometry.location);',
  6662. ' var marker = new google.maps.Marker({',
  6663. ' map: map,',
  6664. ' position: results[0].geometry.location',
  6665. ' });',
  6666. ' } else {',
  6667. ' alert("Invalid address: " + address);',
  6668. ' }',
  6669. ' });',
  6670. '}',
  6671. '</script>',
  6672. '</head>',
  6673. '<body onload="initialize();">',
  6674. '<div id="map_canvas" style="width:100%; height:100%"></div>',
  6675. '</body></html>'].join('\n');
  6676. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'map/map.html" style="width:558px;height:360px;"></iframe>');
  6677. function ready() {
  6678. win = iframe[0].contentWindow;
  6679. doc = K.iframeDoc(iframe);
  6680. }
  6681. iframe.bind('load', function() {
  6682. iframe.unbind('load');
  6683. if (K.IE) {
  6684. ready();
  6685. } else {
  6686. setTimeout(ready, 0);
  6687. }
  6688. });
  6689. K('.ke-map', div).replaceWith(iframe);
  6690. searchBtn.click(function() {
  6691. win.search(addressBox.val());
  6692. });
  6693. });
  6694. });
  6695. /*******************************************************************************
  6696. * KindEditor - WYSIWYG HTML Editor for Internet
  6697. * Copyright (C) 2006-2011 kindsoft.net
  6698. *
  6699. * @author Roddy <luolonghao@gmail.com>
  6700. * @site http://www.kindsoft.net/
  6701. * @licence http://www.kindsoft.net/license.php
  6702. *******************************************************************************/
  6703. KindEditor.plugin('clearhtml', function(K) {
  6704. var self = this, name = 'clearhtml';
  6705. self.clickToolbar(name, function() {
  6706. self.focus();
  6707. var html = self.html();
  6708. html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, '');
  6709. html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, '');
  6710. html = K.formatHtml(html, {
  6711. a : ['href', 'target'],
  6712. embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'],
  6713. img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'],
  6714. table : ['border'],
  6715. 'td,th' : ['rowspan', 'colspan'],
  6716. 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : []
  6717. });
  6718. self.html(html);
  6719. self.cmd.selection(true);
  6720. self.addBookmark();
  6721. });
  6722. });
  6723. /*******************************************************************************
  6724. * KindEditor - WYSIWYG HTML Editor for Internet
  6725. * Copyright (C) 2006-2011 kindsoft.net
  6726. *
  6727. * @author Roddy <luolonghao@gmail.com>
  6728. * @site http://www.kindsoft.net/
  6729. * @licence http://www.kindsoft.net/license.php
  6730. *******************************************************************************/
  6731. KindEditor.plugin('code', function(K) {
  6732. var self = this, name = 'code';
  6733. self.clickToolbar(name, function() {
  6734. var lang = self.lang(name + '.'),
  6735. html = ['<div style="padding:10px 20px;">',
  6736. '<div class="ke-dialog-row">',
  6737. '<select class="ke-code-type">',
  6738. '<option value="js">JavaScript</option>',
  6739. '<option value="html">HTML</option>',
  6740. '<option value="css">CSS</option>',
  6741. '<option value="php">PHP</option>',
  6742. '<option value="pl">Perl</option>',
  6743. '<option value="py">Python</option>',
  6744. '<option value="rb">Ruby</option>',
  6745. '<option value="java">Java</option>',
  6746. '<option value="vb">ASP/VB</option>',
  6747. '<option value="cpp">C/C++</option>',
  6748. '<option value="cs">C#</option>',
  6749. '<option value="xml">XML</option>',
  6750. '<option value="bsh">Shell</option>',
  6751. '<option value="">Other</option>',
  6752. '</select>',
  6753. '</div>',
  6754. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>',
  6755. '</div>'].join(''),
  6756. dialog = self.createDialog({
  6757. name : name,
  6758. width : 450,
  6759. title : self.lang(name),
  6760. body : html,
  6761. yesBtn : {
  6762. name : self.lang('yes'),
  6763. click : function(e) {
  6764. var type = K('.ke-code-type', dialog.div).val(),
  6765. code = textarea.val(),
  6766. cls = type === '' ? '' : ' lang-' + type,
  6767. html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
  6768. if (K.trim(code) === '') {
  6769. alert(lang.pleaseInput);
  6770. textarea[0].focus();
  6771. return;
  6772. }
  6773. self.insertHtml(html).hideDialog().focus();
  6774. }
  6775. }
  6776. }),
  6777. textarea = K('textarea', dialog.div);
  6778. textarea[0].focus();
  6779. });
  6780. });
  6781. /*******************************************************************************
  6782. * KindEditor - WYSIWYG HTML Editor for Internet
  6783. * Copyright (C) 2006-2011 kindsoft.net
  6784. *
  6785. * @author Roddy <luolonghao@gmail.com>
  6786. * @site http://www.kindsoft.net/
  6787. * @licence http://www.kindsoft.net/license.php
  6788. *******************************************************************************/
  6789. KindEditor.plugin('emoticons', function(K) {
  6790. var self = this, name = 'emoticons',
  6791. path = (self.emoticonsPath || self.pluginsPath + 'emoticons/images/'),
  6792. allowPreview = self.allowPreviewEmoticons === undefined ? true : self.allowPreviewEmoticons,
  6793. currentPageNum = 1;
  6794. self.clickToolbar(name, function() {
  6795. var rows = 5, cols = 9, total = 135, startNum = 0,
  6796. cells = rows * cols, pages = Math.ceil(total / cells),
  6797. colsHalf = Math.floor(cols / 2),
  6798. wrapperDiv = K('<div class="ke-plugin-emoticons"></div>'),
  6799. elements = [],
  6800. menu = self.createMenu({
  6801. name : name,
  6802. beforeRemove : function() {
  6803. removeEvent();
  6804. }
  6805. });
  6806. menu.div.append(wrapperDiv);
  6807. var previewDiv, previewImg;
  6808. if (allowPreview) {
  6809. previewDiv = K('<div class="ke-preview"></div>').css('right', 0);
  6810. previewImg = K('<img class="ke-preview-img" src="' + path + startNum + '.gif" />');
  6811. wrapperDiv.append(previewDiv);
  6812. previewDiv.append(previewImg);
  6813. }
  6814. function bindCellEvent(cell, j, num) {
  6815. if (previewDiv) {
  6816. cell.mouseover(function() {
  6817. if (j > colsHalf) {
  6818. previewDiv.css('left', 0);
  6819. previewDiv.css('right', '');
  6820. } else {
  6821. previewDiv.css('left', '');
  6822. previewDiv.css('right', 0);
  6823. }
  6824. previewImg.attr('src', path + num + '.gif');
  6825. K(this).addClass('ke-on');
  6826. });
  6827. } else {
  6828. cell.mouseover(function() {
  6829. K(this).addClass('ke-on');
  6830. });
  6831. }
  6832. cell.mouseout(function() {
  6833. K(this).removeClass('ke-on');
  6834. });
  6835. cell.click(function(e) {
  6836. self.insertHtml('<img src="' + path + num + '.gif" border="0" alt="" />').hideMenu().focus();
  6837. e.stop();
  6838. });
  6839. }
  6840. function createEmoticonsTable(pageNum, parentDiv) {
  6841. var table = document.createElement('table');
  6842. parentDiv.append(table);
  6843. if (previewDiv) {
  6844. K(table).mouseover(function() {
  6845. previewDiv.show('block');
  6846. });
  6847. K(table).mouseout(function() {
  6848. previewDiv.hide();
  6849. });
  6850. elements.push(K(table));
  6851. }
  6852. table.className = 'ke-table';
  6853. table.cellPadding = 0;
  6854. table.cellSpacing = 0;
  6855. table.border = 0;
  6856. var num = (pageNum - 1) * cells + startNum;
  6857. for (var i = 0; i < rows; i++) {
  6858. var row = table.insertRow(i);
  6859. for (var j = 0; j < cols; j++) {
  6860. var cell = K(row.insertCell(j));
  6861. cell.addClass('ke-cell');
  6862. bindCellEvent(cell, j, num);
  6863. var span = K('<span class="ke-img"></span>')
  6864. .css('background-position', '-' + (24 * num) + 'px 0px')
  6865. .css('background-image', 'url(' + path + 'static.gif)');
  6866. cell.append(span);
  6867. elements.push(cell);
  6868. num++;
  6869. }
  6870. }
  6871. return table;
  6872. }
  6873. var table = createEmoticonsTable(currentPageNum, wrapperDiv);
  6874. function removeEvent() {
  6875. K.each(elements, function() {
  6876. this.unbind();
  6877. });
  6878. }
  6879. var pageDiv;
  6880. function bindPageEvent(el, pageNum) {
  6881. el.click(function(e) {
  6882. removeEvent();
  6883. table.parentNode.removeChild(table);
  6884. pageDiv.remove();
  6885. table = createEmoticonsTable(pageNum, wrapperDiv);
  6886. createPageTable(pageNum);
  6887. currentPageNum = pageNum;
  6888. e.stop();
  6889. });
  6890. }
  6891. function createPageTable(currentPageNum) {
  6892. pageDiv = K('<div class="ke-page"></div>');
  6893. wrapperDiv.append(pageDiv);
  6894. for (var pageNum = 1; pageNum <= pages; pageNum++) {
  6895. if (currentPageNum !== pageNum) {
  6896. var a = K('<a href="javascript:;">[' + pageNum + ']</a>');
  6897. bindPageEvent(a, pageNum);
  6898. pageDiv.append(a);
  6899. elements.push(a);
  6900. } else {
  6901. pageDiv.append(K('@[' + pageNum + ']'));
  6902. }
  6903. pageDiv.append(K('@&nbsp;'));
  6904. }
  6905. }
  6906. createPageTable(currentPageNum);
  6907. });
  6908. });
  6909. /*******************************************************************************
  6910. * KindEditor - WYSIWYG HTML Editor for Internet
  6911. * Copyright (C) 2006-2011 kindsoft.net
  6912. *
  6913. * @author Roddy <luolonghao@gmail.com>
  6914. * @site http://www.kindsoft.net/
  6915. * @licence http://www.kindsoft.net/license.php
  6916. *******************************************************************************/
  6917. KindEditor.plugin('filemanager', function(K) {
  6918. var self = this, name = 'filemanager',
  6919. fileManagerJson = K.undef(self.fileManagerJson, self.basePath + 'php/file_manager_json.php'),
  6920. imgPath = self.pluginsPath + name + '/images/',
  6921. lang = self.lang(name + '.');
  6922. function makeFileTitle(filename, filesize, datetime) {
  6923. return filename + ' (' + Math.ceil(filesize / 1024) + 'KB, ' + datetime + ')';
  6924. }
  6925. function bindTitle(el, data) {
  6926. if (data.is_dir) {
  6927. el.attr('title', data.filename);
  6928. } else {
  6929. el.attr('title', makeFileTitle(data.filename, data.filesize, data.datetime));
  6930. }
  6931. }
  6932. self.plugin.filemanagerDialog = function(options) {
  6933. var width = K.undef(options.width, 650),
  6934. height = K.undef(options.height, 510),
  6935. dirName = K.undef(options.dirName, ''),
  6936. viewType = K.undef(options.viewType, 'VIEW').toUpperCase(),
  6937. clickFn = options.clickFn;
  6938. var html = [
  6939. '<div style="padding:10px 20px;">',
  6940. '<div class="ke-plugin-filemanager-header">',
  6941. '<div class="ke-left">',
  6942. '<img class="ke-inline-block" name="moveupImg" src="' + imgPath + 'go-up.gif" width="16" height="16" border="0" alt="" /> ',
  6943. '<a class="ke-inline-block" name="moveupLink" href="javascript:;">' + lang.moveup + '</a>',
  6944. '</div>',
  6945. '<div class="ke-right">',
  6946. '标签 <input type="text" style="width:100px;" value="" name="viewTag">',
  6947. '分类 <select class="ke-inline-block" name="viewCate">',
  6948. '',
  6949. '</select> ',
  6950. lang.viewType + ' <select class="ke-inline-block" name="viewType">',
  6951. '<option value="VIEW">' + lang.viewImage + '</option>',
  6952. '<option value="LIST">' + lang.listImage + '</option>',
  6953. '</select> ',
  6954. lang.orderType + ' <select class="ke-inline-block" name="orderType">',
  6955. '<option value="NAME">' + lang.fileName + '</option>',
  6956. '<option value="SIZE">' + lang.fileSize + '</option>',
  6957. '<option value="TYPE">' + lang.fileType + '</option>',
  6958. '</select>',
  6959. '</div>',
  6960. '<div class="ke-clearfix"></div>',
  6961. '</div>',
  6962. '<div class="ke-plugin-filemanager-body"></div>',
  6963. '</div>'
  6964. ].join('');
  6965. var dialog = self.createDialog({
  6966. name : name,
  6967. width : width,
  6968. height : height,
  6969. title : self.lang(name),
  6970. body : html
  6971. }),
  6972. div = dialog.div,
  6973. bodyDiv = K('.ke-plugin-filemanager-body', div),
  6974. moveupImg = K('[name="moveupImg"]', div),
  6975. moveupLink = K('[name="moveupLink"]', div),
  6976. viewServerBtn = K('[name="viewServer"]', div),
  6977. viewCateBox = K('[name="viewCate"]', div),
  6978. viewTagBox = K('[name="viewTag"]', div),
  6979. viewTypeBox = K('[name="viewType"]', div),
  6980. orderTypeBox = K('[name="orderType"]', div);
  6981. function reloadPage(path, order, func, cate, tag) {
  6982. var param = 'path=' + path + '&order=' + order + '&dir=' + dirName;
  6983. if (cate) {
  6984. param += '&cate=' + cate;
  6985. }
  6986. if (tag) {
  6987. param += '&tag=' + tag;
  6988. }
  6989. dialog.showLoading(self.lang('ajaxLoading'));
  6990. K.ajax(K.addParam(fileManagerJson, param + '&' + new Date().getTime()), function(data) {
  6991. dialog.hideLoading();
  6992. func(data);
  6993. });
  6994. }
  6995. var elList = [];
  6996. function bindEvent(el, result, data, createFunc) {
  6997. var fileUrl = K.formatUrl(result.current_url + data.file, 'absolute'),
  6998. dirPath = encodeURIComponent(result.current_dir_path + data.path + '/');
  6999. if (data.is_dir) {
  7000. el.click(function(e) {
  7001. reloadPage(dirPath, orderTypeBox.val(), createFunc);
  7002. });
  7003. } else if (data.is_photo) {
  7004. el.click(function(e) {
  7005. clickFn.call(this, fileUrl, data.file);
  7006. });
  7007. } else {
  7008. el.click(function(e) {
  7009. clickFn.call(this, fileUrl, data.file);
  7010. });
  7011. }
  7012. elList.push(el);
  7013. }
  7014. function createCommon(result, createFunc) {
  7015. K.each(elList, function() {
  7016. this.unbind();
  7017. });
  7018. moveupLink.unbind();
  7019. viewTypeBox.unbind();
  7020. orderTypeBox.unbind();
  7021. if (result.current_dir_path) {
  7022. moveupLink.click(function(e) {
  7023. reloadPage(result.moveup_dir_path, orderTypeBox.val(), createFunc);
  7024. });
  7025. }
  7026. function changeFunc() {
  7027. if (viewTypeBox.val() == 'VIEW') {
  7028. reloadPage(result.current_dir_path, orderTypeBox.val(), createView, viewCateBox.val(), viewTagBox.val());
  7029. } else {
  7030. reloadPage(result.current_dir_path, orderTypeBox.val(), createList, viewCateBox.val(), viewTagBox.val());
  7031. }
  7032. }
  7033. viewTypeBox.change(changeFunc);
  7034. orderTypeBox.change(changeFunc);
  7035. viewCateBox.change(changeFunc);
  7036. bodyDiv.html('');
  7037. }
  7038. function createList(result) {
  7039. createCommon(result, createList);
  7040. var table = document.createElement('table');
  7041. table.className = 'ke-table';
  7042. table.cellPadding = 0;
  7043. table.cellSpacing = 0;
  7044. table.border = 0;
  7045. bodyDiv.append(table);
  7046. var fileList = result.file_list;
  7047. for (var i = 0, len = fileList.length; i < len; i++) {
  7048. var data = fileList[i], row = K(table.insertRow(i));
  7049. row.mouseover(function(e) {
  7050. K(this).addClass('ke-on');
  7051. })
  7052. .mouseout(function(e) {
  7053. K(this).removeClass('ke-on');
  7054. });
  7055. var iconUrl = imgPath + (data.is_dir ? 'folder-16.gif' : 'file-16.gif'),
  7056. img = K('<img src="' + iconUrl + '" width="16" height="16" alt="' + data.filename + '" align="absmiddle" />'),
  7057. cell0 = K(row[0].insertCell(0)).addClass('ke-cell ke-name').append(img).append(document.createTextNode(' ' + data.filename));
  7058. if (!data.is_dir || data.has_file) {
  7059. row.css('cursor', 'pointer');
  7060. cell0.attr('title', data.filename);
  7061. bindEvent(cell0, result, data, createList);
  7062. } else {
  7063. cell0.attr('title', lang.emptyFolder);
  7064. }
  7065. K(row[0].insertCell(1)).addClass('ke-cell ke-size').html(data.is_dir ? '-' : Math.ceil(data.filesize / 1024) + 'KB');
  7066. K(row[0].insertCell(2)).addClass('ke-cell ke-datetime').html(data.datetime);
  7067. }
  7068. }
  7069. function createView(result) {
  7070. createCommon(result, createView);
  7071. var fileList = result.file_list;
  7072. for (var i = 0, len = fileList.length; i < len; i++) {
  7073. var data = fileList[i],
  7074. div = K('<div class="ke-inline-block ke-item"></div>');
  7075. bodyDiv.append(div);
  7076. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  7077. .mouseover(function(e) {
  7078. K(this).addClass('ke-on');
  7079. })
  7080. .mouseout(function(e) {
  7081. K(this).removeClass('ke-on');
  7082. });
  7083. div.append(photoDiv);
  7084. var fileUrl = result.current_url + data.file,
  7085. iconUrl = data.is_dir ? imgPath + 'folder-64.gif' : (data.is_photo ? fileUrl : imgPath + 'file-64.gif');
  7086. var img = K('<img src="' + iconUrl + '" width="80" height="80" alt="' + data.filename + '" />');
  7087. if (!data.is_dir || data.has_file) {
  7088. photoDiv.css('cursor', 'pointer');
  7089. bindTitle(photoDiv, data);
  7090. bindEvent(photoDiv, result, data, createView);
  7091. } else {
  7092. photoDiv.attr('title', lang.emptyFolder);
  7093. }
  7094. photoDiv.append(img);
  7095. div.append('<div class="ke-name" title="' + data.filename + '">' + data.filename + '</div>');
  7096. }
  7097. }
  7098. viewTypeBox.val(viewType);
  7099. reloadPage('', orderTypeBox.val(), viewType == 'VIEW' ? createView : createList);
  7100. return dialog;
  7101. }
  7102. });
  7103. /*******************************************************************************
  7104. * KindEditor - WYSIWYG HTML Editor for Internet
  7105. * Copyright (C) 2006-2011 kindsoft.net
  7106. *
  7107. * @author Roddy <luolonghao@gmail.com>
  7108. * @site http://www.kindsoft.net/
  7109. * @licence http://www.kindsoft.net/license.php
  7110. *******************************************************************************/
  7111. KindEditor.plugin('flash', function(K) {
  7112. var self = this, name = 'flash', lang = self.lang(name + '.'),
  7113. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  7114. allowFileManager = K.undef(self.allowFileManager, false),
  7115. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7116. extraParams = K.undef(self.extraFileUploadParams, {}),
  7117. filePostName = K.undef(self.filePostName, 'imgFile'),
  7118. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  7119. self.plugin.flash = {
  7120. edit : function() {
  7121. var html = [
  7122. '<div style="padding:20px;">',
  7123. '<div class="ke-dialog-row">',
  7124. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7125. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7126. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7127. '<span class="ke-button-common ke-button-outer">',
  7128. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7129. '</span>',
  7130. '</div>',
  7131. '<div class="ke-dialog-row">',
  7132. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7133. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  7134. '</div>',
  7135. '<div class="ke-dialog-row">',
  7136. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  7137. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  7138. '</div>',
  7139. '</div>'
  7140. ].join('');
  7141. var dialog = self.createDialog({
  7142. name : name,
  7143. width : 450,
  7144. title : self.lang(name),
  7145. body : html,
  7146. yesBtn : {
  7147. name : self.lang('yes'),
  7148. click : function(e) {
  7149. var url = K.trim(urlBox.val()),
  7150. width = widthBox.val(),
  7151. height = heightBox.val();
  7152. if (url == 'http://' || K.invalidUrl(url)) {
  7153. alert(self.lang('invalidUrl'));
  7154. urlBox[0].focus();
  7155. return;
  7156. }
  7157. if (!/^\d*$/.test(width)) {
  7158. alert(self.lang('invalidWidth'));
  7159. widthBox[0].focus();
  7160. return;
  7161. }
  7162. if (!/^\d*$/.test(height)) {
  7163. alert(self.lang('invalidHeight'));
  7164. heightBox[0].focus();
  7165. return;
  7166. }
  7167. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  7168. src : url,
  7169. type : K.mediaType('.swf'),
  7170. width : width,
  7171. height : height,
  7172. quality : 'high'
  7173. });
  7174. self.insertHtml(html).hideDialog().focus();
  7175. }
  7176. }
  7177. }),
  7178. div = dialog.div,
  7179. urlBox = K('[name="url"]', div),
  7180. viewServerBtn = K('[name="viewServer"]', div),
  7181. widthBox = K('[name="width"]', div),
  7182. heightBox = K('[name="height"]', div);
  7183. urlBox.val('http://');
  7184. if (allowFlashUpload) {
  7185. var uploadbutton = K.uploadbutton({
  7186. button : K('.ke-upload-button', div)[0],
  7187. fieldName : filePostName,
  7188. extraParams : extraParams,
  7189. url : K.addParam(uploadJson, 'dir=flash'),
  7190. afterUpload : function(data) {
  7191. dialog.hideLoading();
  7192. if (data.error === 0) {
  7193. var url = data.url;
  7194. if (formatUploadUrl) {
  7195. url = K.formatUrl(url, 'absolute');
  7196. }
  7197. urlBox.val(url);
  7198. if (self.afterUpload) {
  7199. self.afterUpload.call(self, url, data, name);
  7200. }
  7201. alert(self.lang('uploadSuccess'));
  7202. } else {
  7203. alert(data.message);
  7204. }
  7205. },
  7206. afterError : function(html) {
  7207. dialog.hideLoading();
  7208. self.errorDialog(html);
  7209. }
  7210. });
  7211. uploadbutton.fileBox.change(function(e) {
  7212. dialog.showLoading(self.lang('uploadLoading'));
  7213. uploadbutton.submit();
  7214. });
  7215. } else {
  7216. K('.ke-upload-button', div).hide();
  7217. }
  7218. if (allowFileManager) {
  7219. viewServerBtn.click(function(e) {
  7220. var clickFn = function(url, title, id) {
  7221. K('[name="url"]', div).val(url);
  7222. if (self.afterSelectFile) {
  7223. self.afterSelectFile.call(self, url);
  7224. }
  7225. };
  7226. var cur = K('[name="url"]', div).val();
  7227. editorShowUpload(cur, self.fileManagerJson, 'flash库', clickFn, this);
  7228. /*
  7229. self.loadPlugin('filemanager', function() {
  7230. self.plugin.filemanagerDialog({
  7231. viewType : 'LIST',
  7232. dirName : 'flash',
  7233. clickFn : function(url, title) {
  7234. if (self.dialogs.length > 1) {
  7235. K('[name="url"]', div).val(url);
  7236. if (self.afterSelectFile) {
  7237. self.afterSelectFile.call(self, url);
  7238. }
  7239. self.hideDialog();
  7240. }
  7241. }
  7242. });
  7243. });
  7244. */
  7245. });
  7246. } else {
  7247. viewServerBtn.hide();
  7248. }
  7249. var img = self.plugin.getSelectedFlash();
  7250. if (img) {
  7251. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  7252. urlBox.val(attrs.src);
  7253. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  7254. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  7255. }
  7256. urlBox[0].focus();
  7257. urlBox[0].select();
  7258. },
  7259. 'delete' : function() {
  7260. self.plugin.getSelectedFlash().remove();
  7261. self.addBookmark();
  7262. }
  7263. };
  7264. self.clickToolbar(name, self.plugin.flash.edit);
  7265. });
  7266. /*******************************************************************************
  7267. * KindEditor - WYSIWYG HTML Editor for Internet
  7268. * Copyright (C) 2006-2011 kindsoft.net
  7269. *
  7270. * @author Roddy <luolonghao@gmail.com>
  7271. * @site http://www.kindsoft.net/
  7272. * @licence http://www.kindsoft.net/license.php
  7273. *******************************************************************************/
  7274. KindEditor.plugin('image', function(K) {
  7275. var self = this, name = 'image',
  7276. allowImageUpload = K.undef(self.allowImageUpload, true),
  7277. allowImageRemote = K.undef(self.allowImageRemote, true),
  7278. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7279. allowFileManager = K.undef(self.allowFileManager, false),
  7280. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7281. imageTabIndex = K.undef(self.imageTabIndex, 0),
  7282. imgPath = self.pluginsPath + 'image/images/',
  7283. extraParams = K.undef(self.extraFileUploadParams, {}),
  7284. filePostName = K.undef(self.filePostName, 'imgFile'),
  7285. fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
  7286. lang = self.lang(name + '.');
  7287. self.plugin.imageDialog = function(options) {
  7288. var imageUrl = options.imageUrl,
  7289. imageWidth = K.undef(options.imageWidth, ''),
  7290. imageHeight = K.undef(options.imageHeight, ''),
  7291. imageTitle = K.undef(options.imageTitle, ''),
  7292. imageAlign = K.undef(options.imageAlign, ''),
  7293. showRemote = K.undef(options.showRemote, true),
  7294. showLocal = K.undef(options.showLocal, true),
  7295. tabIndex = K.undef(options.tabIndex, 0),
  7296. clickFn = options.clickFn;
  7297. var target = 'kindeditor_upload_iframe_' + new Date().getTime();
  7298. var hiddenElements = [];
  7299. for(var k in extraParams){
  7300. hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
  7301. }
  7302. var html = [
  7303. '<div style="padding:20px;">',
  7304. '<div class="tabs"></div>',
  7305. '<div class="tab1" style="display:none;">',
  7306. '<div class="ke-dialog-row">',
  7307. '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
  7308. '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
  7309. '<span class="ke-button-common ke-button-outer">',
  7310. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7311. '</span>',
  7312. '</div>',
  7313. '<div class="ke-dialog-row">',
  7314. '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
  7315. lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
  7316. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
  7317. '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
  7318. '</div>',
  7319. '<div class="ke-dialog-row">',
  7320. '<label style="width:60px;">' + lang.align + '</label>',
  7321. '<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="" />',
  7322. ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
  7323. ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
  7324. '</div>',
  7325. '<div class="ke-dialog-row">',
  7326. '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
  7327. '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
  7328. '</div>',
  7329. '</div>',
  7330. '<div class="tab2" style="display:none;">',
  7331. '<iframe name="' + target + '" style="display:none;"></iframe>',
  7332. '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
  7333. '<div class="ke-dialog-row">',
  7334. hiddenElements.join(''),
  7335. '<label style="width:60px;">' + lang.localUrl + '</label>',
  7336. '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
  7337. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
  7338. '</div>',
  7339. '</form>',
  7340. '</div>',
  7341. '</div>'
  7342. ].join('');
  7343. var dialogWidth = showLocal || allowFileManager ? 450 : 400,
  7344. dialogHeight = showLocal && showRemote ? 300 : 250;
  7345. var dialog = self.createDialog({
  7346. name : name,
  7347. width : dialogWidth,
  7348. height : dialogHeight,
  7349. title : self.lang(name),
  7350. body : html,
  7351. yesBtn : {
  7352. name : self.lang('yes'),
  7353. click : function(e) {
  7354. if (dialog.isLoading) {
  7355. return;
  7356. }
  7357. if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
  7358. if (uploadbutton.fileBox.val() == '') {
  7359. alert(self.lang('pleaseSelectFile'));
  7360. return;
  7361. }
  7362. dialog.showLoading(self.lang('uploadLoading'));
  7363. uploadbutton.submit();
  7364. localUrlBox.val('');
  7365. return;
  7366. }
  7367. var url = K.trim(urlBox.val()),
  7368. width = widthBox.val(),
  7369. height = heightBox.val(),
  7370. title = titleBox.val(),
  7371. align = '';
  7372. alignBox.each(function() {
  7373. if (this.checked) {
  7374. align = this.value;
  7375. return false;
  7376. }
  7377. });
  7378. if (url == 'http://' || K.invalidUrl(url)) {
  7379. alert(self.lang('invalidUrl'));
  7380. urlBox[0].focus();
  7381. return;
  7382. }
  7383. if (!/^\d*$/.test(width)) {
  7384. alert(self.lang('invalidWidth'));
  7385. widthBox[0].focus();
  7386. return;
  7387. }
  7388. if (!/^\d*$/.test(height)) {
  7389. alert(self.lang('invalidHeight'));
  7390. heightBox[0].focus();
  7391. return;
  7392. }
  7393. clickFn.call(self, url, title, width, height, 0, align);
  7394. }
  7395. },
  7396. beforeRemove : function() {
  7397. viewServerBtn.unbind();
  7398. widthBox.unbind();
  7399. heightBox.unbind();
  7400. refreshBtn.unbind();
  7401. }
  7402. }),
  7403. div = dialog.div;
  7404. var urlBox = K('[name="url"]', div),
  7405. localUrlBox = K('[name="localUrl"]', div),
  7406. viewServerBtn = K('[name="viewServer"]', div),
  7407. widthBox = K('.tab1 [name="width"]', div),
  7408. heightBox = K('.tab1 [name="height"]', div),
  7409. refreshBtn = K('.ke-refresh-btn', div),
  7410. titleBox = K('.tab1 [name="title"]', div),
  7411. alignBox = K('.tab1 [name="align"]', div);
  7412. var tabs;
  7413. if (showRemote && showLocal) {
  7414. tabs = K.tabs({
  7415. src : K('.tabs', div),
  7416. afterSelect : function(i) {}
  7417. });
  7418. tabs.add({
  7419. title : lang.remoteImage,
  7420. panel : K('.tab1', div)
  7421. });
  7422. tabs.add({
  7423. title : lang.localImage,
  7424. panel : K('.tab2', div)
  7425. });
  7426. tabs.select(1);
  7427. } else if (showRemote) {
  7428. K('.tab1', div).show();
  7429. } else if (showLocal) {
  7430. K('.tab2', div).show();
  7431. }
  7432. var uploadbutton = K.uploadbutton({
  7433. button : K('.ke-upload-button', div)[0],
  7434. fieldName : filePostName,
  7435. form : K('.ke-form', div),
  7436. target : target,
  7437. width: 60,
  7438. afterUpload : function(data) {
  7439. dialog.hideLoading();
  7440. if (data.error === 0) {
  7441. var url = data.url;
  7442. if (formatUploadUrl) {
  7443. url = K.formatUrl(url, 'absolute');
  7444. }
  7445. if (self.afterUpload) {
  7446. self.afterUpload.call(self, url, data, name);
  7447. }
  7448. if (!fillDescAfterUploadImage) {
  7449. clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
  7450. } else {
  7451. K(".ke-dialog-row #remoteUrl", div).val(url);
  7452. K(".ke-tabs-li", div)[0].click();
  7453. K(".ke-refresh-btn", div).click();
  7454. }
  7455. } else {
  7456. alert(data.message);
  7457. }
  7458. },
  7459. afterError : function(html) {
  7460. dialog.hideLoading();
  7461. self.errorDialog(html);
  7462. }
  7463. });
  7464. uploadbutton.fileBox.change(function(e) {
  7465. localUrlBox.val(uploadbutton.fileBox.val());
  7466. });
  7467. if (allowFileManager) {
  7468. viewServerBtn.click(function(e) {
  7469. //clickFn.call(this, fileUrl, data.file);
  7470. var clickFn = function(url, title, id) {
  7471. K('[name="url"]', div).val(url);
  7472. if (self.afterSelectFile) {
  7473. self.afterSelectFile.call(self, url);
  7474. }
  7475. };
  7476. var cur = K('[name="url"]', div).val();
  7477. editorShowUpload(cur, self.fileManagerJson, '图库', clickFn, this);
  7478. /*
  7479. self.loadPlugin('filemanager', function() {
  7480. self.plugin.filemanagerDialog({
  7481. viewType : 'VIEW',
  7482. dirName : 'image',
  7483. clickFn : function(url, title) {
  7484. if (self.dialogs.length > 1) {
  7485. K('[name="url"]', div).val(url);
  7486. if (self.afterSelectFile) {
  7487. self.afterSelectFile.call(self, url);
  7488. }
  7489. self.hideDialog();
  7490. }
  7491. }
  7492. });
  7493. });
  7494. */
  7495. });
  7496. } else {
  7497. viewServerBtn.hide();
  7498. }
  7499. var originalWidth = 0, originalHeight = 0;
  7500. function setSize(width, height) {
  7501. widthBox.val(width);
  7502. heightBox.val(height);
  7503. originalWidth = width;
  7504. originalHeight = height;
  7505. }
  7506. refreshBtn.click(function(e) {
  7507. var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
  7508. position : 'absolute',
  7509. visibility : 'hidden',
  7510. top : 0,
  7511. left : '-1000px'
  7512. });
  7513. tempImg.bind('load', function() {
  7514. setSize(tempImg.width(), tempImg.height());
  7515. tempImg.remove();
  7516. });
  7517. K(document.body).append(tempImg);
  7518. });
  7519. widthBox.change(function(e) {
  7520. if (originalWidth > 0) {
  7521. heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
  7522. }
  7523. });
  7524. heightBox.change(function(e) {
  7525. if (originalHeight > 0) {
  7526. widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
  7527. }
  7528. });
  7529. urlBox.val(options.imageUrl);
  7530. setSize(options.imageWidth, options.imageHeight);
  7531. titleBox.val(options.imageTitle);
  7532. alignBox.each(function() {
  7533. if (this.value === options.imageAlign) {
  7534. this.checked = true;
  7535. return false;
  7536. }
  7537. });
  7538. if (showRemote && tabIndex === 0) {
  7539. urlBox[0].focus();
  7540. urlBox[0].select();
  7541. }
  7542. return dialog;
  7543. };
  7544. self.plugin.image = {
  7545. edit : function() {
  7546. var img = self.plugin.getSelectedImage();
  7547. self.plugin.imageDialog({
  7548. imageUrl : img ? img.attr('data-ke-src') : 'http://',
  7549. imageWidth : img ? img.width() : '',
  7550. imageHeight : img ? img.height() : '',
  7551. imageTitle : img ? img.attr('title') : '',
  7552. imageAlign : img ? img.attr('align') : '',
  7553. showRemote : allowImageRemote,
  7554. showLocal : allowImageUpload,
  7555. tabIndex: img ? 0 : imageTabIndex,
  7556. clickFn : function(url, title, width, height, border, align) {
  7557. if (img) {
  7558. img.attr('src', url);
  7559. img.attr('data-ke-src', url);
  7560. img.attr('width', width);
  7561. img.attr('height', height);
  7562. img.attr('title', title);
  7563. img.attr('align', align);
  7564. img.attr('alt', title);
  7565. } else {
  7566. self.exec('insertimage', url, title, width, height, border, align);
  7567. }
  7568. setTimeout(function() {
  7569. self.hideDialog().focus();
  7570. }, 0);
  7571. }
  7572. });
  7573. },
  7574. 'delete' : function() {
  7575. var target = self.plugin.getSelectedImage();
  7576. if (target.parent().name == 'a') {
  7577. target = target.parent();
  7578. }
  7579. target.remove();
  7580. self.addBookmark();
  7581. }
  7582. };
  7583. self.clickToolbar(name, self.plugin.image.edit);
  7584. });
  7585. KindEditor.plugin('diy', function(K) {
  7586. var self = this, name = 'diy';
  7587. self.plugin.diy = {
  7588. edit : function() {
  7589. var value = self.plugin.getSelectedDiy();
  7590. if (value.attr('data-applet')) {
  7591. $('.update_show_editor').each(function(i)
  7592. {
  7593. var key = $(this).attr('key');
  7594. if (key.indexOf('http://') > -1) {
  7595. $(this).attr('data-value', value.attr('data-applet'));
  7596. $(this).click();
  7597. $(this).attr('data-value', '');
  7598. }
  7599. })
  7600. } else if (value.attr('data-key')) {
  7601. var data_key = value.attr('data-key');
  7602. $('.upload_show_editor').each(function(i)
  7603. {
  7604. var key = $(this).attr('key');
  7605. if (key == data_key) {
  7606. $(this).attr('data-value', value.attr('data-id'));
  7607. $(this).click();
  7608. $(this).attr('data-value', '');
  7609. }
  7610. })
  7611. }
  7612. },
  7613. 'delete' : function() {
  7614. var target = self.plugin.getSelectedDiy();
  7615. if (target.parent().name == 'a') {
  7616. target = target.parent();
  7617. }
  7618. target.remove();
  7619. self.addBookmark();
  7620. }
  7621. };
  7622. });
  7623. /*******************************************************************************
  7624. * KindEditor - WYSIWYG HTML Editor for Internet
  7625. * Copyright (C) 2006-2011 kindsoft.net
  7626. *
  7627. * @author Roddy <luolonghao@gmail.com>
  7628. * @site http://www.kindsoft.net/
  7629. * @licence http://www.kindsoft.net/license.php
  7630. *******************************************************************************/
  7631. KindEditor.plugin('insertfile', function(K) {
  7632. var self = this, name = 'insertfile',
  7633. allowFileUpload = K.undef(self.allowFileUpload, true),
  7634. allowFileManager = K.undef(self.allowFileManager, false),
  7635. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7636. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7637. extraParams = K.undef(self.extraFileUploadParams, {}),
  7638. filePostName = K.undef(self.filePostName, 'imgFile'),
  7639. lang = self.lang(name + '.');
  7640. self.plugin.fileDialog = function(options) {
  7641. var fileUrl = K.undef(options.fileUrl, 'http://'),
  7642. fileTitle = K.undef(options.fileTitle, ''),
  7643. clickFn = options.clickFn;
  7644. var html = [
  7645. '<div style="padding:20px;">',
  7646. '<div class="ke-dialog-row">',
  7647. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7648. '<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> &nbsp;',
  7649. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  7650. '<span class="ke-button-common ke-button-outer">',
  7651. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7652. '</span>',
  7653. '</div>',
  7654. '<div class="ke-dialog-row">',
  7655. '<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
  7656. '<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
  7657. '</div>',
  7658. '</form>',
  7659. '</div>'
  7660. ].join('');
  7661. var dialog = self.createDialog({
  7662. name : name,
  7663. width : 450,
  7664. title : self.lang(name),
  7665. body : html,
  7666. yesBtn : {
  7667. name : self.lang('yes'),
  7668. click : function(e) {
  7669. var url = K.trim(urlBox.val()),
  7670. title = titleBox.val();
  7671. if (url == 'http://' || K.invalidUrl(url)) {
  7672. alert(self.lang('invalidUrl'));
  7673. urlBox[0].focus();
  7674. return;
  7675. }
  7676. if (K.trim(title) === '') {
  7677. title = url;
  7678. }
  7679. clickFn.call(self, url, title);
  7680. }
  7681. }
  7682. }),
  7683. div = dialog.div;
  7684. var urlBox = K('[name="url"]', div),
  7685. viewServerBtn = K('[name="viewServer"]', div),
  7686. titleBox = K('[name="title"]', div);
  7687. if (allowFileUpload) {
  7688. var uploadbutton = K.uploadbutton({
  7689. button : K('.ke-upload-button', div)[0],
  7690. fieldName : filePostName,
  7691. url : K.addParam(uploadJson, 'dir=file'),
  7692. extraParams : extraParams,
  7693. afterUpload : function(data) {
  7694. dialog.hideLoading();
  7695. if (data.error === 0) {
  7696. var url = data.url;
  7697. if (formatUploadUrl) {
  7698. url = K.formatUrl(url, 'absolute');
  7699. }
  7700. urlBox.val(url);
  7701. if (self.afterUpload) {
  7702. self.afterUpload.call(self, url, data, name);
  7703. }
  7704. alert(self.lang('uploadSuccess'));
  7705. } else {
  7706. alert(data.message);
  7707. }
  7708. },
  7709. afterError : function(html) {
  7710. dialog.hideLoading();
  7711. self.errorDialog(html);
  7712. }
  7713. });
  7714. uploadbutton.fileBox.change(function(e) {
  7715. dialog.showLoading(self.lang('uploadLoading'));
  7716. uploadbutton.submit();
  7717. });
  7718. } else {
  7719. K('.ke-upload-button', div).hide();
  7720. }
  7721. if (allowFileManager) {
  7722. viewServerBtn.click(function(e) {
  7723. var clickFn = function(url, title, id) {
  7724. K('[name="url"]', div).val(url);
  7725. if (self.afterSelectFile) {
  7726. self.afterSelectFile.call(self, url);
  7727. }
  7728. };
  7729. var cur = K('[name="url"]', div).val();
  7730. editorShowUpload(cur, self.fileManagerJson, '文件库', clickFn, this);
  7731. /*
  7732. self.loadPlugin('filemanager', function() {
  7733. self.plugin.filemanagerDialog({
  7734. viewType : 'LIST',
  7735. dirName : 'file',
  7736. clickFn : function(url, title) {
  7737. if (self.dialogs.length > 1) {
  7738. self.hideDialog();
  7739. }
  7740. }
  7741. });
  7742. });
  7743. */
  7744. });
  7745. } else {
  7746. viewServerBtn.hide();
  7747. }
  7748. urlBox.val(fileUrl);
  7749. titleBox.val(fileTitle);
  7750. urlBox[0].focus();
  7751. urlBox[0].select();
  7752. };
  7753. self.clickToolbar(name, function() {
  7754. self.plugin.fileDialog({
  7755. clickFn : function(url, title) {
  7756. var html = '<a class="ke-insertfile" href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
  7757. self.insertHtml(html).hideDialog().focus();
  7758. }
  7759. });
  7760. });
  7761. });
  7762. /*******************************************************************************
  7763. * KindEditor - WYSIWYG HTML Editor for Internet
  7764. * Copyright (C) 2006-2011 kindsoft.net
  7765. *
  7766. * @author Roddy <luolonghao@gmail.com>
  7767. * @site http://www.kindsoft.net/
  7768. * @licence http://www.kindsoft.net/license.php
  7769. *******************************************************************************/
  7770. KindEditor.plugin('lineheight', function(K) {
  7771. var self = this, name = 'lineheight', lang = self.lang(name + '.');
  7772. self.clickToolbar(name, function() {
  7773. var curVal = '', commonNode = self.cmd.commonNode({'*' : '.line-height'});
  7774. if (commonNode) {
  7775. curVal = commonNode.css('line-height');
  7776. }
  7777. var menu = self.createMenu({
  7778. name : name,
  7779. width : 150
  7780. });
  7781. K.each(lang.lineHeight, function(i, row) {
  7782. K.each(row, function(key, val) {
  7783. menu.addItem({
  7784. title : val,
  7785. checked : curVal === key,
  7786. click : function() {
  7787. self.cmd.toggle('<span style="line-height:' + key + ';"></span>', {
  7788. span : '.line-height=' + key
  7789. });
  7790. self.updateState();
  7791. self.addBookmark();
  7792. self.hideMenu();
  7793. }
  7794. });
  7795. });
  7796. });
  7797. });
  7798. });
  7799. /*******************************************************************************
  7800. * KindEditor - WYSIWYG HTML Editor for Internet
  7801. * Copyright (C) 2006-2011 kindsoft.net
  7802. *
  7803. * @author Roddy <luolonghao@gmail.com>
  7804. * @site http://www.kindsoft.net/
  7805. * @licence http://www.kindsoft.net/license.php
  7806. *******************************************************************************/
  7807. KindEditor.plugin('link', function(K) {
  7808. var self = this, name = 'link';
  7809. self.plugin.link = {
  7810. edit : function() {
  7811. var lang = self.lang(name + '.'),
  7812. html = '<div style="padding:20px;">' +
  7813. '<div class="ke-dialog-row">' +
  7814. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' +
  7815. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' +
  7816. '<div class="ke-dialog-row"">' +
  7817. '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' +
  7818. '<select id="keType" name="type"></select>' +
  7819. '</div>' +
  7820. '</div>',
  7821. dialog = self.createDialog({
  7822. name : name,
  7823. width : 450,
  7824. title : self.lang(name),
  7825. body : html,
  7826. yesBtn : {
  7827. name : self.lang('yes'),
  7828. click : function(e) {
  7829. var url = K.trim(urlBox.val());
  7830. if (url == 'http://' || K.invalidUrl(url)) {
  7831. alert(self.lang('invalidUrl'));
  7832. urlBox[0].focus();
  7833. return;
  7834. }
  7835. self.exec('createlink', url, typeBox.val()).hideDialog().focus();
  7836. }
  7837. }
  7838. }),
  7839. div = dialog.div,
  7840. urlBox = K('input[name="url"]', div),
  7841. typeBox = K('select[name="type"]', div);
  7842. urlBox.val('http://');
  7843. typeBox[0].options[0] = new Option(lang.newWindow, '_blank');
  7844. typeBox[0].options[1] = new Option(lang.selfWindow, '');
  7845. self.cmd.selection();
  7846. var a = self.plugin.getSelectedLink();
  7847. if (a) {
  7848. self.cmd.range.selectNode(a[0]);
  7849. //self.cmd.select();
  7850. urlBox.val(a.attr('data-ke-src'));
  7851. typeBox.val(a.attr('target'));
  7852. }
  7853. urlBox[0].focus();
  7854. urlBox[0].select();
  7855. },
  7856. 'delete' : function() {
  7857. self.exec('unlink', null);
  7858. }
  7859. };
  7860. self.clickToolbar(name, self.plugin.link.edit);
  7861. });
  7862. /*******************************************************************************
  7863. * KindEditor - WYSIWYG HTML Editor for Internet
  7864. * Copyright (C) 2006-2011 kindsoft.net
  7865. *
  7866. * @author Roddy <luolonghao@gmail.com>
  7867. * @site http://www.kindsoft.net/
  7868. * @licence http://www.kindsoft.net/license.php
  7869. *******************************************************************************/
  7870. KindEditor.plugin('media', function(K) {
  7871. var self = this, name = 'media', lang = self.lang(name + '.'),
  7872. allowFileUpload = K.undef(self.allowFileUpload, true),
  7873. allowFileManager = K.undef(self.allowFileManager, false),
  7874. allowMediaUpload = K.undef(self.allowMediaUpload, true),
  7875. allowFileManager = K.undef(self.allowFileManager, false),
  7876. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  7877. extraParams = K.undef(self.extraFileUploadParams, {}),
  7878. uploadCoverJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  7879. filePostName = K.undef(self.filePostName, 'imgFile'),
  7880. uploadJson = K.undef(self.uploadMediaJson, self.basePath + 'php/upload_json.php');
  7881. if (self.uploadYunJson && self.uploadYunJson.domain) {
  7882. uploadJson = self.uploadYunJson.domain;
  7883. extraParams.token = self.uploadYunJson.token;
  7884. extraParams.key = self.uploadYunJson.path;
  7885. }
  7886. self.plugin.media = {
  7887. edit : function() {
  7888. var html = [
  7889. '<div style="padding:20px;">',
  7890. '<div class="ke-dialog-row">',
  7891. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  7892. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  7893. '<input type="button" class="ke-upload-button ke-upload-button-media" value="' + lang.upload + '" /> &nbsp;',
  7894. '<span class="ke-button-common ke-button-outer">',
  7895. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  7896. '</span>',
  7897. '</div>',
  7898. '<div class="ke-dialog-row">',
  7899. '<label for="keWidth" style="width:60px;">标题</label>',
  7900. '<input type="text" id="keName" class="ke-input-text" style="width:160px;" name="name" value="" maxlength="30" />&nbsp;&nbsp;&nbsp;宽高:<input type="text" id="keWh" class="ke-input-text" style="width:100px;" name="wh" value="200px*200px" maxlength="100" />',
  7901. '</div>',
  7902. '<div class="ke-dialog-row">',
  7903. '<label for="keUrl" style="width:60px;">封面</label>',
  7904. '<input class="ke-input-text" type="text" id="keUrlCover" name="cover_url" value="" style="width:160px;" /> &nbsp;',
  7905. '<input type="button" class="ke-upload-button ke-upload-button-cover" value="' + lang.upload + '" /> &nbsp;',
  7906. '<span class="ke-button-common ke-button-outer">',
  7907. '<input type="button" class="ke-button-common ke-button" name="viewCoverServer" value="' + lang.viewServer + '" />',
  7908. '</span>',
  7909. '<br /><br />(封面要求:音频封面图片尺寸200*200px或等比尺寸,视频封面图片尺寸为视频实际尺寸或者等比尺寸,上传大小不能超过2M,建议上传JPG格式)',
  7910. '</div>',
  7911. '<div class="ke-dialog-row" style="display:none;">',
  7912. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  7913. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="200" maxlength="4" />',
  7914. '<div style="display: inline;margin-left: 20px;">',
  7915. '<label for="keHeight" >' + lang.height + '</label>',
  7916. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="200" maxlength="4" />',
  7917. '</div>',
  7918. '</div>',
  7919. '<div class="ke-dialog-row" style="display:none;">',
  7920. '<label for="keAutostart">' + lang.autostart + '</label>',
  7921. '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
  7922. '</div>',
  7923. '</div>'
  7924. ].join('');
  7925. var dialog = self.createDialog({
  7926. name : name,
  7927. width : 450,
  7928. height : 230,
  7929. title : self.lang(name),
  7930. body : html,
  7931. yesBtn : {
  7932. name : self.lang('yes'),
  7933. click : function(e) {
  7934. var url = K.trim(urlBox.val()),
  7935. coverUrl = K.trim(coverUrlBox.val()),
  7936. name = nameBox.val(),
  7937. wh = whBox.val(),
  7938. width = widthBox.val(),
  7939. height = heightBox.val();
  7940. var temp = wh.split('*');
  7941. width = temp[0];
  7942. height = temp[1];
  7943. if (url == 'http://' || K.invalidUrl(url)) {
  7944. alert(self.lang('invalidUrl'));
  7945. urlBox[0].focus();
  7946. return;
  7947. }
  7948. if (!name) {
  7949. alert('请填写标题');
  7950. urlBox[0].focus();
  7951. return;
  7952. }
  7953. if (!wh) {
  7954. alert('请填写宽高');
  7955. urlBox[0].focus();
  7956. return;
  7957. }
  7958. if (coverUrl == 'http://' || K.invalidUrl(coverUrl)) {
  7959. alert('请上传封面');
  7960. urlBox[0].focus();
  7961. return;
  7962. }
  7963. /*
  7964. if (!/^\d*$/.test(width)) {
  7965. alert(self.lang('invalidWidth'));
  7966. widthBox[0].focus();
  7967. return;
  7968. }
  7969. if (!/^\d*$/.test(height)) {
  7970. alert(self.lang('invalidHeight'));
  7971. heightBox[0].focus();
  7972. return;
  7973. }
  7974. */
  7975. if (!coverUrl) {
  7976. var cover = self.themesPath + 'common/blank.gif';
  7977. } else {
  7978. var cover = coverUrl;
  7979. }
  7980. /*
  7981. var html = K.mediaImg(cover, {
  7982. src : url,
  7983. type : K.mediaType(url),
  7984. width : width,
  7985. height : height,
  7986. autostart : autostartBox[0].checked ? 'true' : 'false',
  7987. loop : 'true'
  7988. });
  7989. */
  7990. var html = '<img src="'+cover+'" style="width:'+width+';height:'+height+';" data-file="'+url+'||'+name+'||'+wh+'"/>';
  7991. self.insertHtml(html).hideDialog().focus();
  7992. }
  7993. }
  7994. }),
  7995. div = dialog.div,
  7996. nameBox = K('[name="name"]', div),
  7997. whBox = K('[name="wh"]', div),
  7998. coverUrlBox = K('[name="cover_url"]', div),
  7999. viewCoverServerBtn = K('[name="viewCoverServer"]', div),
  8000. urlBox = K('[name="url"]', div),
  8001. viewServerBtn = K('[name="viewServer"]', div),
  8002. widthBox = K('[name="width"]', div),
  8003. heightBox = K('[name="height"]', div),
  8004. autostartBox = K('[name="autostart"]', div);
  8005. urlBox.val('http://');
  8006. coverUrlBox.val('http://');
  8007. if (allowMediaUpload) {
  8008. var uploadbutton = K.uploadbutton({
  8009. button : K('.ke-upload-button-media', div)[0],
  8010. fieldName : filePostName,
  8011. extraParams : extraParams,
  8012. url : K.addParam(uploadJson, 'dir=media'),
  8013. afterUpload : function(data) {
  8014. console.info(data);
  8015. dialog.hideLoading();
  8016. if (data.error === 0) {
  8017. var url = data.url;
  8018. if (formatUploadUrl) {
  8019. url = K.formatUrl(url, 'absolute');
  8020. }
  8021. urlBox.val(url);
  8022. if (self.afterUpload) {
  8023. self.afterUpload.call(self, url, data, name);
  8024. }
  8025. alert(self.lang('uploadSuccess'));
  8026. } else {
  8027. alert(data.message);
  8028. }
  8029. },
  8030. afterError : function(html) {
  8031. dialog.hideLoading();
  8032. self.errorDialog(html);
  8033. }
  8034. });
  8035. uploadbutton.fileBox.change(function(e) {
  8036. dialog.showLoading(self.lang('uploadLoading'));
  8037. uploadbutton.submit(this);
  8038. });
  8039. } else {
  8040. K('.ke-upload-button-media', div).hide();
  8041. }
  8042. if (allowFileUpload) {
  8043. var uploadbuttonCover = K.uploadbutton({
  8044. button : K('.ke-upload-button-cover', div)[0],
  8045. fieldName : filePostName,
  8046. url : K.addParam(uploadCoverJson, 'dir=file'),
  8047. extraParams : extraParams,
  8048. afterUpload : function(data) {
  8049. dialog.hideLoading();
  8050. if (data.error === 0) {
  8051. var url = data.url;
  8052. if (formatUploadUrl) {
  8053. url = K.formatUrl(url, 'absolute');
  8054. }
  8055. coverUrlBox.val(url);
  8056. if (self.afterUpload) {
  8057. self.afterUpload.call(self, url, data, name);
  8058. }
  8059. alert(self.lang('uploadSuccess'));
  8060. } else {
  8061. alert(data.message);
  8062. }
  8063. },
  8064. afterError : function(html) {
  8065. dialog.hideLoading();
  8066. self.errorDialog(html);
  8067. }
  8068. });
  8069. uploadbuttonCover.fileBox.change(function(e) {
  8070. dialog.showLoading(self.lang('uploadLoading'));
  8071. uploadbuttonCover.submit();
  8072. });
  8073. } else {
  8074. K('.ke-upload-button-cover', div).hide();
  8075. }
  8076. if (allowFileManager) {
  8077. viewServerBtn.click(function(e) {
  8078. var clickFn = function(url, title, id) {
  8079. K('[name="url"]', div).val(url);
  8080. if (self.afterSelectFile) {
  8081. self.afterSelectFile.call(self, url);
  8082. }
  8083. };
  8084. var cur = K('[name="url"]', div).val();
  8085. editorShowUpload(cur, self.fileManagerJson, '音频库', clickFn, this);
  8086. /*
  8087. self.loadPlugin('filemanager', function() {
  8088. self.plugin.filemanagerDialog({
  8089. viewType : 'LIST',
  8090. dirName : 'media',
  8091. clickFn : function(url, title) {
  8092. if (self.dialogs.length > 1) {
  8093. K('[name="url"]', div).val(url);
  8094. if (self.afterSelectFile) {
  8095. self.afterSelectFile.call(self, url);
  8096. }
  8097. self.hideDialog();
  8098. }
  8099. }
  8100. });
  8101. });
  8102. */
  8103. });
  8104. viewCoverServerBtn.click(function(e) {
  8105. var clickFn = function(url, title, id) {
  8106. coverUrlBox.val(url);
  8107. if (self.afterSelectFile) {
  8108. self.afterSelectFile.call(self, url);
  8109. }
  8110. };
  8111. var cur = coverUrlBox.val();
  8112. editorShowUpload(cur, self.fileManagerJson, '图库', clickFn, this);
  8113. /*
  8114. self.loadPlugin('filemanager', function() {
  8115. self.plugin.filemanagerDialog({
  8116. viewType : 'LIST',
  8117. dirName : 'file',
  8118. clickFn : function(url, title) {
  8119. if (self.dialogs.length > 1) {
  8120. self.hideDialog();
  8121. }
  8122. }
  8123. });
  8124. });
  8125. */
  8126. });
  8127. } else {
  8128. viewServerBtn.hide();
  8129. viewCoverServerBtn.hide();
  8130. }
  8131. var img = self.plugin.getSelectedMedia();
  8132. if (img) {
  8133. if (img.attr('data-file')) {
  8134. var temp = img.attr('data-file').split('||');
  8135. nameBox.val(temp[1]);
  8136. whBox.val(temp[2]);
  8137. urlBox.val(temp[0]);
  8138. coverUrlBox.val(img.attr('src'));
  8139. } else {
  8140. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  8141. urlBox.val(attrs.src);
  8142. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  8143. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  8144. autostartBox[0].checked = (attrs.autostart === 'true');
  8145. }
  8146. }
  8147. urlBox[0].focus();
  8148. urlBox[0].select();
  8149. },
  8150. 'delete' : function() {
  8151. self.plugin.getSelectedMedia().remove();
  8152. self.addBookmark();
  8153. }
  8154. };
  8155. self.clickToolbar(name, self.plugin.media.edit);
  8156. });
  8157. /*******************************************************************************
  8158. * KindEditor - WYSIWYG HTML Editor for Internet
  8159. * Copyright (C) 2006-2011 kindsoft.net
  8160. *
  8161. * @author Roddy <luolonghao@gmail.com>
  8162. * @site http://www.kindsoft.net/
  8163. * @licence http://www.kindsoft.net/license.php
  8164. *******************************************************************************/
  8165. (function(K) {
  8166. function KSWFUpload(options) {
  8167. this.init(options);
  8168. }
  8169. K.extend(KSWFUpload, {
  8170. init : function(options) {
  8171. var self = this;
  8172. options.afterError = options.afterError || function(str) {
  8173. alert(str);
  8174. };
  8175. self.options = options;
  8176. self.progressbars = {};
  8177. self.div = K(options.container).html([
  8178. '<div class="ke-swfupload">',
  8179. '<div class="ke-swfupload-top">',
  8180. '<div class="ke-inline-block ke-swfupload-button">',
  8181. '<input type="button" value="Browse" />',
  8182. '</div>',
  8183. '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
  8184. '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
  8185. '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
  8186. '</span>',
  8187. '</div>',
  8188. '<div class="ke-swfupload-body"></div>',
  8189. '</div>'
  8190. ].join(''));
  8191. self.bodyDiv = K('.ke-swfupload-body', self.div);
  8192. function showError(itemDiv, msg) {
  8193. K('.ke-status > div', itemDiv).hide();
  8194. K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
  8195. }
  8196. var settings = {
  8197. debug : false,
  8198. upload_url : options.uploadUrl,
  8199. flash_url : options.flashUrl,
  8200. file_post_name : options.filePostName,
  8201. button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
  8202. button_image_url: options.buttonImageUrl,
  8203. button_width: options.buttonWidth,
  8204. button_height: options.buttonHeight,
  8205. button_cursor : SWFUpload.CURSOR.HAND,
  8206. file_types : options.fileTypes,
  8207. file_types_description : options.fileTypesDesc,
  8208. file_upload_limit : options.fileUploadLimit,
  8209. file_size_limit : options.fileSizeLimit,
  8210. post_params : options.postParams,
  8211. file_queued_handler : function(file) {
  8212. file.url = self.options.fileIconUrl;
  8213. self.appendFile(file);
  8214. },
  8215. file_queue_error_handler : function(file, errorCode, message) {
  8216. var errorName = '';
  8217. switch (errorCode) {
  8218. case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
  8219. errorName = options.queueLimitExceeded;
  8220. break;
  8221. case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
  8222. errorName = options.fileExceedsSizeLimit;
  8223. break;
  8224. case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
  8225. errorName = options.zeroByteFile;
  8226. break;
  8227. case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
  8228. errorName = options.invalidFiletype;
  8229. break;
  8230. default:
  8231. errorName = options.unknownError;
  8232. break;
  8233. }
  8234. K.DEBUG && alert(errorName);
  8235. },
  8236. upload_start_handler : function(file) {
  8237. var self = this;
  8238. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
  8239. K('.ke-status > div', itemDiv).hide();
  8240. K('.ke-progressbar', itemDiv).show();
  8241. },
  8242. upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
  8243. var percent = Math.round(bytesLoaded * 100 / bytesTotal);
  8244. var progressbar = self.progressbars[file.id];
  8245. progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
  8246. progressbar.percent.html(percent + '%');
  8247. },
  8248. upload_error_handler : function(file, errorCode, message) {
  8249. if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
  8250. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  8251. showError(itemDiv, self.options.errorMessage);
  8252. }
  8253. },
  8254. upload_success_handler : function(file, serverData) {
  8255. var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
  8256. var data = {};
  8257. try {
  8258. data = K.json(serverData);
  8259. } catch (e) {
  8260. self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
  8261. }
  8262. if (data.error !== 0) {
  8263. showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
  8264. return;
  8265. }
  8266. file.url = data.url;
  8267. K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
  8268. K('.ke-status > div', itemDiv).hide();
  8269. }
  8270. };
  8271. self.swfu = new SWFUpload(settings);
  8272. K('.ke-swfupload-startupload input', self.div).click(function() {
  8273. self.swfu.startUpload();
  8274. });
  8275. },
  8276. getUrlList : function() {
  8277. var list = [];
  8278. K('.ke-img', self.bodyDiv).each(function() {
  8279. var img = K(this);
  8280. var status = img.attr('data-status');
  8281. if (status == SWFUpload.FILE_STATUS.COMPLETE) {
  8282. list.push(img.data('data'));
  8283. }
  8284. });
  8285. return list;
  8286. },
  8287. removeFile : function(fileId) {
  8288. var self = this;
  8289. self.swfu.cancelUpload(fileId);
  8290. var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
  8291. K('.ke-photo', itemDiv).unbind();
  8292. K('.ke-delete', itemDiv).unbind();
  8293. itemDiv.remove();
  8294. },
  8295. removeFiles : function() {
  8296. var self = this;
  8297. K('.ke-item', self.bodyDiv).each(function() {
  8298. self.removeFile(K(this).attr('data-id'));
  8299. });
  8300. },
  8301. appendFile : function(file) {
  8302. var self = this;
  8303. var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
  8304. self.bodyDiv.append(itemDiv);
  8305. var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
  8306. .mouseover(function(e) {
  8307. K(this).addClass('ke-on');
  8308. })
  8309. .mouseout(function(e) {
  8310. K(this).removeClass('ke-on');
  8311. });
  8312. itemDiv.append(photoDiv);
  8313. var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
  8314. photoDiv.append(img);
  8315. K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
  8316. self.removeFile(file.id);
  8317. });
  8318. var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
  8319. K(['<div class="ke-progressbar">',
  8320. '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
  8321. '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
  8322. K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
  8323. itemDiv.append('<div class="ke-name">' + file.name + '</div>');
  8324. self.progressbars[file.id] = {
  8325. bar : K('.ke-progressbar-bar-inner', photoDiv),
  8326. percent : K('.ke-progressbar-percent', photoDiv)
  8327. };
  8328. },
  8329. remove : function() {
  8330. this.removeFiles();
  8331. this.swfu.destroy();
  8332. this.div.html('');
  8333. }
  8334. });
  8335. K.swfupload = function(element, options) {
  8336. return new KSWFUpload(element, options);
  8337. };
  8338. })(KindEditor);
  8339. KindEditor.plugin('multiimage', function(K) {
  8340. var self = this, name = 'multiimage',
  8341. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  8342. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
  8343. imgPath = self.pluginsPath + 'multiimage/images/',
  8344. imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
  8345. imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
  8346. imageUploadLimit = K.undef(self.imageUploadLimit, 20),
  8347. filePostName = K.undef(self.filePostName, 'imgFile'),
  8348. lang = self.lang(name + '.');
  8349. self.plugin.multiImageDialog = function(options) {
  8350. var clickFn = options.clickFn,
  8351. uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
  8352. uploadDesc = '';
  8353. var html = [
  8354. '<div style="padding:20px;">',
  8355. '<div class="swfupload">',
  8356. '</div>',
  8357. '</div>'
  8358. ].join('');
  8359. var dialog = self.createDialog({
  8360. name : name,
  8361. width : 650,
  8362. height : 510,
  8363. title : self.lang(name),
  8364. body : html,
  8365. previewBtn : {
  8366. name : lang.insertAll,
  8367. click : function(e) {
  8368. clickFn.call(self, swfupload.getUrlList());
  8369. }
  8370. },
  8371. yesBtn : {
  8372. name : lang.clearAll,
  8373. click : function(e) {
  8374. swfupload.removeFiles();
  8375. }
  8376. },
  8377. beforeRemove : function() {
  8378. if (!K.IE || K.V <= 8) {
  8379. swfupload.remove();
  8380. }
  8381. }
  8382. }),
  8383. div = dialog.div;
  8384. var swfupload = K.swfupload({
  8385. container : K('.swfupload', div),
  8386. buttonImageUrl : imgPath + (self.langType == 'zh-CN' ? 'select-files-zh-CN.png' : 'select-files-en.png'),
  8387. buttonWidth : self.langType == 'zh-CN' ? 72 : 88,
  8388. buttonHeight : 23,
  8389. fileIconUrl : imgPath + 'image.png',
  8390. uploadDesc : uploadDesc,
  8391. startButtonValue : lang.startUpload,
  8392. uploadUrl : K.addParam(uploadJson, 'dir=image'),
  8393. //uploadMediaUrl : K.addParam(uploadMediaUrl, 'dir=media'),
  8394. flashUrl : imgPath + 'swfupload.swf',
  8395. filePostName : filePostName,
  8396. fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
  8397. fileTypesDesc : 'Image Files',
  8398. fileUploadLimit : imageUploadLimit,
  8399. fileSizeLimit : imageSizeLimit,
  8400. postParams : K.undef(self.extraFileUploadParams, {}),
  8401. queueLimitExceeded : lang.queueLimitExceeded,
  8402. fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
  8403. zeroByteFile : lang.zeroByteFile,
  8404. invalidFiletype : lang.invalidFiletype,
  8405. unknownError : lang.unknownError,
  8406. pendingMessage : lang.pending,
  8407. errorMessage : lang.uploadError,
  8408. afterError : function(html) {
  8409. self.errorDialog(html);
  8410. }
  8411. });
  8412. return dialog;
  8413. };
  8414. self.clickToolbar(name, function() {
  8415. self.plugin.multiImageDialog({
  8416. clickFn : function (urlList) {
  8417. if (urlList.length === 0) {
  8418. return;
  8419. }
  8420. K.each(urlList, function(i, data) {
  8421. if (self.afterUpload) {
  8422. self.afterUpload.call(self, data.url, data, 'multiimage');
  8423. }
  8424. self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
  8425. });
  8426. setTimeout(function() {
  8427. self.hideDialog().focus();
  8428. }, 0);
  8429. }
  8430. });
  8431. });
  8432. });
  8433. /* ******************* */
  8434. /* Constructor & Init */
  8435. /* ******************* */
  8436. (function() {
  8437. window.SWFUpload = function (settings) {
  8438. this.initSWFUpload(settings);
  8439. };
  8440. SWFUpload.prototype.initSWFUpload = function (settings) {
  8441. try {
  8442. this.customSettings = {};
  8443. this.settings = settings;
  8444. this.eventQueue = [];
  8445. this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
  8446. this.movieElement = null;
  8447. SWFUpload.instances[this.movieName] = this;
  8448. this.initSettings();
  8449. this.loadFlash();
  8450. this.displayDebugInfo();
  8451. } catch (ex) {
  8452. delete SWFUpload.instances[this.movieName];
  8453. throw ex;
  8454. }
  8455. };
  8456. /* *************** */
  8457. /* Static Members */
  8458. /* *************** */
  8459. SWFUpload.instances = {};
  8460. SWFUpload.movieCount = 0;
  8461. SWFUpload.version = "2.2.0 2009-03-25";
  8462. SWFUpload.QUEUE_ERROR = {
  8463. QUEUE_LIMIT_EXCEEDED : -100,
  8464. FILE_EXCEEDS_SIZE_LIMIT : -110,
  8465. ZERO_BYTE_FILE : -120,
  8466. INVALID_FILETYPE : -130
  8467. };
  8468. SWFUpload.UPLOAD_ERROR = {
  8469. HTTP_ERROR : -200,
  8470. MISSING_UPLOAD_URL : -210,
  8471. IO_ERROR : -220,
  8472. SECURITY_ERROR : -230,
  8473. UPLOAD_LIMIT_EXCEEDED : -240,
  8474. UPLOAD_FAILED : -250,
  8475. SPECIFIED_FILE_ID_NOT_FOUND : -260,
  8476. FILE_VALIDATION_FAILED : -270,
  8477. FILE_CANCELLED : -280,
  8478. UPLOAD_STOPPED : -290
  8479. };
  8480. SWFUpload.FILE_STATUS = {
  8481. QUEUED : -1,
  8482. IN_PROGRESS : -2,
  8483. ERROR : -3,
  8484. COMPLETE : -4,
  8485. CANCELLED : -5
  8486. };
  8487. SWFUpload.BUTTON_ACTION = {
  8488. SELECT_FILE : -100,
  8489. SELECT_FILES : -110,
  8490. START_UPLOAD : -120
  8491. };
  8492. SWFUpload.CURSOR = {
  8493. ARROW : -1,
  8494. HAND : -2
  8495. };
  8496. SWFUpload.WINDOW_MODE = {
  8497. WINDOW : "window",
  8498. TRANSPARENT : "transparent",
  8499. OPAQUE : "opaque"
  8500. };
  8501. SWFUpload.completeURL = function(url) {
  8502. if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
  8503. return url;
  8504. }
  8505. var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
  8506. var indexSlash = window.location.pathname.lastIndexOf("/");
  8507. var path;
  8508. if (indexSlash <= 0) {
  8509. path = "/";
  8510. } else {
  8511. path = window.location.pathname.substr(0, indexSlash) + "/";
  8512. }
  8513. return /*currentURL +*/ path + url;
  8514. };
  8515. /* ******************** */
  8516. /* Instance Members */
  8517. /* ******************** */
  8518. SWFUpload.prototype.initSettings = function () {
  8519. this.ensureDefault = function (settingName, defaultValue) {
  8520. this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
  8521. };
  8522. this.ensureDefault("upload_url", "");
  8523. this.ensureDefault("preserve_relative_urls", false);
  8524. this.ensureDefault("file_post_name", "Filedata");
  8525. this.ensureDefault("post_params", {});
  8526. this.ensureDefault("use_query_string", false);
  8527. this.ensureDefault("requeue_on_error", false);
  8528. this.ensureDefault("http_success", []);
  8529. this.ensureDefault("assume_success_timeout", 0);
  8530. this.ensureDefault("file_types", "*.*");
  8531. this.ensureDefault("file_types_description", "All Files");
  8532. this.ensureDefault("file_size_limit", 0);
  8533. this.ensureDefault("file_upload_limit", 0);
  8534. this.ensureDefault("file_queue_limit", 0);
  8535. this.ensureDefault("flash_url", "swfupload.swf");
  8536. this.ensureDefault("prevent_swf_caching", true);
  8537. this.ensureDefault("button_image_url", "");
  8538. this.ensureDefault("button_width", 1);
  8539. this.ensureDefault("button_height", 1);
  8540. this.ensureDefault("button_text", "");
  8541. this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
  8542. this.ensureDefault("button_text_top_padding", 0);
  8543. this.ensureDefault("button_text_left_padding", 0);
  8544. this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
  8545. this.ensureDefault("button_disabled", false);
  8546. this.ensureDefault("button_placeholder_id", "");
  8547. this.ensureDefault("button_placeholder", null);
  8548. this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
  8549. this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
  8550. this.ensureDefault("debug", false);
  8551. this.settings.debug_enabled = this.settings.debug;
  8552. this.settings.return_upload_start_handler = this.returnUploadStart;
  8553. this.ensureDefault("swfupload_loaded_handler", null);
  8554. this.ensureDefault("file_dialog_start_handler", null);
  8555. this.ensureDefault("file_queued_handler", null);
  8556. this.ensureDefault("file_queue_error_handler", null);
  8557. this.ensureDefault("file_dialog_complete_handler", null);
  8558. this.ensureDefault("upload_start_handler", null);
  8559. this.ensureDefault("upload_progress_handler", null);
  8560. this.ensureDefault("upload_error_handler", null);
  8561. this.ensureDefault("upload_success_handler", null);
  8562. this.ensureDefault("upload_complete_handler", null);
  8563. this.ensureDefault("debug_handler", this.debugMessage);
  8564. this.ensureDefault("custom_settings", {});
  8565. this.customSettings = this.settings.custom_settings;
  8566. if (!!this.settings.prevent_swf_caching) {
  8567. this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
  8568. }
  8569. if (!this.settings.preserve_relative_urls) {
  8570. this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
  8571. this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
  8572. }
  8573. delete this.ensureDefault;
  8574. };
  8575. SWFUpload.prototype.loadFlash = function () {
  8576. var targetElement, tempParent;
  8577. if (document.getElementById(this.movieName) !== null) {
  8578. throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
  8579. }
  8580. targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
  8581. if (targetElement == undefined) {
  8582. throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
  8583. }
  8584. tempParent = document.createElement("div");
  8585. tempParent.innerHTML = this.getFlashHTML();
  8586. targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
  8587. if (window[this.movieName] == undefined) {
  8588. window[this.movieName] = this.getMovieElement();
  8589. }
  8590. };
  8591. SWFUpload.prototype.getFlashHTML = function () {
  8592. var classid = '';
  8593. if (KindEditor.IE && KindEditor.V > 8) {
  8594. classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
  8595. }
  8596. 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">',
  8597. '<param name="wmode" value="', this.settings.button_window_mode, '" />',
  8598. '<param name="movie" value="', this.settings.flash_url, '" />',
  8599. '<param name="quality" value="high" />',
  8600. '<param name="menu" value="false" />',
  8601. '<param name="allowScriptAccess" value="always" />',
  8602. '<param name="flashvars" value="' + this.getFlashVars() + '" />',
  8603. '</object>'].join("");
  8604. };
  8605. SWFUpload.prototype.getFlashVars = function () {
  8606. var paramString = this.buildParamString();
  8607. var httpSuccessString = this.settings.http_success.join(",");
  8608. return ["movieName=", encodeURIComponent(this.movieName),
  8609. "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
  8610. "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
  8611. "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
  8612. "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
  8613. "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
  8614. "&amp;params=", encodeURIComponent(paramString),
  8615. "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
  8616. "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
  8617. "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
  8618. "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
  8619. "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
  8620. "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
  8621. "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
  8622. "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
  8623. "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
  8624. "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
  8625. "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
  8626. "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
  8627. "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
  8628. "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
  8629. "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
  8630. "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
  8631. "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
  8632. ].join("");
  8633. };
  8634. SWFUpload.prototype.getMovieElement = function () {
  8635. if (this.movieElement == undefined) {
  8636. this.movieElement = document.getElementById(this.movieName);
  8637. }
  8638. if (this.movieElement === null) {
  8639. throw "Could not find Flash element";
  8640. }
  8641. return this.movieElement;
  8642. };
  8643. SWFUpload.prototype.buildParamString = function () {
  8644. var postParams = this.settings.post_params;
  8645. var paramStringPairs = [];
  8646. if (typeof(postParams) === "object") {
  8647. for (var name in postParams) {
  8648. if (postParams.hasOwnProperty(name)) {
  8649. paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
  8650. }
  8651. }
  8652. }
  8653. return paramStringPairs.join("&amp;");
  8654. };
  8655. SWFUpload.prototype.destroy = function () {
  8656. try {
  8657. this.cancelUpload(null, false);
  8658. var movieElement = null;
  8659. movieElement = this.getMovieElement();
  8660. if (movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8661. for (var i in movieElement) {
  8662. try {
  8663. if (typeof(movieElement[i]) === "function") {
  8664. movieElement[i] = null;
  8665. }
  8666. } catch (ex1) {}
  8667. }
  8668. try {
  8669. movieElement.parentNode.removeChild(movieElement);
  8670. } catch (ex) {}
  8671. }
  8672. window[this.movieName] = null;
  8673. SWFUpload.instances[this.movieName] = null;
  8674. delete SWFUpload.instances[this.movieName];
  8675. this.movieElement = null;
  8676. this.settings = null;
  8677. this.customSettings = null;
  8678. this.eventQueue = null;
  8679. this.movieName = null;
  8680. return true;
  8681. } catch (ex2) {
  8682. return false;
  8683. }
  8684. };
  8685. SWFUpload.prototype.displayDebugInfo = function () {
  8686. this.debug(
  8687. [
  8688. "---SWFUpload Instance Info---\n",
  8689. "Version: ", SWFUpload.version, "\n",
  8690. "Movie Name: ", this.movieName, "\n",
  8691. "Settings:\n",
  8692. "\t", "upload_url: ", this.settings.upload_url, "\n",
  8693. "\t", "flash_url: ", this.settings.flash_url, "\n",
  8694. "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
  8695. "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
  8696. "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
  8697. "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
  8698. "\t", "file_post_name: ", this.settings.file_post_name, "\n",
  8699. "\t", "post_params: ", this.settings.post_params.toString(), "\n",
  8700. "\t", "file_types: ", this.settings.file_types, "\n",
  8701. "\t", "file_types_description: ", this.settings.file_types_description, "\n",
  8702. "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
  8703. "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
  8704. "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
  8705. "\t", "debug: ", this.settings.debug.toString(), "\n",
  8706. "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
  8707. "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
  8708. "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
  8709. "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
  8710. "\t", "button_width: ", this.settings.button_width.toString(), "\n",
  8711. "\t", "button_height: ", this.settings.button_height.toString(), "\n",
  8712. "\t", "button_text: ", this.settings.button_text.toString(), "\n",
  8713. "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
  8714. "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
  8715. "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
  8716. "\t", "button_action: ", this.settings.button_action.toString(), "\n",
  8717. "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
  8718. "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
  8719. "Event Handlers:\n",
  8720. "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
  8721. "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
  8722. "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
  8723. "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
  8724. "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
  8725. "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
  8726. "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
  8727. "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
  8728. "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
  8729. "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
  8730. ].join("")
  8731. );
  8732. };
  8733. /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
  8734. the maintain v2 API compatibility
  8735. */
  8736. SWFUpload.prototype.addSetting = function (name, value, default_value) {
  8737. if (value == undefined) {
  8738. return (this.settings[name] = default_value);
  8739. } else {
  8740. return (this.settings[name] = value);
  8741. }
  8742. };
  8743. SWFUpload.prototype.getSetting = function (name) {
  8744. if (this.settings[name] != undefined) {
  8745. return this.settings[name];
  8746. }
  8747. return "";
  8748. };
  8749. SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
  8750. argumentArray = argumentArray || [];
  8751. var movieElement = this.getMovieElement();
  8752. var returnValue, returnString;
  8753. try {
  8754. returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
  8755. returnValue = eval(returnString);
  8756. } catch (ex) {
  8757. throw "Call to " + functionName + " failed";
  8758. }
  8759. if (returnValue != undefined && typeof returnValue.post === "object") {
  8760. returnValue = this.unescapeFilePostParams(returnValue);
  8761. }
  8762. return returnValue;
  8763. };
  8764. /* *****************************
  8765. -- Flash control methods --
  8766. Your UI should use these
  8767. to operate SWFUpload
  8768. ***************************** */
  8769. SWFUpload.prototype.selectFile = function () {
  8770. this.callFlash("SelectFile");
  8771. };
  8772. SWFUpload.prototype.selectFiles = function () {
  8773. this.callFlash("SelectFiles");
  8774. };
  8775. SWFUpload.prototype.startUpload = function (fileID) {
  8776. this.callFlash("StartUpload", [fileID]);
  8777. };
  8778. SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
  8779. if (triggerErrorEvent !== false) {
  8780. triggerErrorEvent = true;
  8781. }
  8782. this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
  8783. };
  8784. SWFUpload.prototype.stopUpload = function () {
  8785. this.callFlash("StopUpload");
  8786. };
  8787. /* ************************
  8788. * Settings methods
  8789. * These methods change the SWFUpload settings.
  8790. * SWFUpload settings should not be changed directly on the settings object
  8791. * since many of the settings need to be passed to Flash in order to take
  8792. * effect.
  8793. * *********************** */
  8794. SWFUpload.prototype.getStats = function () {
  8795. return this.callFlash("GetStats");
  8796. };
  8797. SWFUpload.prototype.setStats = function (statsObject) {
  8798. this.callFlash("SetStats", [statsObject]);
  8799. };
  8800. SWFUpload.prototype.getFile = function (fileID) {
  8801. if (typeof(fileID) === "number") {
  8802. return this.callFlash("GetFileByIndex", [fileID]);
  8803. } else {
  8804. return this.callFlash("GetFile", [fileID]);
  8805. }
  8806. };
  8807. SWFUpload.prototype.addFileParam = function (fileID, name, value) {
  8808. return this.callFlash("AddFileParam", [fileID, name, value]);
  8809. };
  8810. SWFUpload.prototype.removeFileParam = function (fileID, name) {
  8811. this.callFlash("RemoveFileParam", [fileID, name]);
  8812. };
  8813. SWFUpload.prototype.setUploadURL = function (url) {
  8814. this.settings.upload_url = url.toString();
  8815. this.callFlash("SetUploadURL", [url]);
  8816. };
  8817. SWFUpload.prototype.setPostParams = function (paramsObject) {
  8818. this.settings.post_params = paramsObject;
  8819. this.callFlash("SetPostParams", [paramsObject]);
  8820. };
  8821. SWFUpload.prototype.addPostParam = function (name, value) {
  8822. this.settings.post_params[name] = value;
  8823. this.callFlash("SetPostParams", [this.settings.post_params]);
  8824. };
  8825. SWFUpload.prototype.removePostParam = function (name) {
  8826. delete this.settings.post_params[name];
  8827. this.callFlash("SetPostParams", [this.settings.post_params]);
  8828. };
  8829. SWFUpload.prototype.setFileTypes = function (types, description) {
  8830. this.settings.file_types = types;
  8831. this.settings.file_types_description = description;
  8832. this.callFlash("SetFileTypes", [types, description]);
  8833. };
  8834. SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
  8835. this.settings.file_size_limit = fileSizeLimit;
  8836. this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
  8837. };
  8838. SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
  8839. this.settings.file_upload_limit = fileUploadLimit;
  8840. this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
  8841. };
  8842. SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
  8843. this.settings.file_queue_limit = fileQueueLimit;
  8844. this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
  8845. };
  8846. SWFUpload.prototype.setFilePostName = function (filePostName) {
  8847. this.settings.file_post_name = filePostName;
  8848. this.callFlash("SetFilePostName", [filePostName]);
  8849. };
  8850. SWFUpload.prototype.setUseQueryString = function (useQueryString) {
  8851. this.settings.use_query_string = useQueryString;
  8852. this.callFlash("SetUseQueryString", [useQueryString]);
  8853. };
  8854. SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
  8855. this.settings.requeue_on_error = requeueOnError;
  8856. this.callFlash("SetRequeueOnError", [requeueOnError]);
  8857. };
  8858. SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
  8859. if (typeof http_status_codes === "string") {
  8860. http_status_codes = http_status_codes.replace(" ", "").split(",");
  8861. }
  8862. this.settings.http_success = http_status_codes;
  8863. this.callFlash("SetHTTPSuccess", [http_status_codes]);
  8864. };
  8865. SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
  8866. this.settings.assume_success_timeout = timeout_seconds;
  8867. this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
  8868. };
  8869. SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
  8870. this.settings.debug_enabled = debugEnabled;
  8871. this.callFlash("SetDebugEnabled", [debugEnabled]);
  8872. };
  8873. SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
  8874. if (buttonImageURL == undefined) {
  8875. buttonImageURL = "";
  8876. }
  8877. this.settings.button_image_url = buttonImageURL;
  8878. this.callFlash("SetButtonImageURL", [buttonImageURL]);
  8879. };
  8880. SWFUpload.prototype.setButtonDimensions = function (width, height) {
  8881. this.settings.button_width = width;
  8882. this.settings.button_height = height;
  8883. var movie = this.getMovieElement();
  8884. if (movie != undefined) {
  8885. movie.style.width = width + "px";
  8886. movie.style.height = height + "px";
  8887. }
  8888. this.callFlash("SetButtonDimensions", [width, height]);
  8889. };
  8890. SWFUpload.prototype.setButtonText = function (html) {
  8891. this.settings.button_text = html;
  8892. this.callFlash("SetButtonText", [html]);
  8893. };
  8894. SWFUpload.prototype.setButtonTextPadding = function (left, top) {
  8895. this.settings.button_text_top_padding = top;
  8896. this.settings.button_text_left_padding = left;
  8897. this.callFlash("SetButtonTextPadding", [left, top]);
  8898. };
  8899. SWFUpload.prototype.setButtonTextStyle = function (css) {
  8900. this.settings.button_text_style = css;
  8901. this.callFlash("SetButtonTextStyle", [css]);
  8902. };
  8903. SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
  8904. this.settings.button_disabled = isDisabled;
  8905. this.callFlash("SetButtonDisabled", [isDisabled]);
  8906. };
  8907. SWFUpload.prototype.setButtonAction = function (buttonAction) {
  8908. this.settings.button_action = buttonAction;
  8909. this.callFlash("SetButtonAction", [buttonAction]);
  8910. };
  8911. SWFUpload.prototype.setButtonCursor = function (cursor) {
  8912. this.settings.button_cursor = cursor;
  8913. this.callFlash("SetButtonCursor", [cursor]);
  8914. };
  8915. /* *******************************
  8916. Flash Event Interfaces
  8917. These functions are used by Flash to trigger the various
  8918. events.
  8919. All these functions a Private.
  8920. Because the ExternalInterface library is buggy the event calls
  8921. are added to a queue and the queue then executed by a setTimeout.
  8922. This ensures that events are executed in a determinate order and that
  8923. the ExternalInterface bugs are avoided.
  8924. ******************************* */
  8925. SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
  8926. if (argumentArray == undefined) {
  8927. argumentArray = [];
  8928. } else if (!(argumentArray instanceof Array)) {
  8929. argumentArray = [argumentArray];
  8930. }
  8931. var self = this;
  8932. if (typeof this.settings[handlerName] === "function") {
  8933. this.eventQueue.push(function () {
  8934. this.settings[handlerName].apply(this, argumentArray);
  8935. });
  8936. setTimeout(function () {
  8937. self.executeNextEvent();
  8938. }, 0);
  8939. } else if (this.settings[handlerName] !== null) {
  8940. throw "Event handler " + handlerName + " is unknown or is not a function";
  8941. }
  8942. };
  8943. SWFUpload.prototype.executeNextEvent = function () {
  8944. var f = this.eventQueue ? this.eventQueue.shift() : null;
  8945. if (typeof(f) === "function") {
  8946. f.apply(this);
  8947. }
  8948. };
  8949. SWFUpload.prototype.unescapeFilePostParams = function (file) {
  8950. var reg = /[$]([0-9a-f]{4})/i;
  8951. var unescapedPost = {};
  8952. var uk;
  8953. if (file != undefined) {
  8954. for (var k in file.post) {
  8955. if (file.post.hasOwnProperty(k)) {
  8956. uk = k;
  8957. var match;
  8958. while ((match = reg.exec(uk)) !== null) {
  8959. uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
  8960. }
  8961. unescapedPost[uk] = file.post[k];
  8962. }
  8963. }
  8964. file.post = unescapedPost;
  8965. }
  8966. return file;
  8967. };
  8968. SWFUpload.prototype.testExternalInterface = function () {
  8969. try {
  8970. return this.callFlash("TestExternalInterface");
  8971. } catch (ex) {
  8972. return false;
  8973. }
  8974. };
  8975. SWFUpload.prototype.flashReady = function () {
  8976. var movieElement = this.getMovieElement();
  8977. if (!movieElement) {
  8978. this.debug("Flash called back ready but the flash movie can't be found.");
  8979. return;
  8980. }
  8981. this.cleanUp(movieElement);
  8982. this.queueEvent("swfupload_loaded_handler");
  8983. };
  8984. SWFUpload.prototype.cleanUp = function (movieElement) {
  8985. try {
  8986. if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") {
  8987. this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
  8988. for (var key in movieElement) {
  8989. try {
  8990. if (typeof(movieElement[key]) === "function") {
  8991. movieElement[key] = null;
  8992. }
  8993. } catch (ex) {
  8994. }
  8995. }
  8996. }
  8997. } catch (ex1) {
  8998. }
  8999. window["__flash__removeCallback"] = function (instance, name) {
  9000. try {
  9001. if (instance) {
  9002. instance[name] = null;
  9003. }
  9004. } catch (flashEx) {
  9005. }
  9006. };
  9007. };
  9008. /* This is a chance to do something before the browse window opens */
  9009. SWFUpload.prototype.fileDialogStart = function () {
  9010. this.queueEvent("file_dialog_start_handler");
  9011. };
  9012. /* Called when a file is successfully added to the queue. */
  9013. SWFUpload.prototype.fileQueued = function (file) {
  9014. file = this.unescapeFilePostParams(file);
  9015. this.queueEvent("file_queued_handler", file);
  9016. };
  9017. /* Handle errors that occur when an attempt to queue a file fails. */
  9018. SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
  9019. file = this.unescapeFilePostParams(file);
  9020. this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
  9021. };
  9022. /* Called after the file dialog has closed and the selected files have been queued.
  9023. You could call startUpload here if you want the queued files to begin uploading immediately. */
  9024. SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
  9025. this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
  9026. };
  9027. SWFUpload.prototype.uploadStart = function (file) {
  9028. file = this.unescapeFilePostParams(file);
  9029. this.queueEvent("return_upload_start_handler", file);
  9030. };
  9031. SWFUpload.prototype.returnUploadStart = function (file) {
  9032. var returnValue;
  9033. if (typeof this.settings.upload_start_handler === "function") {
  9034. file = this.unescapeFilePostParams(file);
  9035. returnValue = this.settings.upload_start_handler.call(this, file);
  9036. } else if (this.settings.upload_start_handler != undefined) {
  9037. throw "upload_start_handler must be a function";
  9038. }
  9039. if (returnValue === undefined) {
  9040. returnValue = true;
  9041. }
  9042. returnValue = !!returnValue;
  9043. this.callFlash("ReturnUploadStart", [returnValue]);
  9044. };
  9045. SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
  9046. file = this.unescapeFilePostParams(file);
  9047. this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
  9048. };
  9049. SWFUpload.prototype.uploadError = function (file, errorCode, message) {
  9050. file = this.unescapeFilePostParams(file);
  9051. this.queueEvent("upload_error_handler", [file, errorCode, message]);
  9052. };
  9053. SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
  9054. file = this.unescapeFilePostParams(file);
  9055. this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
  9056. };
  9057. SWFUpload.prototype.uploadComplete = function (file) {
  9058. file = this.unescapeFilePostParams(file);
  9059. this.queueEvent("upload_complete_handler", file);
  9060. };
  9061. /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
  9062. internal debug console. You can override this event and have messages written where you want. */
  9063. SWFUpload.prototype.debug = function (message) {
  9064. this.queueEvent("debug_handler", message);
  9065. };
  9066. /* **********************************
  9067. Debug Console
  9068. The debug console is a self contained, in page location
  9069. for debug message to be sent. The Debug Console adds
  9070. itself to the body if necessary.
  9071. The console is automatically scrolled as messages appear.
  9072. If you are using your own debug handler or when you deploy to production and
  9073. have debug disabled you can remove these functions to reduce the file size
  9074. and complexity.
  9075. ********************************** */
  9076. SWFUpload.prototype.debugMessage = function (message) {
  9077. if (this.settings.debug) {
  9078. var exceptionMessage, exceptionValues = [];
  9079. if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
  9080. for (var key in message) {
  9081. if (message.hasOwnProperty(key)) {
  9082. exceptionValues.push(key + ": " + message[key]);
  9083. }
  9084. }
  9085. exceptionMessage = exceptionValues.join("\n") || "";
  9086. exceptionValues = exceptionMessage.split("\n");
  9087. exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
  9088. SWFUpload.Console.writeLine(exceptionMessage);
  9089. } else {
  9090. SWFUpload.Console.writeLine(message);
  9091. }
  9092. }
  9093. };
  9094. SWFUpload.Console = {};
  9095. SWFUpload.Console.writeLine = function (message) {
  9096. var console, documentForm;
  9097. try {
  9098. console = document.getElementById("SWFUpload_Console");
  9099. if (!console) {
  9100. documentForm = document.createElement("form");
  9101. document.getElementsByTagName("body")[0].appendChild(documentForm);
  9102. console = document.createElement("textarea");
  9103. console.id = "SWFUpload_Console";
  9104. console.style.fontFamily = "monospace";
  9105. console.setAttribute("wrap", "off");
  9106. console.wrap = "off";
  9107. console.style.overflow = "auto";
  9108. console.style.width = "700px";
  9109. console.style.height = "350px";
  9110. console.style.margin = "5px";
  9111. documentForm.appendChild(console);
  9112. }
  9113. console.value += message + "\n";
  9114. console.scrollTop = console.scrollHeight - console.clientHeight;
  9115. } catch (ex) {
  9116. alert("Exception: " + ex.name + " Message: " + ex.message);
  9117. }
  9118. };
  9119. })();
  9120. (function() {
  9121. /*
  9122. Queue Plug-in
  9123. Features:
  9124. *Adds a cancelQueue() method for cancelling the entire queue.
  9125. *All queued files are uploaded when startUpload() is called.
  9126. *If false is returned from uploadComplete then the queue upload is stopped.
  9127. If false is not returned (strict comparison) then the queue upload is continued.
  9128. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  9129. Set the event handler with the queue_complete_handler setting.
  9130. */
  9131. if (typeof(SWFUpload) === "function") {
  9132. SWFUpload.queue = {};
  9133. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  9134. return function () {
  9135. if (typeof(oldInitSettings) === "function") {
  9136. oldInitSettings.call(this);
  9137. }
  9138. this.queueSettings = {};
  9139. this.queueSettings.queue_cancelled_flag = false;
  9140. this.queueSettings.queue_upload_count = 0;
  9141. this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
  9142. this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
  9143. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  9144. this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
  9145. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  9146. };
  9147. })(SWFUpload.prototype.initSettings);
  9148. SWFUpload.prototype.startUpload = function (fileID) {
  9149. this.queueSettings.queue_cancelled_flag = false;
  9150. this.callFlash("StartUpload", [fileID]);
  9151. };
  9152. SWFUpload.prototype.cancelQueue = function () {
  9153. this.queueSettings.queue_cancelled_flag = true;
  9154. this.stopUpload();
  9155. var stats = this.getStats();
  9156. while (stats.files_queued > 0) {
  9157. this.cancelUpload();
  9158. stats = this.getStats();
  9159. }
  9160. };
  9161. SWFUpload.queue.uploadStartHandler = function (file) {
  9162. var returnValue;
  9163. if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
  9164. returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
  9165. }
  9166. returnValue = (returnValue === false) ? false : true;
  9167. this.queueSettings.queue_cancelled_flag = !returnValue;
  9168. return returnValue;
  9169. };
  9170. SWFUpload.queue.uploadCompleteHandler = function (file) {
  9171. var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
  9172. var continueUpload;
  9173. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  9174. this.queueSettings.queue_upload_count++;
  9175. }
  9176. if (typeof(user_upload_complete_handler) === "function") {
  9177. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  9178. } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
  9179. continueUpload = false;
  9180. } else {
  9181. continueUpload = true;
  9182. }
  9183. if (continueUpload) {
  9184. var stats = this.getStats();
  9185. if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
  9186. this.startUpload();
  9187. } else if (this.queueSettings.queue_cancelled_flag === false) {
  9188. this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
  9189. this.queueSettings.queue_upload_count = 0;
  9190. } else {
  9191. this.queueSettings.queue_cancelled_flag = false;
  9192. this.queueSettings.queue_upload_count = 0;
  9193. }
  9194. }
  9195. };
  9196. }
  9197. })();
  9198. /*******************************************************************************
  9199. * KindEditor - WYSIWYG HTML Editor for Internet
  9200. * Copyright (C) 2006-2011 kindsoft.net
  9201. *
  9202. * @author Roddy <luolonghao@gmail.com>
  9203. * @site http://www.kindsoft.net/
  9204. * @licence http://www.kindsoft.net/license.php
  9205. *******************************************************************************/
  9206. KindEditor.plugin('pagebreak', function(K) {
  9207. var self = this;
  9208. var name = 'pagebreak';
  9209. var pagebreakHtml = K.undef(self.pagebreakHtml, '<hr style="page-break-after: always;" class="ke-pagebreak" />');
  9210. self.clickToolbar(name, function() {
  9211. var cmd = self.cmd, range = cmd.range;
  9212. self.focus();
  9213. var tail = self.newlineTag == 'br' || K.WEBKIT ? '' : '<span id="__kindeditor_tail_tag__"></span>';
  9214. self.insertHtml(pagebreakHtml + tail);
  9215. if (tail !== '') {
  9216. var p = K('#__kindeditor_tail_tag__', self.edit.doc);
  9217. range.selectNodeContents(p[0]);
  9218. p.removeAttr('id');
  9219. cmd.select();
  9220. }
  9221. });
  9222. });
  9223. /*******************************************************************************
  9224. * KindEditor - WYSIWYG HTML Editor for Internet
  9225. * Copyright (C) 2006-2011 kindsoft.net
  9226. *
  9227. * @author Roddy <luolonghao@gmail.com>
  9228. * @site http://www.kindsoft.net/
  9229. * @licence http://www.kindsoft.net/license.php
  9230. *******************************************************************************/
  9231. KindEditor.plugin('plainpaste', function(K) {
  9232. var self = this, name = 'plainpaste';
  9233. self.clickToolbar(name, function() {
  9234. var lang = self.lang(name + '.'),
  9235. html = '<div style="padding:10px 20px;">' +
  9236. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  9237. '<textarea class="ke-textarea" style="width:408px;height:260px;"></textarea>' +
  9238. '</div>',
  9239. dialog = self.createDialog({
  9240. name : name,
  9241. width : 450,
  9242. title : self.lang(name),
  9243. body : html,
  9244. yesBtn : {
  9245. name : self.lang('yes'),
  9246. click : function(e) {
  9247. var html = textarea.val();
  9248. html = K.escape(html);
  9249. html = html.replace(/ {2}/g, ' &nbsp;');
  9250. if (self.newlineTag == 'p') {
  9251. html = html.replace(/^/, '<p>').replace(/$/, '</p>').replace(/\n/g, '</p><p>');
  9252. } else {
  9253. html = html.replace(/\n/g, '<br />$&');
  9254. }
  9255. self.insertHtml(html).hideDialog().focus();
  9256. }
  9257. }
  9258. }),
  9259. textarea = K('textarea', dialog.div);
  9260. textarea[0].focus();
  9261. });
  9262. });
  9263. /*******************************************************************************
  9264. * KindEditor - WYSIWYG HTML Editor for Internet
  9265. * Copyright (C) 2006-2011 kindsoft.net
  9266. *
  9267. * @author Roddy <luolonghao@gmail.com>
  9268. * @site http://www.kindsoft.net/
  9269. * @licence http://www.kindsoft.net/license.php
  9270. *******************************************************************************/
  9271. KindEditor.plugin('preview', function(K) {
  9272. var self = this, name = 'preview', undefined;
  9273. self.clickToolbar(name, function() {
  9274. var lang = self.lang(name + '.'),
  9275. html = '<div style="padding:10px 20px;">' +
  9276. '<iframe class="ke-textarea" frameborder="0" style="width:708px;height:400px;"></iframe>' +
  9277. '</div>',
  9278. dialog = self.createDialog({
  9279. name : name,
  9280. width : 750,
  9281. title : self.lang(name),
  9282. body : html
  9283. }),
  9284. iframe = K('iframe', dialog.div),
  9285. doc = K.iframeDoc(iframe);
  9286. doc.open();
  9287. doc.write(self.fullHtml());
  9288. doc.close();
  9289. K(doc.body).css('background-color', '#FFF');
  9290. iframe[0].contentWindow.focus();
  9291. });
  9292. });
  9293. /*******************************************************************************
  9294. * KindEditor - WYSIWYG HTML Editor for Internet
  9295. * Copyright (C) 2006-2011 kindsoft.net
  9296. *
  9297. * @author Roddy <luolonghao@gmail.com>
  9298. * @site http://www.kindsoft.net/
  9299. * @licence http://www.kindsoft.net/license.php
  9300. *******************************************************************************/
  9301. KindEditor.plugin('quickformat', function(K) {
  9302. var self = this, name = 'quickformat',
  9303. blockMap = K.toMap('blockquote,center,div,h1,h2,h3,h4,h5,h6,p');
  9304. function getFirstChild(knode) {
  9305. var child = knode.first();
  9306. while (child && child.first()) {
  9307. child = child.first();
  9308. }
  9309. return child;
  9310. }
  9311. self.clickToolbar(name, function() {
  9312. self.focus();
  9313. var doc = self.edit.doc,
  9314. range = self.cmd.range,
  9315. child = K(doc.body).first(), next,
  9316. nodeList = [], subList = [],
  9317. bookmark = range.createBookmark(true);
  9318. while(child) {
  9319. next = child.next();
  9320. var firstChild = getFirstChild(child);
  9321. if (!firstChild || firstChild.name != 'img') {
  9322. if (blockMap[child.name]) {
  9323. child.html(child.html().replace(/^(\s|&nbsp;| )+/ig, ''));
  9324. child.css('text-indent', '2em');
  9325. } else {
  9326. subList.push(child);
  9327. }
  9328. if (!next || (blockMap[next.name] || blockMap[child.name] && !blockMap[next.name])) {
  9329. if (subList.length > 0) {
  9330. nodeList.push(subList);
  9331. }
  9332. subList = [];
  9333. }
  9334. }
  9335. child = next;
  9336. }
  9337. K.each(nodeList, function(i, subList) {
  9338. var wrapper = K('<p style="text-indent:2em;"></p>', doc);
  9339. subList[0].before(wrapper);
  9340. K.each(subList, function(i, knode) {
  9341. wrapper.append(knode);
  9342. });
  9343. });
  9344. range.moveToBookmark(bookmark);
  9345. self.addBookmark();
  9346. });
  9347. });
  9348. /*******************************************************************************
  9349. * KindEditor - WYSIWYG HTML Editor for Internet
  9350. * Copyright (C) 2006-2011 kindsoft.net
  9351. *
  9352. * @author Roddy <luolonghao@gmail.com>
  9353. * @site http://www.kindsoft.net/
  9354. * @licence http://www.kindsoft.net/license.php
  9355. *******************************************************************************/
  9356. KindEditor.plugin('table', function(K) {
  9357. var self = this, name = 'table', lang = self.lang(name + '.'), zeroborder = 'ke-zeroborder';
  9358. function _setColor(box, color) {
  9359. color = color.toUpperCase();
  9360. box.css('background-color', color);
  9361. box.css('color', color === '#000000' ? '#FFFFFF' : '#000000');
  9362. box.html(color);
  9363. }
  9364. var pickerList = [];
  9365. function _initColorPicker(dialogDiv, colorBox) {
  9366. colorBox.bind('click,mousedown', function(e){
  9367. e.stopPropagation();
  9368. });
  9369. function removePicker() {
  9370. K.each(pickerList, function() {
  9371. this.remove();
  9372. });
  9373. pickerList = [];
  9374. K(document).unbind('click,mousedown', removePicker);
  9375. dialogDiv.unbind('click,mousedown', removePicker);
  9376. }
  9377. colorBox.click(function(e) {
  9378. removePicker();
  9379. var box = K(this),
  9380. pos = box.pos();
  9381. var picker = K.colorpicker({
  9382. x : pos.x,
  9383. y : pos.y + box.height(),
  9384. z : 811214,
  9385. selectedColor : K(this).html(),
  9386. colors : self.colorTable,
  9387. noColor : self.lang('noColor'),
  9388. shadowMode : self.shadowMode,
  9389. click : function(color) {
  9390. _setColor(box, color);
  9391. removePicker();
  9392. }
  9393. });
  9394. pickerList.push(picker);
  9395. K(document).bind('click,mousedown', removePicker);
  9396. dialogDiv.bind('click,mousedown', removePicker);
  9397. });
  9398. }
  9399. function _getCellIndex(table, row, cell) {
  9400. var rowSpanCount = 0;
  9401. for (var i = 0, len = row.cells.length; i < len; i++) {
  9402. if (row.cells[i] == cell) {
  9403. break;
  9404. }
  9405. rowSpanCount += row.cells[i].rowSpan - 1;
  9406. }
  9407. return cell.cellIndex - rowSpanCount;
  9408. }
  9409. self.plugin.table = {
  9410. prop : function(isInsert) {
  9411. var html = [
  9412. '<div style="padding:20px;">',
  9413. '<div class="ke-dialog-row">',
  9414. '<label for="keRows" style="width:90px;">' + lang.cells + '</label>',
  9415. lang.rows + ' <input type="text" id="keRows" class="ke-input-text ke-input-number" name="rows" value="" maxlength="4" /> &nbsp; ',
  9416. lang.cols + ' <input type="text" class="ke-input-text ke-input-number" name="cols" value="" maxlength="4" />',
  9417. '</div>',
  9418. '<div class="ke-dialog-row">',
  9419. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9420. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9421. '<select name="widthType">',
  9422. '<option value="%">' + lang.percent + '</option>',
  9423. '<option value="px">' + lang.px + '</option>',
  9424. '</select> &nbsp; ',
  9425. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9426. '<select name="heightType">',
  9427. '<option value="%">' + lang.percent + '</option>',
  9428. '<option value="px">' + lang.px + '</option>',
  9429. '</select>',
  9430. '</div>',
  9431. '<div class="ke-dialog-row">',
  9432. '<label for="kePadding" style="width:90px;">' + lang.space + '</label>',
  9433. lang.padding + ' <input type="text" id="kePadding" class="ke-input-text ke-input-number" name="padding" value="" maxlength="4" /> &nbsp; ',
  9434. lang.spacing + ' <input type="text" class="ke-input-text ke-input-number" name="spacing" value="" maxlength="4" />',
  9435. '</div>',
  9436. '<div class="ke-dialog-row">',
  9437. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9438. '<select id="keAlign" name="align">',
  9439. '<option value="">' + lang.alignDefault + '</option>',
  9440. '<option value="left">' + lang.alignLeft + '</option>',
  9441. '<option value="center">' + lang.alignCenter + '</option>',
  9442. '<option value="right">' + lang.alignRight + '</option>',
  9443. '</select>',
  9444. '</div>',
  9445. '<div class="ke-dialog-row">',
  9446. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9447. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9448. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9449. '</div>',
  9450. '<div class="ke-dialog-row">',
  9451. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9452. '<span class="ke-inline-block ke-input-color"></span>',
  9453. '</div>',
  9454. '</div>'
  9455. ].join('');
  9456. var bookmark = self.cmd.range.createBookmark();
  9457. var dialog = self.createDialog({
  9458. name : name,
  9459. width : 500,
  9460. title : self.lang(name),
  9461. body : html,
  9462. beforeRemove : function() {
  9463. colorBox.unbind();
  9464. },
  9465. yesBtn : {
  9466. name : self.lang('yes'),
  9467. click : function(e) {
  9468. var rows = rowsBox.val(),
  9469. cols = colsBox.val(),
  9470. width = widthBox.val(),
  9471. height = heightBox.val(),
  9472. widthType = widthTypeBox.val(),
  9473. heightType = heightTypeBox.val(),
  9474. padding = paddingBox.val(),
  9475. spacing = spacingBox.val(),
  9476. align = alignBox.val(),
  9477. border = borderBox.val(),
  9478. borderColor = K(colorBox[0]).html() || '',
  9479. bgColor = K(colorBox[1]).html() || '';
  9480. if (rows == 0 || !/^\d+$/.test(rows)) {
  9481. alert(self.lang('invalidRows'));
  9482. rowsBox[0].focus();
  9483. return;
  9484. }
  9485. if (cols == 0 || !/^\d+$/.test(cols)) {
  9486. alert(self.lang('invalidRows'));
  9487. colsBox[0].focus();
  9488. return;
  9489. }
  9490. if (!/^\d*$/.test(width)) {
  9491. alert(self.lang('invalidWidth'));
  9492. widthBox[0].focus();
  9493. return;
  9494. }
  9495. if (!/^\d*$/.test(height)) {
  9496. alert(self.lang('invalidHeight'));
  9497. heightBox[0].focus();
  9498. return;
  9499. }
  9500. if (!/^\d*$/.test(padding)) {
  9501. alert(self.lang('invalidPadding'));
  9502. paddingBox[0].focus();
  9503. return;
  9504. }
  9505. if (!/^\d*$/.test(spacing)) {
  9506. alert(self.lang('invalidSpacing'));
  9507. spacingBox[0].focus();
  9508. return;
  9509. }
  9510. if (!/^\d*$/.test(border)) {
  9511. alert(self.lang('invalidBorder'));
  9512. borderBox[0].focus();
  9513. return;
  9514. }
  9515. if (table) {
  9516. if (width !== '') {
  9517. table.width(width + widthType);
  9518. } else {
  9519. table.css('width', '');
  9520. }
  9521. if (table[0].width !== undefined) {
  9522. table.removeAttr('width');
  9523. }
  9524. if (height !== '') {
  9525. table.height(height + heightType);
  9526. } else {
  9527. table.css('height', '');
  9528. }
  9529. if (table[0].height !== undefined) {
  9530. table.removeAttr('height');
  9531. }
  9532. table.css('background-color', bgColor);
  9533. if (table[0].bgColor !== undefined) {
  9534. table.removeAttr('bgColor');
  9535. }
  9536. if (padding !== '') {
  9537. table[0].cellPadding = padding;
  9538. } else {
  9539. table.removeAttr('cellPadding');
  9540. }
  9541. if (spacing !== '') {
  9542. table[0].cellSpacing = spacing;
  9543. } else {
  9544. table.removeAttr('cellSpacing');
  9545. }
  9546. if (align !== '') {
  9547. table[0].align = align;
  9548. } else {
  9549. table.removeAttr('align');
  9550. }
  9551. if (border !== '') {
  9552. table.attr('border', border);
  9553. } else {
  9554. table.removeAttr('border');
  9555. }
  9556. if (border === '' || border === '0') {
  9557. table.addClass(zeroborder);
  9558. } else {
  9559. table.removeClass(zeroborder);
  9560. }
  9561. if (borderColor !== '') {
  9562. table.attr('borderColor', borderColor);
  9563. } else {
  9564. table.removeAttr('borderColor');
  9565. }
  9566. self.hideDialog().focus();
  9567. self.cmd.range.moveToBookmark(bookmark);
  9568. self.cmd.select();
  9569. self.addBookmark();
  9570. return;
  9571. }
  9572. var style = '';
  9573. if (width !== '') {
  9574. style += 'width:' + width + widthType + ';';
  9575. }
  9576. if (height !== '') {
  9577. style += 'height:' + height + heightType + ';';
  9578. }
  9579. if (bgColor !== '') {
  9580. style += 'background-color:' + bgColor + ';';
  9581. }
  9582. var html = '<table';
  9583. if (style !== '') {
  9584. html += ' style="' + style + '"';
  9585. }
  9586. if (padding !== '') {
  9587. html += ' cellpadding="' + padding + '"';
  9588. }
  9589. if (spacing !== '') {
  9590. html += ' cellspacing="' + spacing + '"';
  9591. }
  9592. if (align !== '') {
  9593. html += ' align="' + align + '"';
  9594. }
  9595. if (border !== '') {
  9596. html += ' border="' + border + '"';
  9597. }
  9598. if (border === '' || border === '0') {
  9599. html += ' class="' + zeroborder + '"';
  9600. }
  9601. if (borderColor !== '') {
  9602. html += ' bordercolor="' + borderColor + '"';
  9603. }
  9604. html += '>';
  9605. for (var i = 0; i < rows; i++) {
  9606. html += '<tr>';
  9607. for (var j = 0; j < cols; j++) {
  9608. html += '<td>' + (K.IE ? '&nbsp;' : '<br />') + '</td>';
  9609. }
  9610. html += '</tr>';
  9611. }
  9612. html += '</table>';
  9613. if (!K.IE) {
  9614. html += '<br />';
  9615. }
  9616. self.insertHtml(html);
  9617. self.select().hideDialog().focus();
  9618. self.addBookmark();
  9619. }
  9620. }
  9621. }),
  9622. div = dialog.div,
  9623. rowsBox = K('[name="rows"]', div).val(3),
  9624. colsBox = K('[name="cols"]', div).val(2),
  9625. widthBox = K('[name="width"]', div).val(100),
  9626. heightBox = K('[name="height"]', div),
  9627. widthTypeBox = K('[name="widthType"]', div),
  9628. heightTypeBox = K('[name="heightType"]', div),
  9629. paddingBox = K('[name="padding"]', div).val(2),
  9630. spacingBox = K('[name="spacing"]', div).val(0),
  9631. alignBox = K('[name="align"]', div),
  9632. borderBox = K('[name="border"]', div).val(1),
  9633. colorBox = K('.ke-input-color', div);
  9634. _initColorPicker(div, colorBox.eq(0));
  9635. _initColorPicker(div, colorBox.eq(1));
  9636. _setColor(colorBox.eq(0), '#000000');
  9637. _setColor(colorBox.eq(1), '');
  9638. rowsBox[0].focus();
  9639. rowsBox[0].select();
  9640. var table;
  9641. if (isInsert) {
  9642. return;
  9643. }
  9644. table = self.plugin.getSelectedTable();
  9645. if (table) {
  9646. rowsBox.val(table[0].rows.length);
  9647. colsBox.val(table[0].rows.length > 0 ? table[0].rows[0].cells.length : 0);
  9648. rowsBox.attr('disabled', true);
  9649. colsBox.attr('disabled', true);
  9650. var match,
  9651. tableWidth = table[0].style.width || table[0].width,
  9652. tableHeight = table[0].style.height || table[0].height;
  9653. if (tableWidth !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableWidth))) {
  9654. widthBox.val(match[1]);
  9655. widthTypeBox.val(match[2]);
  9656. } else {
  9657. widthBox.val('');
  9658. }
  9659. if (tableHeight !== undefined && (match = /^(\d+)((?:px|%)*)$/.exec(tableHeight))) {
  9660. heightBox.val(match[1]);
  9661. heightTypeBox.val(match[2]);
  9662. }
  9663. paddingBox.val(table[0].cellPadding || '');
  9664. spacingBox.val(table[0].cellSpacing || '');
  9665. alignBox.val(table[0].align || '');
  9666. borderBox.val(table[0].border === undefined ? '' : table[0].border);
  9667. _setColor(colorBox.eq(0), K.toHex(table.attr('borderColor') || ''));
  9668. _setColor(colorBox.eq(1), K.toHex(table[0].style.backgroundColor || table[0].bgColor || ''));
  9669. widthBox[0].focus();
  9670. widthBox[0].select();
  9671. }
  9672. },
  9673. cellprop : function() {
  9674. var html = [
  9675. '<div style="padding:20px;">',
  9676. '<div class="ke-dialog-row">',
  9677. '<label for="keWidth" style="width:90px;">' + lang.size + '</label>',
  9678. lang.width + ' <input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> &nbsp; ',
  9679. '<select name="widthType">',
  9680. '<option value="%">' + lang.percent + '</option>',
  9681. '<option value="px">' + lang.px + '</option>',
  9682. '</select> &nbsp; ',
  9683. lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> &nbsp; ',
  9684. '<select name="heightType">',
  9685. '<option value="%">' + lang.percent + '</option>',
  9686. '<option value="px">' + lang.px + '</option>',
  9687. '</select>',
  9688. '</div>',
  9689. '<div class="ke-dialog-row">',
  9690. '<label for="keAlign" style="width:90px;">' + lang.align + '</label>',
  9691. lang.textAlign + ' <select id="keAlign" name="textAlign">',
  9692. '<option value="">' + lang.alignDefault + '</option>',
  9693. '<option value="left">' + lang.alignLeft + '</option>',
  9694. '<option value="center">' + lang.alignCenter + '</option>',
  9695. '<option value="right">' + lang.alignRight + '</option>',
  9696. '</select> ',
  9697. lang.verticalAlign + ' <select name="verticalAlign">',
  9698. '<option value="">' + lang.alignDefault + '</option>',
  9699. '<option value="top">' + lang.alignTop + '</option>',
  9700. '<option value="middle">' + lang.alignMiddle + '</option>',
  9701. '<option value="bottom">' + lang.alignBottom + '</option>',
  9702. '<option value="baseline">' + lang.alignBaseline + '</option>',
  9703. '</select>',
  9704. '</div>',
  9705. '<div class="ke-dialog-row">',
  9706. '<label for="keBorder" style="width:90px;">' + lang.border + '</label>',
  9707. lang.borderWidth + ' <input type="text" id="keBorder" class="ke-input-text ke-input-number" name="border" value="" maxlength="4" /> &nbsp; ',
  9708. lang.borderColor + ' <span class="ke-inline-block ke-input-color"></span>',
  9709. '</div>',
  9710. '<div class="ke-dialog-row">',
  9711. '<label for="keBgColor" style="width:90px;">' + lang.backgroundColor + '</label>',
  9712. '<span class="ke-inline-block ke-input-color"></span>',
  9713. '</div>',
  9714. '</div>'
  9715. ].join('');
  9716. var bookmark = self.cmd.range.createBookmark();
  9717. var dialog = self.createDialog({
  9718. name : name,
  9719. width : 500,
  9720. title : self.lang('tablecell'),
  9721. body : html,
  9722. beforeRemove : function() {
  9723. colorBox.unbind();
  9724. },
  9725. yesBtn : {
  9726. name : self.lang('yes'),
  9727. click : function(e) {
  9728. var width = widthBox.val(),
  9729. height = heightBox.val(),
  9730. widthType = widthTypeBox.val(),
  9731. heightType = heightTypeBox.val(),
  9732. padding = paddingBox.val(),
  9733. spacing = spacingBox.val(),
  9734. textAlign = textAlignBox.val(),
  9735. verticalAlign = verticalAlignBox.val(),
  9736. border = borderBox.val(),
  9737. borderColor = K(colorBox[0]).html() || '',
  9738. bgColor = K(colorBox[1]).html() || '';
  9739. if (!/^\d*$/.test(width)) {
  9740. alert(self.lang('invalidWidth'));
  9741. widthBox[0].focus();
  9742. return;
  9743. }
  9744. if (!/^\d*$/.test(height)) {
  9745. alert(self.lang('invalidHeight'));
  9746. heightBox[0].focus();
  9747. return;
  9748. }
  9749. if (!/^\d*$/.test(border)) {
  9750. alert(self.lang('invalidBorder'));
  9751. borderBox[0].focus();
  9752. return;
  9753. }
  9754. cell.css({
  9755. width : width !== '' ? (width + widthType) : '',
  9756. height : height !== '' ? (height + heightType) : '',
  9757. 'background-color' : bgColor,
  9758. 'text-align' : textAlign,
  9759. 'vertical-align' : verticalAlign,
  9760. 'border-width' : border,
  9761. 'border-style' : border !== '' ? 'solid' : '',
  9762. 'border-color' : borderColor
  9763. });
  9764. self.hideDialog().focus();
  9765. self.cmd.range.moveToBookmark(bookmark);
  9766. self.cmd.select();
  9767. self.addBookmark();
  9768. }
  9769. }
  9770. }),
  9771. div = dialog.div,
  9772. widthBox = K('[name="width"]', div).val(100),
  9773. heightBox = K('[name="height"]', div),
  9774. widthTypeBox = K('[name="widthType"]', div),
  9775. heightTypeBox = K('[name="heightType"]', div),
  9776. paddingBox = K('[name="padding"]', div).val(2),
  9777. spacingBox = K('[name="spacing"]', div).val(0),
  9778. textAlignBox = K('[name="textAlign"]', div),
  9779. verticalAlignBox = K('[name="verticalAlign"]', div),
  9780. borderBox = K('[name="border"]', div).val(1),
  9781. colorBox = K('.ke-input-color', div);
  9782. _initColorPicker(div, colorBox.eq(0));
  9783. _initColorPicker(div, colorBox.eq(1));
  9784. _setColor(colorBox.eq(0), '#000000');
  9785. _setColor(colorBox.eq(1), '');
  9786. widthBox[0].focus();
  9787. widthBox[0].select();
  9788. var cell = self.plugin.getSelectedCell();
  9789. var match,
  9790. cellWidth = cell[0].style.width || cell[0].width || '',
  9791. cellHeight = cell[0].style.height || cell[0].height || '';
  9792. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellWidth))) {
  9793. widthBox.val(match[1]);
  9794. widthTypeBox.val(match[2]);
  9795. } else {
  9796. widthBox.val('');
  9797. }
  9798. if ((match = /^(\d+)((?:px|%)*)$/.exec(cellHeight))) {
  9799. heightBox.val(match[1]);
  9800. heightTypeBox.val(match[2]);
  9801. }
  9802. textAlignBox.val(cell[0].style.textAlign || '');
  9803. verticalAlignBox.val(cell[0].style.verticalAlign || '');
  9804. var border = cell[0].style.borderWidth || '';
  9805. if (border) {
  9806. border = parseInt(border);
  9807. }
  9808. borderBox.val(border);
  9809. _setColor(colorBox.eq(0), K.toHex(cell[0].style.borderColor || ''));
  9810. _setColor(colorBox.eq(1), K.toHex(cell[0].style.backgroundColor || ''));
  9811. widthBox[0].focus();
  9812. widthBox[0].select();
  9813. },
  9814. insert : function() {
  9815. this.prop(true);
  9816. },
  9817. 'delete' : function() {
  9818. var table = self.plugin.getSelectedTable();
  9819. self.cmd.range.setStartBefore(table[0]).collapse(true);
  9820. self.cmd.select();
  9821. table.remove();
  9822. self.addBookmark();
  9823. },
  9824. colinsert : function(offset) {
  9825. var table = self.plugin.getSelectedTable()[0],
  9826. row = self.plugin.getSelectedRow()[0],
  9827. cell = self.plugin.getSelectedCell()[0],
  9828. index = cell.cellIndex + offset;
  9829. index += table.rows[0].cells.length - row.cells.length;
  9830. for (var i = 0, len = table.rows.length; i < len; i++) {
  9831. var newRow = table.rows[i],
  9832. newCell = newRow.insertCell(index);
  9833. newCell.innerHTML = K.IE ? '' : '<br />';
  9834. index = _getCellIndex(table, newRow, newCell);
  9835. }
  9836. self.cmd.range.selectNodeContents(cell).collapse(true);
  9837. self.cmd.select();
  9838. self.addBookmark();
  9839. },
  9840. colinsertleft : function() {
  9841. this.colinsert(0);
  9842. },
  9843. colinsertright : function() {
  9844. this.colinsert(1);
  9845. },
  9846. rowinsert : function(offset) {
  9847. var table = self.plugin.getSelectedTable()[0],
  9848. row = self.plugin.getSelectedRow()[0],
  9849. cell = self.plugin.getSelectedCell()[0];
  9850. var rowIndex = row.rowIndex;
  9851. if (offset === 1) {
  9852. rowIndex = row.rowIndex + (cell.rowSpan - 1) + offset;
  9853. }
  9854. var newRow = table.insertRow(rowIndex);
  9855. for (var i = 0, len = row.cells.length; i < len; i++) {
  9856. if (row.cells[i].rowSpan > 1) {
  9857. len -= row.cells[i].rowSpan - 1;
  9858. }
  9859. var newCell = newRow.insertCell(i);
  9860. if (offset === 1 && row.cells[i].colSpan > 1) {
  9861. newCell.colSpan = row.cells[i].colSpan;
  9862. }
  9863. newCell.innerHTML = K.IE ? '' : '<br />';
  9864. }
  9865. for (var j = rowIndex; j >= 0; j--) {
  9866. var cells = table.rows[j].cells;
  9867. if (cells.length > i) {
  9868. for (var k = cell.cellIndex; k >= 0; k--) {
  9869. if (cells[k].rowSpan > 1) {
  9870. cells[k].rowSpan += 1;
  9871. }
  9872. }
  9873. break;
  9874. }
  9875. }
  9876. self.cmd.range.selectNodeContents(cell).collapse(true);
  9877. self.cmd.select();
  9878. self.addBookmark();
  9879. },
  9880. rowinsertabove : function() {
  9881. this.rowinsert(0);
  9882. },
  9883. rowinsertbelow : function() {
  9884. this.rowinsert(1);
  9885. },
  9886. rowmerge : function() {
  9887. var table = self.plugin.getSelectedTable()[0],
  9888. row = self.plugin.getSelectedRow()[0],
  9889. cell = self.plugin.getSelectedCell()[0],
  9890. rowIndex = row.rowIndex,
  9891. nextRowIndex = rowIndex + cell.rowSpan,
  9892. nextRow = table.rows[nextRowIndex];
  9893. if (table.rows.length <= nextRowIndex) {
  9894. return;
  9895. }
  9896. var cellIndex = cell.cellIndex;
  9897. if (nextRow.cells.length <= cellIndex) {
  9898. return;
  9899. }
  9900. var nextCell = nextRow.cells[cellIndex];
  9901. if (cell.colSpan !== nextCell.colSpan) {
  9902. return;
  9903. }
  9904. cell.rowSpan += nextCell.rowSpan;
  9905. nextRow.deleteCell(cellIndex);
  9906. self.cmd.range.selectNodeContents(cell).collapse(true);
  9907. self.cmd.select();
  9908. self.addBookmark();
  9909. },
  9910. colmerge : function() {
  9911. var table = self.plugin.getSelectedTable()[0],
  9912. row = self.plugin.getSelectedRow()[0],
  9913. cell = self.plugin.getSelectedCell()[0],
  9914. rowIndex = row.rowIndex,
  9915. cellIndex = cell.cellIndex,
  9916. nextCellIndex = cellIndex + 1;
  9917. if (row.cells.length <= nextCellIndex) {
  9918. return;
  9919. }
  9920. var nextCell = row.cells[nextCellIndex];
  9921. if (cell.rowSpan !== nextCell.rowSpan) {
  9922. return;
  9923. }
  9924. cell.colSpan += nextCell.colSpan;
  9925. row.deleteCell(nextCellIndex);
  9926. self.cmd.range.selectNodeContents(cell).collapse(true);
  9927. self.cmd.select();
  9928. self.addBookmark();
  9929. },
  9930. rowsplit : function() {
  9931. var table = self.plugin.getSelectedTable()[0],
  9932. row = self.plugin.getSelectedRow()[0],
  9933. cell = self.plugin.getSelectedCell()[0],
  9934. rowIndex = row.rowIndex;
  9935. if (cell.rowSpan === 1) {
  9936. return;
  9937. }
  9938. var cellIndex = _getCellIndex(table, row, cell);
  9939. for (var i = 1, len = cell.rowSpan; i < len; i++) {
  9940. var newRow = table.rows[rowIndex + i],
  9941. newCell = newRow.insertCell(cellIndex);
  9942. if (cell.colSpan > 1) {
  9943. newCell.colSpan = cell.colSpan;
  9944. }
  9945. newCell.innerHTML = K.IE ? '' : '<br />';
  9946. cellIndex = _getCellIndex(table, newRow, newCell);
  9947. }
  9948. K(cell).removeAttr('rowSpan');
  9949. self.cmd.range.selectNodeContents(cell).collapse(true);
  9950. self.cmd.select();
  9951. self.addBookmark();
  9952. },
  9953. colsplit : function() {
  9954. var table = self.plugin.getSelectedTable()[0],
  9955. row = self.plugin.getSelectedRow()[0],
  9956. cell = self.plugin.getSelectedCell()[0],
  9957. cellIndex = cell.cellIndex;
  9958. if (cell.colSpan === 1) {
  9959. return;
  9960. }
  9961. for (var i = 1, len = cell.colSpan; i < len; i++) {
  9962. var newCell = row.insertCell(cellIndex + i);
  9963. if (cell.rowSpan > 1) {
  9964. newCell.rowSpan = cell.rowSpan;
  9965. }
  9966. newCell.innerHTML = K.IE ? '' : '<br />';
  9967. }
  9968. K(cell).removeAttr('colSpan');
  9969. self.cmd.range.selectNodeContents(cell).collapse(true);
  9970. self.cmd.select();
  9971. self.addBookmark();
  9972. },
  9973. coldelete : function() {
  9974. var table = self.plugin.getSelectedTable()[0],
  9975. row = self.plugin.getSelectedRow()[0],
  9976. cell = self.plugin.getSelectedCell()[0],
  9977. index = cell.cellIndex;
  9978. for (var i = 0, len = table.rows.length; i < len; i++) {
  9979. var newRow = table.rows[i],
  9980. newCell = newRow.cells[index];
  9981. if (newCell.colSpan > 1) {
  9982. newCell.colSpan -= 1;
  9983. if (newCell.colSpan === 1) {
  9984. K(newCell).removeAttr('colSpan');
  9985. }
  9986. } else {
  9987. newRow.deleteCell(index);
  9988. }
  9989. if (newCell.rowSpan > 1) {
  9990. i += newCell.rowSpan - 1;
  9991. }
  9992. }
  9993. if (row.cells.length === 0) {
  9994. self.cmd.range.setStartBefore(table).collapse(true);
  9995. self.cmd.select();
  9996. K(table).remove();
  9997. } else {
  9998. self.cmd.selection(true);
  9999. }
  10000. self.addBookmark();
  10001. },
  10002. rowdelete : function() {
  10003. var table = self.plugin.getSelectedTable()[0],
  10004. row = self.plugin.getSelectedRow()[0],
  10005. cell = self.plugin.getSelectedCell()[0],
  10006. rowIndex = row.rowIndex;
  10007. for (var i = cell.rowSpan - 1; i >= 0; i--) {
  10008. table.deleteRow(rowIndex + i);
  10009. }
  10010. if (table.rows.length === 0) {
  10011. self.cmd.range.setStartBefore(table).collapse(true);
  10012. self.cmd.select();
  10013. K(table).remove();
  10014. } else {
  10015. self.cmd.selection(true);
  10016. }
  10017. self.addBookmark();
  10018. }
  10019. };
  10020. self.clickToolbar(name, self.plugin.table.prop);
  10021. });
  10022. /*******************************************************************************
  10023. * KindEditor - WYSIWYG HTML Editor for Internet
  10024. * Copyright (C) 2006-2011 kindsoft.net
  10025. *
  10026. * @author Roddy <luolonghao@gmail.com>
  10027. * @site http://www.kindsoft.net/
  10028. * @licence http://www.kindsoft.net/license.php
  10029. *******************************************************************************/
  10030. KindEditor.plugin('template', function(K) {
  10031. var self = this, name = 'template', lang = self.lang(name + '.'),
  10032. htmlPath = self.pluginsPath + name + '/html/';
  10033. function getFilePath(fileName) {
  10034. return htmlPath + fileName + '?ver=' + encodeURIComponent(K.DEBUG ? K.TIME : K.VERSION);
  10035. }
  10036. self.clickToolbar(name, function() {
  10037. var lang = self.lang(name + '.'),
  10038. arr = ['<div style="padding:10px 20px;">',
  10039. '<div class="ke-header">',
  10040. '<div class="ke-left">',
  10041. lang. selectTemplate + ' <select>'];
  10042. K.each(lang.fileList, function(key, val) {
  10043. arr.push('<option value="' + key + '">' + val + '</option>');
  10044. });
  10045. html = [arr.join(''),
  10046. '</select></div>',
  10047. '<div class="ke-right">',
  10048. '<input type="checkbox" id="keReplaceFlag" name="replaceFlag" value="1" /> <label for="keReplaceFlag">' + lang.replaceContent + '</label>',
  10049. '</div>',
  10050. '<div class="ke-clearfix"></div>',
  10051. '</div>',
  10052. '<iframe class="ke-textarea" frameborder="0" style="width:458px;height:260px;background-color:#FFF;"></iframe>',
  10053. '</div>'].join('');
  10054. var dialog = self.createDialog({
  10055. name : name,
  10056. width : 500,
  10057. title : self.lang(name),
  10058. body : html,
  10059. yesBtn : {
  10060. name : self.lang('yes'),
  10061. click : function(e) {
  10062. var doc = K.iframeDoc(iframe);
  10063. self[checkbox[0].checked ? 'html' : 'insertHtml'](doc.body.innerHTML).hideDialog().focus();
  10064. }
  10065. }
  10066. });
  10067. var selectBox = K('select', dialog.div),
  10068. checkbox = K('[name="replaceFlag"]', dialog.div),
  10069. iframe = K('iframe', dialog.div);
  10070. checkbox[0].checked = true;
  10071. iframe.attr('src', getFilePath(selectBox.val()));
  10072. selectBox.change(function() {
  10073. iframe.attr('src', getFilePath(this.value));
  10074. });
  10075. });
  10076. });
  10077. /*******************************************************************************
  10078. * KindEditor - WYSIWYG HTML Editor for Internet
  10079. * Copyright (C) 2006-2011 kindsoft.net
  10080. *
  10081. * @author Roddy <luolonghao@gmail.com>
  10082. * @site http://www.kindsoft.net/
  10083. * @licence http://www.kindsoft.net/license.php
  10084. *******************************************************************************/
  10085. KindEditor.plugin('wordpaste', function(K) {
  10086. var self = this, name = 'wordpaste';
  10087. self.clickToolbar(name, function() {
  10088. var lang = self.lang(name + '.'),
  10089. html = '<div style="padding:10px 20px;">' +
  10090. '<div style="margin-bottom:10px;">' + lang.comment + '</div>' +
  10091. '<iframe class="ke-textarea" frameborder="0" style="width:408px;height:260px;"></iframe>' +
  10092. '</div>',
  10093. dialog = self.createDialog({
  10094. name : name,
  10095. width : 450,
  10096. title : self.lang(name),
  10097. body : html,
  10098. yesBtn : {
  10099. name : self.lang('yes'),
  10100. click : function(e) {
  10101. var str = doc.body.innerHTML;
  10102. str = K.clearMsWord(str, self.filterMode ? self.htmlTags : K.options.htmlTags);
  10103. self.insertHtml(str).hideDialog().focus();
  10104. }
  10105. }
  10106. }),
  10107. div = dialog.div,
  10108. iframe = K('iframe', div),
  10109. doc = K.iframeDoc(iframe);
  10110. if (!K.IE) {
  10111. doc.designMode = 'on';
  10112. }
  10113. doc.open();
  10114. doc.write('<!doctype html><html><head><title>WordPaste</title></head>');
  10115. doc.write('<body style="background-color:#FFF;font-size:12px;margin:2px;">');
  10116. if (!K.IE) {
  10117. doc.write('<br />');
  10118. }
  10119. doc.write('</body></html>');
  10120. doc.close();
  10121. if (K.IE) {
  10122. doc.body.contentEditable = 'true';
  10123. }
  10124. iframe[0].contentWindow.focus();
  10125. });
  10126. });
  10127. KindEditor.plugin('fixtoolbar', function (K) {
  10128. var self = this;
  10129. if (!self.fixToolBar) {
  10130. return;
  10131. }
  10132. function init() {
  10133. var toolbar = K('.ke-toolbar');
  10134. var originY = toolbar.pos().y;
  10135. K(window).bind('scroll', function () {
  10136. if (toolbar.css('position') == 'fixed') {
  10137. if(document.body.scrollTop - originY < 0){
  10138. toolbar.css('position', 'static');
  10139. toolbar.css('top', 'auto');
  10140. }
  10141. } else {
  10142. if (toolbar.pos().y - document.body.scrollTop < 0) {
  10143. toolbar.css('position', 'fixed');
  10144. toolbar.css('top', 0);
  10145. }
  10146. }
  10147. });
  10148. }
  10149. if (self.isCreated) {
  10150. init();
  10151. } else {
  10152. self.afterCreate(init);
  10153. }
  10154. });
  10155. //自定义资源库
  10156. KindEditor.plugin('res', function(K) {
  10157. var self = this;
  10158. // 点击图标时执行
  10159. self.clickToolbar('res', function() {
  10160. var clickFn = function(url, title, id) {
  10161. var html = '<embed src="{url}" type="video/x-ms-asf-plugin" width="550" height="400" autostart="false" loop="true" id="{id}"/>';
  10162. html = html.replace('{url}', url);
  10163. html = html.replace('{id}', id);
  10164. self.insertHtml(html);
  10165. };
  10166. editorShowUpload('', self.fileManagerJson, '视频库', clickFn, this);
  10167. });
  10168. });
  10169. function autoImg(self) {
  10170. var index = self.index;
  10171. var haspicContainer = document.getElementById("has_pic_" + index);
  10172. if (haspicContainer == null) {
  10173. haspicContainer = document.createElement("div");
  10174. haspicContainer.id = "has_pic_" + index;
  10175. 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>";
  10176. $(".ke-toolbar").eq(index).after(haspicContainer);
  10177. }
  10178. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  10179. var piccount = 0;
  10180. var sstr = '';
  10181. $(img).each(function (i) {
  10182. var that = $(this);
  10183. var host = gethost(self.uploadResJson);
  10184. var yhost = '';
  10185. if (self.uploadYunJson && self.uploadYunJson.host) {
  10186. yhost = gethost(self.uploadYunJson.host);
  10187. }
  10188. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  10189. var n = gethost(that.attr("src"));
  10190. if (yhost) {
  10191. if (host != n && yhost != n) {
  10192. piccount++;
  10193. if (i == $(img).length - 1)
  10194. sstr += that.attr("src");
  10195. else
  10196. sstr += that.attr("src") + ",";
  10197. }
  10198. } else {
  10199. if (host != n) {
  10200. piccount++;
  10201. if (i == $(img).length - 1)
  10202. sstr += that.attr("src");
  10203. else
  10204. sstr += that.attr("src") + ",";
  10205. }
  10206. }
  10207. }
  10208. });
  10209. $("#piclist_" + index).val(encodeURIComponent(sstr));
  10210. document.getElementById("has_pic_" + index).style.display = (piccount > 0) ? "block" : "none";
  10211. }
  10212. function closeupload(index) {
  10213. $("#has_pic_" + index).hide();
  10214. $("#upload_" + index).show();
  10215. }
  10216. function uploadpic(url, name, index) {
  10217. var piclist = encodeURI($("#piclist_" + index).val());
  10218. if (piclist.length == 0) return false;
  10219. $.ajax({
  10220. url: url.replace('kindeditor', 'copys') + '&json=1',
  10221. data: name + "=" + piclist,
  10222. type: "POST",
  10223. dataType: "json",
  10224. beforeSend: function () {
  10225. $("#upload_" + index).hide();
  10226. $("#confirm_" + index).text("正在上传中...");
  10227. },
  10228. success: function (msg) {
  10229. var url = msg.data;
  10230. if (url !== "") {
  10231. var str = new Array();
  10232. str = url.split(',');
  10233. var img = $(".ke-edit-iframe").eq(index).contents().find("img");
  10234. $(img).each(function (i) {
  10235. var that = $(this);
  10236. if (that.attr("src").indexOf("http://") >= 0 || that.attr("src").indexOf("https://") >= 0) {
  10237. that.attr("src", str[i]);
  10238. that.attr("data-ke-src", str[i]);
  10239. }
  10240. });
  10241. $("#confirm_" + index).html(img.length + "张图片已经上传成功!&nbsp;&nbsp;<a href='javascript:closeupload("+index+");'>关闭</a>");
  10242. }
  10243. else $("#confirm_" + index).text("上传失败!");
  10244. }
  10245. });
  10246. }
  10247. function gethost(url){
  10248. var reg = /^http(s)?:\/\/(.*?)\//;
  10249. return reg.exec(url)[2];
  10250. }